36 dump <file> [rev] dump the latest or given revision of a file |
36 dump <file> [rev] dump the latest or given revision of a file |
37 dumpmanifest [rev] dump the latest or given revision of the manifest |
37 dumpmanifest [rev] dump the latest or given revision of the manifest |
38 diff [files...] diff working directory (or selected files) |
38 diff [files...] diff working directory (or selected files) |
39 """ |
39 """ |
40 |
40 |
41 def diffdir(node, files = None): |
41 def filterfiles(list, files): |
42 (c, a, d) = repo.diffdir(repo.root, node) |
42 l = [ x for x in list if x in files ] |
43 |
43 |
44 if args: |
44 for f in files: |
45 nc = [ x for x in c if x in args ] |
45 if f[-1] != os.sep: f += os.sep |
46 na = [ x for x in a if x in args ] |
46 l += [ x for x in list if x.startswith(f) ] |
47 nd = [ x for x in d if x in args ] |
47 return l |
48 for arg in args: |
|
49 if not os.path.isdir(arg): continue |
|
50 if arg[-1] != os.sep: arg += os.sep |
|
51 nc += [ x for x in c if x.startswith(arg) ] |
|
52 na += [ x for x in a if x.startswith(arg) ] |
|
53 nd += [ x for x in d if x.startswith(arg) ] |
|
54 (c, a, d) = (nc, na, nd) |
|
55 |
|
56 return (c, a, d) |
|
57 |
|
58 |
48 |
59 options = {} |
49 options = {} |
60 opts = [('v', 'verbose', None, 'verbose'), |
50 opts = [('v', 'verbose', None, 'verbose'), |
61 ('d', 'debug', None, 'debug')] |
51 ('d', 'debug', None, 'debug')] |
62 |
52 |
128 files = f.read().splitlines() |
118 files = f.read().splitlines() |
129 f.close() |
119 f.close() |
130 repo.commit(files) |
120 repo.commit(files) |
131 |
121 |
132 elif cmd == "status": |
122 elif cmd == "status": |
133 (c, a, d) = diffdir(repo.current) |
123 (c, a, d) = repo.diffdir(repo.root, repo.current) |
134 for f in c: print "C", f |
124 for f in c: print "C", f |
135 for f in a: print "?", f |
125 for f in a: print "?", f |
136 for f in d: print "R", f |
126 for f in d: print "R", f |
137 |
127 |
138 elif cmd == "diff": |
128 elif cmd == "diff": |
139 (c, a, d) = diffdir(repo.current, args) |
129 doptions = {} |
140 |
130 revs = [repo.current] |
141 mmap = {} |
131 |
142 if repo.current: |
132 if args: |
143 change = repo.changelog.read(repo.current) |
133 opts = [('r', 'revision', [], 'revision')] |
144 mmap = repo.manifest.read(change[0]) |
134 args = fancyopts.fancyopts(args, opts, doptions, |
|
135 'hg diff [options] [files]') |
|
136 # revs = [ repo.lookup(x) for x in doptions['revision'] ] |
|
137 revs = [hg.bin(x) for x in doptions['revision']] |
|
138 |
|
139 if len(revs) > 2: |
|
140 print "too many revisions to diff" |
|
141 sys.exit(1) |
|
142 elif len(revs) == 2: |
|
143 change = repo.changelog.read(revs[1]) |
|
144 mmap2 = repo.manifest.read(change[0]) |
|
145 (c, a, d) = repo.diffrevs(revs[0], revs[1]) |
|
146 def read(f): return repo.file(f).read(mmap2[f]) |
|
147 else: |
|
148 if len(revs) < 1: |
|
149 if not repo.current: |
|
150 sys.exit(0) |
|
151 (c, a, d) = repo.diffdir(repo.root, revs[0]) |
|
152 def read(f): return file(f).read() |
|
153 |
|
154 change = repo.changelog.read(revs[0]) |
|
155 mmap = repo.manifest.read(change[0]) |
|
156 |
|
157 if args: |
|
158 c = filterfiles(c, args) |
|
159 a = filterfiles(a, args) |
|
160 d = filterfiles(d, args) |
145 |
161 |
146 for f in c: |
162 for f in c: |
147 to = repo.file(f).read(mmap[f]) |
163 to = repo.file(f).read(mmap[f]) |
148 tn = file(f).read() |
164 tn = read(f) |
149 sys.stdout.write(mdiff.unidiff(to, tn, f)) |
165 sys.stdout.write(mdiff.unidiff(to, tn, f)) |
150 for f in a: |
166 for f in a: |
151 to = "" |
167 to = "" |
152 tn = file(f).read() |
168 tn = read(f) |
153 sys.stdout.write(mdiff.unidiff(to, tn, f)) |
169 sys.stdout.write(mdiff.unidiff(to, tn, f)) |
154 for f in d: |
170 for f in d: |
155 to = repo.file(f).read(mmap[f]) |
171 to = repo.file(f).read(mmap[f]) |
156 tn = "" |
172 tn = "" |
157 sys.stdout.write(mdiff.unidiff(to, tn, f)) |
173 sys.stdout.write(mdiff.unidiff(to, tn, f)) |