Add tag write access to merge script.

The script will poll the remote branch until the git updater
has replicated the commit to tag. The tag will then be
directly pushed to git.

BUG=chromium:410721
LOG=n
TEST=script_test.py
R=agable@chromium.org, tandrii@chromium.org
TBR=tandrii@chromium.org

Review URL: https://codereview.chromium.org/607893004

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ff51fa06
...@@ -153,7 +153,9 @@ class MakeTag(Step): ...@@ -153,7 +153,9 @@ class MakeTag(Step):
if not self._options.dry_run: if not self._options.dry_run:
self.GitReset(self["lkgr"]) self.GitReset(self["lkgr"])
# FIXME(machenbach): Make this work with the git repo. # FIXME(machenbach): Make this work with the git repo.
self.vc.Tag(self["candidate_version"], "svn/bleeding_edge") self.vc.Tag(self["candidate_version"],
"svn/bleeding_edge",
"This won't work!")
class CleanUp(Step): class CleanUp(Step):
......
...@@ -295,7 +295,11 @@ class VCInterface(object): ...@@ -295,7 +295,11 @@ class VCInterface(object):
# TODO(machenbach): There is some svn knowledge in this interface. In svn, # TODO(machenbach): There is some svn knowledge in this interface. In svn,
# tag and commit are different remote commands, while in git we would commit # tag and commit are different remote commands, while in git we would commit
# and tag locally and then push/land in one unique step. # and tag locally and then push/land in one unique step.
def Tag(self, tag, remote): def Tag(self, tag, remote, message):
"""Sets a tag for the current commit.
Assumptions: The commit already landed and the commit message is unique.
"""
raise NotImplementedError() raise NotImplementedError()
...@@ -342,13 +346,13 @@ class GitSvnInterface(VCInterface): ...@@ -342,13 +346,13 @@ class GitSvnInterface(VCInterface):
def CLLand(self): def CLLand(self):
self.step.GitDCommit() self.step.GitDCommit()
def Tag(self, tag, remote): def Tag(self, tag, remote, _):
self.step.GitSVNFetch() self.step.GitSVNFetch()
self.step.Git("rebase %s" % remote) self.step.Git("rebase %s" % remote)
self.step.GitSVNTag(tag) self.step.GitSVNTag(tag)
class GitReadOnlyMixin(VCInterface): class GitTagsOnlyMixin(VCInterface):
def Pull(self): def Pull(self):
self.step.GitPull() self.step.GitPull()
...@@ -377,8 +381,28 @@ class GitReadOnlyMixin(VCInterface): ...@@ -377,8 +381,28 @@ class GitReadOnlyMixin(VCInterface):
return "origin/%s" % name return "origin/%s" % name
return "origin/branch-heads/%s" % name return "origin/branch-heads/%s" % name
def Tag(self, tag, remote, message):
# Wait for the commit to appear. Assumes unique commit message titles (this
# is the case for all automated merge and push commits - also no title is
# the prefix of another title).
commit = None
for wait_interval in [3, 7, 15, 35]:
self.step.Git("fetch")
commit = self.step.GitLog(n=1, format="%H", grep=message, branch=remote)
if commit:
break
print("The commit has not replicated to git. Waiting for %s seconds." %
wait_interval)
self.step._side_effect_handler.Sleep(wait_interval)
else:
self.step.Die("Couldn't determine commit for setting the tag. Maybe the "
"git updater is lagging behind?")
self.step.Git("tag %s %s" % (tag, commit))
self.step.Git("push origin %s" % tag)
class GitReadSvnWriteInterface(GitReadOnlyMixin, GitSvnInterface): class GitReadSvnWriteInterface(GitTagsOnlyMixin, GitSvnInterface):
pass pass
......
...@@ -80,7 +80,11 @@ class GitFailedException(Exception): ...@@ -80,7 +80,11 @@ class GitFailedException(Exception):
def Strip(f): def Strip(f):
def new_f(*args, **kwargs): def new_f(*args, **kwargs):
return f(*args, **kwargs).strip() result = f(*args, **kwargs)
if result is None:
return result
else:
return result.strip()
return new_f return new_f
......
...@@ -198,6 +198,7 @@ class CommitLocal(Step): ...@@ -198,6 +198,7 @@ class CommitLocal(Step):
else: else:
title = ("Version %s (merged %s)" title = ("Version %s (merged %s)"
% (self["version"], self["revision_list"])) % (self["version"], self["revision_list"]))
self["commit_title"] = title
self["new_commit_msg"] = "%s\n\n%s" % (title, self["new_commit_msg"]) self["new_commit_msg"] = "%s\n\n%s" % (title, self["new_commit_msg"])
TextToFile(self["new_commit_msg"], self.Config("COMMITMSG_FILE")) TextToFile(self["new_commit_msg"], self.Config("COMMITMSG_FILE"))
self.GitCommit(file_name=self.Config("COMMITMSG_FILE")) self.GitCommit(file_name=self.Config("COMMITMSG_FILE"))
...@@ -219,8 +220,10 @@ class TagRevision(Step): ...@@ -219,8 +220,10 @@ class TagRevision(Step):
def RunStep(self): def RunStep(self):
if self._options.revert_bleeding_edge: if self._options.revert_bleeding_edge:
return return
print "Creating tag svn/tags/%s" % self["version"] print "Creating tag %s" % self["version"]
self.vc.Tag(self["version"], self.vc.RemoteBranch(self["merge_to_branch"])) self.vc.Tag(self["version"],
self.vc.RemoteBranch(self["merge_to_branch"]),
self["commit_title"])
class CleanUp(Step): class CleanUp(Step):
......
...@@ -285,6 +285,7 @@ class SquashCommits(Step): ...@@ -285,6 +285,7 @@ class SquashCommits(Step):
if not text: # pragma: no cover if not text: # pragma: no cover
self.Die("Commit message editing failed.") self.Die("Commit message editing failed.")
self["commit_title"] = text.splitlines()[0]
TextToFile(text, self.Config("COMMITMSG_FILE")) TextToFile(text, self.Config("COMMITMSG_FILE"))
...@@ -361,7 +362,8 @@ class TagRevision(Step): ...@@ -361,7 +362,8 @@ class TagRevision(Step):
MESSAGE = "Tag the new revision." MESSAGE = "Tag the new revision."
def RunStep(self): def RunStep(self):
self.vc.Tag(self["version"], self.vc.RemoteCandidateBranch()) self.vc.Tag(
self["version"], self.vc.RemoteCandidateBranch(), self["commit_title"])
class CleanUp(Step): class CleanUp(Step):
......
...@@ -488,6 +488,24 @@ class ScriptTest(unittest.TestCase): ...@@ -488,6 +488,24 @@ class ScriptTest(unittest.TestCase):
]) ])
self.MakeStep().InitialEnvironmentChecks(TEST_CONFIG["DEFAULT_CWD"]) self.MakeStep().InitialEnvironmentChecks(TEST_CONFIG["DEFAULT_CWD"])
def testTagTimeout(self):
self.Expect([
Cmd("git fetch", ""),
Cmd("git log -1 --format=%H --grep=\"Title\" origin/candidates", ""),
Cmd("git fetch", ""),
Cmd("git log -1 --format=%H --grep=\"Title\" origin/candidates", ""),
Cmd("git fetch", ""),
Cmd("git log -1 --format=%H --grep=\"Title\" origin/candidates", ""),
Cmd("git fetch", ""),
Cmd("git log -1 --format=%H --grep=\"Title\" origin/candidates", ""),
])
args = ["--branch", "candidates", "--vc-interface", "git_read_svn_write",
"12345"]
self._state["version"] = "tag_name"
self._state["commit_title"] = "Title"
self.assertRaises(Exception,
lambda: self.RunStep(MergeToBranch, TagRevision, args))
def testReadAndPersistVersion(self): def testReadAndPersistVersion(self):
self.WriteFakeVersionFile(build=5) self.WriteFakeVersionFile(build=5)
step = self.MakeStep() step = self.MakeStep()
...@@ -1276,10 +1294,18 @@ LOG=N ...@@ -1276,10 +1294,18 @@ LOG=N
Cmd("git cl presubmit", "Presubmit successfull\n"), Cmd("git cl presubmit", "Presubmit successfull\n"),
Cmd("git cl dcommit -f --bypass-hooks", "Closing issue\n", Cmd("git cl dcommit -f --bypass-hooks", "Closing issue\n",
cb=VerifySVNCommit), cb=VerifySVNCommit),
# FIXME(machenbach): This won't work when setting tags on the git repo. Cmd("git fetch", ""),
Cmd("git svn fetch", ""), Cmd("git log -1 --format=%H --grep=\""
Cmd("git rebase origin/candidates", ""), "Version 3.22.5.1 (merged r12345, r23456, r34567, r45678, r56789)"
Cmd("git svn tag 3.22.5.1 -m \"Tagging version 3.22.5.1\"", ""), "\" origin/candidates",
""),
Cmd("git fetch", ""),
Cmd("git log -1 --format=%H --grep=\""
"Version 3.22.5.1 (merged r12345, r23456, r34567, r45678, r56789)"
"\" origin/candidates",
"hsh_to_tag"),
Cmd("git tag 3.22.5.1 hsh_to_tag", ""),
Cmd("git push origin 3.22.5.1", ""),
Cmd("git checkout -f some_branch", ""), Cmd("git checkout -f some_branch", ""),
Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""), Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""),
]) ])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment