Show More
@@ -1,410 +1,428 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # mercurial - a minimal scalable distributed SCM |
|
3 | # mercurial - a minimal scalable distributed SCM | |
4 | # v0.4f "jane dark" |
|
4 | # v0.4f "jane dark" | |
5 | # |
|
5 | # | |
6 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
6 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
7 | # |
|
7 | # | |
8 | # This software may be used and distributed according to the terms |
|
8 | # This software may be used and distributed according to the terms | |
9 | # of the GNU General Public License, incorporated herein by reference. |
|
9 | # of the GNU General Public License, incorporated herein by reference. | |
10 |
|
10 | |||
11 | # the psyco compiler makes commits a bit faster |
|
11 | # the psyco compiler makes commits a bit faster | |
12 | # and makes changegroup merge about 20 times slower! |
|
12 | # and makes changegroup merge about 20 times slower! | |
13 | # try: |
|
13 | # try: | |
14 | # import psyco |
|
14 | # import psyco | |
15 | # psyco.full() |
|
15 | # psyco.full() | |
16 | # except: |
|
16 | # except: | |
17 | # pass |
|
17 | # pass | |
18 |
|
18 | |||
19 | import sys, os, time |
|
19 | import sys, os, time | |
20 | from mercurial import hg, mdiff, fancyopts |
|
20 | from mercurial import hg, mdiff, fancyopts | |
21 |
|
21 | |||
22 | def help(): |
|
22 | def help(): | |
23 | print """\ |
|
23 | print """\ | |
24 | commands: |
|
24 | commands: | |
25 |
|
25 | |||
26 | init create a new repository in this directory |
|
26 | init create a new repository in this directory | |
27 | branch <path> create a branch of <path> in this directory |
|
27 | branch <path> create a branch of <path> in this directory | |
28 | merge <path> merge changes from <path> into local repository |
|
28 | merge <path> merge changes from <path> into local repository | |
29 | checkout [changeset] checkout the latest or given changeset |
|
29 | checkout [changeset] checkout the latest or given changeset | |
30 | status show new, missing, and changed files in working dir |
|
30 | status show new, missing, and changed files in working dir | |
31 | add [files...] add the given files in the next commit |
|
31 | add [files...] add the given files in the next commit | |
32 | remove [files...] remove the given files in the next commit |
|
32 | remove [files...] remove the given files in the next commit | |
33 | addremove add all new files, delete all missing files |
|
33 | addremove add all new files, delete all missing files | |
34 | commit commit all changes to the repository |
|
34 | commit commit all changes to the repository | |
35 | history show changeset history |
|
35 | history show changeset history | |
36 | log <file> show revision history of a single file |
|
36 | log <file> show revision history of a single file | |
37 | dump <file> [rev] dump the latest or given revision of a file |
|
37 | dump <file> [rev] dump the latest or given revision of a file | |
38 | dumpmanifest [rev] dump the latest or given revision of the manifest |
|
38 | dumpmanifest [rev] dump the latest or given revision of the manifest | |
39 | diff [files...] diff working directory (or selected files) |
|
39 | diff [files...] diff working directory (or selected files) | |
40 | tags show current changeset tags |
|
40 | tags show current changeset tags | |
41 | """ |
|
41 | """ | |
42 |
|
42 | |||
43 | def filterfiles(list, files): |
|
43 | def filterfiles(list, files): | |
44 | l = [ x for x in list if x in files ] |
|
44 | l = [ x for x in list if x in files ] | |
45 |
|
45 | |||
46 | for f in files: |
|
46 | for f in files: | |
47 | if f[-1] != os.sep: f += os.sep |
|
47 | if f[-1] != os.sep: f += os.sep | |
48 | l += [ x for x in list if x.startswith(f) ] |
|
48 | l += [ x for x in list if x.startswith(f) ] | |
49 | return l |
|
49 | return l | |
50 |
|
50 | |||
51 | def diff(files = None, node1 = None, node2 = None): |
|
51 | def diff(files = None, node1 = None, node2 = None): | |
52 | def date(c): |
|
52 | def date(c): | |
53 | return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
|
53 | return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) | |
54 |
|
54 | |||
55 | if node2: |
|
55 | if node2: | |
56 | change = repo.changelog.read(node2) |
|
56 | change = repo.changelog.read(node2) | |
57 | mmap2 = repo.manifest.read(change[0]) |
|
57 | mmap2 = repo.manifest.read(change[0]) | |
58 | (c, a, d) = repo.diffrevs(node1, node2) |
|
58 | (c, a, d) = repo.diffrevs(node1, node2) | |
59 | def read(f): return repo.file(f).read(mmap2[f]) |
|
59 | def read(f): return repo.file(f).read(mmap2[f]) | |
60 | date2 = date(change) |
|
60 | date2 = date(change) | |
61 | else: |
|
61 | else: | |
62 | date2 = time.asctime() |
|
62 | date2 = time.asctime() | |
63 | if not node1: |
|
63 | if not node1: | |
64 | node1 = repo.current |
|
64 | node1 = repo.current | |
65 | (c, a, d) = repo.diffdir(repo.root, node1) |
|
65 | (c, a, d) = repo.diffdir(repo.root, node1) | |
66 | def read(f): return file(os.path.join(repo.root, f)).read() |
|
66 | def read(f): return file(os.path.join(repo.root, f)).read() | |
67 |
|
67 | |||
68 | change = repo.changelog.read(node1) |
|
68 | change = repo.changelog.read(node1) | |
69 | mmap = repo.manifest.read(change[0]) |
|
69 | mmap = repo.manifest.read(change[0]) | |
70 | date1 = date(change) |
|
70 | date1 = date(change) | |
71 |
|
71 | |||
72 | if files: |
|
72 | if files: | |
73 | (c, a, d) = map(lambda x: filterfiles(x, files), (c, a, d)) |
|
73 | (c, a, d) = map(lambda x: filterfiles(x, files), (c, a, d)) | |
74 |
|
74 | |||
75 | for f in c: |
|
75 | for f in c: | |
76 | to = repo.file(f).read(mmap[f]) |
|
76 | to = repo.file(f).read(mmap[f]) | |
77 | tn = read(f) |
|
77 | tn = read(f) | |
78 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
78 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | |
79 | for f in a: |
|
79 | for f in a: | |
80 | to = "" |
|
80 | to = "" | |
81 | tn = read(f) |
|
81 | tn = read(f) | |
82 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
82 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | |
83 | for f in d: |
|
83 | for f in d: | |
84 | to = repo.file(f).read(mmap[f]) |
|
84 | to = repo.file(f).read(mmap[f]) | |
85 | tn = "" |
|
85 | tn = "" | |
86 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
86 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) | |
87 |
|
87 | |||
88 | options = {} |
|
88 | options = {} | |
89 | opts = [('v', 'verbose', None, 'verbose'), |
|
89 | opts = [('v', 'verbose', None, 'verbose'), | |
90 | ('d', 'debug', None, 'debug')] |
|
90 | ('d', 'debug', None, 'debug')] | |
91 |
|
91 | |||
92 | args = fancyopts.fancyopts(sys.argv[1:], opts, options, |
|
92 | args = fancyopts.fancyopts(sys.argv[1:], opts, options, | |
93 | 'hg [options] <command> [command options] [files]') |
|
93 | 'hg [options] <command> [command options] [files]') | |
94 |
|
94 | |||
95 | try: |
|
95 | try: | |
96 | cmd = args[0] |
|
96 | cmd = args[0] | |
97 | args = args[1:] |
|
97 | args = args[1:] | |
98 | except: |
|
98 | except: | |
99 | cmd = "" |
|
99 | cmd = "" | |
100 |
|
100 | |||
101 | ui = hg.ui(options["verbose"], options["debug"]) |
|
101 | ui = hg.ui(options["verbose"], options["debug"]) | |
102 |
|
102 | |||
103 | if cmd == "init": |
|
103 | if cmd == "init": | |
104 | repo = hg.repository(ui, ".", create=1) |
|
104 | repo = hg.repository(ui, ".", create=1) | |
105 | sys.exit(0) |
|
105 | sys.exit(0) | |
106 | elif cmd == "branch" or cmd == "clone": |
|
106 | elif cmd == "branch" or cmd == "clone": | |
107 | os.system("cp -al %s/.hg .hg" % args[0]) |
|
107 | os.system("cp -al %s/.hg .hg" % args[0]) | |
108 | sys.exit(0) |
|
108 | sys.exit(0) | |
109 | elif cmd == "help": |
|
109 | elif cmd == "help": | |
110 | help() |
|
110 | help() | |
111 | sys.exit(0) |
|
111 | sys.exit(0) | |
112 | else: |
|
112 | else: | |
113 | try: |
|
113 | try: | |
114 | repo = hg.repository(ui=ui) |
|
114 | repo = hg.repository(ui=ui) | |
115 | except: |
|
115 | except: | |
116 | print "Unable to open repository" |
|
116 | print "Unable to open repository" | |
117 | sys.exit(0) |
|
117 | sys.exit(0) | |
118 |
|
118 | |||
|
119 | relpath = None | |||
|
120 | if os.getcwd() != repo.root: | |||
|
121 | relpath = os.getcwd()[len(repo.root) + 1: ] | |||
|
122 | ||||
119 | if cmd == "checkout" or cmd == "co": |
|
123 | if cmd == "checkout" or cmd == "co": | |
120 | node = repo.changelog.tip() |
|
124 | node = repo.changelog.tip() | |
121 | if args: |
|
125 | if args: | |
122 | node = repo.lookup(args[0]) |
|
126 | node = repo.lookup(args[0]) | |
123 | repo.checkout(node) |
|
127 | repo.checkout(node) | |
124 |
|
128 | |||
125 | elif cmd == "add": |
|
129 | elif cmd == "add": | |
126 | repo.add(args) |
|
130 | repo.add(args) | |
127 |
|
131 | |||
128 | elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete": |
|
132 | elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete": | |
129 | repo.remove(args) |
|
133 | repo.remove(args) | |
130 |
|
134 | |||
131 | elif cmd == "commit" or cmd == "checkin" or cmd == "ci": |
|
135 | elif cmd == "commit" or cmd == "checkin" or cmd == "ci": | |
132 | if 1: |
|
136 | if 1: | |
133 | if len(args) > 0: |
|
137 | if len(args) > 0: | |
134 | repo.commit(repo.current, args) |
|
138 | repo.commit(repo.current, args) | |
135 | else: |
|
139 | else: | |
136 | repo.commit(repo.current) |
|
140 | repo.commit(repo.current) | |
137 |
|
141 | |||
138 | elif cmd == "import" or cmd == "patch": |
|
142 | elif cmd == "import" or cmd == "patch": | |
139 | try: |
|
143 | try: | |
140 | import psyco |
|
144 | import psyco | |
141 | psyco.full() |
|
145 | psyco.full() | |
142 | except: |
|
146 | except: | |
143 | pass |
|
147 | pass | |
144 |
|
148 | |||
145 | ioptions = {} |
|
149 | ioptions = {} | |
146 | opts = [('p', 'strip', 1, 'path strip'), |
|
150 | opts = [('p', 'strip', 1, 'path strip'), | |
147 | ('b', 'base', "", 'base path'), |
|
151 | ('b', 'base', "", 'base path'), | |
148 | ('q', 'quiet', "", 'silence diff') |
|
152 | ('q', 'quiet', "", 'silence diff') | |
149 | ] |
|
153 | ] | |
150 |
|
154 | |||
151 | args = fancyopts.fancyopts(args, opts, ioptions, |
|
155 | args = fancyopts.fancyopts(args, opts, ioptions, | |
152 | 'hg import [options] <patch names>') |
|
156 | 'hg import [options] <patch names>') | |
153 | d = ioptions["base"] |
|
157 | d = ioptions["base"] | |
154 | strip = ioptions["strip"] |
|
158 | strip = ioptions["strip"] | |
155 | quiet = ioptions["quiet"] and "> /dev/null" or "" |
|
159 | quiet = ioptions["quiet"] and "> /dev/null" or "" | |
156 |
|
160 | |||
157 | for patch in args: |
|
161 | for patch in args: | |
158 | ui.status("applying %s\n" % patch) |
|
162 | ui.status("applying %s\n" % patch) | |
159 | pf = os.path.join(d, patch) |
|
163 | pf = os.path.join(d, patch) | |
160 |
|
164 | |||
161 | text = "" |
|
165 | text = "" | |
162 | for l in file(pf): |
|
166 | for l in file(pf): | |
163 | if l[:4] == "--- ": break |
|
167 | if l[:4] == "--- ": break | |
164 | text += l |
|
168 | text += l | |
165 |
|
169 | |||
166 | f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
|
170 | f = os.popen("lsdiff --strip %d %s" % (strip, pf)) | |
167 | files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) |
|
171 | files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) | |
168 | f.close() |
|
172 | f.close() | |
169 |
|
173 | |||
170 | if files: |
|
174 | if files: | |
171 | if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): |
|
175 | if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): | |
172 | raise "patch failed!" |
|
176 | raise "patch failed!" | |
173 | repo.commit(repo.current, files, text) |
|
177 | repo.commit(repo.current, files, text) | |
174 |
|
178 | |||
175 | elif cmd == "status": |
|
179 | elif cmd == "status": | |
176 | (c, a, d) = repo.diffdir(repo.root, repo.current) |
|
180 | (c, a, d) = repo.diffdir(repo.root, repo.current) | |
|
181 | if relpath: | |||
|
182 | (c, a, d) = map(lambda x: filterfiles(x, [ relpath ]), (c, a, d)) | |||
|
183 | ||||
177 | for f in c: print "C", f |
|
184 | for f in c: print "C", f | |
178 | for f in a: print "?", f |
|
185 | for f in a: print "?", f | |
179 | for f in d: print "R", f |
|
186 | for f in d: print "R", f | |
180 |
|
187 | |||
181 | elif cmd == "diff": |
|
188 | elif cmd == "diff": | |
182 | revs = [] |
|
189 | revs = [] | |
183 |
|
190 | |||
184 | if args: |
|
191 | if args: | |
185 | doptions = {} |
|
192 | doptions = {} | |
186 | opts = [('r', 'revision', [], 'revision')] |
|
193 | opts = [('r', 'revision', [], 'revision')] | |
187 | args = fancyopts.fancyopts(args, opts, doptions, |
|
194 | args = fancyopts.fancyopts(args, opts, doptions, | |
188 | 'hg diff [options] [files]') |
|
195 | 'hg diff [options] [files]') | |
189 | revs = map(lambda x: repo.lookup(x), doptions['revision']) |
|
196 | revs = map(lambda x: repo.lookup(x), doptions['revision']) | |
190 |
|
197 | |||
191 | if len(revs) > 2: |
|
198 | if len(revs) > 2: | |
192 | print "too many revisions to diff" |
|
199 | print "too many revisions to diff" | |
193 | sys.exit(1) |
|
200 | sys.exit(1) | |
194 |
|
201 | |||
195 | if os.getcwd() != repo.root: |
|
202 | if relpath: | |
196 | relpath = os.getcwd()[len(repo.root) + 1: ] |
|
|||
197 | if not args: args = [ relpath ] |
|
203 | if not args: args = [ relpath ] | |
198 | else: args = [ os.path.join(relpath, x) for x in args ] |
|
204 | else: args = [ os.path.join(relpath, x) for x in args ] | |
199 |
|
205 | |||
200 | diff(args, *revs) |
|
206 | diff(args, *revs) | |
201 |
|
207 | |||
202 | elif cmd == "export": |
|
208 | elif cmd == "export": | |
203 | node = repo.lookup(args[0]) |
|
209 | node = repo.lookup(args[0]) | |
204 | prev, other = repo.changelog.parents(node) |
|
210 | prev, other = repo.changelog.parents(node) | |
205 | change = repo.changelog.read(node) |
|
211 | change = repo.changelog.read(node) | |
206 | print "# HG changeset patch" |
|
212 | print "# HG changeset patch" | |
207 | print "# User %s" % change[1] |
|
213 | print "# User %s" % change[1] | |
208 | print "# Node ID %s" % hg.hex(node) |
|
214 | print "# Node ID %s" % hg.hex(node) | |
209 | print "# Parent %s" % hg.hex(prev) |
|
215 | print "# Parent %s" % hg.hex(prev) | |
210 |
|
216 | |||
211 | if other != hg.nullid: |
|
217 | if other != hg.nullid: | |
212 | print "# Parent %s" % hg.hex(other) |
|
218 | print "# Parent %s" % hg.hex(other) | |
213 | print change[4] |
|
219 | print change[4] | |
214 |
|
220 | |||
215 | diff(None, prev, node) |
|
221 | diff(None, prev, node) | |
216 |
|
222 | |||
217 | elif cmd == "debugchangegroup": |
|
223 | elif cmd == "debugchangegroup": | |
218 | newer = repo.newer(map(repo.lookup, args)) |
|
224 | newer = repo.newer(map(repo.lookup, args)) | |
219 | for chunk in repo.changegroup(newer): |
|
225 | for chunk in repo.changegroup(newer): | |
220 | sys.stdout.write(chunk) |
|
226 | sys.stdout.write(chunk) | |
221 |
|
227 | |||
222 | elif cmd == "debugaddchangegroup": |
|
228 | elif cmd == "debugaddchangegroup": | |
223 | data = sys.stdin.read() |
|
229 | data = sys.stdin.read() | |
224 | repo.addchangegroup(data) |
|
230 | repo.addchangegroup(data) | |
225 |
|
231 | |||
226 | elif cmd == "addremove": |
|
232 | elif cmd == "addremove": | |
227 | (c, a, d) = repo.diffdir(repo.root, repo.current) |
|
233 | (c, a, d) = repo.diffdir(repo.root, repo.current) | |
228 | repo.add(a) |
|
234 | repo.add(a) | |
229 | repo.remove(d) |
|
235 | repo.remove(d) | |
230 |
|
236 | |||
231 | elif cmd == "history": |
|
237 | elif cmd == "history": | |
232 | for i in range(repo.changelog.count()): |
|
238 | for i in range(repo.changelog.count()): | |
233 | n = repo.changelog.node(i) |
|
239 | n = repo.changelog.node(i) | |
234 | changes = repo.changelog.read(n) |
|
240 | changes = repo.changelog.read(n) | |
235 | (p1, p2) = repo.changelog.parents(n) |
|
241 | (p1, p2) = repo.changelog.parents(n) | |
236 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
242 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
237 | (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
|
243 | (i1, i2) = map(repo.changelog.rev, (p1, p2)) | |
238 | print "rev: %4d:%s" % (i, h) |
|
244 | print "rev: %4d:%s" % (i, h) | |
239 | print "parents: %4d:%s" % (i1, h1) |
|
245 | print "parents: %4d:%s" % (i1, h1) | |
240 | if i2: print " %4d:%s" % (i2, h2) |
|
246 | if i2: print " %4d:%s" % (i2, h2) | |
241 | print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), |
|
247 | print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), | |
242 | hg.hex(changes[0])) |
|
248 | hg.hex(changes[0])) | |
243 | print "user:", changes[1] |
|
249 | print "user:", changes[1] | |
244 | print "date:", time.asctime( |
|
250 | print "date:", time.asctime( | |
245 | time.localtime(float(changes[2].split(' ')[0]))) |
|
251 | time.localtime(float(changes[2].split(' ')[0]))) | |
246 | print "files:", " ".join(changes[3]) |
|
252 | print "files:", " ".join(changes[3]) | |
247 | print "description:" |
|
253 | print "description:" | |
248 | print changes[4] |
|
254 | print changes[4] | |
249 |
|
255 | |||
250 | elif cmd == "log": |
|
256 | elif cmd == "log": | |
251 | if args: |
|
257 | ||
|
258 | if len(args) == 1: | |||
|
259 | if relpath: | |||
|
260 | args[0] = os.path.join(relpath, args[0]) | |||
|
261 | ||||
252 | r = repo.file(args[0]) |
|
262 | r = repo.file(args[0]) | |
253 | for i in range(r.count()): |
|
263 | for i in range(r.count()): | |
254 | n = r.node(i) |
|
264 | n = r.node(i) | |
255 | (p1, p2) = r.parents(n) |
|
265 | (p1, p2) = r.parents(n) | |
256 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
266 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
257 | (i1, i2) = map(r.rev, (p1, p2)) |
|
267 | (i1, i2) = map(r.rev, (p1, p2)) | |
258 | cr = r.linkrev(n) |
|
268 | cr = r.linkrev(n) | |
259 | cn = hg.hex(repo.changelog.node(cr)) |
|
269 | cn = hg.hex(repo.changelog.node(cr)) | |
260 | print "rev: %4d:%s" % (i, h) |
|
270 | print "rev: %4d:%s" % (i, h) | |
261 | print "changeset: %4d:%s" % (cr, cn) |
|
271 | print "changeset: %4d:%s" % (cr, cn) | |
262 | print "parents: %4d:%s" % (i1, h1) |
|
272 | print "parents: %4d:%s" % (i1, h1) | |
263 | if i2: print " %4d:%s" % (i2, h2) |
|
273 | if i2: print " %4d:%s" % (i2, h2) | |
|
274 | changes = repo.changelog.read(repo.changelog.node(cr)) | |||
|
275 | print "user: %s date: %s" % (changes[1], time.asctime( | |||
|
276 | time.localtime(float(changes[2].split(' ')[0])))) | |||
|
277 | print "description:" | |||
|
278 | print changes[4] | |||
|
279 | ||||
|
280 | elif len(args) > 1: | |||
|
281 | print "too many args" | |||
264 | else: |
|
282 | else: | |
265 | print "missing filename" |
|
283 | print "missing filename" | |
266 |
|
284 | |||
267 | elif cmd == "dump": |
|
285 | elif cmd == "dump": | |
268 | if args: |
|
286 | if args: | |
269 | r = repo.file(args[0]) |
|
287 | r = repo.file(args[0]) | |
270 | n = r.tip() |
|
288 | n = r.tip() | |
271 | if len(args) > 1: n = r.lookup(args[1]) |
|
289 | if len(args) > 1: n = r.lookup(args[1]) | |
272 | sys.stdout.write(r.read(n)) |
|
290 | sys.stdout.write(r.read(n)) | |
273 | else: |
|
291 | else: | |
274 | print "missing filename" |
|
292 | print "missing filename" | |
275 |
|
293 | |||
276 | elif cmd == "dumpmanifest": |
|
294 | elif cmd == "dumpmanifest": | |
277 | n = repo.manifest.tip() |
|
295 | n = repo.manifest.tip() | |
278 | if len(args) > 0: |
|
296 | if len(args) > 0: | |
279 | n = repo.manifest.lookup(args[0]) |
|
297 | n = repo.manifest.lookup(args[0]) | |
280 | m = repo.manifest.read(n) |
|
298 | m = repo.manifest.read(n) | |
281 | files = m.keys() |
|
299 | files = m.keys() | |
282 | files.sort() |
|
300 | files.sort() | |
283 |
|
301 | |||
284 | for f in files: |
|
302 | for f in files: | |
285 | print hg.hex(m[f]), f |
|
303 | print hg.hex(m[f]), f | |
286 |
|
304 | |||
287 | elif cmd == "debughash": |
|
305 | elif cmd == "debughash": | |
288 | f = repo.file(args[0]) |
|
306 | f = repo.file(args[0]) | |
289 | print f.encodepath(args[0]) |
|
307 | print f.encodepath(args[0]) | |
290 |
|
308 | |||
291 | elif cmd == "debugindex": |
|
309 | elif cmd == "debugindex": | |
292 | r = hg.revlog(open, args[0], "") |
|
310 | r = hg.revlog(open, args[0], "") | |
293 | print " rev offset length base linkrev"+\ |
|
311 | print " rev offset length base linkrev"+\ | |
294 | " p1 p2 nodeid" |
|
312 | " p1 p2 nodeid" | |
295 | for i in range(r.count()): |
|
313 | for i in range(r.count()): | |
296 | e = r.index[i] |
|
314 | e = r.index[i] | |
297 | print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( |
|
315 | print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( | |
298 | i, e[0], e[1], e[2], e[3], |
|
316 | i, e[0], e[1], e[2], e[3], | |
299 | hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) |
|
317 | hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) | |
300 |
|
318 | |||
301 | elif cmd == "merge": |
|
319 | elif cmd == "merge": | |
302 | if args: |
|
320 | if args: | |
303 | other = hg.repository(ui, args[0]) |
|
321 | other = hg.repository(ui, args[0]) | |
304 | print "requesting changegroup" |
|
322 | print "requesting changegroup" | |
305 | cg = repo.getchangegroup(other) |
|
323 | cg = repo.getchangegroup(other) | |
306 | repo.addchangegroup(cg) |
|
324 | repo.addchangegroup(cg) | |
307 | else: |
|
325 | else: | |
308 | print "missing source repository" |
|
326 | print "missing source repository" | |
309 |
|
327 | |||
310 | elif cmd == "tags": |
|
328 | elif cmd == "tags": | |
311 | repo.lookup(0) # prime the cache |
|
329 | repo.lookup(0) # prime the cache | |
312 | i = repo.tags.items() |
|
330 | i = repo.tags.items() | |
313 | i.sort() |
|
331 | i.sort() | |
314 | for k, n in i: |
|
332 | for k, n in i: | |
315 | try: |
|
333 | try: | |
316 | r = repo.changelog.rev(n) |
|
334 | r = repo.changelog.rev(n) | |
317 | except KeyError: |
|
335 | except KeyError: | |
318 | r = "?" |
|
336 | r = "?" | |
319 | print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) |
|
337 | print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | |
320 |
|
338 | |||
321 | elif cmd == "debugoldmerge": |
|
339 | elif cmd == "debugoldmerge": | |
322 | if args: |
|
340 | if args: | |
323 | other = hg.repository(ui, args[0]) |
|
341 | other = hg.repository(ui, args[0]) | |
324 | repo.merge(other) |
|
342 | repo.merge(other) | |
325 | else: |
|
343 | else: | |
326 | print "missing source repository" |
|
344 | print "missing source repository" | |
327 |
|
345 | |||
328 | elif cmd == "verify": |
|
346 | elif cmd == "verify": | |
329 | filelinkrevs = {} |
|
347 | filelinkrevs = {} | |
330 | filenodes = {} |
|
348 | filenodes = {} | |
331 | manifestchangeset = {} |
|
349 | manifestchangeset = {} | |
332 | changesets = revisions = files = 0 |
|
350 | changesets = revisions = files = 0 | |
333 |
|
351 | |||
334 | print "checking changesets" |
|
352 | print "checking changesets" | |
335 | for i in range(repo.changelog.count()): |
|
353 | for i in range(repo.changelog.count()): | |
336 | changesets += 1 |
|
354 | changesets += 1 | |
337 | n = repo.changelog.node(i) |
|
355 | n = repo.changelog.node(i) | |
338 | changes = repo.changelog.read(n) |
|
356 | changes = repo.changelog.read(n) | |
339 | manifestchangeset[changes[0]] = n |
|
357 | manifestchangeset[changes[0]] = n | |
340 | for f in changes[3]: |
|
358 | for f in changes[3]: | |
341 | revisions += 1 |
|
359 | revisions += 1 | |
342 | filelinkrevs.setdefault(f, []).append(i) |
|
360 | filelinkrevs.setdefault(f, []).append(i) | |
343 |
|
361 | |||
344 | print "checking manifests" |
|
362 | print "checking manifests" | |
345 | for i in range(repo.manifest.count()): |
|
363 | for i in range(repo.manifest.count()): | |
346 | n = repo.manifest.node(i) |
|
364 | n = repo.manifest.node(i) | |
347 | ca = repo.changelog.node(repo.manifest.linkrev(n)) |
|
365 | ca = repo.changelog.node(repo.manifest.linkrev(n)) | |
348 | cc = manifestchangeset[n] |
|
366 | cc = manifestchangeset[n] | |
349 | if ca != cc: |
|
367 | if ca != cc: | |
350 | print "manifest %s points to %s, not %s" % \ |
|
368 | print "manifest %s points to %s, not %s" % \ | |
351 | (hg.hex(n), hg.hex(ca), hg.hex(cc)) |
|
369 | (hg.hex(n), hg.hex(ca), hg.hex(cc)) | |
352 | m = repo.manifest.read(n) |
|
370 | m = repo.manifest.read(n) | |
353 | for f, fn in m.items(): |
|
371 | for f, fn in m.items(): | |
354 | filenodes.setdefault(f, {})[fn] = 1 |
|
372 | filenodes.setdefault(f, {})[fn] = 1 | |
355 |
|
373 | |||
356 | print "crosschecking files in changesets and manifests" |
|
374 | print "crosschecking files in changesets and manifests" | |
357 | for f in filenodes: |
|
375 | for f in filenodes: | |
358 | if f not in filelinkrevs: |
|
376 | if f not in filelinkrevs: | |
359 | print "file %s in manifest but not in changesets" |
|
377 | print "file %s in manifest but not in changesets" | |
360 |
|
378 | |||
361 | for f in filelinkrevs: |
|
379 | for f in filelinkrevs: | |
362 | if f not in filenodes: |
|
380 | if f not in filenodes: | |
363 | print "file %s in changeset but not in manifest" |
|
381 | print "file %s in changeset but not in manifest" | |
364 |
|
382 | |||
365 | print "checking files" |
|
383 | print "checking files" | |
366 | for f in filenodes: |
|
384 | for f in filenodes: | |
367 | files += 1 |
|
385 | files += 1 | |
368 | fl = repo.file(f) |
|
386 | fl = repo.file(f) | |
369 | nodes = {"\0"*20: 1} |
|
387 | nodes = {"\0"*20: 1} | |
370 | for i in range(fl.count()): |
|
388 | for i in range(fl.count()): | |
371 | n = fl.node(i) |
|
389 | n = fl.node(i) | |
372 |
|
390 | |||
373 | if n not in filenodes[f]: |
|
391 | if n not in filenodes[f]: | |
374 | print "%s:%s not in manifests" % (f, hg.hex(n)) |
|
392 | print "%s:%s not in manifests" % (f, hg.hex(n)) | |
375 | else: |
|
393 | else: | |
376 | del filenodes[f][n] |
|
394 | del filenodes[f][n] | |
377 |
|
395 | |||
378 | flr = fl.linkrev(n) |
|
396 | flr = fl.linkrev(n) | |
379 | if flr not in filelinkrevs[f]: |
|
397 | if flr not in filelinkrevs[f]: | |
380 | print "%s:%s points to unexpected changeset rev %d" \ |
|
398 | print "%s:%s points to unexpected changeset rev %d" \ | |
381 | % (f, hg.hex(n), fl.linkrev(n)) |
|
399 | % (f, hg.hex(n), fl.linkrev(n)) | |
382 | else: |
|
400 | else: | |
383 | filelinkrevs[f].remove(flr) |
|
401 | filelinkrevs[f].remove(flr) | |
384 |
|
402 | |||
385 | # verify contents |
|
403 | # verify contents | |
386 | t = fl.read(n) |
|
404 | t = fl.read(n) | |
387 |
|
405 | |||
388 | # verify parents |
|
406 | # verify parents | |
389 | (p1, p2) = fl.parents(n) |
|
407 | (p1, p2) = fl.parents(n) | |
390 | if p1 not in nodes: |
|
408 | if p1 not in nodes: | |
391 | print "%s:%s unknown parent 1 %s" % (f, hg.hex(n), hg.hex(p1)) |
|
409 | print "%s:%s unknown parent 1 %s" % (f, hg.hex(n), hg.hex(p1)) | |
392 | if p2 not in nodes: |
|
410 | if p2 not in nodes: | |
393 | print "file %s:%s unknown parent %s" % (f, hg.hex(n), hg.hex(p1)) |
|
411 | print "file %s:%s unknown parent %s" % (f, hg.hex(n), hg.hex(p1)) | |
394 | nodes[n] = 1 |
|
412 | nodes[n] = 1 | |
395 |
|
413 | |||
396 | # cross-check |
|
414 | # cross-check | |
397 | for flr in filelinkrevs[f]: |
|
415 | for flr in filelinkrevs[f]: | |
398 | print "changeset rev %d not in %s" % (flr, f) |
|
416 | print "changeset rev %d not in %s" % (flr, f) | |
399 |
|
417 | |||
400 | for node in filenodes[f]: |
|
418 | for node in filenodes[f]: | |
401 | print "node %s in manifests not in %s" % (hg.hex(n), f) |
|
419 | print "node %s in manifests not in %s" % (hg.hex(n), f) | |
402 |
|
420 | |||
403 |
|
421 | |||
404 | print "%d files, %d changesets, %d total revisions" % (files, changesets, |
|
422 | print "%d files, %d changesets, %d total revisions" % (files, changesets, | |
405 | revisions) |
|
423 | revisions) | |
406 |
|
424 | |||
407 | else: |
|
425 | else: | |
408 | print "unknown command\n" |
|
426 | print "unknown command\n" | |
409 | help() |
|
427 | help() | |
410 | sys.exit(1) |
|
428 | sys.exit(1) |
General Comments 0
You need to be logged in to leave comments.
Login now