]> arthur.barton.de Git - bup.git/commitdiff
cmd-index: eliminate redundant paths from index update command.
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 7 Jan 2010 23:54:40 +0000 (18:54 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Fri, 8 Jan 2010 22:56:57 +0000 (17:56 -0500)
If someone asks to update "/etc" and "/etc/passwd", the latter is redundant
because it's included in the first.  Don't bother updating the file twice
(and thus causing two index merges, etc).

Ideally we would only do one merge for *any* number of updates (etc /etc and
/var).  This should be possible as long as we sort the entries correctly
(/var/ and then /etc/), since a single sequential indexfile could just have
one appended to the other.  But we don't do that yet.

cmd-index.py

index 19426db4fa06b7386712d78a15b960a0cf3188ad..9aa275725a2ea90253250b66519c2ef9742a661e 100755 (executable)
@@ -274,9 +274,11 @@ class MergeGetter:
         return self.cur
 
 
-def update_index(path):
+def update_index(paths):
     ri = IndexReader(indexfile)
     wi = IndexWriter(indexfile)
+    rig = MergeGetter(ri)
+    
     rpath = os.path.realpath(path)
     st = os.lstat(rpath)
     if opt.xdev:
@@ -291,7 +293,6 @@ def update_index(path):
         dir += '/'
     if stat.S_ISDIR(st.st_mode) and (not rpath or rpath[-1] != '/'):
         name += '/'
-    rig = MergeGetter(ri)
     OsFile(dir or '/').fchdir()
     dirty = handle_path(rig, wi, dir, name, st, xdev)
 
@@ -341,7 +342,22 @@ o = options.Options('bup index', optspec)
 
 indexfile = opt.indexfile or 'index'
 
+xpaths = []
 for path in extra:
+    rp = os.path.realpath(path)
+    st = os.lstat(rp)
+    if stat.S_ISDIR(st.st_mode) and not rp.endswith('/'):
+        rp += '/'
+    xpaths.append(rp)
+
+paths = []
+for path in reversed(sorted(xpaths)):
+    if paths and path.endswith('/') and paths[-1].startswith(path):
+        paths[-1] = path
+    else:
+        paths.append(path)
+
+for path in paths:
     update_index(path)
 
 if opt.fake_valid and not extra: