Mercurial > hg
changeset 2808:30f59f4a327e
Introduce update helper functions: update, merge, clean, and revert
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 07 Aug 2006 22:54:33 -0500 |
parents | a8a7ce1a01a5 |
children | 1c6beafbae97 |
files | hgext/fetch.py hgext/hbisect.py hgext/mq.py mercurial/commands.py mercurial/hg.py tests/test-up-local-change.out tests/test-update-reverse.out |
diffstat | 7 files changed, 41 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/fetch.py Mon Aug 07 22:35:36 2006 -0500 +++ b/hgext/fetch.py Mon Aug 07 22:54:33 2006 -0500 @@ -24,19 +24,19 @@ if modheads == 0: return 0 if modheads == 1: - return commands.doupdate(ui, repo) + return hg.update(repo, repo.changelog.tip()) newheads = repo.heads(parent) newchildren = [n for n in repo.heads(parent) if n != parent] newparent = parent if newchildren: - commands.doupdate(ui, repo, node=hex(newchildren[0])) + hg.update(repo, newchildren[0]) newparent = newchildren[0] newheads = [n for n in repo.heads() if n != newparent] err = False if newheads: ui.status(_('merging with new head %d:%s\n') % (repo.changelog.rev(newheads[0]), short(newheads[0]))) - err = hg.update(repo, newheads[0], allow=True, remind=False) + err = hg.merge(repo, newheads[0], remind=False) if not err and len(newheads) > 1: ui.status(_('not merging with %d other new heads ' '(use "hg heads" and "hg merge" to merge them)') %
--- a/hgext/hbisect.py Mon Aug 07 22:35:36 2006 -0500 +++ b/hgext/hbisect.py Mon Aug 07 22:54:33 2006 -0500 @@ -197,7 +197,7 @@ check_clean(self.ui, self.repo) rev = self.next() if rev is not None: - return hg.update(self.repo, rev, force=True) + return hg.clean(self.repo, rev) def good(self, rev): self.goodrevs.append(rev)
--- a/hgext/mq.py Mon Aug 07 22:35:36 2006 -0500 +++ b/hgext/mq.py Mon Aug 07 22:54:33 2006 -0500 @@ -190,11 +190,11 @@ self.ui.warn("patch didn't work out, merging %s\n" % patch) # apply failed, strip away that rev and merge. - hg.update(repo, head, allow=False, force=True, wlock=wlock) + hg.clean(repo, head, wlock=wlock) self.strip(repo, n, update=False, backup='strip', wlock=wlock) c = repo.changelog.read(rev) - ret = hg.update(repo, rev, allow=True, wlock=wlock) + ret = hg.merge(repo, rev, wlock=wlock) if ret: raise util.Abort(_("update returned %d") % ret) n = repo.commit(None, c[4], c[1], force=1, wlock=wlock) @@ -530,7 +530,7 @@ if c or a or d or r: raise util.Abort(_("local changes found")) urev = self.qparents(repo, rev) - hg.update(repo, urev, allow=False, force=True, wlock=wlock) + hg.clean(repo, urev, wlock=wlock) repo.dirstate.write() # save is a list of all the branches we are truncating away @@ -1019,7 +1019,7 @@ if not r: self.ui.warn("Unable to load queue repository\n") return 1 - hg.update(r, qpp[0], allow=False, force=True) + hg.clean(r, qpp[0]) def save(self, repo, msg=None): if len(self.applied) == 0:
--- a/mercurial/commands.py Mon Aug 07 22:35:36 2006 -0500 +++ b/mercurial/commands.py Mon Aug 07 22:54:33 2006 -0500 @@ -976,7 +976,7 @@ if opts['parent']: raise util.Abort(_('cannot use --parent on non-merge changeset')) parent = p1 - hg.update(repo, node, force=True, show_stats=False) # backout + hg.clean(repo, node, show_stats=False) revert_opts = opts.copy() revert_opts['rev'] = hex(parent) revert(ui, repo, **revert_opts) @@ -994,7 +994,7 @@ if opts['merge']: ui.status(_('merging with changeset %s\n') % nice(op1)) n = _lookup(repo, hex(op1)) - hg.update(repo, n, allow=True) # merge + hg.merge(repo, n) else: ui.status(_('the backout changeset is a new head - ' 'do not forget to merge\n')) @@ -2163,7 +2163,7 @@ """ node = _lookup(repo, node, branch) - hg.update(repo, node, allow=True, forcemerge=force) # merge + return hg.merge(repo, node, force=force) def outgoing(ui, repo, dest=None, **opts): """show changesets not found in destination @@ -2606,8 +2606,7 @@ if not opts.get('dry_run'): repo.dirstate.forget(forget[0]) - r = hg.update(repo, node, False, True, update.has_key, False, - wlock=wlock, show_stats=False) # revert + r = hg.revert(repo, node, update.has_key) repo.dirstate.update(add[0], 'a') repo.dirstate.update(undelete[0], 'n') repo.dirstate.update(remove[0], 'r') @@ -2905,11 +2904,15 @@ By default, update will refuse to run if doing so would require merging or discarding local changes. """ + node = _lookup(repo, node, branch) if merge: ui.warn(_('(the -m/--merge option is deprecated; ' 'use the merge command instead)\n')) - node = _lookup(repo, node, branch) - return hg.update(repo, node, allow=merge, force=clean, forcemerge=force) + return hg.merge(repo, node, force=force) + elif clean: + return hg.clean(repo, node) + else: + return hg.update(repo, node) def _lookup(repo, node, branch=None): if branch:
--- a/mercurial/hg.py Mon Aug 07 22:35:36 2006 -0500 +++ b/mercurial/hg.py Mon Aug 07 22:54:33 2006 -0500 @@ -10,7 +10,7 @@ from demandload import * from i18n import gettext as _ demandload(globals(), "localrepo bundlerepo httprepo sshrepo statichttprepo") -demandload(globals(), "errno lock os shutil util merge") +demandload(globals(), "errno lock os shutil util merge@_merge") def _local(path): return (os.path.isfile(path and util.drop_scheme('file', path)) and @@ -200,20 +200,30 @@ dest_lock.release() if update: - merge.update(dest_repo, dest_repo.changelog.tip()) + _merge.update(dest_repo, dest_repo.changelog.tip()) if dir_cleanup: dir_cleanup.close() return src_repo, dest_repo +def update(repo, node): + """update the working directory to node, merging linear changes""" + return _merge.update(repo, node) -# This should instead be several functions with short arglists, like -# update/merge/revert +def clean(repo, node, wlock=None, show_stats=True): + """forcibly switch the working directory to node, clobbering changes""" + return _merge.update(repo, node, force=True, wlock=wlock, + show_stats=show_stats) -def update(repo, node, allow=False, force=False, choose=None, - moddirstate=True, forcemerge=False, wlock=None, show_stats=True): - return merge.update(repo, node, allow, force, choose, moddirstate, - forcemerge, wlock, show_stats) +def merge(repo, node, force=None, remind=True, wlock=None): + """branch merge with node, resolving changes""" + return _merge.update(repo, node, allow=True, forcemerge=force, + remind=remind, wlock=wlock) + +def revert(repo, node, choose): + """revert changes to revision in node without updating dirstate""" + return _merge.update(repo, node, force=True, choose=choose, + moddirstate=False, show_stats=False) def verify(repo): """verify the consistency of a repository"""
--- a/tests/test-up-local-change.out Mon Aug 07 22:35:36 2006 -0500 +++ b/tests/test-up-local-change.out Mon Aug 07 22:54:33 2006 -0500 @@ -17,7 +17,7 @@ summary: 1 resolving manifests - force None allow None moddirstate True linear True + force False allow False moddirstate True linear True ancestor a0c8bcbbb45c local a0c8bcbbb45c remote 1165e8bd193e a versions differ, resolve remote created b @@ -33,7 +33,7 @@ summary: 2 resolving manifests - force None allow None moddirstate True linear True + force False allow False moddirstate True linear True ancestor a0c8bcbbb45c local 1165e8bd193e remote a0c8bcbbb45c remote deleted b removing b @@ -51,7 +51,7 @@ summary: 1 resolving manifests - force None allow None moddirstate True linear True + force False allow False moddirstate True linear True ancestor a0c8bcbbb45c local a0c8bcbbb45c remote 1165e8bd193e a versions differ, resolve remote created b @@ -99,7 +99,7 @@ summary: 2 resolving manifests - force None allow None moddirstate True linear False + force False allow False moddirstate True linear False ancestor a0c8bcbbb45c local 1165e8bd193e remote 4096f2872392 a versions differ, resolve b versions differ, resolve
--- a/tests/test-update-reverse.out Mon Aug 07 22:35:36 2006 -0500 +++ b/tests/test-update-reverse.out Mon Aug 07 22:54:33 2006 -0500 @@ -40,7 +40,7 @@ side1 side2 resolving manifests - force 1 allow None moddirstate True linear False + force True allow False moddirstate True linear False ancestor 8515d4bfda76 local 1c0f48f8ece6 remote 0594b9004bae remote deleted side2, clobbering remote deleted side1, clobbering