From dd1b9cc98da1b7fdcb510d4fb0b1bdb7d1aaeb3d Mon Sep 17 00:00:00 2001 From: Jun Wu Date: Tue, 14 Jan 2020 21:00:48 -0800 Subject: [PATCH] pull: use transaction Summary: Without this change, the next diff will fail tests with metalog programming errors (write outside transaction). Some test changes are caused by the being deprecated `rollback` command. Reviewed By: DurhamG Differential Revision: D19380939 fbshipit-source-id: 7c893d3025bb697102835670b8a38f8fb9a624c8 --- .../edenscm/mercurial/commands/__init__.py | 100 +++++++++--------- eden/scm/tests/test-bundle.t | 9 +- eden/scm/tests/test-bundle2-exchange.t | 15 +-- .../test-bundle2-multiple-changegroups.t | 6 +- eden/scm/tests/test-pull.t | 2 +- eden/scm/tests/test-url-rev.t | 9 +- 6 files changed, 67 insertions(+), 74 deletions(-) diff --git a/eden/scm/edenscm/mercurial/commands/__init__.py b/eden/scm/edenscm/mercurial/commands/__init__.py index 7b75af54b5..4222563dcd 100644 --- a/eden/scm/edenscm/mercurial/commands/__init__.py +++ b/eden/scm/edenscm/mercurial/commands/__init__.py @@ -4732,60 +4732,62 @@ def pull(ui, repo, source="default", **opts): ui.status(_("pulling from %s\n") % util.hidepassword(source)) with repo.connectionpool.get(source, opts=opts) as conn: - other = conn.peer - revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get("rev")) + with repo.wlock(), repo.lock(), repo.transaction("pull"): + other = conn.peer + revs, checkout = hg.addbranchrevs(repo, other, branches, opts.get("rev")) - pullopargs = {} - if opts.get("bookmark"): - if not revs: - revs = [] - # The list of bookmark used here is not the one used to actually - # update the bookmark name. This can result in the revision pulled - # not ending up with the name of the bookmark because of a race - # condition on the server. (See issue 4689 for details) - remotebookmarks = other.listkeys("bookmarks") - remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) - pullopargs["remotebookmarks"] = remotebookmarks - for b in opts["bookmark"]: - b = repo._bookmarks.expandname(b) - if b not in remotebookmarks: - raise error.Abort(_("remote bookmark %s not found!") % b) - revs.append(hex(remotebookmarks[b])) + pullopargs = {} + if opts.get("bookmark"): + if not revs: + revs = [] + # The list of bookmark used here is not the one used to actually + # update the bookmark name. This can result in the revision pulled + # not ending up with the name of the bookmark because of a race + # condition on the server. (See issue 4689 for details) + remotebookmarks = other.listkeys("bookmarks") + remotebookmarks = bookmarks.unhexlifybookmarks(remotebookmarks) + pullopargs["remotebookmarks"] = remotebookmarks + for b in opts["bookmark"]: + b = repo._bookmarks.expandname(b) + if b not in remotebookmarks: + raise error.Abort(_("remote bookmark %s not found!") % b) + revs.append(hex(remotebookmarks[b])) - if revs: - try: - # When 'rev' is a bookmark name, we cannot guarantee that it - # will be updated with that name because of a race condition - # server side. (See issue 4689 for details) - oldrevs = revs - revs = [] # actually, nodes - for r in oldrevs: - node = other.lookup(r) - revs.append(node) - if r == checkout: - checkout = node - except error.CapabilityError: - err = _( - "other repository doesn't support revision lookup, " - "so a rev cannot be specified." - ) - raise error.Abort(err) + if revs: + try: + # When 'rev' is a bookmark name, we cannot guarantee that it + # will be updated with that name because of a race condition + # server side. (See issue 4689 for details) + oldrevs = revs + revs = [] # actually, nodes + for r in oldrevs: + node = other.lookup(r) + revs.append(node) + if r == checkout: + checkout = node + except error.CapabilityError: + err = _( + "other repository doesn't support revision lookup, " + "so a rev cannot be specified." + ) + raise error.Abort(err) - pullopargs.update(opts.get("opargs", {})) - modheads = exchange.pull( - repo, - other, - heads=revs, - force=opts.get("force"), - bookmarks=opts.get("bookmark", ()), - opargs=pullopargs, - ).cgresult + pullopargs.update(opts.get("opargs", {})) + modheads = exchange.pull( + repo, + other, + heads=revs, + force=opts.get("force"), + bookmarks=opts.get("bookmark", ()), + opargs=pullopargs, + ).cgresult - # brev is a name, which might be a bookmark to be activated at - # the end of the update. In other words, it is an explicit - # destination of the update - brev = None + # brev is a name, which might be a bookmark to be activated at + # the end of the update. In other words, it is an explicit + # destination of the update + brev = None + # Run 'update' in another transaction. if checkout and checkout in repo: checkout = str(repo.changelog.rev(checkout)) diff --git a/eden/scm/tests/test-bundle.t b/eden/scm/tests/test-bundle.t index 3c96c47e6a..b0f5c5ec82 100644 --- a/eden/scm/tests/test-bundle.t +++ b/eden/scm/tests/test-bundle.t @@ -108,8 +108,7 @@ Pull full.hg into empty (using --cwd) Rollback empty - $ hg -R empty rollback - repository tip rolled back to revision -1 (undo pull) + $ hg -R empty debugstrip 0 --no-backup Pull full.hg into empty again (using --cwd) @@ -137,8 +136,7 @@ Pull full.hg into empty (using -R) Rollback empty - $ hg -R empty rollback - repository tip rolled back to revision -1 (undo pull) + $ hg -R empty debugstrip 0 --no-backup Pull full.hg into empty again (using -R) @@ -234,8 +232,7 @@ hg -R ../full.hg verify Rollback empty - $ hg rollback - repository tip rolled back to revision -1 (undo pull) + $ hg debugstrip 0 --no-backup $ cd .. Log -R bundle:empty+full.hg (broken with Rust code path) diff --git a/eden/scm/tests/test-bundle2-exchange.t b/eden/scm/tests/test-bundle2-exchange.t index db02b410c3..023a1b6652 100644 --- a/eden/scm/tests/test-bundle2-exchange.t +++ b/eden/scm/tests/test-bundle2-exchange.t @@ -117,8 +117,7 @@ pull 1 new obsolescence markers pre-close-tip:24b6387c8c8c draft postclose-tip:24b6387c8c8c draft - txnclose hook: HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 HG_NODE=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_NODE_LAST=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull - file:/*/$TESTTMP/main HG_URL=file:$TESTTMP/main (glob) + txnclose hook: HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 HG_NODE=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_NODE_LAST=24b6387c8c8cae37178880f3fa95ded3cb1cf785 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull HG_URL=file:$TESTTMP/main $ hg -R other log -G o 2:24b6387c8c8c draft Nicolas Dumazet F | @@ -141,8 +140,7 @@ pull empty (with phase movement) no changes found pre-close-tip:24b6387c8c8c public postclose-tip:24b6387c8c8c public - txnclose hook: HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=0 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull - file:/*/$TESTTMP/main HG_URL=file:$TESTTMP/main (glob) + txnclose hook: HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=0 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull HG_URL=file:$TESTTMP/main $ hg -R other log -G o 2:24b6387c8c8c public Nicolas Dumazet F | @@ -161,8 +159,7 @@ pull empty no changes found pre-close-tip:24b6387c8c8c public postclose-tip:24b6387c8c8c public - txnclose hook: HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=0 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull - file:/*/$TESTTMP/main HG_URL=file:$TESTTMP/main (glob) + txnclose hook: HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=0 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull HG_URL=file:$TESTTMP/main $ hg -R other log -G o 2:24b6387c8c8c public Nicolas Dumazet F | @@ -287,8 +284,7 @@ pull over ssh updating bookmark book_02de pre-close-tip:02de42196ebe draft book_02de postclose-tip:02de42196ebe draft book_02de - txnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 HG_NODE=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_NODE_LAST=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull - ssh://user@dummy/main HG_URL=ssh://user@dummy/main + txnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 HG_NODE=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_NODE_LAST=02de42196ebee42ef284b6780a87cdc96e8eaab6 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull HG_URL=ssh://user@dummy/main $ hg -R other debugobsolete 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} 2222222222222222222222222222222222222222 24b6387c8c8cae37178880f3fa95ded3cb1cf785 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} @@ -312,8 +308,7 @@ pull over http updating bookmark book_42cc pre-close-tip:42ccdea3bb16 draft book_42cc postclose-tip:42ccdea3bb16 draft book_42cc - txnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 HG_NODE=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_NODE_LAST=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull - http://localhost:$HGPORT/ HG_URL=http://localhost:$HGPORT/ (glob) + txnclose hook: HG_BOOKMARK_MOVED=1 HG_HOOKNAME=txnclose.env HG_HOOKTYPE=txnclose HG_NEW_OBSMARKERS=1 HG_NODE=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_NODE_LAST=42ccdea3bb16d28e1848c95fe2e44c000f3f21b1 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_TXNNAME=pull HG_URL=http://localhost:$HGPORT/ (glob) $ cat main-error.log $ hg -R other debugobsolete 1111111111111111111111111111111111111111 9520eea781bcca16c1e15acc0ba14335a0e8e5ba 0 (Thu Jan 01 00:00:00 1970 +0000) {'user': 'test'} diff --git a/eden/scm/tests/test-bundle2-multiple-changegroups.t b/eden/scm/tests/test-bundle2-multiple-changegroups.t index 7c82a8b078..9d72434b44 100644 --- a/eden/scm/tests/test-bundle2-multiple-changegroups.t +++ b/eden/scm/tests/test-bundle2-multiple-changegroups.t @@ -92,9 +92,9 @@ Pull the new commits in the clone adding file changes added 1 changesets with 1 changes to 1 files pretxnchangegroup hook: HG_HOOKNAME=pretxnchangegroup HG_HOOKTYPE=pretxnchangegroup HG_NODE=f838bfaca5c7226600ebcfd84f3c3c13a28d3757 HG_NODE_LAST=f838bfaca5c7226600ebcfd84f3c3c13a28d3757 HG_PENDING=$TESTTMP/clone HG_PHASES_MOVED=1 HG_SHAREDPENDING=$TESTTMP/clone HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo + pullop.cgresult is 1 changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=27547f69f25460a52fff66ad004e58da7ad3fb56 HG_NODE_LAST=27547f69f25460a52fff66ad004e58da7ad3fb56 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=f838bfaca5c7226600ebcfd84f3c3c13a28d3757 HG_NODE_LAST=f838bfaca5c7226600ebcfd84f3c3c13a28d3757 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo - pullop.cgresult is 1 $ hg update 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg log -G @@ -159,9 +159,9 @@ pullop.cgresult adding file changes added 3 changesets with 3 changes to 3 files pretxnchangegroup hook: HG_HOOKNAME=pretxnchangegroup HG_HOOKTYPE=pretxnchangegroup HG_NODE=7f219660301fe4c8a116f714df5e769695cc2b46 HG_NODE_LAST=5cd59d311f6508b8e0ed28a266756c859419c9f1 HG_PENDING=$TESTTMP/clone HG_PHASES_MOVED=1 HG_SHAREDPENDING=$TESTTMP/clone HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo + pullop.cgresult is 1 changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=b3325c91a4d916bcc4cdc83ea3fe4ece46a42f6e HG_NODE_LAST=8a5212ebc8527f9fb821601504794e3eb11a1ed3 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=7f219660301fe4c8a116f714df5e769695cc2b46 HG_NODE_LAST=5cd59d311f6508b8e0ed28a266756c859419c9f1 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo - pullop.cgresult is 1 $ hg log -G o 7:5cd59d311f65 public test H | @@ -226,9 +226,9 @@ pullop.cgresult adding file changes added 1 changesets with 1 changes to 1 files pretxnchangegroup hook: HG_HOOKNAME=pretxnchangegroup HG_HOOKTYPE=pretxnchangegroup HG_NODE=9d18e5bd9ab09337802595d49f1dad0c98df4d84 HG_NODE_LAST=9d18e5bd9ab09337802595d49f1dad0c98df4d84 HG_PENDING=$TESTTMP/clone HG_PHASES_MOVED=1 HG_SHAREDPENDING=$TESTTMP/clone HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo + pullop.cgresult is 1 changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=71bd7b46de72e69a32455bf88d04757d542e6cf4 HG_NODE_LAST=71bd7b46de72e69a32455bf88d04757d542e6cf4 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo changegroup hook: HG_HOOKNAME=changegroup HG_HOOKTYPE=changegroup HG_NODE=9d18e5bd9ab09337802595d49f1dad0c98df4d84 HG_NODE_LAST=9d18e5bd9ab09337802595d49f1dad0c98df4d84 HG_PHASES_MOVED=1 HG_SOURCE=pull HG_TXNID=TXN:$ID$ HG_URL=file:$TESTTMP/repo - pullop.cgresult is 1 $ hg log -G o 9:9d18e5bd9ab0 public test H | diff --git a/eden/scm/tests/test-pull.t b/eden/scm/tests/test-pull.t index b378b9415f..dbb213ee9c 100644 --- a/eden/scm/tests/test-pull.t +++ b/eden/scm/tests/test-pull.t @@ -54,7 +54,7 @@ no changes found $ hg rollback --dry-run --verbose - repository tip rolled back to revision 0 (undo clone) + repository tip rolled back to revision 0 (undo pull) Test pull of non-existing 20 character revision specification, making sure plain ascii identifiers not are encoded like a node: diff --git a/eden/scm/tests/test-url-rev.t b/eden/scm/tests/test-url-rev.t index 3b76c38f17..ee9e4aad40 100644 --- a/eden/scm/tests/test-url-rev.t +++ b/eden/scm/tests/test-url-rev.t @@ -163,8 +163,7 @@ No new revs, no update: $ hg parents -q 0:1f0dee641bb7 - $ hg rollback - repository tip rolled back to revision 1 (undo pull) + $ hg debugstrip 1 --no-backup $ hg parents -q 0:1f0dee641bb7 @@ -180,12 +179,12 @@ Pull -u takes us back to branch foo: date: Thu Jan 01 00:00:00 1970 +0000 summary: new head of branch foo - $ hg rollback - repository tip rolled back to revision 1 (undo pull) - working directory now based on revision 0 + $ hg debugstrip 2 --no-backup + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg up -C 0 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + (leaving bookmark foo) $ hg parents -q 0:1f0dee641bb7