Patchwork [2,of,2] hg: perform update after pulling during clone with share (issue5103)

login
register
mail settings
Submitter Gregory Szorc
Date Feb. 21, 2016, 1:56 a.m.
Message ID <12b24bd7b041ddad8c83.1456019773@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/13281/
State Superseded
Commit a2c2dd399f3b9fb84edd75a930e895f0c5e4ad5b
Headers show

Comments

Gregory Szorc - Feb. 21, 2016, 1:56 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1456019069 28800
#      Sat Feb 20 17:44:29 2016 -0800
# Node ID 12b24bd7b041ddad8c83967a22e6963b44329ad5
# Parent  3f46918f408fc5594934991a21e704ee6f33a3b2
hg: perform update after pulling during clone with share (issue5103)

When pooled storage is enabled, `hg clone` will initialize a repo
from a local repo using the store sharing mechanism then pull from
the originally requested repo.

Before this patch, the working directory update occurred between
these steps. This meant that we would only update to revisions that
were already present in the local pooled storage.

This patch moves the update to after we pull from the originally
requested repository so we may check out a revision that didn't yet
exist locally. In other words, it makes the behavior like normal
`hg clone`.
Augie Fackler - Feb. 23, 2016, 7:36 p.m.
On Sat, Feb 20, 2016 at 05:56:13PM -0800, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1456019069 28800
> #      Sat Feb 20 17:44:29 2016 -0800
> # Node ID 12b24bd7b041ddad8c83967a22e6963b44329ad5
> # Parent  3f46918f408fc5594934991a21e704ee6f33a3b2
> hg: perform update after pulling during clone with share (issue5103)

Queued these, nice.

