From: Avery Pennarun Date: Thu, 7 Jan 2010 23:54:40 +0000 (-0500) Subject: cmd-index: eliminate redundant paths from index update command. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=1d9d61078a7c82112636fea81db9134930cfb8ae;p=packages%2Fb%2Fbup.git cmd-index: eliminate redundant paths from index update command. 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. --- diff --git a/cmd-index.py b/cmd-index.py index 19426db..9aa2757 100755 --- a/cmd-index.py +++ b/cmd-index.py @@ -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: