]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/git.py
Add bup get; see the documentation for further information
[bup.git] / lib / bup / git.py
index 8b37e616ccb5fa19841c626c78373f13bb2d1f11..73dce1914571adbe0be965c89c8ae4278329b4f4 100644 (file)
@@ -112,13 +112,14 @@ def parse_commit(content):
                       message=matches['message'])
 
 
-def get_commit_items(id, cp):
-    commit_it = cp.get(id)
-    _, typ, _ = next(commit_it)
-    assert(typ == 'commit')
-    commit_content = ''.join(commit_it)
-    return parse_commit(commit_content)
+def get_cat_data(cat_iterator, expected_type):
+    _, kind, _ = next(cat_iterator)
+    if kind != expected_type:
+        raise Exception('expected %r, saw %r' % (expected_type, kind))
+    return ''.join(cat_iterator)
 
+def get_commit_items(id, cp):
+    return parse_commit(get_cat_data(cp.get(id), 'commit'))
 
 def _local_git_date_str(epoch_sec):
     return '%d %s' % (epoch_sec, utc_offset_str(epoch_sec))
@@ -1302,14 +1303,13 @@ WalkItem = namedtuple('WalkItem', ['oid', 'type', 'mode',
 #   ...
 
 
-def walk_object(cat_pipe, oidx,
-                stop_at=None,
-                include_data=None):
-    """Yield everything reachable from oidx via cat_pipe as a WalkItem,
-    stopping whenever stop_at(oidx) returns true.  Throw MissingObject
-    if a hash encountered is missing from the repository, and don't
-    read or return blob content in the data field unless include_data
-    is set.
+def walk_object(get_ref, oidx, stop_at=None, include_data=None):
+    """Yield everything reachable from oidx via get_ref (which must behave
+    like CatPipe get) as a WalkItem, stopping whenever stop_at(oidx)
+    returns true.  Throw MissingObject if a hash encountered is
+    missing from the repository, and don't read or return blob content
+    in the data field unless include_data is set.
+
     """
     # Maintain the pending stack on the heap to avoid stack overflow
     pending = [(oidx, [], [], None)]
@@ -1329,7 +1329,7 @@ def walk_object(cat_pipe, oidx,
                            data=None)
             continue
 
-        item_it = cat_pipe.get(oidx)
+        item_it = get_ref(oidx)
         get_oidx, typ, _ = next(item_it)
         if not get_oidx:
             raise MissingObject(oidx.decode('hex'))