##// END OF EJS Templates
filemerge: reduce creation of tempfiles until needed...
Phil Cohen -
r34037:96123bde default
parent child Browse files
Show More
@@ -493,34 +493,38 b' def _xmerge(repo, mynode, orig, fcd, fco'
493 repo.ui.warn(_('warning: %s cannot merge change/delete conflict '
493 repo.ui.warn(_('warning: %s cannot merge change/delete conflict '
494 'for %s\n') % (tool, fcd.path()))
494 'for %s\n') % (tool, fcd.path()))
495 return False, 1, None
495 return False, 1, None
496 unused, b, c, back = files
496 unused, unused, unused, back = files
497 a = _workingpath(repo, fcd)
497 a = _workingpath(repo, fcd)
498 out = ""
498 b, c = _maketempfiles(repo, fco, fca)
499 env = {'HG_FILE': fcd.path(),
499 try:
500 'HG_MY_NODE': short(mynode),
500 out = ""
501 'HG_OTHER_NODE': str(fco.changectx()),
501 env = {'HG_FILE': fcd.path(),
502 'HG_BASE_NODE': str(fca.changectx()),
502 'HG_MY_NODE': short(mynode),
503 'HG_MY_ISLINK': 'l' in fcd.flags(),
503 'HG_OTHER_NODE': str(fco.changectx()),
504 'HG_OTHER_ISLINK': 'l' in fco.flags(),
504 'HG_BASE_NODE': str(fca.changectx()),
505 'HG_BASE_ISLINK': 'l' in fca.flags(),
505 'HG_MY_ISLINK': 'l' in fcd.flags(),
506 }
506 'HG_OTHER_ISLINK': 'l' in fco.flags(),
507
507 'HG_BASE_ISLINK': 'l' in fca.flags(),
508 ui = repo.ui
508 }
509 ui = repo.ui
509
510
510 args = _toolstr(ui, tool, "args", '$local $base $other')
511 args = _toolstr(ui, tool, "args", '$local $base $other')
511 if "$output" in args:
512 if "$output" in args:
512 out, a = a, back # read input from backup, write to original
513 out, a = a, back # read input from backup, write to original
513 replace = {'local': a, 'base': b, 'other': c, 'output': out}
514 replace = {'local': a, 'base': b, 'other': c, 'output': out}
514 args = util.interpolate(r'\$', replace, args,
515 args = util.interpolate(r'\$', replace, args,
515 lambda s: util.shellquote(util.localpath(s)))
516 lambda s: util.shellquote(util.localpath(s)))
516 cmd = toolpath + ' ' + args
517 cmd = toolpath + ' ' + args
517 if _toolbool(ui, tool, "gui"):
518 if _toolbool(ui, tool, "gui"):
518 repo.ui.status(_('running merge tool %s for file %s\n') %
519 repo.ui.status(_('running merge tool %s for file %s\n') %
519 (tool, fcd.path()))
520 (tool, fcd.path()))
520 repo.ui.debug('launching merge tool: %s\n' % cmd)
521 repo.ui.debug('launching merge tool: %s\n' % cmd)
521 r = ui.system(cmd, cwd=repo.root, environ=env, blockedtag='mergetool')
522 r = ui.system(cmd, cwd=repo.root, environ=env, blockedtag='mergetool')
522 repo.ui.debug('merge tool returned: %s\n' % r)
523 repo.ui.debug('merge tool returned: %s\n' % r)
523 return True, r, False
524 return True, r, False
525 finally:
526 util.unlink(b)
527 util.unlink(c)
524
528
525 def _formatconflictmarker(repo, ctx, template, label, pad):
529 def _formatconflictmarker(repo, ctx, template, label, pad):
526 """Applies the given template to the ctx, prefixed by the label.
530 """Applies the given template to the ctx, prefixed by the label.
@@ -603,12 +607,9 b' def _makebackup(repo, ui, fcd, premerge)'
603 util.copyfile(a, back)
607 util.copyfile(a, back)
604 return back
608 return back
605
609
606 def _maketempfiles(repo, fcd, fco, fca):
610 def _maketempfiles(repo, fco, fca):
607 """Writes out `fco` and `fca` as temporary files, so an external merge
611 """Writes out `fco` and `fca` as temporary files, so an external merge
608 tool may use them.
612 tool may use them.
609
610 `fcd` is returned as-is, by convention, because it currently doubles as both
611 the local version and merge destination.
612 """
613 """
613 def temp(prefix, ctx):
614 def temp(prefix, ctx):
614 fullbase, ext = os.path.splitext(ctx.path())
615 fullbase, ext = os.path.splitext(ctx.path())
@@ -620,11 +621,10 b' def _maketempfiles(repo, fcd, fco, fca):'
620 f.close()
621 f.close()
621 return name
622 return name
622
623
623 a = repo.wjoin(fcd.path())
624 b = temp("base", fca)
624 b = temp("base", fca)
625 c = temp("other", fco)
625 c = temp("other", fco)
626
626
627 return a, b, c
627 return b, c
628
628
629 def _filemerge(premerge, repo, mynode, orig, fcd, fco, fca, labels=None):
629 def _filemerge(premerge, repo, mynode, orig, fcd, fco, fca, labels=None):
630 """perform a 3-way merge in the working directory
630 """perform a 3-way merge in the working directory
@@ -687,7 +687,7 b' def _filemerge(premerge, repo, mynode, o'
687 return True, 1, False
687 return True, 1, False
688
688
689 back = _makebackup(repo, ui, fcd, premerge)
689 back = _makebackup(repo, ui, fcd, premerge)
690 files = _maketempfiles(repo, fcd, fco, fca) + (back,)
690 files = (None, None, None, back)
691 r = 1
691 r = 1
692 try:
692 try:
693 markerstyle = ui.config('ui', 'mergemarkers')
693 markerstyle = ui.config('ui', 'mergemarkers')
@@ -715,8 +715,6 b' def _filemerge(premerge, repo, mynode, o'
715 finally:
715 finally:
716 if not r and back is not None:
716 if not r and back is not None:
717 util.unlink(back)
717 util.unlink(back)
718 util.unlink(files[1])
719 util.unlink(files[2])
720
718
721 def _check(repo, r, ui, tool, fcd, files):
719 def _check(repo, r, ui, tool, fcd, files):
722 fd = fcd.path()
720 fd = fcd.path()
General Comments 0
You need to be logged in to leave comments. Login now