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
|
|
|
|
# GNU General Public License version 2, incorporated herein by reference.
|
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 _
|
2009-06-15 11:45:38 +04:00
|
|
|
import 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
|
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)
|
2008-04-11 21:52:56 +04:00
|
|
|
def _read(self):
|
|
|
|
self._state = {}
|
|
|
|
try:
|
2008-04-12 22:51:26 +04:00
|
|
|
localnode = None
|
2008-04-11 21:52:56 +04:00
|
|
|
f = self._repo.opener("merge/state")
|
2008-04-12 22:51:26 +04:00
|
|
|
for i, l in enumerate(f):
|
|
|
|
if i == 0:
|
|
|
|
localnode = l[:-1]
|
|
|
|
else:
|
|
|
|
bits = l[:-1].split("\0")
|
|
|
|
self._state[bits[0]] = bits[1:]
|
|
|
|
self._local = bin(localnode)
|
2008-04-11 21:52:56 +04:00
|
|
|
except IOError, err:
|
|
|
|
if err.errno != errno.ENOENT:
|
|
|
|
raise
|
|
|
|
def _write(self):
|
|
|
|
f = self._repo.opener("merge/state", "w")
|
|
|
|
f.write(hex(self._local) + "\n")
|
2009-01-12 11:16:03 +03:00
|
|
|
for d, v in self._state.iteritems():
|
2008-04-11 21:52:56 +04:00
|
|
|
f.write("\0".join([d] + v) + "\n")
|
2008-04-11 00:02:24 +04:00
|
|
|
def add(self, fcl, fco, fca, fd, flags):
|
2008-04-11 14:04:26 +04:00
|
|
|
hash = util.sha1(fcl.path()).hexdigest()
|
2008-04-11 00:02:24 +04:00
|
|
|
self._repo.opener("merge/" + hash, "w").write(fcl.data())
|
2008-04-11 21:52:56 +04:00
|
|
|
self._state[fd] = ['u', hash, fcl.path(), fca.path(),
|
|
|
|
hex(fca.filenode()), fco.path(), flags]
|
|
|
|
self._write()
|
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
|
|
|
|
self._write()
|
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
|
|
|
f = self._repo.opener("merge/" + hash)
|
|
|
|
self._repo.wwrite(dfile, f.read(), flags)
|
|
|
|
fcd = wctx[dfile]
|
|
|
|
fco = octx[ofile]
|
|
|
|
fca = self._repo.filectx(afile, fileid=anode)
|
|
|
|
r = filemerge.filemerge(self._repo, self._local, lfile, fcd, fco, fca)
|
|
|
|
if not r:
|
|
|
|
self.mark(dfile, 'r')
|
|
|
|
return r
|
2006-08-04 00:24:41 +04:00
|
|
|
|
2008-03-15 18:02:31 +03:00
|
|
|
def _checkunknown(wctx, mctx):
|
2006-10-10 11:31:02 +04:00
|
|
|
"check for collisions between unknown files and files in mctx"
|
2006-10-03 10:21:46 +04:00
|
|
|
for f in wctx.unknown():
|
2008-03-15 18:02:31 +03:00
|
|
|
if f in mctx and mctx[f].cmp(wctx[f].data()):
|
|
|
|
raise util.Abort(_("untracked file in working directory differs"
|
|
|
|
" from file in requested revision: '%s'") % f)
|
2006-09-18 01:47:33 +04:00
|
|
|
|
2008-03-15 18:02:31 +03:00
|
|
|
def _checkcollision(mctx):
|
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:
|
2006-12-05 02:10:31 +03:00
|
|
|
fold = fn.lower()
|
|
|
|
if fold in folded:
|
|
|
|
raise util.Abort(_("case-folding collision between %s and %s")
|
|
|
|
% (fn, folded[fold]))
|
|
|
|
folded[fold] = 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
|
|
|
"""
|
|
|
|
|
|
|
|
action = []
|
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:
|
2008-03-13 01:44:08 +03:00
|
|
|
action.append((f, state))
|
|
|
|
|
|
|
|
if not branchmerge:
|
|
|
|
for f in wctx.removed():
|
2008-03-15 18:02:31 +03:00
|
|
|
if f not in mctx:
|
2008-03-13 01:44:08 +03:00
|
|
|
action.append((f, "f"))
|
2006-09-18 01:47:33 +04:00
|
|
|
|
|
|
|
return action
|
|
|
|
|
2006-10-10 01:07:19 +04:00
|
|
|
def manifestmerge(repo, p1, p2, pa, overwrite, partial):
|
2006-09-18 01:13:03 +04:00
|
|
|
"""
|
2006-10-10 11:31:02 +04:00
|
|
|
Merge p1 and p2 with ancestor ma and generate merge action list
|
|
|
|
|
|
|
|
overwrite = whether we clobber working files
|
|
|
|
partial = function to filter file lists
|
2006-09-18 01:13:03 +04:00
|
|
|
"""
|
|
|
|
|
2009-06-09 03:14:44 +04:00
|
|
|
def fmerge(f, f2, fa):
|
2006-12-30 05:04:31 +03:00
|
|
|
"""merge flags"""
|
2007-12-28 07:47:44 +03:00
|
|
|
a, m, n = ma.flags(fa), m1.flags(f), m2.flags(f2)
|
|
|
|
if m == n: # flags agree
|
|
|
|
return m # unchanged
|
2009-06-09 03:14:44 +04:00
|
|
|
if m and n and not a: # flags set, don't agree, differ from parent
|
2009-06-21 03:13:19 +04:00
|
|
|
r = repo.ui.promptchoice(
|
2009-06-09 03:14:44 +04:00
|
|
|
_(" conflicting flags for %s\n"
|
|
|
|
"(n)one, e(x)ec or sym(l)ink?") % f,
|
2009-06-21 03:13:19 +04:00
|
|
|
(_("&None"), _("E&xec"), _("Sym&link")), 0)
|
|
|
|
if r == 1: return "x" # Exec
|
|
|
|
if r == 2: return "l" # Symlink
|
|
|
|
return ""
|
2007-12-28 07:47:44 +03:00
|
|
|
if m and m != a: # changed from a to m
|
|
|
|
return m
|
|
|
|
if n and n != a: # changed from a to n
|
|
|
|
return n
|
|
|
|
return '' # flag was cleared
|
2006-09-18 05:38:02 +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))
|
2006-09-18 06:27:30 +04:00
|
|
|
action.append((f, m) + args)
|
|
|
|
|
2009-06-09 03:14:44 +04:00
|
|
|
action, copy = [], {}
|
|
|
|
|
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):
|
|
|
|
dirs = repo.ui.configbool("merge", "followdirs", True)
|
|
|
|
copy, diverge = copies.copies(repo, p1, p2, pa, dirs)
|
|
|
|
for of, fl in diverge.iteritems():
|
|
|
|
act("divergent renames", "dr", of, fl)
|
|
|
|
|
|
|
|
repo.ui.note(_("resolving manifests\n"))
|
2009-09-19 03:15:38 +04:00
|
|
|
repo.ui.debug(" overwrite %s partial %s\n" % (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())
|
2006-10-10 01:07:19 +04:00
|
|
|
|
2006-09-18 01:13:03 +04:00
|
|
|
# Compare manifests
|
|
|
|
for f, n in 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:
|
2009-06-09 03:14:44 +04:00
|
|
|
rflags = fmerge(f, f, f)
|
2009-06-09 03:14:44 +04:00
|
|
|
a = ma.get(f, nullid)
|
|
|
|
if n == m2[f] or m2[f] == a: # same or local newer
|
|
|
|
if m1.flags(f) != rflags:
|
|
|
|
act("update permissions", "e", f, rflags)
|
|
|
|
elif n == a: # remote newer
|
|
|
|
act("remote is newer", "g", f, rflags)
|
|
|
|
else: # both changed
|
|
|
|
act("versions differ", "m", f, f, f, rflags, False)
|
|
|
|
elif f in copied: # files we'll deal with on m2 side
|
|
|
|
pass
|
2006-10-05 00:43:27 +04:00
|
|
|
elif f in copy:
|
|
|
|
f2 = copy[f]
|
2006-12-01 02:36:33 +03:00
|
|
|
if f2 not in m2: # directory rename
|
|
|
|
act("remote renamed directory to " + f2, "d",
|
2006-12-30 05:04:31 +03:00
|
|
|
f, None, f2, m1.flags(f))
|
2009-06-09 03:14:44 +04:00
|
|
|
else: # case 2 A,B/B/B or case 4,21 A/B/B
|
|
|
|
act("local copied/moved to " + f2, "m",
|
2006-12-01 02:36:33 +03:00
|
|
|
f, f2, f, fmerge(f, f2, f2), 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)
|
2009-06-09 03:14:44 +04:00
|
|
|
elif n[20:] != "u":
|
2006-10-10 09:32:30 +04:00
|
|
|
act("other deleted", "r", f)
|
2006-09-18 01:13:03 +04:00
|
|
|
|
|
|
|
for f, n in 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
|
2006-10-05 00:43:27 +04:00
|
|
|
if f in copy:
|
|
|
|
f2 = copy[f]
|
2006-12-01 02:36:33 +03:00
|
|
|
if f2 not in m1: # directory rename
|
|
|
|
act("local renamed directory to " + f2, "d",
|
2006-12-30 05:04:31 +03:00
|
|
|
None, f, f2, m2.flags(f))
|
2006-12-01 02:36:33 +03:00
|
|
|
elif f2 in m2: # rename case 1, A/A,B/A
|
2006-12-01 02:36:33 +03:00
|
|
|
act("remote copied to " + f, "m",
|
|
|
|
f2, f, f, fmerge(f2, f, f2), False)
|
|
|
|
else: # case 3,20 A/B/A
|
|
|
|
act("remote moved to " + f, "m",
|
|
|
|
f2, f, f, fmerge(f2, f, f2), True)
|
2009-06-09 03:14:44 +04:00
|
|
|
elif f not in ma:
|
2006-12-30 05:04:31 +03:00
|
|
|
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
|
|
|
|
|
|
|
return action
|
|
|
|
|
2009-05-13 16:08:39 +04:00
|
|
|
def actionkey(a):
|
|
|
|
return a[1] == 'r' and -1 or 0, a
|
2008-07-01 20:59:31 +04:00
|
|
|
|
2006-10-10 05:32:03 +04:00
|
|
|
def applyupdates(repo, action, wctx, mctx):
|
2006-10-10 11:31:02 +04:00
|
|
|
"apply the merge action list to the working directory"
|
|
|
|
|
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)
|
|
|
|
ms.reset(wctx.parents()[0].node())
|
|
|
|
moves = []
|
2009-05-13 16:08:39 +04:00
|
|
|
action.sort(key=actionkey)
|
2009-06-15 11:45:38 +04:00
|
|
|
substate = wctx.substate # prime
|
2008-04-11 00:02:24 +04:00
|
|
|
|
|
|
|
# prescan for merges
|
2007-08-01 21:33:12 +04:00
|
|
|
for a in action:
|
|
|
|
f, m = a[:2]
|
|
|
|
if m == 'm': # merge
|
|
|
|
f2, fd, flags, move = a[2:]
|
2009-06-15 11:45:38 +04:00
|
|
|
if f == '.hgsubstate': # merged internally
|
|
|
|
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]
|
|
|
|
fca = fcl.ancestor(fco) or repo.filectx(f, fileid=nullrev)
|
|
|
|
ms.add(fcl, fco, fca, fd, flags)
|
|
|
|
if f != fd and move:
|
|
|
|
moves.append(f)
|
|
|
|
|
|
|
|
# remove renamed files after safely stored
|
|
|
|
for f in moves:
|
|
|
|
if util.lexists(repo.wjoin(f)):
|
2009-09-19 03:15:38 +04:00
|
|
|
repo.ui.debug("removing %s\n" % f)
|
2008-04-11 00:02:24 +04:00
|
|
|
os.unlink(repo.wjoin(f))
|
2007-08-01 21:33:12 +04:00
|
|
|
|
2007-08-10 21:46:03 +04:00
|
|
|
audit_path = util.path_auditor(repo.root)
|
|
|
|
|
2006-09-18 02:39:19 +04:00
|
|
|
for a in action:
|
|
|
|
f, m = a[:2]
|
2006-12-01 02:36:33 +03:00
|
|
|
if f and f[0] == "/":
|
2006-09-18 02:39:19 +04:00
|
|
|
continue
|
|
|
|
if m == "r": # remove
|
|
|
|
repo.ui.note(_("removing %s\n") % f)
|
2007-08-10 21:46:03 +04:00
|
|
|
audit_path(f)
|
2009-06-15 11:45:38 +04:00
|
|
|
if f == '.hgsubstate': # subrepo states need updating
|
|
|
|
subrepo.submerge(repo, wctx, mctx, wctx)
|
2006-09-18 02:39:19 +04:00
|
|
|
try:
|
|
|
|
util.unlink(repo.wjoin(f))
|
|
|
|
except OSError, inst:
|
|
|
|
if inst.errno != errno.ENOENT:
|
|
|
|
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
|
2009-06-15 11:45:38 +04:00
|
|
|
if f == '.hgsubstate': # subrepo states need updating
|
|
|
|
subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx))
|
|
|
|
continue
|
2006-12-30 05:04:31 +03:00
|
|
|
f2, fd, flags, move = a[2:]
|
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
|
2008-08-11 06:55:06 +04:00
|
|
|
util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags)
|
2007-08-02 21:29:10 +04:00
|
|
|
if f != fd and move and util.lexists(repo.wjoin(f)):
|
2009-09-19 03:15:38 +04:00
|
|
|
repo.ui.debug("removing %s\n" % f)
|
2007-08-01 21:33:12 +04:00
|
|
|
os.unlink(repo.wjoin(f))
|
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)
|
2006-10-10 08:23:25 +04:00
|
|
|
t = mctx.filectx(f).data()
|
2006-12-30 05:04:31 +03:00
|
|
|
repo.wwrite(f, t, 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
|
|
|
|
subrepo.submerge(repo, wctx, mctx, wctx)
|
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))
|
|
|
|
t = wctx.filectx(f).data()
|
2006-12-30 05:04:31 +03:00
|
|
|
repo.wwrite(fd, t, flags)
|
2006-12-01 02:36:33 +03:00
|
|
|
util.unlink(repo.wjoin(f))
|
|
|
|
if f2:
|
|
|
|
repo.ui.note(_("getting %s to %s\n") % (f2, fd))
|
|
|
|
t = mctx.filectx(f2).data()
|
2006-12-30 05:04:31 +03:00
|
|
|
repo.wwrite(fd, t, 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]
|
2008-08-31 18:12:02 +04:00
|
|
|
repo.ui.warn(_("warning: detected divergent renames of %s to:\n") % f)
|
2007-06-22 03:02:03 +04:00
|
|
|
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]
|
2008-08-11 06:55:06 +04:00
|
|
|
util.set_flags(repo.wjoin(f), 'l' in flags, 'x' in flags)
|
2006-09-18 02:39:19 +04:00
|
|
|
|
|
|
|
return updated, merged, removed, unresolved
|
|
|
|
|
2006-10-14 02:58:04 +04:00
|
|
|
def recordupdates(repo, action, branchmerge):
|
2006-10-10 11:31:02 +04:00
|
|
|
"record merge actions to the dirstate"
|
|
|
|
|
2006-09-18 02:39:19 +04:00
|
|
|
for a in action:
|
|
|
|
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:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.forget(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
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.forget(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:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.normaldirty(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
|
2006-10-10 08:23:25 +04:00
|
|
|
f2, fd, flag, 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.
|
merge: forcefully mark files that we get from the second parent as dirty
After a hg merge, we want to include in the commit all the files that we
got from the second parent, so that we have the correct file-level
history. To make them visible to hg commit, we try to mark them as dirty.
Unfortunately, right now we can't really mark them as dirty[1] - the
best we can do is to mark them as needing a full comparison of their
contents, but they will still be considered clean if they happen to be
identical to the version in the first parent.
This changeset extends the dirstate format in a compatible way, so that
we can mark a file as dirty:
Right now we use a negative file size to indicate we don't have valid
stat data for this entry. In practice, this size is always -1.
This patch uses -2 to indicate that the entry is dirty. Older versions
of hg won't choke on this dirstate, but they may happily mark the file
as clean after a full comparison, destroying all of our hard work.
The patch adds a dirstate.normallookup method with the semantics of the
current normaldirty, and changes normaldirty to forcefully mark the
entry as dirty.
This should fix issue522.
[1] - well, we could put them in state 'm', but that state has a
different meaning.
2007-08-23 08:48:29 +04:00
|
|
|
repo.dirstate.normallookup(fd)
|
2006-10-10 09:41:55 +04:00
|
|
|
if move:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.forget(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:
|
2007-07-22 01:02:09 +04:00
|
|
|
repo.dirstate.forget(f)
|
2006-09-18 02:39:19 +04:00
|
|
|
|
2007-07-22 01:02:10 +04:00
|
|
|
def update(repo, node, branchmerge, force, partial):
|
2006-10-10 11:31:02 +04:00
|
|
|
"""
|
|
|
|
Perform a merge between the working directory and the given node
|
|
|
|
|
|
|
|
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)
|
|
|
|
"""
|
2006-08-08 19:56:48 +04:00
|
|
|
|
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:
|
|
|
|
node = repo.branchtags()[wc.branch()]
|
|
|
|
except KeyError:
|
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]
|
2007-07-22 01:02:10 +04:00
|
|
|
pa = p1.ancestor(p2)
|
|
|
|
fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
|
|
|
|
fastforward = False
|
|
|
|
|
|
|
|
### 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:
|
|
|
|
raise util.Abort(_("can't merge with ancestor"))
|
|
|
|
elif pa == p1:
|
|
|
|
if p1.branch() != p2.branch():
|
2007-07-22 01:02:10 +04:00
|
|
|
fastforward = True
|
|
|
|
else:
|
2008-03-24 18:01:05 +03:00
|
|
|
raise util.Abort(_("nothing to merge (use 'hg update'"
|
|
|
|
" or check 'hg heads')"))
|
|
|
|
if not force and (wc.files() or wc.deleted()):
|
2009-05-22 20:42:21 +04:00
|
|
|
raise util.Abort(_("outstanding uncommitted changes "
|
|
|
|
"(use 'hg status' to list changes)"))
|
2008-03-24 18:01:05 +03:00
|
|
|
elif not overwrite:
|
|
|
|
if pa == p1 or pa == p2: # linear
|
|
|
|
pass # all good
|
|
|
|
elif p1.branch() == p2.branch():
|
|
|
|
if wc.files() or wc.deleted():
|
|
|
|
raise util.Abort(_("crosses branches (use 'hg merge' or "
|
|
|
|
"'hg update -C' to discard changes)"))
|
2008-03-24 22:28:13 +03:00
|
|
|
raise util.Abort(_("crosses branches (use 'hg merge' "
|
2008-03-24 18:01:05 +03:00
|
|
|
"or 'hg update -C')"))
|
|
|
|
elif wc.files() or wc.deleted():
|
|
|
|
raise util.Abort(_("crosses named branches (use "
|
|
|
|
"'hg update -C' to discard changes)"))
|
|
|
|
else:
|
|
|
|
# Allow jumping branches if there are no changes
|
|
|
|
overwrite = True
|
2007-07-22 01:02:10 +04:00
|
|
|
|
|
|
|
### calculate phase
|
|
|
|
action = []
|
|
|
|
if not force:
|
2008-03-15 18:02:31 +03:00
|
|
|
_checkunknown(wc, p2)
|
2008-06-26 22:58:24 +04:00
|
|
|
if not util.checkcase(repo.path):
|
2008-03-15 18:02:31 +03:00
|
|
|
_checkcollision(p2)
|
|
|
|
action += _forgetremoved(wc, p2, branchmerge)
|
2007-07-22 01:02:10 +04:00
|
|
|
action += manifestmerge(repo, wc, p2, pa, overwrite, partial)
|
|
|
|
|
|
|
|
### apply phase
|
|
|
|
if not branchmerge: # just jump to the new rev
|
|
|
|
fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
|
|
|
|
if not partial:
|
|
|
|
repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
|
|
|
|
|
|
|
|
stats = applyupdates(repo, action, wc, p2)
|
|
|
|
|
|
|
|
if not partial:
|
|
|
|
recordupdates(repo, action, branchmerge)
|
|
|
|
repo.dirstate.setparents(fp1, fp2)
|
|
|
|
if not branchmerge and not fastforward:
|
|
|
|
repo.dirstate.setbranch(p2.branch())
|
|
|
|
repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
|
|
|
|
|
|
|
|
return stats
|
|
|
|
finally:
|
2009-04-22 04:01:22 +04:00
|
|
|
wlock.release()
|