Mercurial > hg > gitweb
comparison hg @ 245:fef0f8e041aa
big heap of command clean-up work
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
big heap of command clean-up work
Migrate add, forget, remove, commit, diff, addremove, tip, log,
recover, and serve.
Fix up filterfiles, relfilter, and relpath to be a bit more bulletproof
Alphabetize functions and the command table
Make everything in commands.py relative-path aware
manifest hash: f0856031a7be4e49289677b467f29bcf24ebce4a
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCof6gywK+sNU5EO8RAoW1AJsHu8vchPSjls7wVbvsq/UKlGhqtgCgtnnl
xSBxyf/TEVWjHIk3uTa8WSE=
=YPMl
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Sat, 04 Jun 2005 11:18:56 -0800 |
parents | afe895fcc0d0 |
children | 96cde50a746f |
comparison
equal
deleted
inserted
replaced
244:43105253cf5e | 245:fef0f8e041aa |
---|---|
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, ui, commands | 20 from mercurial import hg, mdiff, fancyopts, ui, commands |
21 | |
22 def help(): | |
23 ui.status("""\ | |
24 commands: | |
25 | |
26 add [files...] add the given files in the next commit | |
27 addremove add all new files, delete all missing files | |
28 annotate [files...] show changeset number per file line | |
29 branch <path> create a branch of <path> in this directory | |
30 checkout [changeset] checkout the latest or given changeset | |
31 commit commit all changes to the repository | |
32 diff [files...] diff working directory (or selected files) | |
33 dump <file> [rev] dump the latest or given revision of a file | |
34 dumpmanifest [rev] dump the latest or given revision of the manifest | |
35 export <rev> dump the changeset header and diffs for a revision | |
36 history show changeset history | |
37 init create a new repository in this directory | |
38 log <file> show revision history of a single file | |
39 merge <path> merge changes from <path> into local repository | |
40 recover rollback an interrupted transaction | |
41 remove [files...] remove the given files in the next commit | |
42 serve export the repository via HTTP | |
43 status show new, missing, and changed files in working dir | |
44 tags show current changeset tags | |
45 undo undo the last transaction | |
46 """) | |
47 | 21 |
48 def filterfiles(list, files): | 22 def filterfiles(list, files): |
49 l = [ x for x in list if x in files ] | 23 l = [ x for x in list if x in files ] |
50 | 24 |
51 for f in files: | 25 for f in files: |
124 | 98 |
125 relpath = None | 99 relpath = None |
126 if os.getcwd() != repo.root: | 100 if os.getcwd() != repo.root: |
127 relpath = os.getcwd()[len(repo.root) + 1: ] | 101 relpath = os.getcwd()[len(repo.root) + 1: ] |
128 | 102 |
129 elif cmd == "add": | |
130 repo.add(args) | |
131 | |
132 elif cmd == "forget": | |
133 repo.forget(args) | |
134 | |
135 elif cmd == "remove" or cmd == "rm" or cmd == "del" or cmd == "delete": | |
136 repo.remove(args) | |
137 | |
138 elif cmd == "commit" or cmd == "checkin" or cmd == "ci": | |
139 if 1: | |
140 if len(args) > 0: | |
141 repo.commit(args) | |
142 else: | |
143 repo.commit() | |
144 elif cmd == "rawcommit": | 103 elif cmd == "rawcommit": |
145 "raw commit interface" | 104 "raw commit interface" |
146 rc = {} | 105 rc = {} |
147 opts = [('p', 'parent', [], 'parent'), | 106 opts = [('p', 'parent', [], 'parent'), |
148 ('d', 'date', "", 'data'), | 107 ('d', 'date', "", 'data'), |
203 if files: | 162 if files: |
204 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): | 163 if os.system("patch -p%d < %s %s" % (strip, pf, quiet)): |
205 raise "patch failed!" | 164 raise "patch failed!" |
206 repo.commit(files, text) | 165 repo.commit(files, text) |
207 | 166 |
208 elif cmd == "diff": | |
209 revs = [] | |
210 | |
211 if args: | |
212 doptions = {} | |
213 opts = [('r', 'revision', [], 'revision')] | |
214 args = fancyopts.fancyopts(args, opts, doptions, | |
215 'hg diff [options] [files]') | |
216 revs = map(lambda x: repo.lookup(x), doptions['revision']) | |
217 | |
218 if len(revs) > 2: | |
219 self.ui.warn("too many revisions to diff\n") | |
220 sys.exit(1) | |
221 | |
222 if relpath: | |
223 if not args: args = [ relpath ] | |
224 else: args = [ os.path.join(relpath, x) for x in args ] | |
225 | |
226 diff(args, *revs) | |
227 | |
228 elif cmd == "export": | 167 elif cmd == "export": |
229 node = repo.lookup(args[0]) | 168 node = repo.lookup(args[0]) |
230 prev, other = repo.changelog.parents(node) | 169 prev, other = repo.changelog.parents(node) |
231 change = repo.changelog.read(node) | 170 change = repo.changelog.read(node) |
232 print "# HG changeset patch" | 171 print "# HG changeset patch" |
247 | 186 |
248 elif cmd == "debugaddchangegroup": | 187 elif cmd == "debugaddchangegroup": |
249 data = sys.stdin.read() | 188 data = sys.stdin.read() |
250 repo.addchangegroup(data) | 189 repo.addchangegroup(data) |
251 | 190 |
252 elif cmd == "addremove": | |
253 (c, a, d, u) = repo.diffdir(repo.root) | |
254 repo.add(a) | |
255 repo.remove(d) | |
256 | |
257 elif cmd == "history": | 191 elif cmd == "history": |
258 for i in range(repo.changelog.count()): | 192 for i in range(repo.changelog.count()): |
259 n = repo.changelog.node(i) | 193 n = repo.changelog.node(i) |
260 changes = repo.changelog.read(n) | 194 changes = repo.changelog.read(n) |
261 (p1, p2) = repo.changelog.parents(n) | 195 (p1, p2) = repo.changelog.parents(n) |
271 time.localtime(float(changes[2].split(' ')[0]))) | 205 time.localtime(float(changes[2].split(' ')[0]))) |
272 if ui.verbose: print "files:", " ".join(changes[3]) | 206 if ui.verbose: print "files:", " ".join(changes[3]) |
273 print "description:" | 207 print "description:" |
274 print changes[4] | 208 print changes[4] |
275 | 209 |
276 elif cmd == "tip": | |
277 n = repo.changelog.tip() | |
278 t = repo.changelog.rev(n) | |
279 ui.status("%d:%s\n" % (t, hg.hex(n))) | |
280 | |
281 elif cmd == "log": | |
282 | |
283 if len(args) == 1: | |
284 if relpath: | |
285 args[0] = os.path.join(relpath, args[0]) | |
286 | |
287 r = repo.file(args[0]) | |
288 for i in range(r.count()): | |
289 n = r.node(i) | |
290 (p1, p2) = r.parents(n) | |
291 (h, h1, h2) = map(hg.hex, (n, p1, p2)) | |
292 (i1, i2) = map(r.rev, (p1, p2)) | |
293 cr = r.linkrev(n) | |
294 cn = hg.hex(repo.changelog.node(cr)) | |
295 print "rev: %4d:%s" % (i, h) | |
296 print "changeset: %4d:%s" % (cr, cn) | |
297 print "parents: %4d:%s" % (i1, h1) | |
298 if i2: print " %4d:%s" % (i2, h2) | |
299 changes = repo.changelog.read(repo.changelog.node(cr)) | |
300 print "user: %s" % changes[1] | |
301 print "date: %s" % time.asctime( | |
302 time.localtime(float(changes[2].split(' ')[0]))) | |
303 print "description:" | |
304 print changes[4] | |
305 print | |
306 elif len(args) > 1: | |
307 print "too many args" | |
308 else: | |
309 print "missing filename" | |
310 | |
311 elif cmd == "dump": | 210 elif cmd == "dump": |
312 if args: | 211 if args: |
313 r = repo.file(args[0]) | 212 r = repo.file(args[0]) |
314 n = r.tip() | 213 n = r.tip() |
315 if len(args) > 1: n = r.lookup(args[1]) | 214 if len(args) > 1: n = r.lookup(args[1]) |
381 try: | 280 try: |
382 r = repo.changelog.rev(n) | 281 r = repo.changelog.rev(n) |
383 except KeyError: | 282 except KeyError: |
384 r = "?" | 283 r = "?" |
385 print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) | 284 print "%-30s %5d:%s" % (k, repo.changelog.rev(n), hg.hex(n)) |
386 | |
387 elif cmd == "recover": | |
388 repo.recover() | |
389 | 285 |
390 elif cmd == "verify": | 286 elif cmd == "verify": |
391 filelinkrevs = {} | 287 filelinkrevs = {} |
392 filenodes = {} | 288 filenodes = {} |
393 manifestchangeset = {} | 289 manifestchangeset = {} |
508 | 404 |
509 if errors: | 405 if errors: |
510 ui.warn("%d integrity errors encountered!\n" % errors) | 406 ui.warn("%d integrity errors encountered!\n" % errors) |
511 sys.exit(1) | 407 sys.exit(1) |
512 | 408 |
513 elif cmd == "serve": | |
514 from mercurial import hgweb | |
515 | |
516 soptions = {} | |
517 opts = [('p', 'port', 8000, 'listen port'), | |
518 ('a', 'address', '', 'interface address'), | |
519 ('n', 'name', os.getcwd(), 'repository name'), | |
520 ('t', 'templates', "", 'template map') | |
521 ] | |
522 | |
523 args = fancyopts.fancyopts(args, opts, soptions, | |
524 'hg serve [options]') | |
525 | |
526 hgweb.server(repo.root, soptions["name"], soptions["templates"], | |
527 soptions["address"], soptions["port"]) | |
528 | |
529 else: | 409 else: |
530 if cmd: ui.warn("unknown command\n\n") | 410 if cmd: ui.warn("unknown command\n\n") |
531 help() | |
532 sys.exit(1) | 411 sys.exit(1) |