##// END OF EJS Templates
patchbomb: Hoist sender config higher.
patchbomb: Hoist sender config higher.

File last commit:

r4417:0912d8df merge default
r4491:6d2d1dcd default
Show More
merge.py
544 lines | 17.9 KiB | text/x-python | PythonLexer
Matt Mackall
Move merge code to its own module...
r2775 # merge.py - directory-level update/merge handling for Mercurial
#
# Copyright 2006 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
from node import *
Matt Mackall
Simplify i18n imports
r3891 from i18n import _
Matt Mackall
Merge with stable
r4417 import errno, util, os, tempfile, context
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
merge: pull file copy/move out of filemerge
r3309 def filemerge(repo, fw, fo, wctx, mctx):
Matt Mackall
merge: extend file merge function for renames
r3211 """perform a 3-way merge in the working directory
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
merge: update some docstrings
r3315 fw = filename in the working directory
Matt Mackall
merge: extend file merge function for renames
r3211 fo = filename in other parent
Matt Mackall
merge: pass contexts to applyupdates
r3297 wctx, mctx = working and merge changecontexts
Matt Mackall
merge: extend file merge function for renames
r3211 """
def temp(prefix, ctx):
pre = "%s~%s." % (os.path.basename(ctx.path()), prefix)
Matt Mackall
Move merge code to its own module...
r2775 (fd, name) = tempfile.mkstemp(prefix=pre)
Matt Mackall
replace filehandle version of wwrite with wwritedata
r4005 data = repo.wwritedata(ctx.path(), ctx.data())
Matt Mackall
Move merge code to its own module...
r2775 f = os.fdopen(fd, "wb")
Matt Mackall
replace filehandle version of wwrite with wwritedata
r4005 f.write(data)
Matt Mackall
Move merge code to its own module...
r2775 f.close()
return name
Matt Mackall
filemerge: use contexts rather than my and other
r3299 fcm = wctx.filectx(fw)
fco = mctx.filectx(fo)
Matt Mackall
merge: shortcircuit filemerge for identical files...
r3311
if not fco.cmp(fcm.data()): # files identical?
Matt Mackall
merge: if filemerge skips merge, report as updated
r3400 return None
Matt Mackall
merge: shortcircuit filemerge for identical files...
r3311
Matt Mackall
merge: extend file merge function for renames
r3211 fca = fcm.ancestor(fco)
if not fca:
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 fca = repo.filectx(fw, fileid=nullrev)
Matt Mackall
merge: extend file merge function for renames
r3211 a = repo.wjoin(fw)
b = temp("base", fca)
c = temp("other", fco)
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
merge: shortcircuit filemerge for identical files...
r3311 if fw != fo:
repo.ui.status(_("merging %s and %s\n") % (fw, fo))
else:
repo.ui.status(_("merging %s\n") % fw)
Matt Mackall
merge: extend file merge function for renames
r3211 repo.ui.debug(_("my %s other %s ancestor %s\n") % (fcm, fco, fca))
Matt Mackall
Move merge code to its own module...
r2775
cmd = (os.environ.get("HGMERGE") or repo.ui.config("ui", "merge")
or "hgmerge")
r = util.system('%s "%s" "%s" "%s"' % (cmd, a, b, c), cwd=repo.root,
Matt Mackall
merge: extend file merge function for renames
r3211 environ={'HG_FILE': fw,
Matt Mackall
merge: pass contexts to applyupdates
r3297 'HG_MY_NODE': str(wctx.parents()[0]),
'HG_OTHER_NODE': str(mctx)})
Matt Mackall
Move merge code to its own module...
r2775 if r:
Matt Mackall
merge: extend file merge function for renames
r3211 repo.ui.warn(_("merging %s failed!\n") % fw)
Matt Mackall
Move merge code to its own module...
r2775
os.unlink(b)
os.unlink(c)
return r
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 def checkunknown(wctx, mctx):
Matt Mackall
merge: update some docstrings
r3315 "check for collisions between unknown files and files in mctx"
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 man = mctx.manifest()
Matt Mackall
merge: use new working context object in update
r3218 for f in wctx.unknown():
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 if f in man:
if mctx.filectx(f).cmp(wctx.filectx(f).data()):
Matt Mackall
Clarify untracked file merge message
r3618 raise util.Abort(_("untracked local file '%s' differs"\
" from remote version") % f)
Matt Mackall
merge: pull manifest checks and updates into separate functions
r3107
Matt Mackall
imported patch collision
r3785 def checkcollision(mctx):
"check for case folding collisions in the destination context"
folded = {}
for fn in mctx.manifest():
fold = fn.lower()
if fold in folded:
raise util.Abort(_("case-folding collision between %s and %s")
% (fn, folded[fold]))
folded[fold] = fn
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 def forgetremoved(wctx, mctx):
Matt Mackall
merge: pull manifest checks and updates into separate functions
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.
"""
action = []
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 man = mctx.manifest()
Matt Mackall
merge: use new working context object in update
r3218 for f in wctx.deleted() + wctx.removed():
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 if f not in man:
Matt Mackall
merge: pull manifest checks and updates into separate functions
r3107 action.append((f, "f"))
return action
Matt Mackall
merge: turn followcopies on by default
r3371 def findcopies(repo, m1, m2, ma, limit):
Matt Mackall
Add core copy detection algorithm...
r3153 """
Find moves and copies between m1 and m2 back to limit linkrev
"""
Matt Mackall
merge: reorganize some hunks in findcopies
r4400 def nonoverlap(d1, d2, d3):
"Return list of elements in d1 not in d2 or d3"
l = [d for d in d1 if d not in d3 and d not in d2]
l.sort()
return l
Matt Mackall
merge: fix a bug detecting directory moves...
r4397 def dirname(f):
s = f.rfind("/")
if s == -1:
return ""
return f[:s]
def dirs(files):
d = {}
for f in files:
f = dirname(f)
while f not in d:
d[f] = True
f = dirname(f)
return d
Matt Mackall
merge: fix spurious merges for copies in linear updates...
r4416 wctx = repo.workingctx()
def makectx(f, n):
if len(n) == 20:
return repo.filectx(f, fileid=n)
return wctx.filectx(f)
ctx = util.cachefunc(makectx)
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 def findold(fctx):
"find files that path was copied from, back to linkrev limit"
old = {}
Matt Mackall
merge: fix quadratic behavior in find-copies
r4350 seen = {}
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 orig = fctx.path()
visit = [fctx]
while visit:
fc = visit.pop()
Matt Mackall
merge: fix quadratic behavior in find-copies
r4350 s = str(fc)
if s in seen:
continue
seen[s] = 1
Matt Mackall
Fix copy detection corner case...
r3875 if fc.path() != orig and fc.path() not in old:
old[fc.path()] = 1
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 if fc.rev() < limit:
continue
visit += fc.parents()
old = old.keys()
old.sort()
return old
Matt Mackall
merge: reorganize some hunks in findcopies
r4400 copy = {}
fullcopy = {}
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732
def checkcopies(c, man):
'''check possible copies for filectx c'''
for of in findold(c):
Matt Mackall
merge: clarify the findcopies code
r4396 if of not in man: # original file not in other manifest?
Matt Mackall
merge: fix a bug where copies were ignored
r4304 continue
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 c2 = ctx(of, man[of])
ca = c.ancestor(c2)
Matt Mackall
merge: clarify the findcopies code
r4396 if not ca: # unrelated?
Matt Mackall
merge: fix a bug where copies were ignored
r4304 continue
Matt Mackall
merge: clarify the findcopies code
r4396 # named changed on only one side?
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 if ca.path() == c.path() or ca.path() == c2.path():
Matt Mackall
merge: clarify the findcopies code
r4396 fullcopy[c.path()] = of # remember for dir rename detection
Matt Mackall
merge: fix spurious merges for copies in linear updates...
r4416 if c == ca or c2 == ca: # no merge needed, ignore copy
Matt Mackall
merge: fix a bug where copies were ignored
r4304 continue
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 copy[c.path()] = of
Matt Mackall
merge: turn followcopies on by default
r3371 if not repo.ui.configbool("merge", "followcopies", True):
Matt Mackall
merge: add rename following...
r3249 return {}
Matt Mackall
findcopies: shortcut for empty working dir
r3160 # avoid silly behavior for update from empty dir
Matt Mackall
merge: move check for empty ancestor into findcopies
r3731 if not m1 or not m2 or not ma:
Matt Mackall
findcopies: shortcut for empty working dir
r3160 return {}
Matt Mackall
merge: turn followcopies on by default
r3371 u1 = nonoverlap(m1, m2, ma)
u2 = nonoverlap(m2, m1, ma)
Matt Mackall
Add core copy detection algorithm...
r3153
for f in u1:
Matt Mackall
merge: fix spurious merges for copies in linear updates...
r4416 checkcopies(ctx(f, m1[f]), m2)
Matt Mackall
Add core copy detection algorithm...
r3153
for f in u2:
Matt Mackall
merge: pull findcopies helpers inside, refactor checkpair to checkcopies
r3732 checkcopies(ctx(f, m2[f]), m1)
Matt Mackall
Add core copy detection algorithm...
r3153
Matt Mackall
merge: handle directory renames...
r3733 if not fullcopy or not repo.ui.configbool("merge", "followdirs", True):
return copy
# generate a directory move map
d1, d2 = dirs(m1), dirs(m2)
invalid = {}
dirmove = {}
Matt Mackall
merge: clarify the findcopies code
r4396 # examine each file copy for a potential directory move, which is
# when all the files in a directory are moved to a new directory
Matt Mackall
merge: handle directory renames...
r3733 for dst, src in fullcopy.items():
Matt Mackall
merge: fix a bug detecting directory moves...
r4397 dsrc, ddst = dirname(src), dirname(dst)
Matt Mackall
merge: handle directory renames...
r3733 if dsrc in invalid:
Matt Mackall
merge: clarify the findcopies code
r4396 # already seen to be uninteresting
Matt Mackall
merge: handle directory renames...
r3733 continue
Matt Mackall
merge: clarify the findcopies code
r4396 elif dsrc in d1 and ddst in d1:
# directory wasn't entirely moved locally
invalid[dsrc] = True
elif dsrc in d2 and ddst in d2:
# directory wasn't entirely moved remotely
Matt Mackall
merge: handle directory renames...
r3733 invalid[dsrc] = True
elif dsrc in dirmove and dirmove[dsrc] != ddst:
Matt Mackall
merge: clarify the findcopies code
r4396 # files from the same directory moved to two different places
Matt Mackall
merge: handle directory renames...
r3733 invalid[dsrc] = True
else:
Matt Mackall
merge: clarify the findcopies code
r4396 # looks good so far
Matt Mackall
merge: fix renaming of subdirectories under renamed directories
r4115 dirmove[dsrc + "/"] = ddst + "/"
Matt Mackall
merge: handle directory renames...
r3733
Matt Mackall
merge: expand and simplify the invalid handling for directory moves
r4398 for i in invalid:
if i in dirmove:
del dirmove[i]
Matt Mackall
merge: handle directory renames...
r3733 del d1, d2, invalid
if not dirmove:
return copy
Matt Mackall
merge: clarify the findcopies code
r4396 # check unaccounted nonoverlapping files against directory moves
Matt Mackall
merge: handle directory renames...
r3733 for f in u1 + u2:
if f not in fullcopy:
Matt Mackall
merge: fix renaming of subdirectories under renamed directories
r4115 for d in dirmove:
if f.startswith(d):
Matt Mackall
merge: clarify the findcopies code
r4396 # new file added in a directory that was moved, move it
Matt Mackall
merge: fix renaming of subdirectories under renamed directories
r4115 copy[f] = dirmove[d] + f[len(d):]
break
Matt Mackall
merge: handle directory renames...
r3733
Matt Mackall
Add core copy detection algorithm...
r3153 return copy
Matt Mackall
merge: use contexts for manifestmerge...
r3295 def manifestmerge(repo, p1, p2, pa, overwrite, partial):
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 """
Matt Mackall
merge: update some docstrings
r3315 Merge p1 and p2 with ancestor ma and generate merge action list
overwrite = whether we clobber working files
partial = function to filter file lists
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 """
Matt Mackall
merge: various tidying...
r3314 repo.ui.note(_("resolving manifests\n"))
repo.ui.debug(_(" overwrite %s partial %s\n") % (overwrite, bool(partial)))
repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (pa, p1, p2))
Matt Mackall
merge: use contexts for manifestmerge...
r3295 m1 = p1.manifest()
m2 = p2.manifest()
ma = pa.manifest()
backwards = (pa == p2)
Matt Mackall
merge: various tidying...
r3314 action = []
copy = {}
Matt Mackall
merge: use contexts for manifestmerge...
r3295
Matt Mackall
merge: add rename following...
r3249 def fmerge(f, f2=None, fa=None):
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 """merge flags"""
Matt Mackall
merge: add rename following...
r3249 if not f2:
f2 = f
fa = f
a, b, c = ma.execf(fa), m1.execf(f), m2.execf(f2)
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 if ((a^b) | (a^c)) ^ a:
return 'x'
a, b, c = ma.linkf(fa), m1.linkf(f), m2.linkf(f2)
if ((a^b) | (a^c)) ^ a:
return 'l'
return ''
Matt Mackall
merge: simplify exec flag handling
r3118
Matt Mackall
merge: swap file and mode args for act()
r3307 def act(msg, m, f, *args):
Matt Mackall
merge: use contexts for manifestmerge...
r3295 repo.ui.debug(" %s: %s -> %s\n" % (f, msg, m))
Matt Mackall
merge: simplify actions with helper function
r3121 action.append((f, m) + args)
Matt Mackall
merge: move check for empty ancestor into findcopies
r3731 if not (backwards or overwrite):
Matt Mackall
merge: turn followcopies on by default
r3371 copy = findcopies(repo, m1, m2, ma, pa.rev())
Matt Mackall
merge: only store one direction of copies in the copy map...
r3730 copied = dict.fromkeys(copy.values())
Matt Mackall
merge: use contexts for manifestmerge...
r3295
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 # Compare manifests
for f, n in m1.iteritems():
Matt Mackall
merge: reduce manifest copying
r3248 if partial and not partial(f):
continue
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 if f in m2:
# are files different?
if n != m2[f]:
a = ma.get(f, nullid)
# are both different from the ancestor?
if not overwrite and n != a and m2[f] != a:
Matt Mackall
merge: unify merge and copy actions
r3308 act("versions differ", "m", f, f, f, fmerge(f), False)
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 # are we clobbering?
# is remote's version newer?
# or are we going back in time and clean?
elif overwrite or m2[f] != a or (backwards and not n[20:]):
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 act("remote is newer", "g", f, m2.flags(f))
Matt Mackall
merge: eliminate confusing queued variable
r3113 # local is newer, not overwrite, check mode bits
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 elif fmerge(f) != m1.flags(f):
act("update permissions", "e", f, m2.flags(f))
Matt Mackall
merge: eliminate confusing queued variable
r3113 # contents same, check mode bits
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 elif m1.flags(f) != m2.flags(f):
if overwrite or fmerge(f) != m1.flags(f):
act("update permissions", "e", f, m2.flags(f))
Matt Mackall
merge: only store one direction of copies in the copy map...
r3730 elif f in copied:
continue
Matt Mackall
merge: add rename following...
r3249 elif f in copy:
f2 = copy[f]
Matt Mackall
merge: handle directory renames...
r3733 if f2 not in m2: # directory rename
act("remote renamed directory to " + f2, "d",
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 f, None, f2, m1.flags(f))
Matt Mackall
merge: handle directory renames...
r3733 elif f2 in m1: # case 2 A,B/B/B
Matt Mackall
merge: only store one direction of copies in the copy map...
r3730 act("local copied to " + f2, "m",
f, f2, f, fmerge(f, f2, f2), False)
else: # case 4,21 A/B/B
act("local moved to " + f2, "m",
f, f2, f, fmerge(f, f2, f2), False)
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 elif f in ma:
Matt Mackall
merge: simplify tests for local changed/remote deleted
r3117 if n != ma[f] and not overwrite:
Matt Mackall
merge: use contexts for manifestmerge...
r3295 if repo.ui.prompt(
Matt Mackall
merge: simplify tests for local changed/remote deleted
r3117 (_(" local changed %s which remote deleted\n") % f) +
Matt Mackall
merge: simplify prompt code
r3119 _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("d"):
Matt Mackall
merge: swap file and mode args for act()
r3307 act("prompt delete", "r", f)
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 else:
Matt Mackall
merge: swap file and mode args for act()
r3307 act("other deleted", "r", f)
Matt Mackall
merge: pull manifest comparison out into separate function
r3105 else:
# file is created on branch or in working directory
Matt Mackall
merge: simplify local created logic
r3120 if (overwrite and n[20:] != "u") or (backwards and not n[20:]):
Matt Mackall
merge: swap file and mode args for act()
r3307 act("remote deleted", "r", f)
Matt Mackall
merge: pull manifest comparison out into separate function
r3105
for f, n in m2.iteritems():
Matt Mackall
merge: reduce manifest copying
r3248 if partial and not partial(f):
continue
if f in m1:
continue
Matt Mackall
merge: add copied hash to simplify copy logic
r3729 if f in copied:
continue
Matt Mackall
merge: add rename following...
r3249 if f in copy:
f2 = copy[f]
Matt Mackall
merge: handle directory renames...
r3733 if f2 not in m1: # directory rename
act("local renamed directory to " + f2, "d",
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 None, f, f2, m2.flags(f))
Matt Mackall
merge: handle directory renames...
r3733 elif f2 in m2: # rename case 1, A/A,B/A
Matt Mackall
merge: only store one direction of copies in the copy map...
r3730 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)
Matt Mackall
merge: add rename following...
r3249 elif f in ma:
Matt Mackall
merge: more simplification of m2 manifest scanning
r3116 if overwrite or backwards:
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 act("recreating", "g", f, m2.flags(f))
Matt Mackall
merge: more simplification of m2 manifest scanning
r3116 elif n != ma[f]:
Matt Mackall
merge: use contexts for manifestmerge...
r3295 if repo.ui.prompt(
Matt Mackall
merge: more simplification of m2 manifest scanning
r3116 (_("remote changed %s which local deleted\n") % f) +
Matt Mackall
merge: simplify prompt code
r3119 _("(k)eep or (d)elete?"), _("[kd]"), _("k")) == _("k"):
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 act("prompt recreating", "g", f, m2.flags(f))
Matt Mackall
merge: reorder tests on m2 items in manifestmerge
r3115 else:
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 act("remote created", "g", f, m2.flags(f))
Matt Mackall
merge: pull manifest comparison out into separate function
r3105
return action
Matt Mackall
merge: pass contexts to applyupdates
r3297 def applyupdates(repo, action, wctx, mctx):
Matt Mackall
merge: update some docstrings
r3315 "apply the merge action list to the working directory"
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 updated, merged, removed, unresolved = 0, 0, 0, 0
action.sort()
for a in action:
f, m = a[:2]
Matt Mackall
merge: handle directory renames...
r3733 if f and f[0] == "/":
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 continue
if m == "r": # remove
repo.ui.note(_("removing %s\n") % f)
util.audit_path(f)
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))
Thomas Arendsen Hein
white space and line break cleanups
r3673 removed += 1
Matt Mackall
merge: unify merge and copy actions
r3308 elif m == "m": # merge
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 f2, fd, flags, move = a[2:]
Matt Mackall
merge: if filemerge skips merge, report as updated
r3400 r = filemerge(repo, f, f2, wctx, mctx)
if r > 0:
Matt Mackall
merge: add rename following...
r3249 unresolved += 1
Matt Mackall
merge: pull file copy/move out of filemerge
r3309 else:
Matt Mackall
merge: if filemerge skips merge, report as updated
r3400 if r is None:
updated += 1
else:
merged += 1
Matt Mackall
merge: pull file copy/move out of filemerge
r3309 if f != fd:
repo.ui.debug(_("copying %s to %s\n") % (f, fd))
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 repo.wwrite(fd, repo.wread(f), flags)
Matt Mackall
merge: pull file copy/move out of filemerge
r3309 if move:
repo.ui.debug(_("removing %s\n") % f)
os.unlink(repo.wjoin(f))
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 util.set_exec(repo.wjoin(fd), "x" in flags)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 elif m == "g": # get
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 flags = a[2]
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 repo.ui.note(_("getting %s\n") % f)
Matt Mackall
merge: eliminate nodes from action list...
r3303 t = mctx.filectx(f).data()
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 repo.wwrite(f, t, flags)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 updated += 1
Matt Mackall
merge: handle directory renames...
r3733 elif m == "d": # directory rename
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 f2, fd, flags = a[2:]
Matt Mackall
merge: handle directory renames...
r3733 if f:
repo.ui.note(_("moving %s to %s\n") % (f, fd))
t = wctx.filectx(f).data()
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 repo.wwrite(fd, t, flags)
Matt Mackall
merge: handle directory renames...
r3733 util.unlink(repo.wjoin(f))
if f2:
repo.ui.note(_("getting %s to %s\n") % (f2, fd))
t = mctx.filectx(f2).data()
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 repo.wwrite(fd, t, flags)
Matt Mackall
merge: handle directory renames...
r3733 updated += 1
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 elif m == "e": # exec
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 flags = a[2]
util.set_exec(repo.wjoin(f), flags)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111
return updated, merged, removed, unresolved
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 def recordupdates(repo, action, branchmerge):
Matt Mackall
merge: update some docstrings
r3315 "record merge actions to the dirstate"
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 for a in action:
f, m = a[:2]
if m == "r": # remove
if branchmerge:
repo.dirstate.update([f], 'r')
else:
repo.dirstate.forget([f])
elif m == "f": # forget
repo.dirstate.forget([f])
elif m == "g": # get
if branchmerge:
repo.dirstate.update([f], 'n', st_mtime=-1)
else:
repo.dirstate.update([f], 'n')
elif m == "m": # merge
Matt Mackall
merge: eliminate nodes from action list...
r3303 f2, fd, flag, move = a[2:]
Matt Mackall
merge: fixes for merge+rename...
r3251 if branchmerge:
# We've done a branch merge, mark this file as merged
# so that we properly record the merger later
repo.dirstate.update([fd], 'm')
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 if f != f2: # copy/rename
if move:
repo.dirstate.update([f], 'r')
if f != fd:
repo.dirstate.copy(f, fd)
else:
repo.dirstate.copy(f2, fd)
Matt Mackall
merge: fixes for merge+rename...
r3251 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.
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 repo.dirstate.update([fd], 'n', st_size=-1, st_mtime=-1)
Matt Mackall
merge: unify merge and copy actions
r3308 if move:
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 repo.dirstate.forget([f])
Matt Mackall
merge: handle directory renames...
r3733 elif m == "d": # directory rename
f2, fd, flag = a[2:]
if branchmerge:
repo.dirstate.update([fd], 'a')
if f:
repo.dirstate.update([f], 'r')
repo.dirstate.copy(f, fd)
if f2:
repo.dirstate.copy(f2, fd)
else:
repo.dirstate.update([fd], 'n')
if f:
repo.dirstate.forget([f])
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111
Matt Mackall
merge: pull user messages out to hg.py...
r3316 def update(repo, node, branchmerge, force, partial, wlock):
Matt Mackall
merge: update some docstrings
r3315 """
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)
wlock = working dir lock, if already held
"""
Matt Mackall
Merge: combine force and forcemerge arguments
r2815
Matt Mackall
Refactor update locking slightly
r2812 if not wlock:
wlock = repo.wlock()
Brendan Cully
Merge with crew-stable
r4182 wc = repo.workingctx()
if node is None:
# tip of current branch
Alexis S. L. Carvalho
Merge with crew-stable
r4232 try:
node = repo.branchtags()[wc.branch()]
except KeyError:
raise util.Abort(_("branch %s not found") % wc.branch())
Matt Mackall
merge: various tidying...
r3314 overwrite = force and not branchmerge
forcemerge = force and branchmerge
Matt Mackall
merge: use new working context object in update
r3218 pl = wc.parents()
Matt Mackall
merge: various tidying...
r3314 p1, p2 = pl[0], repo.changectx(node)
pa = p1.ancestor(p2)
fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
Brendan Cully
Add fast-forward branch merging
r4410 fastforward = False
Matt Mackall
merge: various tidying...
r3314
### check phase
Matt Mackall
merge: use repo.parents and parent contexts in update
r3167 if not overwrite and len(pl) > 1:
Matt Mackall
Move merge code to its own module...
r2775 raise util.Abort(_("outstanding uncommitted merges"))
Matt Mackall
merge: various tidying...
r3314 if pa == p1 or pa == p2: # is there a linear path from p1 to p2?
Matt Mackall
merge: remove linear variable
r3110 if branchmerge:
Brendan Cully
Add fast-forward branch merging
r4410 if p1.branch() != p2.branch():
fastforward = True
branchmerge = False
else:
raise util.Abort(_("there is nothing to merge, just use "
"'hg update' or look at 'hg heads'"))
Benoit Boissinot
Backed out changeset 41989e55fa375de4376e7e64b17e38312e8ec140
r3592 elif not (overwrite or branchmerge):
raise util.Abort(_("update spans branches, use 'hg merge' "
"or 'hg update -C' to lose changes"))
Matt Mackall
Merge: move most tests to the beginning
r2814 if branchmerge and not forcemerge:
Benoit Boissinot
use workingcontext.files() to detect if the repo is unclean
r3581 if wc.files():
Matt Mackall
Merge: move most tests to the beginning
r2814 raise util.Abort(_("outstanding uncommitted changes"))
Matt Mackall
merge: various tidying...
r3314 ### calculate phase
Matt Mackall
merge: convert actions to list
r3100 action = []
Matt Mackall
merge: pull manifest checks and updates into separate functions
r3107 if not force:
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 checkunknown(wc, p2)
Matt Mackall
imported patch collision
r3785 if not util.checkfolding(repo.path):
checkcollision(p2)
Matt Mackall
merge: remove linear variable
r3110 if not branchmerge:
Matt Mackall
merge: use contexts in checkunknown and forgetremoved
r3312 action += forgetremoved(wc, p2)
Matt Mackall
merge: use contexts for manifestmerge...
r3295 action += manifestmerge(repo, wc, p2, pa, overwrite, partial)
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
merge: move forgets to the apply stage
r2897 ### apply phase
Matt Mackall
merge: various tidying...
r3314 if not branchmerge: # just jump to the new rev
fp1, fp2, xp1, xp2 = fp2, nullid, xp2, ''
Matt Mackall
merge: don't call hooks for revert...
r3296 if not partial:
repo.hook('preupdate', throw=True, parent1=xp1, parent2=xp2)
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
merge: pull user messages out to hg.py...
r3316 stats = applyupdates(repo, action, wc, p2)
Matt Mackall
merge: consolidate dirstate updates
r2899
Matt Mackall
Merge: combine choose and moddirstate to partial
r2811 if not partial:
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 recordupdates(repo, action, branchmerge)
Matt Mackall
merge: various tidying...
r3314 repo.dirstate.setparents(fp1, fp2)
Brendan Cully
Add fast-forward branch merging
r4410 if not branchmerge and not fastforward:
Matt Mackall
Move branch read/write to dirstate where it belongs
r4179 repo.dirstate.setbranch(p2.branch())
Matt Mackall
merge: pull user messages out to hg.py...
r3316 repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
Matt Mackall
merge: various tidying...
r3314
Matt Mackall
merge: pull user messages out to hg.py...
r3316 return stats
Matt Mackall
Move merge code to its own module...
r2775