Bug 1330837 - Remove functionality to apply and push; r?aki
Tests based on this code fail in Mercurial 3.8+ due to `hg rebase`
changing its behavior for selecting default revisions. I was going
to update the code to work with 3.8+. However, I could find no actual
consumers of this method! Annotate says this was added back in
mozharness 0.4. However, I can't find a reason for it being added.
Nor can I find any consumers of this method in the mozharness repo
outside the tests. This smells like dead code to me.
MozReview-Commit-ID: 3Q6MTjQJT1p
--- a/testing/mozharness/mozharness/base/vcs/mercurial.py
+++ b/testing/mozharness/mozharness/base/vcs/mercurial.py
@@ -391,67 +391,16 @@ class MercurialVCS(ScriptMixin, LogMixin
if self.run_command(args, output_parser=parser):
raise VCSException('repo checkout failed!')
if not parser.revision:
raise VCSException('could not identify revision updated to')
return parser.revision
- def apply_and_push(self, localrepo, remote, changer, max_attempts=10,
- ssh_username=None, ssh_key=None):
- """This function calls `changer' to make changes to the repo, and
- tries its hardest to get them to the origin repo. `changer' must be
- a callable object that receives two arguments: the directory of the
- local repository, and the attempt number. This function will push
- ALL changesets missing from remote.
- """
- self.info("Applying and pushing local changes from %s to %s." % (localrepo, remote))
- assert callable(changer)
- branch = self.get_branch_from_path(localrepo)
- changer(localrepo, 1)
- for n in range(1, max_attempts + 1):
- try:
- new_revs = self.out(src=localrepo, remote=remote,
- ssh_username=ssh_username,
- ssh_key=ssh_key)
- if len(new_revs) < 1:
- raise VCSException("No revs to push")
- self.push(src=localrepo, remote=remote,
- ssh_username=ssh_username,
- ssh_key=ssh_key)
- return
- except VCSException, e:
- self.debug("Hit error when trying to push: %s" % str(e))
- if n == max_attempts:
- self.debug("Tried %d times, giving up" % max_attempts)
- for r in reversed(new_revs):
- self.run_command(self.hg + ['strip', '-n', r[REVISION]],
- cwd=localrepo, error_list=HgErrorList)
- raise VCSException("Failed to push")
- self.pull(remote, localrepo, update_dest=False,
- ssh_username=ssh_username, ssh_key=ssh_key)
- # After we successfully rebase or strip away heads the push
- # is is attempted again at the start of the loop
- try:
- self.run_command(self.hg + ['rebase'], cwd=localrepo,
- error_list=HgErrorList,
- throw_exception=True)
- except subprocess.CalledProcessError, e:
- self.debug("Failed to rebase: %s" % str(e))
- # clean up any hanging rebase. ignore errors if we aren't
- # in the middle of a rebase.
- self.run_command(self.hg + ['rebase', '--abort'],
- cwd=localrepo, success_codes=[0, 255])
- self.update(localrepo, branch=branch)
- for r in reversed(new_revs):
- self.run_command(self.hg + ['strip', '-n', r[REVISION]],
- cwd=localrepo, error_list=HgErrorList)
- changer(localrepo, n + 1)
-
def cleanOutgoingRevs(self, reponame, remote, username, sshKey):
# TODO retry
self.info("Wiping outgoing local changes from %s to %s." % (reponame, remote))
outgoingRevs = self.out(src=reponame, remote=remote,
ssh_username=username, ssh_key=sshKey)
for r in reversed(outgoingRevs):
self.run_command(self.hg + ['strip', '-n', r[REVISION]],
cwd=reponame, error_list=HgErrorList)
--- a/testing/mozharness/test/test_base_vcs_mercurial.py
+++ b/testing/mozharness/test/test_base_vcs_mercurial.py
@@ -364,77 +364,10 @@ class TestHg(unittest.TestCase):
repo_url = mercurial.make_hg_url(
"hg.mozilla.org",
"/build/tools",
protocol='ssh',
)
expected_url = "ssh://hg.mozilla.org/build/tools"
self.assertEquals(repo_url, expected_url)
- def test_apply_and_push(self):
- m = get_mercurial_vcs_obj()
- m.clone(self.repodir, self.wc)
-
- def c(repo, attempt):
- m.run_command(HG + ['tag', '-f', 'TEST'], cwd=repo)
- m.apply_and_push(self.wc, self.repodir, c)
- self.assertEquals(get_revisions(self.wc), get_revisions(self.repodir))
-
- def test_apply_and_push_fail(self):
- m = get_mercurial_vcs_obj()
- m.clone(self.repodir, self.wc)
-
- def c(repo, attempt, remote):
- m.run_command(HG + ['tag', '-f', 'TEST'], cwd=repo)
- m.run_command(HG + ['tag', '-f', 'CONFLICTING_TAG'], cwd=remote)
- m.config = {'log_to_console': False}
- self.assertRaises(errors.VCSException, m.apply_and_push, self.wc,
- self.repodir, lambda r, a: c(r, a, self.repodir),
- max_attempts=2)
-
- def test_apply_and_push_with_rebase(self):
- m = get_mercurial_vcs_obj()
- m.clone(self.repodir, self.wc)
- m.config = {'log_to_console': False}
-
- def c(repo, attempt, remote):
- m.run_command(HG + ['tag', '-f', 'TEST'], cwd=repo)
- if attempt == 1:
- m.run_command(HG + ['rm', 'hello.txt'], cwd=remote)
- m.run_command(HG + ['commit', '-m', 'test'], cwd=remote)
- m.apply_and_push(self.wc, self.repodir,
- lambda r, a: c(r, a, self.repodir), max_attempts=2)
- self.assertEquals(get_revisions(self.wc), get_revisions(self.repodir))
-
- def test_apply_and_push_rebase_fails(self):
- m = get_mercurial_vcs_obj()
- m.clone(self.repodir, self.wc)
- m.config = {'log_to_console': False}
-
- def c(repo, attempt, remote):
- m.run_command(HG + ['tag', '-f', 'TEST'], cwd=repo)
- if attempt in (1, 2):
- m.run_command(HG + ['tag', '-f', 'CONFLICTING_TAG'], cwd=remote)
- m.apply_and_push(self.wc, self.repodir,
- lambda r, a: c(r, a, self.repodir), max_attempts=4)
- self.assertEquals(get_revisions(self.wc), get_revisions(self.repodir))
-
- def test_apply_and_push_on_branch(self):
- m = get_mercurial_vcs_obj()
- if m.hg_ver() >= (1, 6, 0):
- m.clone(self.repodir, self.wc)
-
- def c(repo, attempt):
- m.run_command(HG + ['branch', 'branch3'], cwd=repo)
- m.run_command(HG + ['tag', '-f', 'TEST'], cwd=repo)
- m.apply_and_push(self.wc, self.repodir, c)
- self.assertEquals(get_revisions(self.wc), get_revisions(self.repodir))
-
- def test_apply_and_push_with_no_change(self):
- m = get_mercurial_vcs_obj()
- m.clone(self.repodir, self.wc)
-
- def c(r, a):
- pass
- self.assertRaises(errors.VCSException, m.apply_and_push, self.wc, self.repodir, c)
-
if __name__ == '__main__':
unittest.main()