]> arthur.barton.de Git - bup.git/commitdiff
vfs: supply ctime/mtime for the root of each commit.
authorAvery Pennarun <apenwarr@gmail.com>
Sun, 28 Feb 2010 22:28:01 +0000 (17:28 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Sun, 28 Feb 2010 22:49:10 +0000 (17:49 -0500)
This makes it a little more obvious which backups were made when.

Mostly useful with 'bup fuse'.

cmd/fuse-cmd.py
lib/bup/git.py
lib/bup/vfs.py

index ffcd036ffffd275ebfd73aad7b30f8d448d6cf39..c1d9f128b1528744d313d6ae4cbf46e96feed89c 100755 (executable)
@@ -56,6 +56,9 @@ class BupFs(fuse.Fuse):
             st.st_mode = node.mode
             st.st_nlink = node.nlinks()
             st.st_size = node.size()
+            st.st_mtime = node.mtime
+            st.st_ctime = node.ctime
+            st.st_atime = node.atime
             return st
         except vfs.NoSuchFile:
             return -errno.ENOENT
index 77e90bfc40f5433b0b714965340628007b7d19be..c755dc5c0f6fac88d4af5c198953505ce282a739 100644 (file)
@@ -497,9 +497,12 @@ def read_ref(refname):
         return None
 
 
-def rev_list(ref):
+def rev_list(ref, count=None):
     assert(not ref.startswith('-'))
-    argv = ['git', 'rev-list', '--pretty=format:%ct', ref, '--']
+    opts = []
+    if count:
+        opts += ['-n', str(atoi(count))]
+    argv = ['git', 'rev-list', '--pretty=format:%ct'] + opts + [ref, '--']
     p = subprocess.Popen(argv, preexec_fn = _gitenv, stdout = subprocess.PIPE)
     commit = None
     for row in p.stdout:
@@ -514,6 +517,12 @@ def rev_list(ref):
         raise GitError, 'git rev-list returned error %d' % rv
 
 
+def rev_get_date(ref):
+    for (date, commit) in rev_list(ref, count=1):
+        return date
+    raise GitError, 'no such commit %r' % ref
+
+
 def update_ref(refname, newval, oldval):
     if not oldval:
         oldval = ''
index efa094793143ca8562773000391fe5f0398b0d8e..80e3c1daa6d54778747209aedebc5f6832e01787 100644 (file)
@@ -54,6 +54,7 @@ class Node:
         self.name = name
         self.mode = mode
         self.hash = hash
+        self.ctime = self.mtime = self.atime = 0
         self._subs = None
         
     def __cmp__(a, b):
@@ -219,14 +220,19 @@ class CommitList(Node):
         for (date, commit) in revs:
             l = time.localtime(date)
             ls = time.strftime('%Y-%m-%d-%H%M%S', l)
-            commithex = commit.encode('hex')
-            self._subs[commithex] = Dir(self, commithex, 040000, commit)
-            self._subs[ls] = FakeSymlink(self, ls, commit.encode('hex'))
+            commithex = '.' + commit.encode('hex')
+            n1 = Dir(self, commithex, 040000, commit)
+            n2 = FakeSymlink(self, ls, commithex)
+            n1.ctime = n1.mtime = n2.ctime = n2.mtime = date
+            self._subs[commithex] = n1
+            self._subs[ls] = n2
             latest = max(revs)
         if latest:
             (date, commit) = latest
-            self._subs['latest'] = FakeSymlink(self, 'latest',
-                                               commit.encode('hex'))
+            commithex = '.' + commit.encode('hex')
+            n2 = FakeSymlink(self, 'latest', commithex)
+            n2.ctime = n2.mtime = date
+            self._subs['latest'] = n2
 
     
 class RefList(Node):
@@ -238,6 +244,9 @@ class RefList(Node):
         for (name,sha) in git.list_refs():
             if name.startswith('refs/heads/'):
                 name = name[11:]
-                self._subs[name] = CommitList(self, name, sha)
+                date = git.rev_get_date(sha.encode('hex'))
+                n1 = CommitList(self, name, sha)
+                n1.ctime = n1.mtime = date
+                self._subs[name] = n1