# HG changeset patch # User Gregory Szorc # Date 2016-03-25 17:47:49 # Node ID a2c2dd399f3b9fb84edd75a930e895f0c5e4ad5b # Parent 7dab4caf11bc717b1319ff10475b078e53f4df6c 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 @@ -236,20 +236,7 @@ def share(ui, source, dest=None, update= 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. @@ -272,6 +259,27 @@ def postshare(sourcerepo, destrepo, book 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 @@ -361,7 +369,7 @@ def clonewithshare(ui, peeropts, sharepa 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 @@ -371,6 +379,8 @@ def clonewithshare(ui, peeropts, sharepa 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, diff --git a/tests/test-clone.t b/tests/test-clone.t --- a/tests/test-clone.t +++ b/tests/test-clone.t @@ -774,11 +774,11 @@ Clone from repo with content should resu 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 @@ -804,8 +804,6 @@ Clone with existing share dir should res $ 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 @@ -813,6 +811,8 @@ Clone with existing share dir should res 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 @@ -831,6 +831,17 @@ 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 @@ -840,10 +851,10 @@ Clone from unrelated repo should result 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 @@ -858,11 +869,11 @@ remote naming mode works as advertised 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 @@ -874,12 +885,12 @@ remote naming mode works as advertised 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 @@ -893,10 +904,10 @@ request to clone a single revision is re 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 @@ -916,8 +927,6 @@ making another clone should only pull do $ 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 @@ -925,9 +934,11 @@ making another clone should only pull do 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 @@ -935,7 +946,7 @@ making another clone should only pull do | 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 @@ -955,9 +966,9 @@ Request to clone a single branch is resp 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 @@ -975,13 +986,13 @@ 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 @@ -1056,18 +1067,18 @@ Cloning into pooled storage doesn't race 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