##// END OF EJS Templates
tests: remove useless sed in test-hook
tests: remove useless sed in test-hook

File last commit:

r11759:05deba16 merge default
r11794:80c63b2a default
Show More
merge.py
528 lines | 19.3 KiB | text/x-python | PythonLexer
Matt Mackall
Move merge code to its own module...
r2775 # merge.py - directory-level update/merge handling for Mercurial
#
Thomas Arendsen Hein
Updated copyright notices and add "and others" to "hg version"
r4635 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com>
Matt Mackall
Move merge code to its own module...
r2775 #
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
resolve: new command...
r6518 from node import nullid, nullrev, hex, bin
Matt Mackall
Simplify i18n imports
r3891 from i18n import _
Matt Mackall
subrepo: add update/merge logic
r8814 import util, filemerge, copies, subrepo
Simon Heimberg
separate import lines from mercurial and general python modules
r8312 import errno, os, shutil
Matt Mackall
merge: introduce mergestate
r6512
class mergestate(object):
'''track 3-way merge state of individual files'''
def __init__(self, repo):
self._repo = repo
Matt Mackall
resolve: new command...
r6518 self._read()
Matt Mackall
resolve: move reset to localrepo.commit...
r7848 def reset(self, node=None):
Matt Mackall
merge: introduce mergestate
r6512 self._state = {}
Matt Mackall
resolve: move reset to localrepo.commit...
r7848 if node:
self._local = node
Matt Mackall
merge: introduce mergestate
r6512 shutil.rmtree(self._repo.join("merge"), True)
Matt Mackall
resolve: new command...
r6518 def _read(self):
self._state = {}
try:
f = self._repo.opener("merge/state")
Patrick Mezard
merge: replace readline() call, missing from posixfile_nt
r6530 for i, l in enumerate(f):
if i == 0:
Martin Geisler
resolve: do not crash on empty mergestate...
r11451 self._local = bin(l[:-1])
Patrick Mezard
merge: replace readline() call, missing from posixfile_nt
r6530 else:
bits = l[:-1].split("\0")
self._state[bits[0]] = bits[1:]
Matt Mackall
resolve: new command...
r6518 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")
Dirkjan Ochtman
use dict.iteritems() rather than dict.items()...
r7622 for d, v in self._state.iteritems():
Matt Mackall
resolve: new command...
r6518 f.write("\0".join([d] + v) + "\n")
Matt Mackall
merge: introduce mergestate
r6512 def add(self, fcl, fco, fca, fd, flags):
Dirkjan Ochtman
python-2.6: use sha wrapper from util for new merge code
r6517 hash = util.sha1(fcl.path()).hexdigest()
Matt Mackall
merge: introduce mergestate
r6512 self._repo.opener("merge/" + hash, "w").write(fcl.data())
Matt Mackall
resolve: new command...
r6518 self._state[fd] = ['u', hash, fcl.path(), fca.path(),
hex(fca.filenode()), fco.path(), flags]
self._write()
Matt Mackall
merge: introduce mergestate
r6512 def __contains__(self, dfile):
return dfile in self._state
def __getitem__(self, dfile):
Matt Mackall
resolve: new command...
r6518 return self._state[dfile][0]
def __iter__(self):
l = self._state.keys()
l.sort()
for f in l:
yield f
Matt Mackall
merge: introduce mergestate
r6512 def mark(self, dfile, state):
Matt Mackall
resolve: new command...
r6518 self._state[dfile][0] = state
self._write()
Matt Mackall
merge: introduce mergestate
r6512 def resolve(self, dfile, wctx, octx):
if self[dfile] == 'r':
return 0
Matt Mackall
resolve: new command...
r6518 state, hash, lfile, afile, anode, ofile, flags = self._state[dfile]
Matt Mackall
merge: introduce mergestate
r6512 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
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
merge: privatize some functions, unnest some others
r6269 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 new working context object in update
r3218 for f in wctx.unknown():
Nicolas Dumazet
filectx: use cmp(self, fctx) instead of cmp(self, text)...
r11702 if f in mctx and mctx[f].cmp(wctx[f]):
Matt Mackall
merge: simplify some helpers
r6272 raise util.Abort(_("untracked file in working directory differs"
" from file in requested revision: '%s'") % f)
Matt Mackall
merge: pull manifest checks and updates into separate functions
r3107
Matt Mackall
merge: privatize some functions, unnest some others
r6269 def _checkcollision(mctx):
Matt Mackall
imported patch collision
r3785 "check for case folding collisions in the destination context"
folded = {}
Matt Mackall
merge: simplify some helpers
r6272 for fn in mctx:
Matt Mackall
imported patch collision
r3785 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: privatize some functions, unnest some others
r6269 def _forgetremoved(wctx, mctx, branchmerge):
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.
Alexis S. L. Carvalho
merge: fix handling of deleted files
r6242
If we're merging, and the other revision has removed a file
that is not present in the working directory, we need to mark it
as removed.
Matt Mackall
merge: pull manifest checks and updates into separate functions
r3107 """
action = []
Alexis S. L. Carvalho
merge: fix handling of deleted files
r6242 state = branchmerge and 'r' or 'f'
for f in wctx.deleted():
Matt Mackall
merge: simplify some helpers
r6272 if f not in mctx:
Alexis S. L. Carvalho
merge: fix handling of deleted files
r6242 action.append((f, state))
if not branchmerge:
for f in wctx.removed():
Matt Mackall
merge: simplify some helpers
r6272 if f not in mctx:
Alexis S. L. Carvalho
merge: fix handling of deleted files
r6242 action.append((f, "f"))
Matt Mackall
merge: pull manifest checks and updates into separate functions
r3107
return action
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: simplify flag merging code slightly
r8733 def fmerge(f, f2, fa):
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 """merge flags"""
Matt Mackall
merge: add flag merging intelligence...
r5708 a, m, n = ma.flags(fa), m1.flags(f), m2.flags(f2)
if m == n: # flags agree
return m # unchanged
Matt Mackall
merge: simplify flag merging code slightly
r8733 if m and n and not a: # flags set, don't agree, differ from parent
Simon Heimberg
ui: extract choice from prompt...
r9048 r = repo.ui.promptchoice(
Matt Mackall
merge: simplify flag merging code slightly
r8733 _(" conflicting flags for %s\n"
"(n)one, e(x)ec or sym(l)ink?") % f,
Simon Heimberg
ui: extract choice from prompt...
r9048 (_("&None"), _("E&xec"), _("Sym&link")), 0)
Matt Mackall
many, many trivial check-code fixups
r10282 if r == 1:
return "x" # Exec
if r == 2:
return "l" # Symlink
Simon Heimberg
ui: extract choice from prompt...
r9048 return ""
Matt Mackall
merge: add flag merging intelligence...
r5708 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
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: refactor manifestmerge init to better report effective ancestor
r8753 action, copy = [], {}
Matt Mackall
merge: refactor some initialization, drop backwards var
r8749 if overwrite:
Matt Mackall
merge: refactor manifestmerge init to better report effective ancestor
r8753 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"))
Martin Geisler
do not attempt to translate ui.debug output
r9467 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: refactor manifestmerge init to better report effective ancestor
r8753
m1, m2, ma = p1.manifest(), p2.manifest(), pa.manifest()
copied = set(copy.values())
Matt Mackall
merge: use contexts for manifestmerge...
r3295
Matt Mackall
subrepo: correctly handle update -C with modified subrepos (issue2022)...
r11470 if '.hgsubstate' in m1:
Matt Mackall
submerge: properly deal with overwrites...
r9783 # check whether sub state is modified
for s in p1.substate:
if p1.sub(s).dirty():
m1['.hgsubstate'] += "+"
break
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:
Matt Mackall
merge: remove a flags case
r8735 rflags = fmerge(f, f, f)
Matt Mackall
merge: simplify file revision comparison logic
r8752 a = ma.get(f, nullid)
if n == m2[f] or m2[f] == a: # same or local newer
Matt Mackall
update: synchronize permissions in the dirstate (issue1473)...
r11466 # is file locally modified or flags need changing?
# dirstate flags may need to be made current
if m1.flags(f) != rflags or n[20:]:
Matt Mackall
merge: simplify file revision comparison logic
r8752 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
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: combine a copy and move case
r8748 else: # case 2 A,B/B/B or case 4,21 A/B/B
act("local copied/moved to " + f2, "m",
Matt Mackall
merge: only store one direction of copies in the copy map...
r3730 f, f2, f, fmerge(f, f2, f2), False)
Matt Mackall
merge: simplify 'other deleted' case
r8744 elif f in ma: # clean, a different, no remote
Matt Mackall
merge: drop an overwrite test
r8739 if n != ma[f]:
Simon Heimberg
ui: extract choice from prompt...
r9048 if repo.ui.promptchoice(
Thomas Arendsen Hein
Fix misleading error and prompts during update/merge (issue556)
r5670 _(" local changed %s which remote deleted\n"
"use (c)hanged version or (d)elete?") % f,
Simon Heimberg
ui: extract choice from prompt...
r9048 (_("&Changed"), _("&Delete")), 0):
Matt Mackall
merge: swap file and mode args for act()
r3307 act("prompt delete", "r", f)
Matt Mackall
merge: fix prompt keep
r8736 else:
act("prompt keep", "a", f)
Matt Mackall
merge: make locally-added file test more correct
r8751 elif n[20:] == "a": # added, no remote
act("remote deleted", "f", f)
Matt Mackall
merge: simplify 'other deleted' case
r8744 elif n[20:] != "u":
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
for f, n in m2.iteritems():
Matt Mackall
merge: reduce manifest copying
r3248 if partial and not partial(f):
continue
Matt Mackall
merge: simplify file revision comparison logic
r8752 if f in m1 or f in copied: # files already visited
Matt Mackall
merge: add copied hash to simplify copy logic
r3729 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: reorder remote creation tests
r8741 elif f not in ma:
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 act("remote created", "g", f, m2.flags(f))
Matt Mackall
merge: reorder remote creation tests
r8741 elif n != ma[f]:
Simon Heimberg
ui: extract choice from prompt...
r9048 if repo.ui.promptchoice(
Matt Mackall
merge: reorder remote creation tests
r8741 _("remote changed %s which local deleted\n"
"use (c)hanged version or leave (d)eleted?") % f,
Simon Heimberg
ui: extract choice from prompt...
r9048 (_("&Changed"), _("&Deleted")), 0) == 0:
Matt Mackall
merge: reorder remote creation tests
r8741 act("prompt recreating", "g", f, m2.flags(f))
Matt Mackall
merge: pull manifest comparison out into separate function
r3105
return action
Dirkjan Ochtman
some modernization cleanups, forward compatibility
r8366 def actionkey(a):
return a[1] == 'r' and -1 or 0, a
Paul Moore
Sort removes first when applying updates (fixes issues 750 and 912)...
r6805
Peter Arrenbrecht
merge: pass constant cset ancestor to fctx.ancestor
r11454 def applyupdates(repo, action, wctx, mctx, actx):
"""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
"""
Matt Mackall
merge: update some docstrings
r3315
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 updated, merged, removed, unresolved = 0, 0, 0, 0
Matt Mackall
merge: introduce mergestate
r6512 ms = mergestate(repo)
ms.reset(wctx.parents()[0].node())
moves = []
Dirkjan Ochtman
some modernization cleanups, forward compatibility
r8366 action.sort(key=actionkey)
Matt Mackall
subrepo: add update/merge logic
r8814 substate = wctx.substate # prime
Matt Mackall
merge: introduce mergestate
r6512
# prescan for merges
Augie Fackler
update: make calls to ui.progress()
r10431 u = repo.ui
Matt Mackall
merge: do early copy to deal with issue636...
r5042 for a in action:
f, m = a[:2]
if m == 'm': # merge
f2, fd, flags, move = a[2:]
Matt Mackall
subrepo: add update/merge logic
r8814 if f == '.hgsubstate': # merged internally
continue
Martin Geisler
do not attempt to translate ui.debug output
r9467 repo.ui.debug("preserving %s for resolve of %s\n" % (f, fd))
Matt Mackall
merge: introduce mergestate
r6512 fcl = wctx[f]
fco = mctx[f2]
Peter Arrenbrecht
merge: pass constant cset ancestor to fctx.ancestor
r11454 fca = fcl.ancestor(fco, actx) or repo.filectx(f, fileid=nullrev)
Matt Mackall
merge: introduce mergestate
r6512 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)):
Martin Geisler
do not attempt to translate ui.debug output
r9467 repo.ui.debug("removing %s\n" % f)
Matt Mackall
merge: introduce mergestate
r6512 os.unlink(repo.wjoin(f))
Matt Mackall
merge: do early copy to deal with issue636...
r5042
Bryan O'Sullivan
Make audit_path more stringent....
r5158 audit_path = util.path_auditor(repo.root)
Augie Fackler
update: make calls to ui.progress()
r10431 numupdates = len(action)
for i, a in enumerate(action):
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 f, m = a[:2]
timeless
progress: use gerund (updating) for merge progress
r11716 u.progress(_('updating'), i + 1, item=f, total=numupdates, unit='files')
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)
Bryan O'Sullivan
Make audit_path more stringent....
r5158 audit_path(f)
Matt Mackall
subrepo: add update/merge logic
r8814 if f == '.hgsubstate': # subrepo states need updating
subrepo.submerge(repo, wctx, mctx, wctx)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 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
subrepo: add update/merge logic
r8814 if f == '.hgsubstate': # subrepo states need updating
subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx))
continue
Matt Mackall
symlinks: minimal support for symlinks in merge/update...
r4007 f2, fd, flags, move = a[2:]
Matt Mackall
merge: introduce mergestate
r6512 r = ms.resolve(fd, wctx, mctx)
Alejandro Santos
compat: can't compare two values of unequal datatypes
r9030 if r is not None and 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
util: set_flags shouldn't know about repo flag formats
r6877 util.set_flags(repo.wjoin(fd), 'l' in flags, 'x' in flags)
Matt Mackall
merge: avoid double deletion mentioned in issue636
r5059 if f != fd and move and util.lexists(repo.wjoin(f)):
Martin Geisler
do not attempt to translate ui.debug output
r9467 repo.ui.debug("removing %s\n" % f)
Matt Mackall
merge: do early copy to deal with issue636...
r5042 os.unlink(repo.wjoin(f))
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: drop reference to file contents after write...
r11755 t = None
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 updated += 1
Matt Mackall
subrepo: add update/merge logic
r8814 if f == '.hgsubstate': # subrepo states need updating
subrepo.submerge(repo, wctx, mctx, wctx)
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: warn user about divergent renames
r4674 elif m == "dr": # divergent renames
fl = a[2]
Martin Geisler
i18n: mark strings for translation in Mercurial
r6953 repo.ui.warn(_("warning: detected divergent renames of %s to:\n") % f)
Matt Mackall
merge: warn user about divergent renames
r4674 for nf in fl:
repo.ui.warn(" %s\n" % nf)
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]
Matt Mackall
util: set_flags shouldn't know about repo flag formats
r6877 util.set_flags(repo.wjoin(f), 'l' in flags, 'x' in flags)
timeless
progress: use gerund (updating) for merge progress
r11716 u.progress(_('updating'), None, total=numupdates, unit='files')
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:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.remove(f)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 else:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.forget(f)
Matt Mackall
merge: mark kept local files as readded on linear update (issue539)
r7768 elif m == "a": # re-add
if not branchmerge:
repo.dirstate.add(f)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 elif m == "f": # forget
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.forget(f)
Benoit Boissinot
correctly update dirstate after update+mode change (issue1456)
r7569 elif m == "e": # exec change
Patrick Mezard
merge: fix execute bit update issue introduced by 89207edf3973
r7630 repo.dirstate.normallookup(f)
Benoit Boissinot
correctly update dirstate after update+mode change (issue1456)
r7569 elif m == "g": # get
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 if branchmerge:
Benoit Boissinot
dirstate: more explicit name, rename normaldirty() to otherparent()
r10968 repo.dirstate.otherparent(f)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 else:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.normal(f)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111 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
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.merge(fd)
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 if f != f2: # copy/rename
if move:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.remove(f)
Matt Mackall
merge: update dirstate correctly for non-branchmerge updates...
r3372 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.
Gilles Moris
merge: avoid to break the dirstate copy status on moved files...
r11178 if f2 == fd: # file not locally copied/moved
repo.dirstate.normallookup(fd)
Matt Mackall
merge: unify merge and copy actions
r3308 if move:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.forget(f)
Matt Mackall
merge: handle directory renames...
r3733 elif m == "d": # directory rename
f2, fd, flag = a[2:]
Matt Mackall
merge: fix adding untracked files on directory rename (issue612)...
r4819 if not f2 and f not in repo.dirstate:
# untracked file moved
continue
Matt Mackall
merge: handle directory renames...
r3733 if branchmerge:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.add(fd)
Matt Mackall
merge: handle directory renames...
r3733 if f:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.remove(f)
Matt Mackall
merge: handle directory renames...
r3733 repo.dirstate.copy(f, fd)
if f2:
repo.dirstate.copy(f2, fd)
else:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.normal(fd)
Matt Mackall
merge: handle directory renames...
r3733 if f:
Matt Mackall
dirstate: break update into separate functions
r4904 repo.dirstate.forget(f)
Matt Mackall
merge: move apply and dirstate code into separate functions
r3111
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 def update(repo, node, branchmerge, force, partial):
Matt Mackall
merge: update some docstrings
r3315 """
Perform a merge between the working directory and the given node
Stuart W Marks
update: add comments and test cases for updating across branches...
r9716 node = the node to update to, or None if unspecified
Matt Mackall
merge: update some docstrings
r3315 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)
Stuart W Marks
update: add comments and test cases for updating across branches...
r9716
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).
This logic is tested by test-update-branches.
-c -C dirty rev | linear same cross
n n n n | ok (1) x
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 n n n y | ok ok ok
n n y * | merge (2) (2)
Stuart W Marks
update: add comments and test cases for updating across branches...
r9716 n y * * | --- discard ---
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 y n y * | --- (3) ---
Stuart W Marks
update: add comments and test cases for updating across branches...
r9716 y n n * | --- ok ---
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 y y * * | --- (4) ---
Stuart W Marks
update: add comments and test cases for updating across branches...
r9716
x = can't happen
* = don't-care
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 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)
Matt Mackall
merge: update some docstrings
r3315 """
Matt Mackall
Merge: combine force and forcemerge arguments
r2815
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 onode = node
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 wlock = repo.wlock()
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 try:
Matt Mackall
use repo[changeid] to get a changectx
r6747 wc = repo[None]
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 if node is None:
# tip of current branch
try:
node = repo.branchtags()[wc.branch()]
except KeyError:
Matt Mackall
update: default to tipmost branch if default branch doesn't exist
r5570 if wc.branch() == "default": # no default branch!
node = repo.lookup("tip") # update to tip
else:
raise util.Abort(_("branch %s not found") % wc.branch())
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 overwrite = force and not branchmerge
pl = wc.parents()
Matt Mackall
use repo[changeid] to get a changectx
r6747 p1, p2 = pl[0], repo[node]
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 pa = p1.ancestor(p2)
fp1, fp2, xp1, xp2 = p1.node(), p2.node(), str(p1), str(p2)
fastforward = False
Matt Mackall
merge: various tidying...
r3314
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 ### check phase
if not overwrite and len(pl) > 1:
raise util.Abort(_("outstanding uncommitted merges"))
Matt Mackall
update: better logic and messages for updates...
r6375 if branchmerge:
if pa == p2:
Matt Mackall
merge: improve merge with ancestor message
r11417 raise util.Abort(_("merging with a working directory ancestor"
" has no effect"))
Matt Mackall
update: better logic and messages for updates...
r6375 elif pa == p1:
if p1.branch() != p2.branch():
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 fastforward = True
else:
Matt Mackall
update: better logic and messages for updates...
r6375 raise util.Abort(_("nothing to merge (use 'hg update'"
" or check 'hg heads')"))
if not force and (wc.files() or wc.deleted()):
Steve Borho
merge: give hint as to how to discover uncommitted changes...
r8545 raise util.Abort(_("outstanding uncommitted changes "
"(use 'hg status' to list changes)"))
Matt Mackall
update: better logic and messages for updates...
r6375 elif not overwrite:
if pa == p1 or pa == p2: # linear
pass # all good
elif wc.files() or wc.deleted():
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 raise util.Abort(_("crosses branches (use 'hg merge' to merge "
"or use 'hg update -C' to discard changes)"))
elif onode is None:
raise util.Abort(_("crosses branches (use 'hg merge' or use "
"'hg update -c')"))
Matt Mackall
update: better logic and messages for updates...
r6375 else:
Stuart W Marks
update: allow branch crossing without -c or -C, with no uncommitted changes...
r9717 # Allow jumping branches if clean and specific rev given
Matt Mackall
update: better logic and messages for updates...
r6375 overwrite = True
Matt Mackall
Merge: move most tests to the beginning
r2814
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 ### calculate phase
action = []
Matt Mackall
context: only scan unknowns when needed
r11101 wc.status(unknown=True) # prime cache
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 if not force:
Matt Mackall
merge: privatize some functions, unnest some others
r6269 _checkunknown(wc, p2)
Matt Mackall
rename checkfolding to checkcase
r6746 if not util.checkcase(repo.path):
Matt Mackall
merge: privatize some functions, unnest some others
r6269 _checkcollision(p2)
action += _forgetremoved(wc, p2, branchmerge)
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 action += manifestmerge(repo, wc, p2, pa, overwrite, partial)
Matt Mackall
Move merge code to its own module...
r2775
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 ### 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)
Matt Mackall
Move merge code to its own module...
r2775
Peter Arrenbrecht
merge: pass constant cset ancestor to fctx.ancestor
r11454 stats = applyupdates(repo, action, wc, p2, pa)
Matt Mackall
merge: consolidate dirstate updates
r2899
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 if not partial:
Benoit Boissinot
dirstate: more explicit name, rename normaldirty() to otherparent()
r10968 repo.dirstate.setparents(fp1, fp2)
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 recordupdates(repo, action, branchmerge)
if not branchmerge and not fastforward:
repo.dirstate.setbranch(p2.branch())
finally:
Ronny Pfannschmidt
switch lock releasing in the core from gc to explicit
r8109 wlock.release()
Sune Foldager
run commit and update hooks after command completion (issue1827)...
r10492
if not partial:
repo.hook('update', parent1=xp1, parent2=xp2, error=stats[3])
return stats