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