comparison mercurial/merge.py @ 2828:0f787997e3c2

Merge: move most tests to the beginning
author Matt Mackall <mpm@selenic.com>
date Tue, 08 Aug 2006 10:35:19 -0500
parents 56f99f5aab34
children 4870f795f681
comparison
equal deleted inserted replaced
2827:56f99f5aab34 2828:0f787997e3c2
51 forcemerge=False, wlock=None, show_stats=True, remind=True): 51 forcemerge=False, wlock=None, show_stats=True, remind=True):
52 52
53 if not wlock: 53 if not wlock:
54 wlock = repo.wlock() 54 wlock = repo.wlock()
55 55
56 ### check phase
57
56 pl = repo.dirstate.parents() 58 pl = repo.dirstate.parents()
57 if not force and pl[1] != nullid: 59 if not force and pl[1] != nullid:
58 raise util.Abort(_("outstanding uncommitted merges")) 60 raise util.Abort(_("outstanding uncommitted merges"))
59 61
60 p1, p2 = pl[0], node 62 p1, p2 = pl[0], node
61 pa = repo.changelog.ancestor(p1, p2) 63 pa = repo.changelog.ancestor(p1, p2)
64
65 # is there a linear path from p1 to p2?
66 linear_path = (pa == p1 or pa == p2)
67 if branchmerge and linear_path:
68 raise util.Abort(_("there is nothing to merge, just use "
69 "'hg update' or look at 'hg heads'"))
70
71 if not force and not linear_path and not branchmerge:
72 raise util.Abort(_("this update spans a branch, use 'hg merge' "
73 "or 'hg update -C' to lose changes"))
74
75 modified, added, removed, deleted, unknown = repo.changes()
76 if branchmerge and not forcemerge:
77 if modified or added or removed:
78 raise util.Abort(_("outstanding uncommitted changes"))
79
62 m1n = repo.changelog.read(p1)[0] 80 m1n = repo.changelog.read(p1)[0]
63 m2n = repo.changelog.read(p2)[0] 81 m2n = repo.changelog.read(p2)[0]
64 man = repo.manifest.ancestor(m1n, m2n) 82 man = repo.manifest.ancestor(m1n, m2n)
65 m1 = repo.manifest.read(m1n) 83 m1 = repo.manifest.read(m1n)
66 mf1 = repo.manifest.readflags(m1n) 84 mf1 = repo.manifest.readflags(m1n)
67 m2 = repo.manifest.read(m2n).copy() 85 m2 = repo.manifest.read(m2n).copy()
68 mf2 = repo.manifest.readflags(m2n) 86 mf2 = repo.manifest.readflags(m2n)
69 ma = repo.manifest.read(man) 87 ma = repo.manifest.read(man)
70 mfa = repo.manifest.readflags(man) 88 mfa = repo.manifest.readflags(man)
71
72 modified, added, removed, deleted, unknown = repo.changes()
73
74 # is this a jump, or a merge? i.e. is there a linear path
75 # from p1 to p2?
76 linear_path = (pa == p1 or pa == p2)
77
78 if branchmerge and linear_path:
79 raise util.Abort(_("there is nothing to merge, just use "
80 "'hg update' or look at 'hg heads'"))
81 if branchmerge and not forcemerge:
82 if modified or added or removed:
83 raise util.Abort(_("outstanding uncommitted changes"))
84 89
85 if not forcemerge and not force: 90 if not forcemerge and not force:
86 for f in unknown: 91 for f in unknown:
87 if f in m2: 92 if f in m2:
88 t1 = repo.wread(f) 93 t1 = repo.wread(f)
232 merge = {} 237 merge = {}
233 238
234 if linear_path or force: 239 if linear_path or force:
235 # we don't need to do any magic, just jump to the new rev 240 # we don't need to do any magic, just jump to the new rev
236 p1, p2 = p2, nullid 241 p1, p2 = p2, nullid
237 else:
238 if not branchmerge:
239 repo.ui.status(_("this update spans a branch"
240 " affecting the following files:\n"))
241 fl = merge.keys() + get.keys()
242 fl.sort()
243 for f in fl:
244 cf = ""
245 if f in merge:
246 cf = _(" (resolve)")
247 repo.ui.status(" %s%s\n" % (f, cf))
248 repo.ui.warn(_("aborting update spanning branches!\n"))
249 repo.ui.status(_("(use 'hg merge' to merge across branches"
250 " or 'hg update -C' to lose changes)\n"))
251 return 1
252 242
253 xp1 = hex(p1) 243 xp1 = hex(p1)
254 xp2 = hex(p2) 244 xp2 = hex(p2)
255 if p2 == nullid: xxp2 = '' 245 if p2 == nullid: xxp2 = ''
256 else: xxp2 = xp2 246 else: xxp2 = xp2