2 import os, sys, stat, time
3 import options, git, index, drecurse
7 def merge_indexes(out, r1, r2):
8 log('bup: merging indexes.\n')
9 for e in index._last_writer_wins_iter([r1, r2]):
10 #if e.flags & index.IX_EXISTS:
15 def __init__(self, l):
22 self.cur = self.i.next()
28 def update_index(top):
29 ri = index.Reader(indexfile)
30 wi = index.Writer(indexfile)
31 rig = IterHelper(ri.iter(name=top))
32 tstart = int(time.time())
37 return (0, index.FAKE_SHA)
39 #log('doing: %r\n' % paths)
41 for (path,pst) in drecurse.recursive_dirlist([top], xdev=opt.xdev):
42 #log('got: %r\n' % path)
43 if opt.verbose>=2 or (opt.verbose==1 and stat.S_ISDIR(pst.st_mode)):
44 sys.stdout.write('%s\n' % path)
46 while rig.cur and rig.cur.name > path: # deleted paths
50 if rig.cur and rig.cur.name == path: # paths that already existed
52 rig.cur.from_stat(pst, tstart)
53 if not (rig.cur.flags & index.IX_HASHVALID):
55 (rig.cur.gitmode, rig.cur.sha) = hashgen(path)
56 rig.cur.flags |= index.IX_HASHVALID
60 #log('adding: %r\n' % path)
61 wi.add(path, pst, hashgen = hashgen)
67 mi = index.Writer(indexfile)
68 merge_indexes(mi, ri, wi.new_reader())
77 bup index <-p|s|m|u> [options...] <filenames...>
79 p,print print the index entries for the given names (also works with -u)
80 m,modified print only added/deleted/modified files (implies -p)
81 s,status print each filename with a status char (A/M/D) (implies -p)
82 H,hash print the hash for each object next to its name (implies -p)
83 u,update (recursively) update the index entries for the given filenames
84 x,xdev,one-file-system don't cross filesystem boundaries
85 fake-valid mark all index entries as up-to-date even if they aren't
86 f,indexfile= the name of the index file (default 'index')
87 v,verbose increase log output (can be used more than once)
89 o = options.Options('bup index', optspec)
90 (opt, flags, extra) = o.parse(sys.argv[1:])
92 if not (opt.modified or opt['print'] or opt.status or opt.update):
93 log('bup index: you must supply one or more of -p, -s, -m, or -u\n')
95 if opt.fake_valid and not opt.update:
96 log('bup index: --fake-valid is meaningless without -u\n')
99 git.check_repo_or_die()
100 indexfile = opt.indexfile or git.repo('bupindex')
102 paths = index.reduce_paths(extra)
106 log('bup index: update (-u) requested but no paths given\n')
108 for (rp,path) in paths:
111 if opt['print'] or opt.status or opt.modified:
112 for (name, ent) in index.Reader(indexfile).filter(extra or ['']):
113 if opt.modified and (ent.flags & index.IX_HASHVALID
114 or stat.S_ISDIR(ent.mode)):
118 if not ent.flags & index.IX_EXISTS:
120 elif not ent.flags & index.IX_HASHVALID:
121 if ent.sha == index.EMPTY_SHA:
128 line += ent.sha.encode('hex') + ' '
129 print line + (name or './')
133 log('WARNING: %d errors encountered.\n' % len(saved_errors))