changeset 993:6f274afc05c7

Clean up some merge logic - rename mode to branch_merge - use explicit update mode - use negative mtime for updates that set mtime - expand some cryptic variable names - elaborate merge dirstate comments - remove redundant manifest lookup for non-merge case - remove impossible merge case - fix up test cases
author mpm@selenic.com
date Tue, 23 Aug 2005 02:19:38 -0700
parents f859e9cba1b9
children 88c15682d9b0
files mercurial/hg.py tests/test-filebranch tests/test-filebranch.out tests/test-merge6.out tests/test-rawcommit1.out tests/test-tags.out
diffstat 6 files changed, 54 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hg.py	Mon Aug 22 01:22:29 2005 -0700
+++ b/mercurial/hg.py	Tue Aug 23 02:19:38 2005 -0700
@@ -1749,7 +1749,7 @@
 
         if linear_path or force:
             # we don't need to do any magic, just jump to the new rev
-            mode = 'n'
+            branch_merge = False
             p1, p2 = p2, nullid
         else:
             if not allow:
@@ -1765,7 +1765,7 @@
                 self.ui.status("(use update -m to merge across branches" +
                                " or -C to lose changes)\n")
                 return 1
-            mode = 'm'
+            branch_merge = True
 
         if moddirstate:
             self.dirstate.setparents(p1, p2)
@@ -1784,8 +1784,8 @@
                 self.wfile(f, "w").write(t)
             util.set_exec(self.wjoin(f), mf2[f])
             if moddirstate:
-                if mode == 'm':
-                    self.dirstate.update([f], 'n', st_mtime=0)
+                if branch_merge:
+                    self.dirstate.update([f], 'n', st_mtime=-1)
                 else:
                     self.dirstate.update([f], 'n')
 
@@ -1794,23 +1794,22 @@
         files.sort()
         for f in files:
             self.ui.status("merging %s\n" % f)
-            m, o, flag = merge[f]
-            self.merge3(f, m, o)
+            my, other, flag = merge[f]
+            self.merge3(f, my, other)
             util.set_exec(self.wjoin(f), flag)
             if moddirstate:
-                if mode == 'm':
-                    # only update dirstate on branch merge, otherwise we
-                    # could mark files with changes as unchanged
-                    self.dirstate.update([f], mode)
-                elif p2 == nullid:
-                    # update dirstate from parent1's manifest
-                    m1n = self.changelog.read(p1)[0]
-                    m1 = self.manifest.read(m1n)
-                    f_len = len(self.file(f).read(m1[f]))
-                    self.dirstate.update([f], mode, st_size=f_len, st_mtime=0)
+                if branch_merge:
+                    # We've done a branch merge, mark this file as merged
+                    # so that we properly record the merger later
+                    self.dirstate.update([f], 'm')
                 else:
-                    self.ui.warn("Second parent without branch merge!?\n"
-                                 "Dirstate for file %s may be wrong.\n" % f)
+                    # We've update-merged a locally modified file, so
+                    # we set the dirstate to emulate a normal checkout
+                    # of that file some time in the past. Thus our
+                    # merge will appear as a normal local file
+                    # modification.
+                    f_len = len(self.file(f).read(other))
+                    self.dirstate.update([f], 'n', st_size=f_len, st_mtime=-1)
 
         remove.sort()
         for f in remove:
@@ -1823,10 +1822,10 @@
             try: os.removedirs(os.path.dirname(self.wjoin(f)))
             except: pass
         if moddirstate:
-            if mode == 'n':
+            if branch_merge:
+                self.dirstate.update(remove, 'r')
+            else:
                 self.dirstate.forget(remove)
-            else:
-                self.dirstate.update(remove, 'r')
 
     def merge3(self, fn, my, other):
         """perform a 3-way merge in the working directory"""
--- a/tests/test-filebranch	Mon Aug 22 01:22:29 2005 -0700
+++ b/tests/test-filebranch	Tue Aug 23 02:19:38 2005 -0700
@@ -41,7 +41,7 @@
 
 echo merging
 hg pull ../a
-env HGMERGE=../merge hg update -vm --debug
+env HGMERGE=../merge hg update -vm
 
 echo 2m > foo
 echo 2b > baz
@@ -55,6 +55,9 @@
 echo "main: we should have a merge here"
 hg debugindex .hg/00changelog.i
 
+echo "log should show foo and quux changed"
+hg log -v -r tip
+
 echo "foo: we should have a merge here"
 hg debugindex .hg/data/foo.i
 
@@ -67,6 +70,9 @@
 echo "quux: we shouldn't have a merge here"
 hg debugindex .hg/data/quux.i
 
+echo "manifest entries should match tips of all files"
+hg manifest
+
 echo "everything should be clean now"
 hg status
 
--- a/tests/test-filebranch.out	Mon Aug 22 01:22:29 2005 -0700
+++ b/tests/test-filebranch.out	Tue Aug 23 02:19:38 2005 -0700
@@ -16,14 +16,9 @@
 (run 'hg update' to get a working copy)
 merging for foo
 resolving manifests
- force None allow 1 moddirstate True linear False
- ancestor a0486579db29 local ef1b4dbe2193 remote 336d8406d617
- remote bar is newer, get
- foo versions differ, resolve
 getting bar
 merging foo
 resolving foo
