Actually warn on pulling from an unrelated repository
authormpm@selenic.com
Sat, 02 Jul 2005 18:25:15 -0800
changeset 579 ffeb2c3a1966
parent 578 e33c85d2812a
child 580 353a2ce50423
Actually warn on pulling from an unrelated repository -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Actually warn on pulling from an unrelated repository add some comments to findincoming track the base nodes of the fetch set report if the base set only contains nullid add a test case manifest hash: 3fc038a6041b0967a20503f5ec8876efc038841a -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCx0yLywK+sNU5EO8RAlK6AJ9J/GKPpYSMzTqmguXPWOISJ+zY5gCghd+j ClLpn0dKZnB46dh0F8zhuuk= =emNb -----END PGP SIGNATURE-----
mercurial/hg.py
tests/test-unrelated-pull
tests/test-unrelated-pull.out
--- a/mercurial/hg.py	Sat Jul 02 15:38:16 2005 -0800
+++ b/mercurial/hg.py	Sat Jul 02 18:25:15 2005 -0800
@@ -852,6 +852,7 @@
         m = self.changelog.nodemap
         search = []
         fetch = []
+        base = {}
         seen = {}
         seenbranch = {}
 
@@ -861,6 +862,7 @@
             return [nullid]
 
         # otherwise, assume we're closer to the tip than the root
+        # and start by examining the heads
         self.ui.status("searching for changes\n")
         heads = remote.heads()
         unknown = []
@@ -874,6 +876,10 @@
         rep = {}
         reqcnt = 0
 
+        # search through remote branches
+        # a 'branch' here is a linear segment of history, with four parts:
+        # head, root, first parent, second parent
+        # (a branch always has two parents (or none) by definition)
         unknown = remote.branches(unknown)
         while unknown:
             r = []
@@ -899,6 +905,7 @@
                             self.ui.debug("found new changeset %s\n" %
                                           short(n[1]))
                             fetch.append(n[1]) # earliest unknown
+                            base[n[2]] = 1 # latest known
                             continue
 
                     for a in n[2:4]:
@@ -919,6 +926,7 @@
                         if b[0] not in m and b[0] not in seen:
                             unknown.append(b)
 
+        # do binary search on the branches we found
         while search:
             n = search.pop(0)
             reqcnt += 1
@@ -933,6 +941,7 @@
                         self.ui.debug("found new branch changeset %s\n" %
                                           short(p))
                         fetch.append(p)
+                        base[i] = 1
                     else:
                         self.ui.debug("narrowed branch search to %s:%s\n"
                                       % (short(p), short(i)))
@@ -940,11 +949,12 @@
                     break
                 p, f = i, f * 2
 
+        # sanity check our fetch list
         for f in fetch:
             if f in m:
                 raise RepoError("already have changeset " + short(f[:4]))
 
-        if fetch == [nullid]:
+        if base.keys() == [nullid]:
             self.ui.warn("warning: pulling from an unrelated repository!\n")
 
         self.ui.note("adding new changesets starting at " +
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-unrelated-pull	Sat Jul 02 18:25:15 2005 -0800
@@ -0,0 +1,17 @@
+mkdir a
+cd a
+hg init
+echo 123 > a
+hg add a
+hg commit -t "a" -u a -d "0 0"
+
+cd ..
+mkdir b
+cd b
+hg init 
+echo 321 > b
+hg add b
+hg commit -t "b" -u b -d "0 0"
+
+hg pull ../a
+hg heads
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-unrelated-pull.out	Sat Jul 02 18:25:15 2005 -0800
@@ -0,0 +1,19 @@
+pulling from ../a
+searching for changes
+warning: pulling from an unrelated repository!
+adding changesets
+adding manifests
+adding file revisions
+modified 1 files, added 1 changesets and 1 new revisions
+(run 'hg update' to get a working copy)
+changeset:   1:9a79c33a9db37480e40fbd2a65d62ebd2a3c441c
+tag:         tip
+user:        a
+date:        Thu Jan  1 00:00:00 1970
+summary:     a
+
+changeset:   0:01f8062b2de51c0fa6428c5db1d1b3ea780189df
+user:        b
+date:        Thu Jan  1 00:00:00 1970
+summary:     b
+