##// END OF EJS Templates
filemerge: extract _maketemp and _makebackup...
Phil Cohen -
r34033:52bd006b default
parent child Browse files
Show More
@@ -586,6 +586,46 b' def partextras(labels):'
586 "o": " [%s]" % labels[1],
586 "o": " [%s]" % labels[1],
587 }
587 }
588
588
589 def _makebackup(repo, ui, fcd, premerge):
590 """Makes a backup of the local `fcd` file prior to merging.
591
592 In addition to preserving the user's pre-existing modifications to `fcd`
593 (if any), the backup is used to undo certain premerges, confirm whether a
594 merge changed anything, and determine what line endings the new file should
595 have.
596 """
597 if fcd.isabsent():
598 return None
599
600 a = repo.wjoin(fcd.path())
601 back = scmutil.origpath(ui, repo, a)
602 if premerge:
603 util.copyfile(a, back)
604 return back
605
606 def _maketempfiles(repo, fcd, fco, fca):
607 """Writes out `fco` and `fca` as temporary files, so an external merge
608 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 def temp(prefix, ctx):
614 fullbase, ext = os.path.splitext(ctx.path())
615 pre = "%s~%s." % (os.path.basename(fullbase), prefix)
616 (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext)
617 data = repo.wwritedata(ctx.path(), ctx.data())
618 f = os.fdopen(fd, pycompat.sysstr("wb"))
619 f.write(data)
620 f.close()
621 return name
622
623 a = repo.wjoin(fcd.path())
624 b = temp("base", fca)
625 c = temp("other", fco)
626
627 return a, b, c
628
589 def _filemerge(premerge, repo, mynode, orig, fcd, fco, fca, labels=None):
629 def _filemerge(premerge, repo, mynode, orig, fcd, fco, fca, labels=None):
590 """perform a 3-way merge in the working directory
630 """perform a 3-way merge in the working directory
591
631
@@ -599,16 +639,6 b' def _filemerge(premerge, repo, mynode, o'
599 Returns whether the merge is complete, the return value of the merge, and
639 Returns whether the merge is complete, the return value of the merge, and
600 a boolean indicating whether the file was deleted from disk."""
640 a boolean indicating whether the file was deleted from disk."""
601
641
602 def temp(prefix, ctx):
603 fullbase, ext = os.path.splitext(ctx.path())
604 pre = "%s~%s." % (os.path.basename(fullbase), prefix)
605 (fd, name) = tempfile.mkstemp(prefix=pre, suffix=ext)
606 data = repo.wwritedata(ctx.path(), ctx.data())
607 f = os.fdopen(fd, pycompat.sysstr("wb"))
608 f.write(data)
609 f.close()
610 return name
611
612 if not fco.cmp(fcd): # files identical?
642 if not fco.cmp(fcd): # files identical?
613 return True, None, False
643 return True, None, False
614
644
@@ -656,17 +686,8 b' def _filemerge(premerge, repo, mynode, o'
656 ui.warn(onfailure % fd)
686 ui.warn(onfailure % fd)
657 return True, 1, False
687 return True, 1, False
658
688
659 a = repo.wjoin(fd)
689 back = _makebackup(repo, ui, fcd, premerge)
660 b = temp("base", fca)
690 files = _maketempfiles(repo, fcd, fco, fca) + (back,)
661 c = temp("other", fco)
662 if not fcd.isabsent():
663 back = scmutil.origpath(ui, repo, a)
664 if premerge:
665 util.copyfile(a, back)
666 else:
667 back = None
668 files = (a, b, c, back)
669
670 r = 1
691 r = 1
671 try:
692 try:
672 markerstyle = ui.config('ui', 'mergemarkers')
693 markerstyle = ui.config('ui', 'mergemarkers')
@@ -694,8 +715,8 b' def _filemerge(premerge, repo, mynode, o'
694 finally:
715 finally:
695 if not r and back is not None:
716 if not r and back is not None:
696 util.unlink(back)
717 util.unlink(back)
697 util.unlink(b)
718 util.unlink(files[1])
698 util.unlink(c)
719 util.unlink(files[2])
699
720
700 def _check(r, ui, tool, fcd, files):
721 def _check(r, ui, tool, fcd, files):
701 fd = fcd.path()
722 fd = fcd.path()
General Comments 0
You need to be logged in to leave comments. Login now