Show More
@@ -1,121 +1,23 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # |
|
3 | 3 | # mercurial - a minimal scalable distributed SCM |
|
4 | 4 | # v0.5b "katje" |
|
5 | 5 | # |
|
6 | 6 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
7 | 7 | # |
|
8 | 8 | # This software may be used and distributed according to the terms |
|
9 | 9 | # of the GNU General Public License, incorporated herein by reference. |
|
10 | 10 | |
|
11 | 11 | # the psyco compiler makes commits a bit faster |
|
12 | 12 | # and makes changegroup merge about 20 times slower! |
|
13 | 13 | # try: |
|
14 | 14 | # import psyco |
|
15 | 15 | # psyco.full() |
|
16 | 16 | # except: |
|
17 | 17 | # pass |
|
18 | 18 | |
|
19 | 19 | import sys |
|
20 |
from mercurial import |
|
|
21 | ||
|
22 | try: | |
|
23 | sys.exit(commands.dispatch(sys.argv[1:])) | |
|
24 | except commands.UnknownCommand: | |
|
25 | # fall through | |
|
26 | pass | |
|
27 | ||
|
28 | options = {} | |
|
29 | opts = [('v', 'verbose', None, 'verbose'), | |
|
30 | ('d', 'debug', None, 'debug'), | |
|
31 | ('q', 'quiet', None, 'quiet'), | |
|
32 | ('y', 'noninteractive', None, 'run non-interactively'), | |
|
33 | ] | |
|
34 | ||
|
35 | args = fancyopts.fancyopts(sys.argv[1:], opts, options, | |
|
36 | 'hg [options] <command> [command options] [files]') | |
|
37 | ||
|
38 | try: | |
|
39 | cmd = args[0] | |
|
40 | args = args[1:] | |
|
41 | except: | |
|
42 | cmd = "help" | |
|
43 | ||
|
44 | ui = ui.ui(options["verbose"], options["debug"], options["quiet"], | |
|
45 | not options["noninteractive"]) | |
|
46 | ||
|
47 | try: | |
|
48 | repo = hg.repository(ui=ui) | |
|
49 | except IOError: | |
|
50 | ui.warn("Unable to open repository\n") | |
|
51 | sys.exit(0) | |
|
52 | ||
|
53 | if cmd == "debugchangegroup": | |
|
54 | newer = repo.newer(map(repo.lookup, args)) | |
|
55 | for chunk in repo.changegroup(newer): | |
|
56 | sys.stdout.write(chunk) | |
|
57 | ||
|
58 | elif cmd == "debugaddchangegroup": | |
|
59 | data = sys.stdin.read() | |
|
60 | repo.addchangegroup(data) | |
|
61 | ||
|
62 | elif cmd == "dump": | |
|
63 | if args: | |
|
64 | r = repo.file(args[0]) | |
|
65 | n = r.tip() | |
|
66 | if len(args) > 1: n = r.lookup(args[1]) | |
|
67 | sys.stdout.write(r.read(n)) | |
|
68 | else: | |
|
69 | print "missing filename" | |
|
20 | from mercurial import commands | |
|
70 | 21 | |
|
71 | elif cmd == "dumpmanifest": | |
|
72 | n = repo.manifest.tip() | |
|
73 | if len(args) > 0: | |
|
74 | n = repo.manifest.lookup(args[0]) | |
|
75 | m = repo.manifest.read(n) | |
|
76 | files = m.keys() | |
|
77 | files.sort() | |
|
78 | ||
|
79 | for f in files: | |
|
80 | print hg.hex(m[f]), f | |
|
81 | ||
|
82 | elif cmd == "debugindex": | |
|
83 | if ".hg" not in args[0]: | |
|
84 | args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i" | |
|
85 | ||
|
86 | r = hg.revlog(open, args[0], "") | |
|
87 | print " rev offset length base linkrev"+\ | |
|
88 | " p1 p2 nodeid" | |
|
89 | for i in range(r.count()): | |
|
90 | e = r.index[i] | |
|
91 | print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( | |
|
92 | i, e[0], e[1], e[2], e[3], | |
|
93 | hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) | |
|
22 | sys.exit(commands.dispatch(sys.argv[1:])) | |
|
94 | 23 | |
|
95 | elif cmd == "debugindexdot": | |
|
96 | if ".hg" not in args[0]: | |
|
97 | args[0] = ".hg/data/" + repo.file(args[0]).encodepath(args[0]) + "i" | |
|
98 | ||
|
99 | r = hg.revlog(open, args[0], "") | |
|
100 | print "digraph G {" | |
|
101 | for i in range(r.count()): | |
|
102 | e = r.index[i] | |
|
103 | print "\t%d -> %d" % (r.rev(e[4]), i) | |
|
104 | if e[5] != hg.nullid: | |
|
105 | print "\t%d -> %d" % (r.rev(e[5]), i) | |
|
106 | print "}" | |
|
107 | ||
|
108 | elif cmd == "tags": | |
|
109 | repo.lookup(0) # prime the cache | |
|
110 | i = repo.tags.items() | |
|
111 | i.sort() | |
|
112 | for k, n in i: | |
|
113 | try: | |
|
114 | r = repo.changelog.rev(n) | |
|
115 | except KeyError: | |
|
116 | r = "?" | |
|
117 | print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | |
|
118 | ||
|
119 | else: | |
|
120 | if cmd: ui.warn("unknown command\n\n") | |
|
121 | sys.exit(1) |
@@ -1,507 +1,571 b'' | |||
|
1 | 1 | import os, re, traceback, sys, signal, time, mdiff |
|
2 | 2 | from mercurial import fancyopts, ui, hg |
|
3 | 3 | |
|
4 | 4 | class UnknownCommand(Exception): pass |
|
5 | 5 | |
|
6 | 6 | def filterfiles(filters, files): |
|
7 | 7 | l = [ x for x in files if x in filters ] |
|
8 | 8 | |
|
9 | 9 | for t in filters: |
|
10 | 10 | if t and t[-1] != os.sep: t += os.sep |
|
11 | 11 | l += [ x for x in files if x.startswith(t) ] |
|
12 | 12 | return l |
|
13 | 13 | |
|
14 | 14 | def relfilter(repo, files): |
|
15 | 15 | if os.getcwd() != repo.root: |
|
16 | 16 | p = os.getcwd()[len(repo.root) + 1: ] |
|
17 | 17 | return filterfiles(p, files) |
|
18 | 18 | return files |
|
19 | 19 | |
|
20 | 20 | def relpath(repo, args): |
|
21 | 21 | if os.getcwd() != repo.root: |
|
22 | 22 | p = os.getcwd()[len(repo.root) + 1: ] |
|
23 | 23 | return [ os.path.normpath(os.path.join(p, x)) for x in args ] |
|
24 | 24 | return args |
|
25 | 25 | |
|
26 | 26 | def dodiff(repo, files = None, node1 = None, node2 = None): |
|
27 | 27 | def date(c): |
|
28 | 28 | return time.asctime(time.gmtime(float(c[2].split(' ')[0]))) |
|
29 | 29 | |
|
30 | 30 | if node2: |
|
31 | 31 | change = repo.changelog.read(node2) |
|
32 | 32 | mmap2 = repo.manifest.read(change[0]) |
|
33 | 33 | (c, a, d) = repo.diffrevs(node1, node2) |
|
34 | 34 | def read(f): return repo.file(f).read(mmap2[f]) |
|
35 | 35 | date2 = date(change) |
|
36 | 36 | else: |
|
37 | 37 | date2 = time.asctime() |
|
38 | 38 | (c, a, d, u) = repo.diffdir(repo.root, node1) |
|
39 | 39 | if not node1: |
|
40 | 40 | node1 = repo.dirstate.parents()[0] |
|
41 | 41 | def read(f): return file(os.path.join(repo.root, f)).read() |
|
42 | 42 | |
|
43 | 43 | change = repo.changelog.read(node1) |
|
44 | 44 | mmap = repo.manifest.read(change[0]) |
|
45 | 45 | date1 = date(change) |
|
46 | 46 | |
|
47 | 47 | if files: |
|
48 | 48 | c, a, d = map(lambda x: filterfiles(files, x), (c, a, d)) |
|
49 | 49 | |
|
50 | 50 | for f in c: |
|
51 | 51 | to = repo.file(f).read(mmap[f]) |
|
52 | 52 | tn = read(f) |
|
53 | 53 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
54 | 54 | for f in a: |
|
55 | 55 | to = "" |
|
56 | 56 | tn = read(f) |
|
57 | 57 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
58 | 58 | for f in d: |
|
59 | 59 | to = repo.file(f).read(mmap[f]) |
|
60 | 60 | tn = "" |
|
61 | 61 | sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f)) |
|
62 | 62 | |
|
63 | 63 | def help(ui, cmd=None): |
|
64 | 64 | '''show help''' |
|
65 | 65 | if cmd: |
|
66 | 66 | try: |
|
67 | 67 | i = find(cmd) |
|
68 | 68 | ui.write("%s\n\n" % i[2]) |
|
69 | 69 | ui.write(i[0].__doc__, "\n") |
|
70 | 70 | except UnknownCommand: |
|
71 | 71 | ui.warn("unknown command %s", cmd) |
|
72 | 72 | sys.exit(0) |
|
73 | 73 | |
|
74 | 74 | ui.status("""\ |
|
75 | 75 | hg commands: |
|
76 | 76 | |
|
77 | 77 | add [files...] add the given files in the next commit |
|
78 | 78 | addremove add all new files, delete all missing files |
|
79 | 79 | annotate [files...] show changeset number per file line |
|
80 | 80 | branch <path> create a branch of <path> in this directory |
|
81 | 81 | checkout [changeset] checkout the latest or given changeset |
|
82 | 82 | commit commit all changes to the repository |
|
83 | 83 | diff [files...] diff working directory (or selected files) |
|
84 | 84 | dump <file> [rev] dump the latest or given revision of a file |
|
85 | 85 | dumpmanifest [rev] dump the latest or given revision of the manifest |
|
86 | 86 | export <rev> dump the changeset header and diffs for a revision |
|
87 | 87 | history show changeset history |
|
88 | 88 | init create a new repository in this directory |
|
89 | 89 | log <file> show revision history of a single file |
|
90 | 90 | merge <path> merge changes from <path> into local repository |
|
91 | 91 | recover rollback an interrupted transaction |
|
92 | 92 | remove [files...] remove the given files in the next commit |
|
93 | 93 | serve export the repository via HTTP |
|
94 | 94 | status show new, missing, and changed files in working dir |
|
95 | 95 | tags show current changeset tags |
|
96 | 96 | undo undo the last transaction |
|
97 | 97 | """) |
|
98 | 98 | |
|
99 | 99 | def add(ui, repo, file, *files): |
|
100 | 100 | '''add the specified files on the next commit''' |
|
101 | 101 | repo.add(relpath(repo, (file,) + files)) |
|
102 | 102 | |
|
103 | 103 | def addremove(ui, repo): |
|
104 | 104 | (c, a, d, u) = repo.diffdir(repo.root) |
|
105 | 105 | repo.add(a) |
|
106 | 106 | repo.remove(d) |
|
107 | 107 | |
|
108 | 108 | def annotate(u, repo, file, *files, **ops): |
|
109 | 109 | def getnode(rev): |
|
110 | 110 | return hg.short(repo.changelog.node(rev)) |
|
111 | 111 | |
|
112 | 112 | def getname(rev): |
|
113 | 113 | try: |
|
114 | 114 | return bcache[rev] |
|
115 | 115 | except KeyError: |
|
116 | 116 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
117 | 117 | name = cl[1] |
|
118 | 118 | f = name.find('@') |
|
119 | 119 | if f >= 0: |
|
120 | 120 | name = name[:f] |
|
121 | 121 | bcache[rev] = name |
|
122 | 122 | return name |
|
123 | 123 | |
|
124 | 124 | bcache = {} |
|
125 | 125 | opmap = [['user', getname], ['number', str], ['changeset', getnode]] |
|
126 | 126 | if not ops['user'] and not ops['changeset']: |
|
127 | 127 | ops['number'] = 1 |
|
128 | 128 | |
|
129 | 129 | node = repo.dirstate.parents()[0] |
|
130 | 130 | if ops['revision']: |
|
131 | 131 | node = repo.changelog.lookup(ops['revision']) |
|
132 | 132 | change = repo.changelog.read(node) |
|
133 | 133 | mmap = repo.manifest.read(change[0]) |
|
134 | 134 | maxuserlen = 0 |
|
135 | 135 | maxchangelen = 0 |
|
136 | 136 | for f in relpath(repo, (file,) + files): |
|
137 | 137 | lines = repo.file(f).annotate(mmap[f]) |
|
138 | 138 | pieces = [] |
|
139 | 139 | |
|
140 | 140 | for o, f in opmap: |
|
141 | 141 | if ops[o]: |
|
142 | 142 | l = [ f(n) for n,t in lines ] |
|
143 | 143 | m = max(map(len, l)) |
|
144 | 144 | pieces.append([ "%*s" % (m, x) for x in l]) |
|
145 | 145 | |
|
146 | 146 | for p,l in zip(zip(*pieces), lines): |
|
147 | 147 | u.write(" ".join(p) + ": " + l[1]) |
|
148 | 148 | |
|
149 | 149 | def branch(ui, path): |
|
150 | 150 | '''branch from a local repository''' |
|
151 | 151 | # this should eventually support remote repos |
|
152 | 152 | os.system("cp -al %s/.hg .hg" % path) |
|
153 | 153 | |
|
154 | def cat(ui, repo, file, rev = []): | |
|
155 | r = repo.file(file) | |
|
156 | n = r.tip() | |
|
157 | if rev: n = r.lookup(rev) | |
|
158 | sys.stdout.write(r.read(n)) | |
|
159 | ||
|
154 | 160 | def checkout(ui, repo, changeset=None): |
|
155 | 161 | '''checkout a given changeset or the current tip''' |
|
156 | 162 | (c, a, d, u) = repo.diffdir(repo.root) |
|
157 | 163 | if c or a or d: |
|
158 | 164 | ui.warn("aborting (outstanding changes in working directory)\n") |
|
159 | 165 | sys.exit(1) |
|
160 | 166 | |
|
161 | 167 | node = repo.changelog.tip() |
|
162 | 168 | if changeset: |
|
163 | 169 | node = repo.lookup(changeset) |
|
164 | 170 | repo.checkout(node) |
|
165 | 171 | |
|
166 | 172 | def commit(ui, repo, *files): |
|
167 | 173 | """commit the specified files or all outstanding changes""" |
|
168 | 174 | repo.commit(relpath(repo, files)) |
|
169 | 175 | |
|
176 | def debugaddchangegroup(ui, repo): | |
|
177 | data = sys.stdin.read() | |
|
178 | repo.addchangegroup(data) | |
|
179 | ||
|
180 | def debugchangegroup(ui, repo, roots): | |
|
181 | newer = repo.newer(map(repo.lookup, roots)) | |
|
182 | for chunk in repo.changegroup(newer): | |
|
183 | sys.stdout.write(chunk) | |
|
184 | ||
|
185 | def debugindex(ui, file): | |
|
186 | r = hg.revlog(open, file, "") | |
|
187 | print " rev offset length base linkrev"+\ | |
|
188 | " p1 p2 nodeid" | |
|
189 | for i in range(r.count()): | |
|
190 | e = r.index[i] | |
|
191 | print "% 6d % 9d % 7d % 6d % 7d %s.. %s.. %s.." % ( | |
|
192 | i, e[0], e[1], e[2], e[3], | |
|
193 | hg.hex(e[4][:5]), hg.hex(e[5][:5]), hg.hex(e[6][:5])) | |
|
194 | ||
|
195 | def debugindexdot(ui, file): | |
|
196 | r = hg.revlog(open, file, "") | |
|
197 | print "digraph G {" | |
|
198 | for i in range(r.count()): | |
|
199 | e = r.index[i] | |
|
200 | print "\t%d -> %d" % (r.rev(e[4]), i) | |
|
201 | if e[5] != hg.nullid: | |
|
202 | print "\t%d -> %d" % (r.rev(e[5]), i) | |
|
203 | print "}" | |
|
204 | ||
|
170 | 205 | def diff(ui, repo, *files, **opts): |
|
171 | 206 | revs = [] |
|
172 | 207 | if opts['rev']: |
|
173 | 208 | revs = map(lambda x: repo.lookup(x), opts['rev']) |
|
174 | 209 | |
|
175 | 210 | if len(revs) > 2: |
|
176 | 211 | self.ui.warn("too many revisions to diff\n") |
|
177 | 212 | sys.exit(1) |
|
178 | 213 | |
|
179 | 214 | if files: |
|
180 | 215 | files = relpath(repo, files) |
|
181 | 216 | else: |
|
182 | 217 | files = relpath(repo, [""]) |
|
183 | 218 | |
|
184 | 219 | dodiff(repo, files, *revs) |
|
185 | 220 | |
|
186 | 221 | def export(ui, repo, changeset): |
|
187 | 222 | node = repo.lookup(changeset) |
|
188 | 223 | prev, other = repo.changelog.parents(node) |
|
189 | 224 | change = repo.changelog.read(node) |
|
190 | 225 | print "# HG changeset patch" |
|
191 | 226 | print "# User %s" % change[1] |
|
192 | 227 | print "# Node ID %s" % hg.hex(node) |
|
193 | 228 | print "# Parent %s" % hg.hex(prev) |
|
194 | 229 | |
|
195 | 230 | if other != hg.nullid: |
|
196 | 231 | print "# Parent %s" % hg.hex(other) |
|
197 | 232 | print change[4].rstrip() |
|
198 | 233 | |
|
199 | 234 | |
|
200 | 235 | dodiff(repo, None, prev, node) |
|
201 | 236 | |
|
202 | 237 | def forget(ui, repo, file, *files): |
|
203 | 238 | """don't add the specified files on the next commit""" |
|
204 | 239 | repo.forget(relpath(repo, (file,) + files)) |
|
205 | 240 | |
|
206 | 241 | def heads(ui, repo): |
|
207 | 242 | '''show current repository heads''' |
|
208 | 243 | for n in repo.changelog.heads(): |
|
209 | 244 | i = repo.changelog.rev(n) |
|
210 | 245 | changes = repo.changelog.read(n) |
|
211 | 246 | (p1, p2) = repo.changelog.parents(n) |
|
212 | 247 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
213 | 248 | (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
|
214 | 249 | print "rev: %4d:%s" % (i, h) |
|
215 | 250 | print "parents: %4d:%s" % (i1, h1) |
|
216 | 251 | if i2: print " %4d:%s" % (i2, h2) |
|
217 | 252 | print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), |
|
218 | 253 | hg.hex(changes[0])) |
|
219 | 254 | print "user:", changes[1] |
|
220 | 255 | print "date:", time.asctime( |
|
221 | 256 | time.localtime(float(changes[2].split(' ')[0]))) |
|
222 | 257 | if ui.verbose: print "files:", " ".join(changes[3]) |
|
223 | 258 | print "description:" |
|
224 | 259 | print changes[4] |
|
225 | 260 | |
|
226 | 261 | def history(ui, repo): |
|
227 | 262 | """show the changelog history""" |
|
228 | 263 | for i in range(repo.changelog.count()): |
|
229 | 264 | n = repo.changelog.node(i) |
|
230 | 265 | changes = repo.changelog.read(n) |
|
231 | 266 | (p1, p2) = repo.changelog.parents(n) |
|
232 | 267 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
233 | 268 | (i1, i2) = map(repo.changelog.rev, (p1, p2)) |
|
234 | 269 | print "rev: %4d:%s" % (i, h) |
|
235 | 270 | print "parents: %4d:%s" % (i1, h1) |
|
236 | 271 | if i2: print " %4d:%s" % (i2, h2) |
|
237 | 272 | print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]), |
|
238 | 273 | hg.hex(changes[0])) |
|
239 | 274 | print "user:", changes[1] |
|
240 | 275 | print "date:", time.asctime( |
|
241 | 276 | time.localtime(float(changes[2].split(' ')[0]))) |
|
242 | 277 | if ui.verbose: print "files:", " ".join(changes[3]) |
|
243 | 278 | print "description:" |
|
244 | 279 | print changes[4] |
|
245 | 280 | |
|
246 | 281 | def patch(ui, repo, patches, opts): |
|
247 | 282 | """import an ordered set of patches""" |
|
248 | 283 | try: |
|
249 | 284 | import psyco |
|
250 | 285 | psyco.full() |
|
251 | 286 | except: |
|
252 | 287 | pass |
|
253 | 288 | |
|
254 | 289 | d = opts["base"] |
|
255 | 290 | strip = opts["strip"] |
|
256 | 291 | quiet = opts["quiet"] and "> /dev/null" or "" |
|
257 | 292 | |
|
258 | 293 | for patch in patches: |
|
259 | 294 | ui.status("applying %s\n" % patch) |
|
260 | 295 | pf = os.path.join(d, patch) |
|
261 | 296 | |
|
262 | 297 | text = "" |
|
263 | 298 | for l in file(pf): |
|
264 | 299 | if l[:4] == "--- ": break |
|
265 | 300 | text += l |
|
266 | 301 | |
|
267 | 302 | f = os.popen("lsdiff --strip %d %s" % (strip, pf)) |
|
268 | 303 | files = filter(None, map(lambda x: x.rstrip(), f.read().splitlines())) |
|
269 | 304 | f.close() |
|
270 | 305 | |
|
271 | 306 | if files: |
|
272 | 307 | if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): |
|
273 | 308 | raise "patch failed!" |
|
274 | 309 | repo.commit(files, text) |
|
275 | 310 | |
|
276 | 311 | def init(ui): |
|
277 | 312 | """create a repository""" |
|
278 | 313 | hg.repository(ui, ".", create=1) |
|
279 | 314 | |
|
280 | 315 | def log(ui, repo, f): |
|
281 | 316 | f = relpath(repo, [f])[0] |
|
282 | 317 | |
|
283 | 318 | r = repo.file(f) |
|
284 | 319 | for i in range(r.count()): |
|
285 | 320 | n = r.node(i) |
|
286 | 321 | (p1, p2) = r.parents(n) |
|
287 | 322 | (h, h1, h2) = map(hg.hex, (n, p1, p2)) |
|
288 | 323 | (i1, i2) = map(r.rev, (p1, p2)) |
|
289 | 324 | cr = r.linkrev(n) |
|
290 | 325 | cn = hg.hex(repo.changelog.node(cr)) |
|
291 | 326 | print "rev: %4d:%s" % (i, h) |
|
292 | 327 | print "changeset: %4d:%s" % (cr, cn) |
|
293 | 328 | print "parents: %4d:%s" % (i1, h1) |
|
294 | 329 | if i2: print " %4d:%s" % (i2, h2) |
|
295 | 330 | changes = repo.changelog.read(repo.changelog.node(cr)) |
|
296 | 331 | print "user: %s" % changes[1] |
|
297 | 332 | print "date: %s" % time.asctime( |
|
298 | 333 | time.localtime(float(changes[2].split(' ')[0]))) |
|
299 | 334 | print "description:" |
|
300 | 335 | print changes[4].rstrip() |
|
301 | 336 | |
|
302 | 337 | |
|
338 | def manifest(ui, repo, rev = []): | |
|
339 | n = repo.manifest.tip() | |
|
340 | if rev: | |
|
341 | n = repo.manifest.lookup(rev) | |
|
342 | m = repo.manifest.read(n) | |
|
343 | files = m.keys() | |
|
344 | files.sort() | |
|
345 | ||
|
346 | for f in files: | |
|
347 | print hg.hex(m[f]), f | |
|
348 | ||
|
303 | 349 | def parents(ui, repo, node = None): |
|
304 | 350 | '''show the parents of the current working dir''' |
|
305 | 351 | if node: |
|
306 | 352 | p = repo.changelog.parents(repo.lookup(hg.bin(node))) |
|
307 | 353 | else: |
|
308 | 354 | p = repo.dirstate.parents() |
|
309 | 355 | |
|
310 | 356 | for n in p: |
|
311 | 357 | if n != hg.nullid: |
|
312 | 358 | ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n))) |
|
313 | 359 | |
|
314 | 360 | def pull(ui, repo, source): |
|
315 | 361 | """pull changes from the specified source""" |
|
316 | 362 | paths = {} |
|
317 | 363 | try: |
|
318 | 364 | pf = os.path.expanduser("~/.hgpaths") |
|
319 | 365 | for l in file(pf): |
|
320 | 366 | name, path = l.split() |
|
321 | 367 | paths[name] = path |
|
322 | 368 | except IOError: |
|
323 | 369 | pass |
|
324 | 370 | |
|
325 | 371 | if source in paths: source = paths[source] |
|
326 | 372 | |
|
327 | 373 | other = hg.repository(ui, source) |
|
328 | 374 | cg = repo.getchangegroup(other) |
|
329 | 375 | repo.addchangegroup(cg) |
|
330 | 376 | |
|
331 | 377 | def rawcommit(ui, repo, files, rc): |
|
332 | 378 | "raw commit interface" |
|
333 | 379 | |
|
334 | 380 | text = rc['text'] |
|
335 | 381 | if not text and rc['logfile']: |
|
336 | 382 | try: text = open(rc['logfile']).read() |
|
337 | 383 | except IOError: pass |
|
338 | 384 | if not text and not rc['logfile']: |
|
339 | 385 | print "missing commit text" |
|
340 | 386 | return 1 |
|
341 | 387 | |
|
342 | 388 | files = relpath(repo, files) |
|
343 | 389 | if rc['files']: |
|
344 | 390 | files += open(rc['files']).read().splitlines() |
|
345 | 391 | |
|
346 | 392 | repo.rawcommit(files, text, rc['user'], rc['date'], *rc['parent']) |
|
347 | 393 | |
|
348 | 394 | def recover(ui, repo): |
|
349 | 395 | repo.recover() |
|
350 | 396 | |
|
351 | 397 | def remove(ui, repo, file, *files): |
|
352 | 398 | """remove the specified files on the next commit""" |
|
353 | 399 | repo.remove(relpath(repo, (file,) + files)) |
|
354 | 400 | |
|
355 | 401 | def resolve(ui, repo, node=None): |
|
356 | 402 | '''merge a given node or the current tip into the working dir''' |
|
357 | 403 | if not node: |
|
358 | 404 | node = repo.changelog.tip() |
|
359 | 405 | else: |
|
360 | 406 | node = repo.lookup(node) |
|
361 | 407 | repo.resolve(node) |
|
362 | 408 | |
|
363 | 409 | def serve(ui, repo, **opts): |
|
364 | 410 | from mercurial import hgweb |
|
365 | 411 | hgweb.server(repo.root, opts["name"], opts["templates"], |
|
366 | 412 | opts["address"], opts["port"]) |
|
367 | 413 | |
|
368 | 414 | def status(ui, repo): |
|
369 | 415 | '''show changed files in the working directory |
|
370 | 416 | |
|
371 | 417 | C = changed |
|
372 | 418 | A = added |
|
373 | 419 | R = removed |
|
374 | 420 | ? = not tracked''' |
|
375 | 421 | |
|
376 | 422 | (c, a, d, u) = repo.diffdir(repo.root) |
|
377 | 423 | (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u)) |
|
378 | 424 | |
|
379 | 425 | for f in c: print "C", f |
|
380 | 426 | for f in a: print "A", f |
|
381 | 427 | for f in d: print "R", f |
|
382 | 428 | for f in u: print "?", f |
|
383 | 429 | |
|
430 | def tags(ui, repo): | |
|
431 | repo.lookup(0) # prime the cache | |
|
432 | i = repo.tags.items() | |
|
433 | i.sort() | |
|
434 | for k, n in i: | |
|
435 | try: | |
|
436 | r = repo.changelog.rev(n) | |
|
437 | except KeyError: | |
|
438 | r = "?" | |
|
439 | print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | |
|
440 | ||
|
384 | 441 | def tip(ui, repo): |
|
385 | 442 | n = repo.changelog.tip() |
|
386 | 443 | t = repo.changelog.rev(n) |
|
387 | 444 | ui.status("%d:%s\n" % (t, hg.hex(n))) |
|
388 | 445 | |
|
389 | 446 | def undo(ui, repo): |
|
390 | 447 | repo.undo() |
|
391 | 448 | |
|
392 | 449 | def verify(ui, repo): |
|
393 | 450 | """verify the integrity of the repository""" |
|
394 | 451 | return repo.verify() |
|
395 | 452 | |
|
396 | 453 | table = { |
|
397 | 454 | "add": (add, [], "hg add [files]"), |
|
398 | 455 | "addremove": (addremove, [], "hg addremove"), |
|
399 | 456 | "ann|annotate": (annotate, |
|
400 | 457 | [('r', 'revision', '', 'revision'), |
|
401 | 458 | ('u', 'user', None, 'show user'), |
|
402 | 459 | ('n', 'number', None, 'show revision number'), |
|
403 | 460 | ('c', 'changeset', None, 'show changeset')], |
|
404 | 461 | 'hg annotate [-u] [-c] [-n] [-r id] [files]'), |
|
405 | 462 | "branch|clone": (branch, [], 'hg branch [path]'), |
|
463 | "cat|dump": (cat, [], 'hg cat <file> [rev]'), | |
|
406 | 464 | "checkout|co": (checkout, [], 'hg checkout [changeset]'), |
|
407 | 465 | "commit|ci": (commit, [], 'hg commit [files]'), |
|
466 | "debugaddchangegroup": (debugaddchangegroup, [], 'debugaddchangegroup'), | |
|
467 | "debugchangegroup": (debugchangegroup, [], 'debugchangegroup [roots]'), | |
|
468 | "debugindex": (debugindex, [], 'debugindex <file>'), | |
|
469 | "debugindexdot": (debugindexdot, [], 'debugindexdot <file>'), | |
|
408 | 470 | "diff": (diff, [('r', 'rev', [], 'revision')], |
|
409 | 471 | 'hg diff [-r A] [-r B] [files]'), |
|
410 | 472 | "export": (export, [], "hg export <changeset>"), |
|
411 | 473 | "forget": (forget, [], "hg forget [files]"), |
|
412 | 474 | "heads": (heads, [], 'hg heads'), |
|
413 | 475 | "history": (history, [], 'hg history'), |
|
414 | 476 | "help": (help, [], 'hg help [command]'), |
|
415 | 477 | "init": (init, [], 'hg init'), |
|
416 | 478 | "log": (log, [], 'hg log <file>'), |
|
479 | "manifest|dumpmanifest": (manifest, [], 'hg manifest [rev]'), | |
|
417 | 480 | "parents": (parents, [], 'hg parents [node]'), |
|
418 | 481 | "patch|import": (patch, |
|
419 | 482 | [('p', 'strip', 1, 'path strip'), |
|
420 | 483 | ('b', 'base', "", 'base path'), |
|
421 | 484 | ('q', 'quiet', "", 'silence diff')], |
|
422 | 485 | "hg import [options] patches"), |
|
423 | 486 | "pull|merge": (pull, [], 'hg pull [source]'), |
|
424 | 487 | "rawcommit": (rawcommit, |
|
425 | 488 | [('p', 'parent', [], 'parent'), |
|
426 | 489 | ('d', 'date', "", 'data'), |
|
427 | 490 | ('u', 'user', "", 'user'), |
|
428 | 491 | ('F', 'files', "", 'file list'), |
|
429 | 492 | ('t', 'text', "", 'commit text'), |
|
430 | 493 | ('l', 'logfile', "", 'commit text file')], |
|
431 | 494 | 'hg rawcommit [options] [files]'), |
|
432 | 495 | "recover": (recover, [], "hg recover"), |
|
433 | 496 | "remove": (remove, [], "hg remove [files]"), |
|
434 | 497 | "resolve": (resolve, [], 'hg resolve [node]'), |
|
435 | 498 | "serve": (serve, [('p', 'port', 8000, 'listen port'), |
|
436 | 499 | ('a', 'address', '', 'interface address'), |
|
437 | 500 | ('n', 'name', os.getcwd(), 'repository name'), |
|
438 | 501 | ('t', 'templates', "", 'template map')], |
|
439 | 502 | "hg serve [options]"), |
|
440 | 503 | "status": (status, [], 'hg status'), |
|
504 | "tags": (tags, [], 'hg tags'), | |
|
441 | 505 | "tip": (tip, [], 'hg tip'), |
|
442 | 506 | "undo": (undo, [], 'hg undo'), |
|
443 | 507 | "verify": (verify, [], 'hg verify'), |
|
444 | 508 | } |
|
445 | 509 | |
|
446 | norepo = "init branch help" | |
|
510 | norepo = "init branch help debugindex debugindexdot" | |
|
447 | 511 | |
|
448 | 512 | def find(cmd): |
|
449 | 513 | i = None |
|
450 | 514 | for e in table.keys(): |
|
451 | 515 | if re.match(e + "$", cmd): |
|
452 | 516 | return table[e] |
|
453 | 517 | |
|
454 | 518 | raise UnknownCommand(cmd) |
|
455 | 519 | |
|
456 | 520 | class SignalInterrupt(Exception): pass |
|
457 | 521 | |
|
458 | 522 | def catchterm(*args): |
|
459 | 523 | raise SignalInterrupt |
|
460 | 524 | |
|
461 | 525 | def dispatch(args): |
|
462 | 526 | options = {} |
|
463 | 527 | opts = [('v', 'verbose', None, 'verbose'), |
|
464 | 528 | ('d', 'debug', None, 'debug'), |
|
465 | 529 | ('q', 'quiet', None, 'quiet'), |
|
466 | 530 | ('y', 'noninteractive', None, 'run non-interactively'), |
|
467 | 531 | ] |
|
468 | 532 | |
|
469 | 533 | args = fancyopts.fancyopts(args, opts, options, |
|
470 | 534 | 'hg [options] <command> [options] [files]') |
|
471 | 535 | |
|
472 | 536 | if not args: |
|
473 | 537 | cmd = "help" |
|
474 | 538 | else: |
|
475 | 539 | cmd, args = args[0], args[1:] |
|
476 | 540 | |
|
477 | 541 | u = ui.ui(options["verbose"], options["debug"], options["quiet"], |
|
478 | 542 | not options["noninteractive"]) |
|
479 | 543 | |
|
480 | 544 | # deal with unfound commands later |
|
481 | 545 | i = find(cmd) |
|
482 | 546 | |
|
483 | 547 | signal.signal(signal.SIGTERM, catchterm) |
|
484 | 548 | |
|
485 | 549 | cmdoptions = {} |
|
486 | 550 | args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2]) |
|
487 | 551 | |
|
488 | 552 | if cmd not in norepo.split(): |
|
489 | 553 | repo = hg.repository(ui = u) |
|
490 | 554 | d = lambda: i[0](u, repo, *args, **cmdoptions) |
|
491 | 555 | else: |
|
492 | 556 | d = lambda: i[0](u, *args, **cmdoptions) |
|
493 | 557 | |
|
494 | 558 | try: |
|
495 | 559 | return d() |
|
496 | 560 | except SignalInterrupt: |
|
497 | 561 | u.warn("killed!\n") |
|
498 | 562 | except KeyboardInterrupt: |
|
499 | 563 | u.warn("interrupted!\n") |
|
500 | 564 | except TypeError, inst: |
|
501 | 565 | # was this an argument error? |
|
502 | 566 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
503 | 567 | if len(tb) > 2: # no |
|
504 | 568 | raise |
|
505 | 569 | u.warn("%s: invalid arguments\n" % i[0].__name__) |
|
506 | 570 | u.warn("syntax: %s\n" % i[2]) |
|
507 | 571 | sys.exit(-1) |
General Comments 0
You need to be logged in to leave comments.
Login now