comparison mercurial/commands.py @ 3887:79e5a6e7c451

Merge with main
author Brendan Cully <brendan@kublai.com>
date Thu, 14 Dec 2006 13:49:33 -0800
parents 6081b4c68baf abaee83ce0a6
children 6b4127c7d52a
comparison
equal deleted inserted replaced
3884:d83b125b7d7e 3887:79e5a6e7c451
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 # 4 #
5 # This software may be used and distributed according to the terms 5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference. 6 # of the GNU General Public License, incorporated herein by reference.
7 7
8 from demandload import demandload 8 import demandimport; demandimport.enable()
9 from node import * 9 from node import *
10 from i18n import gettext as _ 10 from i18n import gettext as _
11 demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat") 11 import bisect, os, re, sys, signal, imp, urllib, pdb, shlex, stat
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo") 12 import fancyopts, ui, hg, util, lock, revlog, bundlerepo
13 demandload(globals(), "difflib patch time help mdiff tempfile") 13 import difflib, patch, time, help, mdiff, tempfile
14 demandload(globals(), "traceback errno version atexit") 14 import traceback, errno, version, atexit
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver") 15 import archival, changegroup, cmdutil, hgweb.server, sshserver
16 16
17 class UnknownCommand(Exception): 17 class UnknownCommand(Exception):
18 """Exception raised if command is not in the command table.""" 18 """Exception raised if command is not in the command table."""
19 class AmbiguousCommand(Exception): 19 class AmbiguousCommand(Exception):
20 """Exception raised if command shortcut matches more than one command.""" 20 """Exception raised if command shortcut matches more than one command."""
238 ui.status(_('changeset %s backs out changeset %s\n') % 238 ui.status(_('changeset %s backs out changeset %s\n') %
239 (nice(repo.changelog.tip()), nice(node))) 239 (nice(repo.changelog.tip()), nice(node)))
240 if op1 != node: 240 if op1 != node:
241 if opts['merge']: 241 if opts['merge']:
242 ui.status(_('merging with changeset %s\n') % nice(op1)) 242 ui.status(_('merging with changeset %s\n') % nice(op1))
243 n = _lookup(repo, hex(op1)) 243 hg.merge(repo, hex(op1))
244 hg.merge(repo, n)
245 else: 244 else:
246 ui.status(_('the backout changeset is a new head - ' 245 ui.status(_('the backout changeset is a new head - '
247 'do not forget to merge\n')) 246 'do not forget to merge\n'))
248 ui.status(_('(use "backout --merge" ' 247 ui.status(_('(use "backout --merge" '
249 'if you want to auto-merge)\n')) 248 'if you want to auto-merge)\n'))
1696 1695
1697 df = False 1696 df = False
1698 if opts["date"]: 1697 if opts["date"]:
1699 df = util.matchdate(opts["date"]) 1698 df = util.matchdate(opts["date"])
1700 1699
1701
1702 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) 1700 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
1703 for st, rev, fns in changeiter: 1701 for st, rev, fns in changeiter:
1704 if st == 'add': 1702 if st == 'add':
1705 changenode = repo.changelog.node(rev) 1703 changenode = repo.changelog.node(rev)
1706 parents = [p for p in repo.changelog.parentrevs(rev) 1704 parents = [p for p in repo.changelog.parentrevs(rev)
1761 ui.write("%40s " % hex(m[f])) 1759 ui.write("%40s " % hex(m[f]))
1762 if ui.verbose: 1760 if ui.verbose:
1763 ui.write("%3s " % (m.execf(f) and "755" or "644")) 1761 ui.write("%3s " % (m.execf(f) and "755" or "644"))
1764 ui.write("%s\n" % f) 1762 ui.write("%s\n" % f)
1765 1763
1766 def merge(ui, repo, node=None, force=None, branch=None): 1764 def merge(ui, repo, node=None, force=None):
1767 """Merge working directory with another revision 1765 """Merge working directory with another revision
1768 1766
1769 Merge the contents of the current working directory and the 1767 Merge the contents of the current working directory and the
1770 requested revision. Files that changed between either parent are 1768 requested revision. Files that changed between either parent are
1771 marked as changed for the next commit and a commit must be 1769 marked as changed for the next commit and a commit must be
1775 head revision, and the repository contains exactly one other head, 1773 head revision, and the repository contains exactly one other head,
1776 the other head is merged with by default. Otherwise, an explicit 1774 the other head is merged with by default. Otherwise, an explicit
1777 revision to merge with must be provided. 1775 revision to merge with must be provided.
1778 """ 1776 """
1779 1777
1780 if node or branch: 1778 if not node:
1781 node = _lookup(repo, node, branch)
1782 else:
1783 heads = repo.heads() 1779 heads = repo.heads()
1784 if len(heads) > 2: 1780 if len(heads) > 2:
1785 raise util.Abort(_('repo has %d heads - ' 1781 raise util.Abort(_('repo has %d heads - '
1786 'please merge with an explicit rev') % 1782 'please merge with an explicit rev') %
1787 len(heads)) 1783 len(heads))
2476 """ 2472 """
2477 gen = changegroup.readbundle(urllib.urlopen(fname), fname) 2473 gen = changegroup.readbundle(urllib.urlopen(fname), fname)
2478 modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname) 2474 modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
2479 return postincoming(ui, repo, modheads, opts['update']) 2475 return postincoming(ui, repo, modheads, opts['update'])
2480 2476
2481 def update(ui, repo, node=None, clean=False, branch=None, date=None): 2477 def update(ui, repo, node=None, clean=False, date=None):
2482 """update or merge working directory 2478 """update or merge working directory
2483 2479
2484 Update the working directory to the specified revision. 2480 Update the working directory to the specified revision.
2485 2481
2486 If there are no outstanding changes in the working directory and 2482 If there are no outstanding changes in the working directory and
2496 if date: 2492 if date:
2497 if node: 2493 if node:
2498 raise util.Abort(_("you can't specify a revision and a date")) 2494 raise util.Abort(_("you can't specify a revision and a date"))
2499 node = cmdutil.finddate(ui, repo, date) 2495 node = cmdutil.finddate(ui, repo, date)
2500 2496
2501 node = _lookup(repo, node, branch)
2502 if clean: 2497 if clean:
2503 return hg.clean(repo, node) 2498 return hg.clean(repo, node)
2504 else: 2499 else:
2505 return hg.update(repo, node) 2500 return hg.update(repo, node)
2506
2507 def _lookup(repo, node, branch=None):
2508 if branch:
2509 repo.ui.warn(_("the --branch option is deprecated, "
2510 "please use 'hg branch' instead\n"))
2511 br = repo.branchlookup(branch=branch)
2512 found = []
2513 for x in br:
2514 if branch in br[x]:
2515 found.append(x)
2516 if len(found) > 1:
2517 repo.ui.warn(_("Found multiple heads for %s\n") % branch)
2518 for x in found:
2519 cmdutil.show_changeset(ui, repo, {}).show(changenode=x)
2520 raise util.Abort("")
2521 if len(found) == 1:
2522 node = found[0]
2523 repo.ui.warn(_("Using head %s for branch %s\n")
2524 % (short(node), branch))
2525 else:
2526 raise util.Abort(_("branch %s not found") % branch)
2527 else:
2528 node = node and repo.lookup(node) or repo.changelog.tip()
2529 return node
2530 2501
2531 def verify(ui, repo): 2502 def verify(ui, repo):
2532 """verify the integrity of the repository 2503 """verify the integrity of the repository
2533 2504
2534 Verify the integrity of the current repository. 2505 Verify the integrity of the current repository.
2731 ('u', 'user', None, _('print user who committed change')), 2702 ('u', 'user', None, _('print user who committed change')),
2732 ] + walkopts, 2703 ] + walkopts,
2733 _('hg grep [OPTION]... PATTERN [FILE]...')), 2704 _('hg grep [OPTION]... PATTERN [FILE]...')),
2734 "heads": 2705 "heads":
2735 (heads, 2706 (heads,
2736 [('b', 'branches', None, _('show branches (DEPRECATED)')), 2707 [('', 'style', '', _('display using template map file')),
2737 ('', 'style', '', _('display using template map file')),
2738 ('r', 'rev', '', _('show only heads which are descendants of rev')), 2708 ('r', 'rev', '', _('show only heads which are descendants of rev')),
2739 ('', 'template', '', _('display with template'))], 2709 ('', 'template', '', _('display with template'))],
2740 _('hg heads [-r REV]')), 2710 _('hg heads [-r REV]')),
2741 "help": (help_, [], _('hg help [COMMAND]')), 2711 "help": (help_, [], _('hg help [COMMAND]')),
2742 "identify|id": (identify, [], _('hg identify')), 2712 "identify|id": (identify, [], _('hg identify')),
2743 "import|patch": 2713 "import|patch":
2744 (import_, 2714 (import_,
2745 [('p', 'strip', 1, 2715 [('p', 'strip', 1,
2746 _('directory strip option for patch. This has the same\n' 2716 _('directory strip option for patch. This has the same\n'
2747 'meaning as the corresponding patch option')), 2717 'meaning as the corresponding patch option')),
2748 ('b', 'base', '', _('base path (DEPRECATED)')), 2718 ('b', 'base', '', _('base path')),
2749 ('f', 'force', None, 2719 ('f', 'force', None,
2750 _('skip check for outstanding uncommitted changes'))] + commitopts, 2720 _('skip check for outstanding uncommitted changes'))] + commitopts,
2751 _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')), 2721 _('hg import [-p NUM] [-m MESSAGE] [-f] PATCH...')),
2752 "incoming|in": (incoming, 2722 "incoming|in": (incoming,
2753 [('M', 'no-merges', None, _('do not show merges')), 2723 [('M', 'no-merges', None, _('do not show merges')),
2775 _('print complete paths from the filesystem root')), 2745 _('print complete paths from the filesystem root')),
2776 ] + walkopts, 2746 ] + walkopts,
2777 _('hg locate [OPTION]... [PATTERN]...')), 2747 _('hg locate [OPTION]... [PATTERN]...')),
2778 "^log|history": 2748 "^log|history":
2779 (log, 2749 (log,
2780 [('b', 'branches', None, _('show branches (DEPRECATED)')), 2750 [('f', 'follow', None,
2781 ('f', 'follow', None,
2782 _('follow changeset history, or file history across copies and renames')), 2751 _('follow changeset history, or file history across copies and renames')),
2783 ('', 'follow-first', None, 2752 ('', 'follow-first', None,
2784 _('only follow the first parent of merge changesets')), 2753 _('only follow the first parent of merge changesets')),
2785 ('d', 'date', '', _('show revs matching date spec')), 2754 ('d', 'date', '', _('show revs matching date spec')),
2786 ('C', 'copies', None, _('show copied files')), 2755 ('C', 'copies', None, _('show copied files')),
2797 ] + walkopts, 2766 ] + walkopts,
2798 _('hg log [OPTION]... [FILE]')), 2767 _('hg log [OPTION]... [FILE]')),
2799 "manifest": (manifest, [], _('hg manifest [REV]')), 2768 "manifest": (manifest, [], _('hg manifest [REV]')),
2800 "merge": 2769 "merge":
2801 (merge, 2770 (merge,
2802 [('b', 'branch', '', _('merge with head of a specific branch (DEPRECATED)')), 2771 [('f', 'force', None, _('force a merge with outstanding changes'))],
2803 ('f', 'force', None, _('force a merge with outstanding changes'))],
2804 _('hg merge [-f] [REV]')), 2772 _('hg merge [-f] [REV]')),
2805 "outgoing|out": (outgoing, 2773 "outgoing|out": (outgoing,
2806 [('M', 'no-merges', None, _('do not show merges')), 2774 [('M', 'no-merges', None, _('do not show merges')),
2807 ('f', 'force', None, 2775 ('f', 'force', None,
2808 _('run even when remote repository is unrelated')), 2776 _('run even when remote repository is unrelated')),
2813 ('', 'template', '', _('display with template')), 2781 ('', 'template', '', _('display with template')),
2814 ] + remoteopts, 2782 ] + remoteopts,
2815 _('hg outgoing [-M] [-p] [-n] [-f] [-r REV]... [DEST]')), 2783 _('hg outgoing [-M] [-p] [-n] [-f] [-r REV]... [DEST]')),
2816 "^parents": 2784 "^parents":
2817 (parents, 2785 (parents,
2818 [('b', 'branches', None, _('show branches (DEPRECATED)')), 2786 [('r', 'rev', '', _('show parents from the specified rev')),
2819 ('r', 'rev', '', _('show parents from the specified rev')),
2820 ('', 'style', '', _('display using template map file')), 2787 ('', 'style', '', _('display using template map file')),
2821 ('', 'template', '', _('display with template'))], 2788 ('', 'template', '', _('display with template'))],
2822 _('hg parents [-r REV] [FILE]')), 2789 _('hg parents [-r REV] [FILE]')),
2823 "paths": (paths, [], _('hg paths [NAME]')), 2790 "paths": (paths, [], _('hg paths [NAME]')),
2824 "^pull": 2791 "^pull":
2917 ('r', 'rev', '', _('revision to tag'))], 2884 ('r', 'rev', '', _('revision to tag'))],
2918 _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')), 2885 _('hg tag [-l] [-m TEXT] [-d DATE] [-u USER] [-r REV] NAME')),
2919 "tags": (tags, [], _('hg tags')), 2886 "tags": (tags, [], _('hg tags')),
2920 "tip": 2887 "tip":
2921 (tip, 2888 (tip,
2922 [('b', 'branches', None, _('show branches (DEPRECATED)')), 2889 [('', 'style', '', _('display using template map file')),
2923 ('', 'style', '', _('display using template map file')),
2924 ('p', 'patch', None, _('show patch')), 2890 ('p', 'patch', None, _('show patch')),
2925 ('', 'template', '', _('display with template'))], 2891 ('', 'template', '', _('display with template'))],
2926 _('hg tip [-p]')), 2892 _('hg tip [-p]')),
2927 "unbundle": 2893 "unbundle":
2928 (unbundle, 2894 (unbundle,
2929 [('u', 'update', None, 2895 [('u', 'update', None,
2930 _('update to new tip if changesets were unbundled'))], 2896 _('update to new tip if changesets were unbundled'))],
2931 _('hg unbundle [-u] FILE')), 2897 _('hg unbundle [-u] FILE')),
2932 "^update|up|checkout|co": 2898 "^update|up|checkout|co":
2933 (update, 2899 (update,
2934 [('b', 'branch', '', 2900 [('C', 'clean', None, _('overwrite locally modified files')),
2935 _('checkout the head of a specific branch (DEPRECATED)')),
2936 ('C', 'clean', None, _('overwrite locally modified files')),
2937 ('d', 'date', '', _('tipmost revision matching date'))], 2901 ('d', 'date', '', _('tipmost revision matching date'))],
2938 _('hg update [-C] [-d DATE] [REV]')), 2902 _('hg update [-C] [-d DATE] [REV]')),
2939 "verify": (verify, [], _('hg verify')), 2903 "verify": (verify, [], _('hg verify')),
2940 "version": (version_, [], _('hg version')), 2904 "version": (version_, [], _('hg version')),
2941 } 2905 }