comparison mercurial/hg.py @ 42600:3bc400ccbf99

abort: added support for merge This adds support of `hg merge --abort` to `hg abort` plan. This involves refactoring `hg.merge` into two different functions removing the abort logic of `merge` from `hg.merge` and then creating a seperate `hg.abortmerge` to handle the abort logic so that the abortion of merge can be called independently. `hg.abortmerge` is then registered as `abortfunc` for the state detection API so that `commands.abort` can use it to deal with an unfinished merge operation. Results are shown as tests. Differential Revision: https://phab.mercurial-scm.org/D6588
author Taapas Agrawal <taapas2897@gmail.com>
date Sun, 30 Jun 2019 01:07:14 +0530
parents 57539e5ea2e0
children 209f2b8a50dc
comparison
equal deleted inserted replaced
42599:3fb0493812c0 42600:3bc400ccbf99
954 954
955 def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None, 955 def merge(repo, node, force=None, remind=True, mergeforce=False, labels=None,
956 abort=False): 956 abort=False):
957 """Branch merge with node, resolving changes. Return true if any 957 """Branch merge with node, resolving changes. Return true if any
958 unresolved conflicts.""" 958 unresolved conflicts."""
959 if not abort: 959 if abort:
960 stats = mergemod.update(repo, node, branchmerge=True, force=force, 960 return abortmerge(repo.ui, repo, labels=labels)
961 mergeforce=mergeforce, labels=labels) 961
962 else: 962 stats = mergemod.update(repo, node, branchmerge=True, force=force,
963 ms = mergemod.mergestate.read(repo) 963 mergeforce=mergeforce, labels=labels)
964 if ms.active():
965 # there were conflicts
966 node = ms.localctx.hex()
967 else:
968 # there were no conficts, mergestate was not stored
969 node = repo['.'].hex()
970
971 repo.ui.status(_("aborting the merge, updating back to"
972 " %s\n") % node[:12])
973 stats = mergemod.update(repo, node, branchmerge=False, force=True,
974 labels=labels)
975
976 _showstats(repo, stats) 964 _showstats(repo, stats)
977 if stats.unresolvedcount: 965 if stats.unresolvedcount:
978 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges " 966 repo.ui.status(_("use 'hg resolve' to retry unresolved file merges "
979 "or 'hg merge --abort' to abandon\n")) 967 "or 'hg merge --abort' to abandon\n"))
980 elif remind and not abort: 968 elif remind:
981 repo.ui.status(_("(branch merge, don't forget to commit)\n")) 969 repo.ui.status(_("(branch merge, don't forget to commit)\n"))
970 return stats.unresolvedcount > 0
971
972 def abortmerge(ui, repo, labels=None):
973 ms = mergemod.mergestate.read(repo)
974 if ms.active():
975 # there were conflicts
976 node = ms.localctx.hex()
977 else:
978 # there were no conficts, mergestate was not stored
979 node = repo['.'].hex()
980
981 repo.ui.status(_("aborting the merge, updating back to"
982 " %s\n") % node[:12])
983 stats = mergemod.update(repo, node, branchmerge=False, force=True,
984 labels=labels)
985 _showstats(repo, stats)
982 return stats.unresolvedcount > 0 986 return stats.unresolvedcount > 0
983 987
984 def _incoming(displaychlist, subreporecurse, ui, repo, source, 988 def _incoming(displaychlist, subreporecurse, ui, repo, source,
985 opts, buffered=False): 989 opts, buffered=False):
986 """ 990 """