2006-08-04 00:24:41 +04:00
|
|
|
# merge.py - directory-level update/merge handling for Mercurial
|
|
|
|
#
|
2007-06-19 10:51:34 +04:00
|
|
|
# Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
|
2006-08-04 00:24:41 +04:00
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2006-08-04 00:24:41 +04:00
|
|
|
|
2008-04-11 21:52:56 +04:00
|
|
|
from node import nullid, nullrev, hex, bin
|
2006-12-15 05:25:19 +03:00
|
|
|
from i18n import _
|
2013-01-09 03:01:33 +04:00
|
|
|
import error, util, filemerge, copies, subrepo
|
2009-04-28 19:40:46 +04:00
|
|
|
import errno, os, shutil
|
2008-04-11 00:02:24 +04:00
|
|
|
|
|
|
|
class mergestate(object):
|
|
|
|
'''track 3-way merge state of individual files'''
|
|
|
|
def __init__(self, repo):
|
|
|
|
self._repo = repo
|
2010-09-06 19:35:49 +04:00
|
|
|
self._dirty = False
|
2008-04-11 21:52:56 +04:00
|
|
|
self._read()
|
2009-03-17 00:58:41 +03:00
|
|
|
def reset(self, node=None):
|
2008-04-11 21:52:56 +04:00
|
|
|
self._state = {}
|
2009-03-17 00:58:41 +03:00
|
|
|
if node:
|
|
|
|
self._local = node
|
2008-04-11 00:02:24 +04:00
|
|
|
shutil.rmtree(self._repo.join("merge"), True)
|
2010-09-06 19:35:49 +04:00
|
|
|
self._dirty = False
|
2008-04-11 21:52:56 +04:00
|
|
|
def _read(self):
|
|
|
|
self._state = {}
|
|
|
|
try:
|
|
|
|
f = self._repo.opener("merge/state")
|
2008-04-12 22:51:26 +04:00
|
|
|
for i, l in enumerate(f):
|
|
|
|
if i == 0:
|
2010-06-28 01:12:05 +04:00
|
|
|
self._local = bin(l[:-1])
|
2008-04-12 22:51:26 +04:00
|
|
|
else:
|
|
|
|
bits = l[:-1].split("\0")
|
|
|
|
self._state[bits[0]] = bits[1:]
|
2010-12-24 17:23:01 +03:00
|
|
|
f.close()
|
2008-04-11 21:52:56 +04:00
|
|
|
except IOError, err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
2010-09-06 19:35:49 +04:00
|
|
|
self._dirty = False
|
|
|
|
def commit(self):
|
|
|
|
if self._dirty:
|
|
|
|
f = self._repo.opener("merge/state", "w")
|
|
|
|
f.write(hex(self._local) + "\n")
|
|
|
|
for d, v in self._state.iteritems():
|
|
|
|
f.write("\0".join([d] + v) + "\n")
|
2010-12-24 17:23:01 +03:00
|
|
|
f.close()
|
2010-09-06 19:35:49 +04:00
|
|
|
self._dirty = False
|
2013-01-09 05:02:45 +04:00
|
|
|
def add(self, fcl, fco, fca, fd):
|
2008-04-11 14:04:26 +04:00
|
|
|
hash = util.sha1(fcl.path()).hexdigest()
|
2011-05-02 12:11:18 +04:00
|
|
|
self._repo.opener.write("merge/" + hash, fcl.data())
|
2008-04-11 21:52:56 +04:00
|
|
|
self._state[fd] = ['u', hash, fcl.path(), fca.path(),
|
2013-01-09 05:02:45 +04:00
|
|
|
hex(fca.filenode()), fco.path(), fcl.flags()]
|
2010-09-06 19:35:49 +04:00
|
|
|
self._dirty = True
|
2008-04-11 00:02:24 +04:00
|
|
|
def __contains__(self, dfile):
|
|
|
|
return dfile in self._state
|
|
|
|
def __getitem__(self, dfile):
|
2008-04-11 21:52:56 +04:00
|
|
|
return self._state[dfile][0]
|
|
|
|
def __iter__(self):
|
|
|
|
l = self._state.keys()
|
|
|
|
l.sort()
|
|
|
|
for f in l:
|
|
|
|
yield f
|
2008-04-11 00:02:24 +04:00
|
|
|
def mark(self, dfile, state):
|
2008-04-11 21:52:56 +04:00
|
|
|
self._state[dfile][0] = state
|
2010-09-06 19:35:49 +04:00
|
|
|
self._dirty = True
|
2008-04-11 00:02:24 +04:00
|
|
|
def resolve(self, dfile, wctx, octx):
|
|
|
|
if self[dfile] == 'r':
|
|
|
|
return 0
|
2008-04-11 21:52:56 +04:00
|
|
|
state, hash, lfile, afile, anode, ofile, flags = self._state[dfile]
|
2008-04-11 00:02:24 +04:00
|
|
|
fcd = wctx[dfile]
|
|
|
|
fco = octx[ofile]
|
|
|
|
fca = self._repo.filectx(afile, fileid=anode)
|
2013-01-09 05:02:45 +04:00
|
|
|
# "premerge" x flags
|
|
|
|
flo = fco.flags()
|
|
|
|
fla = fca.flags()
|
|
|
|
if 'x' in flags + flo + fla and 'l' not in flags + flo + fla:
|
|
|
|
if fca.node() == nullid:
|
|
|
|
self._repo.ui.warn(_('warning: cannot merge flags for %s\n') %
|
|
|
|
afile)
|
|
|
|
elif flags == fla:
|
|
|
|
flags = flo
|
|
|
|
# restore local
|
|
|
|
f = self._repo.opener("merge/" + hash)
|
|
|
|
self._repo.wwrite(dfile, f.read(), flags)
|
|
|
|
f.close()
|
2008-04-11 00:02:24 +04:00
|
|
|
r = filemerge.filemerge(self._repo, self._local, lfile, fcd, fco, fca)
|
2011-03-06 01:34:59 +03:00
|
|
|
if r is None:
|
|
|
|
# no real conflict
|
|
|
|
del self._state[dfile]
|
|
|
|
elif not r:
|
2008-04-11 00:02:24 +04:00
|
|
|
self.mark(dfile, 'r')
|
|
|
|
return r
|
2006-08-04 00:24:41 +04:00
|
|
|
|
2012-02-10 02:50:19 +04:00
|
|
|
def _checkunknownfile(repo, wctx, mctx, f):
|
|
|
|
return (not repo.dirstate._ignore(f)
|
2012-04-27 22:18:09 +04:00
|
|
|
and os.path.isfile(repo.wjoin(f))
|
2012-03-27 01:41:54 +04:00
|
|
|
and repo.dirstate.normalize(f) not in repo.dirstate
|
2012-02-10 02:50:19 +04:00
|
|
|
and mctx[f].cmp(wctx[f]))
|
|
|
|
|
|
|
|
def _checkunknown(repo, wctx, mctx):
|
2006-10-10 11:31:02 +04:00
|
|
|
"check for collisions between unknown files and files in mctx"
|
2012-01-12 00:53:42 +04:00
|
|
|
|
|
|
|
error = False
|
2012-02-10 02:50:19 +04:00
|
|
|
for f in mctx:
|
|
|
|
if f not in wctx and _checkunknownfile(repo, wctx, mctx, f):
|
2012-01-12 00:53:42 +04:00
|
|
|
error = True
|
2012-02-10 02:50:19 +04:00
|
|
|
wctx._repo.ui.warn(_("%s: untracked file differs\n") % f)
|
2012-01-12 00:53:42 +04:00
|
|
|
if error:
|
|
|
|
raise util.Abort(_("untracked files in working directory differ "
|
|
|
|
"from files in requested revision"))
|
2006-09-18 01:47:33 +04:00
|
|
|
|
icasefs: make case-folding collision detection as deletion aware (issue3648)
Before this patch, case-folding collision is checked simply between
manifests of each merged revisions.
So, files may be considered as colliding each other, even though one
of them is already deleted on one of merged branches: in such case,
merge causes deleting it, so case-folding collision doesn't occur.
This patch checks whether both of files colliding each other still
remain after merge or not, and ignores collision if at least one of
them is deleted by merge.
In the case that one of colliding files is deleted on one of merged
branches and changed on another, file is considered to still remain
after merge, even though it may be deleted by merge, if "deleting" of
it is chosen in "manifestmerge()".
This avoids fail to merge by case-folding collisions after choices
from "changing" and "deleting" of files.
This patch adds only tests for "removed remotely" code paths in
"_remains()", because other ones are tested by existing tests in
"test-casecollision-merge.t".
2012-10-31 11:50:22 +04:00
|
|
|
def _remains(f, m, ma, workingctx=False):
|
|
|
|
"""check whether specified file remains after merge.
|
|
|
|
|
|
|
|
It is assumed that specified file is not contained in the manifest
|
|
|
|
of the other context.
|
|
|
|
"""
|
|
|
|
if f in ma:
|
|
|
|
n = m[f]
|
|
|
|
if n != ma[f]:
|
|
|
|
return True # because it is changed locally
|
|
|
|
# even though it doesn't remain, if "remote deleted" is
|
|
|
|
# chosen in manifestmerge()
|
|
|
|
elif workingctx and n[20:] == "a":
|
|
|
|
return True # because it is added locally (linear merge specific)
|
|
|
|
else:
|
|
|
|
return False # because it is removed remotely
|
|
|
|
else:
|
|
|
|
return True # because it is added locally
|
|
|
|
|
|
|
|
def _checkcollision(mctx, extractxs):
|
2006-12-05 02:10:31 +03:00
|
|
|
"check for case folding collisions in the destination context"
|
|
|
|
folded = {}
|
2008-03-15 18:02:31 +03:00
|
|
|
for fn in mctx:
|
2011-12-12 12:10:19 +04:00
|
|
|
fold = util.normcase(fn)
|
2006-12-05 02:10:31 +03:00
|
|
|
if fold in folded:
|
|
|
|
raise util.Abort(_("case-folding collision between %s and %s")
|
|
|
|
% (fn, folded[fold]))
|
|
|
|
folded[fold] = fn
|
|
|
|
|
icasefs: make case-folding collision detection as deletion aware (issue3648)
Before this patch, case-folding collision is checked simply between
manifests of each merged revisions.
So, files may be considered as colliding each other, even though one
of them is already deleted on one of merged branches: in such case,
merge causes deleting it, so case-folding collision doesn't occur.
This patch checks whether both of files colliding each other still
remain after merge or not, and ignores collision if at least one of
them is deleted by merge.
In the case that one of colliding files is deleted on one of merged
branches and changed on another, file is considered to still remain
after merge, even though it may be deleted by merge, if "deleting" of
it is chosen in "manifestmerge()".
This avoids fail to merge by case-folding collisions after choices
from "changing" and "deleting" of files.
This patch adds only tests for "removed remotely" code paths in
"_remains()", because other ones are tested by existing tests in
"test-casecollision-merge.t".
2012-10-31 11:50:22 +04:00
|
|
|
if extractxs:
|
|
|
|
wctx, actx = extractxs
|
2012-04-15 20:11:29 +04:00
|
|
|
# class to delay looking up copy mapping
|
|
|
|
class pathcopies(object):
|
|
|
|
@util.propertycache
|
|
|
|
def map(self):
|
|
|
|
# {dst@mctx: src@wctx} copy mapping
|
|
|
|
return copies.pathcopies(wctx, mctx)
|
|
|
|
pc = pathcopies()
|
|
|
|
|
2011-12-16 16:21:27 +04:00
|
|
|
for fn in wctx:
|
|
|
|
fold = util.normcase(fn)
|
|
|
|
mfn = folded.get(fold, None)
|
icasefs: make case-folding collision detection as deletion aware (issue3648)
Before this patch, case-folding collision is checked simply between
manifests of each merged revisions.
So, files may be considered as colliding each other, even though one
of them is already deleted on one of merged branches: in such case,
merge causes deleting it, so case-folding collision doesn't occur.
This patch checks whether both of files colliding each other still
remain after merge or not, and ignores collision if at least one of
them is deleted by merge.
In the case that one of colliding files is deleted on one of merged
branches and changed on another, file is considered to still remain
after merge, even though it may be deleted by merge, if "deleting" of
it is chosen in "manifestmerge()".
This avoids fail to merge by case-folding collisions after choices
from "changing" and "deleting" of files.
This patch adds only tests for "removed remotely" code paths in
"_remains()", because other ones are tested by existing tests in
"test-casecollision-merge.t".
2012-10-31 11:50:22 +04:00
|
|
|
if (mfn and mfn != fn and pc.map.get(mfn) != fn and
|
|
|
|
_remains(fn, wctx.manifest(), actx.manifest(), True) and
|
|
|
|
_remains(mfn, mctx.manifest(), actx.manifest())):
|
2011-12-16 16:21:27 +04:00
|
|
|
raise util.Abort(_("case-folding collision between %s and %s")
|
|
|
|
% (mfn, fn))
|
|
|
|
|
2008-03-15 18:02:31 +03:00
|
|
|
def _forgetremoved(wctx, mctx, branchmerge):
|
2006-09-18 01:47:33 +04:00
|
|
|
"""
|
|
|
|
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.
|
2008-03-13 01:44:08 +03:00
|
|
|
|
|
|
|
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.
|
2006-09-18 01:47:33 +04:00
|
|
|
"""
|
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
actions = []
|
2008-03-13 01:44:08 +03:00
|
|
|
state = branchmerge and 'r' or 'f'
|
|
|
|
for f in wctx.deleted():
|
2008-03-15 18:02:31 +03:00
|
|
|
if f not in mctx:
|
2013-01-09 03:01:33 +04:00
|
|
|
actions.append((f, state))
|
2008-03-13 01:44:08 +03:00
|
|
|
|
|
|
|
if not branchmerge:
|
|
|
|
for f in wctx.removed():
|
2008-03-15 18:02:31 +03:00
|
|
|
if f not in mctx:
|
2013-01-09 03:01:33 +04:00
|
|
|
actions.append((f, "f"))
|
2006-09-18 01:47:33 +04:00
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
return actions
|
2006-09-18 01:47:33 +04:00
|
|
|
|
2006-10-10 01:07:19 +04:00
|
|
|
def manifestmerge(repo, p1, p2, pa, overwrite, partial):
|
2006-09-18 01:13:03 +04:00
|
|
|
"""
|
2010-08-11 16:16:22 +04:00
|
|
|
Merge p1 and p2 with ancestor pa and generate merge action list
|
2006-10-10 11:31:02 +04:00
|
|
|
|
|
|
|
overwrite = whether we clobber working files
|
|
|
|
partial = function to filter file lists
|
2006-09-18 01:13:03 +04:00
|
|
|
"""
|
|
|
|
|
2006-10-10 09:32:30 +04:00
|
|
|
def act(msg, m, f, *args):
|
2006-10-10 01:07:19 +04:00
|
|
|
repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
|
2013-01-09 03:01:33 +04:00
|
|
|
actions.append((f, m) + args)
|
2006-09-18 06:27:30 +04:00
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
actions, copy, movewithdir = [], {}, {}
|
2009-06-09 03:14:44 +04:00
|
|
|
|
2009-06-09 03:14:44 +04:00
|
|
|
if overwrite:
|
2009-06-09 03:14:44 +04:00
|
|
|
pa = p1
|
|
|
|
elif pa == p2: # backwards
|
|
|
|
pa = p1.p1()
|
|
|
|
elif pa and repo.ui.configbool("merge", "followcopies", True):
|
2012-12-27 02:50:17 +04:00
|
|
|
ret = copies.mergecopies(repo, p1, p2, pa)
|
|
|
|
copy, movewithdir, diverge, renamedelete = ret
|
2009-06-09 03:14:44 +04:00
|
|
|
for of, fl in diverge.iteritems():
|
|
|
|
act("divergent renames", "dr", of, fl)
|
2012-05-23 22:50:16 +04:00
|
|
|
for of, fl in renamedelete.iteritems():
|
|
|
|
act("rename and delete", "rd", of, fl)
|
2009-06-09 03:14:44 +04:00
|
|
|
|
|
|
|
repo.ui.note(_("resolving manifests\n"))
|
2011-12-09 20:34:53 +04:00
|
|
|
repo.ui.debug(" overwrite: %s, partial: %s\n"
|
|
|
|
% (bool(overwrite), bool(partial)))
|
|
|
|
repo.ui.debug(" ancestor: %s, local: %s, remote: %s\n" % (pa, p1, p2))
|
2009-06-09 03:14:44 +04:00
|
|
|
|
|
|
|
m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest()
|
|
|
|
copied = set(copy.values())
|
2012-12-27 02:50:17 +04:00
|
|
|
copied.update(movewithdir.values())
|
2006-10-10 01:07:19 +04:00
|
|
|
|
2010-07-01 08:56:35 +04:00
|
|
|
if '.hgsubstate' in m1:
|
2009-11-08 19:29:52 +03:00
|
|
|
# check whether sub state is modified
|
2012-12-12 05:38:14 +04:00
|
|
|
for s in sorted(p1.substate):
|
2009-11-08 19:29:52 +03:00
|
|
|
if p1.sub(s).dirty():
|
|
|
|
m1['.hgsubstate'] += "+"
|
|
|
|
break
|
|
|
|
|
2006-09-18 01:13:03 +04:00
|
|
|
# Compare manifests
|
2013-01-15 05:59:12 +04:00
|
|
|
for f, n in sorted(m1.iteritems()):
|
2006-10-04 23:33:22 +04:00
|
|
|
if partial and not partial(f):
|
|
|
|
continue
|
2006-09-18 01:13:03 +04:00
|
|
|
if f in m2:
|
2013-01-09 05:02:45 +04:00
|
|
|
n2 = m2[f]
|
|
|
|
fl1, fl2, fla = m1.flags(f), m2.flags(f), ma.flags(f)
|
|
|
|
nol = 'l' not in fl1 + fl2 + fla
|
2009-06-09 03:14:44 +04:00
|
|
|
a = ma.get(f, nullid)
|
2013-01-09 05:02:45 +04:00
|
|
|
if n == n2 and fl1 == fl2:
|
|
|
|
pass # same - keep local
|
|
|
|
elif n2 == a and fl2 == fla:
|
|
|
|
pass # remote unchanged - keep local
|
|
|
|
elif n == a and fl1 == fla: # local unchanged - use remote
|
|
|
|
if n == n2: # optimization: keep local content
|
|
|
|
act("update permissions", "e", f, fl2)
|
|
|
|
else:
|
|
|
|
act("remote is newer", "g", f, fl2)
|
|
|
|
elif nol and n2 == a: # remote only changed 'x'
|
|
|
|
act("update permissions", "e", f, fl2)
|
|
|
|
elif nol and n == a: # local only changed 'x'
|
|
|
|
act("remote is newer", "g", f, fl)
|
|
|
|
else: # both changed something
|
|
|
|
act("versions differ", "m", f, f, f, False)
|
2009-06-09 03:14:44 +04:00
|
|
|
elif f in copied: # files we'll deal with on m2 side
|
|
|
|
pass
|
2012-12-27 02:50:17 +04:00
|
|
|
elif f in movewithdir: # directory rename
|
|
|
|
f2 = movewithdir[f]
|
|
|
|
act("remote renamed directory to " + f2, "d", f, None, f2,
|
|
|
|
m1.flags(f))
|
2013-01-15 04:05:12 +04:00
|
|
|
elif f in copy:
|
2006-10-05 00:43:27 +04:00
|
|
|
f2 = copy[f]
|
2013-01-09 05:02:45 +04:00
|
|
|
act("local copied/moved to " + f2, "m", f, f2, f, False)
|
2009-06-09 03:14:44 +04:00
|
|
|
elif f in ma: # clean, a different, no remote
|
2009-06-09 03:14:44 +04:00
|
|
|
if n != ma[f]:
|
2009-06-21 03:13:19 +04:00
|
|
|
if repo.ui.promptchoice(
|
2007-12-27 00:47:16 +03:00
|
|
|
_(" local changed %s which remote deleted\n"
|
|
|
|
"use (c)hanged version or (d)elete?") % f,
|
2009-06-21 03:13:19 +04:00
|
|
|
(_("&Changed"), _("&Delete")), 0):
|
2006-10-10 09:32:30 +04:00
|
|
|
act("prompt delete", "r", f)
|
2009-06-09 03:14:44 +04:00
|
|
|
else:
|
|
|
|
act("prompt keep", "a", f)
|
2009-06-09 03:14:44 +04:00
|
|
|
elif n[20:] == "a": # added, no remote
|
|
|
|
act("remote deleted", "f", f)
|
2012-02-10 03:04:17 +04:00
|
|
|
else:
|
2006-10-10 09:32:30 +04:00
|
|
|
act("other deleted", "r", f)
|
2006-09-18 01:13:03 +04:00
|
|
|
|
2013-01-15 05:59:12 +04:00
|
|
|
for f, n in sorted(m2.iteritems()):
|
2006-10-04 23:33:22 +04:00
|
|
|
if partial and not partial(f):
|
|
|
|
continue
|
2009-06-09 03:14:44 +04:00
|
|
|
if f in m1 or f in copied: # files already visited
|
2006-12-01 02:36:33 +03:00
|
|
|
continue
|
2012-12-27 02:50:17 +04:00
|
|
|
if f in movewithdir:
|
|
|
|
f2 = movewithdir[f]
|
|
|
|
act("local renamed directory to " + f2, "d", None, f, f2,
|
|
|
|
m2.flags(f))
|
|
|
|
elif f in copy:
|
2006-10-05 00:43:27 +04:00
|
|
|
f2 = copy[f]
|
2013-01-15 04:05:12 +04:00
|
|
|
if f2 in m2:
|
2006-12-01 02:36:33 +03:00
|
|
|
act("remote copied to " + f, "m",
|
2013-01-09 05:02:45 +04:00
|
|
|
f2, f, f, False)
|
2013-01-15 04:05:12 +04:00
|
|
|
else:
|
2006-12-01 02:36:33 +03:00
|
|
|
act("remote moved to " + f, "m",
|
2013-01-09 05:02:45 +04:00
|
|
|
f2, f, f, True)
|
2009-06-09 03:14:44 +04:00
|
|
|
elif f not in ma:
|
2012-02-10 03:04:17 +04:00
|
|
|
if (not overwrite
|
|
|
|
and _checkunknownfile(repo, p1, p2, f)):
|
|
|
|
act("remote differs from untracked local",
|
2013-01-09 05:02:45 +04:00
|
|
|
"m", f, f, f, False)
|
2012-02-10 03:04:17 +04:00
|
|
|
else:
|
|
|
|
act("remote created", "g", f, m2.flags(f))
|
2009-06-09 03:14:44 +04:00
|
|
|
elif n != ma[f]:
|
2009-06-21 03:13:19 +04:00
|
|
|
if repo.ui.promptchoice(
|
2009-06-09 03:14:44 +04:00
|
|
|
_("remote changed %s which local deleted\n"
|
|
|
|
"use (c)hanged version or leave (d)eleted?") % f,
|
2009-06-21 03:13:19 +04:00
|
|
|
(_("&Changed"), _("&Deleted")), 0) == 0:
|
2009-06-09 03:14:44 +04:00
|
|
|
act("prompt recreating", "g", f, m2.flags(f))
|
2006-09-18 01:13:03 +04:00
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
return actions
|
2006-09-18 01:13:03 +04:00
|
|
|
|
2009-05-13 16:08:39 +04:00
|
|
|
def actionkey(a):
|
2013-01-09 03:01:33 +04:00
|
|
|
return a[1] == "r" and -1 or 0, a
|
2008-07-01 20:59:31 +04:00
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
def applyupdates(repo, actions, wctx, mctx, actx, overwrite):
|
2010-06-18 10:49:24 +04:00
|
|
|
"""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
|
|
|
|
actx is the context of the common ancestor
|
2010-12-13 19:46:31 +03:00
|
|
|
|
|
|
|
Return a tuple of counts (updated, merged, removed, unresolved) that
|
|
|
|
describes how many files were affected by the update.
|
2010-06-18 10:49:24 +04:00
|
|
|
"""
|
2006-10-10 11:31:02 +04:00
|
|
|
|
2006-09-18 02:39:19 +04:00
|
|
|
updated, merged, removed, unresolved = 0, 0, 0, 0
|
2008-04-11 00:02:24 +04:00
|
|
|
ms = mergestate(repo)
|
2011-04-05 01:21:59 +04:00
|
|
|
ms.reset(wctx.p1().node())
|
2008-04-11 00:02:24 +04:00
|
|
|
moves = []
|
2013-01-09 03:01:33 +04:00
|
|
|
actions.sort(key=actionkey)
|
2008-04-11 00:02:24 +04:00
|
|
|
|
|
|
|
# prescan for merges
|
2013-01-09 03:01:33 +04:00
|
|
|
for a in actions:
|
2007-08-01 21:33:12 +04:00
|
|
|
f, m = a[:2]
|
2013-01-09 03:01:33 +04:00
|
|
|
if m == "m": # merge
|
2013-01-09 05:02:45 +04:00
|
|
|
f2, fd, move = a[2:]
|
2013-01-15 04:05:12 +04:00
|
|
|
if fd == '.hgsubstate': # merged internally
|
2009-06-15 11:45:38 +04:00
|
|
|
continue
|
2009-09-19 03:15:38 +04:00
|
|
|
repo.ui.debug("preserving %s for resolve of %s\n" % (f, fd))
|
2008-04-11 00:02:24 +04:00
|
|
|
fcl = wctx[f]
|
|
|
|
fco = mctx[f2]
|
2010-08-21 19:41:29 +04:00
|
|
|
if mctx == actx: # backwards, use working dir parent as ancestor
|
2010-10-09 23:50:20 +04:00
|
|
|
if fcl.parents():
|
2011-04-05 01:21:59 +04:00
|
|
|
fca = fcl.p1()
|
2010-10-09 23:50:20 +04:00
|
|
|
else:
|
|
|
|
fca = repo.filectx(f, fileid=nullrev)
|
2010-08-21 19:41:29 +04:00
|
|
|
else:
|
|
|
|
fca = fcl.ancestor(fco, actx)
|
|
|
|
if not fca:
|
|
|
|
fca = repo.filectx(f, fileid=nullrev)
|
2013-01-09 05:02:45 +04:00
|
|
|
ms.add(fcl, fco, fca, fd)
|
2008-04-11 00:02:24 +04:00
|
|
|
if f != fd and move:
|
|
|
|
moves.append(f)
|
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
audit = repo.wopener.audit
|
2011-05-21 04:05:00 +04:00
|
|
|
|
2008-04-11 00:02:24 +04:00
|
|
|
# remove renamed files after safely stored
|
|
|
|
for f in moves:
|
2010-08-25 18:23:32 +04:00
|
|
|
if os.path.lexists(repo.wjoin(f)):
|
2009-09-19 03:15:38 +04:00
|
|
|
repo.ui.debug("removing %s\n" % f)
|
2011-05-21 04:05:00 +04:00
|
|
|
audit(f)
|
2013-01-15 04:05:12 +04:00
|
|
|
util.unlinkpath(repo.wjoin(f))
|
2007-08-01 21:33:12 +04:00
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
numupdates = len(actions)
|
|
|
|
for i, a in enumerate(actions):
|
2006-09-18 02:39:19 +04:00
|
|
|
f, m = a[:2]
|
2011-08-17 16:11:46 +04:00
|
|
|
repo.ui.progress(_('updating'), i + 1, item=f, total=numupdates,
|
|
|
|
unit=_('files'))
|
2006-09-18 02:39:19 +04:00
|
|
|
if m == "r": # remove
|
|
|
|
repo.ui.note(_("removing %s\n") % f)
|
2011-05-21 04:05:00 +04:00
|
|
|
audit(f)
|
2009-06-15 11:45:38 +04:00
|
|
|
if f == '.hgsubstate': # subrepo states need updating
|
2011-01-31 15:33:41 +03:00
|
|
|
subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
|
2006-09-18 02:39:19 +04:00
|
|
|
try:
|
2012-12-28 14:55:57 +04:00
|
|
|
util.unlinkpath(repo.wjoin(f), ignoremissing=True)
|
2006-09-18 02:39:19 +04:00
|
|
|
except OSError, inst:
|
2012-12-28 14:55:57 +04:00
|
|
|
repo.ui.warn(_("update failed to remove %s: %s!\n") %
|
|
|
|
(f, inst.strerror))
|
2006-11-17 10:06:54 +03:00
|
|
|
removed += 1
|
2006-10-10 09:41:55 +04:00
|
|
|
elif m == "m": # merge
|
2013-01-15 04:05:12 +04:00
|
|
|
if fd == '.hgsubstate': # subrepo states need updating
|
2012-05-12 17:54:54 +04:00
|
|
|
subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
|
|
|
|
overwrite)
|
2009-06-15 11:45:38 +04:00
|
|
|
continue
|
2013-01-09 05:02:45 +04:00
|
|
|
f2, fd, move = a[2:]
|
2013-01-09 03:01:33 +04:00
|
|
|
audit(fd)
|
2008-04-11 00:02:24 +04:00
|
|
|
r = ms.resolve(fd, wctx, mctx)
|
2009-07-05 13:01:01 +04:00
|
|
|
if r is not None and r > 0:
|
2006-10-05 00:43:27 +04:00
|
|
|
unresolved += 1
|
2006-10-10 09:54:00 +04:00
|
|
|
else:
|
2006-10-16 01:18:09 +04:00
|
|
|
if r is None:
|
|
|
|
updated += 1
|
|
|
|
else:
|
|
|
|
merged += 1
|
2006-09-18 02:39:19 +04:00
|
|
|
elif m == "g": # get
|
2006-12-30 05:04:31 +03:00
|
|
|
flags = a[2]
|
2006-09-18 02:39:19 +04:00
|
|
|
repo.ui.note(_("getting %s\n") % f)
|
2013-01-10 03:45:51 +04:00
|
|
|
repo.wwrite(f, mctx.filectx(f).data(), flags)
|
2006-09-18 02:39:19 +04:00
|
|
|
updated += 1
|
2009-06-15 11:45:38 +04:00
|
|
|
if f == '.hgsubstate': # subrepo states need updating
|
2011-01-31 15:33:41 +03:00
|
|
|
subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
|
2006-12-01 02:36:33 +03:00
|
|
|
elif m == "d": # directory rename
|
2006-12-30 05:04:31 +03:00
|
|
|
f2, fd, flags = a[2:]
|
2006-12-01 02:36:33 +03:00
|
|
|
if f:
|
|
|
|
repo.ui.note(_("moving %s to %s\n") % (f, fd))
|
2011-05-21 04:05:00 +04:00
|
|
|
audit(f)
|
2013-01-10 03:45:51 +04:00
|
|
|
repo.wwrite(fd, wctx.filectx(f).data(), flags)
|
2011-01-02 21:34:41 +03:00
|
|
|
util.unlinkpath(repo.wjoin(f))
|
2006-12-01 02:36:33 +03:00
|
|
|
if f2:
|
|
|
|
repo.ui.note(_("getting %s to %s\n") % (f2, fd))
|
2013-01-10 03:45:51 +04:00
|
|
|
repo.wwrite(fd, mctx.filectx(f2).data(), flags)
|
2006-12-01 02:36:33 +03:00
|
|
|
updated += 1
|
2007-06-22 03:02:03 +04:00
|
|
|
elif m == "dr": # divergent renames
|
|
|
|
fl = a[2]
|
2010-10-10 18:50:25 +04:00
|
|
|
repo.ui.warn(_("note: possible conflict - %s was renamed "
|
|
|
|
"multiple times to:\n") % f)
|
2007-06-22 03:02:03 +04:00
|
|
|
for nf in fl:
|
|
|
|
repo.ui.warn(" %s\n" % nf)
|
2012-05-23 22:50:16 +04:00
|
|
|
elif m == "rd": # rename and delete
|
|
|
|
fl = a[2]
|
|
|
|
repo.ui.warn(_("note: possible conflict - %s was deleted "
|
|
|
|
"and renamed to:\n") % f)
|
|
|
|
for nf in fl:
|
|
|
|
repo.ui.warn(" %s\n" % nf)
|
2006-09-18 02:39:19 +04:00
|
|
|
elif m == "e": # exec
|
2006-12-30 05:04:31 +03:00
|
|
|
flags = a[2]
|
2013-01-09 03:01:33 +04:00
|
|
|
audit(f)
|
2011-05-06 17:22:31 +04:00
|
|
|
util.setflags(repo.wjoin(f), 'l' in flags, 'x' in flags)
|
2013-01-10 03:44:23 +04:00
|
|
|
updated += 1
|
2010-09-06 19:35:49 +04:00
|
|
|
ms.commit()
|
2011-08-17 16:11:46 +04:00
|
|
|
repo.ui.progress(_('updating'), None, total=numupdates, unit=_('files'))
|
2006-09-18 02:39:19 +04:00
|
|
|
|
|
|
|
return updated, merged, removed, unresolved
|
|
|
|
|
2012-12-05 00:54:18 +04:00
|
|
|
def calculateupdates(repo, tctx, mctx, ancestor, branchmerge, force, partial):
|
|
|
|
"Calculate the actions needed to merge mctx into tctx"
|
2013-01-09 03:01:33 +04:00
|
|
|
actions = []
|
2012-12-05 00:54:18 +04:00
|
|
|
folding = not util.checkcase(repo.path)
|
|
|
|
if folding:
|
|
|
|
# collision check is not needed for clean update
|
|
|
|
if (not branchmerge and
|
|
|
|
(force or not tctx.dirty(missing=True, branch=False))):
|
|
|
|
_checkcollision(mctx, None)
|
|
|
|
else:
|
2012-12-07 08:07:44 +04:00
|
|
|
_checkcollision(mctx, (tctx, ancestor))
|
2012-12-05 00:54:18 +04:00
|
|
|
if not force:
|
|
|
|
_checkunknown(repo, tctx, mctx)
|
2012-12-05 00:54:18 +04:00
|
|
|
if tctx.rev() is None:
|
2013-01-09 03:01:33 +04:00
|
|
|
actions += _forgetremoved(tctx, mctx, branchmerge)
|
|
|
|
actions += manifestmerge(repo, tctx, mctx,
|
|
|
|
ancestor,
|
|
|
|
force and not branchmerge,
|
|
|
|
partial)
|
|
|
|
return actions
|
|
|
|
|
|
|
|
def recordupdates(repo, actions, branchmerge):
|
2006-10-10 11:31:02 +04:00
|
|
|
"record merge actions to the dirstate"
|
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
for a in actions:
|
2006-09-18 02:39:19 +04:00
|
|
|
f, m = a[:2]
|
|
|
|
if m == "r": # remove
|
|
|
|
if branchmerge:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.remove(f)
|
2006-09-18 02:39:19 +04:00
|
|
|
else:
|
2011-05-27 02:15:35 +04:00
|
|
|
repo.dirstate.drop(f)
|
2009-02-15 19:50:48 +03:00
|
|
|
elif m == "a": # re-add
|
|
|
|
if not branchmerge:
|
|
|
|
repo.dirstate.add(f)
|
2006-09-18 02:39:19 +04:00
|
|
|
elif m == "f": # forget
|
2011-05-27 02:15:35 +04:00
|
|
|
repo.dirstate.drop(f)
|
2009-01-07 04:11:17 +03:00
|
|
|
elif m == "e": # exec change
|
2009-01-14 00:41:06 +03:00
|
|
|
repo.dirstate.normallookup(f)
|
2009-01-07 04:11:17 +03:00
|
|
|
elif m == "g": # get
|
2006-09-18 02:39:19 +04:00
|
|
|
if branchmerge:
|
2010-04-20 13:17:01 +04:00
|
|
|
repo.dirstate.otherparent(f)
|
2006-09-18 02:39:19 +04:00
|
|
|
else:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.normal(f)
|
2006-09-18 02:39:19 +04:00
|
|
|
elif m == "m": # merge
|
2013-01-09 05:02:45 +04:00
|
|
|
f2, fd, move = a[2:]
|
2006-10-05 04:08:04 +04:00
|
|
|
if branchmerge:
|
|
|
|
# We've done a branch merge, mark this file as merged
|
|
|
|
# so that we properly record the merger later
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.merge(fd)
|
2006-10-14 02:58:04 +04:00
|
|
|
if f != f2: # copy/rename
|
|
|
|
if move:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.remove(f)
|
2006-10-14 02:58:04 +04:00
|
|
|
if f != fd:
|
|
|
|
repo.dirstate.copy(f, fd)
|
|
|
|
else:
|
|
|
|
repo.dirstate.copy(f2, fd)
|
2006-10-05 04:08:04 +04:00
|
|
|
else:
|
|
|
|
# We've update-merged a locally modified file, so
|
|
|
|
# we set the dirstate to emulate a normal checkout
|
|
|
|
# of that file some time in the past. Thus our
|
|
|
|
# merge will appear as a normal local file
|
|
|
|
# modification.
|
2010-05-04 11:57:16 +04:00
|
|
|
if f2 == fd: # file not locally copied/moved
|
|
|
|
repo.dirstate.normallookup(fd)
|
2006-10-10 09:41:55 +04:00
|
|
|
if move:
|
2011-05-27 02:15:35 +04:00
|
|
|
repo.dirstate.drop(f)
|
2006-12-01 02:36:33 +03:00
|
|
|
elif m == "d": # directory rename
|
|
|
|
f2, fd, flag = a[2:]
|
2007-07-06 01:01:07 +04:00
|
|
|
if not f2 and f not in repo.dirstate:
|
|
|
|
# untracked file moved
|
|
|
|
continue
|
2006-12-01 02:36:33 +03:00
|
|
|
if branchmerge:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.add(fd)
|
2006-12-01 02:36:33 +03:00
|
|
|
if f:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.remove(f)
|
2006-12-01 02:36:33 +03:00
|
|
|
repo.dirstate.copy(f, fd)
|
|
|
|
if f2:
|
|
|
|
repo.dirstate.copy(f2, fd)
|
|
|
|
else:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.normal(fd)
|
2006-12-01 02:36:33 +03:00
|
|
|
if f:
|
2011-05-27 02:15:35 +04:00
|
|
|
repo.dirstate.drop(f)
|
2006-09-18 02:39:19 +04:00
|
|
|
|
rebase: allow collapsing branches in place (issue3111)
We allow rebase plus collapse, but not collapse only? I imagine people would
rebase first then collapse once they are sure the rebase is correct and it is
the right time to finish it.
I was reluctant to submit this patch for reasons detailed below, but it
improves rebase --collapse usefulness so much it is worth the ugliness.
The fix is ugly because we should be fixing the collapse code path rather than
the merge. Collapsing by merging changesets repeatedly is inefficient compared
to what commit --amend does: commitctx(), update, strip. The problem with the
latter is, to generate the synthetic changeset, copy records are gathered with
copies.pathcopies(). copies.pathcopies() is still implemented with merging in
mind and discards information like file replaced by the copy of another,
criss-cross copies and so forth. I believe this information should not be lost,
even if we decide not to interpret it fully later, at merge time.
The second issue with improving rebase --collapse is the option should not be
there to begin with. Rebasing and collapsing are orthogonal and a dedicated
command would probably enable a better, simpler ui. We should avoid advertizing
rebase --collapse, but with this fix it becomes the best shipped solution to
collapse changesets.
And for the record, available techniques are:
- revert + commit + strip: lose copies
- mq/qfold: repeated patching() (mostly correct, fragile)
- rebase: repeated merges (mostly correct, fragile)
- collapse: revert + tag rewriting wizardry, lose copies
- histedit: repeated patching() (mostly correct, fragile)
- amend: copies.pathcopies() + commitctx() + update + strip
2012-05-03 17:14:58 +04:00
|
|
|
def update(repo, node, branchmerge, force, partial, ancestor=None,
|
|
|
|
mergeancestor=False):
|
2006-10-10 11:31:02 +04:00
|
|
|
"""
|
|
|
|
Perform a merge between the working directory and the given node
|
|
|
|
|
2009-11-05 12:53:36 +03:00
|
|
|
node = the node to update to, or None if unspecified
|
2006-10-10 11:31:02 +04:00
|
|
|
branchmerge = whether to merge between branches
|
|
|
|
force = whether to force branch merging or file overwriting
|
|
|
|
partial = a function to filter file lists (dirstate not updated)
|
rebase: allow collapsing branches in place (issue3111)
We allow rebase plus collapse, but not collapse only? I imagine people would
rebase first then collapse once they are sure the rebase is correct and it is
the right time to finish it.
I was reluctant to submit this patch for reasons detailed below, but it
improves rebase --collapse usefulness so much it is worth the ugliness.
The fix is ugly because we should be fixing the collapse code path rather than
the merge. Collapsing by merging changesets repeatedly is inefficient compared
to what commit --amend does: commitctx(), update, strip. The problem with the
latter is, to generate the synthetic changeset, copy records are gathered with
copies.pathcopies(). copies.pathcopies() is still implemented with merging in
mind and discards information like file replaced by the copy of another,
criss-cross copies and so forth. I believe this information should not be lost,
even if we decide not to interpret it fully later, at merge time.
The second issue with improving rebase --collapse is the option should not be
there to begin with. Rebasing and collapsing are orthogonal and a dedicated
command would probably enable a better, simpler ui. We should avoid advertizing
rebase --collapse, but with this fix it becomes the best shipped solution to
collapse changesets.
And for the record, available techniques are:
- revert + commit + strip: lose copies
- mq/qfold: repeated patching() (mostly correct, fragile)
- rebase: repeated merges (mostly correct, fragile)
- collapse: revert + tag rewriting wizardry, lose copies
- histedit: repeated patching() (mostly correct, fragile)
- amend: copies.pathcopies() + commitctx() + update + strip
2012-05-03 17:14:58 +04:00
|
|
|
mergeancestor = 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.
|
2009-11-05 12:53:36 +03:00
|
|
|
|
|
|
|
The table below shows all the behaviors of the update command
|
|
|
|
given the -c and -C 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, on the same named
|
|
|
|
branch, or on another named branch).
|
|
|
|
|
2010-09-14 14:20:51 +04:00
|
|
|
This logic is tested by test-update-branches.t.
|
2009-11-05 12:53:36 +03:00
|
|
|
|
|
|
|
-c -C dirty rev | linear same cross
|
|
|
|
n n n n | ok (1) x
|
2009-11-05 12:53:59 +03:00
|
|
|
n n n y | ok ok ok
|
|
|
|
n n y * | merge (2) (2)
|
2009-11-05 12:53:36 +03:00
|
|
|
n y * * | --- discard ---
|
2009-11-05 12:53:59 +03:00
|
|
|
y n y * | --- (3) ---
|
2009-11-05 12:53:36 +03:00
|
|
|
y n n * | --- ok ---
|
2009-11-05 12:53:59 +03:00
|
|
|
y y * * | --- (4) ---
|
2009-11-05 12:53:36 +03:00
|
|
|
|
|
|
|
x = can't happen
|
|
|
|
* = don't-care
|
2009-11-05 12:53:59 +03:00
|
|
|
1 = abort: crosses branches (use 'hg merge' or 'hg update -c')
|
|
|
|
2 = abort: crosses branches (use 'hg merge' to merge or
|
|
|
|
use 'hg update -C' to discard changes)
|
|
|
|
3 = abort: uncommitted local changes
|
|
|
|
4 = incompatible options (checked in commands.py)
|
2010-12-13 19:46:31 +03:00
|
|
|
|
|
|
|
Return the same tuple as applyupdates().
|
2006-10-10 11:31:02 +04:00
|
|
|
"""
|
2006-08-08 19:56:48 +04:00
|
|
|
|
2009-11-05 12:53:59 +03:00
|
|
|
onode = node
|
2007-07-22 01:02:10 +04:00
|
|
|
wlock = repo.wlock()
|
2007-07-22 01:02:10 +04:00
|
|
|
try:
|
2008-06-26 23:35:46 +04:00
|
|
|
wc = repo[None]
|
2007-07-22 01:02:10 +04:00
|
|
|
if node is None:
|
|
|
|
# tip of current branch
|
|
|
|
try:
|
2012-05-13 16:04:04 +04:00
|
|
|
node = repo.branchtip(wc.branch())
|
|
|
|
except error.RepoLookupError:
|
2007-12-03 00:15:49 +03:00
|
|
|
if wc.branch() == "default": # no default branch!
|
|
|
|
node = repo.lookup("tip") # update to tip
|
|
|
|
else:
|
|
|
|
raise util.Abort(_("branch %s not found") % wc.branch())
|
2007-07-22 01:02:10 +04:00
|
|
|
overwrite = force and not branchmerge
|
|
|
|
pl = wc.parents()
|
2008-06-26 23:35:46 +04:00
|
|
|
p1, p2 = pl[0], repo[node]
|
2011-04-05 00:25:20 +04:00
|
|
|
if ancestor:
|
|
|
|
pa = repo[ancestor]
|
|
|
|
else:
|
|
|
|
pa = p1.ancestor(p2)
|
|
|
|
|
2007-07-22 01:02:10 +04:00
|
|
|
fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
|
|
|
|
|
|
|
|
### check phase
|
|
|
|
if not overwrite and len(pl) > 1:
|
|
|
|
raise util.Abort(_("outstanding uncommitted merges"))
|
2008-03-24 18:01:05 +03:00
|
|
|
if branchmerge:
|
|
|
|
if pa == p2:
|
2010-06-20 23:21:56 +04:00
|
|
|
raise util.Abort(_("merging with a working directory ancestor"
|
|
|
|
" has no effect"))
|
2008-03-24 18:01:05 +03:00
|
|
|
elif pa == p1:
|
rebase: allow collapsing branches in place (issue3111)
We allow rebase plus collapse, but not collapse only? I imagine people would
rebase first then collapse once they are sure the rebase is correct and it is
the right time to finish it.
I was reluctant to submit this patch for reasons detailed below, but it
improves rebase --collapse usefulness so much it is worth the ugliness.
The fix is ugly because we should be fixing the collapse code path rather than
the merge. Collapsing by merging changesets repeatedly is inefficient compared
to what commit --amend does: commitctx(), update, strip. The problem with the
latter is, to generate the synthetic changeset, copy records are gathered with
copies.pathcopies(). copies.pathcopies() is still implemented with merging in
mind and discards information like file replaced by the copy of another,
criss-cross copies and so forth. I believe this information should not be lost,
even if we decide not to interpret it fully later, at merge time.
The second issue with improving rebase --collapse is the option should not be
there to begin with. Rebasing and collapsing are orthogonal and a dedicated
command would probably enable a better, simpler ui. We should avoid advertizing
rebase --collapse, but with this fix it becomes the best shipped solution to
collapse changesets.
And for the record, available techniques are:
- revert + commit + strip: lose copies
- mq/qfold: repeated patching() (mostly correct, fragile)
- rebase: repeated merges (mostly correct, fragile)
- collapse: revert + tag rewriting wizardry, lose copies
- histedit: repeated patching() (mostly correct, fragile)
- amend: copies.pathcopies() + commitctx() + update + strip
2012-05-03 17:14:58 +04:00
|
|
|
if not mergeancestor and p1.branch() == p2.branch():
|
2011-12-07 21:23:01 +04:00
|
|
|
raise util.Abort(_("nothing to merge"),
|
|
|
|
hint=_("use 'hg update' "
|
|
|
|
"or check 'hg heads'"))
|
2008-03-24 18:01:05 +03:00
|
|
|
if not force and (wc.files() or wc.deleted()):
|
2011-12-07 21:23:01 +04:00
|
|
|
raise util.Abort(_("outstanding uncommitted changes"),
|
|
|
|
hint=_("use 'hg status' to list changes"))
|
2012-12-12 05:38:14 +04:00
|
|
|
for s in sorted(wc.substate):
|
2011-02-16 19:56:11 +03:00
|
|
|
if wc.sub(s).dirty():
|
|
|
|
raise util.Abort(_("outstanding uncommitted changes in "
|
|
|
|
"subrepository '%s'") % s)
|
|
|
|
|
2008-03-24 18:01:05 +03:00
|
|
|
elif not overwrite:
|
2010-09-24 21:46:54 +04:00
|
|
|
if pa == p1 or pa == p2: # linear
|
2008-03-24 18:01:05 +03:00
|
|
|
pass # all good
|
2011-06-18 00:21:02 +04:00
|
|
|
elif wc.dirty(missing=True):
|
2010-10-10 02:02:28 +04:00
|
|
|
raise util.Abort(_("crosses branches (merge branches or use"
|
|
|
|
" --clean to discard changes)"))
|
2009-11-05 12:53:59 +03:00
|
|
|
elif onode is None:
|
2011-05-31 22:52:22 +04:00
|
|
|
raise util.Abort(_("crosses branches (merge branches or update"
|
2010-10-10 02:02:28 +04:00
|
|
|
" --check to force update)"))
|
2008-03-24 18:01:05 +03:00
|
|
|
else:
|
2009-11-05 12:53:59 +03:00
|
|
|
# Allow jumping branches if clean and specific rev given
|
2012-02-09 23:16:20 +04:00
|
|
|
pa = p1
|
2007-07-22 01:02:10 +04:00
|
|
|
|
|
|
|
### calculate phase
|
2013-01-09 03:01:33 +04:00
|
|
|
actions = calculateupdates(repo, wc, p2, pa,
|
|
|
|
branchmerge, force, partial)
|
2007-07-22 01:02:10 +04:00
|
|
|
|
|
|
|
### apply phase
|
2011-03-08 00:03:10 +03:00
|
|
|
if not branchmerge: # just jump to the new rev
|
2007-07-22 01:02:10 +04:00
|
|
|
fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
|
|
|
|
if not partial:
|
|
|
|
repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
|
|
|
|
|
2013-01-09 03:01:33 +04:00
|
|
|
stats = applyupdates(repo, actions, wc, p2, pa, overwrite)
|
2007-07-22 01:02:10 +04:00
|
|
|
|
|
|
|
if not partial:
|
2012-04-30 00:25:55 +04:00
|
|
|
repo.setparents(fp1, fp2)
|
2013-01-09 03:01:33 +04:00
|
|
|
recordupdates(repo, actions, branchmerge)
|
2011-03-08 03:21:50 +03:00
|
|
|
if not branchmerge:
|
2007-07-22 01:02:10 +04:00
|
|
|
repo.dirstate.setbranch(p2.branch())
|
|
|
|
finally:
|
2009-04-22 04:01:22 +04:00
|
|
|
wlock.release()
|
2010-02-17 17:43:21 +03:00
|
|
|
|
|
|
|
if not partial:
|
|
|
|
repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
|
|
|
|
return stats
|