# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1444619080 25200
#      Sun Oct 11 20:04:40 2015 -0700
# Node ID f9f82c444ff79a87e902d859797daf2d505bf434
# Parent  47681e77e48477404c7383517af3963e999383e8
filemerge: only copy to backup during premerge step

The premerge might leave the original file in an unclean state. Therefore it's
important to only copy the file in the beginning.

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -505,7 +505,8 @@
     b = temp("base", fca)
     c = temp("other", fco)
     back = a + ".orig"
-    util.copyfile(a, back)
+    if premerge:
+        util.copyfile(a, back)
     files = (a, b, c, back)
 
     r = 1