Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master-1, master-0, and 0.9.4

Split out tree parsing function.

Changeset 8032747902c4

Parent 2643a6b8935e

by Jelmer Vernooij

Changes to one file · Browse files at 8032747902c4 Showing diff from parent 2643a6b8935e Diff from another changeset...

 
318
319
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
322
323
 
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
 
374
375
376
 
437
438
439
 
440
441
442
 
461
462
463
 
464
465
466
 
554
555
556
557
 
558
559
560
 
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
 
376
377
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
380
381
382
 
443
444
445
446
447
448
449
 
468
469
470
471
472
473
474
 
562
563
564
 
565
566
567
568
@@ -318,6 +318,33 @@
  return self._message     +def parse_tree(text): + ret = [] + count = 0 + while count < len(text): + mode = 0 + chr = text[count] + while chr != ' ': + assert chr >= '0' and chr <= '7', "%s is not a valid mode char" % chr + mode = (mode << 3) + (ord(chr) - ord('0')) + count += 1 + chr = text[count] + count += 1 + chr = text[count] + name = '' + while chr != '\0': + name += chr + count += 1 + chr = text[count] + count += 1 + chr = text[count] + sha = text[count:count+20] + hexsha = sha_to_hex(sha) + ret.append((mode, name, hexsha)) + count = count + 20 + return ret + +  class Tree(ShaFile):   """A Git tree object"""   @@ -349,28 +376,7 @@
    def _parse_text(self):   """Grab the entries in the tree""" - count = 0 - while count < len(self._text): - mode = 0 - chr = self._text[count] - while chr != ' ': - assert chr >= '0' and chr <= '7', "%s is not a valid mode char" % chr - mode = (mode << 3) + (ord(chr) - ord('0')) - count += 1 - chr = self._text[count] - count += 1 - chr = self._text[count] - name = '' - while chr != '\0': - name += chr - count += 1 - chr = self._text[count] - count += 1 - chr = self._text[count] - sha = self._text[count:count+20] - hexsha = sha_to_hex(sha) - self.add(mode, name, hexsha) - count = count + 20 + self._entries = parse_tree(self._text)     def serialize(self):   self._text = "" @@ -437,6 +443,7 @@
  count += 1   self._author_time = int(text[count:count+10])   while text[count] != ' ': + assert text[count] != '\n', "Malformed author information"   count += 1   self._author_timezone = int(text[count:count+6])   count += 1 @@ -461,6 +468,7 @@
  count += 1   self._commit_time = int(text[count:count+10])   while text[count] != ' ': + assert text[count] != '\n', "Malformed committer information"   count += 1   self._commit_timezone = int(text[count:count+6])   count += 1 @@ -554,7 +562,7 @@
   try:   # Try to import C versions - from dulwich._objects import hex_to_sha, sha_to_hex + from dulwich._objects import hex_to_sha, sha_to_hex, parse_tree  except ImportError:   pass