annotate mercurial/commands.py @ 227:f57519cddd3d

move repo.current to dirstate.parents() -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 move repo.current to dirstate.parents() dirstate now tracks the parents for the working dir add a parents command to show them manifest hash: cd69237838c3f69f7937723c4a6803d47cb27cfa -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCoMGuywK+sNU5EO8RAg5UAKCVLUrsJtkoIOTM+e0BLqEVN3Ni3gCeNDyy ZF8jD728cl9K7S4sIN4gX4Y= =P4bu -----END PGP SIGNATURE-----
author mpm@selenic.com
date Fri, 03 Jun 2005 12:46:38 -0800
parents 2bfe525ef6ca
children 00ea3613f82c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
1 import os, re, traceback, sys, signal, time
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
2 from mercurial import fancyopts, ui, hg
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
3
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
4 class UnknownCommand(Exception): pass
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
5
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
6 def filterfiles(list, files):
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
7 l = [ x for x in list if x in files ]
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
8
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
9 for f in files:
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
10 if f[-1] != os.sep: f += os.sep
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
11 l += [ x for x in list if x.startswith(f) ]
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
12 return l
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
13
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
14 def relfilter(repo, args):
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
15 if os.getcwd() != repo.root:
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
16 p = os.getcwd()[len(repo.root) + 1: ]
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
17 return filterfiles(p, args)
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
18 return args
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
19
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
20 def relpath(repo, args):
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
21 if os.getcwd() != repo.root:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
22 p = os.getcwd()[len(repo.root) + 1: ]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
23 return [ os.path.join(p, x) for x in args ]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
24 return args
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
25
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
26 def help(ui, cmd=None):
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
27 '''show help'''
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
28 if cmd:
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
29 try:
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
30 i = find(cmd)
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
31 ui.write("%s\n\n" % i[2])
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
32 ui.write(i[0].__doc__, "\n")
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
33 except UnknownCommand:
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
34 ui.warn("unknown command %s", cmd)
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
35 sys.exit(0)
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
36
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
37 ui.status("""\
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
38 hg commands:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
39
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
40 add [files...] add the given files in the next commit
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
41 addremove add all new files, delete all missing files
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
42 annotate [files...] show changeset number per file line
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
43 branch <path> create a branch of <path> in this directory
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
44 checkout [changeset] checkout the latest or given changeset
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
45 commit commit all changes to the repository
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
46 diff [files...] diff working directory (or selected files)
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
47 dump <file> [rev] dump the latest or given revision of a file
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
48 dumpmanifest [rev] dump the latest or given revision of the manifest
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
49 export <rev> dump the changeset header and diffs for a revision
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
50 history show changeset history
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
51 init create a new repository in this directory
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
52 log <file> show revision history of a single file
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
53 merge <path> merge changes from <path> into local repository
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
54 recover rollback an interrupted transaction
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
55 remove [files...] remove the given files in the next commit
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
56 serve export the repository via HTTP
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
57 status show new, missing, and changed files in working dir
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
58 tags show current changeset tags
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
59 undo undo the last transaction
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
60 """)
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
61
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
62 def init(ui):
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
63 """create a repository"""
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
64 hg.repository(ui, ".", create=1)
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
65
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
66 def branch(ui, path):
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
67 '''branch from a local repository'''
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
68 # this should eventually support remote repos
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
69 os.system("cp -al %s/.hg .hg" % path)
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
70
219
8ff4532376a4 hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents: 214
diff changeset
71 def checkout(ui, repo, changeset=None):
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
72 '''checkout a given changeset or the current tip'''
220
3113a94c1bff change dircache into dirstate
mpm@selenic.com
parents: 219
diff changeset
73 (c, a, d, u) = repo.diffdir(repo.root, repo.current)
3113a94c1bff change dircache into dirstate
mpm@selenic.com
parents: 219
diff changeset
74 if c or a or d:
219
8ff4532376a4 hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents: 214
diff changeset
75 ui.warn("aborting (outstanding changes in working directory)\n")
8ff4532376a4 hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents: 214
diff changeset
76 sys.exit(1)
8ff4532376a4 hg checkout: refuse to checkout if there are outstanding changes
mpm@selenic.com
parents: 214
diff changeset
77
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
78 node = repo.changelog.tip()
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
79 if changeset:
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
80 node = repo.lookup(changeset)
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
81 repo.checkout(node)
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
82
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
83 def annotate(u, repo, *args, **ops):
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
84 def getnode(rev):
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
85 return hg.short(repo.changelog.node(rev))
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
86
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
87 def getname(rev):
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
88 try:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
89 return bcache[rev]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
90 except KeyError:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
91 cl = repo.changelog.read(repo.changelog.node(rev))
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
92 name = cl[1]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
93 f = name.find('@')
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
94 if f >= 0:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
95 name = name[:f]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
96 bcache[rev] = name
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
97 return name
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
98
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
99 bcache = {}
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
100 opmap = [['user', getname], ['number', str], ['changeset', getnode]]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
101 if not ops['user'] and not ops['changeset']:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
102 ops['number'] = 1
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
103
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
104 args = relpath(repo, args)
227
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
105 node = repo.dirstate.parents()[0]
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
106 if ops['revision']:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
107 node = repo.changelog.lookup(ops['revision'])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
108 change = repo.changelog.read(node)
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
109 mmap = repo.manifest.read(change[0])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
110 maxuserlen = 0
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
111 maxchangelen = 0
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
112 for f in args:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
113 lines = repo.file(f).annotate(mmap[f])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
114 pieces = []
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
115
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
116 for o, f in opmap:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
117 if ops[o]:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
118 l = [ f(n) for n,t in lines ]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
119 m = max(map(len, l))
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
120 pieces.append([ "%*s" % (m, x) for x in l])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
121
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
122 for p,l in zip(zip(*pieces), lines):
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
123 u.write(" ".join(p) + ": " + l[1])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
124
221
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
125 def heads(ui, repo):
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
126 '''show current repository heads'''
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
127 for n in repo.changelog.heads():
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
128 i = repo.changelog.rev(n)
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
129 changes = repo.changelog.read(n)
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
130 (p1, p2) = repo.changelog.parents(n)
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
131 (h, h1, h2) = map(hg.hex, (n, p1, p2))
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
132 (i1, i2) = map(repo.changelog.rev, (p1, p2))
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
133 print "rev: %4d:%s" % (i, h)
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
134 print "parents: %4d:%s" % (i1, h1)
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
135 if i2: print " %4d:%s" % (i2, h2)
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
136 print "manifest: %4d:%s" % (repo.manifest.rev(changes[0]),
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
137 hg.hex(changes[0]))
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
138 print "user:", changes[1]
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
139 print "date:", time.asctime(
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
140 time.localtime(float(changes[2].split(' ')[0])))
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
141 if ui.verbose: print "files:", " ".join(changes[3])
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
142 print "description:"
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
143 print changes[4]
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
144
227
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
145 def parents(ui, repo, node = None):
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
146 '''show the parents of the current working dir'''
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
147 if node:
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
148 p = repo.changelog.parents(repo.lookup(hg.bin(node)))
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
149 else:
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
150 p = repo.dirstate.parents()
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
151
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
152 for n in p:
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
153 if n != hg.nullid:
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
154 ui.write("%d:%s\n" % (repo.changelog.rev(n), hg.hex(n)))
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
155
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
156 def status(ui, repo):
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
157 '''show changed files in the working directory
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
158
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
159 C = changed
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
160 A = added
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
161 R = removed
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
162 ? = not tracked'''
220
3113a94c1bff change dircache into dirstate
mpm@selenic.com
parents: 219
diff changeset
163 (c, a, d, u) = repo.diffdir(repo.root, repo.current)
3113a94c1bff change dircache into dirstate
mpm@selenic.com
parents: 219
diff changeset
164 (c, a, d, u) = map(lambda x: relfilter(repo, x), (c, a, d, u))
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
165
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
166 for f in c: print "C", f
220
3113a94c1bff change dircache into dirstate
mpm@selenic.com
parents: 219
diff changeset
167 for f in a: print "A", f
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
168 for f in d: print "R", f
220
3113a94c1bff change dircache into dirstate
mpm@selenic.com
parents: 219
diff changeset
169 for f in u: print "?", f
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
170
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
171 def undo(ui, repo):
210
d2badbd7d1ad hg undo: fixup working dir state
mpm@selenic.com
parents: 209
diff changeset
172 repo.undo()
d2badbd7d1ad hg undo: fixup working dir state
mpm@selenic.com
parents: 209
diff changeset
173
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
174 table = {
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
175 "init": (init, [], 'hg init'),
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
176 "branch|clone": (branch, [], 'hg branch [path]'),
221
2bfe525ef6ca Beginning of multi-head support
mpm@selenic.com
parents: 220
diff changeset
177 "heads": (heads, [], 'hg heads'),
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
178 "help": (help, [], 'hg help [command]'),
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
179 "checkout|co": (checkout, [], 'hg checkout [changeset]'),
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
180 "ann|annotate": (annotate,
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
181 [('r', 'revision', '', 'revision'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
182 ('u', 'user', None, 'show user'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
183 ('n', 'number', None, 'show revision number'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
184 ('c', 'changeset', None, 'show changeset')],
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
185 'hg annotate [-u] [-c] [-n] [-r id] [files]'),
227
f57519cddd3d move repo.current to dirstate.parents()
mpm@selenic.com
parents: 221
diff changeset
186 "parents": (parents, [], 'hg parents [node]'),
213
d2172916ef6c commands: migrate status and branch
mpm@selenic.com
parents: 212
diff changeset
187 "status": (status, [], 'hg status'),
210
d2badbd7d1ad hg undo: fixup working dir state
mpm@selenic.com
parents: 209
diff changeset
188 "undo": (undo, [], 'hg undo'),
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
189 }
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
190
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
191 norepo = "init branch help"
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
192
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
193 def find(cmd):
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
194 i = None
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
195 for e in table.keys():
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
196 if re.match(e + "$", cmd):
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
197 return table[e]
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
198
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
199 raise UnknownCommand(cmd)
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
200
214
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
201 class SignalInterrupt(Exception): pass
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
202
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
203 def catchterm(*args):
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
204 raise SignalInterrupt
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
205
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
206 def dispatch(args):
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
207 options = {}
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
208 opts = [('v', 'verbose', None, 'verbose'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
209 ('d', 'debug', None, 'debug'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
210 ('q', 'quiet', None, 'quiet'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
211 ('y', 'noninteractive', None, 'run non-interactively'),
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
212 ]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
213
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
214 args = fancyopts.fancyopts(args, opts, options,
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
215 'hg [options] <command> [options] [files]')
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
216
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
217 if not args:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
218 cmd = "help"
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
219 else:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
220 cmd, args = args[0], args[1:]
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
221
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
222 u = ui.ui(options["verbose"], options["debug"], options["quiet"],
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
223 not options["noninteractive"])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
224
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
225 # deal with unfound commands later
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
226 i = find(cmd)
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
227
214
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
228 signal.signal(signal.SIGTERM, catchterm)
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
229
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
230 cmdoptions = {}
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
231 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
232
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
233 if cmd not in norepo.split():
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
234 repo = hg.repository(ui = u)
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
235 d = lambda: i[0](u, repo, *args, **cmdoptions)
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
236 else:
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
237 d = lambda: i[0](u, *args, **cmdoptions)
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
238
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
239 try:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
240 d()
214
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
241 except SignalInterrupt:
2d60aa9bde0a catch TERM signal in command processor
mpm@selenic.com
parents: 213
diff changeset
242 u.warn("killed!\n")
209
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
243 except KeyboardInterrupt:
63af1db35611 Beginning of new command parsing interface
mpm@selenic.com
parents:
diff changeset
244 u.warn("interrupted!\n")
212
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
245 except TypeError, inst:
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
246 # was this an argument error?
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
247 tb = traceback.extract_tb(sys.exc_info()[2])
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
248 if len(tb) > 2: # no
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
249 raise
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
250 u.warn("%s: invalid arguments\n" % i[0].__name__)
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
251 u.warn("syntax: %s\n" % i[2])
48398a5353e3 commands: better argument processing, per-command help
mpm@selenic.com
parents: 211
diff changeset
252 sys.exit(-1)