comparison mercurial/commands.py @ 2820:0bf22c109cc3

Factor doupdate into _lookup + hg.update
author Matt Mackall <mpm@selenic.com>
date Mon, 07 Aug 2006 20:54:03 -0500
parents 987c31e2a08c
children 30f59f4a327e
comparison
equal deleted inserted replaced
2819:90a4181ca9ed 2820:0bf22c109cc3
974 parent = p 974 parent = p
975 else: 975 else:
976 if opts['parent']: 976 if opts['parent']:
977 raise util.Abort(_('cannot use --parent on non-merge changeset')) 977 raise util.Abort(_('cannot use --parent on non-merge changeset'))
978 parent = p1 978 parent = p1
979 hg.update(repo, node, force=True, show_stats=False) 979 hg.update(repo, node, force=True, show_stats=False) # backout
980 revert_opts = opts.copy() 980 revert_opts = opts.copy()
981 revert_opts['rev'] = hex(parent) 981 revert_opts['rev'] = hex(parent)
982 revert(ui, repo, **revert_opts) 982 revert(ui, repo, **revert_opts)
983 commit_opts = opts.copy() 983 commit_opts = opts.copy()
984 commit_opts['addremove'] = False 984 commit_opts['addremove'] = False
991 ui.status(_('changeset %s backs out changeset %s\n') % 991 ui.status(_('changeset %s backs out changeset %s\n') %
992 (nice(repo.changelog.tip()), nice(node))) 992 (nice(repo.changelog.tip()), nice(node)))
993 if op1 != node: 993 if op1 != node:
994 if opts['merge']: 994 if opts['merge']:
995 ui.status(_('merging with changeset %s\n') % nice(op1)) 995 ui.status(_('merging with changeset %s\n') % nice(op1))
996 doupdate(ui, repo, hex(op1), merge=True) 996 n = _lookup(repo, hex(op1))
997 hg.update(repo, n, allow=True) # merge
997 else: 998 else:
998 ui.status(_('the backout changeset is a new head - ' 999 ui.status(_('the backout changeset is a new head - '
999 'do not forget to merge\n')) 1000 'do not forget to merge\n'))
1000 ui.status(_('(use "backout --merge" ' 1001 ui.status(_('(use "backout --merge" '
1001 'if you want to auto-merge)\n')) 1002 'if you want to auto-merge)\n'))
2150 files.sort() 2151 files.sort()
2151 2152
2152 for f in files: 2153 for f in files:
2153 ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f)) 2154 ui.write("%40s %3s %s\n" % (hex(m[f]), mf[f] and "755" or "644", f))
2154 2155
2155 def merge(ui, repo, node=None, **opts): 2156 def merge(ui, repo, node=None, force=None, branch=None):
2156 """Merge working directory with another revision 2157 """Merge working directory with another revision
2157 2158
2158 Merge the contents of the current working directory and the 2159 Merge the contents of the current working directory and the
2159 requested revision. Files that changed between either parent are 2160 requested revision. Files that changed between either parent are
2160 marked as changed for the next commit and a commit must be 2161 marked as changed for the next commit and a commit must be
2161 performed before any further updates are allowed. 2162 performed before any further updates are allowed.
2162 """ 2163 """
2163 return doupdate(ui, repo, node=node, merge=True, **opts) 2164
2165 node = _lookup(repo, node, branch)
2166 hg.update(repo, node, allow=True, forcemerge=force) # merge
2164 2167
2165 def outgoing(ui, repo, dest=None, **opts): 2168 def outgoing(ui, repo, dest=None, **opts):
2166 """show changesets not found in destination 2169 """show changesets not found in destination
2167 2170
2168 Show changesets not found in the specified destination repository or 2171 Show changesets not found in the specified destination repository or
2252 def postincoming(ui, repo, modheads, optupdate): 2255 def postincoming(ui, repo, modheads, optupdate):
2253 if modheads == 0: 2256 if modheads == 0:
2254 return 2257 return
2255 if optupdate: 2258 if optupdate:
2256 if modheads == 1: 2259 if modheads == 1:
2257 return doupdate(ui, repo) 2260 return hg.update(repo, repo.changelog.tip()) # update
2258 else: 2261 else:
2259 ui.status(_("not updating, since new heads added\n")) 2262 ui.status(_("not updating, since new heads added\n"))
2260 if modheads > 1: 2263 if modheads > 1:
2261 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n")) 2264 ui.status(_("(run 'hg heads' to see heads, 'hg merge' to merge)\n"))
2262 else: 2265 else:
2602 handle(remove, False) 2605 handle(remove, False)
2603 2606
2604 if not opts.get('dry_run'): 2607 if not opts.get('dry_run'):
2605 repo.dirstate.forget(forget[0]) 2608 repo.dirstate.forget(forget[0])
2606 r = hg.update(repo, node, False, True, update.has_key, False, 2609 r = hg.update(repo, node, False, True, update.has_key, False,
2607 wlock=wlock, show_stats=False) 2610 wlock=wlock, show_stats=False) # revert
2608 repo.dirstate.update(add[0], 'a') 2611 repo.dirstate.update(add[0], 'a')
2609 repo.dirstate.update(undelete[0], 'n') 2612 repo.dirstate.update(undelete[0], 'n')
2610 repo.dirstate.update(remove[0], 'r') 2613 repo.dirstate.update(remove[0], 'r')
2611 return r 2614 return r
2612 2615
2903 merging or discarding local changes. 2906 merging or discarding local changes.
2904 """ 2907 """
2905 if merge: 2908 if merge:
2906 ui.warn(_('(the -m/--merge option is deprecated; ' 2909 ui.warn(_('(the -m/--merge option is deprecated; '
2907 'use the merge command instead)\n')) 2910 'use the merge command instead)\n'))
2908 return doupdate(ui, repo, node, merge, clean, force, branch) 2911 node = _lookup(repo, node, branch)
2909 2912 return hg.update(repo, node, allow=merge, force=clean, forcemerge=force)
2910 def doupdate(ui, repo, node=None, merge=False, clean=False, force=None, 2913
2911 branch=None): 2914 def _lookup(repo, node, branch=None):
2912 if branch: 2915 if branch:
2913 br = repo.branchlookup(branch=branch) 2916 br = repo.branchlookup(branch=branch)
2914 found = [] 2917 found = []
2915 for x in br: 2918 for x in br:
2916 if branch in br[x]: 2919 if branch in br[x]:
2917 found.append(x) 2920 found.append(x)
2918 if len(found) > 1: 2921 if len(found) > 1:
2919 ui.warn(_("Found multiple heads for %s\n") % branch) 2922 repo.ui.warn(_("Found multiple heads for %s\n") % branch)
2920 for x in found: 2923 for x in found:
2921 show_changeset(ui, repo, {}).show(changenode=x, brinfo=br) 2924 show_changeset(ui, repo, {}).show(changenode=x, brinfo=br)
2922 return 1 2925 raise util.Abort("")
2923 if len(found) == 1: 2926 if len(found) == 1:
2924 node = found[0] 2927 node = found[0]
2925 ui.warn(_("Using head %s for branch %s\n") % (short(node), branch)) 2928 repo.ui.warn(_("Using head %s for branch %s\n")
2929 % (short(node), branch))
2926 else: 2930 else:
2927 ui.warn(_("branch %s not found\n") % (branch)) 2931 raise util.Abort(_("branch %s not found\n") % (branch))
2928 return 1
2929 else: 2932 else:
2930 node = node and repo.lookup(node) or repo.changelog.tip() 2933 node = node and repo.lookup(node) or repo.changelog.tip()
2931 return hg.update(repo, node, allow=merge, force=clean, forcemerge=force) 2934 return node
2932 2935
2933 def verify(ui, repo): 2936 def verify(ui, repo):
2934 """verify the integrity of the repository 2937 """verify the integrity of the repository
2935 2938
2936 Verify the integrity of the current repository. 2939 Verify the integrity of the current repository.