# HG changeset patch # User mpm@selenic.com # Date 2005-07-03 02:25:15 # Node ID ffeb2c3a19669102df8110b513fa163d0da36e7f # Parent e33c85d2812a5f6cfdff9caed9ef6c7c72b88499 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----- diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -852,6 +852,7 @@ class localrepository: m = self.changelog.nodemap search = [] fetch = [] + base = {} seen = {} seenbranch = {} @@ -861,6 +862,7 @@ class localrepository: 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 @@ class localrepository: 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 @@ class localrepository: 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 @@ class localrepository: 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 @@ class localrepository: 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 @@ class localrepository: 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 " + diff --git a/tests/test-unrelated-pull b/tests/test-unrelated-pull new file mode 100755 --- /dev/null +++ b/tests/test-unrelated-pull @@ -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 diff --git a/tests/test-unrelated-pull.out b/tests/test-unrelated-pull.out new file mode 100644 --- /dev/null +++ b/tests/test-unrelated-pull.out @@ -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 +