Mercurial > hg
comparison mercurial/commands.py @ 12925:6eab8f0df2ca
commands: add revset support to most commands
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 04 Nov 2010 16:21:28 -0500 |
parents | 5c3e5cd141ea |
children | 34034e55424f |
comparison
equal
deleted
inserted
replaced
12924:2f1174b2c4fa | 12925:6eab8f0df2ca |
---|---|
124 funcmap = [func for op, func in opmap if opts.get(op)] | 124 funcmap = [func for op, func in opmap if opts.get(op)] |
125 if linenumber: | 125 if linenumber: |
126 lastfunc = funcmap[-1] | 126 lastfunc = funcmap[-1] |
127 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) | 127 funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1]) |
128 | 128 |
129 ctx = repo[opts.get('rev')] | 129 ctx = cmdutil.revsingle(repo, opts.get('rev')) |
130 m = cmdutil.match(repo, pats, opts) | 130 m = cmdutil.match(repo, pats, opts) |
131 follow = not opts.get('no_follow') | 131 follow = not opts.get('no_follow') |
132 for abs in ctx.walk(m): | 132 for abs in ctx.walk(m): |
133 fctx = ctx[abs] | 133 fctx = ctx[abs] |
134 if not opts.get('text') and util.binary(fctx.data()): | 134 if not opts.get('text') and util.binary(fctx.data()): |
176 removed. | 176 removed. |
177 | 177 |
178 Returns 0 on success. | 178 Returns 0 on success. |
179 ''' | 179 ''' |
180 | 180 |
181 ctx = repo[opts.get('rev')] | 181 ctx = cmdutil.revsingle(repo, opts.get('rev')) |
182 if not ctx: | 182 if not ctx: |
183 raise util.Abort(_('no working directory: please specify a revision')) | 183 raise util.Abort(_('no working directory: please specify a revision')) |
184 node = ctx.node() | 184 node = ctx.node() |
185 dest = cmdutil.make_filename(repo, dest, node) | 185 dest = cmdutil.make_filename(repo, dest, node) |
186 if os.path.realpath(dest) == repo.root: | 186 if os.path.realpath(dest) == repo.root: |
241 date = opts.get('date') | 241 date = opts.get('date') |
242 if date: | 242 if date: |
243 opts['date'] = util.parsedate(date) | 243 opts['date'] = util.parsedate(date) |
244 | 244 |
245 cmdutil.bail_if_changed(repo) | 245 cmdutil.bail_if_changed(repo) |
246 node = repo.lookup(rev) | 246 node = cmdutil.revsingle(repo, rev).node() |
247 | 247 |
248 op1, op2 = repo.dirstate.parents() | 248 op1, op2 = repo.dirstate.parents() |
249 a = repo.changelog.ancestor(op1, node) | 249 a = repo.changelog.ancestor(op1, node) |
250 if a != node: | 250 if a != node: |
251 raise util.Abort(_('cannot backout change on a different branch')) | 251 raise util.Abort(_('cannot backout change on a different branch')) |
406 raise util.Abort(_("failed to execute %s") % command) | 406 raise util.Abort(_("failed to execute %s") % command) |
407 elif status < 0: | 407 elif status < 0: |
408 raise util.Abort(_("%s killed") % command) | 408 raise util.Abort(_("%s killed") % command) |
409 else: | 409 else: |
410 transition = "bad" | 410 transition = "bad" |
411 ctx = repo[rev or '.'] | 411 ctx = cmdutil.revsingle(repo, rev) |
412 rev = None # clear for future iterations | |
412 state[transition].append(ctx.node()) | 413 state[transition].append(ctx.node()) |
413 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) | 414 ui.status(_('Changeset %d:%s: %s\n') % (ctx, ctx, transition)) |
414 check_state(state, interactive=False) | 415 check_state(state, interactive=False) |
415 # bisect | 416 # bisect |
416 nodes, changesets, good = hbisect.bisect(repo.changelog, state) | 417 nodes, changesets, good = hbisect.bisect(repo.changelog, state) |
570 Applying bundles preserves all changeset contents including | 571 Applying bundles preserves all changeset contents including |
571 permissions, copy/rename information, and revision history. | 572 permissions, copy/rename information, and revision history. |
572 | 573 |
573 Returns 0 on success, 1 if no changes found. | 574 Returns 0 on success, 1 if no changes found. |
574 """ | 575 """ |
575 revs = opts.get('rev') or None | 576 revs = None |
577 if 'rev' in opts: | |
578 revs = cmdutil.revrange(repo, opts['rev']) | |
579 | |
576 if opts.get('all'): | 580 if opts.get('all'): |
577 base = ['null'] | 581 base = ['null'] |
578 else: | 582 else: |
579 base = opts.get('base') | 583 base = cmdutil.revrange(repo, opts.get('base')) |
580 if base: | 584 if base: |
581 if dest: | 585 if dest: |
582 raise util.Abort(_("--base is incompatible with specifying " | 586 raise util.Abort(_("--base is incompatible with specifying " |
583 "a destination")) | 587 "a destination")) |
584 base = [repo.lookup(rev) for rev in base] | 588 base = [repo.lookup(rev) for rev in base] |
1024 and 'yes' or 'no')) | 1028 and 'yes' or 'no')) |
1025 os.unlink('.debugfsinfo') | 1029 os.unlink('.debugfsinfo') |
1026 | 1030 |
1027 def debugrebuildstate(ui, repo, rev="tip"): | 1031 def debugrebuildstate(ui, repo, rev="tip"): |
1028 """rebuild the dirstate as it would look like for the given revision""" | 1032 """rebuild the dirstate as it would look like for the given revision""" |
1029 ctx = repo[rev] | 1033 ctx = cmdutil.revsingle(repo, rev) |
1030 wlock = repo.wlock() | 1034 wlock = repo.wlock() |
1031 try: | 1035 try: |
1032 repo.dirstate.rebuild(ctx.node(), ctx.manifest()) | 1036 repo.dirstate.rebuild(ctx.node(), ctx.manifest()) |
1033 finally: | 1037 finally: |
1034 wlock.release() | 1038 wlock.release() |
1138 be used with care. | 1142 be used with care. |
1139 | 1143 |
1140 Returns 0 on success. | 1144 Returns 0 on success. |
1141 """ | 1145 """ |
1142 | 1146 |
1143 if not rev2: | 1147 r1 = cmdutil.revsingle(repo, rev1).node() |
1144 rev2 = hex(nullid) | 1148 r2 = cmdutil.revsingle(repo, rev2, 'null').node() |
1145 | 1149 |
1146 wlock = repo.wlock() | 1150 wlock = repo.wlock() |
1147 try: | 1151 try: |
1148 repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2)) | 1152 repo.dirstate.setparents(r1, r2) |
1149 finally: | 1153 finally: |
1150 wlock.release() | 1154 wlock.release() |
1151 | 1155 |
1152 def debugstate(ui, repo, nodates=None): | 1156 def debugstate(ui, repo, nodates=None): |
1153 """show the contents of the current dirstate""" | 1157 """show the contents of the current dirstate""" |
1172 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) | 1176 ui.write("%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) |
1173 for f in repo.dirstate.copies(): | 1177 for f in repo.dirstate.copies(): |
1174 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) | 1178 ui.write(_("copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) |
1175 | 1179 |
1176 def debugsub(ui, repo, rev=None): | 1180 def debugsub(ui, repo, rev=None): |
1177 if rev == '': | 1181 ctx = cmdutil.revsingle(repo, rev, None) |
1178 rev = None | 1182 for k, v in sorted(ctx.substate.items()): |
1179 for k, v in sorted(repo[rev].substate.items()): | |
1180 ui.write('path %s\n' % k) | 1183 ui.write('path %s\n' % k) |
1181 ui.write(' source %s\n' % v[0]) | 1184 ui.write(' source %s\n' % v[0]) |
1182 ui.write(' revision %s\n' % v[1]) | 1185 ui.write(' revision %s\n' % v[1]) |
1183 | 1186 |
1184 def debugdag(ui, repo, file_=None, *revs, **opts): | 1187 def debugdag(ui, repo, file_=None, *revs, **opts): |
1433 return problems | 1436 return problems |
1434 | 1437 |
1435 def debugrename(ui, repo, file1, *pats, **opts): | 1438 def debugrename(ui, repo, file1, *pats, **opts): |
1436 """dump rename information""" | 1439 """dump rename information""" |
1437 | 1440 |
1438 ctx = repo[opts.get('rev')] | 1441 ctx = cmdutil.revsingle(repo, opts.get('rev')) |
1439 m = cmdutil.match(repo, (file1,) + pats, opts) | 1442 m = cmdutil.match(repo, (file1,) + pats, opts) |
1440 for abs in ctx.walk(m): | 1443 for abs in ctx.walk(m): |
1441 fctx = ctx[abs] | 1444 fctx = ctx[abs] |
1442 o = fctx.filelog().renamed(fctx.filenode()) | 1445 o = fctx.filelog().renamed(fctx.filenode()) |
1443 rel = m.rel(abs) | 1446 rel = m.rel(abs) |
1806 changesets without children will be shown. | 1809 changesets without children will be shown. |
1807 | 1810 |
1808 Returns 0 if matching heads are found, 1 if not. | 1811 Returns 0 if matching heads are found, 1 if not. |
1809 """ | 1812 """ |
1810 | 1813 |
1811 if opts.get('rev'): | 1814 start = None |
1812 start = repo.lookup(opts['rev']) | 1815 if 'rev' in opts: |
1813 else: | 1816 start = cmdutil.revsingle(repo, opts['rev'], None).node() |
1814 start = None | |
1815 | 1817 |
1816 if opts.get('topo'): | 1818 if opts.get('topo'): |
1817 heads = [repo[h] for h in repo.heads(start)] | 1819 heads = [repo[h] for h in repo.heads(start)] |
1818 else: | 1820 else: |
1819 heads = [] | 1821 heads = [] |
2198 (changed) and "+" or "")] | 2200 (changed) and "+" or "")] |
2199 if num: | 2201 if num: |
2200 output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]), | 2202 output.append("%s%s" % ('+'.join([str(p.rev()) for p in parents]), |
2201 (changed) and "+" or "")) | 2203 (changed) and "+" or "")) |
2202 else: | 2204 else: |
2203 ctx = repo[rev] | 2205 ctx = cmdutil.revsingle(repo, rev) |
2204 if default or id: | 2206 if default or id: |
2205 output = [hexfunc(ctx.node())] | 2207 output = [hexfunc(ctx.node())] |
2206 if num: | 2208 if num: |
2207 output.append(str(ctx.rev())) | 2209 output.append(str(ctx.rev())) |
2208 | 2210 |
2441 contain whitespace as multiple filenames. | 2443 contain whitespace as multiple filenames. |
2442 | 2444 |
2443 Returns 0 if a match is found, 1 otherwise. | 2445 Returns 0 if a match is found, 1 otherwise. |
2444 """ | 2446 """ |
2445 end = opts.get('print0') and '\0' or '\n' | 2447 end = opts.get('print0') and '\0' or '\n' |
2446 rev = opts.get('rev') or None | 2448 rev = cmdutil.revsingle(repo, opts.get('rev'), None).node() |
2447 | 2449 |
2448 ret = 1 | 2450 ret = 1 |
2449 m = cmdutil.match(repo, pats, opts, default='relglob') | 2451 m = cmdutil.match(repo, pats, opts, default='relglob') |
2450 m.bad = lambda x, y: False | 2452 m.bad = lambda x, y: False |
2451 for abs in repo[rev].walk(m): | 2453 for abs in repo[rev].walk(m): |
2576 | 2578 |
2577 if not node: | 2579 if not node: |
2578 node = rev | 2580 node = rev |
2579 | 2581 |
2580 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} | 2582 decor = {'l':'644 @ ', 'x':'755 * ', '':'644 '} |
2581 ctx = repo[node] | 2583 ctx = cmdutil.revsingle(repo, node) |
2582 for f in ctx: | 2584 for f in ctx: |
2583 if ui.debugflag: | 2585 if ui.debugflag: |
2584 ui.write("%40s " % hex(ctx.manifest()[f])) | 2586 ui.write("%40s " % hex(ctx.manifest()[f])) |
2585 if ui.verbose: | 2587 if ui.verbose: |
2586 ui.write(decor[ctx.flags(f)]) | 2588 ui.write(decor[ctx.flags(f)]) |
2645 | 2647 |
2646 if parent not in bheads: | 2648 if parent not in bheads: |
2647 raise util.Abort(_('working dir not at a head rev - ' | 2649 raise util.Abort(_('working dir not at a head rev - ' |
2648 'use "hg update" or merge with an explicit rev')) | 2650 'use "hg update" or merge with an explicit rev')) |
2649 node = parent == bheads[0] and bheads[-1] or bheads[0] | 2651 node = parent == bheads[0] and bheads[-1] or bheads[0] |
2652 else: | |
2653 node = cmdutil.revsingle(repo, node).node() | |
2650 | 2654 |
2651 if opts.get('preview'): | 2655 if opts.get('preview'): |
2652 # find nodes that are ancestors of p2 but not of p1 | 2656 # find nodes that are ancestors of p2 but not of p1 |
2653 p1 = repo.lookup('.') | 2657 p1 = repo.lookup('.') |
2654 p2 = repo.lookup(node) | 2658 p2 = repo.lookup(node) |
2690 last changed (before the working directory revision or the | 2694 last changed (before the working directory revision or the |
2691 argument to --rev if given) is printed. | 2695 argument to --rev if given) is printed. |
2692 | 2696 |
2693 Returns 0 on success. | 2697 Returns 0 on success. |
2694 """ | 2698 """ |
2695 rev = opts.get('rev') | 2699 |
2696 if rev: | 2700 ctx = cmdutil.revsingle(repo, opts.get('rev'), None) |
2697 ctx = repo[rev] | |
2698 else: | |
2699 ctx = repo[None] | |
2700 | 2701 |
2701 if file_: | 2702 if file_: |
2702 m = cmdutil.match(repo, (file_,), opts) | 2703 m = cmdutil.match(repo, (file_,), opts) |
2703 if m.anypats() or len(m.files()) != 1: | 2704 if m.anypats() or len(m.files()) != 1: |
2704 raise util.Abort(_('can only specify an explicit filename')) | 2705 raise util.Abort(_('can only specify an explicit filename')) |
3110 | 3111 |
3111 parent, p2 = repo.dirstate.parents() | 3112 parent, p2 = repo.dirstate.parents() |
3112 if not opts.get('rev') and p2 != nullid: | 3113 if not opts.get('rev') and p2 != nullid: |
3113 raise util.Abort(_('uncommitted merge - please provide a ' | 3114 raise util.Abort(_('uncommitted merge - please provide a ' |
3114 'specific revision')) | 3115 'specific revision')) |
3115 ctx = repo[opts.get('rev')] | 3116 ctx = cmdutil.revsingle(repo, opts.get('rev')) |
3116 node = ctx.node() | 3117 node = ctx.node() |
3117 mf = ctx.manifest() | 3118 mf = ctx.manifest() |
3118 if node == parent: | 3119 if node == parent: |
3119 pmf = mf | 3120 pmf = mf |
3120 else: | 3121 else: |
3719 raise util.Abort(_('tag \'%s\' already exists ' | 3720 raise util.Abort(_('tag \'%s\' already exists ' |
3720 '(use -f to force)') % n) | 3721 '(use -f to force)') % n) |
3721 if not rev_ and repo.dirstate.parents()[1] != nullid: | 3722 if not rev_ and repo.dirstate.parents()[1] != nullid: |
3722 raise util.Abort(_('uncommitted merge - please provide a ' | 3723 raise util.Abort(_('uncommitted merge - please provide a ' |
3723 'specific revision')) | 3724 'specific revision')) |
3724 r = repo[rev_].node() | 3725 r = cmdutil.revsingle(repo, rev_).node() |
3725 | 3726 |
3726 if not message: | 3727 if not message: |
3727 # we don't translate commit messages | 3728 # we don't translate commit messages |
3728 message = ('Added tag %s for changeset %s' % | 3729 message = ('Added tag %s for changeset %s' % |
3729 (', '.join(names), short(r))) | 3730 (', '.join(names), short(r))) |