]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/vfs.py
vfs: include unique repo id in resolution cache key
[bup.git] / lib / bup / vfs.py
index bb0bfb70fc13f6d569864e01a560a2ae87bc21c4..e0aeb6ff9c0236790785224486b989299ce77216 100644 (file)
@@ -253,7 +253,7 @@ def clear_cache():
 def is_valid_cache_key(x):
     """Return logically true if x looks like it could be a valid cache key
     (with respect to structure).  Current valid cache entries:
-      (path, parent, want_meta, dref) -> resolution
+      (repo-id, path, parent, want_meta, dref) -> resolution
       commit_oid -> commit
       commit_oid + ':r' -> rev-list
          i.e. rev-list -> {'.', commit, '2012...', next_commit, ...}
@@ -261,7 +261,7 @@ def is_valid_cache_key(x):
     # Suspect we may eventually add "(container_oid, name) -> ...", and others.
     x_t = type(x)
     if x_t is tuple:
-        return len(x) == 4
+        return len(x) == 5
     if x_t is bytes:
         if len(x) == 20:
             return True
@@ -734,24 +734,19 @@ def contents(repo, item, names=None, want_meta=True):
     assert repo
     assert S_ISDIR(item_mode(item))
     item_t = type(item)
-
     if item_t in real_tree_types:
         it = repo.cat(item.oid.encode('hex'))
-        _, obj_type, size = next(it)
+        _, obj_t, size = next(it)
         data = ''.join(it)
-        if obj_type == 'tree':
-            if want_meta:
-                item_gen = tree_items_with_meta(repo, item.oid, data, names)
-            else:
-                item_gen = tree_items(item.oid, data, names)
-        elif obj_type == 'commit':
-            if want_meta:
-                item_gen = tree_items_with_meta(repo, item.oid, tree_data, names)
-            else:
-                item_gen = tree_items(item.oid, tree_data, names)
-        else:
+        if obj_t != 'tree':
             for _ in it: pass
-            raise Exception('unexpected git ' + obj_type)
+            # Note: it shouldn't be possible to see an Item with type
+            # 'commit' since a 'commit' should always produce a Commit.
+            raise Exception('unexpected git ' + obj_t)
+        if want_meta:
+            item_gen = tree_items_with_meta(repo, item.oid, data, names)
+        else:
+            item_gen = tree_items(item.oid, data, names)
     elif item_t == RevList:
         item_gen = revlist_items(repo, item.oid, names)
     elif item_t == Root:
@@ -764,7 +759,7 @@ def contents(repo, item, names=None, want_meta=True):
         yield x
 
 def _resolve_path(repo, path, parent=None, want_meta=True, deref=False):
-    cache_key = (tuple(path), parent, not not want_meta, not not deref)
+    cache_key = (repo.id(), tuple(path), parent, bool(want_meta), bool(deref))
     resolution = cache_get(cache_key)
     if resolution:
         return resolution