Show More
@@ -0,0 +1,81 b'' | |||
|
1 | #!/bin/sh | |
|
2 | ||
|
3 | hg init a | |
|
4 | echo line 1 > a/a | |
|
5 | hg --cwd a ci -d '0 0' -Ama | |
|
6 | ||
|
7 | echo line 2 >> a/a | |
|
8 | hg --cwd a ci -u someone -d '1 0' -m'second change' | |
|
9 | ||
|
10 | echo % import exported patch | |
|
11 | hg clone -r0 a b | |
|
12 | hg --cwd a export tip > tip.patch | |
|
13 | hg --cwd b import ../tip.patch | |
|
14 | echo % message should be same | |
|
15 | hg --cwd b tip | grep 'second change' | |
|
16 | echo % committer should be same | |
|
17 | hg --cwd b tip | grep someone | |
|
18 | rm -rf b | |
|
19 | ||
|
20 | echo % import of plain diff should fail without message | |
|
21 | hg clone -r0 a b | |
|
22 | hg --cwd a diff -r0:1 > tip.patch | |
|
23 | hg --cwd b import ../tip.patch | |
|
24 | rm -rf b | |
|
25 | ||
|
26 | echo % import of plain diff should be ok with message | |
|
27 | hg clone -r0 a b | |
|
28 | hg --cwd a diff -r0:1 > tip.patch | |
|
29 | hg --cwd b import -mpatch ../tip.patch | |
|
30 | rm -rf b | |
|
31 | ||
|
32 | echo % import from stdin | |
|
33 | hg clone -r0 a b | |
|
34 | hg --cwd a export tip | hg --cwd b import - | |
|
35 | rm -rf b | |
|
36 | ||
|
37 | echo % override commit message | |
|
38 | hg clone -r0 a b | |
|
39 | hg --cwd a export tip | hg --cwd b import -m 'override' - | |
|
40 | hg --cwd b tip | grep override | |
|
41 | rm -rf b | |
|
42 | ||
|
43 | cat > mkmsg.py <<EOF | |
|
44 | import email.Message, sys | |
|
45 | msg = email.Message.Message() | |
|
46 | msg.set_payload('email commit message\n' + open('tip.patch').read()) | |
|
47 | msg['Subject'] = 'email patch' | |
|
48 | msg['From'] = 'email patcher' | |
|
49 | sys.stdout.write(msg.as_string()) | |
|
50 | EOF | |
|
51 | ||
|
52 | echo % plain diff in email, subject, message body | |
|
53 | hg clone -r0 a b | |
|
54 | hg --cwd a diff -r0:1 > tip.patch | |
|
55 | python mkmsg.py > msg.patch | |
|
56 | hg --cwd b import ../msg.patch | |
|
57 | hg --cwd b tip | grep email | |
|
58 | rm -rf b | |
|
59 | ||
|
60 | echo % plain diff in email, no subject, message body | |
|
61 | hg clone -r0 a b | |
|
62 | grep -v '^Subject:' msg.patch | hg --cwd b import - | |
|
63 | rm -rf b | |
|
64 | ||
|
65 | echo % plain diff in email, subject, no message body | |
|
66 | hg clone -r0 a b | |
|
67 | grep -v '^email ' msg.patch | hg --cwd b import - | |
|
68 | rm -rf b | |
|
69 | ||
|
70 | echo % plain diff in email, no subject, no message body, should fail | |
|
71 | hg clone -r0 a b | |
|
72 | grep -v '^\(Subject\|email\)' msg.patch | hg --cwd b import - | |
|
73 | rm -rf b | |
|
74 | ||
|
75 | echo % hg export in email, should use patch header | |
|
76 | hg clone -r0 a b | |
|
77 | hg --cwd a export tip > tip.patch | |
|
78 | python mkmsg.py | hg --cwd b import - | |
|
79 | hg --cwd b tip | grep second | |
|
80 | rm -rf b | |
|
81 |
@@ -0,0 +1,103 b'' | |||
|
1 | adding a | |
|
2 | % import exported patch | |
|
3 | requesting all changes | |
|
4 | adding changesets | |
|
5 | adding manifests | |
|
6 | adding file changes | |
|
7 | added 1 changesets with 1 changes to 1 files | |
|
8 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
9 | applying ../tip.patch | |
|
10 | patching file a | |
|
11 | % message should be same | |
|
12 | summary: second change | |
|
13 | % committer should be same | |
|
14 | user: someone | |
|
15 | % import of plain diff should fail without message | |
|
16 | requesting all changes | |
|
17 | adding changesets | |
|
18 | adding manifests | |
|
19 | adding file changes | |
|
20 | added 1 changesets with 1 changes to 1 files | |
|
21 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
22 | applying ../tip.patch | |
|
23 | patching file a | |
|
24 | transaction abort! | |
|
25 | rollback completed | |
|
26 | % import of plain diff should be ok with message | |
|
27 | requesting all changes | |
|
28 | adding changesets | |
|
29 | adding manifests | |
|
30 | adding file changes | |
|
31 | added 1 changesets with 1 changes to 1 files | |
|
32 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
33 | applying ../tip.patch | |
|
34 | patching file a | |
|
35 | % import from stdin | |
|
36 | requesting all changes | |
|
37 | adding changesets | |
|
38 | adding manifests | |
|
39 | adding file changes | |
|
40 | added 1 changesets with 1 changes to 1 files | |
|
41 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
42 | applying patch from stdin | |
|
43 | patching file a | |
|
44 | % override commit message | |
|
45 | requesting all changes | |
|
46 | adding changesets | |
|
47 | adding manifests | |
|
48 | adding file changes | |
|
49 | added 1 changesets with 1 changes to 1 files | |
|
50 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
51 | applying patch from stdin | |
|
52 | patching file a | |
|
53 | summary: override | |
|
54 | % plain diff in email, subject, message body | |
|
55 | requesting all changes | |
|
56 | adding changesets | |
|
57 | adding manifests | |
|
58 | adding file changes | |
|
59 | added 1 changesets with 1 changes to 1 files | |
|
60 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
61 | applying ../msg.patch | |
|
62 | patching file a | |
|
63 | user: email patcher | |
|
64 | summary: email patch | |
|
65 | % plain diff in email, no subject, message body | |
|
66 | requesting all changes | |
|
67 | adding changesets | |
|
68 | adding manifests | |
|
69 | adding file changes | |
|
70 | added 1 changesets with 1 changes to 1 files | |
|
71 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
72 | applying patch from stdin | |
|
73 | patching file a | |
|
74 | % plain diff in email, subject, no message body | |
|
75 | requesting all changes | |
|
76 | adding changesets | |
|
77 | adding manifests | |
|
78 | adding file changes | |
|
79 | added 1 changesets with 1 changes to 1 files | |
|
80 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
81 | applying patch from stdin | |
|
82 | patching file a | |
|
83 | % plain diff in email, no subject, no message body, should fail | |
|
84 | requesting all changes | |
|
85 | adding changesets | |
|
86 | adding manifests | |
|
87 | adding file changes | |
|
88 | added 1 changesets with 1 changes to 1 files | |
|
89 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
90 | applying patch from stdin | |
|
91 | patching file a | |
|
92 | transaction abort! | |
|
93 | rollback completed | |
|
94 | % hg export in email, should use patch header | |
|
95 | requesting all changes | |
|
96 | adding changesets | |
|
97 | adding manifests | |
|
98 | adding file changes | |
|
99 | added 1 changesets with 1 changes to 1 files | |
|
100 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
|
101 | applying patch from stdin | |
|
102 | patching file a | |
|
103 | summary: second change |
@@ -1,3539 +1,3544 b'' | |||
|
1 | 1 | # commands.py - command processing for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | from demandload import demandload |
|
9 | 9 | from node import * |
|
10 | 10 | from i18n import gettext as _ |
|
11 | 11 | demandload(globals(), "os re sys signal shutil imp urllib pdb") |
|
12 | 12 | demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo") |
|
13 | 13 | demandload(globals(), "fnmatch mdiff random signal tempfile time") |
|
14 | 14 | demandload(globals(), "traceback errno socket version struct atexit sets bz2") |
|
15 | 15 | demandload(globals(), "archival cStringIO changegroup email.Parser") |
|
16 | 16 | demandload(globals(), "hgweb.server sshserver") |
|
17 | 17 | |
|
18 | 18 | class UnknownCommand(Exception): |
|
19 | 19 | """Exception raised if command is not in the command table.""" |
|
20 | 20 | class AmbiguousCommand(Exception): |
|
21 | 21 | """Exception raised if command shortcut matches more than one command.""" |
|
22 | 22 | |
|
23 | 23 | def bail_if_changed(repo): |
|
24 | 24 | modified, added, removed, deleted, unknown = repo.changes() |
|
25 | 25 | if modified or added or removed or deleted: |
|
26 | 26 | raise util.Abort(_("outstanding uncommitted changes")) |
|
27 | 27 | |
|
28 | 28 | def filterfiles(filters, files): |
|
29 | 29 | l = [x for x in files if x in filters] |
|
30 | 30 | |
|
31 | 31 | for t in filters: |
|
32 | 32 | if t and t[-1] != "/": |
|
33 | 33 | t += "/" |
|
34 | 34 | l += [x for x in files if x.startswith(t)] |
|
35 | 35 | return l |
|
36 | 36 | |
|
37 | 37 | def relpath(repo, args): |
|
38 | 38 | cwd = repo.getcwd() |
|
39 | 39 | if cwd: |
|
40 | 40 | return [util.normpath(os.path.join(cwd, x)) for x in args] |
|
41 | 41 | return args |
|
42 | 42 | |
|
43 | 43 | def matchpats(repo, pats=[], opts={}, head=''): |
|
44 | 44 | cwd = repo.getcwd() |
|
45 | 45 | if not pats and cwd: |
|
46 | 46 | opts['include'] = [os.path.join(cwd, i) for i in opts['include']] |
|
47 | 47 | opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']] |
|
48 | 48 | cwd = '' |
|
49 | 49 | return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'), |
|
50 | 50 | opts.get('exclude'), head) |
|
51 | 51 | |
|
52 | 52 | def makewalk(repo, pats, opts, node=None, head='', badmatch=None): |
|
53 | 53 | files, matchfn, anypats = matchpats(repo, pats, opts, head) |
|
54 | 54 | exact = dict(zip(files, files)) |
|
55 | 55 | def walk(): |
|
56 | 56 | for src, fn in repo.walk(node=node, files=files, match=matchfn, |
|
57 | 57 | badmatch=badmatch): |
|
58 | 58 | yield src, fn, util.pathto(repo.getcwd(), fn), fn in exact |
|
59 | 59 | return files, matchfn, walk() |
|
60 | 60 | |
|
61 | 61 | def walk(repo, pats, opts, node=None, head='', badmatch=None): |
|
62 | 62 | files, matchfn, results = makewalk(repo, pats, opts, node, head, badmatch) |
|
63 | 63 | for r in results: |
|
64 | 64 | yield r |
|
65 | 65 | |
|
66 | 66 | def walkchangerevs(ui, repo, pats, opts): |
|
67 | 67 | '''Iterate over files and the revs they changed in. |
|
68 | 68 | |
|
69 | 69 | Callers most commonly need to iterate backwards over the history |
|
70 | 70 | it is interested in. Doing so has awful (quadratic-looking) |
|
71 | 71 | performance, so we use iterators in a "windowed" way. |
|
72 | 72 | |
|
73 | 73 | We walk a window of revisions in the desired order. Within the |
|
74 | 74 | window, we first walk forwards to gather data, then in the desired |
|
75 | 75 | order (usually backwards) to display it. |
|
76 | 76 | |
|
77 | 77 | This function returns an (iterator, getchange, matchfn) tuple. The |
|
78 | 78 | getchange function returns the changelog entry for a numeric |
|
79 | 79 | revision. The iterator yields 3-tuples. They will be of one of |
|
80 | 80 | the following forms: |
|
81 | 81 | |
|
82 | 82 | "window", incrementing, lastrev: stepping through a window, |
|
83 | 83 | positive if walking forwards through revs, last rev in the |
|
84 | 84 | sequence iterated over - use to reset state for the current window |
|
85 | 85 | |
|
86 | 86 | "add", rev, fns: out-of-order traversal of the given file names |
|
87 | 87 | fns, which changed during revision rev - use to gather data for |
|
88 | 88 | possible display |
|
89 | 89 | |
|
90 | 90 | "iter", rev, None: in-order traversal of the revs earlier iterated |
|
91 | 91 | over with "add" - use to display data''' |
|
92 | 92 | |
|
93 | 93 | def increasing_windows(start, end, windowsize=8, sizelimit=512): |
|
94 | 94 | if start < end: |
|
95 | 95 | while start < end: |
|
96 | 96 | yield start, min(windowsize, end-start) |
|
97 | 97 | start += windowsize |
|
98 | 98 | if windowsize < sizelimit: |
|
99 | 99 | windowsize *= 2 |
|
100 | 100 | else: |
|
101 | 101 | while start > end: |
|
102 | 102 | yield start, min(windowsize, start-end-1) |
|
103 | 103 | start -= windowsize |
|
104 | 104 | if windowsize < sizelimit: |
|
105 | 105 | windowsize *= 2 |
|
106 | 106 | |
|
107 | 107 | |
|
108 | 108 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
109 | 109 | |
|
110 | 110 | if repo.changelog.count() == 0: |
|
111 | 111 | return [], False, matchfn |
|
112 | 112 | |
|
113 | 113 | revs = map(int, revrange(ui, repo, opts['rev'] or ['tip:0'])) |
|
114 | 114 | wanted = {} |
|
115 | 115 | slowpath = anypats |
|
116 | 116 | fncache = {} |
|
117 | 117 | |
|
118 | 118 | chcache = {} |
|
119 | 119 | def getchange(rev): |
|
120 | 120 | ch = chcache.get(rev) |
|
121 | 121 | if ch is None: |
|
122 | 122 | chcache[rev] = ch = repo.changelog.read(repo.lookup(str(rev))) |
|
123 | 123 | return ch |
|
124 | 124 | |
|
125 | 125 | if not slowpath and not files: |
|
126 | 126 | # No files, no patterns. Display all revs. |
|
127 | 127 | wanted = dict(zip(revs, revs)) |
|
128 | 128 | if not slowpath: |
|
129 | 129 | # Only files, no patterns. Check the history of each file. |
|
130 | 130 | def filerevgen(filelog): |
|
131 | 131 | for i, window in increasing_windows(filelog.count()-1, -1): |
|
132 | 132 | revs = [] |
|
133 | 133 | for j in xrange(i - window, i + 1): |
|
134 | 134 | revs.append(filelog.linkrev(filelog.node(j))) |
|
135 | 135 | revs.reverse() |
|
136 | 136 | for rev in revs: |
|
137 | 137 | yield rev |
|
138 | 138 | |
|
139 | 139 | minrev, maxrev = min(revs), max(revs) |
|
140 | 140 | for file_ in files: |
|
141 | 141 | filelog = repo.file(file_) |
|
142 | 142 | # A zero count may be a directory or deleted file, so |
|
143 | 143 | # try to find matching entries on the slow path. |
|
144 | 144 | if filelog.count() == 0: |
|
145 | 145 | slowpath = True |
|
146 | 146 | break |
|
147 | 147 | for rev in filerevgen(filelog): |
|
148 | 148 | if rev <= maxrev: |
|
149 | 149 | if rev < minrev: |
|
150 | 150 | break |
|
151 | 151 | fncache.setdefault(rev, []) |
|
152 | 152 | fncache[rev].append(file_) |
|
153 | 153 | wanted[rev] = 1 |
|
154 | 154 | if slowpath: |
|
155 | 155 | # The slow path checks files modified in every changeset. |
|
156 | 156 | def changerevgen(): |
|
157 | 157 | for i, window in increasing_windows(repo.changelog.count()-1, -1): |
|
158 | 158 | for j in xrange(i - window, i + 1): |
|
159 | 159 | yield j, getchange(j)[3] |
|
160 | 160 | |
|
161 | 161 | for rev, changefiles in changerevgen(): |
|
162 | 162 | matches = filter(matchfn, changefiles) |
|
163 | 163 | if matches: |
|
164 | 164 | fncache[rev] = matches |
|
165 | 165 | wanted[rev] = 1 |
|
166 | 166 | |
|
167 | 167 | def iterate(): |
|
168 | 168 | for i, window in increasing_windows(0, len(revs)): |
|
169 | 169 | yield 'window', revs[0] < revs[-1], revs[-1] |
|
170 | 170 | nrevs = [rev for rev in revs[i:i+window] |
|
171 | 171 | if rev in wanted] |
|
172 | 172 | srevs = list(nrevs) |
|
173 | 173 | srevs.sort() |
|
174 | 174 | for rev in srevs: |
|
175 | 175 | fns = fncache.get(rev) or filter(matchfn, getchange(rev)[3]) |
|
176 | 176 | yield 'add', rev, fns |
|
177 | 177 | for rev in nrevs: |
|
178 | 178 | yield 'iter', rev, None |
|
179 | 179 | return iterate(), getchange, matchfn |
|
180 | 180 | |
|
181 | 181 | revrangesep = ':' |
|
182 | 182 | |
|
183 | 183 | def revfix(repo, val, defval): |
|
184 | 184 | '''turn user-level id of changeset into rev number. |
|
185 | 185 | user-level id can be tag, changeset, rev number, or negative rev |
|
186 | 186 | number relative to number of revs (-1 is tip, etc).''' |
|
187 | 187 | if not val: |
|
188 | 188 | return defval |
|
189 | 189 | try: |
|
190 | 190 | num = int(val) |
|
191 | 191 | if str(num) != val: |
|
192 | 192 | raise ValueError |
|
193 | 193 | if num < 0: |
|
194 | 194 | num += repo.changelog.count() |
|
195 | 195 | if num < 0: |
|
196 | 196 | num = 0 |
|
197 | 197 | elif num >= repo.changelog.count(): |
|
198 | 198 | raise ValueError |
|
199 | 199 | except ValueError: |
|
200 | 200 | try: |
|
201 | 201 | num = repo.changelog.rev(repo.lookup(val)) |
|
202 | 202 | except KeyError: |
|
203 | 203 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
204 | 204 | return num |
|
205 | 205 | |
|
206 | 206 | def revpair(ui, repo, revs): |
|
207 | 207 | '''return pair of nodes, given list of revisions. second item can |
|
208 | 208 | be None, meaning use working dir.''' |
|
209 | 209 | if not revs: |
|
210 | 210 | return repo.dirstate.parents()[0], None |
|
211 | 211 | end = None |
|
212 | 212 | if len(revs) == 1: |
|
213 | 213 | start = revs[0] |
|
214 | 214 | if revrangesep in start: |
|
215 | 215 | start, end = start.split(revrangesep, 1) |
|
216 | 216 | start = revfix(repo, start, 0) |
|
217 | 217 | end = revfix(repo, end, repo.changelog.count() - 1) |
|
218 | 218 | else: |
|
219 | 219 | start = revfix(repo, start, None) |
|
220 | 220 | elif len(revs) == 2: |
|
221 | 221 | if revrangesep in revs[0] or revrangesep in revs[1]: |
|
222 | 222 | raise util.Abort(_('too many revisions specified')) |
|
223 | 223 | start = revfix(repo, revs[0], None) |
|
224 | 224 | end = revfix(repo, revs[1], None) |
|
225 | 225 | else: |
|
226 | 226 | raise util.Abort(_('too many revisions specified')) |
|
227 | 227 | if end is not None: end = repo.lookup(str(end)) |
|
228 | 228 | return repo.lookup(str(start)), end |
|
229 | 229 | |
|
230 | 230 | def revrange(ui, repo, revs): |
|
231 | 231 | """Yield revision as strings from a list of revision specifications.""" |
|
232 | 232 | seen = {} |
|
233 | 233 | for spec in revs: |
|
234 | 234 | if spec.find(revrangesep) >= 0: |
|
235 | 235 | start, end = spec.split(revrangesep, 1) |
|
236 | 236 | start = revfix(repo, start, 0) |
|
237 | 237 | end = revfix(repo, end, repo.changelog.count() - 1) |
|
238 | 238 | step = start > end and -1 or 1 |
|
239 | 239 | for rev in xrange(start, end+step, step): |
|
240 | 240 | if rev in seen: |
|
241 | 241 | continue |
|
242 | 242 | seen[rev] = 1 |
|
243 | 243 | yield str(rev) |
|
244 | 244 | else: |
|
245 | 245 | rev = revfix(repo, spec, None) |
|
246 | 246 | if rev in seen: |
|
247 | 247 | continue |
|
248 | 248 | seen[rev] = 1 |
|
249 | 249 | yield str(rev) |
|
250 | 250 | |
|
251 | 251 | def make_filename(repo, r, pat, node=None, |
|
252 | 252 | total=None, seqno=None, revwidth=None, pathname=None): |
|
253 | 253 | node_expander = { |
|
254 | 254 | 'H': lambda: hex(node), |
|
255 | 255 | 'R': lambda: str(r.rev(node)), |
|
256 | 256 | 'h': lambda: short(node), |
|
257 | 257 | } |
|
258 | 258 | expander = { |
|
259 | 259 | '%': lambda: '%', |
|
260 | 260 | 'b': lambda: os.path.basename(repo.root), |
|
261 | 261 | } |
|
262 | 262 | |
|
263 | 263 | try: |
|
264 | 264 | if node: |
|
265 | 265 | expander.update(node_expander) |
|
266 | 266 | if node and revwidth is not None: |
|
267 | 267 | expander['r'] = lambda: str(r.rev(node)).zfill(revwidth) |
|
268 | 268 | if total is not None: |
|
269 | 269 | expander['N'] = lambda: str(total) |
|
270 | 270 | if seqno is not None: |
|
271 | 271 | expander['n'] = lambda: str(seqno) |
|
272 | 272 | if total is not None and seqno is not None: |
|
273 | 273 | expander['n'] = lambda:str(seqno).zfill(len(str(total))) |
|
274 | 274 | if pathname is not None: |
|
275 | 275 | expander['s'] = lambda: os.path.basename(pathname) |
|
276 | 276 | expander['d'] = lambda: os.path.dirname(pathname) or '.' |
|
277 | 277 | expander['p'] = lambda: pathname |
|
278 | 278 | |
|
279 | 279 | newname = [] |
|
280 | 280 | patlen = len(pat) |
|
281 | 281 | i = 0 |
|
282 | 282 | while i < patlen: |
|
283 | 283 | c = pat[i] |
|
284 | 284 | if c == '%': |
|
285 | 285 | i += 1 |
|
286 | 286 | c = pat[i] |
|
287 | 287 | c = expander[c]() |
|
288 | 288 | newname.append(c) |
|
289 | 289 | i += 1 |
|
290 | 290 | return ''.join(newname) |
|
291 | 291 | except KeyError, inst: |
|
292 | 292 | raise util.Abort(_("invalid format spec '%%%s' in output file name"), |
|
293 | 293 | inst.args[0]) |
|
294 | 294 | |
|
295 | 295 | def make_file(repo, r, pat, node=None, |
|
296 | 296 | total=None, seqno=None, revwidth=None, mode='wb', pathname=None): |
|
297 | 297 | if not pat or pat == '-': |
|
298 | 298 | return 'w' in mode and sys.stdout or sys.stdin |
|
299 | 299 | if hasattr(pat, 'write') and 'w' in mode: |
|
300 | 300 | return pat |
|
301 | 301 | if hasattr(pat, 'read') and 'r' in mode: |
|
302 | 302 | return pat |
|
303 | 303 | return open(make_filename(repo, r, pat, node, total, seqno, revwidth, |
|
304 | 304 | pathname), |
|
305 | 305 | mode) |
|
306 | 306 | |
|
307 | 307 | def write_bundle(cg, filename=None, compress=True): |
|
308 | 308 | """Write a bundle file and return its filename. |
|
309 | 309 | |
|
310 | 310 | Existing files will not be overwritten. |
|
311 | 311 | If no filename is specified, a temporary file is created. |
|
312 | 312 | bz2 compression can be turned off. |
|
313 | 313 | The bundle file will be deleted in case of errors. |
|
314 | 314 | """ |
|
315 | 315 | class nocompress(object): |
|
316 | 316 | def compress(self, x): |
|
317 | 317 | return x |
|
318 | 318 | def flush(self): |
|
319 | 319 | return "" |
|
320 | 320 | |
|
321 | 321 | fh = None |
|
322 | 322 | cleanup = None |
|
323 | 323 | try: |
|
324 | 324 | if filename: |
|
325 | 325 | if os.path.exists(filename): |
|
326 | 326 | raise util.Abort(_("file '%s' already exists"), filename) |
|
327 | 327 | fh = open(filename, "wb") |
|
328 | 328 | else: |
|
329 | 329 | fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") |
|
330 | 330 | fh = os.fdopen(fd, "wb") |
|
331 | 331 | cleanup = filename |
|
332 | 332 | |
|
333 | 333 | if compress: |
|
334 | 334 | fh.write("HG10") |
|
335 | 335 | z = bz2.BZ2Compressor(9) |
|
336 | 336 | else: |
|
337 | 337 | fh.write("HG10UN") |
|
338 | 338 | z = nocompress() |
|
339 | 339 | # parse the changegroup data, otherwise we will block |
|
340 | 340 | # in case of sshrepo because we don't know the end of the stream |
|
341 | 341 | |
|
342 | 342 | # an empty chunkiter is the end of the changegroup |
|
343 | 343 | empty = False |
|
344 | 344 | while not empty: |
|
345 | 345 | empty = True |
|
346 | 346 | for chunk in changegroup.chunkiter(cg): |
|
347 | 347 | empty = False |
|
348 | 348 | fh.write(z.compress(changegroup.genchunk(chunk))) |
|
349 | 349 | fh.write(z.compress(changegroup.closechunk())) |
|
350 | 350 | fh.write(z.flush()) |
|
351 | 351 | cleanup = None |
|
352 | 352 | return filename |
|
353 | 353 | finally: |
|
354 | 354 | if fh is not None: |
|
355 | 355 | fh.close() |
|
356 | 356 | if cleanup is not None: |
|
357 | 357 | os.unlink(cleanup) |
|
358 | 358 | |
|
359 | 359 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
360 | 360 | changes=None, text=False, opts={}): |
|
361 | 361 | if not node1: |
|
362 | 362 | node1 = repo.dirstate.parents()[0] |
|
363 | 363 | # reading the data for node1 early allows it to play nicely |
|
364 | 364 | # with repo.changes and the revlog cache. |
|
365 | 365 | change = repo.changelog.read(node1) |
|
366 | 366 | mmap = repo.manifest.read(change[0]) |
|
367 | 367 | date1 = util.datestr(change[2]) |
|
368 | 368 | |
|
369 | 369 | if not changes: |
|
370 | 370 | changes = repo.changes(node1, node2, files, match=match) |
|
371 | 371 | modified, added, removed, deleted, unknown = changes |
|
372 | 372 | if files: |
|
373 | 373 | modified, added, removed = map(lambda x: filterfiles(files, x), |
|
374 | 374 | (modified, added, removed)) |
|
375 | 375 | |
|
376 | 376 | if not modified and not added and not removed: |
|
377 | 377 | return |
|
378 | 378 | |
|
379 | 379 | if node2: |
|
380 | 380 | change = repo.changelog.read(node2) |
|
381 | 381 | mmap2 = repo.manifest.read(change[0]) |
|
382 | 382 | _date2 = util.datestr(change[2]) |
|
383 | 383 | def date2(f): |
|
384 | 384 | return _date2 |
|
385 | 385 | def read(f): |
|
386 | 386 | return repo.file(f).read(mmap2[f]) |
|
387 | 387 | else: |
|
388 | 388 | tz = util.makedate()[1] |
|
389 | 389 | _date2 = util.datestr() |
|
390 | 390 | def date2(f): |
|
391 | 391 | try: |
|
392 | 392 | return util.datestr((os.lstat(repo.wjoin(f)).st_mtime, tz)) |
|
393 | 393 | except OSError, err: |
|
394 | 394 | if err.errno != errno.ENOENT: raise |
|
395 | 395 | return _date2 |
|
396 | 396 | def read(f): |
|
397 | 397 | return repo.wread(f) |
|
398 | 398 | |
|
399 | 399 | if ui.quiet: |
|
400 | 400 | r = None |
|
401 | 401 | else: |
|
402 | 402 | hexfunc = ui.verbose and hex or short |
|
403 | 403 | r = [hexfunc(node) for node in [node1, node2] if node] |
|
404 | 404 | |
|
405 | 405 | diffopts = ui.diffopts() |
|
406 | 406 | showfunc = opts.get('show_function') or diffopts['showfunc'] |
|
407 | 407 | ignorews = opts.get('ignore_all_space') or diffopts['ignorews'] |
|
408 | 408 | for f in modified: |
|
409 | 409 | to = None |
|
410 | 410 | if f in mmap: |
|
411 | 411 | to = repo.file(f).read(mmap[f]) |
|
412 | 412 | tn = read(f) |
|
413 | 413 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text, |
|
414 | 414 | showfunc=showfunc, ignorews=ignorews)) |
|
415 | 415 | for f in added: |
|
416 | 416 | to = None |
|
417 | 417 | tn = read(f) |
|
418 | 418 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text, |
|
419 | 419 | showfunc=showfunc, ignorews=ignorews)) |
|
420 | 420 | for f in removed: |
|
421 | 421 | to = repo.file(f).read(mmap[f]) |
|
422 | 422 | tn = None |
|
423 | 423 | fp.write(mdiff.unidiff(to, date1, tn, date2(f), f, r, text=text, |
|
424 | 424 | showfunc=showfunc, ignorews=ignorews)) |
|
425 | 425 | |
|
426 | 426 | def trimuser(ui, name, rev, revcache): |
|
427 | 427 | """trim the name of the user who committed a change""" |
|
428 | 428 | user = revcache.get(rev) |
|
429 | 429 | if user is None: |
|
430 | 430 | user = revcache[rev] = ui.shortuser(name) |
|
431 | 431 | return user |
|
432 | 432 | |
|
433 | 433 | class changeset_printer(object): |
|
434 | 434 | '''show changeset information when templating not requested.''' |
|
435 | 435 | |
|
436 | 436 | def __init__(self, ui, repo): |
|
437 | 437 | self.ui = ui |
|
438 | 438 | self.repo = repo |
|
439 | 439 | |
|
440 | 440 | def show(self, rev=0, changenode=None, brinfo=None): |
|
441 | 441 | '''show a single changeset or file revision''' |
|
442 | 442 | log = self.repo.changelog |
|
443 | 443 | if changenode is None: |
|
444 | 444 | changenode = log.node(rev) |
|
445 | 445 | elif not rev: |
|
446 | 446 | rev = log.rev(changenode) |
|
447 | 447 | |
|
448 | 448 | if self.ui.quiet: |
|
449 | 449 | self.ui.write("%d:%s\n" % (rev, short(changenode))) |
|
450 | 450 | return |
|
451 | 451 | |
|
452 | 452 | changes = log.read(changenode) |
|
453 | 453 | date = util.datestr(changes[2]) |
|
454 | 454 | |
|
455 | 455 | parents = [(log.rev(p), self.ui.verbose and hex(p) or short(p)) |
|
456 | 456 | for p in log.parents(changenode) |
|
457 | 457 | if self.ui.debugflag or p != nullid] |
|
458 | 458 | if (not self.ui.debugflag and len(parents) == 1 and |
|
459 | 459 | parents[0][0] == rev-1): |
|
460 | 460 | parents = [] |
|
461 | 461 | |
|
462 | 462 | if self.ui.verbose: |
|
463 | 463 | self.ui.write(_("changeset: %d:%s\n") % (rev, hex(changenode))) |
|
464 | 464 | else: |
|
465 | 465 | self.ui.write(_("changeset: %d:%s\n") % (rev, short(changenode))) |
|
466 | 466 | |
|
467 | 467 | for tag in self.repo.nodetags(changenode): |
|
468 | 468 | self.ui.status(_("tag: %s\n") % tag) |
|
469 | 469 | for parent in parents: |
|
470 | 470 | self.ui.write(_("parent: %d:%s\n") % parent) |
|
471 | 471 | |
|
472 | 472 | if brinfo and changenode in brinfo: |
|
473 | 473 | br = brinfo[changenode] |
|
474 | 474 | self.ui.write(_("branch: %s\n") % " ".join(br)) |
|
475 | 475 | |
|
476 | 476 | self.ui.debug(_("manifest: %d:%s\n") % |
|
477 | 477 | (self.repo.manifest.rev(changes[0]), hex(changes[0]))) |
|
478 | 478 | self.ui.status(_("user: %s\n") % changes[1]) |
|
479 | 479 | self.ui.status(_("date: %s\n") % date) |
|
480 | 480 | |
|
481 | 481 | if self.ui.debugflag: |
|
482 | 482 | files = self.repo.changes(log.parents(changenode)[0], changenode) |
|
483 | 483 | for key, value in zip([_("files:"), _("files+:"), _("files-:")], |
|
484 | 484 | files): |
|
485 | 485 | if value: |
|
486 | 486 | self.ui.note("%-12s %s\n" % (key, " ".join(value))) |
|
487 | 487 | else: |
|
488 | 488 | self.ui.note(_("files: %s\n") % " ".join(changes[3])) |
|
489 | 489 | |
|
490 | 490 | description = changes[4].strip() |
|
491 | 491 | if description: |
|
492 | 492 | if self.ui.verbose: |
|
493 | 493 | self.ui.status(_("description:\n")) |
|
494 | 494 | self.ui.status(description) |
|
495 | 495 | self.ui.status("\n\n") |
|
496 | 496 | else: |
|
497 | 497 | self.ui.status(_("summary: %s\n") % |
|
498 | 498 | description.splitlines()[0]) |
|
499 | 499 | self.ui.status("\n") |
|
500 | 500 | |
|
501 | 501 | def show_changeset(ui, repo, opts): |
|
502 | 502 | '''show one changeset. uses template or regular display. caller |
|
503 | 503 | can pass in 'style' and 'template' options in opts.''' |
|
504 | 504 | |
|
505 | 505 | tmpl = opts.get('template') |
|
506 | 506 | if tmpl: |
|
507 | 507 | tmpl = templater.parsestring(tmpl, quoted=False) |
|
508 | 508 | else: |
|
509 | 509 | tmpl = ui.config('ui', 'logtemplate') |
|
510 | 510 | if tmpl: tmpl = templater.parsestring(tmpl) |
|
511 | 511 | mapfile = opts.get('style') or ui.config('ui', 'style') |
|
512 | 512 | if tmpl or mapfile: |
|
513 | 513 | if mapfile: |
|
514 | 514 | if not os.path.isfile(mapfile): |
|
515 | 515 | mapname = templater.templatepath('map-cmdline.' + mapfile) |
|
516 | 516 | if not mapname: mapname = templater.templatepath(mapfile) |
|
517 | 517 | if mapname: mapfile = mapname |
|
518 | 518 | try: |
|
519 | 519 | t = templater.changeset_templater(ui, repo, mapfile) |
|
520 | 520 | except SyntaxError, inst: |
|
521 | 521 | raise util.Abort(inst.args[0]) |
|
522 | 522 | if tmpl: t.use_template(tmpl) |
|
523 | 523 | return t |
|
524 | 524 | return changeset_printer(ui, repo) |
|
525 | 525 | |
|
526 | 526 | def show_version(ui): |
|
527 | 527 | """output version and copyright information""" |
|
528 | 528 | ui.write(_("Mercurial Distributed SCM (version %s)\n") |
|
529 | 529 | % version.get_version()) |
|
530 | 530 | ui.status(_( |
|
531 | 531 | "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n" |
|
532 | 532 | "This is free software; see the source for copying conditions. " |
|
533 | 533 | "There is NO\nwarranty; " |
|
534 | 534 | "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" |
|
535 | 535 | )) |
|
536 | 536 | |
|
537 | 537 | def help_(ui, cmd=None, with_version=False): |
|
538 | 538 | """show help for a given command or all commands""" |
|
539 | 539 | option_lists = [] |
|
540 | 540 | if cmd and cmd != 'shortlist': |
|
541 | 541 | if with_version: |
|
542 | 542 | show_version(ui) |
|
543 | 543 | ui.write('\n') |
|
544 | 544 | aliases, i = find(cmd) |
|
545 | 545 | # synopsis |
|
546 | 546 | ui.write("%s\n\n" % i[2]) |
|
547 | 547 | |
|
548 | 548 | # description |
|
549 | 549 | doc = i[0].__doc__ |
|
550 | 550 | if not doc: |
|
551 | 551 | doc = _("(No help text available)") |
|
552 | 552 | if ui.quiet: |
|
553 | 553 | doc = doc.splitlines(0)[0] |
|
554 | 554 | ui.write("%s\n" % doc.rstrip()) |
|
555 | 555 | |
|
556 | 556 | if not ui.quiet: |
|
557 | 557 | # aliases |
|
558 | 558 | if len(aliases) > 1: |
|
559 | 559 | ui.write(_("\naliases: %s\n") % ', '.join(aliases[1:])) |
|
560 | 560 | |
|
561 | 561 | # options |
|
562 | 562 | if i[1]: |
|
563 | 563 | option_lists.append(("options", i[1])) |
|
564 | 564 | |
|
565 | 565 | else: |
|
566 | 566 | # program name |
|
567 | 567 | if ui.verbose or with_version: |
|
568 | 568 | show_version(ui) |
|
569 | 569 | else: |
|
570 | 570 | ui.status(_("Mercurial Distributed SCM\n")) |
|
571 | 571 | ui.status('\n') |
|
572 | 572 | |
|
573 | 573 | # list of commands |
|
574 | 574 | if cmd == "shortlist": |
|
575 | 575 | ui.status(_('basic commands (use "hg help" ' |
|
576 | 576 | 'for the full list or option "-v" for details):\n\n')) |
|
577 | 577 | elif ui.verbose: |
|
578 | 578 | ui.status(_('list of commands:\n\n')) |
|
579 | 579 | else: |
|
580 | 580 | ui.status(_('list of commands (use "hg help -v" ' |
|
581 | 581 | 'to show aliases and global options):\n\n')) |
|
582 | 582 | |
|
583 | 583 | h = {} |
|
584 | 584 | cmds = {} |
|
585 | 585 | for c, e in table.items(): |
|
586 | 586 | f = c.split("|")[0] |
|
587 | 587 | if cmd == "shortlist" and not f.startswith("^"): |
|
588 | 588 | continue |
|
589 | 589 | f = f.lstrip("^") |
|
590 | 590 | if not ui.debugflag and f.startswith("debug"): |
|
591 | 591 | continue |
|
592 | 592 | doc = e[0].__doc__ |
|
593 | 593 | if not doc: |
|
594 | 594 | doc = _("(No help text available)") |
|
595 | 595 | h[f] = doc.splitlines(0)[0].rstrip() |
|
596 | 596 | cmds[f] = c.lstrip("^") |
|
597 | 597 | |
|
598 | 598 | fns = h.keys() |
|
599 | 599 | fns.sort() |
|
600 | 600 | m = max(map(len, fns)) |
|
601 | 601 | for f in fns: |
|
602 | 602 | if ui.verbose: |
|
603 | 603 | commands = cmds[f].replace("|",", ") |
|
604 | 604 | ui.write(" %s:\n %s\n"%(commands, h[f])) |
|
605 | 605 | else: |
|
606 | 606 | ui.write(' %-*s %s\n' % (m, f, h[f])) |
|
607 | 607 | |
|
608 | 608 | # global options |
|
609 | 609 | if ui.verbose: |
|
610 | 610 | option_lists.append(("global options", globalopts)) |
|
611 | 611 | |
|
612 | 612 | # list all option lists |
|
613 | 613 | opt_output = [] |
|
614 | 614 | for title, options in option_lists: |
|
615 | 615 | opt_output.append(("\n%s:\n" % title, None)) |
|
616 | 616 | for shortopt, longopt, default, desc in options: |
|
617 | 617 | opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt, |
|
618 | 618 | longopt and " --%s" % longopt), |
|
619 | 619 | "%s%s" % (desc, |
|
620 | 620 | default |
|
621 | 621 | and _(" (default: %s)") % default |
|
622 | 622 | or ""))) |
|
623 | 623 | |
|
624 | 624 | if opt_output: |
|
625 | 625 | opts_len = max([len(line[0]) for line in opt_output if line[1]]) |
|
626 | 626 | for first, second in opt_output: |
|
627 | 627 | if second: |
|
628 | 628 | ui.write(" %-*s %s\n" % (opts_len, first, second)) |
|
629 | 629 | else: |
|
630 | 630 | ui.write("%s\n" % first) |
|
631 | 631 | |
|
632 | 632 | # Commands start here, listed alphabetically |
|
633 | 633 | |
|
634 | 634 | def add(ui, repo, *pats, **opts): |
|
635 | 635 | """add the specified files on the next commit |
|
636 | 636 | |
|
637 | 637 | Schedule files to be version controlled and added to the repository. |
|
638 | 638 | |
|
639 | 639 | The files will be added to the repository at the next commit. |
|
640 | 640 | |
|
641 | 641 | If no names are given, add all files in the repository. |
|
642 | 642 | """ |
|
643 | 643 | |
|
644 | 644 | names = [] |
|
645 | 645 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
646 | 646 | if exact: |
|
647 | 647 | if ui.verbose: |
|
648 | 648 | ui.status(_('adding %s\n') % rel) |
|
649 | 649 | names.append(abs) |
|
650 | 650 | elif repo.dirstate.state(abs) == '?': |
|
651 | 651 | ui.status(_('adding %s\n') % rel) |
|
652 | 652 | names.append(abs) |
|
653 | 653 | if not opts.get('dry_run'): |
|
654 | 654 | repo.add(names) |
|
655 | 655 | |
|
656 | 656 | def addremove(ui, repo, *pats, **opts): |
|
657 | 657 | """add all new files, delete all missing files (DEPRECATED) |
|
658 | 658 | |
|
659 | 659 | (DEPRECATED) |
|
660 | 660 | Add all new files and remove all missing files from the repository. |
|
661 | 661 | |
|
662 | 662 | New files are ignored if they match any of the patterns in .hgignore. As |
|
663 | 663 | with add, these changes take effect at the next commit. |
|
664 | 664 | |
|
665 | 665 | This command is now deprecated and will be removed in a future |
|
666 | 666 | release. Please use add and remove --after instead. |
|
667 | 667 | """ |
|
668 | 668 | ui.warn(_('(the addremove command is deprecated; use add and remove ' |
|
669 | 669 | '--after instead)\n')) |
|
670 | 670 | return addremove_lock(ui, repo, pats, opts) |
|
671 | 671 | |
|
672 | 672 | def addremove_lock(ui, repo, pats, opts, wlock=None): |
|
673 | 673 | add, remove = [], [] |
|
674 | 674 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
675 | 675 | if src == 'f' and repo.dirstate.state(abs) == '?': |
|
676 | 676 | add.append(abs) |
|
677 | 677 | if ui.verbose or not exact: |
|
678 | 678 | ui.status(_('adding %s\n') % ((pats and rel) or abs)) |
|
679 | 679 | if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel): |
|
680 | 680 | remove.append(abs) |
|
681 | 681 | if ui.verbose or not exact: |
|
682 | 682 | ui.status(_('removing %s\n') % ((pats and rel) or abs)) |
|
683 | 683 | if not opts.get('dry_run'): |
|
684 | 684 | repo.add(add, wlock=wlock) |
|
685 | 685 | repo.remove(remove, wlock=wlock) |
|
686 | 686 | |
|
687 | 687 | def annotate(ui, repo, *pats, **opts): |
|
688 | 688 | """show changeset information per file line |
|
689 | 689 | |
|
690 | 690 | List changes in files, showing the revision id responsible for each line |
|
691 | 691 | |
|
692 | 692 | This command is useful to discover who did a change or when a change took |
|
693 | 693 | place. |
|
694 | 694 | |
|
695 | 695 | Without the -a option, annotate will avoid processing files it |
|
696 | 696 | detects as binary. With -a, annotate will generate an annotation |
|
697 | 697 | anyway, probably with undesirable results. |
|
698 | 698 | """ |
|
699 | 699 | def getnode(rev): |
|
700 | 700 | return short(repo.changelog.node(rev)) |
|
701 | 701 | |
|
702 | 702 | ucache = {} |
|
703 | 703 | def getname(rev): |
|
704 | 704 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
705 | 705 | return trimuser(ui, cl[1], rev, ucache) |
|
706 | 706 | |
|
707 | 707 | dcache = {} |
|
708 | 708 | def getdate(rev): |
|
709 | 709 | datestr = dcache.get(rev) |
|
710 | 710 | if datestr is None: |
|
711 | 711 | cl = repo.changelog.read(repo.changelog.node(rev)) |
|
712 | 712 | datestr = dcache[rev] = util.datestr(cl[2]) |
|
713 | 713 | return datestr |
|
714 | 714 | |
|
715 | 715 | if not pats: |
|
716 | 716 | raise util.Abort(_('at least one file name or pattern required')) |
|
717 | 717 | |
|
718 | 718 | opmap = [['user', getname], ['number', str], ['changeset', getnode], |
|
719 | 719 | ['date', getdate]] |
|
720 | 720 | if not opts['user'] and not opts['changeset'] and not opts['date']: |
|
721 | 721 | opts['number'] = 1 |
|
722 | 722 | |
|
723 | 723 | if opts['rev']: |
|
724 | 724 | node = repo.changelog.lookup(opts['rev']) |
|
725 | 725 | else: |
|
726 | 726 | node = repo.dirstate.parents()[0] |
|
727 | 727 | change = repo.changelog.read(node) |
|
728 | 728 | mmap = repo.manifest.read(change[0]) |
|
729 | 729 | |
|
730 | 730 | for src, abs, rel, exact in walk(repo, pats, opts, node=node): |
|
731 | 731 | f = repo.file(abs) |
|
732 | 732 | if not opts['text'] and util.binary(f.read(mmap[abs])): |
|
733 | 733 | ui.write(_("%s: binary file\n") % ((pats and rel) or abs)) |
|
734 | 734 | continue |
|
735 | 735 | |
|
736 | 736 | lines = f.annotate(mmap[abs]) |
|
737 | 737 | pieces = [] |
|
738 | 738 | |
|
739 | 739 | for o, f in opmap: |
|
740 | 740 | if opts[o]: |
|
741 | 741 | l = [f(n) for n, dummy in lines] |
|
742 | 742 | if l: |
|
743 | 743 | m = max(map(len, l)) |
|
744 | 744 | pieces.append(["%*s" % (m, x) for x in l]) |
|
745 | 745 | |
|
746 | 746 | if pieces: |
|
747 | 747 | for p, l in zip(zip(*pieces), lines): |
|
748 | 748 | ui.write("%s: %s" % (" ".join(p), l[1])) |
|
749 | 749 | |
|
750 | 750 | def archive(ui, repo, dest, **opts): |
|
751 | 751 | '''create unversioned archive of a repository revision |
|
752 | 752 | |
|
753 | 753 | By default, the revision used is the parent of the working |
|
754 | 754 | directory; use "-r" to specify a different revision. |
|
755 | 755 | |
|
756 | 756 | To specify the type of archive to create, use "-t". Valid |
|
757 | 757 | types are: |
|
758 | 758 | |
|
759 | 759 | "files" (default): a directory full of files |
|
760 | 760 | "tar": tar archive, uncompressed |
|
761 | 761 | "tbz2": tar archive, compressed using bzip2 |
|
762 | 762 | "tgz": tar archive, compressed using gzip |
|
763 | 763 | "uzip": zip archive, uncompressed |
|
764 | 764 | "zip": zip archive, compressed using deflate |
|
765 | 765 | |
|
766 | 766 | The exact name of the destination archive or directory is given |
|
767 | 767 | using a format string; see "hg help export" for details. |
|
768 | 768 | |
|
769 | 769 | Each member added to an archive file has a directory prefix |
|
770 | 770 | prepended. Use "-p" to specify a format string for the prefix. |
|
771 | 771 | The default is the basename of the archive, with suffixes removed. |
|
772 | 772 | ''' |
|
773 | 773 | |
|
774 | 774 | if opts['rev']: |
|
775 | 775 | node = repo.lookup(opts['rev']) |
|
776 | 776 | else: |
|
777 | 777 | node, p2 = repo.dirstate.parents() |
|
778 | 778 | if p2 != nullid: |
|
779 | 779 | raise util.Abort(_('uncommitted merge - please provide a ' |
|
780 | 780 | 'specific revision')) |
|
781 | 781 | |
|
782 | 782 | dest = make_filename(repo, repo.changelog, dest, node) |
|
783 | 783 | if os.path.realpath(dest) == repo.root: |
|
784 | 784 | raise util.Abort(_('repository root cannot be destination')) |
|
785 | 785 | dummy, matchfn, dummy = matchpats(repo, [], opts) |
|
786 | 786 | kind = opts.get('type') or 'files' |
|
787 | 787 | prefix = opts['prefix'] |
|
788 | 788 | if dest == '-': |
|
789 | 789 | if kind == 'files': |
|
790 | 790 | raise util.Abort(_('cannot archive plain files to stdout')) |
|
791 | 791 | dest = sys.stdout |
|
792 | 792 | if not prefix: prefix = os.path.basename(repo.root) + '-%h' |
|
793 | 793 | prefix = make_filename(repo, repo.changelog, prefix, node) |
|
794 | 794 | archival.archive(repo, dest, node, kind, not opts['no_decode'], |
|
795 | 795 | matchfn, prefix) |
|
796 | 796 | |
|
797 | 797 | def backout(ui, repo, rev, **opts): |
|
798 | 798 | '''reverse effect of earlier changeset |
|
799 | 799 | |
|
800 | 800 | Commit the backed out changes as a new changeset. The new |
|
801 | 801 | changeset is a child of the backed out changeset. |
|
802 | 802 | |
|
803 | 803 | If you back out a changeset other than the tip, a new head is |
|
804 | 804 | created. This head is the parent of the working directory. If |
|
805 | 805 | you back out an old changeset, your working directory will appear |
|
806 | 806 | old after the backout. You should merge the backout changeset |
|
807 | 807 | with another head. |
|
808 | 808 | |
|
809 | 809 | The --merge option remembers the parent of the working directory |
|
810 | 810 | before starting the backout, then merges the new head with that |
|
811 | 811 | changeset afterwards. This saves you from doing the merge by |
|
812 | 812 | hand. The result of this merge is not committed, as for a normal |
|
813 | 813 | merge.''' |
|
814 | 814 | |
|
815 | 815 | bail_if_changed(repo) |
|
816 | 816 | op1, op2 = repo.dirstate.parents() |
|
817 | 817 | if op2 != nullid: |
|
818 | 818 | raise util.Abort(_('outstanding uncommitted merge')) |
|
819 | 819 | node = repo.lookup(rev) |
|
820 | 820 | parent, p2 = repo.changelog.parents(node) |
|
821 | 821 | if parent == nullid: |
|
822 | 822 | raise util.Abort(_('cannot back out a change with no parents')) |
|
823 | 823 | if p2 != nullid: |
|
824 | 824 | raise util.Abort(_('cannot back out a merge')) |
|
825 | 825 | repo.update(node, force=True, show_stats=False) |
|
826 | 826 | revert_opts = opts.copy() |
|
827 | 827 | revert_opts['rev'] = hex(parent) |
|
828 | 828 | revert(ui, repo, **revert_opts) |
|
829 | 829 | commit_opts = opts.copy() |
|
830 | 830 | commit_opts['addremove'] = False |
|
831 | 831 | if not commit_opts['message'] and not commit_opts['logfile']: |
|
832 | 832 | commit_opts['message'] = _("Backed out changeset %s") % (hex(node)) |
|
833 | 833 | commit_opts['force_editor'] = True |
|
834 | 834 | commit(ui, repo, **commit_opts) |
|
835 | 835 | def nice(node): |
|
836 | 836 | return '%d:%s' % (repo.changelog.rev(node), short(node)) |
|
837 | 837 | ui.status(_('changeset %s backs out changeset %s\n') % |
|
838 | 838 | (nice(repo.changelog.tip()), nice(node))) |
|
839 | 839 | if op1 != node: |
|
840 | 840 | if opts['merge']: |
|
841 | 841 | ui.status(_('merging with changeset %s\n') % nice(op1)) |
|
842 | 842 | doupdate(ui, repo, hex(op1), **opts) |
|
843 | 843 | else: |
|
844 | 844 | ui.status(_('the backout changeset is a new head - ' |
|
845 | 845 | 'do not forget to merge\n')) |
|
846 | 846 | ui.status(_('(use "backout -m" if you want to auto-merge)\n')) |
|
847 | 847 | |
|
848 | 848 | def bundle(ui, repo, fname, dest=None, **opts): |
|
849 | 849 | """create a changegroup file |
|
850 | 850 | |
|
851 | 851 | Generate a compressed changegroup file collecting all changesets |
|
852 | 852 | not found in the other repository. |
|
853 | 853 | |
|
854 | 854 | This file can then be transferred using conventional means and |
|
855 | 855 | applied to another repository with the unbundle command. This is |
|
856 | 856 | useful when native push and pull are not available or when |
|
857 | 857 | exporting an entire repository is undesirable. The standard file |
|
858 | 858 | extension is ".hg". |
|
859 | 859 | |
|
860 | 860 | Unlike import/export, this exactly preserves all changeset |
|
861 | 861 | contents including permissions, rename data, and revision history. |
|
862 | 862 | """ |
|
863 | 863 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
864 | 864 | other = hg.repository(ui, dest) |
|
865 | 865 | o = repo.findoutgoing(other, force=opts['force']) |
|
866 | 866 | cg = repo.changegroup(o, 'bundle') |
|
867 | 867 | write_bundle(cg, fname) |
|
868 | 868 | |
|
869 | 869 | def cat(ui, repo, file1, *pats, **opts): |
|
870 | 870 | """output the latest or given revisions of files |
|
871 | 871 | |
|
872 | 872 | Print the specified files as they were at the given revision. |
|
873 | 873 | If no revision is given then the tip is used. |
|
874 | 874 | |
|
875 | 875 | Output may be to a file, in which case the name of the file is |
|
876 | 876 | given using a format string. The formatting rules are the same as |
|
877 | 877 | for the export command, with the following additions: |
|
878 | 878 | |
|
879 | 879 | %s basename of file being printed |
|
880 | 880 | %d dirname of file being printed, or '.' if in repo root |
|
881 | 881 | %p root-relative path name of file being printed |
|
882 | 882 | """ |
|
883 | 883 | mf = {} |
|
884 | 884 | rev = opts['rev'] |
|
885 | 885 | if rev: |
|
886 | 886 | node = repo.lookup(rev) |
|
887 | 887 | else: |
|
888 | 888 | node = repo.changelog.tip() |
|
889 | 889 | change = repo.changelog.read(node) |
|
890 | 890 | mf = repo.manifest.read(change[0]) |
|
891 | 891 | for src, abs, rel, exact in walk(repo, (file1,) + pats, opts, node): |
|
892 | 892 | r = repo.file(abs) |
|
893 | 893 | n = mf[abs] |
|
894 | 894 | fp = make_file(repo, r, opts['output'], node=n, pathname=abs) |
|
895 | 895 | fp.write(r.read(n)) |
|
896 | 896 | |
|
897 | 897 | def clone(ui, source, dest=None, **opts): |
|
898 | 898 | """make a copy of an existing repository |
|
899 | 899 | |
|
900 | 900 | Create a copy of an existing repository in a new directory. |
|
901 | 901 | |
|
902 | 902 | If no destination directory name is specified, it defaults to the |
|
903 | 903 | basename of the source. |
|
904 | 904 | |
|
905 | 905 | The location of the source is added to the new repository's |
|
906 | 906 | .hg/hgrc file, as the default to be used for future pulls. |
|
907 | 907 | |
|
908 | 908 | For efficiency, hardlinks are used for cloning whenever the source |
|
909 | 909 | and destination are on the same filesystem. Some filesystems, |
|
910 | 910 | such as AFS, implement hardlinking incorrectly, but do not report |
|
911 | 911 | errors. In these cases, use the --pull option to avoid |
|
912 | 912 | hardlinking. |
|
913 | 913 | |
|
914 | 914 | See pull for valid source format details. |
|
915 | 915 | """ |
|
916 | 916 | if dest is None: |
|
917 | 917 | dest = os.path.basename(os.path.normpath(source)) |
|
918 | 918 | |
|
919 | 919 | if os.path.exists(dest): |
|
920 | 920 | raise util.Abort(_("destination '%s' already exists"), dest) |
|
921 | 921 | |
|
922 | 922 | dest = os.path.realpath(dest) |
|
923 | 923 | |
|
924 | 924 | class Dircleanup(object): |
|
925 | 925 | def __init__(self, dir_): |
|
926 | 926 | self.rmtree = shutil.rmtree |
|
927 | 927 | self.dir_ = dir_ |
|
928 | 928 | os.mkdir(dir_) |
|
929 | 929 | def close(self): |
|
930 | 930 | self.dir_ = None |
|
931 | 931 | def __del__(self): |
|
932 | 932 | if self.dir_: |
|
933 | 933 | self.rmtree(self.dir_, True) |
|
934 | 934 | |
|
935 | 935 | if opts['ssh']: |
|
936 | 936 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
937 | 937 | if opts['remotecmd']: |
|
938 | 938 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
939 | 939 | |
|
940 | 940 | source = ui.expandpath(source) |
|
941 | 941 | |
|
942 | 942 | d = Dircleanup(dest) |
|
943 | 943 | abspath = source |
|
944 | 944 | other = hg.repository(ui, source) |
|
945 | 945 | |
|
946 | 946 | copy = False |
|
947 | 947 | if other.dev() != -1: |
|
948 | 948 | abspath = os.path.abspath(source) |
|
949 | 949 | if not opts['pull'] and not opts['rev']: |
|
950 | 950 | copy = True |
|
951 | 951 | |
|
952 | 952 | if copy: |
|
953 | 953 | try: |
|
954 | 954 | # we use a lock here because if we race with commit, we |
|
955 | 955 | # can end up with extra data in the cloned revlogs that's |
|
956 | 956 | # not pointed to by changesets, thus causing verify to |
|
957 | 957 | # fail |
|
958 | 958 | l1 = other.lock() |
|
959 | 959 | except lock.LockException: |
|
960 | 960 | copy = False |
|
961 | 961 | |
|
962 | 962 | if copy: |
|
963 | 963 | # we lock here to avoid premature writing to the target |
|
964 | 964 | os.mkdir(os.path.join(dest, ".hg")) |
|
965 | 965 | l2 = lock.lock(os.path.join(dest, ".hg", "lock")) |
|
966 | 966 | |
|
967 | 967 | files = "data 00manifest.d 00manifest.i 00changelog.d 00changelog.i" |
|
968 | 968 | for f in files.split(): |
|
969 | 969 | src = os.path.join(source, ".hg", f) |
|
970 | 970 | dst = os.path.join(dest, ".hg", f) |
|
971 | 971 | try: |
|
972 | 972 | util.copyfiles(src, dst) |
|
973 | 973 | except OSError, inst: |
|
974 | 974 | if inst.errno != errno.ENOENT: |
|
975 | 975 | raise |
|
976 | 976 | |
|
977 | 977 | repo = hg.repository(ui, dest) |
|
978 | 978 | |
|
979 | 979 | else: |
|
980 | 980 | revs = None |
|
981 | 981 | if opts['rev']: |
|
982 | 982 | if not other.local(): |
|
983 | 983 | error = _("clone -r not supported yet for remote repositories.") |
|
984 | 984 | raise util.Abort(error) |
|
985 | 985 | else: |
|
986 | 986 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
987 | 987 | repo = hg.repository(ui, dest, create=1) |
|
988 | 988 | repo.pull(other, heads = revs) |
|
989 | 989 | |
|
990 | 990 | f = repo.opener("hgrc", "w", text=True) |
|
991 | 991 | f.write("[paths]\n") |
|
992 | 992 | f.write("default = %s\n" % abspath) |
|
993 | 993 | f.close() |
|
994 | 994 | |
|
995 | 995 | if not opts['noupdate']: |
|
996 | 996 | doupdate(repo.ui, repo) |
|
997 | 997 | |
|
998 | 998 | d.close() |
|
999 | 999 | |
|
1000 | 1000 | def commit(ui, repo, *pats, **opts): |
|
1001 | 1001 | """commit the specified files or all outstanding changes |
|
1002 | 1002 | |
|
1003 | 1003 | Commit changes to the given files into the repository. |
|
1004 | 1004 | |
|
1005 | 1005 | If a list of files is omitted, all changes reported by "hg status" |
|
1006 | 1006 | will be committed. |
|
1007 | 1007 | |
|
1008 | 1008 | If no commit message is specified, the editor configured in your hgrc |
|
1009 | 1009 | or in the EDITOR environment variable is started to enter a message. |
|
1010 | 1010 | """ |
|
1011 | 1011 | message = opts['message'] |
|
1012 | 1012 | logfile = opts['logfile'] |
|
1013 | 1013 | |
|
1014 | 1014 | if message and logfile: |
|
1015 | 1015 | raise util.Abort(_('options --message and --logfile are mutually ' |
|
1016 | 1016 | 'exclusive')) |
|
1017 | 1017 | if not message and logfile: |
|
1018 | 1018 | try: |
|
1019 | 1019 | if logfile == '-': |
|
1020 | 1020 | message = sys.stdin.read() |
|
1021 | 1021 | else: |
|
1022 | 1022 | message = open(logfile).read() |
|
1023 | 1023 | except IOError, inst: |
|
1024 | 1024 | raise util.Abort(_("can't read commit message '%s': %s") % |
|
1025 | 1025 | (logfile, inst.strerror)) |
|
1026 | 1026 | |
|
1027 | 1027 | if opts['addremove']: |
|
1028 | 1028 | addremove_lock(ui, repo, pats, opts) |
|
1029 | 1029 | fns, match, anypats = matchpats(repo, pats, opts) |
|
1030 | 1030 | if pats: |
|
1031 | 1031 | modified, added, removed, deleted, unknown = ( |
|
1032 | 1032 | repo.changes(files=fns, match=match)) |
|
1033 | 1033 | files = modified + added + removed |
|
1034 | 1034 | else: |
|
1035 | 1035 | files = [] |
|
1036 | 1036 | try: |
|
1037 | 1037 | repo.commit(files, message, opts['user'], opts['date'], match, |
|
1038 | 1038 | force_editor=opts.get('force_editor')) |
|
1039 | 1039 | except ValueError, inst: |
|
1040 | 1040 | raise util.Abort(str(inst)) |
|
1041 | 1041 | |
|
1042 | 1042 | def docopy(ui, repo, pats, opts, wlock): |
|
1043 | 1043 | # called with the repo lock held |
|
1044 | 1044 | cwd = repo.getcwd() |
|
1045 | 1045 | errors = 0 |
|
1046 | 1046 | copied = [] |
|
1047 | 1047 | targets = {} |
|
1048 | 1048 | |
|
1049 | 1049 | def okaytocopy(abs, rel, exact): |
|
1050 | 1050 | reasons = {'?': _('is not managed'), |
|
1051 | 1051 | 'a': _('has been marked for add'), |
|
1052 | 1052 | 'r': _('has been marked for remove')} |
|
1053 | 1053 | state = repo.dirstate.state(abs) |
|
1054 | 1054 | reason = reasons.get(state) |
|
1055 | 1055 | if reason: |
|
1056 | 1056 | if state == 'a': |
|
1057 | 1057 | origsrc = repo.dirstate.copied(abs) |
|
1058 | 1058 | if origsrc is not None: |
|
1059 | 1059 | return origsrc |
|
1060 | 1060 | if exact: |
|
1061 | 1061 | ui.warn(_('%s: not copying - file %s\n') % (rel, reason)) |
|
1062 | 1062 | else: |
|
1063 | 1063 | return abs |
|
1064 | 1064 | |
|
1065 | 1065 | def copy(origsrc, abssrc, relsrc, target, exact): |
|
1066 | 1066 | abstarget = util.canonpath(repo.root, cwd, target) |
|
1067 | 1067 | reltarget = util.pathto(cwd, abstarget) |
|
1068 | 1068 | prevsrc = targets.get(abstarget) |
|
1069 | 1069 | if prevsrc is not None: |
|
1070 | 1070 | ui.warn(_('%s: not overwriting - %s collides with %s\n') % |
|
1071 | 1071 | (reltarget, abssrc, prevsrc)) |
|
1072 | 1072 | return |
|
1073 | 1073 | if (not opts['after'] and os.path.exists(reltarget) or |
|
1074 | 1074 | opts['after'] and repo.dirstate.state(abstarget) not in '?r'): |
|
1075 | 1075 | if not opts['force']: |
|
1076 | 1076 | ui.warn(_('%s: not overwriting - file exists\n') % |
|
1077 | 1077 | reltarget) |
|
1078 | 1078 | return |
|
1079 | 1079 | if not opts['after'] and not opts.get('dry_run'): |
|
1080 | 1080 | os.unlink(reltarget) |
|
1081 | 1081 | if opts['after']: |
|
1082 | 1082 | if not os.path.exists(reltarget): |
|
1083 | 1083 | return |
|
1084 | 1084 | else: |
|
1085 | 1085 | targetdir = os.path.dirname(reltarget) or '.' |
|
1086 | 1086 | if not os.path.isdir(targetdir) and not opts.get('dry_run'): |
|
1087 | 1087 | os.makedirs(targetdir) |
|
1088 | 1088 | try: |
|
1089 | 1089 | restore = repo.dirstate.state(abstarget) == 'r' |
|
1090 | 1090 | if restore and not opts.get('dry_run'): |
|
1091 | 1091 | repo.undelete([abstarget], wlock) |
|
1092 | 1092 | try: |
|
1093 | 1093 | if not opts.get('dry_run'): |
|
1094 | 1094 | shutil.copyfile(relsrc, reltarget) |
|
1095 | 1095 | shutil.copymode(relsrc, reltarget) |
|
1096 | 1096 | restore = False |
|
1097 | 1097 | finally: |
|
1098 | 1098 | if restore: |
|
1099 | 1099 | repo.remove([abstarget], wlock) |
|
1100 | 1100 | except shutil.Error, inst: |
|
1101 | 1101 | raise util.Abort(str(inst)) |
|
1102 | 1102 | except IOError, inst: |
|
1103 | 1103 | if inst.errno == errno.ENOENT: |
|
1104 | 1104 | ui.warn(_('%s: deleted in working copy\n') % relsrc) |
|
1105 | 1105 | else: |
|
1106 | 1106 | ui.warn(_('%s: cannot copy - %s\n') % |
|
1107 | 1107 | (relsrc, inst.strerror)) |
|
1108 | 1108 | errors += 1 |
|
1109 | 1109 | return |
|
1110 | 1110 | if ui.verbose or not exact: |
|
1111 | 1111 | ui.status(_('copying %s to %s\n') % (relsrc, reltarget)) |
|
1112 | 1112 | targets[abstarget] = abssrc |
|
1113 | 1113 | if abstarget != origsrc and not opts.get('dry_run'): |
|
1114 | 1114 | repo.copy(origsrc, abstarget, wlock) |
|
1115 | 1115 | copied.append((abssrc, relsrc, exact)) |
|
1116 | 1116 | |
|
1117 | 1117 | def targetpathfn(pat, dest, srcs): |
|
1118 | 1118 | if os.path.isdir(pat): |
|
1119 | 1119 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1120 | 1120 | if destdirexists: |
|
1121 | 1121 | striplen = len(os.path.split(abspfx)[0]) |
|
1122 | 1122 | else: |
|
1123 | 1123 | striplen = len(abspfx) |
|
1124 | 1124 | if striplen: |
|
1125 | 1125 | striplen += len(os.sep) |
|
1126 | 1126 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1127 | 1127 | elif destdirexists: |
|
1128 | 1128 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1129 | 1129 | else: |
|
1130 | 1130 | res = lambda p: dest |
|
1131 | 1131 | return res |
|
1132 | 1132 | |
|
1133 | 1133 | def targetpathafterfn(pat, dest, srcs): |
|
1134 | 1134 | if util.patkind(pat, None)[0]: |
|
1135 | 1135 | # a mercurial pattern |
|
1136 | 1136 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1137 | 1137 | else: |
|
1138 | 1138 | abspfx = util.canonpath(repo.root, cwd, pat) |
|
1139 | 1139 | if len(abspfx) < len(srcs[0][0]): |
|
1140 | 1140 | # A directory. Either the target path contains the last |
|
1141 | 1141 | # component of the source path or it does not. |
|
1142 | 1142 | def evalpath(striplen): |
|
1143 | 1143 | score = 0 |
|
1144 | 1144 | for s in srcs: |
|
1145 | 1145 | t = os.path.join(dest, s[0][striplen:]) |
|
1146 | 1146 | if os.path.exists(t): |
|
1147 | 1147 | score += 1 |
|
1148 | 1148 | return score |
|
1149 | 1149 | |
|
1150 | 1150 | striplen = len(abspfx) |
|
1151 | 1151 | if striplen: |
|
1152 | 1152 | striplen += len(os.sep) |
|
1153 | 1153 | if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
|
1154 | 1154 | score = evalpath(striplen) |
|
1155 | 1155 | striplen1 = len(os.path.split(abspfx)[0]) |
|
1156 | 1156 | if striplen1: |
|
1157 | 1157 | striplen1 += len(os.sep) |
|
1158 | 1158 | if evalpath(striplen1) > score: |
|
1159 | 1159 | striplen = striplen1 |
|
1160 | 1160 | res = lambda p: os.path.join(dest, p[striplen:]) |
|
1161 | 1161 | else: |
|
1162 | 1162 | # a file |
|
1163 | 1163 | if destdirexists: |
|
1164 | 1164 | res = lambda p: os.path.join(dest, os.path.basename(p)) |
|
1165 | 1165 | else: |
|
1166 | 1166 | res = lambda p: dest |
|
1167 | 1167 | return res |
|
1168 | 1168 | |
|
1169 | 1169 | |
|
1170 | 1170 | pats = list(pats) |
|
1171 | 1171 | if not pats: |
|
1172 | 1172 | raise util.Abort(_('no source or destination specified')) |
|
1173 | 1173 | if len(pats) == 1: |
|
1174 | 1174 | raise util.Abort(_('no destination specified')) |
|
1175 | 1175 | dest = pats.pop() |
|
1176 | 1176 | destdirexists = os.path.isdir(dest) |
|
1177 | 1177 | if (len(pats) > 1 or util.patkind(pats[0], None)[0]) and not destdirexists: |
|
1178 | 1178 | raise util.Abort(_('with multiple sources, destination must be an ' |
|
1179 | 1179 | 'existing directory')) |
|
1180 | 1180 | if opts['after']: |
|
1181 | 1181 | tfn = targetpathafterfn |
|
1182 | 1182 | else: |
|
1183 | 1183 | tfn = targetpathfn |
|
1184 | 1184 | copylist = [] |
|
1185 | 1185 | for pat in pats: |
|
1186 | 1186 | srcs = [] |
|
1187 | 1187 | for tag, abssrc, relsrc, exact in walk(repo, [pat], opts): |
|
1188 | 1188 | origsrc = okaytocopy(abssrc, relsrc, exact) |
|
1189 | 1189 | if origsrc: |
|
1190 | 1190 | srcs.append((origsrc, abssrc, relsrc, exact)) |
|
1191 | 1191 | if not srcs: |
|
1192 | 1192 | continue |
|
1193 | 1193 | copylist.append((tfn(pat, dest, srcs), srcs)) |
|
1194 | 1194 | if not copylist: |
|
1195 | 1195 | raise util.Abort(_('no files to copy')) |
|
1196 | 1196 | |
|
1197 | 1197 | for targetpath, srcs in copylist: |
|
1198 | 1198 | for origsrc, abssrc, relsrc, exact in srcs: |
|
1199 | 1199 | copy(origsrc, abssrc, relsrc, targetpath(abssrc), exact) |
|
1200 | 1200 | |
|
1201 | 1201 | if errors: |
|
1202 | 1202 | ui.warn(_('(consider using --after)\n')) |
|
1203 | 1203 | return errors, copied |
|
1204 | 1204 | |
|
1205 | 1205 | def copy(ui, repo, *pats, **opts): |
|
1206 | 1206 | """mark files as copied for the next commit |
|
1207 | 1207 | |
|
1208 | 1208 | Mark dest as having copies of source files. If dest is a |
|
1209 | 1209 | directory, copies are put in that directory. If dest is a file, |
|
1210 | 1210 | there can only be one source. |
|
1211 | 1211 | |
|
1212 | 1212 | By default, this command copies the contents of files as they |
|
1213 | 1213 | stand in the working directory. If invoked with --after, the |
|
1214 | 1214 | operation is recorded, but no copying is performed. |
|
1215 | 1215 | |
|
1216 | 1216 | This command takes effect in the next commit. |
|
1217 | 1217 | |
|
1218 | 1218 | NOTE: This command should be treated as experimental. While it |
|
1219 | 1219 | should properly record copied files, this information is not yet |
|
1220 | 1220 | fully used by merge, nor fully reported by log. |
|
1221 | 1221 | """ |
|
1222 | 1222 | wlock = repo.wlock(0) |
|
1223 | 1223 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
1224 | 1224 | return errs |
|
1225 | 1225 | |
|
1226 | 1226 | def debugancestor(ui, index, rev1, rev2): |
|
1227 | 1227 | """find the ancestor revision of two revisions in a given index""" |
|
1228 | 1228 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), index, "", 0) |
|
1229 | 1229 | a = r.ancestor(r.lookup(rev1), r.lookup(rev2)) |
|
1230 | 1230 | ui.write("%d:%s\n" % (r.rev(a), hex(a))) |
|
1231 | 1231 | |
|
1232 | 1232 | def debugcomplete(ui, cmd='', **opts): |
|
1233 | 1233 | """returns the completion list associated with the given command""" |
|
1234 | 1234 | |
|
1235 | 1235 | if opts['options']: |
|
1236 | 1236 | options = [] |
|
1237 | 1237 | otables = [globalopts] |
|
1238 | 1238 | if cmd: |
|
1239 | 1239 | aliases, entry = find(cmd) |
|
1240 | 1240 | otables.append(entry[1]) |
|
1241 | 1241 | for t in otables: |
|
1242 | 1242 | for o in t: |
|
1243 | 1243 | if o[0]: |
|
1244 | 1244 | options.append('-%s' % o[0]) |
|
1245 | 1245 | options.append('--%s' % o[1]) |
|
1246 | 1246 | ui.write("%s\n" % "\n".join(options)) |
|
1247 | 1247 | return |
|
1248 | 1248 | |
|
1249 | 1249 | clist = findpossible(cmd).keys() |
|
1250 | 1250 | clist.sort() |
|
1251 | 1251 | ui.write("%s\n" % "\n".join(clist)) |
|
1252 | 1252 | |
|
1253 | 1253 | def debugrebuildstate(ui, repo, rev=None): |
|
1254 | 1254 | """rebuild the dirstate as it would look like for the given revision""" |
|
1255 | 1255 | if not rev: |
|
1256 | 1256 | rev = repo.changelog.tip() |
|
1257 | 1257 | else: |
|
1258 | 1258 | rev = repo.lookup(rev) |
|
1259 | 1259 | change = repo.changelog.read(rev) |
|
1260 | 1260 | n = change[0] |
|
1261 | 1261 | files = repo.manifest.readflags(n) |
|
1262 | 1262 | wlock = repo.wlock() |
|
1263 | 1263 | repo.dirstate.rebuild(rev, files.iteritems()) |
|
1264 | 1264 | |
|
1265 | 1265 | def debugcheckstate(ui, repo): |
|
1266 | 1266 | """validate the correctness of the current dirstate""" |
|
1267 | 1267 | parent1, parent2 = repo.dirstate.parents() |
|
1268 | 1268 | repo.dirstate.read() |
|
1269 | 1269 | dc = repo.dirstate.map |
|
1270 | 1270 | keys = dc.keys() |
|
1271 | 1271 | keys.sort() |
|
1272 | 1272 | m1n = repo.changelog.read(parent1)[0] |
|
1273 | 1273 | m2n = repo.changelog.read(parent2)[0] |
|
1274 | 1274 | m1 = repo.manifest.read(m1n) |
|
1275 | 1275 | m2 = repo.manifest.read(m2n) |
|
1276 | 1276 | errors = 0 |
|
1277 | 1277 | for f in dc: |
|
1278 | 1278 | state = repo.dirstate.state(f) |
|
1279 | 1279 | if state in "nr" and f not in m1: |
|
1280 | 1280 | ui.warn(_("%s in state %s, but not in manifest1\n") % (f, state)) |
|
1281 | 1281 | errors += 1 |
|
1282 | 1282 | if state in "a" and f in m1: |
|
1283 | 1283 | ui.warn(_("%s in state %s, but also in manifest1\n") % (f, state)) |
|
1284 | 1284 | errors += 1 |
|
1285 | 1285 | if state in "m" and f not in m1 and f not in m2: |
|
1286 | 1286 | ui.warn(_("%s in state %s, but not in either manifest\n") % |
|
1287 | 1287 | (f, state)) |
|
1288 | 1288 | errors += 1 |
|
1289 | 1289 | for f in m1: |
|
1290 | 1290 | state = repo.dirstate.state(f) |
|
1291 | 1291 | if state not in "nrm": |
|
1292 | 1292 | ui.warn(_("%s in manifest1, but listed as state %s") % (f, state)) |
|
1293 | 1293 | errors += 1 |
|
1294 | 1294 | if errors: |
|
1295 | 1295 | error = _(".hg/dirstate inconsistent with current parent's manifest") |
|
1296 | 1296 | raise util.Abort(error) |
|
1297 | 1297 | |
|
1298 | 1298 | def debugconfig(ui, repo, *values): |
|
1299 | 1299 | """show combined config settings from all hgrc files |
|
1300 | 1300 | |
|
1301 | 1301 | With no args, print names and values of all config items. |
|
1302 | 1302 | |
|
1303 | 1303 | With one arg of the form section.name, print just the value of |
|
1304 | 1304 | that config item. |
|
1305 | 1305 | |
|
1306 | 1306 | With multiple args, print names and values of all config items |
|
1307 | 1307 | with matching section names.""" |
|
1308 | 1308 | |
|
1309 | 1309 | if values: |
|
1310 | 1310 | if len([v for v in values if '.' in v]) > 1: |
|
1311 | 1311 | raise util.Abort(_('only one config item permitted')) |
|
1312 | 1312 | for section, name, value in ui.walkconfig(): |
|
1313 | 1313 | sectname = section + '.' + name |
|
1314 | 1314 | if values: |
|
1315 | 1315 | for v in values: |
|
1316 | 1316 | if v == section: |
|
1317 | 1317 | ui.write('%s=%s\n' % (sectname, value)) |
|
1318 | 1318 | elif v == sectname: |
|
1319 | 1319 | ui.write(value, '\n') |
|
1320 | 1320 | else: |
|
1321 | 1321 | ui.write('%s=%s\n' % (sectname, value)) |
|
1322 | 1322 | |
|
1323 | 1323 | def debugsetparents(ui, repo, rev1, rev2=None): |
|
1324 | 1324 | """manually set the parents of the current working directory |
|
1325 | 1325 | |
|
1326 | 1326 | This is useful for writing repository conversion tools, but should |
|
1327 | 1327 | be used with care. |
|
1328 | 1328 | """ |
|
1329 | 1329 | |
|
1330 | 1330 | if not rev2: |
|
1331 | 1331 | rev2 = hex(nullid) |
|
1332 | 1332 | |
|
1333 | 1333 | repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) |
|
1334 | 1334 | |
|
1335 | 1335 | def debugstate(ui, repo): |
|
1336 | 1336 | """show the contents of the current dirstate""" |
|
1337 | 1337 | repo.dirstate.read() |
|
1338 | 1338 | dc = repo.dirstate.map |
|
1339 | 1339 | keys = dc.keys() |
|
1340 | 1340 | keys.sort() |
|
1341 | 1341 | for file_ in keys: |
|
1342 | 1342 | ui.write("%c %3o %10d %s %s\n" |
|
1343 | 1343 | % (dc[file_][0], dc[file_][1] & 0777, dc[file_][2], |
|
1344 | 1344 | time.strftime("%x %X", |
|
1345 | 1345 | time.localtime(dc[file_][3])), file_)) |
|
1346 | 1346 | for f in repo.dirstate.copies: |
|
1347 | 1347 | ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copies[f], f)) |
|
1348 | 1348 | |
|
1349 | 1349 | def debugdata(ui, file_, rev): |
|
1350 | 1350 | """dump the contents of an data file revision""" |
|
1351 | 1351 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), |
|
1352 | 1352 | file_[:-2] + ".i", file_, 0) |
|
1353 | 1353 | try: |
|
1354 | 1354 | ui.write(r.revision(r.lookup(rev))) |
|
1355 | 1355 | except KeyError: |
|
1356 | 1356 | raise util.Abort(_('invalid revision identifier %s'), rev) |
|
1357 | 1357 | |
|
1358 | 1358 | def debugindex(ui, file_): |
|
1359 | 1359 | """dump the contents of an index file""" |
|
1360 | 1360 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1361 | 1361 | ui.write(" rev offset length base linkrev" + |
|
1362 | 1362 | " nodeid p1 p2\n") |
|
1363 | 1363 | for i in range(r.count()): |
|
1364 | 1364 | node = r.node(i) |
|
1365 | 1365 | pp = r.parents(node) |
|
1366 | 1366 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
1367 | 1367 | i, r.start(i), r.length(i), r.base(i), r.linkrev(node), |
|
1368 | 1368 | short(node), short(pp[0]), short(pp[1]))) |
|
1369 | 1369 | |
|
1370 | 1370 | def debugindexdot(ui, file_): |
|
1371 | 1371 | """dump an index DAG as a .dot file""" |
|
1372 | 1372 | r = revlog.revlog(util.opener(os.getcwd(), audit=False), file_, "", 0) |
|
1373 | 1373 | ui.write("digraph G {\n") |
|
1374 | 1374 | for i in range(r.count()): |
|
1375 | 1375 | node = r.node(i) |
|
1376 | 1376 | pp = r.parents(node) |
|
1377 | 1377 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
1378 | 1378 | if pp[1] != nullid: |
|
1379 | 1379 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
1380 | 1380 | ui.write("}\n") |
|
1381 | 1381 | |
|
1382 | 1382 | def debugrename(ui, repo, file, rev=None): |
|
1383 | 1383 | """dump rename information""" |
|
1384 | 1384 | r = repo.file(relpath(repo, [file])[0]) |
|
1385 | 1385 | if rev: |
|
1386 | 1386 | try: |
|
1387 | 1387 | # assume all revision numbers are for changesets |
|
1388 | 1388 | n = repo.lookup(rev) |
|
1389 | 1389 | change = repo.changelog.read(n) |
|
1390 | 1390 | m = repo.manifest.read(change[0]) |
|
1391 | 1391 | n = m[relpath(repo, [file])[0]] |
|
1392 | 1392 | except (hg.RepoError, KeyError): |
|
1393 | 1393 | n = r.lookup(rev) |
|
1394 | 1394 | else: |
|
1395 | 1395 | n = r.tip() |
|
1396 | 1396 | m = r.renamed(n) |
|
1397 | 1397 | if m: |
|
1398 | 1398 | ui.write(_("renamed from %s:%s\n") % (m[0], hex(m[1]))) |
|
1399 | 1399 | else: |
|
1400 | 1400 | ui.write(_("not renamed\n")) |
|
1401 | 1401 | |
|
1402 | 1402 | def debugwalk(ui, repo, *pats, **opts): |
|
1403 | 1403 | """show how files match on given patterns""" |
|
1404 | 1404 | items = list(walk(repo, pats, opts)) |
|
1405 | 1405 | if not items: |
|
1406 | 1406 | return |
|
1407 | 1407 | fmt = '%%s %%-%ds %%-%ds %%s' % ( |
|
1408 | 1408 | max([len(abs) for (src, abs, rel, exact) in items]), |
|
1409 | 1409 | max([len(rel) for (src, abs, rel, exact) in items])) |
|
1410 | 1410 | for src, abs, rel, exact in items: |
|
1411 | 1411 | line = fmt % (src, abs, rel, exact and 'exact' or '') |
|
1412 | 1412 | ui.write("%s\n" % line.rstrip()) |
|
1413 | 1413 | |
|
1414 | 1414 | def diff(ui, repo, *pats, **opts): |
|
1415 | 1415 | """diff repository (or selected files) |
|
1416 | 1416 | |
|
1417 | 1417 | Show differences between revisions for the specified files. |
|
1418 | 1418 | |
|
1419 | 1419 | Differences between files are shown using the unified diff format. |
|
1420 | 1420 | |
|
1421 | 1421 | When two revision arguments are given, then changes are shown |
|
1422 | 1422 | between those revisions. If only one revision is specified then |
|
1423 | 1423 | that revision is compared to the working directory, and, when no |
|
1424 | 1424 | revisions are specified, the working directory files are compared |
|
1425 | 1425 | to its parent. |
|
1426 | 1426 | |
|
1427 | 1427 | Without the -a option, diff will avoid generating diffs of files |
|
1428 | 1428 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1429 | 1429 | probably with undesirable results. |
|
1430 | 1430 | """ |
|
1431 | 1431 | node1, node2 = revpair(ui, repo, opts['rev']) |
|
1432 | 1432 | |
|
1433 | 1433 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1434 | 1434 | |
|
1435 | 1435 | dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
|
1436 | 1436 | text=opts['text'], opts=opts) |
|
1437 | 1437 | |
|
1438 | 1438 | def doexport(ui, repo, changeset, seqno, total, revwidth, opts): |
|
1439 | 1439 | node = repo.lookup(changeset) |
|
1440 | 1440 | parents = [p for p in repo.changelog.parents(node) if p != nullid] |
|
1441 | 1441 | if opts['switch_parent']: |
|
1442 | 1442 | parents.reverse() |
|
1443 | 1443 | prev = (parents and parents[0]) or nullid |
|
1444 | 1444 | change = repo.changelog.read(node) |
|
1445 | 1445 | |
|
1446 | 1446 | fp = make_file(repo, repo.changelog, opts['output'], |
|
1447 | 1447 | node=node, total=total, seqno=seqno, |
|
1448 | 1448 | revwidth=revwidth) |
|
1449 | 1449 | if fp != sys.stdout: |
|
1450 | 1450 | ui.note("%s\n" % fp.name) |
|
1451 | 1451 | |
|
1452 | 1452 | fp.write("# HG changeset patch\n") |
|
1453 | 1453 | fp.write("# User %s\n" % change[1]) |
|
1454 | 1454 | fp.write("# Date %d %d\n" % change[2]) |
|
1455 | 1455 | fp.write("# Node ID %s\n" % hex(node)) |
|
1456 | 1456 | fp.write("# Parent %s\n" % hex(prev)) |
|
1457 | 1457 | if len(parents) > 1: |
|
1458 | 1458 | fp.write("# Parent %s\n" % hex(parents[1])) |
|
1459 | 1459 | fp.write(change[4].rstrip()) |
|
1460 | 1460 | fp.write("\n\n") |
|
1461 | 1461 | |
|
1462 | 1462 | dodiff(fp, ui, repo, prev, node, text=opts['text']) |
|
1463 | 1463 | if fp != sys.stdout: |
|
1464 | 1464 | fp.close() |
|
1465 | 1465 | |
|
1466 | 1466 | def export(ui, repo, *changesets, **opts): |
|
1467 | 1467 | """dump the header and diffs for one or more changesets |
|
1468 | 1468 | |
|
1469 | 1469 | Print the changeset header and diffs for one or more revisions. |
|
1470 | 1470 | |
|
1471 | 1471 | The information shown in the changeset header is: author, |
|
1472 | 1472 | changeset hash, parent and commit comment. |
|
1473 | 1473 | |
|
1474 | 1474 | Output may be to a file, in which case the name of the file is |
|
1475 | 1475 | given using a format string. The formatting rules are as follows: |
|
1476 | 1476 | |
|
1477 | 1477 | %% literal "%" character |
|
1478 | 1478 | %H changeset hash (40 bytes of hexadecimal) |
|
1479 | 1479 | %N number of patches being generated |
|
1480 | 1480 | %R changeset revision number |
|
1481 | 1481 | %b basename of the exporting repository |
|
1482 | 1482 | %h short-form changeset hash (12 bytes of hexadecimal) |
|
1483 | 1483 | %n zero-padded sequence number, starting at 1 |
|
1484 | 1484 | %r zero-padded changeset revision number |
|
1485 | 1485 | |
|
1486 | 1486 | Without the -a option, export will avoid generating diffs of files |
|
1487 | 1487 | it detects as binary. With -a, export will generate a diff anyway, |
|
1488 | 1488 | probably with undesirable results. |
|
1489 | 1489 | |
|
1490 | 1490 | With the --switch-parent option, the diff will be against the second |
|
1491 | 1491 | parent. It can be useful to review a merge. |
|
1492 | 1492 | """ |
|
1493 | 1493 | if not changesets: |
|
1494 | 1494 | raise util.Abort(_("export requires at least one changeset")) |
|
1495 | 1495 | seqno = 0 |
|
1496 | 1496 | revs = list(revrange(ui, repo, changesets)) |
|
1497 | 1497 | total = len(revs) |
|
1498 | 1498 | revwidth = max(map(len, revs)) |
|
1499 | 1499 | msg = len(revs) > 1 and _("Exporting patches:\n") or _("Exporting patch:\n") |
|
1500 | 1500 | ui.note(msg) |
|
1501 | 1501 | for cset in revs: |
|
1502 | 1502 | seqno += 1 |
|
1503 | 1503 | doexport(ui, repo, cset, seqno, total, revwidth, opts) |
|
1504 | 1504 | |
|
1505 | 1505 | def forget(ui, repo, *pats, **opts): |
|
1506 | 1506 | """don't add the specified files on the next commit (DEPRECATED) |
|
1507 | 1507 | |
|
1508 | 1508 | (DEPRECATED) |
|
1509 | 1509 | Undo an 'hg add' scheduled for the next commit. |
|
1510 | 1510 | |
|
1511 | 1511 | This command is now deprecated and will be removed in a future |
|
1512 | 1512 | release. Please use revert instead. |
|
1513 | 1513 | """ |
|
1514 | 1514 | ui.warn(_("(the forget command is deprecated; use revert instead)\n")) |
|
1515 | 1515 | forget = [] |
|
1516 | 1516 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
1517 | 1517 | if repo.dirstate.state(abs) == 'a': |
|
1518 | 1518 | forget.append(abs) |
|
1519 | 1519 | if ui.verbose or not exact: |
|
1520 | 1520 | ui.status(_('forgetting %s\n') % ((pats and rel) or abs)) |
|
1521 | 1521 | repo.forget(forget) |
|
1522 | 1522 | |
|
1523 | 1523 | def grep(ui, repo, pattern, *pats, **opts): |
|
1524 | 1524 | """search for a pattern in specified files and revisions |
|
1525 | 1525 | |
|
1526 | 1526 | Search revisions of files for a regular expression. |
|
1527 | 1527 | |
|
1528 | 1528 | This command behaves differently than Unix grep. It only accepts |
|
1529 | 1529 | Python/Perl regexps. It searches repository history, not the |
|
1530 | 1530 | working directory. It always prints the revision number in which |
|
1531 | 1531 | a match appears. |
|
1532 | 1532 | |
|
1533 | 1533 | By default, grep only prints output for the first revision of a |
|
1534 | 1534 | file in which it finds a match. To get it to print every revision |
|
1535 | 1535 | that contains a change in match status ("-" for a match that |
|
1536 | 1536 | becomes a non-match, or "+" for a non-match that becomes a match), |
|
1537 | 1537 | use the --all flag. |
|
1538 | 1538 | """ |
|
1539 | 1539 | reflags = 0 |
|
1540 | 1540 | if opts['ignore_case']: |
|
1541 | 1541 | reflags |= re.I |
|
1542 | 1542 | regexp = re.compile(pattern, reflags) |
|
1543 | 1543 | sep, eol = ':', '\n' |
|
1544 | 1544 | if opts['print0']: |
|
1545 | 1545 | sep = eol = '\0' |
|
1546 | 1546 | |
|
1547 | 1547 | fcache = {} |
|
1548 | 1548 | def getfile(fn): |
|
1549 | 1549 | if fn not in fcache: |
|
1550 | 1550 | fcache[fn] = repo.file(fn) |
|
1551 | 1551 | return fcache[fn] |
|
1552 | 1552 | |
|
1553 | 1553 | def matchlines(body): |
|
1554 | 1554 | begin = 0 |
|
1555 | 1555 | linenum = 0 |
|
1556 | 1556 | while True: |
|
1557 | 1557 | match = regexp.search(body, begin) |
|
1558 | 1558 | if not match: |
|
1559 | 1559 | break |
|
1560 | 1560 | mstart, mend = match.span() |
|
1561 | 1561 | linenum += body.count('\n', begin, mstart) + 1 |
|
1562 | 1562 | lstart = body.rfind('\n', begin, mstart) + 1 or begin |
|
1563 | 1563 | lend = body.find('\n', mend) |
|
1564 | 1564 | yield linenum, mstart - lstart, mend - lstart, body[lstart:lend] |
|
1565 | 1565 | begin = lend + 1 |
|
1566 | 1566 | |
|
1567 | 1567 | class linestate(object): |
|
1568 | 1568 | def __init__(self, line, linenum, colstart, colend): |
|
1569 | 1569 | self.line = line |
|
1570 | 1570 | self.linenum = linenum |
|
1571 | 1571 | self.colstart = colstart |
|
1572 | 1572 | self.colend = colend |
|
1573 | 1573 | def __eq__(self, other): |
|
1574 | 1574 | return self.line == other.line |
|
1575 | 1575 | def __hash__(self): |
|
1576 | 1576 | return hash(self.line) |
|
1577 | 1577 | |
|
1578 | 1578 | matches = {} |
|
1579 | 1579 | def grepbody(fn, rev, body): |
|
1580 | 1580 | matches[rev].setdefault(fn, {}) |
|
1581 | 1581 | m = matches[rev][fn] |
|
1582 | 1582 | for lnum, cstart, cend, line in matchlines(body): |
|
1583 | 1583 | s = linestate(line, lnum, cstart, cend) |
|
1584 | 1584 | m[s] = s |
|
1585 | 1585 | |
|
1586 | 1586 | # FIXME: prev isn't used, why ? |
|
1587 | 1587 | prev = {} |
|
1588 | 1588 | ucache = {} |
|
1589 | 1589 | def display(fn, rev, states, prevstates): |
|
1590 | 1590 | diff = list(sets.Set(states).symmetric_difference(sets.Set(prevstates))) |
|
1591 | 1591 | diff.sort(lambda x, y: cmp(x.linenum, y.linenum)) |
|
1592 | 1592 | counts = {'-': 0, '+': 0} |
|
1593 | 1593 | filerevmatches = {} |
|
1594 | 1594 | for l in diff: |
|
1595 | 1595 | if incrementing or not opts['all']: |
|
1596 | 1596 | change = ((l in prevstates) and '-') or '+' |
|
1597 | 1597 | r = rev |
|
1598 | 1598 | else: |
|
1599 | 1599 | change = ((l in states) and '-') or '+' |
|
1600 | 1600 | r = prev[fn] |
|
1601 | 1601 | cols = [fn, str(rev)] |
|
1602 | 1602 | if opts['line_number']: |
|
1603 | 1603 | cols.append(str(l.linenum)) |
|
1604 | 1604 | if opts['all']: |
|
1605 | 1605 | cols.append(change) |
|
1606 | 1606 | if opts['user']: |
|
1607 | 1607 | cols.append(trimuser(ui, getchange(rev)[1], rev, |
|
1608 | 1608 | ucache)) |
|
1609 | 1609 | if opts['files_with_matches']: |
|
1610 | 1610 | c = (fn, rev) |
|
1611 | 1611 | if c in filerevmatches: |
|
1612 | 1612 | continue |
|
1613 | 1613 | filerevmatches[c] = 1 |
|
1614 | 1614 | else: |
|
1615 | 1615 | cols.append(l.line) |
|
1616 | 1616 | ui.write(sep.join(cols), eol) |
|
1617 | 1617 | counts[change] += 1 |
|
1618 | 1618 | return counts['+'], counts['-'] |
|
1619 | 1619 | |
|
1620 | 1620 | fstate = {} |
|
1621 | 1621 | skip = {} |
|
1622 | 1622 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1623 | 1623 | count = 0 |
|
1624 | 1624 | incrementing = False |
|
1625 | 1625 | for st, rev, fns in changeiter: |
|
1626 | 1626 | if st == 'window': |
|
1627 | 1627 | incrementing = rev |
|
1628 | 1628 | matches.clear() |
|
1629 | 1629 | elif st == 'add': |
|
1630 | 1630 | change = repo.changelog.read(repo.lookup(str(rev))) |
|
1631 | 1631 | mf = repo.manifest.read(change[0]) |
|
1632 | 1632 | matches[rev] = {} |
|
1633 | 1633 | for fn in fns: |
|
1634 | 1634 | if fn in skip: |
|
1635 | 1635 | continue |
|
1636 | 1636 | fstate.setdefault(fn, {}) |
|
1637 | 1637 | try: |
|
1638 | 1638 | grepbody(fn, rev, getfile(fn).read(mf[fn])) |
|
1639 | 1639 | except KeyError: |
|
1640 | 1640 | pass |
|
1641 | 1641 | elif st == 'iter': |
|
1642 | 1642 | states = matches[rev].items() |
|
1643 | 1643 | states.sort() |
|
1644 | 1644 | for fn, m in states: |
|
1645 | 1645 | if fn in skip: |
|
1646 | 1646 | continue |
|
1647 | 1647 | if incrementing or not opts['all'] or fstate[fn]: |
|
1648 | 1648 | pos, neg = display(fn, rev, m, fstate[fn]) |
|
1649 | 1649 | count += pos + neg |
|
1650 | 1650 | if pos and not opts['all']: |
|
1651 | 1651 | skip[fn] = True |
|
1652 | 1652 | fstate[fn] = m |
|
1653 | 1653 | prev[fn] = rev |
|
1654 | 1654 | |
|
1655 | 1655 | if not incrementing: |
|
1656 | 1656 | fstate = fstate.items() |
|
1657 | 1657 | fstate.sort() |
|
1658 | 1658 | for fn, state in fstate: |
|
1659 | 1659 | if fn in skip: |
|
1660 | 1660 | continue |
|
1661 | 1661 | display(fn, rev, {}, state) |
|
1662 | 1662 | return (count == 0 and 1) or 0 |
|
1663 | 1663 | |
|
1664 | 1664 | def heads(ui, repo, **opts): |
|
1665 | 1665 | """show current repository heads |
|
1666 | 1666 | |
|
1667 | 1667 | Show all repository head changesets. |
|
1668 | 1668 | |
|
1669 | 1669 | Repository "heads" are changesets that don't have children |
|
1670 | 1670 | changesets. They are where development generally takes place and |
|
1671 | 1671 | are the usual targets for update and merge operations. |
|
1672 | 1672 | """ |
|
1673 | 1673 | if opts['rev']: |
|
1674 | 1674 | heads = repo.heads(repo.lookup(opts['rev'])) |
|
1675 | 1675 | else: |
|
1676 | 1676 | heads = repo.heads() |
|
1677 | 1677 | br = None |
|
1678 | 1678 | if opts['branches']: |
|
1679 | 1679 | br = repo.branchlookup(heads) |
|
1680 | 1680 | displayer = show_changeset(ui, repo, opts) |
|
1681 | 1681 | for n in heads: |
|
1682 | 1682 | displayer.show(changenode=n, brinfo=br) |
|
1683 | 1683 | |
|
1684 | 1684 | def identify(ui, repo): |
|
1685 | 1685 | """print information about the working copy |
|
1686 | 1686 | |
|
1687 | 1687 | Print a short summary of the current state of the repo. |
|
1688 | 1688 | |
|
1689 | 1689 | This summary identifies the repository state using one or two parent |
|
1690 | 1690 | hash identifiers, followed by a "+" if there are uncommitted changes |
|
1691 | 1691 | in the working directory, followed by a list of tags for this revision. |
|
1692 | 1692 | """ |
|
1693 | 1693 | parents = [p for p in repo.dirstate.parents() if p != nullid] |
|
1694 | 1694 | if not parents: |
|
1695 | 1695 | ui.write(_("unknown\n")) |
|
1696 | 1696 | return |
|
1697 | 1697 | |
|
1698 | 1698 | hexfunc = ui.verbose and hex or short |
|
1699 | 1699 | modified, added, removed, deleted, unknown = repo.changes() |
|
1700 | 1700 | output = ["%s%s" % |
|
1701 | 1701 | ('+'.join([hexfunc(parent) for parent in parents]), |
|
1702 | 1702 | (modified or added or removed or deleted) and "+" or "")] |
|
1703 | 1703 | |
|
1704 | 1704 | if not ui.quiet: |
|
1705 | 1705 | # multiple tags for a single parent separated by '/' |
|
1706 | 1706 | parenttags = ['/'.join(tags) |
|
1707 | 1707 | for tags in map(repo.nodetags, parents) if tags] |
|
1708 | 1708 | # tags for multiple parents separated by ' + ' |
|
1709 | 1709 | if parenttags: |
|
1710 | 1710 | output.append(' + '.join(parenttags)) |
|
1711 | 1711 | |
|
1712 | 1712 | ui.write("%s\n" % ' '.join(output)) |
|
1713 | 1713 | |
|
1714 | 1714 | def import_(ui, repo, patch1, *patches, **opts): |
|
1715 | 1715 | """import an ordered set of patches |
|
1716 | 1716 | |
|
1717 | 1717 | Import a list of patches and commit them individually. |
|
1718 | 1718 | |
|
1719 | 1719 | If there are outstanding changes in the working directory, import |
|
1720 | 1720 | will abort unless given the -f flag. |
|
1721 | 1721 | |
|
1722 | 1722 | You can import a patch straight from a mail message. Even patches |
|
1723 | 1723 | as attachments work (body part must be type text/plain or |
|
1724 | 1724 | text/x-patch to be used). Sender and subject line of email |
|
1725 | 1725 | message are used as default committer and commit message. Any |
|
1726 | 1726 | text/plain body part before first diff is added to commit message. |
|
1727 | 1727 | |
|
1728 | 1728 | If imported patch was generated by hg export, user and description |
|
1729 | 1729 | from patch override values from message headers and body. Values |
|
1730 | 1730 | given on command line with -m and -u override these. |
|
1731 | 1731 | |
|
1732 | 1732 | To read a patch from standard input, use patch name "-". |
|
1733 | 1733 | """ |
|
1734 | 1734 | patches = (patch1,) + patches |
|
1735 | 1735 | |
|
1736 | 1736 | if not opts['force']: |
|
1737 | 1737 | bail_if_changed(repo) |
|
1738 | 1738 | |
|
1739 | 1739 | d = opts["base"] |
|
1740 | 1740 | strip = opts["strip"] |
|
1741 | 1741 | |
|
1742 | 1742 | mailre = re.compile(r'(?:From |[\w-]+:)') |
|
1743 | 1743 | |
|
1744 | 1744 | # attempt to detect the start of a patch |
|
1745 | 1745 | # (this heuristic is borrowed from quilt) |
|
1746 | 1746 | diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |' + |
|
1747 | 1747 | 'retrieving revision [0-9]+(\.[0-9]+)*$|' + |
|
1748 | 1748 | '(---|\*\*\*)[ \t])', re.MULTILINE) |
|
1749 | 1749 | |
|
1750 | 1750 | for patch in patches: |
|
1751 | 1751 | pf = os.path.join(d, patch) |
|
1752 | 1752 | |
|
1753 | 1753 | message = None |
|
1754 | 1754 | user = None |
|
1755 | 1755 | date = None |
|
1756 | 1756 | hgpatch = False |
|
1757 | 1757 | |
|
1758 | 1758 | p = email.Parser.Parser() |
|
1759 | 1759 | if pf == '-': |
|
1760 | 1760 | msg = p.parse(sys.stdin) |
|
1761 | 1761 | ui.status(_("applying patch from stdin\n")) |
|
1762 | 1762 | else: |
|
1763 | 1763 | msg = p.parse(file(pf)) |
|
1764 | 1764 | ui.status(_("applying %s\n") % patch) |
|
1765 | 1765 | |
|
1766 | 1766 | fd, tmpname = tempfile.mkstemp(prefix='hg-patch-') |
|
1767 | 1767 | tmpfp = os.fdopen(fd, 'w') |
|
1768 | 1768 | try: |
|
1769 | 1769 | message = msg['Subject'] |
|
1770 | 1770 | if message: |
|
1771 | 1771 | message = message.replace('\n\t', ' ') |
|
1772 | 1772 | ui.debug('Subject: %s\n' % message) |
|
1773 | 1773 | user = msg['From'] |
|
1774 | 1774 | if user: |
|
1775 | 1775 | ui.debug('From: %s\n' % user) |
|
1776 | 1776 | diffs_seen = 0 |
|
1777 | 1777 | ok_types = ('text/plain', 'text/x-patch') |
|
1778 | 1778 | for part in msg.walk(): |
|
1779 | 1779 | content_type = part.get_content_type() |
|
1780 | 1780 | ui.debug('Content-Type: %s\n' % content_type) |
|
1781 | 1781 | if content_type not in ok_types: |
|
1782 | 1782 | continue |
|
1783 | 1783 | payload = part.get_payload(decode=True) |
|
1784 | 1784 | m = diffre.search(payload) |
|
1785 | 1785 | if m: |
|
1786 | 1786 | ui.debug(_('found patch at byte %d\n') % m.start(0)) |
|
1787 | 1787 | diffs_seen += 1 |
|
1788 | 1788 | hgpatch = False |
|
1789 | 1789 | fp = cStringIO.StringIO() |
|
1790 | if message: | |
|
1791 | fp.write(message) | |
|
1792 | fp.write('\n') | |
|
1790 | 1793 | for line in payload[:m.start(0)].splitlines(): |
|
1791 | 1794 | if line.startswith('# HG changeset patch'): |
|
1792 | 1795 | ui.debug(_('patch generated by hg export\n')) |
|
1793 | 1796 | hgpatch = True |
|
1797 | # drop earlier commit message content | |
|
1798 | fp.seek(0) | |
|
1799 | fp.truncate() | |
|
1794 | 1800 | elif hgpatch: |
|
1795 | 1801 | if line.startswith('# User '): |
|
1796 | 1802 | user = line[7:] |
|
1797 | 1803 | ui.debug('From: %s\n' % user) |
|
1798 | 1804 | elif line.startswith("# Date "): |
|
1799 | 1805 | date = line[7:] |
|
1800 | 1806 | if not line.startswith('# '): |
|
1801 | 1807 | fp.write(line) |
|
1802 | 1808 | fp.write('\n') |
|
1803 |
|
|
|
1804 | message = fp.getvalue() or message | |
|
1809 | message = fp.getvalue() | |
|
1805 | 1810 | if tmpfp: |
|
1806 | 1811 | tmpfp.write(payload) |
|
1807 | 1812 | if not payload.endswith('\n'): |
|
1808 | 1813 | tmpfp.write('\n') |
|
1809 | 1814 | elif not diffs_seen and message and content_type == 'text/plain': |
|
1810 | 1815 | message += '\n' + payload |
|
1811 | 1816 | |
|
1812 | 1817 | if opts['message']: |
|
1813 | 1818 | # pickup the cmdline msg |
|
1814 | 1819 | message = opts['message'] |
|
1815 | 1820 | elif message: |
|
1816 | 1821 | # pickup the patch msg |
|
1817 | 1822 | message = message.strip() |
|
1818 | 1823 | else: |
|
1819 | 1824 | # launch the editor |
|
1820 | 1825 | message = None |
|
1821 | 1826 | ui.debug(_('message:\n%s\n') % message) |
|
1822 | 1827 | |
|
1823 | 1828 | tmpfp.close() |
|
1824 | 1829 | if not diffs_seen: |
|
1825 | 1830 | raise util.Abort(_('no diffs found')) |
|
1826 | 1831 | |
|
1827 | 1832 | files = util.patch(strip, tmpname, ui) |
|
1828 | 1833 | if len(files) > 0: |
|
1829 | 1834 | addremove_lock(ui, repo, files, {}) |
|
1830 | 1835 | repo.commit(files, message, user, date) |
|
1831 | 1836 | finally: |
|
1832 | 1837 | os.unlink(tmpname) |
|
1833 | 1838 | |
|
1834 | 1839 | def incoming(ui, repo, source="default", **opts): |
|
1835 | 1840 | """show new changesets found in source |
|
1836 | 1841 | |
|
1837 | 1842 | Show new changesets found in the specified path/URL or the default |
|
1838 | 1843 | pull location. These are the changesets that would be pulled if a pull |
|
1839 | 1844 | was requested. |
|
1840 | 1845 | |
|
1841 | 1846 | For remote repository, using --bundle avoids downloading the changesets |
|
1842 | 1847 | twice if the incoming is followed by a pull. |
|
1843 | 1848 | |
|
1844 | 1849 | See pull for valid source format details. |
|
1845 | 1850 | """ |
|
1846 | 1851 | source = ui.expandpath(source) |
|
1847 | 1852 | if opts['ssh']: |
|
1848 | 1853 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
1849 | 1854 | if opts['remotecmd']: |
|
1850 | 1855 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
1851 | 1856 | |
|
1852 | 1857 | other = hg.repository(ui, source) |
|
1853 | 1858 | incoming = repo.findincoming(other, force=opts["force"]) |
|
1854 | 1859 | if not incoming: |
|
1855 | 1860 | ui.status(_("no changes found\n")) |
|
1856 | 1861 | return |
|
1857 | 1862 | |
|
1858 | 1863 | cleanup = None |
|
1859 | 1864 | try: |
|
1860 | 1865 | fname = opts["bundle"] |
|
1861 | 1866 | if fname or not other.local(): |
|
1862 | 1867 | # create a bundle (uncompressed if other repo is not local) |
|
1863 | 1868 | cg = other.changegroup(incoming, "incoming") |
|
1864 | 1869 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) |
|
1865 | 1870 | # keep written bundle? |
|
1866 | 1871 | if opts["bundle"]: |
|
1867 | 1872 | cleanup = None |
|
1868 | 1873 | if not other.local(): |
|
1869 | 1874 | # use the created uncompressed bundlerepo |
|
1870 | 1875 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1871 | 1876 | |
|
1872 | 1877 | o = other.changelog.nodesbetween(incoming)[0] |
|
1873 | 1878 | if opts['newest_first']: |
|
1874 | 1879 | o.reverse() |
|
1875 | 1880 | displayer = show_changeset(ui, other, opts) |
|
1876 | 1881 | for n in o: |
|
1877 | 1882 | parents = [p for p in other.changelog.parents(n) if p != nullid] |
|
1878 | 1883 | if opts['no_merges'] and len(parents) == 2: |
|
1879 | 1884 | continue |
|
1880 | 1885 | displayer.show(changenode=n) |
|
1881 | 1886 | if opts['patch']: |
|
1882 | 1887 | prev = (parents and parents[0]) or nullid |
|
1883 | 1888 | dodiff(ui, ui, other, prev, n) |
|
1884 | 1889 | ui.write("\n") |
|
1885 | 1890 | finally: |
|
1886 | 1891 | if hasattr(other, 'close'): |
|
1887 | 1892 | other.close() |
|
1888 | 1893 | if cleanup: |
|
1889 | 1894 | os.unlink(cleanup) |
|
1890 | 1895 | |
|
1891 | 1896 | def init(ui, dest="."): |
|
1892 | 1897 | """create a new repository in the given directory |
|
1893 | 1898 | |
|
1894 | 1899 | Initialize a new repository in the given directory. If the given |
|
1895 | 1900 | directory does not exist, it is created. |
|
1896 | 1901 | |
|
1897 | 1902 | If no directory is given, the current directory is used. |
|
1898 | 1903 | """ |
|
1899 | 1904 | if not os.path.exists(dest): |
|
1900 | 1905 | os.mkdir(dest) |
|
1901 | 1906 | hg.repository(ui, dest, create=1) |
|
1902 | 1907 | |
|
1903 | 1908 | def locate(ui, repo, *pats, **opts): |
|
1904 | 1909 | """locate files matching specific patterns |
|
1905 | 1910 | |
|
1906 | 1911 | Print all files under Mercurial control whose names match the |
|
1907 | 1912 | given patterns. |
|
1908 | 1913 | |
|
1909 | 1914 | This command searches the current directory and its |
|
1910 | 1915 | subdirectories. To search an entire repository, move to the root |
|
1911 | 1916 | of the repository. |
|
1912 | 1917 | |
|
1913 | 1918 | If no patterns are given to match, this command prints all file |
|
1914 | 1919 | names. |
|
1915 | 1920 | |
|
1916 | 1921 | If you want to feed the output of this command into the "xargs" |
|
1917 | 1922 | command, use the "-0" option to both this command and "xargs". |
|
1918 | 1923 | This will avoid the problem of "xargs" treating single filenames |
|
1919 | 1924 | that contain white space as multiple filenames. |
|
1920 | 1925 | """ |
|
1921 | 1926 | end = opts['print0'] and '\0' or '\n' |
|
1922 | 1927 | rev = opts['rev'] |
|
1923 | 1928 | if rev: |
|
1924 | 1929 | node = repo.lookup(rev) |
|
1925 | 1930 | else: |
|
1926 | 1931 | node = None |
|
1927 | 1932 | |
|
1928 | 1933 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
1929 | 1934 | head='(?:.*/|)'): |
|
1930 | 1935 | if not node and repo.dirstate.state(abs) == '?': |
|
1931 | 1936 | continue |
|
1932 | 1937 | if opts['fullpath']: |
|
1933 | 1938 | ui.write(os.path.join(repo.root, abs), end) |
|
1934 | 1939 | else: |
|
1935 | 1940 | ui.write(((pats and rel) or abs), end) |
|
1936 | 1941 | |
|
1937 | 1942 | def log(ui, repo, *pats, **opts): |
|
1938 | 1943 | """show revision history of entire repository or files |
|
1939 | 1944 | |
|
1940 | 1945 | Print the revision history of the specified files or the entire project. |
|
1941 | 1946 | |
|
1942 | 1947 | By default this command outputs: changeset id and hash, tags, |
|
1943 | 1948 | non-trivial parents, user, date and time, and a summary for each |
|
1944 | 1949 | commit. When the -v/--verbose switch is used, the list of changed |
|
1945 | 1950 | files and full commit message is shown. |
|
1946 | 1951 | """ |
|
1947 | 1952 | class dui(object): |
|
1948 | 1953 | # Implement and delegate some ui protocol. Save hunks of |
|
1949 | 1954 | # output for later display in the desired order. |
|
1950 | 1955 | def __init__(self, ui): |
|
1951 | 1956 | self.ui = ui |
|
1952 | 1957 | self.hunk = {} |
|
1953 | 1958 | self.header = {} |
|
1954 | 1959 | def bump(self, rev): |
|
1955 | 1960 | self.rev = rev |
|
1956 | 1961 | self.hunk[rev] = [] |
|
1957 | 1962 | self.header[rev] = [] |
|
1958 | 1963 | def note(self, *args): |
|
1959 | 1964 | if self.verbose: |
|
1960 | 1965 | self.write(*args) |
|
1961 | 1966 | def status(self, *args): |
|
1962 | 1967 | if not self.quiet: |
|
1963 | 1968 | self.write(*args) |
|
1964 | 1969 | def write(self, *args): |
|
1965 | 1970 | self.hunk[self.rev].append(args) |
|
1966 | 1971 | def write_header(self, *args): |
|
1967 | 1972 | self.header[self.rev].append(args) |
|
1968 | 1973 | def debug(self, *args): |
|
1969 | 1974 | if self.debugflag: |
|
1970 | 1975 | self.write(*args) |
|
1971 | 1976 | def __getattr__(self, key): |
|
1972 | 1977 | return getattr(self.ui, key) |
|
1973 | 1978 | |
|
1974 | 1979 | changeiter, getchange, matchfn = walkchangerevs(ui, repo, pats, opts) |
|
1975 | 1980 | |
|
1976 | 1981 | if opts['limit']: |
|
1977 | 1982 | try: |
|
1978 | 1983 | limit = int(opts['limit']) |
|
1979 | 1984 | except ValueError: |
|
1980 | 1985 | raise util.Abort(_('limit must be a positive integer')) |
|
1981 | 1986 | if limit <= 0: raise util.Abort(_('limit must be positive')) |
|
1982 | 1987 | else: |
|
1983 | 1988 | limit = sys.maxint |
|
1984 | 1989 | count = 0 |
|
1985 | 1990 | |
|
1986 | 1991 | displayer = show_changeset(ui, repo, opts) |
|
1987 | 1992 | for st, rev, fns in changeiter: |
|
1988 | 1993 | if st == 'window': |
|
1989 | 1994 | du = dui(ui) |
|
1990 | 1995 | displayer.ui = du |
|
1991 | 1996 | elif st == 'add': |
|
1992 | 1997 | du.bump(rev) |
|
1993 | 1998 | changenode = repo.changelog.node(rev) |
|
1994 | 1999 | parents = [p for p in repo.changelog.parents(changenode) |
|
1995 | 2000 | if p != nullid] |
|
1996 | 2001 | if opts['no_merges'] and len(parents) == 2: |
|
1997 | 2002 | continue |
|
1998 | 2003 | if opts['only_merges'] and len(parents) != 2: |
|
1999 | 2004 | continue |
|
2000 | 2005 | |
|
2001 | 2006 | if opts['keyword']: |
|
2002 | 2007 | changes = getchange(rev) |
|
2003 | 2008 | miss = 0 |
|
2004 | 2009 | for k in [kw.lower() for kw in opts['keyword']]: |
|
2005 | 2010 | if not (k in changes[1].lower() or |
|
2006 | 2011 | k in changes[4].lower() or |
|
2007 | 2012 | k in " ".join(changes[3][:20]).lower()): |
|
2008 | 2013 | miss = 1 |
|
2009 | 2014 | break |
|
2010 | 2015 | if miss: |
|
2011 | 2016 | continue |
|
2012 | 2017 | |
|
2013 | 2018 | br = None |
|
2014 | 2019 | if opts['branches']: |
|
2015 | 2020 | br = repo.branchlookup([repo.changelog.node(rev)]) |
|
2016 | 2021 | |
|
2017 | 2022 | displayer.show(rev, brinfo=br) |
|
2018 | 2023 | if opts['patch']: |
|
2019 | 2024 | prev = (parents and parents[0]) or nullid |
|
2020 | 2025 | dodiff(du, du, repo, prev, changenode, match=matchfn) |
|
2021 | 2026 | du.write("\n\n") |
|
2022 | 2027 | elif st == 'iter': |
|
2023 | 2028 | if count == limit: break |
|
2024 | 2029 | if du.header[rev]: |
|
2025 | 2030 | for args in du.header[rev]: |
|
2026 | 2031 | ui.write_header(*args) |
|
2027 | 2032 | if du.hunk[rev]: |
|
2028 | 2033 | count += 1 |
|
2029 | 2034 | for args in du.hunk[rev]: |
|
2030 | 2035 | ui.write(*args) |
|
2031 | 2036 | |
|
2032 | 2037 | def manifest(ui, repo, rev=None): |
|
2033 | 2038 | """output the latest or given revision of the project manifest |
|
2034 | 2039 | |
|
2035 | 2040 | Print a list of version controlled files for the given revision. |
|
2036 | 2041 | |
|
2037 | 2042 | The manifest is the list of files being version controlled. If no revision |
|
2038 | 2043 | is given then the tip is used. |
|
2039 | 2044 | """ |
|
2040 | 2045 | if rev: |
|
2041 | 2046 | try: |
|
2042 | 2047 | # assume all revision numbers are for changesets |
|
2043 | 2048 | n = repo.lookup(rev) |
|
2044 | 2049 | change = repo.changelog.read(n) |
|
2045 | 2050 | n = change[0] |
|
2046 | 2051 | except hg.RepoError: |
|
2047 | 2052 | n = repo.manifest.lookup(rev) |
|
2048 | 2053 | else: |
|
2049 | 2054 | n = repo.manifest.tip() |
|
2050 | 2055 | m = repo.manifest.read(n) |
|
2051 | 2056 | mf = repo.manifest.readflags(n) |
|
2052 | 2057 | files = m.keys() |
|
2053 | 2058 | files.sort() |
|
2054 | 2059 | |
|
2055 | 2060 | for f in files: |
|
2056 | 2061 | ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) |
|
2057 | 2062 | |
|
2058 | 2063 | def merge(ui, repo, node=None, **opts): |
|
2059 | 2064 | """Merge working directory with another revision |
|
2060 | 2065 | |
|
2061 | 2066 | Merge the contents of the current working directory and the |
|
2062 | 2067 | requested revision. Files that changed between either parent are |
|
2063 | 2068 | marked as changed for the next commit and a commit must be |
|
2064 | 2069 | performed before any further updates are allowed. |
|
2065 | 2070 | """ |
|
2066 | 2071 | return doupdate(ui, repo, node=node, merge=True, **opts) |
|
2067 | 2072 | |
|
2068 | 2073 | def outgoing(ui, repo, dest=None, **opts): |
|
2069 | 2074 | """show changesets not found in destination |
|
2070 | 2075 | |
|
2071 | 2076 | Show changesets not found in the specified destination repository or |
|
2072 | 2077 | the default push location. These are the changesets that would be pushed |
|
2073 | 2078 | if a push was requested. |
|
2074 | 2079 | |
|
2075 | 2080 | See pull for valid destination format details. |
|
2076 | 2081 | """ |
|
2077 | 2082 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
2078 | 2083 | if opts['ssh']: |
|
2079 | 2084 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2080 | 2085 | if opts['remotecmd']: |
|
2081 | 2086 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2082 | 2087 | |
|
2083 | 2088 | other = hg.repository(ui, dest) |
|
2084 | 2089 | o = repo.findoutgoing(other, force=opts['force']) |
|
2085 | 2090 | if not o: |
|
2086 | 2091 | ui.status(_("no changes found\n")) |
|
2087 | 2092 | return |
|
2088 | 2093 | o = repo.changelog.nodesbetween(o)[0] |
|
2089 | 2094 | if opts['newest_first']: |
|
2090 | 2095 | o.reverse() |
|
2091 | 2096 | displayer = show_changeset(ui, repo, opts) |
|
2092 | 2097 | for n in o: |
|
2093 | 2098 | parents = [p for p in repo.changelog.parents(n) if p != nullid] |
|
2094 | 2099 | if opts['no_merges'] and len(parents) == 2: |
|
2095 | 2100 | continue |
|
2096 | 2101 | displayer.show(changenode=n) |
|
2097 | 2102 | if opts['patch']: |
|
2098 | 2103 | prev = (parents and parents[0]) or nullid |
|
2099 | 2104 | dodiff(ui, ui, repo, prev, n) |
|
2100 | 2105 | ui.write("\n") |
|
2101 | 2106 | |
|
2102 | 2107 | def parents(ui, repo, rev=None, branches=None, **opts): |
|
2103 | 2108 | """show the parents of the working dir or revision |
|
2104 | 2109 | |
|
2105 | 2110 | Print the working directory's parent revisions. |
|
2106 | 2111 | """ |
|
2107 | 2112 | if rev: |
|
2108 | 2113 | p = repo.changelog.parents(repo.lookup(rev)) |
|
2109 | 2114 | else: |
|
2110 | 2115 | p = repo.dirstate.parents() |
|
2111 | 2116 | |
|
2112 | 2117 | br = None |
|
2113 | 2118 | if branches is not None: |
|
2114 | 2119 | br = repo.branchlookup(p) |
|
2115 | 2120 | displayer = show_changeset(ui, repo, opts) |
|
2116 | 2121 | for n in p: |
|
2117 | 2122 | if n != nullid: |
|
2118 | 2123 | displayer.show(changenode=n, brinfo=br) |
|
2119 | 2124 | |
|
2120 | 2125 | def paths(ui, repo, search=None): |
|
2121 | 2126 | """show definition of symbolic path names |
|
2122 | 2127 | |
|
2123 | 2128 | Show definition of symbolic path name NAME. If no name is given, show |
|
2124 | 2129 | definition of available names. |
|
2125 | 2130 | |
|
2126 | 2131 | Path names are defined in the [paths] section of /etc/mercurial/hgrc |
|
2127 | 2132 | and $HOME/.hgrc. If run inside a repository, .hg/hgrc is used, too. |
|
2128 | 2133 | """ |
|
2129 | 2134 | if search: |
|
2130 | 2135 | for name, path in ui.configitems("paths"): |
|
2131 | 2136 | if name == search: |
|
2132 | 2137 | ui.write("%s\n" % path) |
|
2133 | 2138 | return |
|
2134 | 2139 | ui.warn(_("not found!\n")) |
|
2135 | 2140 | return 1 |
|
2136 | 2141 | else: |
|
2137 | 2142 | for name, path in ui.configitems("paths"): |
|
2138 | 2143 | ui.write("%s = %s\n" % (name, path)) |
|
2139 | 2144 | |
|
2140 | 2145 | def postincoming(ui, repo, modheads, optupdate): |
|
2141 | 2146 | if modheads == 0: |
|
2142 | 2147 | return |
|
2143 | 2148 | if optupdate: |
|
2144 | 2149 | if modheads == 1: |
|
2145 | 2150 | return doupdate(ui, repo) |
|
2146 | 2151 | else: |
|
2147 | 2152 | ui.status(_("not updating, since new heads added\n")) |
|
2148 | 2153 | if modheads > 1: |
|
2149 | 2154 | ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) |
|
2150 | 2155 | else: |
|
2151 | 2156 | ui.status(_("(run 'hg update' to get a working copy)\n")) |
|
2152 | 2157 | |
|
2153 | 2158 | def pull(ui, repo, source="default", **opts): |
|
2154 | 2159 | """pull changes from the specified source |
|
2155 | 2160 | |
|
2156 | 2161 | Pull changes from a remote repository to a local one. |
|
2157 | 2162 | |
|
2158 | 2163 | This finds all changes from the repository at the specified path |
|
2159 | 2164 | or URL and adds them to the local repository. By default, this |
|
2160 | 2165 | does not update the copy of the project in the working directory. |
|
2161 | 2166 | |
|
2162 | 2167 | Valid URLs are of the form: |
|
2163 | 2168 | |
|
2164 | 2169 | local/filesystem/path |
|
2165 | 2170 | http://[user@]host[:port][/path] |
|
2166 | 2171 | https://[user@]host[:port][/path] |
|
2167 | 2172 | ssh://[user@]host[:port][/path] |
|
2168 | 2173 | |
|
2169 | 2174 | Some notes about using SSH with Mercurial: |
|
2170 | 2175 | - SSH requires an accessible shell account on the destination machine |
|
2171 | 2176 | and a copy of hg in the remote path or specified with as remotecmd. |
|
2172 | 2177 | - /path is relative to the remote user's home directory by default. |
|
2173 | 2178 | Use two slashes at the start of a path to specify an absolute path. |
|
2174 | 2179 | - Mercurial doesn't use its own compression via SSH; the right thing |
|
2175 | 2180 | to do is to configure it in your ~/.ssh/ssh_config, e.g.: |
|
2176 | 2181 | Host *.mylocalnetwork.example.com |
|
2177 | 2182 | Compression off |
|
2178 | 2183 | Host * |
|
2179 | 2184 | Compression on |
|
2180 | 2185 | Alternatively specify "ssh -C" as your ssh command in your hgrc or |
|
2181 | 2186 | with the --ssh command line option. |
|
2182 | 2187 | """ |
|
2183 | 2188 | source = ui.expandpath(source) |
|
2184 | 2189 | |
|
2185 | 2190 | if opts['ssh']: |
|
2186 | 2191 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2187 | 2192 | if opts['remotecmd']: |
|
2188 | 2193 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2189 | 2194 | |
|
2190 | 2195 | other = hg.repository(ui, source) |
|
2191 | 2196 | ui.status(_('pulling from %s\n') % (source)) |
|
2192 | 2197 | revs = None |
|
2193 | 2198 | if opts['rev'] and not other.local(): |
|
2194 | 2199 | raise util.Abort(_("pull -r doesn't work for remote repositories yet")) |
|
2195 | 2200 | elif opts['rev']: |
|
2196 | 2201 | revs = [other.lookup(rev) for rev in opts['rev']] |
|
2197 | 2202 | modheads = repo.pull(other, heads=revs, force=opts['force']) |
|
2198 | 2203 | return postincoming(ui, repo, modheads, opts['update']) |
|
2199 | 2204 | |
|
2200 | 2205 | def push(ui, repo, dest=None, **opts): |
|
2201 | 2206 | """push changes to the specified destination |
|
2202 | 2207 | |
|
2203 | 2208 | Push changes from the local repository to the given destination. |
|
2204 | 2209 | |
|
2205 | 2210 | This is the symmetrical operation for pull. It helps to move |
|
2206 | 2211 | changes from the current repository to a different one. If the |
|
2207 | 2212 | destination is local this is identical to a pull in that directory |
|
2208 | 2213 | from the current one. |
|
2209 | 2214 | |
|
2210 | 2215 | By default, push will refuse to run if it detects the result would |
|
2211 | 2216 | increase the number of remote heads. This generally indicates the |
|
2212 | 2217 | the client has forgotten to sync and merge before pushing. |
|
2213 | 2218 | |
|
2214 | 2219 | Valid URLs are of the form: |
|
2215 | 2220 | |
|
2216 | 2221 | local/filesystem/path |
|
2217 | 2222 | ssh://[user@]host[:port][/path] |
|
2218 | 2223 | |
|
2219 | 2224 | Look at the help text for the pull command for important details |
|
2220 | 2225 | about ssh:// URLs. |
|
2221 | 2226 | """ |
|
2222 | 2227 | dest = ui.expandpath(dest or 'default-push', dest or 'default') |
|
2223 | 2228 | |
|
2224 | 2229 | if opts['ssh']: |
|
2225 | 2230 | ui.setconfig("ui", "ssh", opts['ssh']) |
|
2226 | 2231 | if opts['remotecmd']: |
|
2227 | 2232 | ui.setconfig("ui", "remotecmd", opts['remotecmd']) |
|
2228 | 2233 | |
|
2229 | 2234 | other = hg.repository(ui, dest) |
|
2230 | 2235 | ui.status('pushing to %s\n' % (dest)) |
|
2231 | 2236 | revs = None |
|
2232 | 2237 | if opts['rev']: |
|
2233 | 2238 | revs = [repo.lookup(rev) for rev in opts['rev']] |
|
2234 | 2239 | r = repo.push(other, opts['force'], revs=revs) |
|
2235 | 2240 | return r == 0 |
|
2236 | 2241 | |
|
2237 | 2242 | def rawcommit(ui, repo, *flist, **rc): |
|
2238 | 2243 | """raw commit interface (DEPRECATED) |
|
2239 | 2244 | |
|
2240 | 2245 | (DEPRECATED) |
|
2241 | 2246 | Lowlevel commit, for use in helper scripts. |
|
2242 | 2247 | |
|
2243 | 2248 | This command is not intended to be used by normal users, as it is |
|
2244 | 2249 | primarily useful for importing from other SCMs. |
|
2245 | 2250 | |
|
2246 | 2251 | This command is now deprecated and will be removed in a future |
|
2247 | 2252 | release, please use debugsetparents and commit instead. |
|
2248 | 2253 | """ |
|
2249 | 2254 | |
|
2250 | 2255 | ui.warn(_("(the rawcommit command is deprecated)\n")) |
|
2251 | 2256 | |
|
2252 | 2257 | message = rc['message'] |
|
2253 | 2258 | if not message and rc['logfile']: |
|
2254 | 2259 | try: |
|
2255 | 2260 | message = open(rc['logfile']).read() |
|
2256 | 2261 | except IOError: |
|
2257 | 2262 | pass |
|
2258 | 2263 | if not message and not rc['logfile']: |
|
2259 | 2264 | raise util.Abort(_("missing commit message")) |
|
2260 | 2265 | |
|
2261 | 2266 | files = relpath(repo, list(flist)) |
|
2262 | 2267 | if rc['files']: |
|
2263 | 2268 | files += open(rc['files']).read().splitlines() |
|
2264 | 2269 | |
|
2265 | 2270 | rc['parent'] = map(repo.lookup, rc['parent']) |
|
2266 | 2271 | |
|
2267 | 2272 | try: |
|
2268 | 2273 | repo.rawcommit(files, message, rc['user'], rc['date'], *rc['parent']) |
|
2269 | 2274 | except ValueError, inst: |
|
2270 | 2275 | raise util.Abort(str(inst)) |
|
2271 | 2276 | |
|
2272 | 2277 | def recover(ui, repo): |
|
2273 | 2278 | """roll back an interrupted transaction |
|
2274 | 2279 | |
|
2275 | 2280 | Recover from an interrupted commit or pull. |
|
2276 | 2281 | |
|
2277 | 2282 | This command tries to fix the repository status after an interrupted |
|
2278 | 2283 | operation. It should only be necessary when Mercurial suggests it. |
|
2279 | 2284 | """ |
|
2280 | 2285 | if repo.recover(): |
|
2281 | 2286 | return repo.verify() |
|
2282 | 2287 | return 1 |
|
2283 | 2288 | |
|
2284 | 2289 | def remove(ui, repo, *pats, **opts): |
|
2285 | 2290 | """remove the specified files on the next commit |
|
2286 | 2291 | |
|
2287 | 2292 | Schedule the indicated files for removal from the repository. |
|
2288 | 2293 | |
|
2289 | 2294 | This command schedules the files to be removed at the next commit. |
|
2290 | 2295 | This only removes files from the current branch, not from the |
|
2291 | 2296 | entire project history. If the files still exist in the working |
|
2292 | 2297 | directory, they will be deleted from it. If invoked with --after, |
|
2293 | 2298 | files that have been manually deleted are marked as removed. |
|
2294 | 2299 | |
|
2295 | 2300 | Modified files and added files are not removed by default. To |
|
2296 | 2301 | remove them, use the -f/--force option. |
|
2297 | 2302 | """ |
|
2298 | 2303 | names = [] |
|
2299 | 2304 | if not opts['after'] and not pats: |
|
2300 | 2305 | raise util.Abort(_('no files specified')) |
|
2301 | 2306 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2302 | 2307 | exact = dict.fromkeys(files) |
|
2303 | 2308 | mardu = map(dict.fromkeys, repo.changes(files=files, match=matchfn)) |
|
2304 | 2309 | modified, added, removed, deleted, unknown = mardu |
|
2305 | 2310 | remove, forget = [], [] |
|
2306 | 2311 | for src, abs, rel, exact in walk(repo, pats, opts): |
|
2307 | 2312 | reason = None |
|
2308 | 2313 | if abs not in deleted and opts['after']: |
|
2309 | 2314 | reason = _('is still present') |
|
2310 | 2315 | elif abs in modified and not opts['force']: |
|
2311 | 2316 | reason = _('is modified (use -f to force removal)') |
|
2312 | 2317 | elif abs in added: |
|
2313 | 2318 | if opts['force']: |
|
2314 | 2319 | forget.append(abs) |
|
2315 | 2320 | continue |
|
2316 | 2321 | reason = _('has been marked for add (use -f to force removal)') |
|
2317 | 2322 | elif abs in unknown: |
|
2318 | 2323 | reason = _('is not managed') |
|
2319 | 2324 | elif abs in removed: |
|
2320 | 2325 | continue |
|
2321 | 2326 | if reason: |
|
2322 | 2327 | if exact: |
|
2323 | 2328 | ui.warn(_('not removing %s: file %s\n') % (rel, reason)) |
|
2324 | 2329 | else: |
|
2325 | 2330 | if ui.verbose or not exact: |
|
2326 | 2331 | ui.status(_('removing %s\n') % rel) |
|
2327 | 2332 | remove.append(abs) |
|
2328 | 2333 | repo.forget(forget) |
|
2329 | 2334 | repo.remove(remove, unlink=not opts['after']) |
|
2330 | 2335 | |
|
2331 | 2336 | def rename(ui, repo, *pats, **opts): |
|
2332 | 2337 | """rename files; equivalent of copy + remove |
|
2333 | 2338 | |
|
2334 | 2339 | Mark dest as copies of sources; mark sources for deletion. If |
|
2335 | 2340 | dest is a directory, copies are put in that directory. If dest is |
|
2336 | 2341 | a file, there can only be one source. |
|
2337 | 2342 | |
|
2338 | 2343 | By default, this command copies the contents of files as they |
|
2339 | 2344 | stand in the working directory. If invoked with --after, the |
|
2340 | 2345 | operation is recorded, but no copying is performed. |
|
2341 | 2346 | |
|
2342 | 2347 | This command takes effect in the next commit. |
|
2343 | 2348 | |
|
2344 | 2349 | NOTE: This command should be treated as experimental. While it |
|
2345 | 2350 | should properly record rename files, this information is not yet |
|
2346 | 2351 | fully used by merge, nor fully reported by log. |
|
2347 | 2352 | """ |
|
2348 | 2353 | wlock = repo.wlock(0) |
|
2349 | 2354 | errs, copied = docopy(ui, repo, pats, opts, wlock) |
|
2350 | 2355 | names = [] |
|
2351 | 2356 | for abs, rel, exact in copied: |
|
2352 | 2357 | if ui.verbose or not exact: |
|
2353 | 2358 | ui.status(_('removing %s\n') % rel) |
|
2354 | 2359 | names.append(abs) |
|
2355 | 2360 | if not opts.get('dry_run'): |
|
2356 | 2361 | repo.remove(names, True, wlock) |
|
2357 | 2362 | return errs |
|
2358 | 2363 | |
|
2359 | 2364 | def revert(ui, repo, *pats, **opts): |
|
2360 | 2365 | """revert files or dirs to their states as of some revision |
|
2361 | 2366 | |
|
2362 | 2367 | With no revision specified, revert the named files or directories |
|
2363 | 2368 | to the contents they had in the parent of the working directory. |
|
2364 | 2369 | This restores the contents of the affected files to an unmodified |
|
2365 | 2370 | state. If the working directory has two parents, you must |
|
2366 | 2371 | explicitly specify the revision to revert to. |
|
2367 | 2372 | |
|
2368 | 2373 | Modified files are saved with a .orig suffix before reverting. |
|
2369 | 2374 | To disable these backups, use --no-backup. |
|
2370 | 2375 | |
|
2371 | 2376 | Using the -r option, revert the given files or directories to |
|
2372 | 2377 | their contents as of a specific revision. This can be helpful to"roll |
|
2373 | 2378 | back" some or all of a change that should not have been committed. |
|
2374 | 2379 | |
|
2375 | 2380 | Revert modifies the working directory. It does not commit any |
|
2376 | 2381 | changes, or change the parent of the working directory. If you |
|
2377 | 2382 | revert to a revision other than the parent of the working |
|
2378 | 2383 | directory, the reverted files will thus appear modified |
|
2379 | 2384 | afterwards. |
|
2380 | 2385 | |
|
2381 | 2386 | If a file has been deleted, it is recreated. If the executable |
|
2382 | 2387 | mode of a file was changed, it is reset. |
|
2383 | 2388 | |
|
2384 | 2389 | If names are given, all files matching the names are reverted. |
|
2385 | 2390 | |
|
2386 | 2391 | If no arguments are given, all files in the repository are reverted. |
|
2387 | 2392 | """ |
|
2388 | 2393 | parent, p2 = repo.dirstate.parents() |
|
2389 | 2394 | if opts['rev']: |
|
2390 | 2395 | node = repo.lookup(opts['rev']) |
|
2391 | 2396 | elif p2 != nullid: |
|
2392 | 2397 | raise util.Abort(_('working dir has two parents; ' |
|
2393 | 2398 | 'you must specify the revision to revert to')) |
|
2394 | 2399 | else: |
|
2395 | 2400 | node = parent |
|
2396 | 2401 | mf = repo.manifest.read(repo.changelog.read(node)[0]) |
|
2397 | 2402 | if node == parent: |
|
2398 | 2403 | pmf = mf |
|
2399 | 2404 | else: |
|
2400 | 2405 | pmf = None |
|
2401 | 2406 | |
|
2402 | 2407 | wlock = repo.wlock() |
|
2403 | 2408 | |
|
2404 | 2409 | # need all matching names in dirstate and manifest of target rev, |
|
2405 | 2410 | # so have to walk both. do not print errors if files exist in one |
|
2406 | 2411 | # but not other. |
|
2407 | 2412 | |
|
2408 | 2413 | names = {} |
|
2409 | 2414 | target_only = {} |
|
2410 | 2415 | |
|
2411 | 2416 | # walk dirstate. |
|
2412 | 2417 | |
|
2413 | 2418 | for src, abs, rel, exact in walk(repo, pats, opts, badmatch=mf.has_key): |
|
2414 | 2419 | names[abs] = (rel, exact) |
|
2415 | 2420 | if src == 'b': |
|
2416 | 2421 | target_only[abs] = True |
|
2417 | 2422 | |
|
2418 | 2423 | # walk target manifest. |
|
2419 | 2424 | |
|
2420 | 2425 | for src, abs, rel, exact in walk(repo, pats, opts, node=node, |
|
2421 | 2426 | badmatch=names.has_key): |
|
2422 | 2427 | if abs in names: continue |
|
2423 | 2428 | names[abs] = (rel, exact) |
|
2424 | 2429 | target_only[abs] = True |
|
2425 | 2430 | |
|
2426 | 2431 | changes = repo.changes(match=names.has_key, wlock=wlock) |
|
2427 | 2432 | modified, added, removed, deleted, unknown = map(dict.fromkeys, changes) |
|
2428 | 2433 | |
|
2429 | 2434 | revert = ([], _('reverting %s\n')) |
|
2430 | 2435 | add = ([], _('adding %s\n')) |
|
2431 | 2436 | remove = ([], _('removing %s\n')) |
|
2432 | 2437 | forget = ([], _('forgetting %s\n')) |
|
2433 | 2438 | undelete = ([], _('undeleting %s\n')) |
|
2434 | 2439 | update = {} |
|
2435 | 2440 | |
|
2436 | 2441 | disptable = ( |
|
2437 | 2442 | # dispatch table: |
|
2438 | 2443 | # file state |
|
2439 | 2444 | # action if in target manifest |
|
2440 | 2445 | # action if not in target manifest |
|
2441 | 2446 | # make backup if in target manifest |
|
2442 | 2447 | # make backup if not in target manifest |
|
2443 | 2448 | (modified, revert, remove, True, True), |
|
2444 | 2449 | (added, revert, forget, True, False), |
|
2445 | 2450 | (removed, undelete, None, False, False), |
|
2446 | 2451 | (deleted, revert, remove, False, False), |
|
2447 | 2452 | (unknown, add, None, True, False), |
|
2448 | 2453 | (target_only, add, None, False, False), |
|
2449 | 2454 | ) |
|
2450 | 2455 | |
|
2451 | 2456 | entries = names.items() |
|
2452 | 2457 | entries.sort() |
|
2453 | 2458 | |
|
2454 | 2459 | for abs, (rel, exact) in entries: |
|
2455 | 2460 | mfentry = mf.get(abs) |
|
2456 | 2461 | def handle(xlist, dobackup): |
|
2457 | 2462 | xlist[0].append(abs) |
|
2458 | 2463 | update[abs] = 1 |
|
2459 | 2464 | if dobackup and not opts['no_backup'] and os.path.exists(rel): |
|
2460 | 2465 | bakname = "%s.orig" % rel |
|
2461 | 2466 | ui.note(_('saving current version of %s as %s\n') % |
|
2462 | 2467 | (rel, bakname)) |
|
2463 | 2468 | if not opts.get('dry_run'): |
|
2464 | 2469 | shutil.copyfile(rel, bakname) |
|
2465 | 2470 | shutil.copymode(rel, bakname) |
|
2466 | 2471 | if ui.verbose or not exact: |
|
2467 | 2472 | ui.status(xlist[1] % rel) |
|
2468 | 2473 | for table, hitlist, misslist, backuphit, backupmiss in disptable: |
|
2469 | 2474 | if abs not in table: continue |
|
2470 | 2475 | # file has changed in dirstate |
|
2471 | 2476 | if mfentry: |
|
2472 | 2477 | handle(hitlist, backuphit) |
|
2473 | 2478 | elif misslist is not None: |
|
2474 | 2479 | handle(misslist, backupmiss) |
|
2475 | 2480 | else: |
|
2476 | 2481 | if exact: ui.warn(_('file not managed: %s\n' % rel)) |
|
2477 | 2482 | break |
|
2478 | 2483 | else: |
|
2479 | 2484 | # file has not changed in dirstate |
|
2480 | 2485 | if node == parent: |
|
2481 | 2486 | if exact: ui.warn(_('no changes needed to %s\n' % rel)) |
|
2482 | 2487 | continue |
|
2483 | 2488 | if pmf is None: |
|
2484 | 2489 | # only need parent manifest in this unlikely case, |
|
2485 | 2490 | # so do not read by default |
|
2486 | 2491 | pmf = repo.manifest.read(repo.changelog.read(parent)[0]) |
|
2487 | 2492 | if abs in pmf: |
|
2488 | 2493 | if mfentry: |
|
2489 | 2494 | # if version of file is same in parent and target |
|
2490 | 2495 | # manifests, do nothing |
|
2491 | 2496 | if pmf[abs] != mfentry: |
|
2492 | 2497 | handle(revert, False) |
|
2493 | 2498 | else: |
|
2494 | 2499 | handle(remove, False) |
|
2495 | 2500 | |
|
2496 | 2501 | if not opts.get('dry_run'): |
|
2497 | 2502 | repo.dirstate.forget(forget[0]) |
|
2498 | 2503 | r = repo.update(node, False, True, update.has_key, False, wlock=wlock, |
|
2499 | 2504 | show_stats=False) |
|
2500 | 2505 | repo.dirstate.update(add[0], 'a') |
|
2501 | 2506 | repo.dirstate.update(undelete[0], 'n') |
|
2502 | 2507 | repo.dirstate.update(remove[0], 'r') |
|
2503 | 2508 | return r |
|
2504 | 2509 | |
|
2505 | 2510 | def rollback(ui, repo): |
|
2506 | 2511 | """roll back the last transaction in this repository |
|
2507 | 2512 | |
|
2508 | 2513 | Roll back the last transaction in this repository, restoring the |
|
2509 | 2514 | project to its state prior to the transaction. |
|
2510 | 2515 | |
|
2511 | 2516 | Transactions are used to encapsulate the effects of all commands |
|
2512 | 2517 | that create new changesets or propagate existing changesets into a |
|
2513 | 2518 | repository. For example, the following commands are transactional, |
|
2514 | 2519 | and their effects can be rolled back: |
|
2515 | 2520 | |
|
2516 | 2521 | commit |
|
2517 | 2522 | import |
|
2518 | 2523 | pull |
|
2519 | 2524 | push (with this repository as destination) |
|
2520 | 2525 | unbundle |
|
2521 | 2526 | |
|
2522 | 2527 | This command should be used with care. There is only one level of |
|
2523 | 2528 | rollback, and there is no way to undo a rollback. |
|
2524 | 2529 | |
|
2525 | 2530 | This command is not intended for use on public repositories. Once |
|
2526 | 2531 | changes are visible for pull by other users, rolling a transaction |
|
2527 | 2532 | back locally is ineffective (someone else may already have pulled |
|
2528 | 2533 | the changes). Furthermore, a race is possible with readers of the |
|
2529 | 2534 | repository; for example an in-progress pull from the repository |
|
2530 | 2535 | may fail if a rollback is performed. |
|
2531 | 2536 | """ |
|
2532 | 2537 | repo.rollback() |
|
2533 | 2538 | |
|
2534 | 2539 | def root(ui, repo): |
|
2535 | 2540 | """print the root (top) of the current working dir |
|
2536 | 2541 | |
|
2537 | 2542 | Print the root directory of the current repository. |
|
2538 | 2543 | """ |
|
2539 | 2544 | ui.write(repo.root + "\n") |
|
2540 | 2545 | |
|
2541 | 2546 | def serve(ui, repo, **opts): |
|
2542 | 2547 | """export the repository via HTTP |
|
2543 | 2548 | |
|
2544 | 2549 | Start a local HTTP repository browser and pull server. |
|
2545 | 2550 | |
|
2546 | 2551 | By default, the server logs accesses to stdout and errors to |
|
2547 | 2552 | stderr. Use the "-A" and "-E" options to log to files. |
|
2548 | 2553 | """ |
|
2549 | 2554 | |
|
2550 | 2555 | if opts["stdio"]: |
|
2551 | 2556 | if repo is None: |
|
2552 | 2557 | raise hg.RepoError(_('no repo found')) |
|
2553 | 2558 | s = sshserver.sshserver(ui, repo) |
|
2554 | 2559 | s.serve_forever() |
|
2555 | 2560 | |
|
2556 | 2561 | optlist = ("name templates style address port ipv6" |
|
2557 | 2562 | " accesslog errorlog webdir_conf") |
|
2558 | 2563 | for o in optlist.split(): |
|
2559 | 2564 | if opts[o]: |
|
2560 | 2565 | ui.setconfig("web", o, opts[o]) |
|
2561 | 2566 | |
|
2562 | 2567 | if repo is None and not ui.config("web", "webdir_conf"): |
|
2563 | 2568 | raise hg.RepoError(_('no repo found')) |
|
2564 | 2569 | |
|
2565 | 2570 | if opts['daemon'] and not opts['daemon_pipefds']: |
|
2566 | 2571 | rfd, wfd = os.pipe() |
|
2567 | 2572 | args = sys.argv[:] |
|
2568 | 2573 | args.append('--daemon-pipefds=%d,%d' % (rfd, wfd)) |
|
2569 | 2574 | pid = os.spawnvp(os.P_NOWAIT | getattr(os, 'P_DETACH', 0), |
|
2570 | 2575 | args[0], args) |
|
2571 | 2576 | os.close(wfd) |
|
2572 | 2577 | os.read(rfd, 1) |
|
2573 | 2578 | os._exit(0) |
|
2574 | 2579 | |
|
2575 | 2580 | try: |
|
2576 | 2581 | httpd = hgweb.server.create_server(ui, repo) |
|
2577 | 2582 | except socket.error, inst: |
|
2578 | 2583 | raise util.Abort(_('cannot start server: ') + inst.args[1]) |
|
2579 | 2584 | |
|
2580 | 2585 | if ui.verbose: |
|
2581 | 2586 | addr, port = httpd.socket.getsockname() |
|
2582 | 2587 | if addr == '0.0.0.0': |
|
2583 | 2588 | addr = socket.gethostname() |
|
2584 | 2589 | else: |
|
2585 | 2590 | try: |
|
2586 | 2591 | addr = socket.gethostbyaddr(addr)[0] |
|
2587 | 2592 | except socket.error: |
|
2588 | 2593 | pass |
|
2589 | 2594 | if port != 80: |
|
2590 | 2595 | ui.status(_('listening at http://%s:%d/\n') % (addr, port)) |
|
2591 | 2596 | else: |
|
2592 | 2597 | ui.status(_('listening at http://%s/\n') % addr) |
|
2593 | 2598 | |
|
2594 | 2599 | if opts['pid_file']: |
|
2595 | 2600 | fp = open(opts['pid_file'], 'w') |
|
2596 | 2601 | fp.write(str(os.getpid())) |
|
2597 | 2602 | fp.close() |
|
2598 | 2603 | |
|
2599 | 2604 | if opts['daemon_pipefds']: |
|
2600 | 2605 | rfd, wfd = [int(x) for x in opts['daemon_pipefds'].split(',')] |
|
2601 | 2606 | os.close(rfd) |
|
2602 | 2607 | os.write(wfd, 'y') |
|
2603 | 2608 | os.close(wfd) |
|
2604 | 2609 | sys.stdout.flush() |
|
2605 | 2610 | sys.stderr.flush() |
|
2606 | 2611 | fd = os.open(util.nulldev, os.O_RDWR) |
|
2607 | 2612 | if fd != 0: os.dup2(fd, 0) |
|
2608 | 2613 | if fd != 1: os.dup2(fd, 1) |
|
2609 | 2614 | if fd != 2: os.dup2(fd, 2) |
|
2610 | 2615 | if fd not in (0, 1, 2): os.close(fd) |
|
2611 | 2616 | |
|
2612 | 2617 | httpd.serve_forever() |
|
2613 | 2618 | |
|
2614 | 2619 | def status(ui, repo, *pats, **opts): |
|
2615 | 2620 | """show changed files in the working directory |
|
2616 | 2621 | |
|
2617 | 2622 | Show changed files in the repository. If names are |
|
2618 | 2623 | given, only files that match are shown. |
|
2619 | 2624 | |
|
2620 | 2625 | The codes used to show the status of files are: |
|
2621 | 2626 | M = modified |
|
2622 | 2627 | A = added |
|
2623 | 2628 | R = removed |
|
2624 | 2629 | ! = deleted, but still tracked |
|
2625 | 2630 | ? = not tracked |
|
2626 | 2631 | I = ignored (not shown by default) |
|
2627 | 2632 | """ |
|
2628 | 2633 | |
|
2629 | 2634 | show_ignored = opts['ignored'] and True or False |
|
2630 | 2635 | files, matchfn, anypats = matchpats(repo, pats, opts) |
|
2631 | 2636 | cwd = (pats and repo.getcwd()) or '' |
|
2632 | 2637 | modified, added, removed, deleted, unknown, ignored = [ |
|
2633 | 2638 | [util.pathto(cwd, x) for x in n] |
|
2634 | 2639 | for n in repo.changes(files=files, match=matchfn, |
|
2635 | 2640 | show_ignored=show_ignored)] |
|
2636 | 2641 | |
|
2637 | 2642 | changetypes = [('modified', 'M', modified), |
|
2638 | 2643 | ('added', 'A', added), |
|
2639 | 2644 | ('removed', 'R', removed), |
|
2640 | 2645 | ('deleted', '!', deleted), |
|
2641 | 2646 | ('unknown', '?', unknown), |
|
2642 | 2647 | ('ignored', 'I', ignored)] |
|
2643 | 2648 | |
|
2644 | 2649 | end = opts['print0'] and '\0' or '\n' |
|
2645 | 2650 | |
|
2646 | 2651 | for opt, char, changes in ([ct for ct in changetypes if opts[ct[0]]] |
|
2647 | 2652 | or changetypes): |
|
2648 | 2653 | if opts['no_status']: |
|
2649 | 2654 | format = "%%s%s" % end |
|
2650 | 2655 | else: |
|
2651 | 2656 | format = "%s %%s%s" % (char, end) |
|
2652 | 2657 | |
|
2653 | 2658 | for f in changes: |
|
2654 | 2659 | ui.write(format % f) |
|
2655 | 2660 | |
|
2656 | 2661 | def tag(ui, repo, name, rev_=None, **opts): |
|
2657 | 2662 | """add a tag for the current tip or a given revision |
|
2658 | 2663 | |
|
2659 | 2664 | Name a particular revision using <name>. |
|
2660 | 2665 | |
|
2661 | 2666 | Tags are used to name particular revisions of the repository and are |
|
2662 | 2667 | very useful to compare different revision, to go back to significant |
|
2663 | 2668 | earlier versions or to mark branch points as releases, etc. |
|
2664 | 2669 | |
|
2665 | 2670 | If no revision is given, the tip is used. |
|
2666 | 2671 | |
|
2667 | 2672 | To facilitate version control, distribution, and merging of tags, |
|
2668 | 2673 | they are stored as a file named ".hgtags" which is managed |
|
2669 | 2674 | similarly to other project files and can be hand-edited if |
|
2670 | 2675 | necessary. The file '.hg/localtags' is used for local tags (not |
|
2671 | 2676 | shared among repositories). |
|
2672 | 2677 | """ |
|
2673 | 2678 | if name == "tip": |
|
2674 | 2679 | raise util.Abort(_("the name 'tip' is reserved")) |
|
2675 | 2680 | if rev_ is not None: |
|
2676 | 2681 | ui.warn(_("use of 'hg tag NAME [REV]' is deprecated, " |
|
2677 | 2682 | "please use 'hg tag [-r REV] NAME' instead\n")) |
|
2678 | 2683 | if opts['rev']: |
|
2679 | 2684 | raise util.Abort(_("use only one form to specify the revision")) |
|
2680 | 2685 | if opts['rev']: |
|
2681 | 2686 | rev_ = opts['rev'] |
|
2682 | 2687 | if rev_: |
|
2683 | 2688 | r = hex(repo.lookup(rev_)) |
|
2684 | 2689 | else: |
|
2685 | 2690 | r = hex(repo.changelog.tip()) |
|
2686 | 2691 | |
|
2687 | 2692 | disallowed = (revrangesep, '\r', '\n') |
|
2688 | 2693 | for c in disallowed: |
|
2689 | 2694 | if name.find(c) >= 0: |
|
2690 | 2695 | raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) |
|
2691 | 2696 | |
|
2692 | 2697 | repo.hook('pretag', throw=True, node=r, tag=name, |
|
2693 | 2698 | local=int(not not opts['local'])) |
|
2694 | 2699 | |
|
2695 | 2700 | if opts['local']: |
|
2696 | 2701 | repo.opener("localtags", "a").write("%s %s\n" % (r, name)) |
|
2697 | 2702 | repo.hook('tag', node=r, tag=name, local=1) |
|
2698 | 2703 | return |
|
2699 | 2704 | |
|
2700 | 2705 | for x in repo.changes(): |
|
2701 | 2706 | if ".hgtags" in x: |
|
2702 | 2707 | raise util.Abort(_("working copy of .hgtags is changed " |
|
2703 | 2708 | "(please commit .hgtags manually)")) |
|
2704 | 2709 | |
|
2705 | 2710 | repo.wfile(".hgtags", "ab").write("%s %s\n" % (r, name)) |
|
2706 | 2711 | if repo.dirstate.state(".hgtags") == '?': |
|
2707 | 2712 | repo.add([".hgtags"]) |
|
2708 | 2713 | |
|
2709 | 2714 | message = (opts['message'] or |
|
2710 | 2715 | _("Added tag %s for changeset %s") % (name, r)) |
|
2711 | 2716 | try: |
|
2712 | 2717 | repo.commit([".hgtags"], message, opts['user'], opts['date']) |
|
2713 | 2718 | repo.hook('tag', node=r, tag=name, local=0) |
|
2714 | 2719 | except ValueError, inst: |
|
2715 | 2720 | raise util.Abort(str(inst)) |
|
2716 | 2721 | |
|
2717 | 2722 | def tags(ui, repo): |
|
2718 | 2723 | """list repository tags |
|
2719 | 2724 | |
|
2720 | 2725 | List the repository tags. |
|
2721 | 2726 | |
|
2722 | 2727 | This lists both regular and local tags. |
|
2723 | 2728 | """ |
|
2724 | 2729 | |
|
2725 | 2730 | l = repo.tagslist() |
|
2726 | 2731 | l.reverse() |
|
2727 | 2732 | for t, n in l: |
|
2728 | 2733 | try: |
|
2729 | 2734 | r = "%5d:%s" % (repo.changelog.rev(n), hex(n)) |
|
2730 | 2735 | except KeyError: |
|
2731 | 2736 | r = " ?:?" |
|
2732 | 2737 | if ui.quiet: |
|
2733 | 2738 | ui.write("%s\n" % t) |
|
2734 | 2739 | else: |
|
2735 | 2740 | ui.write("%-30s %s\n" % (t, r)) |
|
2736 | 2741 | |
|
2737 | 2742 | def tip(ui, repo, **opts): |
|
2738 | 2743 | """show the tip revision |
|
2739 | 2744 | |
|
2740 | 2745 | Show the tip revision. |
|
2741 | 2746 | """ |
|
2742 | 2747 | n = repo.changelog.tip() |
|
2743 | 2748 | br = None |
|
2744 | 2749 | if opts['branches']: |
|
2745 | 2750 | br = repo.branchlookup([n]) |
|
2746 | 2751 | show_changeset(ui, repo, opts).show(changenode=n, brinfo=br) |
|
2747 | 2752 | if opts['patch']: |
|
2748 | 2753 | dodiff(ui, ui, repo, repo.changelog.parents(n)[0], n) |
|
2749 | 2754 | |
|
2750 | 2755 | def unbundle(ui, repo, fname, **opts): |
|
2751 | 2756 | """apply a changegroup file |
|
2752 | 2757 | |
|
2753 | 2758 | Apply a compressed changegroup file generated by the bundle |
|
2754 | 2759 | command. |
|
2755 | 2760 | """ |
|
2756 | 2761 | f = urllib.urlopen(fname) |
|
2757 | 2762 | |
|
2758 | 2763 | header = f.read(6) |
|
2759 | 2764 | if not header.startswith("HG"): |
|
2760 | 2765 | raise util.Abort(_("%s: not a Mercurial bundle file") % fname) |
|
2761 | 2766 | elif not header.startswith("HG10"): |
|
2762 | 2767 | raise util.Abort(_("%s: unknown bundle version") % fname) |
|
2763 | 2768 | elif header == "HG10BZ": |
|
2764 | 2769 | def generator(f): |
|
2765 | 2770 | zd = bz2.BZ2Decompressor() |
|
2766 | 2771 | zd.decompress("BZ") |
|
2767 | 2772 | for chunk in f: |
|
2768 | 2773 | yield zd.decompress(chunk) |
|
2769 | 2774 | elif header == "HG10UN": |
|
2770 | 2775 | def generator(f): |
|
2771 | 2776 | for chunk in f: |
|
2772 | 2777 | yield chunk |
|
2773 | 2778 | else: |
|
2774 | 2779 | raise util.Abort(_("%s: unknown bundle compression type") |
|
2775 | 2780 | % fname) |
|
2776 | 2781 | gen = generator(util.filechunkiter(f, 4096)) |
|
2777 | 2782 | modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle') |
|
2778 | 2783 | return postincoming(ui, repo, modheads, opts['update']) |
|
2779 | 2784 | |
|
2780 | 2785 | def undo(ui, repo): |
|
2781 | 2786 | """undo the last commit or pull (DEPRECATED) |
|
2782 | 2787 | |
|
2783 | 2788 | (DEPRECATED) |
|
2784 | 2789 | This command is now deprecated and will be removed in a future |
|
2785 | 2790 | release. Please use the rollback command instead. For usage |
|
2786 | 2791 | instructions, see the rollback command. |
|
2787 | 2792 | """ |
|
2788 | 2793 | ui.warn(_('(the undo command is deprecated; use rollback instead)\n')) |
|
2789 | 2794 | repo.rollback() |
|
2790 | 2795 | |
|
2791 | 2796 | def update(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2792 | 2797 | branch=None, **opts): |
|
2793 | 2798 | """update or merge working directory |
|
2794 | 2799 | |
|
2795 | 2800 | Update the working directory to the specified revision. |
|
2796 | 2801 | |
|
2797 | 2802 | If there are no outstanding changes in the working directory and |
|
2798 | 2803 | there is a linear relationship between the current version and the |
|
2799 | 2804 | requested version, the result is the requested version. |
|
2800 | 2805 | |
|
2801 | 2806 | To merge the working directory with another revision, use the |
|
2802 | 2807 | merge command. |
|
2803 | 2808 | |
|
2804 | 2809 | By default, update will refuse to run if doing so would require |
|
2805 | 2810 | merging or discarding local changes. |
|
2806 | 2811 | """ |
|
2807 | 2812 | if merge: |
|
2808 | 2813 | ui.warn(_('(the -m/--merge option is deprecated; ' |
|
2809 | 2814 | 'use the merge command instead)\n')) |
|
2810 | 2815 | return doupdate(ui, repo, node, merge, clean, force, branch, **opts) |
|
2811 | 2816 | |
|
2812 | 2817 | def doupdate(ui, repo, node=None, merge=False, clean=False, force=None, |
|
2813 | 2818 | branch=None, **opts): |
|
2814 | 2819 | if branch: |
|
2815 | 2820 | br = repo.branchlookup(branch=branch) |
|
2816 | 2821 | found = [] |
|
2817 | 2822 | for x in br: |
|
2818 | 2823 | if branch in br[x]: |
|
2819 | 2824 | found.append(x) |
|
2820 | 2825 | if len(found) > 1: |
|
2821 | 2826 | ui.warn(_("Found multiple heads for %s\n") % branch) |
|
2822 | 2827 | for x in found: |
|
2823 | 2828 | show_changeset(ui, repo, opts).show(changenode=x, brinfo=br) |
|
2824 | 2829 | return 1 |
|
2825 | 2830 | if len(found) == 1: |
|
2826 | 2831 | node = found[0] |
|
2827 | 2832 | ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) |
|
2828 | 2833 | else: |
|
2829 | 2834 | ui.warn(_("branch %s not found\n") % (branch)) |
|
2830 | 2835 | return 1 |
|
2831 | 2836 | else: |
|
2832 | 2837 | node = node and repo.lookup(node) or repo.changelog.tip() |
|
2833 | 2838 | return repo.update(node, allow=merge, force=clean, forcemerge=force) |
|
2834 | 2839 | |
|
2835 | 2840 | def verify(ui, repo): |
|
2836 | 2841 | """verify the integrity of the repository |
|
2837 | 2842 | |
|
2838 | 2843 | Verify the integrity of the current repository. |
|
2839 | 2844 | |
|
2840 | 2845 | This will perform an extensive check of the repository's |
|
2841 | 2846 | integrity, validating the hashes and checksums of each entry in |
|
2842 | 2847 | the changelog, manifest, and tracked files, as well as the |
|
2843 | 2848 | integrity of their crosslinks and indices. |
|
2844 | 2849 | """ |
|
2845 | 2850 | return repo.verify() |
|
2846 | 2851 | |
|
2847 | 2852 | # Command options and aliases are listed here, alphabetically |
|
2848 | 2853 | |
|
2849 | 2854 | table = { |
|
2850 | 2855 | "^add": |
|
2851 | 2856 | (add, |
|
2852 | 2857 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2853 | 2858 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2854 | 2859 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
2855 | 2860 | _('hg add [OPTION]... [FILE]...')), |
|
2856 | 2861 | "debugaddremove|addremove": |
|
2857 | 2862 | (addremove, |
|
2858 | 2863 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2859 | 2864 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2860 | 2865 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
2861 | 2866 | _('hg addremove [OPTION]... [FILE]...')), |
|
2862 | 2867 | "^annotate": |
|
2863 | 2868 | (annotate, |
|
2864 | 2869 | [('r', 'rev', '', _('annotate the specified revision')), |
|
2865 | 2870 | ('a', 'text', None, _('treat all files as text')), |
|
2866 | 2871 | ('u', 'user', None, _('list the author')), |
|
2867 | 2872 | ('d', 'date', None, _('list the date')), |
|
2868 | 2873 | ('n', 'number', None, _('list the revision number (default)')), |
|
2869 | 2874 | ('c', 'changeset', None, _('list the changeset')), |
|
2870 | 2875 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2871 | 2876 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2872 | 2877 | _('hg annotate [-r REV] [-a] [-u] [-d] [-n] [-c] FILE...')), |
|
2873 | 2878 | "archive": |
|
2874 | 2879 | (archive, |
|
2875 | 2880 | [('', 'no-decode', None, _('do not pass files through decoders')), |
|
2876 | 2881 | ('p', 'prefix', '', _('directory prefix for files in archive')), |
|
2877 | 2882 | ('r', 'rev', '', _('revision to distribute')), |
|
2878 | 2883 | ('t', 'type', '', _('type of distribution to create')), |
|
2879 | 2884 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2880 | 2885 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2881 | 2886 | _('hg archive [OPTION]... DEST')), |
|
2882 | 2887 | "backout": |
|
2883 | 2888 | (backout, |
|
2884 | 2889 | [('', 'merge', None, |
|
2885 | 2890 | _('merge with old dirstate parent after backout')), |
|
2886 | 2891 | ('m', 'message', '', _('use <text> as commit message')), |
|
2887 | 2892 | ('l', 'logfile', '', _('read commit message from <file>')), |
|
2888 | 2893 | ('d', 'date', '', _('record datecode as commit date')), |
|
2889 | 2894 | ('u', 'user', '', _('record user as committer')), |
|
2890 | 2895 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2891 | 2896 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2892 | 2897 | _('hg backout [OPTION]... REV')), |
|
2893 | 2898 | "bundle": |
|
2894 | 2899 | (bundle, |
|
2895 | 2900 | [('f', 'force', None, |
|
2896 | 2901 | _('run even when remote repository is unrelated'))], |
|
2897 | 2902 | _('hg bundle FILE DEST')), |
|
2898 | 2903 | "cat": |
|
2899 | 2904 | (cat, |
|
2900 | 2905 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2901 | 2906 | ('r', 'rev', '', _('print the given revision')), |
|
2902 | 2907 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2903 | 2908 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2904 | 2909 | _('hg cat [OPTION]... FILE...')), |
|
2905 | 2910 | "^clone": |
|
2906 | 2911 | (clone, |
|
2907 | 2912 | [('U', 'noupdate', None, _('do not update the new working directory')), |
|
2908 | 2913 | ('r', 'rev', [], |
|
2909 | 2914 | _('a changeset you would like to have after cloning')), |
|
2910 | 2915 | ('', 'pull', None, _('use pull protocol to copy metadata')), |
|
2911 | 2916 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
2912 | 2917 | ('', 'remotecmd', '', |
|
2913 | 2918 | _('specify hg command to run on the remote side'))], |
|
2914 | 2919 | _('hg clone [OPTION]... SOURCE [DEST]')), |
|
2915 | 2920 | "^commit|ci": |
|
2916 | 2921 | (commit, |
|
2917 | 2922 | [('A', 'addremove', None, |
|
2918 | 2923 | _('mark new/missing files as added/removed before committing')), |
|
2919 | 2924 | ('m', 'message', '', _('use <text> as commit message')), |
|
2920 | 2925 | ('l', 'logfile', '', _('read the commit message from <file>')), |
|
2921 | 2926 | ('d', 'date', '', _('record datecode as commit date')), |
|
2922 | 2927 | ('u', 'user', '', _('record user as commiter')), |
|
2923 | 2928 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2924 | 2929 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2925 | 2930 | _('hg commit [OPTION]... [FILE]...')), |
|
2926 | 2931 | "copy|cp": |
|
2927 | 2932 | (copy, |
|
2928 | 2933 | [('A', 'after', None, _('record a copy that has already occurred')), |
|
2929 | 2934 | ('f', 'force', None, |
|
2930 | 2935 | _('forcibly copy over an existing managed file')), |
|
2931 | 2936 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2932 | 2937 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
2933 | 2938 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
2934 | 2939 | _('hg copy [OPTION]... [SOURCE]... DEST')), |
|
2935 | 2940 | "debugancestor": (debugancestor, [], _('debugancestor INDEX REV1 REV2')), |
|
2936 | 2941 | "debugcomplete": |
|
2937 | 2942 | (debugcomplete, |
|
2938 | 2943 | [('o', 'options', None, _('show the command options'))], |
|
2939 | 2944 | _('debugcomplete [-o] CMD')), |
|
2940 | 2945 | "debugrebuildstate": |
|
2941 | 2946 | (debugrebuildstate, |
|
2942 | 2947 | [('r', 'rev', '', _('revision to rebuild to'))], |
|
2943 | 2948 | _('debugrebuildstate [-r REV] [REV]')), |
|
2944 | 2949 | "debugcheckstate": (debugcheckstate, [], _('debugcheckstate')), |
|
2945 | 2950 | "debugconfig": (debugconfig, [], _('debugconfig [NAME]...')), |
|
2946 | 2951 | "debugsetparents": (debugsetparents, [], _('debugsetparents REV1 [REV2]')), |
|
2947 | 2952 | "debugstate": (debugstate, [], _('debugstate')), |
|
2948 | 2953 | "debugdata": (debugdata, [], _('debugdata FILE REV')), |
|
2949 | 2954 | "debugindex": (debugindex, [], _('debugindex FILE')), |
|
2950 | 2955 | "debugindexdot": (debugindexdot, [], _('debugindexdot FILE')), |
|
2951 | 2956 | "debugrename": (debugrename, [], _('debugrename FILE [REV]')), |
|
2952 | 2957 | "debugwalk": |
|
2953 | 2958 | (debugwalk, |
|
2954 | 2959 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2955 | 2960 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2956 | 2961 | _('debugwalk [OPTION]... [FILE]...')), |
|
2957 | 2962 | "^diff": |
|
2958 | 2963 | (diff, |
|
2959 | 2964 | [('r', 'rev', [], _('revision')), |
|
2960 | 2965 | ('a', 'text', None, _('treat all files as text')), |
|
2961 | 2966 | ('p', 'show-function', None, |
|
2962 | 2967 | _('show which function each change is in')), |
|
2963 | 2968 | ('w', 'ignore-all-space', None, |
|
2964 | 2969 | _('ignore white space when comparing lines')), |
|
2965 | 2970 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2966 | 2971 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2967 | 2972 | _('hg diff [-a] [-I] [-X] [-r REV1 [-r REV2]] [FILE]...')), |
|
2968 | 2973 | "^export": |
|
2969 | 2974 | (export, |
|
2970 | 2975 | [('o', 'output', '', _('print output to file with formatted name')), |
|
2971 | 2976 | ('a', 'text', None, _('treat all files as text')), |
|
2972 | 2977 | ('', 'switch-parent', None, _('diff against the second parent'))], |
|
2973 | 2978 | _('hg export [-a] [-o OUTFILESPEC] REV...')), |
|
2974 | 2979 | "debugforget|forget": |
|
2975 | 2980 | (forget, |
|
2976 | 2981 | [('I', 'include', [], _('include names matching the given patterns')), |
|
2977 | 2982 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2978 | 2983 | _('hg forget [OPTION]... FILE...')), |
|
2979 | 2984 | "grep": |
|
2980 | 2985 | (grep, |
|
2981 | 2986 | [('0', 'print0', None, _('end fields with NUL')), |
|
2982 | 2987 | ('', 'all', None, _('print all revisions that match')), |
|
2983 | 2988 | ('i', 'ignore-case', None, _('ignore case when matching')), |
|
2984 | 2989 | ('l', 'files-with-matches', None, |
|
2985 | 2990 | _('print only filenames and revs that match')), |
|
2986 | 2991 | ('n', 'line-number', None, _('print matching line numbers')), |
|
2987 | 2992 | ('r', 'rev', [], _('search in given revision range')), |
|
2988 | 2993 | ('u', 'user', None, _('print user who committed change')), |
|
2989 | 2994 | ('I', 'include', [], _('include names matching the given patterns')), |
|
2990 | 2995 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
2991 | 2996 | _('hg grep [OPTION]... PATTERN [FILE]...')), |
|
2992 | 2997 | "heads": |
|
2993 | 2998 | (heads, |
|
2994 | 2999 | [('b', 'branches', None, _('show branches')), |
|
2995 | 3000 | ('', 'style', '', _('display using template map file')), |
|
2996 | 3001 | ('r', 'rev', '', _('show only heads which are descendants of rev')), |
|
2997 | 3002 | ('', 'template', '', _('display with template'))], |
|
2998 | 3003 | _('hg heads [-b] [-r <rev>]')), |
|
2999 | 3004 | "help": (help_, [], _('hg help [COMMAND]')), |
|
3000 | 3005 | "identify|id": (identify, [], _('hg identify')), |
|
3001 | 3006 | "import|patch": |
|
3002 | 3007 | (import_, |
|
3003 | 3008 | [('p', 'strip', 1, |
|
3004 | 3009 | _('directory strip option for patch. This has the same\n' |
|
3005 | 3010 | 'meaning as the corresponding patch option')), |
|
3006 | 3011 | ('m', 'message', '', _('use <text> as commit message')), |
|
3007 | 3012 | ('b', 'base', '', _('base path')), |
|
3008 | 3013 | ('f', 'force', None, |
|
3009 | 3014 | _('skip check for outstanding uncommitted changes'))], |
|
3010 | 3015 | _('hg import [-p NUM] [-b BASE] [-m MESSAGE] [-f] PATCH...')), |
|
3011 | 3016 | "incoming|in": (incoming, |
|
3012 | 3017 | [('M', 'no-merges', None, _('do not show merges')), |
|
3013 | 3018 | ('f', 'force', None, |
|
3014 | 3019 | _('run even when remote repository is unrelated')), |
|
3015 | 3020 | ('', 'style', '', _('display using template map file')), |
|
3016 | 3021 | ('n', 'newest-first', None, _('show newest record first')), |
|
3017 | 3022 | ('', 'bundle', '', _('file to store the bundles into')), |
|
3018 | 3023 | ('p', 'patch', None, _('show patch')), |
|
3019 | 3024 | ('', 'template', '', _('display with template')), |
|
3020 | 3025 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3021 | 3026 | ('', 'remotecmd', '', |
|
3022 | 3027 | _('specify hg command to run on the remote side'))], |
|
3023 | 3028 | _('hg incoming [-p] [-n] [-M] [--bundle FILENAME] [SOURCE]')), |
|
3024 | 3029 | "^init": (init, [], _('hg init [DEST]')), |
|
3025 | 3030 | "locate": |
|
3026 | 3031 | (locate, |
|
3027 | 3032 | [('r', 'rev', '', _('search the repository as it stood at rev')), |
|
3028 | 3033 | ('0', 'print0', None, |
|
3029 | 3034 | _('end filenames with NUL, for use with xargs')), |
|
3030 | 3035 | ('f', 'fullpath', None, |
|
3031 | 3036 | _('print complete paths from the filesystem root')), |
|
3032 | 3037 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3033 | 3038 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3034 | 3039 | _('hg locate [OPTION]... [PATTERN]...')), |
|
3035 | 3040 | "^log|history": |
|
3036 | 3041 | (log, |
|
3037 | 3042 | [('b', 'branches', None, _('show branches')), |
|
3038 | 3043 | ('k', 'keyword', [], _('search for a keyword')), |
|
3039 | 3044 | ('l', 'limit', '', _('limit number of changes displayed')), |
|
3040 | 3045 | ('r', 'rev', [], _('show the specified revision or range')), |
|
3041 | 3046 | ('M', 'no-merges', None, _('do not show merges')), |
|
3042 | 3047 | ('', 'style', '', _('display using template map file')), |
|
3043 | 3048 | ('m', 'only-merges', None, _('show only merges')), |
|
3044 | 3049 | ('p', 'patch', None, _('show patch')), |
|
3045 | 3050 | ('', 'template', '', _('display with template')), |
|
3046 | 3051 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3047 | 3052 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3048 | 3053 | _('hg log [OPTION]... [FILE]')), |
|
3049 | 3054 | "manifest": (manifest, [], _('hg manifest [REV]')), |
|
3050 | 3055 | "merge": |
|
3051 | 3056 | (merge, |
|
3052 | 3057 | [('b', 'branch', '', _('merge with head of a specific branch')), |
|
3053 | 3058 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
3054 | 3059 | _('hg merge [-b TAG] [-f] [REV]')), |
|
3055 | 3060 | "outgoing|out": (outgoing, |
|
3056 | 3061 | [('M', 'no-merges', None, _('do not show merges')), |
|
3057 | 3062 | ('f', 'force', None, |
|
3058 | 3063 | _('run even when remote repository is unrelated')), |
|
3059 | 3064 | ('p', 'patch', None, _('show patch')), |
|
3060 | 3065 | ('', 'style', '', _('display using template map file')), |
|
3061 | 3066 | ('n', 'newest-first', None, _('show newest record first')), |
|
3062 | 3067 | ('', 'template', '', _('display with template')), |
|
3063 | 3068 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3064 | 3069 | ('', 'remotecmd', '', |
|
3065 | 3070 | _('specify hg command to run on the remote side'))], |
|
3066 | 3071 | _('hg outgoing [-M] [-p] [-n] [DEST]')), |
|
3067 | 3072 | "^parents": |
|
3068 | 3073 | (parents, |
|
3069 | 3074 | [('b', 'branches', None, _('show branches')), |
|
3070 | 3075 | ('', 'style', '', _('display using template map file')), |
|
3071 | 3076 | ('', 'template', '', _('display with template'))], |
|
3072 | 3077 | _('hg parents [-b] [REV]')), |
|
3073 | 3078 | "paths": (paths, [], _('hg paths [NAME]')), |
|
3074 | 3079 | "^pull": |
|
3075 | 3080 | (pull, |
|
3076 | 3081 | [('u', 'update', None, |
|
3077 | 3082 | _('update the working directory to tip after pull')), |
|
3078 | 3083 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3079 | 3084 | ('f', 'force', None, |
|
3080 | 3085 | _('run even when remote repository is unrelated')), |
|
3081 | 3086 | ('r', 'rev', [], _('a specific revision you would like to pull')), |
|
3082 | 3087 | ('', 'remotecmd', '', |
|
3083 | 3088 | _('specify hg command to run on the remote side'))], |
|
3084 | 3089 | _('hg pull [-u] [-e FILE] [-r REV]... [--remotecmd FILE] [SOURCE]')), |
|
3085 | 3090 | "^push": |
|
3086 | 3091 | (push, |
|
3087 | 3092 | [('f', 'force', None, _('force push')), |
|
3088 | 3093 | ('e', 'ssh', '', _('specify ssh command to use')), |
|
3089 | 3094 | ('r', 'rev', [], _('a specific revision you would like to push')), |
|
3090 | 3095 | ('', 'remotecmd', '', |
|
3091 | 3096 | _('specify hg command to run on the remote side'))], |
|
3092 | 3097 | _('hg push [-f] [-e FILE] [-r REV]... [--remotecmd FILE] [DEST]')), |
|
3093 | 3098 | "debugrawcommit|rawcommit": |
|
3094 | 3099 | (rawcommit, |
|
3095 | 3100 | [('p', 'parent', [], _('parent')), |
|
3096 | 3101 | ('d', 'date', '', _('date code')), |
|
3097 | 3102 | ('u', 'user', '', _('user')), |
|
3098 | 3103 | ('F', 'files', '', _('file list')), |
|
3099 | 3104 | ('m', 'message', '', _('commit message')), |
|
3100 | 3105 | ('l', 'logfile', '', _('commit message file'))], |
|
3101 | 3106 | _('hg debugrawcommit [OPTION]... [FILE]...')), |
|
3102 | 3107 | "recover": (recover, [], _('hg recover')), |
|
3103 | 3108 | "^remove|rm": |
|
3104 | 3109 | (remove, |
|
3105 | 3110 | [('A', 'after', None, _('record remove that has already occurred')), |
|
3106 | 3111 | ('f', 'force', None, _('remove file even if modified')), |
|
3107 | 3112 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3108 | 3113 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3109 | 3114 | _('hg remove [OPTION]... FILE...')), |
|
3110 | 3115 | "rename|mv": |
|
3111 | 3116 | (rename, |
|
3112 | 3117 | [('A', 'after', None, _('record a rename that has already occurred')), |
|
3113 | 3118 | ('f', 'force', None, |
|
3114 | 3119 | _('forcibly copy over an existing managed file')), |
|
3115 | 3120 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3116 | 3121 | ('X', 'exclude', [], _('exclude names matching the given patterns')), |
|
3117 | 3122 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
3118 | 3123 | _('hg rename [OPTION]... SOURCE... DEST')), |
|
3119 | 3124 | "^revert": |
|
3120 | 3125 | (revert, |
|
3121 | 3126 | [('r', 'rev', '', _('revision to revert to')), |
|
3122 | 3127 | ('', 'no-backup', None, _('do not save backup copies of files')), |
|
3123 | 3128 | ('I', 'include', [], _('include names matching given patterns')), |
|
3124 | 3129 | ('X', 'exclude', [], _('exclude names matching given patterns')), |
|
3125 | 3130 | ('n', 'dry-run', None, _('do not perform actions, just print output'))], |
|
3126 | 3131 | _('hg revert [-r REV] [NAME]...')), |
|
3127 | 3132 | "rollback": (rollback, [], _('hg rollback')), |
|
3128 | 3133 | "root": (root, [], _('hg root')), |
|
3129 | 3134 | "^serve": |
|
3130 | 3135 | (serve, |
|
3131 | 3136 | [('A', 'accesslog', '', _('name of access log file to write to')), |
|
3132 | 3137 | ('d', 'daemon', None, _('run server in background')), |
|
3133 | 3138 | ('', 'daemon-pipefds', '', _('used internally by daemon mode')), |
|
3134 | 3139 | ('E', 'errorlog', '', _('name of error log file to write to')), |
|
3135 | 3140 | ('p', 'port', 0, _('port to use (default: 8000)')), |
|
3136 | 3141 | ('a', 'address', '', _('address to use')), |
|
3137 | 3142 | ('n', 'name', '', |
|
3138 | 3143 | _('name to show in web pages (default: working dir)')), |
|
3139 | 3144 | ('', 'webdir-conf', '', _('name of the webdir config file' |
|
3140 | 3145 | ' (serve more than one repo)')), |
|
3141 | 3146 | ('', 'pid-file', '', _('name of file to write process ID to')), |
|
3142 | 3147 | ('', 'stdio', None, _('for remote clients')), |
|
3143 | 3148 | ('t', 'templates', '', _('web templates to use')), |
|
3144 | 3149 | ('', 'style', '', _('template style to use')), |
|
3145 | 3150 | ('6', 'ipv6', None, _('use IPv6 in addition to IPv4'))], |
|
3146 | 3151 | _('hg serve [OPTION]...')), |
|
3147 | 3152 | "^status|st": |
|
3148 | 3153 | (status, |
|
3149 | 3154 | [('m', 'modified', None, _('show only modified files')), |
|
3150 | 3155 | ('a', 'added', None, _('show only added files')), |
|
3151 | 3156 | ('r', 'removed', None, _('show only removed files')), |
|
3152 | 3157 | ('d', 'deleted', None, _('show only deleted (but tracked) files')), |
|
3153 | 3158 | ('u', 'unknown', None, _('show only unknown (not tracked) files')), |
|
3154 | 3159 | ('i', 'ignored', None, _('show ignored files')), |
|
3155 | 3160 | ('n', 'no-status', None, _('hide status prefix')), |
|
3156 | 3161 | ('0', 'print0', None, |
|
3157 | 3162 | _('end filenames with NUL, for use with xargs')), |
|
3158 | 3163 | ('I', 'include', [], _('include names matching the given patterns')), |
|
3159 | 3164 | ('X', 'exclude', [], _('exclude names matching the given patterns'))], |
|
3160 | 3165 | _('hg status [OPTION]... [FILE]...')), |
|
3161 | 3166 | "tag": |
|
3162 | 3167 | (tag, |
|
3163 | 3168 | [('l', 'local', None, _('make the tag local')), |
|
3164 | 3169 | ('m', 'message', '', _('message for tag commit log entry')), |
|
3165 | 3170 | ('d', 'date', '', _('record datecode as commit date')), |
|
3166 | 3171 | ('u', 'user', '', _('record user as commiter')), |
|
3167 | 3172 | ('r', 'rev', '', _('revision to tag'))], |
|
3168 | 3173 | _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), |
|
3169 | 3174 | "tags": (tags, [], _('hg tags')), |
|
3170 | 3175 | "tip": |
|
3171 | 3176 | (tip, |
|
3172 | 3177 | [('b', 'branches', None, _('show branches')), |
|
3173 | 3178 | ('', 'style', '', _('display using template map file')), |
|
3174 | 3179 | ('p', 'patch', None, _('show patch')), |
|
3175 | 3180 | ('', 'template', '', _('display with template'))], |
|
3176 | 3181 | _('hg tip [-b] [-p]')), |
|
3177 | 3182 | "unbundle": |
|
3178 | 3183 | (unbundle, |
|
3179 | 3184 | [('u', 'update', None, |
|
3180 | 3185 | _('update the working directory to tip after unbundle'))], |
|
3181 | 3186 | _('hg unbundle [-u] FILE')), |
|
3182 | 3187 | "debugundo|undo": (undo, [], _('hg undo')), |
|
3183 | 3188 | "^update|up|checkout|co": |
|
3184 | 3189 | (update, |
|
3185 | 3190 | [('b', 'branch', '', _('checkout the head of a specific branch')), |
|
3186 | 3191 | ('m', 'merge', None, _('allow merging of branches (DEPRECATED)')), |
|
3187 | 3192 | ('C', 'clean', None, _('overwrite locally modified files')), |
|
3188 | 3193 | ('f', 'force', None, _('force a merge with outstanding changes'))], |
|
3189 | 3194 | _('hg update [-b TAG] [-m] [-C] [-f] [REV]')), |
|
3190 | 3195 | "verify": (verify, [], _('hg verify')), |
|
3191 | 3196 | "version": (show_version, [], _('hg version')), |
|
3192 | 3197 | } |
|
3193 | 3198 | |
|
3194 | 3199 | globalopts = [ |
|
3195 | 3200 | ('R', 'repository', '', |
|
3196 | 3201 | _('repository root directory or symbolic path name')), |
|
3197 | 3202 | ('', 'cwd', '', _('change working directory')), |
|
3198 | 3203 | ('y', 'noninteractive', None, |
|
3199 | 3204 | _('do not prompt, assume \'yes\' for any required answers')), |
|
3200 | 3205 | ('q', 'quiet', None, _('suppress output')), |
|
3201 | 3206 | ('v', 'verbose', None, _('enable additional output')), |
|
3202 | 3207 | ('', 'config', [], _('set/override config option')), |
|
3203 | 3208 | ('', 'debug', None, _('enable debugging output')), |
|
3204 | 3209 | ('', 'debugger', None, _('start debugger')), |
|
3205 | 3210 | ('', 'lsprof', None, _('print improved command execution profile')), |
|
3206 | 3211 | ('', 'traceback', None, _('print traceback on exception')), |
|
3207 | 3212 | ('', 'time', None, _('time how long the command takes')), |
|
3208 | 3213 | ('', 'profile', None, _('print command execution profile')), |
|
3209 | 3214 | ('', 'version', None, _('output version information and exit')), |
|
3210 | 3215 | ('h', 'help', None, _('display help and exit')), |
|
3211 | 3216 | ] |
|
3212 | 3217 | |
|
3213 | 3218 | norepo = ("clone init version help debugancestor debugcomplete debugdata" |
|
3214 | 3219 | " debugindex debugindexdot") |
|
3215 | 3220 | optionalrepo = ("paths serve debugconfig") |
|
3216 | 3221 | |
|
3217 | 3222 | def findpossible(cmd): |
|
3218 | 3223 | """ |
|
3219 | 3224 | Return cmd -> (aliases, command table entry) |
|
3220 | 3225 | for each matching command. |
|
3221 | 3226 | Return debug commands (or their aliases) only if no normal command matches. |
|
3222 | 3227 | """ |
|
3223 | 3228 | choice = {} |
|
3224 | 3229 | debugchoice = {} |
|
3225 | 3230 | for e in table.keys(): |
|
3226 | 3231 | aliases = e.lstrip("^").split("|") |
|
3227 | 3232 | found = None |
|
3228 | 3233 | if cmd in aliases: |
|
3229 | 3234 | found = cmd |
|
3230 | 3235 | else: |
|
3231 | 3236 | for a in aliases: |
|
3232 | 3237 | if a.startswith(cmd): |
|
3233 | 3238 | found = a |
|
3234 | 3239 | break |
|
3235 | 3240 | if found is not None: |
|
3236 | 3241 | if aliases[0].startswith("debug"): |
|
3237 | 3242 | debugchoice[found] = (aliases, table[e]) |
|
3238 | 3243 | else: |
|
3239 | 3244 | choice[found] = (aliases, table[e]) |
|
3240 | 3245 | |
|
3241 | 3246 | if not choice and debugchoice: |
|
3242 | 3247 | choice = debugchoice |
|
3243 | 3248 | |
|
3244 | 3249 | return choice |
|
3245 | 3250 | |
|
3246 | 3251 | def find(cmd): |
|
3247 | 3252 | """Return (aliases, command table entry) for command string.""" |
|
3248 | 3253 | choice = findpossible(cmd) |
|
3249 | 3254 | |
|
3250 | 3255 | if choice.has_key(cmd): |
|
3251 | 3256 | return choice[cmd] |
|
3252 | 3257 | |
|
3253 | 3258 | if len(choice) > 1: |
|
3254 | 3259 | clist = choice.keys() |
|
3255 | 3260 | clist.sort() |
|
3256 | 3261 | raise AmbiguousCommand(cmd, clist) |
|
3257 | 3262 | |
|
3258 | 3263 | if choice: |
|
3259 | 3264 | return choice.values()[0] |
|
3260 | 3265 | |
|
3261 | 3266 | raise UnknownCommand(cmd) |
|
3262 | 3267 | |
|
3263 | 3268 | def catchterm(*args): |
|
3264 | 3269 | raise util.SignalInterrupt |
|
3265 | 3270 | |
|
3266 | 3271 | def run(): |
|
3267 | 3272 | sys.exit(dispatch(sys.argv[1:])) |
|
3268 | 3273 | |
|
3269 | 3274 | class ParseError(Exception): |
|
3270 | 3275 | """Exception raised on errors in parsing the command line.""" |
|
3271 | 3276 | |
|
3272 | 3277 | def parse(ui, args): |
|
3273 | 3278 | options = {} |
|
3274 | 3279 | cmdoptions = {} |
|
3275 | 3280 | |
|
3276 | 3281 | try: |
|
3277 | 3282 | args = fancyopts.fancyopts(args, globalopts, options) |
|
3278 | 3283 | except fancyopts.getopt.GetoptError, inst: |
|
3279 | 3284 | raise ParseError(None, inst) |
|
3280 | 3285 | |
|
3281 | 3286 | if args: |
|
3282 | 3287 | cmd, args = args[0], args[1:] |
|
3283 | 3288 | aliases, i = find(cmd) |
|
3284 | 3289 | cmd = aliases[0] |
|
3285 | 3290 | defaults = ui.config("defaults", cmd) |
|
3286 | 3291 | if defaults: |
|
3287 | 3292 | args = defaults.split() + args |
|
3288 | 3293 | c = list(i[1]) |
|
3289 | 3294 | else: |
|
3290 | 3295 | cmd = None |
|
3291 | 3296 | c = [] |
|
3292 | 3297 | |
|
3293 | 3298 | # combine global options into local |
|
3294 | 3299 | for o in globalopts: |
|
3295 | 3300 | c.append((o[0], o[1], options[o[1]], o[3])) |
|
3296 | 3301 | |
|
3297 | 3302 | try: |
|
3298 | 3303 | args = fancyopts.fancyopts(args, c, cmdoptions) |
|
3299 | 3304 | except fancyopts.getopt.GetoptError, inst: |
|
3300 | 3305 | raise ParseError(cmd, inst) |
|
3301 | 3306 | |
|
3302 | 3307 | # separate global options back out |
|
3303 | 3308 | for o in globalopts: |
|
3304 | 3309 | n = o[1] |
|
3305 | 3310 | options[n] = cmdoptions[n] |
|
3306 | 3311 | del cmdoptions[n] |
|
3307 | 3312 | |
|
3308 | 3313 | return (cmd, cmd and i[0] or None, args, options, cmdoptions) |
|
3309 | 3314 | |
|
3310 | 3315 | def dispatch(args): |
|
3311 | 3316 | for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
|
3312 | 3317 | num = getattr(signal, name, None) |
|
3313 | 3318 | if num: signal.signal(num, catchterm) |
|
3314 | 3319 | |
|
3315 | 3320 | try: |
|
3316 | 3321 | u = ui.ui(traceback='--traceback' in sys.argv[1:]) |
|
3317 | 3322 | except util.Abort, inst: |
|
3318 | 3323 | sys.stderr.write(_("abort: %s\n") % inst) |
|
3319 | 3324 | return -1 |
|
3320 | 3325 | |
|
3321 | 3326 | external = [] |
|
3322 | 3327 | for x in u.extensions(): |
|
3323 | 3328 | try: |
|
3324 | 3329 | if x[1]: |
|
3325 | 3330 | # the module will be loaded in sys.modules |
|
3326 | 3331 | # choose an unique name so that it doesn't |
|
3327 | 3332 | # conflicts with other modules |
|
3328 | 3333 | module_name = "hgext_%s" % x[0].replace('.', '_') |
|
3329 | 3334 | mod = imp.load_source(module_name, x[1]) |
|
3330 | 3335 | else: |
|
3331 | 3336 | def importh(name): |
|
3332 | 3337 | mod = __import__(name) |
|
3333 | 3338 | components = name.split('.') |
|
3334 | 3339 | for comp in components[1:]: |
|
3335 | 3340 | mod = getattr(mod, comp) |
|
3336 | 3341 | return mod |
|
3337 | 3342 | try: |
|
3338 | 3343 | mod = importh("hgext." + x[0]) |
|
3339 | 3344 | except ImportError: |
|
3340 | 3345 | mod = importh(x[0]) |
|
3341 | 3346 | external.append(mod) |
|
3342 | 3347 | except (util.SignalInterrupt, KeyboardInterrupt): |
|
3343 | 3348 | raise |
|
3344 | 3349 | except Exception, inst: |
|
3345 | 3350 | u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst)) |
|
3346 | 3351 | if u.print_exc(): |
|
3347 | 3352 | return 1 |
|
3348 | 3353 | |
|
3349 | 3354 | for x in external: |
|
3350 | 3355 | uisetup = getattr(x, 'uisetup', None) |
|
3351 | 3356 | if uisetup: |
|
3352 | 3357 | uisetup(u) |
|
3353 | 3358 | cmdtable = getattr(x, 'cmdtable', {}) |
|
3354 | 3359 | for t in cmdtable: |
|
3355 | 3360 | if t in table: |
|
3356 | 3361 | u.warn(_("module %s overrides %s\n") % (x.__name__, t)) |
|
3357 | 3362 | table.update(cmdtable) |
|
3358 | 3363 | |
|
3359 | 3364 | try: |
|
3360 | 3365 | cmd, func, args, options, cmdoptions = parse(u, args) |
|
3361 | 3366 | if options["time"]: |
|
3362 | 3367 | def get_times(): |
|
3363 | 3368 | t = os.times() |
|
3364 | 3369 | if t[4] == 0.0: # Windows leaves this as zero, so use time.clock() |
|
3365 | 3370 | t = (t[0], t[1], t[2], t[3], time.clock()) |
|
3366 | 3371 | return t |
|
3367 | 3372 | s = get_times() |
|
3368 | 3373 | def print_time(): |
|
3369 | 3374 | t = get_times() |
|
3370 | 3375 | u.warn(_("Time: real %.3f secs (user %.3f+%.3f sys %.3f+%.3f)\n") % |
|
3371 | 3376 | (t[4]-s[4], t[0]-s[0], t[2]-s[2], t[1]-s[1], t[3]-s[3])) |
|
3372 | 3377 | atexit.register(print_time) |
|
3373 | 3378 | |
|
3374 | 3379 | u.updateopts(options["verbose"], options["debug"], options["quiet"], |
|
3375 | 3380 | not options["noninteractive"], options["traceback"], |
|
3376 | 3381 | options["config"]) |
|
3377 | 3382 | |
|
3378 | 3383 | # enter the debugger before command execution |
|
3379 | 3384 | if options['debugger']: |
|
3380 | 3385 | pdb.set_trace() |
|
3381 | 3386 | |
|
3382 | 3387 | try: |
|
3383 | 3388 | if options['cwd']: |
|
3384 | 3389 | try: |
|
3385 | 3390 | os.chdir(options['cwd']) |
|
3386 | 3391 | except OSError, inst: |
|
3387 | 3392 | raise util.Abort('%s: %s' % |
|
3388 | 3393 | (options['cwd'], inst.strerror)) |
|
3389 | 3394 | |
|
3390 | 3395 | path = u.expandpath(options["repository"]) or "" |
|
3391 | 3396 | repo = path and hg.repository(u, path=path) or None |
|
3392 | 3397 | |
|
3393 | 3398 | if options['help']: |
|
3394 | 3399 | return help_(u, cmd, options['version']) |
|
3395 | 3400 | elif options['version']: |
|
3396 | 3401 | return show_version(u) |
|
3397 | 3402 | elif not cmd: |
|
3398 | 3403 | return help_(u, 'shortlist') |
|
3399 | 3404 | |
|
3400 | 3405 | if cmd not in norepo.split(): |
|
3401 | 3406 | try: |
|
3402 | 3407 | if not repo: |
|
3403 | 3408 | repo = hg.repository(u, path=path) |
|
3404 | 3409 | u = repo.ui |
|
3405 | 3410 | for x in external: |
|
3406 | 3411 | if hasattr(x, 'reposetup'): |
|
3407 | 3412 | x.reposetup(u, repo) |
|
3408 | 3413 | except hg.RepoError: |
|
3409 | 3414 | if cmd not in optionalrepo.split(): |
|
3410 | 3415 | raise |
|
3411 | 3416 | d = lambda: func(u, repo, *args, **cmdoptions) |
|
3412 | 3417 | else: |
|
3413 | 3418 | d = lambda: func(u, *args, **cmdoptions) |
|
3414 | 3419 | |
|
3415 | 3420 | try: |
|
3416 | 3421 | if options['profile']: |
|
3417 | 3422 | import hotshot, hotshot.stats |
|
3418 | 3423 | prof = hotshot.Profile("hg.prof") |
|
3419 | 3424 | try: |
|
3420 | 3425 | try: |
|
3421 | 3426 | return prof.runcall(d) |
|
3422 | 3427 | except: |
|
3423 | 3428 | try: |
|
3424 | 3429 | u.warn(_('exception raised - generating ' |
|
3425 | 3430 | 'profile anyway\n')) |
|
3426 | 3431 | except: |
|
3427 | 3432 | pass |
|
3428 | 3433 | raise |
|
3429 | 3434 | finally: |
|
3430 | 3435 | prof.close() |
|
3431 | 3436 | stats = hotshot.stats.load("hg.prof") |
|
3432 | 3437 | stats.strip_dirs() |
|
3433 | 3438 | stats.sort_stats('time', 'calls') |
|
3434 | 3439 | stats.print_stats(40) |
|
3435 | 3440 | elif options['lsprof']: |
|
3436 | 3441 | try: |
|
3437 | 3442 | from mercurial import lsprof |
|
3438 | 3443 | except ImportError: |
|
3439 | 3444 | raise util.Abort(_( |
|
3440 | 3445 | 'lsprof not available - install from ' |
|
3441 | 3446 | 'http://codespeak.net/svn/user/arigo/hack/misc/lsprof/')) |
|
3442 | 3447 | p = lsprof.Profiler() |
|
3443 | 3448 | p.enable(subcalls=True) |
|
3444 | 3449 | try: |
|
3445 | 3450 | return d() |
|
3446 | 3451 | finally: |
|
3447 | 3452 | p.disable() |
|
3448 | 3453 | stats = lsprof.Stats(p.getstats()) |
|
3449 | 3454 | stats.sort() |
|
3450 | 3455 | stats.pprint(top=10, file=sys.stderr, climit=5) |
|
3451 | 3456 | else: |
|
3452 | 3457 | return d() |
|
3453 | 3458 | finally: |
|
3454 | 3459 | u.flush() |
|
3455 | 3460 | except: |
|
3456 | 3461 | # enter the debugger when we hit an exception |
|
3457 | 3462 | if options['debugger']: |
|
3458 | 3463 | pdb.post_mortem(sys.exc_info()[2]) |
|
3459 | 3464 | u.print_exc() |
|
3460 | 3465 | raise |
|
3461 | 3466 | except ParseError, inst: |
|
3462 | 3467 | if inst.args[0]: |
|
3463 | 3468 | u.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1])) |
|
3464 | 3469 | help_(u, inst.args[0]) |
|
3465 | 3470 | else: |
|
3466 | 3471 | u.warn(_("hg: %s\n") % inst.args[1]) |
|
3467 | 3472 | help_(u, 'shortlist') |
|
3468 | 3473 | except AmbiguousCommand, inst: |
|
3469 | 3474 | u.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
|
3470 | 3475 | (inst.args[0], " ".join(inst.args[1]))) |
|
3471 | 3476 | except UnknownCommand, inst: |
|
3472 | 3477 | u.warn(_("hg: unknown command '%s'\n") % inst.args[0]) |
|
3473 | 3478 | help_(u, 'shortlist') |
|
3474 | 3479 | except hg.RepoError, inst: |
|
3475 | 3480 | u.warn(_("abort: %s!\n") % inst) |
|
3476 | 3481 | except lock.LockHeld, inst: |
|
3477 | 3482 | if inst.errno == errno.ETIMEDOUT: |
|
3478 | 3483 | reason = _('timed out waiting for lock held by %s') % inst.locker |
|
3479 | 3484 | else: |
|
3480 | 3485 | reason = _('lock held by %s') % inst.locker |
|
3481 | 3486 | u.warn(_("abort: %s: %s\n") % (inst.desc or inst.filename, reason)) |
|
3482 | 3487 | except lock.LockUnavailable, inst: |
|
3483 | 3488 | u.warn(_("abort: could not lock %s: %s\n") % |
|
3484 | 3489 | (inst.desc or inst.filename, inst.strerror)) |
|
3485 | 3490 | except revlog.RevlogError, inst: |
|
3486 | 3491 | u.warn(_("abort: "), inst, "!\n") |
|
3487 | 3492 | except util.SignalInterrupt: |
|
3488 | 3493 | u.warn(_("killed!\n")) |
|
3489 | 3494 | except KeyboardInterrupt: |
|
3490 | 3495 | try: |
|
3491 | 3496 | u.warn(_("interrupted!\n")) |
|
3492 | 3497 | except IOError, inst: |
|
3493 | 3498 | if inst.errno == errno.EPIPE: |
|
3494 | 3499 | if u.debugflag: |
|
3495 | 3500 | u.warn(_("\nbroken pipe\n")) |
|
3496 | 3501 | else: |
|
3497 | 3502 | raise |
|
3498 | 3503 | except IOError, inst: |
|
3499 | 3504 | if hasattr(inst, "code"): |
|
3500 | 3505 | u.warn(_("abort: %s\n") % inst) |
|
3501 | 3506 | elif hasattr(inst, "reason"): |
|
3502 | 3507 | u.warn(_("abort: error: %s\n") % inst.reason[1]) |
|
3503 | 3508 | elif hasattr(inst, "args") and inst[0] == errno.EPIPE: |
|
3504 | 3509 | if u.debugflag: |
|
3505 | 3510 | u.warn(_("broken pipe\n")) |
|
3506 | 3511 | elif getattr(inst, "strerror", None): |
|
3507 | 3512 | if getattr(inst, "filename", None): |
|
3508 | 3513 | u.warn(_("abort: %s - %s\n") % (inst.strerror, inst.filename)) |
|
3509 | 3514 | else: |
|
3510 | 3515 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3511 | 3516 | else: |
|
3512 | 3517 | raise |
|
3513 | 3518 | except OSError, inst: |
|
3514 | 3519 | if hasattr(inst, "filename"): |
|
3515 | 3520 | u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename)) |
|
3516 | 3521 | else: |
|
3517 | 3522 | u.warn(_("abort: %s\n") % inst.strerror) |
|
3518 | 3523 | except util.Abort, inst: |
|
3519 | 3524 | u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n') |
|
3520 | 3525 | except TypeError, inst: |
|
3521 | 3526 | # was this an argument error? |
|
3522 | 3527 | tb = traceback.extract_tb(sys.exc_info()[2]) |
|
3523 | 3528 | if len(tb) > 2: # no |
|
3524 | 3529 | raise |
|
3525 | 3530 | u.debug(inst, "\n") |
|
3526 | 3531 | u.warn(_("%s: invalid arguments\n") % cmd) |
|
3527 | 3532 | help_(u, cmd) |
|
3528 | 3533 | except SystemExit, inst: |
|
3529 | 3534 | # Commands shouldn't sys.exit directly, but give a return code. |
|
3530 | 3535 | # Just in case catch this and and pass exit code to caller. |
|
3531 | 3536 | return inst.code |
|
3532 | 3537 | except: |
|
3533 | 3538 | u.warn(_("** unknown exception encountered, details follow\n")) |
|
3534 | 3539 | u.warn(_("** report bug details to mercurial@selenic.com\n")) |
|
3535 | 3540 | u.warn(_("** Mercurial Distributed SCM (version %s)\n") |
|
3536 | 3541 | % version.get_version()) |
|
3537 | 3542 | raise |
|
3538 | 3543 | |
|
3539 | 3544 | return -1 |
General Comments 0
You need to be logged in to leave comments.
Login now