comparison mercurial/merge.py @ 3240:8d4855fd9d7b

merge: use new working context object in update
author Matt Mackall <mpm@selenic.com>
date Tue, 03 Oct 2006 01:21:46 -0500
parents cac7be0b9b99
children 7a0d70b69d74
comparison
equal deleted inserted replaced
3239:6d98149d70fe 3240:8d4855fd9d7b
57 57
58 os.unlink(b) 58 os.unlink(b)
59 os.unlink(c) 59 os.unlink(c)
60 return r 60 return r
61 61
62 def checkunknown(repo, m2, status): 62 def checkunknown(repo, m2, wctx):
63 """ 63 """
64 check for collisions between unknown files and files in m2 64 check for collisions between unknown files and files in m2
65 """ 65 """
66 modified, added, removed, deleted, unknown = status[:5] 66 for f in wctx.unknown():
67 for f in unknown:
68 if f in m2: 67 if f in m2:
69 if repo.file(f).cmp(m2[f], repo.wread(f)): 68 if repo.file(f).cmp(m2[f], repo.wread(f)):
70 raise util.Abort(_("'%s' already exists in the working" 69 raise util.Abort(_("'%s' already exists in the working"
71 " dir and differs from remote") % f) 70 " dir and differs from remote") % f)
72 71
73 def workingmanifest(repo, man, status): 72 def forgetremoved(m2, wctx):
74 """
75 Update manifest to correspond to the working directory
76 """
77
78 copied = repo.dirstate.copies()
79 modified, added, removed, deleted, unknown = status[:5]
80 for i,l in (("a", added), ("m", modified), ("u", unknown)):
81 for f in l:
82 man[f] = man.get(copied.get(f, f), nullid) + i
83 man.set(f, util.is_exec(repo.wjoin(f), man.execf(f)))
84
85 for f in deleted + removed:
86 del man[f]
87
88 return man
89
90 def forgetremoved(m2, status):
91 """ 73 """
92 Forget removed files 74 Forget removed files
93 75
94 If we're jumping between revisions (as opposed to merging), and if 76 If we're jumping between revisions (as opposed to merging), and if
95 neither the working directory nor the target rev has the file, 77 neither the working directory nor the target rev has the file,
96 then we need to remove it from the dirstate, to prevent the 78 then we need to remove it from the dirstate, to prevent the
97 dirstate from listing the file when it is no longer in the 79 dirstate from listing the file when it is no longer in the
98 manifest. 80 manifest.
99 """ 81 """
100 82
101 modified, added, removed, deleted, unknown = status[:5]
102 action = [] 83 action = []
103 84
104 for f in deleted + removed: 85 for f in wctx.deleted() + wctx.removed():
105 if f not in m2: 86 if f not in m2:
106 action.append((f, "f")) 87 action.append((f, "f"))
107 88
108 return action 89 return action
109 90
330 if not wlock: 311 if not wlock:
331 wlock = repo.wlock() 312 wlock = repo.wlock()
332 313
333 ### check phase 314 ### check phase
334 315
335 pl = repo.parents() 316 wc = repo.workingctx()
317 pl = wc.parents()
336 if not overwrite and len(pl) > 1: 318 if not overwrite and len(pl) > 1:
337 raise util.Abort(_("outstanding uncommitted merges")) 319 raise util.Abort(_("outstanding uncommitted merges"))
338 320
339 p1, p2 = pl[0], repo.changectx(node) 321 p1, p2 = pl[0], repo.changectx(node)
340 pa = p1.ancestor(p2) 322 pa = p1.ancestor(p2)
349 "'hg update' or look at 'hg heads'")) 331 "'hg update' or look at 'hg heads'"))
350 elif not (overwrite or branchmerge): 332 elif not (overwrite or branchmerge):
351 raise util.Abort(_("update spans branches, use 'hg merge' " 333 raise util.Abort(_("update spans branches, use 'hg merge' "
352 "or 'hg update -C' to lose changes")) 334 "or 'hg update -C' to lose changes"))
353 335
354 status = repo.status()
355 modified, added, removed, deleted, unknown = status[:5]
356 if branchmerge and not forcemerge: 336 if branchmerge and not forcemerge:
357 if modified or added or removed: 337 if wc.modified() or wc.added() or wc.removed():
358 raise util.Abort(_("outstanding uncommitted changes")) 338 raise util.Abort(_("outstanding uncommitted changes"))
359 339
360 m1 = p1.manifest().copy() 340 m1 = wc.manifest().copy()
361 m2 = p2.manifest().copy() 341 m2 = p2.manifest().copy()
362 ma = pa.manifest() 342 ma = pa.manifest()
363 343
364 # resolve the manifest to determine which files 344 # resolve the manifest to determine which files
365 # we care about merging 345 # we care about merging
369 repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (p1, p2, pa)) 349 repo.ui.debug(_(" ancestor %s local %s remote %s\n") % (p1, p2, pa))
370 350
371 action = [] 351 action = []
372 copy = {} 352 copy = {}
373 353
374 m1 = workingmanifest(repo, m1, status)
375 filtermanifest(m1, partial) 354 filtermanifest(m1, partial)
376 filtermanifest(m2, partial) 355 filtermanifest(m2, partial)
377 356
378 if not force: 357 if not force:
379 checkunknown(repo, m2, status) 358 checkunknown(repo, m2, wc)
380 if not branchmerge: 359 if not branchmerge:
381 action += forgetremoved(m2, status) 360 action += forgetremoved(m2, wc)
382 if not (backwards or overwrite): 361 if not (backwards or overwrite):
383 copy = findcopies(repo, m1, m2, pa.rev()) 362 copy = findcopies(repo, m1, m2, pa.rev())
384 363
385 action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards) 364 action += manifestmerge(repo.ui, m1, m2, ma, overwrite, backwards)
386 del m1, m2, ma 365 del m1, m2, ma