Signed-off-by: Stefan Buller <
stefan...@gmail.com>
---
lib/bup/vfs.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 50 insertions(+), 6 deletions(-)
diff --git a/lib/bup/vfs.py b/lib/bup/vfs.py
index 4543553..7026b4d 100644
--- a/lib/bup/vfs.py
+++ b/lib/bup/vfs.py
@@ -96,6 +96,11 @@ def _chunkiter(hash, startofs):
else:
yield ''.join(cp().join(sha.encode('hex')))[skipmore:]
+def _depth(node):
+ if node.parent == None:
+ return 0
+ else:
+ return _depth(node.parent) + 1
class _ChunkReader:
def __init__(self, hash, isdir, startofs):
@@ -459,11 +464,36 @@ class TagDir(Node):
name = name[10:]
date = git.rev_get_date(sha.encode('hex'))
commithex = sha.encode('hex')
- target = '../.commit/%s/%s' % (commithex[:2], commithex[2:])
+ commitdir = ('../' * _depth(self)) + '.commit/'
+ target = commitdir + '%s/%s' % (commithex[:2], commithex[2:])
tag1 = FakeSymlink(self, name, target)
tag1.ctime = tag1.mtime = date
self._subs[name] = tag1
+class BranchDir(Node):
+ """A directory that represents part of a ref name"""
+ def __init__(self, parent, name):
+ Node.__init__(self, parent, name, GIT_MODE_TREE, EMPTY_SHA)
+ self.subitems = []
+
+ def _mksubs(self):
+ self._subs = {}
+ for (name, date, sha) in self.subitems:
+ parts = name.split('/')
+ head = parts[0]
+ rest = parts[1:]
+ if not rest:
+ n1 = BranchList(self, name, sha)
+ n1.ctime = n1.mtime = date
+ self._subs[name] = n1
+ else:
+ n1 = self._subs.get(head)
+ if not n1:
+ n1 = BranchDir(self, head)
+ self._subs[head] = n1
+ else:
+ pass
+ n1.subitems.append(rest)
class BranchList(Node):
"""A list of links to commits reachable by a branch in bup's repository.
@@ -484,7 +514,8 @@ class BranchList(Node):
l = time.localtime(date)
ls = time.strftime('%Y-%m-%d-%H%M%S', l)
commithex = commit.encode('hex')
- target = '../.commit/%s/%s' % (commithex[:2], commithex[2:])
+ commitdir = ('../' * _depth(self)) + '.commit/'
+ target = commitdir + '%s/%s' % (commithex[:2], commithex[2:])
n1 = FakeSymlink(self, ls, target)
n1.ctime = n1.mtime = date
self._subs[ls] = n1
@@ -498,7 +529,8 @@ class BranchList(Node):
if latest:
(date, commit) = latest
commithex = commit.encode('hex')
- target = '../.commit/%s/%s' % (commithex[:2], commithex[2:])
+ commitdir = ('../' * _depth(self)) + '.commit/'
+ target = commitdir + '%s/%s' % (commithex[:2], commithex[2:])
n1 = FakeSymlink(self, 'latest', target)
n1.ctime = n1.mtime = date
self._subs['latest'] = n1
@@ -529,6 +561,18 @@ class RefList(Node):
if name.startswith('refs/heads/'):
name = name[11:]
date = git.rev_get_date(sha.encode('hex'))
- n1 = BranchList(self, name, sha)
- n1.ctime = n1.mtime = date
- self._subs[name] = n1
+ parts = name.split('/')
+ head = parts[0]
+ rest = parts[1:]
+ if not rest:
+ n1 = BranchList(self, name, sha)
+ n1.ctime = n1.mtime = date
+ self._subs[name] = n1
+ else:
+ n1 = self._subs.get(head)
+ if not n1:
+ n1 = BranchDir(self, head)
+ self._subs[head] = n1
+ else:
+ pass
+ n1.subitems.append( ("/".join(rest), date, sha) )
--
1.7.9.5