Mercurial > hgsubversion
changeset 1236:f367a4462191
push: update to branch tip instead of tip
We previously updated to the repository tip after pushing a revision,
presumably on the assumption that tip would be the last revision we
just pushed. This assumption is flawed for high traffic repositories.
In particular, you previsouly would sometimes end up on a completley
unrelated commit if someone else commits to a different branch in
between the time we push a revision and pull it back from the server.
This changes to instead update to the branch tip of the branch we were
on at the beginning of the push. This should be either the revision
we just pushed or a linear descendent of the revision we just pushed,
with a fair degree of reliability.
author | David Schleimer <dschleimer@fb.com> |
---|---|
date | Sat, 30 Aug 2014 09:23:31 -0700 |
parents | 6b15eeb78c1a |
children | 4ed0855d211f |
files | hgsubversion/wrappers.py tests/test_push_command.py |
diffstat | 2 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/wrappers.py +++ b/hgsubversion/wrappers.py @@ -210,6 +210,7 @@ def push(repo, dest, force, revs): ui.status('Cowardly refusing to push branch merge\n') return 0 # results in nonzero exit status, see hg's commands.py workingrev = repo.parents()[0] + workingbranch = workingrev.branch() ui.status('searching for changes\n') hashes = meta.revmap.hashes() outgoing = util.outgoing_revisions(repo, hashes, workingrev.node()) @@ -273,6 +274,13 @@ def push(repo, dest, force, revs): "in svn.\n" % current_ctx) return + # This hook is here purely for testing. It allows us to + # onsistently trigger hit the race condition between + # pushing and pulling here. In particular, we use it to + # trigger another revision landing between the time we + # push a revision and pull it back. + repo.hook('debug-hgsubversion-between-push-and-pull-for-tests') + # 5. Pull the latest changesets from subversion, which will # include the one we just committed (and possibly others). r = repo.pull(dest, force=force) @@ -325,7 +333,7 @@ def push(repo, dest, force, revs): util.swap_out_encoding(old_encoding) try: - hg.update(repo, repo['tip'].node()) + hg.update(repo, repo.branchtip(workingbranch)) finally: util.swap_out_encoding()
--- a/tests/test_push_command.py +++ b/tests/test_push_command.py @@ -754,3 +754,20 @@ class PushTests(test_util.TestBase): self.assertEqual(tip['adding_file'].data(), 'fooFirstFile') self.assertEqual(tip['newdir/new_file'].data(), 'fooNewFile') self.assertEqual(tip.branch(), 'default') + + def test_update_after_push(self): + repo = self.repo + ui = repo.ui + + ui.setconfig('hooks', + 'debug-hgsubversion-between-push-and-pull-for-tests', + lambda ui, repo, hooktype: self.add_svn_rev( + self.repo_path, + {'trunk/racey_file': 'race conditions suck'})) + + self.test_push_to_branch(push=False) + commands.push(ui, repo) + newctx = self.repo['.'] + self.assertNotEqual(newctx.node(), self.repo['tip'].node()) + self.assertEqual(newctx['adding_file'].data(), 'foo') + self.assertEqual(newctx.branch(), 'the_branch')