]> arthur.barton.de Git - bup.git/commitdiff
Move VFS cp() to git.py; handle repodir changes
authorRob Browning <rlb@defaultvalue.org>
Wed, 21 May 2014 02:40:51 +0000 (21:40 -0500)
committerRob Browning <rlb@defaultvalue.org>
Wed, 21 May 2014 16:45:05 +0000 (11:45 -0500)
Move the VFS's cp() to git.py and reset the cp() CatPipe whenever the
global repodir changes.

Previously, if two different lib/bup/t/ tests (for example) needed to
use two different repositories, and both happened to indirectly call
cp(), the second test would end up with a CatPipe() connected to the
wrong repository.

In the longer run, we may want to consider further cleanup here, but
this should fix the immediate problem without too much risk.

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

index 314a5b3956a59bbd9602d93da771aee865d674f5..50a7bf1346d5ee91424b1c8c16aa9e1dddf78843 100644 (file)
@@ -1065,6 +1065,20 @@ class CatPipe:
         except StopIteration:
             log('booger!\n')
 
+
+_cp = (None, None)
+
+def cp():
+    """Create a CatPipe object or reuse an already existing one."""
+    global _cp
+    cp_dir, cp = _cp
+    cur_dir = os.path.realpath(repo())
+    if cur_dir != cp_dir:
+        cp = CatPipe()
+        _cp = (cur_dir, cp)
+    return cp
+
+
 def tags():
     """Return a dictionary of all tags in the form {hash: [tag_names, ...]}."""
     tags = {}
index 301d14572ef6ae5e3817f3ae4d0c791b35bf56ba..9e2d560629f1292995518061b1b525e35bc0e2b1 100644 (file)
@@ -6,18 +6,11 @@ and abstracts internal name mangling and storage from the exposition layer.
 import os, re, stat, time
 from bup import git, metadata
 from helpers import *
-from bup.git import BUP_NORMAL, BUP_CHUNKED
+from bup.git import BUP_NORMAL, BUP_CHUNKED, cp
 from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE
 
 EMPTY_SHA='\0'*20
 
-_cp = None
-def cp():
-    """Create a git.CatPipe object or reuse the already existing one."""
-    global _cp
-    if not _cp:
-        _cp = git.CatPipe()
-    return _cp
 
 class NodeError(Exception):
     """VFS base exception."""