diff mercurial/hg.py @ 990:5007e0bdeed2

Fix long-standing excessive file merges Since switching to the multihead approach, we've been creating excessive file-level merges where files are marked as merged with their ancestors. This explicitly checks at commit time whether the two parent versions are linearly related, and if so, reduces the file check-in to a non-merge. Then the file is compared against the remaining parent, and, if equal, skips check-in of that file (as it's not changed). Since we're not checking in all files that were different between versions, we no longer need to mark so many files for merge. This removes most of the 'm' state marking as well. Finally, it is possible to do a tree-level merge with no file-level changes. This will happen if one user changes file A and another changes file B. Thus, if we have have two parents, we allow commit to proceed even if there are no file-level changes.
author mpm@selenic.com
date Sun, 21 Aug 2005 21:59:55 -0700
parents 4f81068ed8cd
children b634b15c020b
line wrap: on
line diff
--- a/mercurial/hg.py	Sun Aug 21 16:51:50 2005 -0700
+++ b/mercurial/hg.py	Sun Aug 21 21:59:55 2005 -0700
@@ -840,8 +840,30 @@
                 tm = util.is_exec(self.wjoin(f), mfm.get(f, False))
                 r = self.file(f)
                 mfm[f] = tm
-                mm[f] = r.add(t, {}, tr, linkrev,
-                              m1.get(f, nullid), m2.get(f, nullid))
+
+                fp1 = m1.get(f, nullid)
+                fp2 = m2.get(f, nullid)
+
+                # is the same revision on two branches of a merge?
+                if fp2 == fp1:
+                    fp2 = nullid
+
+                if fp2 != nullid:
+                    # is one parent an ancestor of the other?
+                    fpa = r.ancestor(fp1, fp2)
+                    if fpa == fp1:
+                        fp1, fp2 = fp2, nullid
+                    elif fpa == fp2:
+                        fp2 = nullid
+
+                    # is the file unmodified from the parent?
+                    if t == r.read(fp1):
+                        # record the proper existing parent in manifest
+                        # no need to add a revision
+                        mm[f] = fp1
+                        continue
+
+                mm[f] = r.add(t, {}, tr, linkrev, fp1, fp2)
                 if update_dirstate:
                     self.dirstate.update([f], "n")
             except IOError:
@@ -879,19 +901,20 @@
             commit = c + a
             remove = d
 
-        if not commit and not remove and not force:
+        p1, p2 = self.dirstate.parents()
+        c1 = self.changelog.read(p1)
+        c2 = self.changelog.read(p2)
+        m1 = self.manifest.read(c1[0])
+        mf1 = self.manifest.readflags(c1[0])
+        m2 = self.manifest.read(c2[0])
+
+        if not commit and not remove and not force and p2 == nullid:
             self.ui.status("nothing changed\n")
             return None
 
         if not self.hook("precommit"):
             return None
 
-        p1, p2 = self.dirstate.parents()
-        c1 = self.changelog.read(p1)
-        c2 = self.changelog.read(p2)
-        m1 = self.manifest.read(c1[0])
-        mf1 = self.manifest.readflags(c1[0])
-        m2 = self.manifest.read(c2[0])
         lock = self.lock()
         tr = self.transaction()
 
@@ -918,6 +941,26 @@
             r = self.file(f)
             fp1 = m1.get(f, nullid)
             fp2 = m2.get(f, nullid)
+
+            # is the same revision on two branches of a merge?
+            if fp2 == fp1:
+                fp2 = nullid
+
+            if fp2 != nullid:
+                # is one parent an ancestor of the other?
+                fpa = r.ancestor(fp1, fp2)
+                if fpa == fp1:
+                    fp1, fp2 = fp2, nullid
+                elif fpa == fp2:
+                    fp2 = nullid
+
+                # is the file unmodified from the parent?
+                if not meta and t == r.read(fp1):
+                    # record the proper existing parent in manifest
+                    # no need to add a revision
+                    new[f] = fp1
+                    continue
+
             new[f] = r.add(t, meta, tr, linkrev, fp1, fp2)
 
         # update manifest
@@ -1715,12 +1758,7 @@
                 self.ui.status("(use update -m to merge across branches" +
                                " or -C to lose changes)\n")
                 return 1
-            # we have to remember what files we needed to get/change
-            # because any file that's different from either one of its
-            # parents must be in the changeset
             mode = 'm'
-            if moddirstate:
-                self.dirstate.update(mark.keys(), "m")
 
         if moddirstate:
             self.dirstate.setparents(p1, p2)
@@ -1739,7 +1777,7 @@
                 self.wfile(f, "w").write(t)
             util.set_exec(self.wjoin(f), mf2[f])
             if moddirstate:
-                self.dirstate.update([f], mode)
+                self.dirstate.update([f], 'n')
 
         # merge the tricky bits
         files = merge.keys()