>
> When pooled storage is enabled, `hg clone` will initialize a repo
> from a local repo using the store sharing mechanism then pull from
> the originally requested repo.
>
> Before this patch, the working directory update occurred between
> these steps. This meant that we would only update to revisions that
> were already present in the local pooled storage.
>
> This patch moves the update to after we pull from the originally
> requested repository so we may check out a revision that didn't yet
> exist locally. In other words, it makes the behavior like normal
> `hg clone`.
>
> diff --git a/mercurial/hg.py b/mercurial/hg.py
> --- a/mercurial/hg.py
> +++ b/mercurial/hg.py
> @@ -351,26 +351,28 @@ def clonewithshare(ui, peeropts, sharepa
>      else:
>          ui.status(_('(sharing from new pooled repository %s)\n') % basename)
>          # Always use pull mode because hardlinks in share mode don't work well.
>          # Never update because working copies aren't necessary in share mode.
>          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
>      # is a bit weird. But at the time it was implemented, there wasn't an easy
>      # 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):
>      """Make a copy of an existing repository.
>
>      Create a copy of an existing repository in a new directory.  The
>      source and destination are URLs, as passed to the repository
> diff --git a/tests/test-clone.t b/tests/test-clone.t
> --- a/tests/test-clone.t
> +++ b/tests/test-clone.t
> @@ -769,21 +769,21 @@ Clone from repo with content should resu
>
>    $ hg --config share.pool=share clone source1a share-dest1a
>    (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
>    requesting all changes
>    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
>    b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1
>
>  The destination should point to it
>
> @@ -799,25 +799,25 @@ The default path should be the remote, n
>
>    $ hg -R share-dest1a config paths.default
>    $TESTTMP/source1a (glob)
>
>  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
>
>    $ cat share-dest1b/.hg/sharedpath; echo
>    $TESTTMP/share/b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1/.hg (glob)
>
>  We only get bookmarks from the remote, not everything in the share
> @@ -826,82 +826,93 @@ We only get bookmarks from the remote, n
>       head1                     3:4a8dc1ab4c13
>       head2                     4:99f71071f117
>
>  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)
>    requesting all changes
>    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
>
>  remote naming mode works as advertised
>
>    $ hg --config share.pool=shareremote --config share.poolnaming=remote clone source1a share-remote1a
>    (sharing from new pooled repository 195bb1fcdb595c14a6c13e0269129ed78f6debde)
>    requesting all changes
>    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
>
>    $ hg --config share.pool=shareremote --config share.poolnaming=remote clone source1b share-remote1b
>    (sharing from new pooled repository c0d4f83847ca2a873741feb7048a45085fd47c46)
>    requesting all changes
>    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
>
>  request to clone a single revision is respected in sharing mode
>
>    $ hg --config share.pool=sharerevs clone -r 4a8dc1ab4c13 source1b share-1arev
>    (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
>    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
>    |  tag:         tip
>    |  user:        test
>    |  date:        Thu Jan 01 00:00:00 1970 +0000
>    |  summary:     head1
> @@ -911,36 +922,36 @@ request to clone a single revision is re
>       date:        Thu Jan 01 00:00:00 1970 +0000
>       summary:     initial
>
>
>  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
>    |
>    o  changeset:   0:b5f04eac9d8f
>       user:        test
>       date:        Thu Jan 01 00:00:00 1970 +0000
> @@ -950,19 +961,19 @@ making another clone should only pull do
>  Request to clone a single branch is respected in sharing mode
>
>    $ hg --config share.pool=sharebranch clone -b branch1 source1b share-1bbranch1
>    (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
>    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
>    |  tag:         tip
>    |  user:        test
>    |  date:        Thu Jan 01 00:00:00 1970 +0000
>    |  summary:     branch1
> @@ -970,23 +981,23 @@ Request to clone a single branch is resp
>    @  changeset:   0:b5f04eac9d8f
>       user:        test
>       date:        Thu Jan 01 00:00:00 1970 +0000
>       summary:     initial
>
>
>    $ 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
>    |  tag:         tip
>    |  parent:      0:b5f04eac9d8f
>    |  user:        test
>    |  date:        Thu Jan 01 00:00:00 1970 +0000
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -351,26 +351,28 @@  def clonewithshare(ui, peeropts, sharepa
     else:
         ui.status(_('(sharing from new pooled repository %s)\n') % basename)
         # Always use pull mode because hardlinks in share mode don't work well.
         # Never update because working copies aren't necessary in share mode.
         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
     # is a bit weird. But at the time it was implemented, there wasn't an easy
     # 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):
     """Make a copy of an existing repository.
 
     Create a copy of an existing repository in a new directory.  The
     source and destination are URLs, as passed to the repository
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -769,21 +769,21 @@  Clone from repo with content should resu
 
   $ hg --config share.pool=share clone source1a share-dest1a
   (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
   requesting all changes
   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
   b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1
 
 The destination should point to it
 
@@ -799,25 +799,25 @@  The default path should be the remote, n
 
   $ hg -R share-dest1a config paths.default
   $TESTTMP/source1a (glob)
 
 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
 
   $ cat share-dest1b/.hg/sharedpath; echo
   $TESTTMP/share/b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1/.hg (glob)
 
 We only get bookmarks from the remote, not everything in the share
@@ -826,82 +826,93 @@  We only get bookmarks from the remote, n
      head1                     3:4a8dc1ab4c13
      head2                     4:99f71071f117
 
 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)
   requesting all changes
   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
 
 remote naming mode works as advertised
 
   $ hg --config share.pool=shareremote --config share.poolnaming=remote clone source1a share-remote1a
   (sharing from new pooled repository 195bb1fcdb595c14a6c13e0269129ed78f6debde)
   requesting all changes
   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
 
   $ hg --config share.pool=shareremote --config share.poolnaming=remote clone source1b share-remote1b
   (sharing from new pooled repository c0d4f83847ca2a873741feb7048a45085fd47c46)
   requesting all changes
   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
 
 request to clone a single revision is respected in sharing mode
 
   $ hg --config share.pool=sharerevs clone -r 4a8dc1ab4c13 source1b share-1arev
   (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
   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
   |  tag:         tip
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     head1
@@ -911,36 +922,36 @@  request to clone a single revision is re
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     initial
   
 
 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
   |
   o  changeset:   0:b5f04eac9d8f
      user:        test
      date:        Thu Jan 01 00:00:00 1970 +0000
@@ -950,19 +961,19 @@  making another clone should only pull do
 Request to clone a single branch is respected in sharing mode
 
   $ hg --config share.pool=sharebranch clone -b branch1 source1b share-1bbranch1
   (sharing from new pooled repository b5f04eac9d8f7a6a9fcb070243cccea7dc5ea0c1)
   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
   |  tag:         tip
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     branch1
@@ -970,23 +981,23 @@  Request to clone a single branch is resp
   @  changeset:   0:b5f04eac9d8f
      user:        test
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     initial
   
 
   $ 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
   |  tag:         tip
   |  parent:      0:b5f04eac9d8f
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000