merge.py
2105 lines
| 74.5 KiB
| text/x-python
|
PythonLexer
/ mercurial / merge.py
Matt Mackall
|
r2775 | # merge.py - directory-level update/merge handling for Mercurial | ||
# | ||||
Thomas Arendsen Hein
|
r4635 | # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> | ||
Matt Mackall
|
r2775 | # | ||
Martin Geisler
|
r8225 | # This software may be used and distributed according to the terms of the | ||
Matt Mackall
|
r10263 | # GNU General Public License version 2 or any later version. | ||
Matt Mackall
|
r2775 | |||
Gregory Szorc
|
r25959 | from __future__ import absolute_import | ||
import errno | ||||
Valentin Gatien-Baron
|
r42656 | import stat | ||
Pierre-Yves David
|
r20590 | import struct | ||
Gregory Szorc
|
r25959 | from .i18n import _ | ||
from .node import ( | ||||
Durham Goode
|
r30361 | addednodeid, | ||
Durham Goode
|
r30362 | modifiednodeid, | ||
Gregory Szorc
|
r25959 | nullid, | ||
nullrev, | ||||
) | ||||
Augie Fackler
|
r43346 | from .thirdparty import attr | ||
Gregory Szorc
|
r25959 | from . import ( | ||
copies, | ||||
Matt Harbison
|
r39843 | encoding, | ||
Pierre-Yves David
|
r26587 | error, | ||
Gregory Szorc
|
r25959 | filemerge, | ||
Durham Goode
|
r31257 | match as matchmod, | ||
Augie Fackler
|
r45383 | mergestate as mergestatemod, | ||
r33147 | obsutil, | |||
Martin von Zweigbergk
|
r44032 | pathutil, | ||
Pulkit Goyal
|
r30519 | pycompat, | ||
Siddharth Agarwal
|
r27656 | scmutil, | ||
Yuya Nishihara
|
r36026 | subrepoutil, | ||
Gregory Szorc
|
r25959 | util, | ||
worker, | ||||
) | ||||
Matt Mackall
|
r6512 | |||
Pierre-Yves David
|
r20590 | _pack = struct.pack | ||
_unpack = struct.unpack | ||||
Augie Fackler
|
r43346 | |||
Siddharth Agarwal
|
r27740 | def _getcheckunknownconfig(repo, section, name): | ||
Boris Feld
|
r34523 | config = repo.ui.config(section, name) | ||
Augie Fackler
|
r43347 | valid = [b'abort', b'ignore', b'warn'] | ||
Siddharth Agarwal
|
r27740 | if config not in valid: | ||
Augie Fackler
|
r43347 | validstr = b', '.join([b"'" + v + b"'" for v in valid]) | ||
Augie Fackler
|
r43346 | raise error.ConfigError( | ||
Martin von Zweigbergk
|
r43387 | _(b"%s.%s not valid ('%s' is none of %s)") | ||
Augie Fackler
|
r43346 | % (section, name, config, validstr) | ||
) | ||||
Siddharth Agarwal
|
r27740 | return config | ||
Augie Fackler
|
r43346 | |||
Martin von Zweigbergk
|
r23653 | def _checkunknownfile(repo, wctx, mctx, f, f2=None): | ||
Phil Cohen
|
r35289 | if wctx.isinmemory(): | ||
# Nothing to do in IMM because nothing in the "working copy" can be an | ||||
# unknown file. | ||||
# | ||||
# Note that we should bail out here, not in ``_checkunknownfiles()``, | ||||
# because that function does other useful work. | ||||
return False | ||||
Martin von Zweigbergk
|
r23653 | if f2 is None: | ||
f2 = f | ||||
Augie Fackler
|
r43346 | return ( | ||
repo.wvfs.audit.check(f) | ||||
Durham Goode
|
r28088 | and repo.wvfs.isfileorlink(f) | ||
Matt Mackall
|
r16284 | and repo.dirstate.normalize(f) not in repo.dirstate | ||
Augie Fackler
|
r43346 | and mctx[f2].cmp(wctx[f]) | ||
) | ||||
Matt Mackall
|
r16093 | |||
Mark Thomas
|
r35181 | class _unknowndirschecker(object): | ||
Mark Thomas
|
r34551 | """ | ||
Look for any unknown files or directories that may have a path conflict | ||||
with a file. If any path prefix of the file exists as a file or link, | ||||
then it conflicts. If the file itself is a directory that contains any | ||||
file that is not tracked, then it conflicts. | ||||
Returns the shortest path at which a conflict occurs, or None if there is | ||||
no conflict. | ||||
""" | ||||
Augie Fackler
|
r43346 | |||
Mark Thomas
|
r35181 | def __init__(self): | ||
# A set of paths known to be good. This prevents repeated checking of | ||||
# dirs. It will be updated with any new dirs that are checked and found | ||||
# to be safe. | ||||
self._unknowndircache = set() | ||||
Mark Thomas
|
r34551 | |||
Mark Thomas
|
r35181 | # A set of paths that are known to be absent. This prevents repeated | ||
# checking of subdirectories that are known not to exist. It will be | ||||
# updated with any new dirs that are checked and found to be absent. | ||||
self._missingdircache = set() | ||||
Mark Thomas
|
r34551 | |||
Phil Cohen
|
r35289 | def __call__(self, repo, wctx, f): | ||
if wctx.isinmemory(): | ||||
# Nothing to do in IMM for the same reason as ``_checkunknownfile``. | ||||
return False | ||||
Mark Thomas
|
r35181 | # Check for path prefixes that exist as unknown files. | ||
Martin von Zweigbergk
|
r44032 | for p in reversed(list(pathutil.finddirs(f))): | ||
Mark Thomas
|
r35181 | if p in self._missingdircache: | ||
return | ||||
if p in self._unknowndircache: | ||||
continue | ||||
if repo.wvfs.audit.check(p): | ||||
Augie Fackler
|
r43346 | if ( | ||
repo.wvfs.isfileorlink(p) | ||||
and repo.dirstate.normalize(p) not in repo.dirstate | ||||
): | ||||
Mark Thomas
|
r35181 | return p | ||
if not repo.wvfs.lexists(p): | ||||
self._missingdircache.add(p) | ||||
return | ||||
self._unknowndircache.add(p) | ||||
# Check if the file conflicts with a directory containing unknown files. | ||||
if repo.wvfs.audit.check(f) and repo.wvfs.isdir(f): | ||||
# Does the directory contain any files that are not in the dirstate? | ||||
for p, dirs, files in repo.wvfs.walk(f): | ||||
for fn in files: | ||||
Matt Harbison
|
r37104 | relf = util.pconvert(repo.wvfs.reljoin(p, fn)) | ||
Matt Harbison
|
r37105 | relf = repo.dirstate.normalize(relf, isknown=True) | ||
Mark Thomas
|
r35181 | if relf not in repo.dirstate: | ||
return f | ||||
return None | ||||
Mark Thomas
|
r34551 | |||
Augie Fackler
|
r43346 | |||
Siddharth Agarwal
|
r28020 | def _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce): | ||
Martin von Zweigbergk
|
r23655 | """ | ||
Considers any actions that care about the presence of conflicting unknown | ||||
files. For some actions, the result is to abort; for others, it is to | ||||
choose a different action. | ||||
""" | ||||
Mark Thomas
|
r34552 | fileconflicts = set() | ||
Mark Thomas
|
r34553 | pathconflicts = set() | ||
Siddharth Agarwal
|
r28018 | warnconflicts = set() | ||
abortconflicts = set() | ||||
Augie Fackler
|
r43347 | unknownconfig = _getcheckunknownconfig(repo, b'merge', b'checkunknown') | ||
ignoredconfig = _getcheckunknownconfig(repo, b'merge', b'checkignored') | ||||
pathconfig = repo.ui.configbool( | ||||
b'experimental', b'merge.checkpathconflicts' | ||||
) | ||||
Martin von Zweigbergk
|
r23655 | if not force: | ||
Augie Fackler
|
r43346 | |||
Siddharth Agarwal
|
r27741 | def collectconflicts(conflicts, config): | ||
Augie Fackler
|
r43347 | if config == b'abort': | ||
Siddharth Agarwal
|
r27741 | abortconflicts.update(conflicts) | ||
Augie Fackler
|
r43347 | elif config == b'warn': | ||
Siddharth Agarwal
|
r27741 | warnconflicts.update(conflicts) | ||
Mark Thomas
|
r35181 | checkunknowndirs = _unknowndirschecker() | ||
Gregory Szorc
|
r43376 | for f, (m, args, msg) in pycompat.iteritems(actions): | ||
Augie Fackler
|
r45383 | if m in ( | ||
mergestatemod.ACTION_CREATED, | ||||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
): | ||||
Martin von Zweigbergk
|
r23655 | if _checkunknownfile(repo, wctx, mctx, f): | ||
Mark Thomas
|
r34552 | fileconflicts.add(f) | ||
Siddharth Agarwal
|
r34942 | elif pathconfig and f not in wctx: | ||
Phil Cohen
|
r35289 | path = checkunknowndirs(repo, wctx, f) | ||
Mark Thomas
|
r34553 | if path is not None: | ||
pathconflicts.add(path) | ||||
Augie Fackler
|
r45383 | elif m == mergestatemod.ACTION_LOCAL_DIR_RENAME_GET: | ||
Martin von Zweigbergk
|
r23655 | if _checkunknownfile(repo, wctx, mctx, f, args[0]): | ||
Mark Thomas
|
r34552 | fileconflicts.add(f) | ||
Martin von Zweigbergk
|
r23655 | |||
Mark Thomas
|
r34553 | allconflicts = fileconflicts | pathconflicts | ||
Augie Fackler
|
r43346 | ignoredconflicts = {c for c in allconflicts if repo.dirstate._ignore(c)} | ||
Mark Thomas
|
r34552 | unknownconflicts = allconflicts - ignoredconflicts | ||
Siddharth Agarwal
|
r27742 | collectconflicts(ignoredconflicts, ignoredconfig) | ||
collectconflicts(unknownconflicts, unknownconfig) | ||||
Siddharth Agarwal
|
r28022 | else: | ||
Gregory Szorc
|
r43376 | for f, (m, args, msg) in pycompat.iteritems(actions): | ||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_CREATED_MERGE: | ||
Siddharth Agarwal
|
r28022 | fl2, anc = args | ||
different = _checkunknownfile(repo, wctx, mctx, f) | ||||
if repo.dirstate._ignore(f): | ||||
config = ignoredconfig | ||||
else: | ||||
config = unknownconfig | ||||
# The behavior when force is True is described by this table: | ||||
# config different mergeforce | action backup | ||||
# * n * | get n | ||||
# * y y | merge - | ||||
# abort y n | merge - (1) | ||||
# warn y n | warn + get y | ||||
# ignore y n | get y | ||||
# | ||||
# (1) this is probably the wrong behavior here -- we should | ||||
# probably abort, but some actions like rebases currently | ||||
# don't like an abort happening in the middle of | ||||
# merge.update. | ||||
if not different: | ||||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_GET, | ||||
(fl2, False), | ||||
b'remote created', | ||||
) | ||||
Augie Fackler
|
r43347 | elif mergeforce or config == b'abort': | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f, f, None, False, anc), | ||
Augie Fackler
|
r43347 | b'remote differs from untracked local', | ||
Augie Fackler
|
r43346 | ) | ||
Augie Fackler
|
r43347 | elif config == b'abort': | ||
Siddharth Agarwal
|
r28022 | abortconflicts.add(f) | ||
else: | ||||
Augie Fackler
|
r43347 | if config == b'warn': | ||
Siddharth Agarwal
|
r28022 | warnconflicts.add(f) | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_GET, | ||||
(fl2, True), | ||||
b'remote created', | ||||
) | ||||
Siddharth Agarwal
|
r27741 | |||
Siddharth Agarwal
|
r28018 | for f in sorted(abortconflicts): | ||
Mark Thomas
|
r34554 | warn = repo.ui.warn | ||
if f in pathconflicts: | ||||
if repo.wvfs.isfileorlink(f): | ||||
Augie Fackler
|
r43347 | warn(_(b"%s: untracked file conflicts with directory\n") % f) | ||
Mark Thomas
|
r34554 | else: | ||
Augie Fackler
|
r43347 | warn(_(b"%s: untracked directory conflicts with file\n") % f) | ||
Mark Thomas
|
r34554 | else: | ||
Augie Fackler
|
r43347 | warn(_(b"%s: untracked file differs\n") % f) | ||
Siddharth Agarwal
|
r28018 | if abortconflicts: | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
_( | ||||
Augie Fackler
|
r43347 | b"untracked files in working directory " | ||
b"differ from files in requested revision" | ||||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Siddharth Agarwal
|
r28018 | |||
for f in sorted(warnconflicts): | ||||
Mark Thomas
|
r34554 | if repo.wvfs.isfileorlink(f): | ||
Augie Fackler
|
r43347 | repo.ui.warn(_(b"%s: replacing untracked file\n") % f) | ||
Mark Thomas
|
r34554 | else: | ||
Augie Fackler
|
r43347 | repo.ui.warn(_(b"%s: replacing untracked files in directory\n") % f) | ||
Martin von Zweigbergk
|
r23655 | |||
Gregory Szorc
|
r43376 | for f, (m, args, msg) in pycompat.iteritems(actions): | ||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_CREATED: | ||
Augie Fackler
|
r43346 | backup = ( | ||
f in fileconflicts | ||||
or f in pathconflicts | ||||
Martin von Zweigbergk
|
r44032 | or any(p in pathconflicts for p in pathutil.finddirs(f)) | ||
Augie Fackler
|
r43346 | ) | ||
(flags,) = args | ||||
Augie Fackler
|
r45383 | actions[f] = (mergestatemod.ACTION_GET, (flags, backup), msg) | ||
Martin von Zweigbergk
|
r23655 | |||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r6269 | def _forgetremoved(wctx, mctx, branchmerge): | ||
Matt Mackall
|
r3107 | """ | ||
Forget removed files | ||||
If we're jumping between revisions (as opposed to merging), and if | ||||
neither the working directory nor the target rev has the file, | ||||
then we need to remove it from the dirstate, to prevent the | ||||
dirstate from listing the file when it is no longer in the | ||||
manifest. | ||||
Alexis S. L. Carvalho
|
r6242 | |||
If we're merging, and the other revision has removed a file | ||||
that is not present in the working directory, we need to mark it | ||||
as removed. | ||||
Matt Mackall
|
r3107 | """ | ||
Martin von Zweigbergk
|
r23640 | actions = {} | ||
Augie Fackler
|
r45383 | m = mergestatemod.ACTION_FORGET | ||
Mads Kiilerich
|
r21545 | if branchmerge: | ||
Augie Fackler
|
r45383 | m = mergestatemod.ACTION_REMOVE | ||
Alexis S. L. Carvalho
|
r6242 | for f in wctx.deleted(): | ||
Matt Mackall
|
r6272 | if f not in mctx: | ||
Augie Fackler
|
r43347 | actions[f] = m, None, b"forget deleted" | ||
Alexis S. L. Carvalho
|
r6242 | |||
if not branchmerge: | ||||
for f in wctx.removed(): | ||||
Matt Mackall
|
r6272 | if f not in mctx: | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_FORGET, | ||||
None, | ||||
b"forget removed", | ||||
) | ||||
Matt Mackall
|
r3107 | |||
Martin von Zweigbergk
|
r23640 | return actions | ||
Matt Mackall
|
r3107 | |||
Augie Fackler
|
r43346 | |||
Mads Kiilerich
|
r20640 | def _checkcollision(repo, wmf, actions): | ||
Martin von Zweigbergk
|
r38056 | """ | ||
Check for case-folding collisions. | ||||
""" | ||||
# If the repo is narrowed, filter out files outside the narrowspec. | ||||
narrowmatch = repo.narrowmatch() | ||||
if not narrowmatch.always(): | ||||
Augie Fackler
|
r44769 | pmmf = set(wmf.walk(narrowmatch)) | ||
Martin von Zweigbergk
|
r38056 | if actions: | ||
narrowactions = {} | ||||
Gregory Szorc
|
r43376 | for m, actionsfortype in pycompat.iteritems(actions): | ||
Martin von Zweigbergk
|
r38056 | narrowactions[m] = [] | ||
for (f, args, msg) in actionsfortype: | ||||
if narrowmatch(f): | ||||
narrowactions[m].append((f, args, msg)) | ||||
actions = narrowactions | ||||
Augie Fackler
|
r44769 | else: | ||
# build provisional merged manifest up | ||||
pmmf = set(wmf) | ||||
FUJIWARA Katsunori
|
r19105 | |||
Mads Kiilerich
|
r21545 | if actions: | ||
Gregory Szorc
|
r37130 | # KEEP and EXEC are no-op | ||
Augie Fackler
|
r43346 | for m in ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_ADD, | ||
mergestatemod.ACTION_ADD_MODIFIED, | ||||
mergestatemod.ACTION_FORGET, | ||||
mergestatemod.ACTION_GET, | ||||
mergestatemod.ACTION_CHANGED_DELETED, | ||||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
Augie Fackler
|
r43346 | ): | ||
Mads Kiilerich
|
r21545 | for f, args, msg in actions[m]: | ||
pmmf.add(f) | ||||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_REMOVE]: | ||
Mads Kiilerich
|
r21545 | pmmf.discard(f) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL]: | ||
Mads Kiilerich
|
r21545 | f2, flags = args | ||
pmmf.discard(f2) | ||||
pmmf.add(f) | ||||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_LOCAL_DIR_RENAME_GET]: | ||
Mads Kiilerich
|
r21545 | pmmf.add(f) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_MERGE]: | ||
Mads Kiilerich
|
r21545 | f1, f2, fa, move, anc = args | ||
if move: | ||||
pmmf.discard(f1) | ||||
pmmf.add(f) | ||||
FUJIWARA Katsunori
|
r19105 | |||
# check case-folding collision in provisional merged manifest | ||||
foldmap = {} | ||||
Alex Gaynor
|
r33807 | for f in pmmf: | ||
FUJIWARA Katsunori
|
r19105 | fold = util.normcase(f) | ||
if fold in foldmap: | ||||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Augie Fackler
|
r43347 | _(b"case-folding collision between %s and %s") | ||
Augie Fackler
|
r43346 | % (f, foldmap[fold]) | ||
) | ||||
FUJIWARA Katsunori
|
r19105 | foldmap[fold] = f | ||
Mads Kiilerich
|
r26661 | # check case-folding of directories | ||
Augie Fackler
|
r43347 | foldprefix = unfoldprefix = lastfull = b'' | ||
Mads Kiilerich
|
r26661 | for fold, f in sorted(foldmap.items()): | ||
if fold.startswith(foldprefix) and not f.startswith(unfoldprefix): | ||||
# the folded prefix matches but actual casing is different | ||||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Martin von Zweigbergk
|
r43387 | _(b"case-folding collision between %s and directory of %s") | ||
Augie Fackler
|
r43346 | % (lastfull, f) | ||
) | ||||
Augie Fackler
|
r43347 | foldprefix = fold + b'/' | ||
unfoldprefix = f + b'/' | ||||
Mads Kiilerich
|
r26661 | lastfull = f | ||
Augie Fackler
|
r43346 | |||
Siddharth Agarwal
|
r26785 | def driverpreprocess(repo, ms, wctx, labels=None): | ||
"""run the preprocess step of the merge driver, if any | ||||
This is currently not implemented -- it's an extension point.""" | ||||
return True | ||||
Augie Fackler
|
r43346 | |||
Siddharth Agarwal
|
r26785 | def driverconclude(repo, ms, wctx, labels=None): | ||
"""run the conclude step of the merge driver, if any | ||||
This is currently not implemented -- it's an extension point.""" | ||||
return True | ||||
Augie Fackler
|
r43346 | |||
Mark Thomas
|
r34556 | def _filesindirs(repo, manifest, dirs): | ||
""" | ||||
Generator that yields pairs of all the files in the manifest that are found | ||||
inside the directories listed in dirs, and which directory they are found | ||||
in. | ||||
""" | ||||
for f in manifest: | ||||
Martin von Zweigbergk
|
r44032 | for p in pathutil.finddirs(f): | ||
Mark Thomas
|
r34556 | if p in dirs: | ||
yield f, p | ||||
break | ||||
Augie Fackler
|
r43346 | |||
Mark Thomas
|
r34556 | def checkpathconflicts(repo, wctx, mctx, actions): | ||
""" | ||||
Check if any actions introduce path conflicts in the repository, updating | ||||
actions to record or handle the path conflict accordingly. | ||||
""" | ||||
mf = wctx.manifest() | ||||
# The set of local files that conflict with a remote directory. | ||||
localconflicts = set() | ||||
# The set of directories that conflict with a remote file, and so may cause | ||||
# conflicts if they still contain any files after the merge. | ||||
remoteconflicts = set() | ||||
# The set of directories that appear as both a file and a directory in the | ||||
# remote manifest. These indicate an invalid remote manifest, which | ||||
# can't be updated to cleanly. | ||||
invalidconflicts = set() | ||||
Mark Thomas
|
r35182 | # The set of directories that contain files that are being created. | ||
createdfiledirs = set() | ||||
Mark Thomas
|
r34556 | # The set of files deleted by all the actions. | ||
deletedfiles = set() | ||||
for f, (m, args, msg) in actions.items(): | ||||
Augie Fackler
|
r43346 | if m in ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_CREATED, | ||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
mergestatemod.ACTION_MERGE, | ||||
mergestatemod.ACTION_CREATED_MERGE, | ||||
Augie Fackler
|
r43346 | ): | ||
Mark Thomas
|
r34556 | # This action may create a new local file. | ||
Martin von Zweigbergk
|
r44032 | createdfiledirs.update(pathutil.finddirs(f)) | ||
Mark Thomas
|
r34556 | if mf.hasdir(f): | ||
# The file aliases a local directory. This might be ok if all | ||||
# the files in the local directory are being deleted. This | ||||
# will be checked once we know what all the deleted files are. | ||||
remoteconflicts.add(f) | ||||
# Track the names of all deleted files. | ||||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_REMOVE: | ||
Mark Thomas
|
r34556 | deletedfiles.add(f) | ||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_MERGE: | ||
Mark Thomas
|
r34556 | f1, f2, fa, move, anc = args | ||
if move: | ||||
deletedfiles.add(f1) | ||||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL: | ||
Mark Thomas
|
r34556 | f2, flags = args | ||
deletedfiles.add(f2) | ||||
Mark Thomas
|
r35182 | # Check all directories that contain created files for path conflicts. | ||
for p in createdfiledirs: | ||||
if p in mf: | ||||
if p in mctx: | ||||
# A file is in a directory which aliases both a local | ||||
# and a remote file. This is an internal inconsistency | ||||
# within the remote manifest. | ||||
invalidconflicts.add(p) | ||||
else: | ||||
# A file is in a directory which aliases a local file. | ||||
# We will need to rename the local file. | ||||
localconflicts.add(p) | ||||
Augie Fackler
|
r43346 | if p in actions and actions[p][0] in ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_CREATED, | ||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
mergestatemod.ACTION_MERGE, | ||||
mergestatemod.ACTION_CREATED_MERGE, | ||||
Augie Fackler
|
r43346 | ): | ||
Mark Thomas
|
r35182 | # The file is in a directory which aliases a remote file. | ||
# This is an internal inconsistency within the remote | ||||
# manifest. | ||||
invalidconflicts.add(p) | ||||
Mark Thomas
|
r34556 | # Rename all local conflicting files that have not been deleted. | ||
for p in localconflicts: | ||||
if p not in deletedfiles: | ||||
Augie Fackler
|
r43347 | ctxname = bytes(wctx).rstrip(b'+') | ||
Mark Thomas
|
r34556 | pnew = util.safename(p, ctxname, wctx, set(actions.keys())) | ||
Martin von Zweigbergk
|
r45465 | porig = wctx[p].copysource() or p | ||
Augie Fackler
|
r43346 | actions[pnew] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_PATH_CONFLICT_RESOLVE, | ||
Martin von Zweigbergk
|
r45465 | (p, porig), | ||
Augie Fackler
|
r43347 | b'local path conflict', | ||
Augie Fackler
|
r43346 | ) | ||
Augie Fackler
|
r45383 | actions[p] = ( | ||
mergestatemod.ACTION_PATH_CONFLICT, | ||||
(pnew, b'l'), | ||||
b'path conflict', | ||||
) | ||||
Mark Thomas
|
r34556 | |||
if remoteconflicts: | ||||
# Check if all files in the conflicting directories have been removed. | ||||
Augie Fackler
|
r43347 | ctxname = bytes(mctx).rstrip(b'+') | ||
Mark Thomas
|
r34556 | for f, p in _filesindirs(repo, mf, remoteconflicts): | ||
if f not in deletedfiles: | ||||
m, args, msg = actions[p] | ||||
pnew = util.safename(p, ctxname, wctx, set(actions.keys())) | ||||
Augie Fackler
|
r45383 | if m in ( | ||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
mergestatemod.ACTION_MERGE, | ||||
): | ||||
Mark Thomas
|
r34556 | # Action was merge, just update target. | ||
actions[pnew] = (m, args, msg) | ||||
else: | ||||
# Action was create, change to renamed get action. | ||||
fl = args[0] | ||||
Augie Fackler
|
r43346 | actions[pnew] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_LOCAL_DIR_RENAME_GET, | ||
Augie Fackler
|
r43346 | (p, fl), | ||
Augie Fackler
|
r43347 | b'remote path conflict', | ||
Augie Fackler
|
r43346 | ) | ||
actions[p] = ( | ||||
Augie Fackler
|
r45383 | mergestatemod.ACTION_PATH_CONFLICT, | ||
(pnew, mergestatemod.ACTION_REMOVE), | ||||
Augie Fackler
|
r43347 | b'path conflict', | ||
Augie Fackler
|
r43346 | ) | ||
Mark Thomas
|
r34556 | remoteconflicts.remove(p) | ||
break | ||||
if invalidconflicts: | ||||
for p in invalidconflicts: | ||||
Augie Fackler
|
r43347 | repo.ui.warn(_(b"%s: is both a file and a directory\n") % p) | ||
raise error.Abort(_(b"destination manifest contains path conflicts")) | ||||
Mark Thomas
|
r34556 | |||
Augie Fackler
|
r43346 | |||
Martin von Zweigbergk
|
r38055 | def _filternarrowactions(narrowmatch, branchmerge, actions): | ||
""" | ||||
Filters out actions that can ignored because the repo is narrowed. | ||||
Raise an exception if the merge cannot be completed because the repo is | ||||
narrowed. | ||||
""" | ||||
Augie Fackler
|
r43347 | nooptypes = {b'k'} # TODO: handle with nonconflicttypes | ||
Pulkit Goyal
|
r45178 | nonconflicttypes = set(b'a am c cm f g gs r e'.split()) | ||
Martin von Zweigbergk
|
r38055 | # We mutate the items in the dict during iteration, so iterate | ||
# over a copy. | ||||
for f, action in list(actions.items()): | ||||
if narrowmatch(f): | ||||
pass | ||||
elif not branchmerge: | ||||
Augie Fackler
|
r43346 | del actions[f] # just updating, ignore changes outside clone | ||
Martin von Zweigbergk
|
r38055 | elif action[0] in nooptypes: | ||
Augie Fackler
|
r43346 | del actions[f] # merge does not affect file | ||
Martin von Zweigbergk
|
r38055 | elif action[0] in nonconflicttypes: | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
_( | ||||
Augie Fackler
|
r43347 | b'merge affects file \'%s\' outside narrow, ' | ||
b'which is not yet supported' | ||||
Augie Fackler
|
r43346 | ) | ||
% f, | ||||
Martin von Zweigbergk
|
r43387 | hint=_(b'merging in the other direction may work'), | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r38055 | else: | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Martin von Zweigbergk
|
r43387 | _(b'conflict in file \'%s\' is outside narrow clone') % f | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r38055 | |||
Augie Fackler
|
r43346 | def manifestmerge( | ||
repo, | ||||
wctx, | ||||
p2, | ||||
pa, | ||||
branchmerge, | ||||
force, | ||||
matcher, | ||||
acceptremote, | ||||
followcopies, | ||||
forcefulldiff=False, | ||||
): | ||||
Matt Mackall
|
r3105 | """ | ||
Yuya Nishihara
|
r30096 | Merge wctx and p2 with ancestor pa and generate merge action list | ||
Matt Mackall
|
r3315 | |||
Siddharth Agarwal
|
r18605 | branchmerge and force are as passed in to update | ||
Augie Fackler
|
r27346 | matcher = matcher to filter file lists | ||
Durham Goode
|
r18778 | acceptremote = accept the incoming changes without prompting | ||
Pulkit Goyal
|
r45728 | |||
Returns: | ||||
actions: dict of filename as keys and action related info as values | ||||
diverge: mapping of source name -> list of dest name for divergent renames | ||||
renamedelete: mapping of source name -> list of destinations for files | ||||
deleted on one side and renamed on other. | ||||
Matt Mackall
|
r3105 | """ | ||
Augie Fackler
|
r27346 | if matcher is not None and matcher.always(): | ||
matcher = None | ||||
Matt Mackall
|
r3105 | |||
Siddharth Agarwal
|
r18651 | # manifests fetched in order are going to be faster, so prime the caches | ||
Augie Fackler
|
r43346 | [ | ||
x.manifest() | ||||
for x in sorted(wctx.parents() + [p2, pa], key=scmutil.intrev) | ||||
] | ||||
Siddharth Agarwal
|
r18651 | |||
Martin von Zweigbergk
|
r44682 | branch_copies1 = copies.branch_copies() | ||
branch_copies2 = copies.branch_copies() | ||||
diverge = {} | ||||
Siddharth Agarwal
|
r18651 | if followcopies: | ||
Martin von Zweigbergk
|
r44682 | branch_copies1, branch_copies2, diverge = copies.mergecopies( | ||
repo, wctx, p2, pa | ||||
) | ||||
Matt Mackall
|
r8753 | |||
Pulkit Goyal
|
r32641 | boolbm = pycompat.bytestr(bool(branchmerge)) | ||
boolf = pycompat.bytestr(bool(force)) | ||||
boolm = pycompat.bytestr(bool(matcher)) | ||||
Augie Fackler
|
r43347 | repo.ui.note(_(b"resolving manifests\n")) | ||
Augie Fackler
|
r43346 | repo.ui.debug( | ||
Augie Fackler
|
r43347 | b" branchmerge: %s, force: %s, partial: %s\n" % (boolbm, boolf, boolm) | ||
Augie Fackler
|
r43346 | ) | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" ancestor: %s, local: %s, remote: %s\n" % (pa, wctx, p2)) | ||
Matt Mackall
|
r8753 | |||
Bryan O'Sullivan
|
r18611 | m1, m2, ma = wctx.manifest(), p2.manifest(), pa.manifest() | ||
Martin von Zweigbergk
|
r44682 | copied1 = set(branch_copies1.copy.values()) | ||
copied1.update(branch_copies1.movewithdir.values()) | ||||
copied2 = set(branch_copies2.copy.values()) | ||||
copied2.update(branch_copies2.movewithdir.values()) | ||||
Matt Mackall
|
r3295 | |||
Augie Fackler
|
r43347 | if b'.hgsubstate' in m1 and wctx.rev() is None: | ||
Yuya Nishihara
|
r38444 | # Check whether sub state is modified, and overwrite the manifest | ||
# to flag the change. If wctx is a committed revision, we shouldn't | ||||
# care for the dirty state of the working directory. | ||||
Martin von Zweigbergk
|
r28226 | if any(wctx.sub(s).dirty() for s in wctx.substate): | ||
Augie Fackler
|
r43347 | m1[b'.hgsubstate'] = modifiednodeid | ||
Matt Mackall
|
r9783 | |||
Durham Goode
|
r32151 | # Don't use m2-vs-ma optimization if: | ||
# - ma is the same as m1 or m2, which we're just going to diff again later | ||||
# - The caller specifically asks for a full diff, which is useful during bid | ||||
# merge. | ||||
Augie Fackler
|
r43346 | if pa not in ([wctx, p2] + wctx.parents()) and not forcefulldiff: | ||
Durham Goode
|
r32151 | # Identify which files are relevant to the merge, so we can limit the | ||
# total m1-vs-m2 diff to just those files. This has significant | ||||
# performance benefits in large repositories. | ||||
relevantfiles = set(ma.diff(m2).keys()) | ||||
# For copied and moved files, we need to add the source file too. | ||||
Martin von Zweigbergk
|
r44682 | for copykey, copyvalue in pycompat.iteritems(branch_copies1.copy): | ||
Durham Goode
|
r32151 | if copyvalue in relevantfiles: | ||
relevantfiles.add(copykey) | ||||
Martin von Zweigbergk
|
r44682 | for movedirkey in branch_copies1.movewithdir: | ||
Durham Goode
|
r32151 | relevantfiles.add(movedirkey) | ||
Martin von Zweigbergk
|
r32498 | filesmatcher = scmutil.matchfiles(repo, relevantfiles) | ||
matcher = matchmod.intersectmatchers(matcher, filesmatcher) | ||||
Durham Goode
|
r32151 | |||
Durham Goode
|
r31257 | diff = m1.diff(m2, match=matcher) | ||
Martin von Zweigbergk
|
r23637 | actions = {} | ||
Gregory Szorc
|
r43376 | for f, ((n1, fl1), (n2, fl2)) in pycompat.iteritems(diff): | ||
Augie Fackler
|
r43346 | if n1 and n2: # file exists on both local and remote side | ||
Martin von Zweigbergk
|
r23396 | if f not in ma: | ||
Martin von Zweigbergk
|
r44682 | # TODO: what if they're renamed from different sources? | ||
fa = branch_copies1.copy.get( | ||||
f, None | ||||
) or branch_copies2.copy.get(f, None) | ||||
Martin von Zweigbergk
|
r23397 | if fa is not None: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f, f, fa, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'both renamed from %s' % fa, | ||
Augie Fackler
|
r43346 | ) | ||
Mads Kiilerich
|
r18338 | else: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f, f, None, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'both created', | ||
Augie Fackler
|
r43346 | ) | ||
Matt Mackall
|
r16094 | else: | ||
Martin von Zweigbergk
|
r23396 | a = ma[f] | ||
fla = ma.flags(f) | ||||
Augie Fackler
|
r43347 | nol = b'l' not in fl1 + fl2 + fla | ||
Martin von Zweigbergk
|
r23395 | if n2 == a and fl2 == fla: | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_KEEP, | ||||
(), | ||||
b'remote unchanged', | ||||
) | ||||
Augie Fackler
|
r43346 | elif n1 == a and fl1 == fla: # local unchanged - use remote | ||
if n1 == n2: # optimization: keep local content | ||||
Augie Fackler
|
r43347 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_EXEC, | ||
Augie Fackler
|
r43347 | (fl2,), | ||
b'update permissions', | ||||
) | ||||
Martin von Zweigbergk
|
r23395 | else: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_GET_OTHER_AND_STORE | ||
Pulkit Goyal
|
r45178 | if branchmerge | ||
Augie Fackler
|
r45383 | else mergestatemod.ACTION_GET, | ||
Augie Fackler
|
r43346 | (fl2, False), | ||
Augie Fackler
|
r43347 | b'remote is newer', | ||
Augie Fackler
|
r43346 | ) | ||
elif nol and n2 == a: # remote only changed 'x' | ||||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_EXEC, | ||||
(fl2,), | ||||
b'update permissions', | ||||
) | ||||
Augie Fackler
|
r43346 | elif nol and n1 == a: # local only changed 'x' | ||
Pulkit Goyal
|
r45178 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_GET_OTHER_AND_STORE | ||
Pulkit Goyal
|
r45178 | if branchmerge | ||
Augie Fackler
|
r45383 | else mergestatemod.ACTION_GET, | ||
Pulkit Goyal
|
r45178 | (fl1, False), | ||
b'remote is newer', | ||||
) | ||||
Augie Fackler
|
r43346 | else: # both changed something | ||
actions[f] = ( | ||||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f, f, f, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'versions differ', | ||
Augie Fackler
|
r43346 | ) | ||
elif n1: # file exists only on local side | ||||
Martin von Zweigbergk
|
r44682 | if f in copied2: | ||
Augie Fackler
|
r43346 | pass # we'll deal with it on m2 side | ||
Martin von Zweigbergk
|
r44682 | elif ( | ||
f in branch_copies1.movewithdir | ||||
): # directory rename, move local | ||||
f2 = branch_copies1.movewithdir[f] | ||||
Durham Goode
|
r31515 | if f2 in m2: | ||
Augie Fackler
|
r43346 | actions[f2] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f, f2, None, True, pa.node()), | ||
Augie Fackler
|
r43347 | b'remote directory rename, both created', | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23475 | else: | ||
Augie Fackler
|
r43346 | actions[f2] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL, | ||
Augie Fackler
|
r43346 | (f, fl1), | ||
Augie Fackler
|
r43347 | b'remote directory rename - move from %s' % f, | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r44682 | elif f in branch_copies1.copy: | ||
f2 = branch_copies1.copy[f] | ||||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f, f2, f2, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'local copied/moved from %s' % f2, | ||
Augie Fackler
|
r43346 | ) | ||
elif f in ma: # clean, a different, no remote | ||||
Martin von Zweigbergk
|
r23473 | if n1 != ma[f]: | ||
if acceptremote: | ||||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_REMOVE, | ||||
None, | ||||
b'remote delete', | ||||
) | ||||
Martin von Zweigbergk
|
r23473 | else: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_CHANGED_DELETED, | ||
Augie Fackler
|
r43346 | (f, None, f, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'prompt changed/deleted', | ||
Augie Fackler
|
r43346 | ) | ||
Durham Goode
|
r30361 | elif n1 == addednodeid: | ||
Joerg Sonnenberger
|
r45678 | # This file was locally added. We should forget it instead of | ||
Martin von Zweigbergk
|
r23473 | # deleting it. | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_FORGET, | ||||
None, | ||||
b'remote deleted', | ||||
) | ||||
Mads Kiilerich
|
r20639 | else: | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_REMOVE, | ||||
None, | ||||
b'other deleted', | ||||
) | ||||
Augie Fackler
|
r43346 | elif n2: # file exists only on remote side | ||
Martin von Zweigbergk
|
r44682 | if f in copied1: | ||
Augie Fackler
|
r43346 | pass # we'll deal with it on m1 side | ||
Martin von Zweigbergk
|
r44682 | elif f in branch_copies2.movewithdir: | ||
f2 = branch_copies2.movewithdir[f] | ||||
Durham Goode
|
r31515 | if f2 in m1: | ||
Augie Fackler
|
r43346 | actions[f2] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f2, f, None, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'local directory rename, both created', | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23476 | else: | ||
Augie Fackler
|
r43346 | actions[f2] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_LOCAL_DIR_RENAME_GET, | ||
Augie Fackler
|
r43346 | (f, fl2), | ||
Augie Fackler
|
r43347 | b'local directory rename - get from %s' % f, | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r44682 | elif f in branch_copies2.copy: | ||
f2 = branch_copies2.copy[f] | ||||
Durham Goode
|
r31515 | if f2 in m2: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f2, f, f2, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'remote copied from %s' % f2, | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23473 | else: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (f2, f, f2, True, pa.node()), | ||
Augie Fackler
|
r43347 | b'remote moved from %s' % f2, | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23473 | elif f not in ma: | ||
# local unknown, remote created: the logic is described by the | ||||
# following table: | ||||
# | ||||
# force branchmerge different | action | ||||
Martin von Zweigbergk
|
r23651 | # n * * | create | ||
Martin von Zweigbergk
|
r23650 | # y n * | create | ||
# y y n | create | ||||
Martin von Zweigbergk
|
r23473 | # y y y | merge | ||
# | ||||
# Checking whether the files are different is expensive, so we | ||||
# don't do that when we can avoid it. | ||||
Martin von Zweigbergk
|
r23649 | if not force: | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_CREATED, | ||||
(fl2,), | ||||
b'remote created', | ||||
) | ||||
Martin von Zweigbergk
|
r23649 | elif not branchmerge: | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_CREATED, | ||||
(fl2,), | ||||
b'remote created', | ||||
) | ||||
Martin von Zweigbergk
|
r23473 | else: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_CREATED_MERGE, | ||
Augie Fackler
|
r43346 | (fl2, pa.node()), | ||
Augie Fackler
|
r43347 | b'remote created, get or merge', | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23473 | elif n2 != ma[f]: | ||
Gábor Stefanik
|
r30581 | df = None | ||
Martin von Zweigbergk
|
r44682 | for d in branch_copies1.dirmove: | ||
Gábor Stefanik
|
r30581 | if f.startswith(d): | ||
# new file added in a directory that was moved | ||||
Martin von Zweigbergk
|
r44682 | df = branch_copies1.dirmove[d] + f[len(d) :] | ||
Gábor Stefanik
|
r30581 | break | ||
Durham Goode
|
r31515 | if df is not None and df in m1: | ||
Augie Fackler
|
r43346 | actions[df] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_MERGE, | ||
Augie Fackler
|
r43346 | (df, f, f, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'local directory rename - respect move ' | ||
b'from %s' % f, | ||||
Augie Fackler
|
r43346 | ) | ||
Gábor Stefanik
|
r30581 | elif acceptremote: | ||
Augie Fackler
|
r45383 | actions[f] = ( | ||
mergestatemod.ACTION_CREATED, | ||||
(fl2,), | ||||
b'remote recreating', | ||||
) | ||||
Siddharth Agarwal
|
r18606 | else: | ||
Augie Fackler
|
r43346 | actions[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_DELETED_CHANGED, | ||
Augie Fackler
|
r43346 | (None, f, f, False, pa.node()), | ||
Augie Fackler
|
r43347 | b'prompt deleted/changed', | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23651 | |||
Augie Fackler
|
r43347 | if repo.ui.configbool(b'experimental', b'merge.checkpathconflicts'): | ||
Siddharth Agarwal
|
r34942 | # If we are merging, look for path conflicts. | ||
checkpathconflicts(repo, wctx, p2, actions) | ||||
Mark Thomas
|
r34556 | |||
Martin von Zweigbergk
|
r38055 | narrowmatch = repo.narrowmatch() | ||
if not narrowmatch.always(): | ||||
# Updates "actions" in place | ||||
_filternarrowactions(narrowmatch, branchmerge, actions) | ||||
Martin von Zweigbergk
|
r44682 | renamedelete = branch_copies1.renamedelete | ||
renamedelete.update(branch_copies2.renamedelete) | ||||
Martin von Zweigbergk
|
r23526 | return actions, diverge, renamedelete | ||
Matt Mackall
|
r3105 | |||
Augie Fackler
|
r43346 | |||
Martin von Zweigbergk
|
r23531 | def _resolvetrivial(repo, wctx, mctx, ancestor, actions): | ||
"""Resolves false conflicts where the nodeid changed but the content | ||||
remained the same.""" | ||||
Augie Fackler
|
r36334 | # We force a copy of actions.items() because we're going to mutate | ||
# actions as we resolve trivial conflicts. | ||||
for f, (m, args, msg) in list(actions.items()): | ||||
Augie Fackler
|
r43346 | if ( | ||
Augie Fackler
|
r45383 | m == mergestatemod.ACTION_CHANGED_DELETED | ||
Augie Fackler
|
r43346 | and f in ancestor | ||
and not wctx[f].cmp(ancestor[f]) | ||||
): | ||||
Martin von Zweigbergk
|
r23531 | # local did change but ended up with same content | ||
Augie Fackler
|
r45383 | actions[f] = mergestatemod.ACTION_REMOVE, None, b'prompt same' | ||
Augie Fackler
|
r43346 | elif ( | ||
Augie Fackler
|
r45383 | m == mergestatemod.ACTION_DELETED_CHANGED | ||
Augie Fackler
|
r43346 | and f in ancestor | ||
and not mctx[f].cmp(ancestor[f]) | ||||
): | ||||
Martin von Zweigbergk
|
r23531 | # remote did change but ended up with same content | ||
Augie Fackler
|
r43346 | del actions[f] # don't get = keep local deleted | ||
Martin von Zweigbergk
|
r23531 | |||
Augie Fackler
|
r43346 | def calculateupdates( | ||
repo, | ||||
wctx, | ||||
mctx, | ||||
ancestors, | ||||
branchmerge, | ||||
force, | ||||
acceptremote, | ||||
followcopies, | ||||
matcher=None, | ||||
mergeforce=False, | ||||
): | ||||
Pulkit Goyal
|
r45728 | """ | ||
Calculate the actions needed to merge mctx into wctx using ancestors | ||||
Uses manifestmerge() to merge manifest and get list of actions required to | ||||
perform for merging two manifests. If there are multiple ancestors, uses bid | ||||
merge if enabled. | ||||
Also filters out actions which are unrequired if repository is sparse. | ||||
Returns same 3 element tuple as manifestmerge(). | ||||
""" | ||||
Gregory Szorc
|
r33323 | # Avoid cycle. | ||
from . import sparse | ||||
Augie Fackler
|
r43346 | if len(ancestors) == 1: # default | ||
Martin von Zweigbergk
|
r23526 | actions, diverge, renamedelete = manifestmerge( | ||
Augie Fackler
|
r43346 | repo, | ||
wctx, | ||||
mctx, | ||||
ancestors[0], | ||||
branchmerge, | ||||
force, | ||||
matcher, | ||||
acceptremote, | ||||
followcopies, | ||||
) | ||||
Siddharth Agarwal
|
r28020 | _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) | ||
Martin von Zweigbergk
|
r23385 | |||
Augie Fackler
|
r43346 | else: # only when merge.preferancestor=* - the default | ||
Martin von Zweigbergk
|
r23385 | repo.ui.note( | ||
Augie Fackler
|
r43347 | _(b"note: merging %s and %s using bids from ancestors %s\n") | ||
Augie Fackler
|
r43346 | % ( | ||
wctx, | ||||
mctx, | ||||
Augie Fackler
|
r43347 | _(b' and ').join(pycompat.bytestr(anc) for anc in ancestors), | ||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Martin von Zweigbergk
|
r23385 | |||
# Call for bids | ||||
Augie Fackler
|
r43346 | fbids = ( | ||
{} | ||||
) # mapping filename to bids (action method to list af actions) | ||||
Martin von Zweigbergk
|
r23526 | diverge, renamedelete = None, None | ||
Martin von Zweigbergk
|
r23385 | for ancestor in ancestors: | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b'\ncalculating bids for ancestor %s\n') % ancestor) | ||
Martin von Zweigbergk
|
r23526 | actions, diverge1, renamedelete1 = manifestmerge( | ||
Augie Fackler
|
r43346 | repo, | ||
wctx, | ||||
mctx, | ||||
ancestor, | ||||
branchmerge, | ||||
force, | ||||
matcher, | ||||
acceptremote, | ||||
followcopies, | ||||
forcefulldiff=True, | ||||
) | ||||
Siddharth Agarwal
|
r28020 | _checkunknownfiles(repo, wctx, mctx, force, actions, mergeforce) | ||
Matt Mackall
|
r26318 | |||
# Track the shortest set of warning on the theory that bid | ||||
# merge will correctly incorporate more information | ||||
if diverge is None or len(diverge1) < len(diverge): | ||||
Martin von Zweigbergk
|
r23526 | diverge = diverge1 | ||
Matt Mackall
|
r26318 | if renamedelete is None or len(renamedelete) < len(renamedelete1): | ||
Martin von Zweigbergk
|
r23526 | renamedelete = renamedelete1 | ||
Matt Mackall
|
r26318 | |||
Gregory Szorc
|
r43376 | for f, a in sorted(pycompat.iteritems(actions)): | ||
Martin von Zweigbergk
|
r23638 | m, args, msg = a | ||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_GET_OTHER_AND_STORE: | ||
m = mergestatemod.ACTION_GET | ||||
Augie Fackler
|
r43347 | repo.ui.debug(b' %s: %s -> %s\n' % (f, msg, m)) | ||
Martin von Zweigbergk
|
r23638 | if f in fbids: | ||
d = fbids[f] | ||||
if m in d: | ||||
d[m].append(a) | ||||
Martin von Zweigbergk
|
r23385 | else: | ||
Martin von Zweigbergk
|
r23638 | d[m] = [a] | ||
else: | ||||
fbids[f] = {m: [a]} | ||||
Martin von Zweigbergk
|
r23385 | |||
# Pick the best bid for each file | ||||
Augie Fackler
|
r43347 | repo.ui.note(_(b'\nauction for merging merge bids\n')) | ||
Martin von Zweigbergk
|
r23638 | actions = {} | ||
Martin von Zweigbergk
|
r23385 | for f, bids in sorted(fbids.items()): | ||
# bids is a mapping from action method to list af actions | ||||
# Consensus? | ||||
Augie Fackler
|
r43346 | if len(bids) == 1: # all bids are the same kind of method | ||
Pulkit Goyal
|
r34350 | m, l = list(bids.items())[0] | ||
Augie Fackler
|
r43346 | if all(a == l[0] for a in l[1:]): # len(bids) is > 1 | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b" %s: consensus for %s\n") % (f, m)) | ||
Martin von Zweigbergk
|
r23638 | actions[f] = l[0] | ||
Martin von Zweigbergk
|
r23385 | continue | ||
# If keep is an option, just do it. | ||||
Augie Fackler
|
r45383 | if mergestatemod.ACTION_KEEP in bids: | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b" %s: picking 'keep' action\n") % f) | ||
Augie Fackler
|
r45383 | actions[f] = bids[mergestatemod.ACTION_KEEP][0] | ||
Martin von Zweigbergk
|
r23385 | continue | ||
# If there are gets and they all agree [how could they not?], do it. | ||||
Augie Fackler
|
r45383 | if mergestatemod.ACTION_GET in bids: | ||
ga0 = bids[mergestatemod.ACTION_GET][0] | ||||
if all(a == ga0 for a in bids[mergestatemod.ACTION_GET][1:]): | ||||
Augie Fackler
|
r43347 | repo.ui.note(_(b" %s: picking 'get' action\n") % f) | ||
Martin von Zweigbergk
|
r23638 | actions[f] = ga0 | ||
Martin von Zweigbergk
|
r23385 | continue | ||
# TODO: Consider other simple actions such as mode changes | ||||
# Handle inefficient democrazy. | ||||
Augie Fackler
|
r43347 | repo.ui.note(_(b' %s: multiple bids for merge action:\n') % f) | ||
Martin von Zweigbergk
|
r23385 | for m, l in sorted(bids.items()): | ||
for _f, args, msg in l: | ||||
Augie Fackler
|
r43347 | repo.ui.note(b' %s -> %s\n' % (msg, m)) | ||
Martin von Zweigbergk
|
r23385 | # Pick random action. TODO: Instead, prompt user when resolving | ||
Pulkit Goyal
|
r34350 | m, l = list(bids.items())[0] | ||
Augie Fackler
|
r43346 | repo.ui.warn( | ||
Augie Fackler
|
r43347 | _(b' %s: ambiguous merge - picked %s action\n') % (f, m) | ||
Augie Fackler
|
r43346 | ) | ||
Martin von Zweigbergk
|
r23638 | actions[f] = l[0] | ||
Martin von Zweigbergk
|
r23385 | continue | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b'end of auction\n\n')) | ||
Martin von Zweigbergk
|
r23385 | |||
Martin von Zweigbergk
|
r23640 | if wctx.rev() is None: | ||
fractions = _forgetremoved(wctx, mctx, branchmerge) | ||||
actions.update(fractions) | ||||
Augie Fackler
|
r43346 | prunedactions = sparse.filterupdatesactions( | ||
repo, wctx, mctx, branchmerge, actions | ||||
) | ||||
Pulkit Goyal
|
r38780 | _resolvetrivial(repo, wctx, mctx, ancestors[0], actions) | ||
Gregory Szorc
|
r33323 | |||
return prunedactions, diverge, renamedelete | ||||
Martin von Zweigbergk
|
r23385 | |||
Augie Fackler
|
r43346 | |||
Phil Cohen
|
r34144 | def _getcwd(): | ||
try: | ||||
Matt Harbison
|
r39843 | return encoding.getcwd() | ||
Phil Cohen
|
r34144 | except OSError as err: | ||
if err.errno == errno.ENOENT: | ||||
return None | ||||
raise | ||||
Augie Fackler
|
r43346 | |||
Phil Cohen
|
r33081 | def batchremove(repo, wctx, actions): | ||
Mads Kiilerich
|
r21392 | """apply removes to the working directory | ||
Bryan O'Sullivan
|
r18630 | |||
yields tuples for progress updates | ||||
""" | ||||
Bryan O'Sullivan
|
r18640 | verbose = repo.ui.verbose | ||
Phil Cohen
|
r34144 | cwd = _getcwd() | ||
Bryan O'Sullivan
|
r18633 | i = 0 | ||
Mads Kiilerich
|
r21545 | for f, args, msg in actions: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> r\n" % (f, msg)) | ||
Mads Kiilerich
|
r21551 | if verbose: | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b"removing %s\n") % f) | ||
Phil Cohen
|
r33086 | wctx[f].audit() | ||
Mads Kiilerich
|
r21551 | try: | ||
Phil Cohen
|
r33082 | wctx[f].remove(ignoremissing=True) | ||
Gregory Szorc
|
r25660 | except OSError as inst: | ||
Augie Fackler
|
r43346 | repo.ui.warn( | ||
Augie Fackler
|
r43347 | _(b"update failed to remove %s: %s!\n") % (f, inst.strerror) | ||
Augie Fackler
|
r43346 | ) | ||
Mads Kiilerich
|
r21392 | if i == 100: | ||
yield i, f | ||||
i = 0 | ||||
i += 1 | ||||
if i > 0: | ||||
yield i, f | ||||
Phil Cohen
|
r34144 | |||
if cwd and not _getcwd(): | ||||
# cwd was removed in the course of removing files; print a helpful | ||||
# warning. | ||||
Augie Fackler
|
r43346 | repo.ui.warn( | ||
_( | ||||
Augie Fackler
|
r43347 | b"current directory was removed\n" | ||
b"(consider changing to repo root: %s)\n" | ||||
Augie Fackler
|
r43346 | ) | ||
% repo.root | ||||
) | ||||
Mads Kiilerich
|
r21392 | |||
Valentin Gatien-Baron
|
r42656 | def batchget(repo, mctx, wctx, wantfiledata, actions): | ||
Mads Kiilerich
|
r21392 | """apply gets to the working directory | ||
mctx is the context to get from | ||||
Valentin Gatien-Baron
|
r42656 | Yields arbitrarily many (False, tuple) for progress updates, followed by | ||
exactly one (True, filedata). When wantfiledata is false, filedata is an | ||||
Valentin Gatien-Baron
|
r42722 | empty dict. When wantfiledata is true, filedata[f] is a triple (mode, size, | ||
mtime) of the file f written for each action. | ||||
Mads Kiilerich
|
r21392 | """ | ||
Valentin Gatien-Baron
|
r42722 | filedata = {} | ||
Mads Kiilerich
|
r21392 | verbose = repo.ui.verbose | ||
fctx = mctx.filectx | ||||
Siddharth Agarwal
|
r27656 | ui = repo.ui | ||
Mads Kiilerich
|
r21392 | i = 0 | ||
Gregory Szorc
|
r28200 | with repo.wvfs.backgroundclosing(ui, expectedcount=len(actions)): | ||
Gregory Szorc
|
r28199 | for f, (flags, backup), msg in actions: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> g\n" % (f, msg)) | ||
Gregory Szorc
|
r28199 | if verbose: | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b"getting %s\n") % f) | ||
Siddharth Agarwal
|
r27656 | |||
Gregory Szorc
|
r28199 | if backup: | ||
Mark Thomas
|
r34550 | # If a file or directory exists with the same name, back that | ||
# up. Otherwise, look to see if there is a file that conflicts | ||||
# with a directory this file is in, and if so, back that up. | ||||
Martin von Zweigbergk
|
r41711 | conflicting = f | ||
Mark Thomas
|
r34550 | if not repo.wvfs.lexists(f): | ||
Martin von Zweigbergk
|
r44032 | for p in pathutil.finddirs(f): | ||
Mark Thomas
|
r34550 | if repo.wvfs.isfileorlink(p): | ||
Martin von Zweigbergk
|
r41711 | conflicting = p | ||
Mark Thomas
|
r34550 | break | ||
Martin von Zweigbergk
|
r41711 | if repo.wvfs.lexists(conflicting): | ||
Martin von Zweigbergk
|
r41750 | orig = scmutil.backuppath(ui, repo, conflicting) | ||
util.rename(repo.wjoin(conflicting), orig) | ||||
Valentin Gatien-Baron
|
r42656 | wfctx = wctx[f] | ||
wfctx.clearunknown() | ||||
Augie Fackler
|
r43347 | atomictemp = ui.configbool(b"experimental", b"update.atomic-file") | ||
Augie Fackler
|
r43346 | size = wfctx.write( | ||
fctx(f).data(), | ||||
flags, | ||||
backgroundclose=True, | ||||
atomictemp=atomictemp, | ||||
) | ||||
Valentin Gatien-Baron
|
r42656 | if wantfiledata: | ||
s = wfctx.lstat() | ||||
mode = s.st_mode | ||||
mtime = s[stat.ST_MTIME] | ||||
Augie Fackler
|
r43346 | filedata[f] = (mode, size, mtime) # for dirstate.normal | ||
Gregory Szorc
|
r28199 | if i == 100: | ||
Valentin Gatien-Baron
|
r42656 | yield False, (i, f) | ||
Gregory Szorc
|
r28199 | i = 0 | ||
i += 1 | ||||
Bryan O'Sullivan
|
r18633 | if i > 0: | ||
Valentin Gatien-Baron
|
r42656 | yield False, (i, f) | ||
yield True, filedata | ||||
Bryan O'Sullivan
|
r18630 | |||
Augie Fackler
|
r43346 | |||
Matt Harbison
|
r36159 | def _prefetchfiles(repo, ctx, actions): | ||
Matt Harbison
|
r37780 | """Invoke ``scmutil.prefetchfiles()`` for the files relevant to the dict | ||
Matt Harbison
|
r36159 | of merge actions. ``ctx`` is the context being merged in.""" | ||
# Skipping 'a', 'am', 'f', 'r', 'dm', 'e', 'k', 'p' and 'pr', because they | ||||
# don't touch the context to be merged in. 'cd' is skipped, because | ||||
# changed/deleted never resolves to something from the remote side. | ||||
Augie Fackler
|
r43346 | oplist = [ | ||
actions[a] | ||||
for a in ( | ||||
Augie Fackler
|
r45383 | mergestatemod.ACTION_GET, | ||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
mergestatemod.ACTION_LOCAL_DIR_RENAME_GET, | ||||
mergestatemod.ACTION_MERGE, | ||||
Augie Fackler
|
r43346 | ) | ||
] | ||||
Matt Harbison
|
r37780 | prefetch = scmutil.prefetchfiles | ||
matchfiles = scmutil.matchfiles | ||||
Augie Fackler
|
r43346 | prefetch( | ||
repo, | ||||
Rodrigo Damazio Bovendorp
|
r45632 | [ | ||
( | ||||
ctx.rev(), | ||||
matchfiles( | ||||
repo, [f for sublist in oplist for f, args, msg in sublist] | ||||
), | ||||
) | ||||
], | ||||
Augie Fackler
|
r43346 | ) | ||
Phil Cohen
|
r34126 | |||
Gregory Szorc
|
r37125 | @attr.s(frozen=True) | ||
class updateresult(object): | ||||
updatedcount = attr.ib() | ||||
mergedcount = attr.ib() | ||||
removedcount = attr.ib() | ||||
unresolvedcount = attr.ib() | ||||
Gregory Szorc
|
r37143 | def isempty(self): | ||
Augie Fackler
|
r43346 | return not ( | ||
self.updatedcount | ||||
or self.mergedcount | ||||
or self.removedcount | ||||
or self.unresolvedcount | ||||
) | ||||
Gregory Szorc
|
r37143 | |||
Martin von Zweigbergk
|
r41068 | def emptyactions(): | ||
"""create an actions dict, to be populated and passed to applyupdates()""" | ||||
Augie Fackler
|
r44937 | return { | ||
m: [] | ||||
Augie Fackler
|
r43346 | for m in ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_ADD, | ||
mergestatemod.ACTION_ADD_MODIFIED, | ||||
mergestatemod.ACTION_FORGET, | ||||
mergestatemod.ACTION_GET, | ||||
mergestatemod.ACTION_CHANGED_DELETED, | ||||
mergestatemod.ACTION_DELETED_CHANGED, | ||||
mergestatemod.ACTION_REMOVE, | ||||
mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL, | ||||
mergestatemod.ACTION_LOCAL_DIR_RENAME_GET, | ||||
mergestatemod.ACTION_MERGE, | ||||
mergestatemod.ACTION_EXEC, | ||||
mergestatemod.ACTION_KEEP, | ||||
mergestatemod.ACTION_PATH_CONFLICT, | ||||
mergestatemod.ACTION_PATH_CONFLICT_RESOLVE, | ||||
mergestatemod.ACTION_GET_OTHER_AND_STORE, | ||||
Augie Fackler
|
r43346 | ) | ||
Augie Fackler
|
r44937 | } | ||
Martin von Zweigbergk
|
r41068 | |||
Augie Fackler
|
r43346 | |||
def applyupdates( | ||||
repo, actions, wctx, mctx, overwrite, wantfiledata, labels=None | ||||
): | ||||
Peter Arrenbrecht
|
r11454 | """apply the merge action list to the working directory | ||
wctx is the working copy context | ||||
mctx is the context to be merged into the working copy | ||||
Greg Ward
|
r13162 | |||
Valentin Gatien-Baron
|
r42656 | Return a tuple of (counts, filedata), where counts is a tuple | ||
(updated, merged, removed, unresolved) that describes how many | ||||
files were affected by the update, and filedata is as described in | ||||
batchget. | ||||
Peter Arrenbrecht
|
r11454 | """ | ||
Matt Mackall
|
r3315 | |||
Matt Harbison
|
r36159 | _prefetchfiles(repo, mctx, actions) | ||
Siddharth Agarwal
|
r27078 | updated, merged, removed = 0, 0, 0 | ||
Augie Fackler
|
r45383 | ms = mergestatemod.mergestate.clean( | ||
repo, wctx.p1().node(), mctx.node(), labels | ||||
) | ||||
Pulkit Goyal
|
r45178 | |||
# add ACTION_GET_OTHER_AND_STORE to mergestate | ||||
Augie Fackler
|
r45383 | for e in actions[mergestatemod.ACTION_GET_OTHER_AND_STORE]: | ||
Pulkit Goyal
|
r45178 | ms.addmergedother(e[0]) | ||
Matt Mackall
|
r6512 | moves = [] | ||
Mads Kiilerich
|
r21545 | for m, l in actions.items(): | ||
l.sort() | ||||
Matt Mackall
|
r6512 | |||
Siddharth Agarwal
|
r27137 | # 'cd' and 'dc' actions are treated like other merge conflicts | ||
Augie Fackler
|
r45383 | mergeactions = sorted(actions[mergestatemod.ACTION_CHANGED_DELETED]) | ||
mergeactions.extend(sorted(actions[mergestatemod.ACTION_DELETED_CHANGED])) | ||||
mergeactions.extend(actions[mergestatemod.ACTION_MERGE]) | ||||
Siddharth Agarwal
|
r27137 | for f, args, msg in mergeactions: | ||
Mads Kiilerich
|
r21551 | f1, f2, fa, move, anc = args | ||
Augie Fackler
|
r43347 | if f == b'.hgsubstate': # merged internally | ||
Mads Kiilerich
|
r21551 | continue | ||
Siddharth Agarwal
|
r27091 | if f1 is None: | ||
fcl = filemerge.absentfilectx(wctx, fa) | ||||
else: | ||||
Augie Fackler
|
r43347 | repo.ui.debug(b" preserving %s for resolve of %s\n" % (f1, f)) | ||
Siddharth Agarwal
|
r27091 | fcl = wctx[f1] | ||
if f2 is None: | ||||
fco = filemerge.absentfilectx(mctx, fa) | ||||
else: | ||||
fco = mctx[f2] | ||||
Mads Kiilerich
|
r21551 | actx = repo[anc] | ||
if fa in actx: | ||||
fca = actx[fa] | ||||
else: | ||||
Siddharth Agarwal
|
r27091 | # TODO: move to absentfilectx | ||
Mads Kiilerich
|
r21551 | fca = repo.filectx(f1, fileid=nullrev) | ||
ms.add(fcl, fco, fca, f) | ||||
if f1 != f and move: | ||||
moves.append(f1) | ||||
Matt Mackall
|
r6512 | |||
# remove renamed files after safely stored | ||||
for f in moves: | ||||
Phil Cohen
|
r33283 | if wctx[f].lexists(): | ||
Augie Fackler
|
r43347 | repo.ui.debug(b"removing %s\n" % f) | ||
Phil Cohen
|
r33086 | wctx[f].audit() | ||
Phil Cohen
|
r33082 | wctx[f].remove() | ||
Matt Mackall
|
r5042 | |||
Augie Fackler
|
r45383 | numupdates = sum( | ||
len(l) for m, l in actions.items() if m != mergestatemod.ACTION_KEEP | ||||
) | ||||
Augie Fackler
|
r43346 | progress = repo.ui.makeprogress( | ||
Augie Fackler
|
r43347 | _(b'updating'), unit=_(b'files'), total=numupdates | ||
Augie Fackler
|
r43346 | ) | ||
Bryan O'Sullivan
|
r18630 | |||
Augie Fackler
|
r45383 | if [ | ||
a | ||||
for a in actions[mergestatemod.ACTION_REMOVE] | ||||
if a[0] == b'.hgsubstate' | ||||
]: | ||||
Yuya Nishihara
|
r36026 | subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) | ||
Bryan O'Sullivan
|
r18632 | |||
Mark Thomas
|
r34548 | # record path conflicts | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_PATH_CONFLICT]: | ||
Mark Thomas
|
r34548 | f1, fo = args | ||
s = repo.ui.status | ||||
Augie Fackler
|
r43346 | s( | ||
_( | ||||
Augie Fackler
|
r43347 | b"%s: path conflict - a file or link has the same name as a " | ||
b"directory\n" | ||||
Augie Fackler
|
r43346 | ) | ||
% f | ||||
) | ||||
Augie Fackler
|
r43347 | if fo == b'l': | ||
s(_(b"the local file has been renamed to %s\n") % f1) | ||||
Mark Thomas
|
r34548 | else: | ||
Augie Fackler
|
r43347 | s(_(b"the remote file has been renamed to %s\n") % f1) | ||
s(_(b"resolve manually then use 'hg resolve --mark %s'\n") % f) | ||||
Pulkit Goyal
|
r45719 | ms.addpathconflict(f, f1, fo) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Mark Thomas
|
r34548 | |||
Phil Cohen
|
r34787 | # When merging in-memory, we can't support worker processes, so set the | ||
# per-item cost at 0 in that case. | ||||
cost = 0 if wctx.isinmemory() else 0.001 | ||||
Mark Thomas
|
r34549 | # remove in parallel (must come before resolving path conflicts and getting) | ||
Augie Fackler
|
r43346 | prog = worker.worker( | ||
Augie Fackler
|
r45383 | repo.ui, | ||
cost, | ||||
batchremove, | ||||
(repo, wctx), | ||||
actions[mergestatemod.ACTION_REMOVE], | ||||
Augie Fackler
|
r43346 | ) | ||
FUJIWARA Katsunori
|
r19095 | for i, item in prog: | ||
Martin von Zweigbergk
|
r38364 | progress.increment(step=i, item=item) | ||
Augie Fackler
|
r45383 | removed = len(actions[mergestatemod.ACTION_REMOVE]) | ||
Mads Kiilerich
|
r21390 | |||
Mark Thomas
|
r34549 | # resolve path conflicts (must come before getting) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_PATH_CONFLICT_RESOLVE]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> pr\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r45465 | (f0, origf0) = args | ||
Mark Thomas
|
r34549 | if wctx[f0].lexists(): | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b"moving %s to %s\n") % (f0, f)) | ||
Mark Thomas
|
r34549 | wctx[f].audit() | ||
wctx[f].write(wctx.filectx(f0).data(), wctx.filectx(f0).flags()) | ||||
wctx[f0].remove() | ||||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Mark Thomas
|
r34549 | |||
Gregory Szorc
|
r38755 | # get in parallel. | ||
Augie Fackler
|
r43346 | threadsafe = repo.ui.configbool( | ||
Augie Fackler
|
r43347 | b'experimental', b'worker.wdir-get-thread-safe' | ||
Augie Fackler
|
r43346 | ) | ||
prog = worker.worker( | ||||
repo.ui, | ||||
cost, | ||||
batchget, | ||||
(repo, mctx, wctx, wantfiledata), | ||||
Augie Fackler
|
r45383 | actions[mergestatemod.ACTION_GET], | ||
Augie Fackler
|
r43346 | threadsafe=threadsafe, | ||
hasretval=True, | ||||
) | ||||
Valentin Gatien-Baron
|
r42722 | getfiledata = {} | ||
Valentin Gatien-Baron
|
r42656 | for final, res in prog: | ||
if final: | ||||
getfiledata = res | ||||
else: | ||||
i, item = res | ||||
progress.increment(step=i, item=item) | ||||
Augie Fackler
|
r45383 | updated = len(actions[mergestatemod.ACTION_GET]) | ||
Bryan O'Sullivan
|
r18630 | |||
Augie Fackler
|
r45383 | if [a for a in actions[mergestatemod.ACTION_GET] if a[0] == b'.hgsubstate']: | ||
Yuya Nishihara
|
r36026 | subrepoutil.submerge(repo, wctx, mctx, wctx, overwrite, labels) | ||
Bryan O'Sullivan
|
r18632 | |||
Mads Kiilerich
|
r21551 | # forget (manifest only, just log it) (must come first) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_FORGET]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> f\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Mads Kiilerich
|
r21391 | |||
Mads Kiilerich
|
r21551 | # re-add (manifest only, just log it) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_ADD]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> a\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Mads Kiilerich
|
r21391 | |||
Siddharth Agarwal
|
r27131 | # re-add/mark as modified (manifest only, just log it) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_ADD_MODIFIED]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> am\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Siddharth Agarwal
|
r27131 | |||
Mads Kiilerich
|
r21551 | # keep (noop, just log it) | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_KEEP]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> k\n" % (f, msg)) | ||
Mads Kiilerich
|
r21551 | # no progress | ||
Mads Kiilerich
|
r21391 | |||
Mads Kiilerich
|
r21551 | # directory rename, move local | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_DIR_RENAME_MOVE_LOCAL]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> dm\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Mads Kiilerich
|
r21551 | f0, flags = args | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b"moving %s to %s\n") % (f0, f)) | ||
Phil Cohen
|
r33086 | wctx[f].audit() | ||
Phil Cohen
|
r33083 | wctx[f].write(wctx.filectx(f0).data(), flags) | ||
Phil Cohen
|
r33082 | wctx[f0].remove() | ||
Mads Kiilerich
|
r21551 | updated += 1 | ||
Mads Kiilerich
|
r21391 | |||
Mads Kiilerich
|
r21551 | # local directory rename, get | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_LOCAL_DIR_RENAME_GET]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> dg\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Mads Kiilerich
|
r21551 | f0, flags = args | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b"getting %s to %s\n") % (f0, f)) | ||
Phil Cohen
|
r33083 | wctx[f].write(mctx.filectx(f0).data(), flags) | ||
Mads Kiilerich
|
r21551 | updated += 1 | ||
Mads Kiilerich
|
r21391 | |||
Mads Kiilerich
|
r21551 | # exec | ||
Augie Fackler
|
r45383 | for f, args, msg in actions[mergestatemod.ACTION_EXEC]: | ||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> e\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Augie Fackler
|
r43346 | (flags,) = args | ||
Phil Cohen
|
r33086 | wctx[f].audit() | ||
Augie Fackler
|
r43347 | wctx[f].setflags(b'l' in flags, b'x' in flags) | ||
Mads Kiilerich
|
r21551 | updated += 1 | ||
Mads Kiilerich
|
r21391 | |||
Siddharth Agarwal
|
r26786 | # the ordering is important here -- ms.mergedriver will raise if the merge | ||
# driver has changed, and we want to be able to bypass it when overwrite is | ||||
# True | ||||
usemergedriver = not overwrite and mergeactions and ms.mergedriver | ||||
if usemergedriver: | ||||
Phil Cohen
|
r35516 | if wctx.isinmemory(): | ||
Augie Fackler
|
r43346 | raise error.InMemoryMergeConflictsError( | ||
Martin von Zweigbergk
|
r43387 | b"in-memory merge does not support mergedriver" | ||
Augie Fackler
|
r43346 | ) | ||
Siddharth Agarwal
|
r26786 | ms.commit() | ||
proceed = driverpreprocess(repo, ms, wctx, labels=labels) | ||||
# the driver might leave some files unresolved | ||||
unresolvedf = set(ms.unresolved()) | ||||
if not proceed: | ||||
# XXX setting unresolved to at least 1 is a hack to make sure we | ||||
# error out | ||||
Augie Fackler
|
r43346 | return updateresult( | ||
updated, merged, removed, max(len(unresolvedf), 1) | ||||
) | ||||
Siddharth Agarwal
|
r26786 | newactions = [] | ||
for f, args, msg in mergeactions: | ||||
if f in unresolvedf: | ||||
newactions.append((f, args, msg)) | ||||
mergeactions = newactions | ||||
Ryan McElroy
|
r34681 | try: | ||
# premerge | ||||
tocomplete = [] | ||||
for f, args, msg in mergeactions: | ||||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> m (premerge)\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f) | ||
Augie Fackler
|
r43347 | if f == b'.hgsubstate': # subrepo states need updating | ||
Augie Fackler
|
r43346 | subrepoutil.submerge( | ||
repo, wctx, mctx, wctx.ancestor(mctx), overwrite, labels | ||||
) | ||||
Ryan McElroy
|
r34681 | continue | ||
wctx[f].audit() | ||||
complete, r = ms.preresolve(f, wctx) | ||||
if not complete: | ||||
numupdates += 1 | ||||
tocomplete.append((f, args, msg)) | ||||
Siddharth Agarwal
|
r26618 | |||
Ryan McElroy
|
r34681 | # merge | ||
for f, args, msg in tocomplete: | ||||
Augie Fackler
|
r43347 | repo.ui.debug(b" %s: %s -> m (merge)\n" % (f, msg)) | ||
Martin von Zweigbergk
|
r38364 | progress.increment(item=f, total=numupdates) | ||
Ryan McElroy
|
r34681 | ms.resolve(f, wctx) | ||
Siddharth Agarwal
|
r26292 | |||
Ryan McElroy
|
r34681 | finally: | ||
ms.commit() | ||||
Siddharth Agarwal
|
r26787 | |||
Siddharth Agarwal
|
r27078 | unresolved = ms.unresolvedcount() | ||
Augie Fackler
|
r43346 | if ( | ||
usemergedriver | ||||
and not unresolved | ||||
Augie Fackler
|
r45383 | and ms.mdstate() != mergestatemod.MERGE_DRIVER_STATE_SUCCESS | ||
Augie Fackler
|
r43346 | ): | ||
Siddharth Agarwal
|
r26787 | if not driverconclude(repo, ms, wctx, labels=labels): | ||
# XXX setting unresolved to at least 1 is a hack to make sure we | ||||
# error out | ||||
Siddharth Agarwal
|
r26975 | unresolved = max(unresolved, 1) | ||
Siddharth Agarwal
|
r26787 | |||
ms.commit() | ||||
Siddharth Agarwal
|
r27078 | msupdated, msmerged, msremoved = ms.counts() | ||
updated += msupdated | ||||
merged += msmerged | ||||
removed += msremoved | ||||
Siddharth Agarwal
|
r27080 | |||
extraactions = ms.actions() | ||||
Siddharth Agarwal
|
r29831 | if extraactions: | ||
Augie Fackler
|
r45383 | mfiles = {a[0] for a in actions[mergestatemod.ACTION_MERGE]} | ||
Gregory Szorc
|
r43376 | for k, acts in pycompat.iteritems(extraactions): | ||
Siddharth Agarwal
|
r29831 | actions[k].extend(acts) | ||
Augie Fackler
|
r45383 | if k == mergestatemod.ACTION_GET and wantfiledata: | ||
Valentin Gatien-Baron
|
r42656 | # no filedata until mergestate is updated to provide it | ||
Valentin Gatien-Baron
|
r42722 | for a in acts: | ||
getfiledata[a[0]] = None | ||||
Gregory Szorc
|
r37130 | # Remove these files from actions[ACTION_MERGE] as well. This is | ||
# important because in recordupdates, files in actions[ACTION_MERGE] | ||||
# are processed after files in other actions, and the merge driver | ||||
# might add files to those actions via extraactions above. This can | ||||
# lead to a file being recorded twice, with poor results. This is | ||||
# especially problematic for actions[ACTION_REMOVE] (currently only | ||||
# possible with the merge driver in the initial merge process; | ||||
# interrupted merges don't go through this flow). | ||||
Siddharth Agarwal
|
r29831 | # | ||
# The real fix here is to have indexes by both file and action so | ||||
# that when the action for a file is changed it is automatically | ||||
# reflected in the other action lists. But that involves a more | ||||
# complex data structure, so this will do for now. | ||||
# | ||||
# We don't need to do the same operation for 'dc' and 'cd' because | ||||
# those lists aren't consulted again. | ||||
mfiles.difference_update(a[0] for a in acts) | ||||
Augie Fackler
|
r45383 | actions[mergestatemod.ACTION_MERGE] = [ | ||
a for a in actions[mergestatemod.ACTION_MERGE] if a[0] in mfiles | ||||
Augie Fackler
|
r43346 | ] | ||
Siddharth Agarwal
|
r27080 | |||
Martin von Zweigbergk
|
r38392 | progress.complete() | ||
Augie Fackler
|
r45383 | assert len(getfiledata) == ( | ||
len(actions[mergestatemod.ACTION_GET]) if wantfiledata else 0 | ||||
) | ||||
Valentin Gatien-Baron
|
r42656 | return updateresult(updated, merged, removed, unresolved), getfiledata | ||
Matt Mackall
|
r3111 | |||
Augie Fackler
|
r43346 | |||
Pulkit Goyal
|
r45727 | def _advertisefsmonitor(repo, num_gets, p1node): | ||
# Advertise fsmonitor when its presence could be useful. | ||||
# | ||||
# We only advertise when performing an update from an empty working | ||||
# directory. This typically only occurs during initial clone. | ||||
# | ||||
# We give users a mechanism to disable the warning in case it is | ||||
# annoying. | ||||
# | ||||
# We only allow on Linux and MacOS because that's where fsmonitor is | ||||
# considered stable. | ||||
fsmonitorwarning = repo.ui.configbool(b'fsmonitor', b'warn_when_unused') | ||||
fsmonitorthreshold = repo.ui.configint( | ||||
b'fsmonitor', b'warn_update_file_count' | ||||
) | ||||
try: | ||||
# avoid cycle: extensions -> cmdutil -> merge | ||||
from . import extensions | ||||
extensions.find(b'fsmonitor') | ||||
fsmonitorenabled = repo.ui.config(b'fsmonitor', b'mode') != b'off' | ||||
# We intentionally don't look at whether fsmonitor has disabled | ||||
# itself because a) fsmonitor may have already printed a warning | ||||
# b) we only care about the config state here. | ||||
except KeyError: | ||||
fsmonitorenabled = False | ||||
if ( | ||||
fsmonitorwarning | ||||
and not fsmonitorenabled | ||||
and p1node == nullid | ||||
and num_gets >= fsmonitorthreshold | ||||
and pycompat.sysplatform.startswith((b'linux', b'darwin')) | ||||
): | ||||
repo.ui.warn( | ||||
_( | ||||
b'(warning: large working directory being used without ' | ||||
b'fsmonitor enabled; enable fsmonitor to improve performance; ' | ||||
b'see "hg help -e fsmonitor")\n' | ||||
) | ||||
) | ||||
Augie Fackler
|
r43347 | UPDATECHECK_ABORT = b'abort' # handled at higher layers | ||
UPDATECHECK_NONE = b'none' | ||||
UPDATECHECK_LINEAR = b'linear' | ||||
UPDATECHECK_NO_CONFLICT = b'noconflict' | ||||
Augie Fackler
|
r43240 | |||
Augie Fackler
|
r43346 | |||
def update( | ||||
repo, | ||||
node, | ||||
branchmerge, | ||||
force, | ||||
ancestor=None, | ||||
mergeancestor=False, | ||||
labels=None, | ||||
matcher=None, | ||||
mergeforce=False, | ||||
Martin von Zweigbergk
|
r44744 | updatedirstate=True, | ||
Augie Fackler
|
r43346 | updatecheck=None, | ||
wc=None, | ||||
): | ||||
Matt Mackall
|
r3315 | """ | ||
Perform a merge between the working directory and the given node | ||||
Martin von Zweigbergk
|
r30902 | node = the node to update to | ||
Matt Mackall
|
r3315 | branchmerge = whether to merge between branches | ||
force = whether to force branch merging or file overwriting | ||||
Augie Fackler
|
r27344 | matcher = a matcher to filter file lists (dirstate not updated) | ||
Durham Goode
|
r18778 | mergeancestor = whether it is merging with an ancestor. If true, | ||
we should accept the incoming changes for any prompts that occur. | ||||
If false, merging with an ancestor (fast-forward) is only allowed | ||||
between different named branches. This flag is used by rebase extension | ||||
as a temporary fix and should be avoided in general. | ||||
Siddharth Agarwal
|
r28019 | labels = labels to use for base, local and other | ||
Siddharth Agarwal
|
r28020 | mergeforce = whether the merge was run with 'merge --force' (deprecated): if | ||
this is True, then 'force' should be True as well. | ||||
Stuart W Marks
|
r9716 | |||
muxator
|
r34920 | The table below shows all the behaviors of the update command given the | ||
-c/--check and -C/--clean or no options, whether the working directory is | ||||
dirty, whether a revision is specified, and the relationship of the parent | ||||
rev to the target rev (linear or not). Match from top first. The -n | ||||
option doesn't exist on the command line, but represents the | ||||
Martin von Zweigbergk
|
r31168 | experimental.updatecheck=noconflict option. | ||
Stuart W Marks
|
r9716 | |||
Adrian Buehlmann
|
r12279 | This logic is tested by test-update-branches.t. | ||
Stuart W Marks
|
r9716 | |||
Martin von Zweigbergk
|
r31168 | -c -C -n -m dirty rev linear | result | ||
y y * * * * * | (1) | ||||
y * y * * * * | (1) | ||||
y * * y * * * | (1) | ||||
* y y * * * * | (1) | ||||
* y * y * * * | (1) | ||||
* * y y * * * | (1) | ||||
* * * * * n n | x | ||||
* * * * n * * | ok | ||||
n n n n y * y | merge | ||||
n n n n y y n | (2) | ||||
n n n y y * * | merge | ||||
n n y n y * * | merge if no conflict | ||||
n y n n y * * | discard | ||||
y n n n y * * | (3) | ||||
Stuart W Marks
|
r9716 | |||
x = can't happen | ||||
* = don't-care | ||||
Martin von Zweigbergk
|
r31161 | 1 = incompatible options (checked in commands.py) | ||
2 = abort: uncommitted changes (commit or update --clean to discard changes) | ||||
3 = abort: uncommitted changes (checked in commands.py) | ||||
Greg Ward
|
r13162 | |||
Phil Cohen
|
r34303 | The merge is performed inside ``wc``, a workingctx-like objects. It defaults | ||
to repo[None] if None is passed. | ||||
Greg Ward
|
r13162 | Return the same tuple as applyupdates(). | ||
Matt Mackall
|
r3315 | """ | ||
Gregory Szorc
|
r33321 | # Avoid cycle. | ||
from . import sparse | ||||
Matt Mackall
|
r2815 | |||
Martin von Zweigbergk
|
r31166 | # This function used to find the default destination if node was None, but | ||
Martin von Zweigbergk
|
r30902 | # that's now in destutil.py. | ||
assert node is not None | ||||
Martin von Zweigbergk
|
r31166 | if not branchmerge and not force: | ||
# TODO: remove the default once all callers that pass branchmerge=False | ||||
# and force=False pass a value for updatecheck. We may want to allow | ||||
# updatecheck='abort' to better suppport some of these callers. | ||||
if updatecheck is None: | ||||
Augie Fackler
|
r43240 | updatecheck = UPDATECHECK_LINEAR | ||
Augie Fackler
|
r43346 | if updatecheck not in ( | ||
UPDATECHECK_NONE, | ||||
UPDATECHECK_LINEAR, | ||||
UPDATECHECK_NO_CONFLICT, | ||||
Augie Fackler
|
r43242 | ): | ||
Augie Fackler
|
r43346 | raise ValueError( | ||
r'Invalid updatecheck %r (can accept %r)' | ||||
% ( | ||||
updatecheck, | ||||
( | ||||
UPDATECHECK_NONE, | ||||
UPDATECHECK_LINEAR, | ||||
UPDATECHECK_NO_CONFLICT, | ||||
), | ||||
) | ||||
) | ||||
Martin von Zweigbergk
|
r45536 | if wc is not None and wc.isinmemory(): | ||
maybe_wlock = util.nullcontextmanager() | ||||
else: | ||||
maybe_wlock = repo.wlock() | ||||
with maybe_wlock: | ||||
Phil Cohen
|
r34303 | if wc is None: | ||
wc = repo[None] | ||||
Sean Farley
|
r20279 | pl = wc.parents() | ||
p1 = pl[0] | ||||
Martin von Zweigbergk
|
r42601 | p2 = repo[node] | ||
Mads Kiilerich
|
r23405 | if ancestor is not None: | ||
Mads Kiilerich
|
r21081 | pas = [repo[ancestor]] | ||
Martin von Zweigbergk
|
r42602 | else: | ||
Augie Fackler
|
r43347 | if repo.ui.configlist(b'merge', b'preferancestor') == [b'*']: | ||
Mads Kiilerich
|
r21128 | cahs = repo.changelog.commonancestorsheads(p1.node(), p2.node()) | ||
pas = [repo[anc] for anc in (sorted(cahs) or [nullid])] | ||||
else: | ||||
Mads Kiilerich
|
r22179 | pas = [p1.ancestor(p2, warn=branchmerge)] | ||
Matt Mackall
|
r13874 | |||
Augie Fackler
|
r36195 | fp1, fp2, xp1, xp2 = p1.node(), p2.node(), bytes(p1), bytes(p2) | ||
Matt Mackall
|
r3314 | |||
Martin von Zweigbergk
|
r42601 | overwrite = force and not branchmerge | ||
Matt Mackall
|
r4915 | ### check phase | ||
Martin von Zweigbergk
|
r27316 | if not overwrite: | ||
if len(pl) > 1: | ||||
Augie Fackler
|
r43347 | raise error.Abort(_(b"outstanding uncommitted merge")) | ||
Augie Fackler
|
r45383 | ms = mergestatemod.mergestate.read(repo) | ||
Martin von Zweigbergk
|
r27316 | if list(ms.unresolved()): | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Augie Fackler
|
r43347 | _(b"outstanding merge conflicts"), | ||
hint=_(b"use 'hg resolve' to resolve"), | ||||
Augie Fackler
|
r43346 | ) | ||
Matt Mackall
|
r6375 | if branchmerge: | ||
Mads Kiilerich
|
r21081 | if pas == [p2]: | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
_( | ||||
Augie Fackler
|
r43347 | b"merging with a working directory ancestor" | ||
b" has no effect" | ||||
Augie Fackler
|
r43346 | ) | ||
) | ||||
Mads Kiilerich
|
r21081 | elif pas == [p1]: | ||
Mads Kiilerich
|
r31379 | if not mergeancestor and wc.branch() == p2.branch(): | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Augie Fackler
|
r43347 | _(b"nothing to merge"), | ||
Martin von Zweigbergk
|
r43387 | hint=_(b"use 'hg update' or check 'hg heads'"), | ||
Augie Fackler
|
r43346 | ) | ||
Matt Mackall
|
r6375 | if not force and (wc.files() or wc.deleted()): | ||
Augie Fackler
|
r43346 | raise error.Abort( | ||
Augie Fackler
|
r43347 | _(b"uncommitted changes"), | ||
hint=_(b"use 'hg status' to list changes"), | ||||
Augie Fackler
|
r43346 | ) | ||
Phil Cohen
|
r35285 | if not wc.isinmemory(): | ||
for s in sorted(wc.substate): | ||||
wc.sub(s).bailifchanged() | ||||
Oleg Stepanov
|
r13437 | |||
Matt Mackall
|
r6375 | elif not overwrite: | ||
Augie Fackler
|
r43346 | if p1 == p2: # no-op update | ||
Siddharth Agarwal
|
r19929 | # call the hooks and exit early | ||
Augie Fackler
|
r43347 | repo.hook(b'preupdate', throw=True, parent1=xp2, parent2=b'') | ||
repo.hook(b'update', parent1=xp2, parent2=b'', error=0) | ||||
Gregory Szorc
|
r37125 | return updateresult(0, 0, 0, 0) | ||
Siddharth Agarwal
|
r19929 | |||
Augie Fackler
|
r43346 | if updatecheck == UPDATECHECK_LINEAR and pas not in ( | ||
[p1], | ||||
[p2], | ||||
): # nonlinear | ||||
Pierre-Yves David
|
r18985 | dirty = wc.dirty(missing=True) | ||
Martin von Zweigbergk
|
r30902 | if dirty: | ||
Pierre-Yves David
|
r18985 | # Branching is a bit strange to ensure we do the minimal | ||
r33147 | # amount of call to obsutil.foreground. | |||
foreground = obsutil.foreground(repo, [p1.node()]) | ||||
Pierre-Yves David
|
r18985 | # note: the <node> variable contains a random identifier | ||
if repo[node].node() in foreground: | ||||
Augie Fackler
|
r43346 | pass # allow updating to successors | ||
Martin von Zweigbergk
|
r30902 | else: | ||
Augie Fackler
|
r43347 | msg = _(b"uncommitted changes") | ||
hint = _(b"commit or update --clean to discard changes") | ||||
Martin von Zweigbergk
|
r30961 | raise error.UpdateAbort(msg, hint=hint) | ||
Pierre-Yves David
|
r18985 | else: | ||
# Allow jumping branches if clean and specific rev given | ||||
Martin von Zweigbergk
|
r30901 | pass | ||
if overwrite: | ||||
pas = [wc] | ||||
elif not branchmerge: | ||||
pas = [p1] | ||||
Matt Mackall
|
r2814 | |||
Matt Mackall
|
r25843 | # deprecated config: merge.followcopies | ||
Augie Fackler
|
r43347 | followcopies = repo.ui.configbool(b'merge', b'followcopies') | ||
Mads Kiilerich
|
r21080 | if overwrite: | ||
Gábor Stefanik
|
r30200 | followcopies = False | ||
elif not pas[0]: | ||||
followcopies = False | ||||
if not branchmerge and not wc.dirty(missing=True): | ||||
followcopies = False | ||||
Mads Kiilerich
|
r21080 | |||
Matt Mackall
|
r4915 | ### calculate phase | ||
Martin von Zweigbergk
|
r23641 | actionbyfile, diverge, renamedelete = calculateupdates( | ||
Augie Fackler
|
r43346 | repo, | ||
wc, | ||||
p2, | ||||
pas, | ||||
branchmerge, | ||||
force, | ||||
mergeancestor, | ||||
followcopies, | ||||
matcher=matcher, | ||||
mergeforce=mergeforce, | ||||
) | ||||
Siddharth Agarwal
|
r27951 | |||
Augie Fackler
|
r43240 | if updatecheck == UPDATECHECK_NO_CONFLICT: | ||
Gregory Szorc
|
r43376 | for f, (m, args, msg) in pycompat.iteritems(actionbyfile): | ||
Augie Fackler
|
r43346 | if m not in ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_GET, | ||
mergestatemod.ACTION_KEEP, | ||||
mergestatemod.ACTION_EXEC, | ||||
mergestatemod.ACTION_REMOVE, | ||||
mergestatemod.ACTION_PATH_CONFLICT_RESOLVE, | ||||
mergestatemod.ACTION_GET_OTHER_AND_STORE, | ||||
Augie Fackler
|
r43346 | ): | ||
Augie Fackler
|
r43347 | msg = _(b"conflicting changes") | ||
hint = _(b"commit or update --clean to discard changes") | ||||
Martin von Zweigbergk
|
r31168 | raise error.Abort(msg, hint=hint) | ||
Siddharth Agarwal
|
r27951 | # Prompt and create actions. Most of this is in the resolve phase | ||
# already, but we can't handle .hgsubstate in filemerge or | ||||
Yuya Nishihara
|
r36026 | # subrepoutil.submerge yet so we have to keep prompting for it. | ||
Augie Fackler
|
r43347 | if b'.hgsubstate' in actionbyfile: | ||
f = b'.hgsubstate' | ||||
Siddharth Agarwal
|
r27951 | m, args, msg = actionbyfile[f] | ||
Simon Farnsworth
|
r29774 | prompts = filemerge.partextras(labels) | ||
Augie Fackler
|
r43347 | prompts[b'f'] = f | ||
Augie Fackler
|
r45383 | if m == mergestatemod.ACTION_CHANGED_DELETED: | ||
Siddharth Agarwal
|
r27951 | if repo.ui.promptchoice( | ||
Augie Fackler
|
r43346 | _( | ||
Augie Fackler
|
r43347 | b"local%(l)s changed %(f)s which other%(o)s deleted\n" | ||
b"use (c)hanged version or (d)elete?" | ||||
b"$$ &Changed $$ &Delete" | ||||
Augie Fackler
|
r43346 | ) | ||
% prompts, | ||||
0, | ||||
): | ||||
Augie Fackler
|
r45383 | actionbyfile[f] = ( | ||
mergestatemod.ACTION_REMOVE, | ||||
None, | ||||
b'prompt delete', | ||||
) | ||||
Siddharth Agarwal
|
r27951 | elif f in p1: | ||
Augie Fackler
|
r43347 | actionbyfile[f] = ( | ||
Augie Fackler
|
r45383 | mergestatemod.ACTION_ADD_MODIFIED, | ||
Augie Fackler
|
r43347 | None, | ||
b'prompt keep', | ||||
) | ||||
Siddharth Agarwal
|
r27951 | else: | ||
Augie Fackler
|
r45383 | actionbyfile[f] = ( | ||
mergestatemod.ACTION_ADD, | ||||
None, | ||||
b'prompt keep', | ||||
) | ||||
elif m == mergestatemod.ACTION_DELETED_CHANGED: | ||||
Siddharth Agarwal
|
r27951 | f1, f2, fa, move, anc = args | ||
flags = p2[f2].flags() | ||||
Augie Fackler
|
r43346 | if ( | ||
repo.ui.promptchoice( | ||||
_( | ||||
Augie Fackler
|
r43347 | b"other%(o)s changed %(f)s which local%(l)s deleted\n" | ||
b"use (c)hanged version or leave (d)eleted?" | ||||
b"$$ &Changed $$ &Deleted" | ||||
Augie Fackler
|
r43346 | ) | ||
% prompts, | ||||
0, | ||||
) | ||||
== 0 | ||||
): | ||||
actionbyfile[f] = ( | ||||
Augie Fackler
|
r45383 | mergestatemod.ACTION_GET, | ||
Augie Fackler
|
r43346 | (flags, False), | ||
Augie Fackler
|
r43347 | b'prompt recreating', | ||
Augie Fackler
|
r43346 | ) | ||
Siddharth Agarwal
|
r27951 | else: | ||
del actionbyfile[f] | ||||
Martin von Zweigbergk
|
r23641 | # Convert to dictionary-of-lists format | ||
Martin von Zweigbergk
|
r41068 | actions = emptyactions() | ||
Gregory Szorc
|
r43376 | for f, (m, args, msg) in pycompat.iteritems(actionbyfile): | ||
Martin von Zweigbergk
|
r23641 | if m not in actions: | ||
actions[m] = [] | ||||
actions[m].append((f, args, msg)) | ||||
Matt Mackall
|
r2775 | |||
Augie Fackler
|
r45383 | # ACTION_GET_OTHER_AND_STORE is a mergestatemod.ACTION_GET + store in mergestate | ||
for e in actions[mergestatemod.ACTION_GET_OTHER_AND_STORE]: | ||||
actions[mergestatemod.ACTION_GET].append(e) | ||||
Pulkit Goyal
|
r45178 | |||
Martin von Zweigbergk
|
r29889 | if not util.fscasesensitive(repo.path): | ||
Martin von Zweigbergk
|
r23544 | # check collision between files only in p2 for clean update | ||
Augie Fackler
|
r43346 | if not branchmerge and ( | ||
force or not wc.dirty(missing=True, branch=False) | ||||
): | ||||
Martin von Zweigbergk
|
r23544 | _checkcollision(repo, p2.manifest(), None) | ||
else: | ||||
_checkcollision(repo, wc.manifest(), actions) | ||||
Martin von Zweigbergk
|
r23525 | # divergent renames | ||
Gregory Szorc
|
r43376 | for f, fl in sorted(pycompat.iteritems(diverge)): | ||
Augie Fackler
|
r43346 | repo.ui.warn( | ||
_( | ||||
Augie Fackler
|
r43347 | b"note: possible conflict - %s was renamed " | ||
b"multiple times to:\n" | ||||
Augie Fackler
|
r43346 | ) | ||
% f | ||||
) | ||||
Martin von Zweigbergk
|
r42279 | for nf in sorted(fl): | ||
Augie Fackler
|
r43347 | repo.ui.warn(b" %s\n" % nf) | ||
Martin von Zweigbergk
|
r23525 | |||
# rename and delete | ||||
Gregory Szorc
|
r43376 | for f, fl in sorted(pycompat.iteritems(renamedelete)): | ||
Augie Fackler
|
r43346 | repo.ui.warn( | ||
_( | ||||
Augie Fackler
|
r43347 | b"note: possible conflict - %s was deleted " | ||
b"and renamed to:\n" | ||||
Augie Fackler
|
r43346 | ) | ||
% f | ||||
) | ||||
Martin von Zweigbergk
|
r42279 | for nf in sorted(fl): | ||
Augie Fackler
|
r43347 | repo.ui.warn(b" %s\n" % nf) | ||
Martin von Zweigbergk
|
r23525 | |||
Martin von Zweigbergk
|
r26957 | ### apply phase | ||
Augie Fackler
|
r43346 | if not branchmerge: # just jump to the new rev | ||
Augie Fackler
|
r43347 | fp1, fp2, xp1, xp2 = fp2, nullid, xp2, b'' | ||
Martin von Zweigbergk
|
r44625 | # If we're doing a partial update, we need to skip updating | ||
Martin von Zweigbergk
|
r44626 | # the dirstate. | ||
always = matcher is None or matcher.always() | ||||
Martin von Zweigbergk
|
r44744 | updatedirstate = updatedirstate and always and not wc.isinmemory() | ||
Martin von Zweigbergk
|
r44612 | if updatedirstate: | ||
Augie Fackler
|
r43347 | repo.hook(b'preupdate', throw=True, parent1=xp1, parent2=xp2) | ||
Martin von Zweigbergk
|
r26957 | # note that we're in the middle of an update | ||
Augie Fackler
|
r43347 | repo.vfs.write(b'updatestate', p2.hex()) | ||
Martin von Zweigbergk
|
r26957 | |||
Pulkit Goyal
|
r45727 | _advertisefsmonitor( | ||
repo, len(actions[mergestatemod.ACTION_GET]), p1.node() | ||||
Augie Fackler
|
r43346 | ) | ||
Gregory Szorc
|
r34886 | |||
Valentin Gatien-Baron
|
r42656 | wantfiledata = updatedirstate and not branchmerge | ||
Augie Fackler
|
r43346 | stats, getfiledata = applyupdates( | ||
repo, actions, wc, p2, overwrite, wantfiledata, labels=labels | ||||
) | ||||
Martin von Zweigbergk
|
r26957 | |||
Valentin Gatien-Baron
|
r42656 | if updatedirstate: | ||
Augie Fackler
|
r32351 | with repo.dirstate.parentchange(): | ||
repo.setparents(fp1, fp2) | ||||
Augie Fackler
|
r45383 | mergestatemod.recordupdates( | ||
repo, actions, branchmerge, getfiledata | ||||
) | ||||
Augie Fackler
|
r32351 | # update completed, clear state | ||
Augie Fackler
|
r43347 | util.unlink(repo.vfs.join(b'updatestate')) | ||
Matt Mackall
|
r19482 | |||
Augie Fackler
|
r32351 | if not branchmerge: | ||
repo.dirstate.setbranch(p2.branch()) | ||||
Sune Foldager
|
r10492 | |||
Gregory Szorc
|
r33321 | # If we're updating to a location, clean up any stale temporary includes | ||
# (ex: this happens during hg rebase --abort). | ||||
if not branchmerge: | ||||
sparse.prunetemporaryincludes(repo) | ||||
Martin von Zweigbergk
|
r44611 | if updatedirstate: | ||
Augie Fackler
|
r43346 | repo.hook( | ||
Augie Fackler
|
r43347 | b'update', parent1=xp1, parent2=xp2, error=stats.unresolvedcount | ||
Augie Fackler
|
r43346 | ) | ||
Sune Foldager
|
r10492 | return stats | ||
Matt Mackall
|
r22902 | |||
Augie Fackler
|
r43346 | |||
Martin von Zweigbergk
|
r44883 | def merge(ctx, labels=None, force=False, wc=None): | ||
"""Merge another topological branch into the working copy. | ||||
force = whether the merge was run with 'merge --force' (deprecated) | ||||
""" | ||||
return update( | ||||
ctx.repo(), | ||||
ctx.rev(), | ||||
labels=labels, | ||||
branchmerge=True, | ||||
force=force, | ||||
mergeforce=force, | ||||
wc=wc, | ||||
) | ||||
Martin von Zweigbergk
|
r44743 | def clean_update(ctx, wc=None): | ||
"""Do a clean update to the given commit. | ||||
This involves updating to the commit and discarding any changes in the | ||||
working copy. | ||||
""" | ||||
return update(ctx.repo(), ctx.rev(), branchmerge=False, force=True, wc=wc) | ||||
Martin von Zweigbergk
|
r44744 | def revert_to(ctx, matcher=None, wc=None): | ||
"""Revert the working copy to the given commit. | ||||
The working copy will keep its current parent(s) but its content will | ||||
be the same as in the given commit. | ||||
""" | ||||
return update( | ||||
ctx.repo(), | ||||
ctx.rev(), | ||||
branchmerge=False, | ||||
force=True, | ||||
updatedirstate=False, | ||||
matcher=matcher, | ||||
wc=wc, | ||||
) | ||||
Augie Fackler
|
r43346 | def graft( | ||
Martin von Zweigbergk
|
r44692 | repo, | ||
ctx, | ||||
Martin von Zweigbergk
|
r44693 | base=None, | ||
Martin von Zweigbergk
|
r44692 | labels=None, | ||
keepparent=False, | ||||
keepconflictparent=False, | ||||
wctx=None, | ||||
Augie Fackler
|
r43346 | ): | ||
Matt Mackall
|
r22902 | """Do a graft-like merge. | ||
This is a merge where the merge ancestor is chosen such that one | ||||
or more changesets are grafted onto the current changeset. In | ||||
addition to the merge, this fixes up the dirstate to include only | ||||
Andrew Halberstadt
|
r27267 | a single parent (if keepparent is False) and tries to duplicate any | ||
renames/copies appropriately. | ||||
Matt Mackall
|
r22902 | |||
ctx - changeset to rebase | ||||
Martin von Zweigbergk
|
r44693 | base - merge base, or ctx.p1() if not specified | ||
Matt Mackall
|
r22902 | labels - merge labels eg ['local', 'graft'] | ||
Andrew Halberstadt
|
r27267 | keepparent - keep second parent if any | ||
r42604 | keepconflictparent - if unresolved, keep parent used for the merge | |||
Matt Mackall
|
r22902 | |||
""" | ||||
Durham Goode
|
r24643 | # If we're grafting a descendant onto an ancestor, be sure to pass | ||
# mergeancestor=True to update. This does two things: 1) allows the merge if | ||||
# the destination is the same as the parent of the ctx (so we can use graft | ||||
# to copy commits), and 2) informs update that the incoming changes are | ||||
# newer than the destination so it doesn't prompt about "remote changed foo | ||||
# which local deleted". | ||||
Valentin Gatien-Baron
|
r44867 | # We also pass mergeancestor=True when base is the same revision as p1. 2) | ||
# doesn't matter as there can't possibly be conflicts, but 1) is necessary. | ||||
Martin von Zweigbergk
|
r44692 | wctx = wctx or repo[None] | ||
Martin von Zweigbergk
|
r44548 | pctx = wctx.p1() | ||
Martin von Zweigbergk
|
r44693 | base = base or ctx.p1() | ||
Valentin Gatien-Baron
|
r44867 | mergeancestor = ( | ||
repo.changelog.isancestor(pctx.node(), ctx.node()) | ||||
or pctx.rev() == base.rev() | ||||
) | ||||
Matt Mackall
|
r22902 | |||
Augie Fackler
|
r43346 | stats = update( | ||
repo, | ||||
ctx.node(), | ||||
True, | ||||
True, | ||||
Martin von Zweigbergk
|
r44235 | base.node(), | ||
Augie Fackler
|
r43346 | mergeancestor=mergeancestor, | ||
labels=labels, | ||||
Martin von Zweigbergk
|
r44692 | wc=wctx, | ||
Augie Fackler
|
r43346 | ) | ||
Boris Feld
|
r38513 | |||
if keepconflictparent and stats.unresolvedcount: | ||||
pother = ctx.node() | ||||
else: | ||||
pother = nullid | ||||
parents = ctx.parents() | ||||
Martin von Zweigbergk
|
r44235 | if keepparent and len(parents) == 2 and base in parents: | ||
parents.remove(base) | ||||
Boris Feld
|
r38513 | pother = parents[0].node() | ||
Martin von Zweigbergk
|
r44237 | # Never set both parents equal to each other | ||
if pother == pctx.node(): | ||||
pother = nullid | ||||
Andrew Halberstadt
|
r27267 | |||
Martin von Zweigbergk
|
r44692 | if wctx.isinmemory(): | ||
wctx.setparents(pctx.node(), pother) | ||||
Augie Fackler
|
r32351 | # fix up dirstate for copies and renames | ||
Martin von Zweigbergk
|
r44551 | copies.graftcopies(wctx, ctx, base) | ||
Martin von Zweigbergk
|
r44692 | else: | ||
with repo.dirstate.parentchange(): | ||||
repo.setparents(pctx.node(), pother) | ||||
repo.dirstate.write(repo.currenttransaction()) | ||||
# fix up dirstate for copies and renames | ||||
copies.graftcopies(wctx, ctx, base) | ||||
Matt Mackall
|
r22902 | return stats | ||
Gregory Szorc
|
r39499 | |||
Augie Fackler
|
r43346 | |||
def purge( | ||||
repo, | ||||
matcher, | ||||
Valentin Gatien-Baron
|
r44771 | unknown=True, | ||
Augie Fackler
|
r43346 | ignored=False, | ||
removeemptydirs=True, | ||||
removefiles=True, | ||||
abortonerror=False, | ||||
noop=False, | ||||
): | ||||
Gregory Szorc
|
r39499 | """Purge the working directory of untracked files. | ||
``matcher`` is a matcher configured to scan the working directory - | ||||
potentially a subset. | ||||
Valentin Gatien-Baron
|
r44771 | ``unknown`` controls whether unknown files should be purged. | ||
``ignored`` controls whether ignored files should be purged. | ||||
Gregory Szorc
|
r39499 | |||
``removeemptydirs`` controls whether empty directories should be removed. | ||||
``removefiles`` controls whether files are removed. | ||||
``abortonerror`` causes an exception to be raised if an error occurs | ||||
deleting a file or directory. | ||||
``noop`` controls whether to actually remove files. If not defined, actions | ||||
will be taken. | ||||
Returns an iterable of relative paths in the working directory that were | ||||
or would be removed. | ||||
""" | ||||
def remove(removefn, path): | ||||
try: | ||||
Gregory Szorc
|
r39500 | removefn(path) | ||
Gregory Szorc
|
r39499 | except OSError: | ||
Augie Fackler
|
r43347 | m = _(b'%s cannot be removed') % path | ||
Gregory Szorc
|
r39499 | if abortonerror: | ||
raise error.Abort(m) | ||||
else: | ||||
Augie Fackler
|
r43347 | repo.ui.warn(_(b'warning: %s\n') % m) | ||
Gregory Szorc
|
r39499 | |||
# There's no API to copy a matcher. So mutate the passed matcher and | ||||
# restore it when we're done. | ||||
oldtraversedir = matcher.traversedir | ||||
res = [] | ||||
try: | ||||
if removeemptydirs: | ||||
directories = [] | ||||
Martin von Zweigbergk
|
r44112 | matcher.traversedir = directories.append | ||
Gregory Szorc
|
r39499 | |||
Valentin Gatien-Baron
|
r44771 | status = repo.status(match=matcher, ignored=ignored, unknown=unknown) | ||
Gregory Szorc
|
r39499 | |||
if removefiles: | ||||
for f in sorted(status.unknown + status.ignored): | ||||
if not noop: | ||||
Augie Fackler
|
r43347 | repo.ui.note(_(b'removing file %s\n') % f) | ||
Gregory Szorc
|
r39500 | remove(repo.wvfs.unlink, f) | ||
Gregory Szorc
|
r39499 | res.append(f) | ||
if removeemptydirs: | ||||
for f in sorted(directories, reverse=True): | ||||
Gregory Szorc
|
r39500 | if matcher(f) and not repo.wvfs.listdir(f): | ||
Gregory Szorc
|
r39499 | if not noop: | ||
Augie Fackler
|
r43347 | repo.ui.note(_(b'removing directory %s\n') % f) | ||
Gregory Szorc
|
r39500 | remove(repo.wvfs.rmdir, f) | ||
Gregory Szorc
|
r39499 | res.append(f) | ||
return res | ||||
finally: | ||||
matcher.traversedir = oldtraversedir | ||||