[PATCH STABLE] hg: perform update after pulling during clone with share (issue5103)

Gregory Szorc gregory.szorc at gmail.com
Fri Mar 25 13:51:35 EDT 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1458928069 25200
#      Fri Mar 25 10:47:49 2016 -0700
# Branch stable
# Node ID 69a863eeb7ea4c420b29726de75ae2f315a258c3
# Parent  aa440c3d7c5d2baafeb632ee35db4d917ed9cf83
hg: perform update after pulling during clone with share (issue5103)

This is a graft of 60adda1a0188 and a4692267bc2d from the default
branch. Combined, they address a bug with pooled shared storage where
an update may not update to the most recent revision when performing
a `hg clone`.

The patches should have been written against the stable branch in
the beginning. I screwed up.

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -235,22 +235,9 @@ def share(ui, source, dest=None, update=
     destvfs.write('sharedpath', sharedpath)
 
     r = repository(ui, destwvfs.base)
     postshare(srcrepo, r, bookmarks=bookmarks)
-
-    if update:
-        r.ui.status(_("updating working directory\n"))
-        if update is not True:
-            checkout = update
-        for test in (checkout, 'default', 'tip'):
-            if test is None:
-                continue
-            try:
-                uprev = r.lookup(test)
-                break
-            except error.RepoLookupError:
-                continue
-        _update(r, uprev)
+    _postshareupdate(r, update, checkout=checkout)
 
 def postshare(sourcerepo, destrepo, bookmarks=True):
     """Called after a new shared repo is created.
 
@@ -271,8 +258,29 @@ def postshare(sourcerepo, destrepo, book
         fp = destrepo.vfs('shared', 'w')
         fp.write('bookmarks\n')
         fp.close()
 
+def _postshareupdate(repo, update, checkout=None):
+    """Maybe perform a working directory update after a shared repo is created.
+
+    ``update`` can be a boolean or a revision to update to.
+    """
+    if not update:
+        return
+
+    repo.ui.status(_("updating working directory\n"))
+    if update is not True:
+        checkout = update
+    for test in (checkout, 'default', 'tip'):
+        if test is None:
+            continue
+        try:
+            uprev = repo.lookup(test)
+            break
+        except error.RepoLookupError:
+            continue
+    _update(repo, uprev)
+
 def copystore(ui, srcrepo, destpath):
     '''copy files from store of srcrepo in destpath
 
     returns destlock
@@ -360,9 +368,9 @@ def clonewithshare(ui, peeropts, sharepa
             clone(ui, peeropts, source, dest=sharepath, pull=True,
                   rev=rev, update=False, stream=stream)
 
     sharerepo = repository(ui, path=sharepath)
-    share(ui, sharerepo, dest=dest, update=update, bookmarks=False)
+    share(ui, sharerepo, dest=dest, update=False, bookmarks=False)
 
     # We need to perform a pull against the dest repo to fetch bookmarks
     # and other non-store data that isn't shared by default. In the case of
     # non-existing shared repo, this means we pull from the remote twice. This
@@ -370,8 +378,10 @@ def clonewithshare(ui, peeropts, sharepa
     # way to pull just non-changegroup data.
     destrepo = repository(ui, path=dest)
     exchange.pull(destrepo, srcpeer, heads=revs)
 
+    _postshareupdate(destrepo, update)
+
     return srcpeer, peer(ui, peeropts, dest)
 
 def clone(ui, peeropts, source, dest=None, pull=False, rev=None,
           update=True, stream=False, branch=None, shareopts=None):
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -773,13 +773,13 @@ Clone from repo with content should resu
   adding changesets
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 1 files
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   no changes found
   adding remote bookmark bookA
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 The shared repo should have been created
 
   $ ls share
@@ -803,17 +803,17 @@ The default path should be the remote, n
 Clone with existing share dir should result in pull + share
 
   $ hg --config share.pool=share clone source1b share-dest1b
   (sharing from existing pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 4 changesets with 4 changes to 1 files (+4 heads)
   adding remote bookmark head1
   adding remote bookmark head2
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ ls share
   b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1
 
@@ -830,8 +830,19 @@ Default path should be source, not share
 
   $ hg -R share-dest1b config paths.default
   $TESTTMP/source1a (glob)
 
+Checked out revision should be head of default branch
+
+  $ hg -R share-dest1b log -r .
+  changeset:   4:99f71071f117
+  bookmark:    head2
+  parent:      0:b5f04eac9d8f
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     head2
+  
+
 Clone from unrelated repo should result in new share
 
   $ hg --config share.pool=share clone source2 share-dest2
   (sharing from new pooled repository 22aeff664783fd44c6d9b435618173c118c3448e)
@@ -839,12 +850,12 @@ Clone from unrelated repo should result 
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
+  searching for changes
+  no changes found
   updating working directory
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  searching for changes
-  no changes found
 
   $ ls share
   22aeff664783fd44c6d9b435618173c118c3448e
   b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1
@@ -857,13 +868,13 @@ remote naming mode works as advertised
   adding changesets
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 1 files
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   no changes found
   adding remote bookmark bookA
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ ls shareremote
   195bb1fcdb595c14a6c13e0269129ed78f6debde
 
@@ -873,14 +884,14 @@ remote naming mode works as advertised
   adding changesets
   adding manifests
   adding file changes
   added 6 changesets with 6 changes to 1 files (+4 heads)
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   no changes found
   adding remote bookmark head1
   adding remote bookmark head2
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ ls shareremote
   195bb1fcdb595c14a6c13e0269129ed78f6debde
   c0d4f83847ca2a873741feb7048a45085fd47c46
@@ -892,12 +903,12 @@ request to clone a single revision is re
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
+  no changes found
+  adding remote bookmark head1
   updating working directory
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  no changes found
-  adding remote bookmark head1
 
   $ hg -R share-1arev log -G
   @  changeset:   1:4a8dc1ab4c13
   |  bookmark:    head1
@@ -915,28 +926,28 @@ request to clone a single revision is re
 making another clone should only pull down requested rev
 
   $ hg --config share.pool=sharerevs clone -r 99f71071f117 source1b share-1brev
   (sharing from existing pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
   adding remote bookmark head1
   adding remote bookmark head2
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ hg -R share-1brev log -G
-  o  changeset:   2:99f71071f117
+  @  changeset:   2:99f71071f117
   |  bookmark:    head2
   |  tag:         tip
   |  parent:      0:b5f04eac9d8f
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     head2
   |
-  | @  changeset:   1:4a8dc1ab4c13
+  | o  changeset:   1:4a8dc1ab4c13
   |/   bookmark:    head1
   |    user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000
   |    summary:     head1
@@ -954,11 +965,11 @@ Request to clone a single branch is resp
   adding changesets
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 1 files
+  no changes found
   updating working directory
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
-  no changes found
 
   $ hg -R share-1bbranch1 log -G
   o  changeset:   1:5f92a6c1a1b1
   |  branch:      branch1
@@ -974,15 +985,15 @@ Request to clone a single branch is resp
   
 
   $ hg --config share.pool=sharebranch clone -b branch2 source1b share-1bbranch2
   (sharing from existing pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   adding changesets
   adding manifests
   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ hg -R share-1bbranch2 log -G
   o  changeset:   2:6bacf4683960
   |  branch:      branch2
@@ -1055,19 +1066,19 @@ Cloning into pooled storage doesn't race
   adding changesets
   adding manifests
   adding file changes
   added 3 changesets with 3 changes to 1 files
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   searching for changes
   no changes found
   adding remote bookmark bookA
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
   $ cat race2.log
   (sharing from existing pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
-  updating working directory
-  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   waiting for lock on repository share-destrace2 held by * (glob)
   got lock after \d+ seconds (re)
   searching for changes
   no changes found
   adding remote bookmark bookA
+  updating working directory
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved


More information about the Mercurial-devel mailing list