-file foo: other 33d1fb69067a ancestor b8e02f643373
 we shouldn't have anything but foo in merge state here
 m 644          3 foo
 main: we should have a merge here
@@ -31,7 +26,19 @@
      0         0      73      0       0 cdca01651b96 000000000000 000000000000
      1        73      68      1       1 f6718a9cb7f3 cdca01651b96 000000000000
      2       141      68      2       2 bdd988058d16 cdca01651b96 000000000000
-     3       209      66      3       3 9da9fbd62226 f6718a9cb7f3 bdd988058d16
+     3       209      66      3       3 d8a521142a3c f6718a9cb7f3 bdd988058d16
+log should show foo and quux changed
+changeset:   3:d8a521142a3c02186ee6c7254738a7e6427ed4c8
+tag:         tip
+parent:      1:f6718a9cb7f31f1a92d27bd6544c71617d6d4e4f
+parent:      2:bdd988058d16e2d7392958eace7b64817e44a54e
+user:        test
+date:        Thu Jan  1 00:00:00 1970 +0000
+files:       foo quux
+description:
+merge
+
+
 foo: we should have a merge here
    rev    offset  length   base linkrev nodeid       p1           p2
      0         0       3      0       0 b8e02f643373 000000000000 000000000000
@@ -50,6 +57,11 @@
    rev    offset  length   base linkrev nodeid       p1           p2
      0         0       3      0       0 b8e02f643373 000000000000 000000000000
      1         3       5      1       3 6128c0f33108 b8e02f643373 000000000000
+manifest entries should match tips of all files
+33d1fb69067a0139622a3fa3b7ba1cdb1367972e 644 bar
+2ffeddde1b65b4827f6746174a145474129fa2ce 644 baz
+aa27919ee4303cfd575e1fb932dd64d75aa08be4 644 foo
+6128c0f33108e8cfbb4e0824d13ae48b466d7280 644 quux
 everything should be clean now
 checking changesets
 checking manifests
--- a/tests/test-merge6.out	Mon Aug 22 01:22:29 2005 -0700
+++ b/tests/test-merge6.out	Tue Aug 23 02:19:38 2005 -0700
@@ -6,7 +6,7 @@
 added 1 changesets with 1 changes to 1 files
 (run 'hg update' to get a working copy)
 bar should remain deleted.
-f405ac83a5611071d6b54dd5eb26943b1fdc4460 644 foo
+f9b0e817f6a48de3564c6b2957687c5e7297c5a0 644 foo
 pulling from ../A2
 searching for changes
 adding changesets
--- a/tests/test-rawcommit1.out	Mon Aug 22 01:22:29 2005 -0700
+++ b/tests/test-rawcommit1.out	Tue Aug 23 02:19:38 2005 -0700
@@ -11,7 +11,7 @@
 
 05f9e54f4c9b86b09099803d8b49a50edcb4eaab 644 a
 76d5e637cbec1bcc04a5a3fa4bcc7d13f6847c00 644 c
-changeset:   3:c8225a106186
+changeset:   3:142428fbbcc5
 tag:         tip
 user:        test
 date:        Thu Jan  1 00:00:00 1970 +0000
@@ -19,7 +19,7 @@
 
 d6e3c4976c13feb1728cd3ac851abaf7256a5c23 644 a
 76d5e637cbec1bcc04a5a3fa4bcc7d13f6847c00 644 c
-changeset:   4:8dfeee82a94b
+changeset:   4:4d450f9aa680
 tag:         tip
 user:        test
 date:        Thu Jan  1 00:00:00 1970 +0000
@@ -28,16 +28,16 @@
 05f9e54f4c9b86b09099803d8b49a50edcb4eaab 644 a
 54837d97f2932a8194e69745a280a2c11e61ff9c 644 b
 3570202ceac2b52517df64ebd0a062cb0d8fe33a 644 c
-changeset:   4:8dfeee82a94b
+changeset:   4:4d450f9aa680
 user:        test
 date:        Thu Jan  1 00:00:00 1970 +0000
 summary:     4
 
 d6e3c4976c13feb1728cd3ac851abaf7256a5c23 644 a
 76d5e637cbec1bcc04a5a3fa4bcc7d13f6847c00 644 c
-changeset:   6:c0e932ecae5e
+changeset:   6:b4b8b9afa8cc
 tag:         tip
-parent:      4:8dfeee82a94b
+parent:      4:4d450f9aa680
 parent:      5:a7925a42d0df
 user:        test
 date:        Thu Jan  1 00:00:00 1970 +0000
@@ -45,7 +45,7 @@
 
 d6e3c4976c13feb1728cd3ac851abaf7256a5c23 644 a
 76d5e637cbec1bcc04a5a3fa4bcc7d13f6847c00 644 c
-changeset:   7:3a157da4365d
+changeset:   7:f84d0b1b024e
 tag:         tip
 user:        test
 date:        Thu Jan  1 00:00:00 1970 +0000
--- a/tests/test-tags.out	Mon Aug 22 01:22:29 2005 -0700
+++ b/tests/test-tags.out	Tue Aug 23 02:19:38 2005 -0700
@@ -10,4 +10,5 @@
 acb14030fe0a21b60322c440ad2d20cf7685a376+ first
 M a
 c8edf04160c7 tip
-c8edf04160c7+b9154636be93 tip
+c8edf04160c7+b9154636be93+ tip
+M .hgtags