From: Rob Browning Date: Sat, 31 Mar 2018 19:42:07 +0000 (-0500) Subject: walk_object: accept a get function instead of catpipe X-Git-Tag: 0.30~38 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=17f54bbc5ec73bbd341a2ac56e026f62b2f50714 walk_object: accept a get function instead of catpipe This will be needed by upcoming changes to the repo classes. Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/gc.py b/lib/bup/gc.py index 5a351f5..7491b5b 100644 --- a/lib/bup/gc.py +++ b/lib/bup/gc.py @@ -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 diff --git a/lib/bup/git.py b/lib/bup/git.py index 8b37e61..45fab04 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -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'))