Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

Distinguish between ShaFile.from_file and ShaFile.from_path.

Changeset d987b8a88089

Parent 7ed2a0a70f29

by Jelmer Vernooij

Changes to 3 files · Browse files at d987b8a88089 Showing diff from parent 7ed2a0a70f29 Diff from another changeset...

 
378
379
380
381
 
382
383
384
 
378
379
380
 
381
382
383
384
@@ -378,7 +378,7 @@
  def _get_loose_object(self, sha):   path = self._get_shafile_path(sha)   try: - return ShaFile.from_file(path) + return ShaFile.from_path(path)   except (OSError, IOError), e:   if e.errno == errno.ENOENT:   return None
 
256
257
258
259
 
260
261
262
 
318
319
320
321
322
323
 
 
324
325
326
327
328
329
330
331
332
 
 
 
333
334
 
 
 
 
 
 
 
 
 
 
 
 
335
336
337
 
491
492
493
494
495
 
 
496
497
 
498
499
500
 
539
540
541
542
543
 
 
544
545
546
 
625
626
627
628
 
629
630
631
 
711
712
713
714
715
 
 
716
717
718
 
860
861
862
863
864
 
 
865
866
 
867
868
869
 
256
257
258
 
259
260
261
262
 
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
 
497
498
499
 
 
500
501
502
 
503
504
505
506
 
545
546
547
 
 
548
549
550
551
552
 
631
632
633
 
634
635
636
637
 
717
718
719
 
 
720
721
722
723
724
 
866
867
868
 
 
869
870
871
 
872
873
874
875
@@ -256,7 +256,7 @@
  num_type = (ord(magic[0]) >> 4) & 7   obj_class = object_class(num_type)   if not obj_class: - raise ObjectFormatError("Not a known type: %d" % num_type) + raise ObjectFormatException("Not a known type: %d" % num_type)   obj = obj_class()   obj._filename = f.name   return obj @@ -318,20 +318,26 @@
  f.close()     @classmethod - def from_file(cls, filename): - """Get the contents of a SHA file on disk.""" - f = GitFile(filename, 'rb') + def from_path(cls, path): + f = GitFile(path, 'rb')   try: - try: - obj = cls._parse_file_header(f) - obj._sha = FixedSha(filename_to_hex(filename)) - obj._needs_parsing = True - obj._needs_serialization = True - return obj - except (IndexError, ValueError), e: - raise ObjectFormatException("invalid object header") + obj = cls.from_file(f) + obj._sha = FixedSha(filename_to_hex(path)) + return obj   finally:   f.close() + + @classmethod + def from_file(cls, f): + """Get the contents of a SHA file on disk.""" + try: + obj = cls._parse_file_header(f) + obj._sha = None + obj._needs_parsing = True + obj._needs_serialization = True + return obj + except (IndexError, ValueError), e: + raise ObjectFormatException("invalid object header")     @staticmethod   def from_raw_string(type_num, string): @@ -491,10 +497,10 @@
  "The text within the blob object, as chunks (not necessarily lines).")     @classmethod - def from_file(cls, filename): - blob = ShaFile.from_file(filename) + def from_path(cls, path): + blob = ShaFile.from_path(path)   if not isinstance(blob, cls): - raise NotBlobError(filename) + raise NotBlobError(path)   return blob     def check(self): @@ -539,8 +545,8 @@
  self._tag_timezone_neg_utc = False     @classmethod - def from_file(cls, filename): - tag = ShaFile.from_file(filename) + def from_path(cls, filename): + tag = ShaFile.from_path(filename)   if not isinstance(tag, cls):   raise NotTagError(filename)   return tag @@ -625,7 +631,7 @@
  elif field is None:   self._message = value   else: - raise ObjectFormatError("Unknown field %s" % field) + raise ObjectFormatException("Unknown field %s" % field)     def _get_object(self):   """Get the object pointed to by this tag. @@ -711,8 +717,8 @@
  self._entries = {}     @classmethod - def from_file(cls, filename): - tree = ShaFile.from_file(filename) + def from_path(cls, filename): + tree = ShaFile.from_path(filename)   if not isinstance(tree, cls):   raise NotTreeError(filename)   return tree @@ -860,10 +866,10 @@
  self._commit_timezone_neg_utc = False     @classmethod - def from_file(cls, filename): - commit = ShaFile.from_file(filename) + def from_path(cls, path): + commit = ShaFile.from_path(path)   if not isinstance(commit, cls): - raise NotCommitError(filename) + raise NotCommitError(path)   return commit     def _deserialize(self, chunks):
 
104
105
106
107
 
108
109
110
 
424
425
426
427
 
428
429
430
 
104
105
106
 
107
108
109
110
 
424
425
426
 
427
428
429
430
@@ -104,7 +104,7 @@
    def get_sha_file(self, cls, base, sha):   dir = os.path.join(os.path.dirname(__file__), 'data', base) - return cls.from_file(hex_to_filename(dir, sha)) + return cls.from_path(hex_to_filename(dir, sha))     def get_blob(self, sha):   """Return the blob named sha from the test data dir""" @@ -424,7 +424,7 @@
    def _do_test_parse_tree(self, parse_tree):   dir = os.path.join(os.path.dirname(__file__), 'data', 'trees') - o = Tree.from_file(hex_to_filename(dir, tree_sha)) + o = Tree.from_path(hex_to_filename(dir, tree_sha))   o._parse_file()   self.assertEquals([('a', 0100644, a_sha), ('b', 0100644, b_sha)],   list(parse_tree(o.as_raw_string())))