comparison mercurial/merge.py @ 18630:9b9e2d9e83a1

merge: split out mostly-non-interactive working dir updates In a later patch, we'll run these updates in parallel.
author Bryan O'Sullivan <bryano@fb.com>
date Sat, 09 Feb 2013 15:21:58 -0800
parents 0b6e6eacc939
children 3e20079117c5
comparison
equal deleted inserted replaced
18622:f9eebf5629fa 18630:9b9e2d9e83a1
340 return actions 340 return actions
341 341
342 def actionkey(a): 342 def actionkey(a):
343 return a[1] == "r" and -1 or 0, a 343 return a[1] == "r" and -1 or 0, a
344 344
345 def getremove(repo, wctx, mctx, overwrite, args):
346 """apply usually-non-interactive updates to the working directory
347
348 wctx is the working copy context
349 mctx is the context to be merged into the working copy
350
351 yields tuples for progress updates
352 """
353 audit = repo.wopener.audit
354 for i, arg in enumerate(args):
355 f = arg[0]
356 if arg[1] == 'r':
357 repo.ui.note(_("removing %s\n") % f)
358 if f == '.hgsubstate': # subrepo states need updating
359 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
360 audit(f)
361 try:
362 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
363 except OSError, inst:
364 repo.ui.warn(_("update failed to remove %s: %s!\n") %
365 (f, inst.strerror))
366 else:
367 repo.ui.note(_("getting %s\n") % f)
368 repo.wwrite(f, mctx.filectx(f).data(), arg[2][0])
369 if f == '.hgsubstate': # subrepo states need updating
370 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
371 yield i, f
372
345 def applyupdates(repo, actions, wctx, mctx, actx, overwrite): 373 def applyupdates(repo, actions, wctx, mctx, actx, overwrite):
346 """apply the merge action list to the working directory 374 """apply the merge action list to the working directory
347 375
348 wctx is the working copy context 376 wctx is the working copy context
349 mctx is the context to be merged into the working copy 377 mctx is the context to be merged into the working copy
391 repo.ui.debug("removing %s\n" % f) 419 repo.ui.debug("removing %s\n" % f)
392 audit(f) 420 audit(f)
393 util.unlinkpath(repo.wjoin(f)) 421 util.unlinkpath(repo.wjoin(f))
394 422
395 numupdates = len(actions) 423 numupdates = len(actions)
424 workeractions = [a for a in actions if a[1] in 'gr']
425 updated = len([a for a in workeractions if a[1] == 'g'])
426 removed = len([a for a in workeractions if a[1] == 'r'])
427 actions = [a for a in actions if a[1] not in 'gr']
428
429 for i, item in getremove(repo, wctx, mctx, overwrite, workeractions):
430 repo.ui.progress(_('updating'), i + 1, item=item, total=numupdates,
431 unit=_('files'))
432
433 z = len(workeractions)
434
396 for i, a in enumerate(actions): 435 for i, a in enumerate(actions):
397 f, m, args, msg = a 436 f, m, args, msg = a
398 repo.ui.progress(_('updating'), i + 1, item=f, total=numupdates, 437 repo.ui.progress(_('updating'), z + i + 1, item=f, total=numupdates,
399 unit=_('files')) 438 unit=_('files'))
400 if m == "r": # remove 439 if m == "m": # merge
401 repo.ui.note(_("removing %s\n") % f)
402 audit(f)
403 if f == '.hgsubstate': # subrepo states need updating
404 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
405 try:
406 util.unlinkpath(repo.wjoin(f), ignoremissing=True)
407 except OSError, inst:
408 repo.ui.warn(_("update failed to remove %s: %s!\n") %
409 (f, inst.strerror))
410 removed += 1
411 elif m == "m": # merge
412 if fd == '.hgsubstate': # subrepo states need updating 440 if fd == '.hgsubstate': # subrepo states need updating
413 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx), 441 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
414 overwrite) 442 overwrite)
415 continue 443 continue
416 f2, fd, move = args 444 f2, fd, move = args
421 else: 449 else:
422 if r is None: 450 if r is None:
423 updated += 1 451 updated += 1
424 else: 452 else:
425 merged += 1 453 merged += 1
426 elif m == "g": # get
427 flags, = args
428 repo.ui.note(_("getting %s\n") % f)
429 repo.wwrite(f, mctx.filectx(f).data(), flags)
430 updated += 1
431 if f == '.hgsubstate': # subrepo states need updating
432 subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
433 elif m == "d": # directory rename 454 elif m == "d": # directory rename
434 f2, fd, flags = args 455 f2, fd, flags = args
435 if f: 456 if f:
436 repo.ui.note(_("moving %s to %s\n") % (f, fd)) 457 repo.ui.note(_("moving %s to %s\n") % (f, fd))
437 audit(f) 458 audit(f)