示例#1
0
 def iterentries(self, ext_resolve_ref=None):
   found = {}
   at = {}
   postponed = defaultdict(list)
   class Postpone(Exception):
       """Raised to postpone delta resolving."""
       
   def get_ref_text(sha):
       if sha in found:
           return found[sha]
       if ext_resolve_ref:
           try:
               return ext_resolve_ref(sha)
           except KeyError:
               pass
       raise Postpone, (sha, )
   todo = list(self.iterobjects())
   while todo:
     (offset, type, obj) = todo.pop(0)
     at[offset] = (type, obj)
     assert isinstance(offset, int)
     assert isinstance(type, int)
     assert isinstance(obj, tuple) or isinstance(obj, str)
     try:
       type, obj = resolve_object(offset, type, obj, get_ref_text,
           at.__getitem__)
     except Postpone, (sha, ):
       postponed[sha].append((offset, type, obj))
     else:
       shafile = ShaFile.from_raw_string(type, obj)
       sha = shafile.sha().digest()
       found[sha] = (type, obj)
       yield sha, offset, shafile.crc32()
       todo += postponed.get(sha, [])
示例#2
0
文件: pack.py 项目: SRabbelier/hg-git
 def iterentries(self, ext_resolve_ref=None, progress=None):
     found = {}
     postponed = defaultdict(list)
     class Postpone(Exception):
         """Raised to postpone delta resolving."""
       
     def get_ref_text(sha):
         assert len(sha) == 20
         if sha in found:
             return self.get_object_at(found[sha])
         if ext_resolve_ref:
             try:
                 return ext_resolve_ref(sha)
             except KeyError:
                 pass
         raise Postpone, (sha, )
     extra = []
     todo = chain(self.iterobjects(progress=progress), extra)
     for (offset, type, obj, crc32) in todo:
         assert isinstance(offset, int)
         assert isinstance(type, int)
         assert isinstance(obj, tuple) or isinstance(obj, str)
         try:
             type, obj = self.resolve_object(offset, type, obj, get_ref_text)
         except Postpone, (sha, ):
             postponed[sha].append((offset, type, obj))
         else:
             shafile = ShaFile.from_raw_string(type, obj)
             sha = shafile.sha().digest()
             found[sha] = offset
             yield sha, offset, crc32
             extra.extend(postponed.get(sha, []))
示例#3
0
 def __getitem__(self, sha):
     assert len(sha) == 40, "Incorrect length sha: %s" % str(sha)
     ret = self._get_shafile(sha)
     if ret is not None:
         return ret
     # Check from packs
     type, uncomp = self.get_raw(sha)
     return ShaFile.from_raw_string(type, uncomp)
示例#4
0
 def _get_shafile(self, sha):
     dir = sha[:2]
     file = sha[2:]
     # Check from object dir
     path = os.path.join(self.path, dir, file)
     if os.path.exists(path):
       return ShaFile.from_file(path)
     return None
示例#5
0
文件: pack.py 项目: SRabbelier/hg-git
 def iterobjects(self, get_raw=None):
     """Iterate over the objects in this pack."""
     if get_raw is None:
         get_raw = self.get_raw
     for offset, type, obj, crc32 in self.data.iterobjects():
         assert isinstance(offset, int)
         yield ShaFile.from_raw_string(
                 *self.data.resolve_object(offset, type, obj, get_raw))
示例#6
0
 def iterobjects(self, get_raw=None):
     if get_raw is None:
         def get_raw(x):
             raise KeyError(x)
     for offset, type, obj in self.data.iterobjects():
         assert isinstance(offset, int)
         yield ShaFile.from_raw_string(
                 *resolve_object(offset, type, obj, 
                     get_raw, 
                 self.data.get_object_at))
示例#7
0
 def __getitem__(self, sha):
     """Obtain an object by SHA1."""
     type, uncomp = self.get_raw(sha)
     return ShaFile.from_raw_string(type, uncomp)
示例#8
0
 def _get_shafile(self, sha):
     path = self._get_shafile_path(sha)
     if os.path.exists(path):
       return ShaFile.from_file(path)
     return None
示例#9
0
 def __getitem__(self, sha1):
     """Retrieve the specified SHA1."""
     type, uncomp = self.get_raw(sha1)
     return ShaFile.from_raw_string(type, uncomp)