]> arthur.barton.de Git - bup.git/commitdiff
walk_object: accept a get function instead of catpipe
authorRob Browning <rlb@defaultvalue.org>
Sat, 31 Mar 2018 19:42:07 +0000 (14:42 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 13 Jan 2019 18:09:13 +0000 (12:09 -0600)
This will be needed by upcoming changes to the repo classes.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/gc.py
lib/bup/git.py

index 5a351f579750790968e547795b9d54b84dcc4d62..7491b5bc31151a9a5db1d78ab609bd2fae8e1341 100644 (file)
@@ -105,7 +105,7 @@ def find_live_objects(existing_count, cat_pipe, verbosity=0):
         stop_at = lambda x: x.decode('hex') in trees_visited
     approx_live_count = 0
     for ref_name, ref_id in git.list_refs():
-        for item in walk_object(cat_pipe, ref_id.encode('hex'),
+        for item in walk_object(cat_pipe.get, ref_id.encode('hex'),
                                 stop_at=stop_at,
                                 include_data=None):
             # FIXME: batch ids
index 8b37e616ccb5fa19841c626c78373f13bb2d1f11..45fab04ad7470edb0320a31227fd4a0a26c1daf6 100644 (file)
@@ -1302,14 +1302,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 +1328,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'))