Refactoring: Extract interface for VC in release scripts.

Also simplify tagging in merge_to_branch.

BUG=chromium:410721
LOG=n
R=jkummerow@chromium.org, tandrii@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24228 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0a9992d1
......@@ -16,7 +16,7 @@ class Preparation(Step):
self.CommonPrepare()
self.PrepareBranch()
self.GitCheckout("master")
self.GitSVNRebase()
self.vc.Pull()
class GetTags(Step):
......@@ -24,13 +24,7 @@ class GetTags(Step):
def RunStep(self):
self.GitCreateBranch(self._config["BRANCHNAME"])
# Get remote tags.
tags = filter(lambda s: re.match(r"^svn/tags/[\d+\.]+$", s),
self.GitRemotes())
# Remove 'svn/tags/' prefix.
self["tags"] = map(lambda s: s[9:], tags)
self["tags"] = self.vc.GetTags()
class GetOldestUntaggedVersion(Step):
......@@ -114,9 +108,9 @@ class CalculateTagRevision(Step):
def RunStep(self):
# Get the lkgr after the tag candidate and before the next tag candidate.
candidate_svn = self.GitSVNFindSVNRev(self["candidate"])
candidate_svn = self.vc.GitSvn(self["candidate"])
if self["next"]:
next_svn = self.GitSVNFindSVNRev(self["next"])
next_svn = self.vc.GitSvn(self["next"])
else:
# Don't include the version change commit itself if there is no upper
# limit yet.
......@@ -130,7 +124,7 @@ class CalculateTagRevision(Step):
return True
# Let's check if the lkgr is at least three hours old.
self["lkgr"] = self.GitSVNFindGitHash(lkgr_svn)
self["lkgr"] = self.vc.SvnGit(lkgr_svn)
if not self["lkgr"]:
print "Couldn't find git hash for lkgr %s" % lkgr_svn
self.CommonCleanup()
......@@ -153,7 +147,7 @@ class MakeTag(Step):
def RunStep(self):
if not self._options.dry_run:
self.GitReset(self["lkgr"])
self.GitSVNTag(self["candidate_version"])
self.vc.Tag(self["candidate_version"])
class CleanUp(Step):
......
......@@ -28,6 +28,7 @@ from common_includes import *
VERSION_BRANCH = "auto-bump-up-version"
#TODO(machenbach): Add vc interface that works on git mirror.
class Preparation(Step):
MESSAGE = "Preparation."
......
......@@ -255,6 +255,98 @@ class NoRetryException(Exception):
pass
class VCInterface(object):
def InjectStep(self, step):
self.step=step
def Pull(self):
raise NotImplementedError()
def Fetch(self):
raise NotImplementedError()
def GetTags(self):
raise NotImplementedError()
def GetBranches(self):
raise NotImplementedError()
def GitSvn(self, hsh, branch=""):
raise NotImplementedError()
def SvnGit(self, rev, branch=""):
raise NotImplementedError()
def RemoteMasterBranch(self):
raise NotImplementedError()
def RemoteCandidateBranch(self):
raise NotImplementedError()
def RemoteBranch(self, name):
raise NotImplementedError()
def Land(self):
raise NotImplementedError()
def CLLand(self):
raise NotImplementedError()
# 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
# and tag locally and then push/land in one unique step.
def Tag(self, tag):
raise NotImplementedError()
class GitSvnInterface(VCInterface):
def Pull(self):
self.step.GitSVNRebase()
def Fetch(self):
self.step.GitSVNFetch()
def GetTags(self):
# Get remote tags.
tags = filter(lambda s: re.match(r"^svn/tags/[\d+\.]+$", s),
self.step.GitRemotes())
# Remove 'svn/tags/' prefix.
return map(lambda s: s[9:], tags)
def GetBranches(self):
# Get relevant remote branches, e.g. "svn/3.25".
branches = filter(lambda s: re.match(r"^svn/\d+\.\d+$", s),
self.step.GitRemotes())
# Remove 'svn/' prefix.
return map(lambda s: s[4:], branches)
def GitSvn(self, hsh, branch=""):
return self.step.GitSVNFindSVNRev(hsh, branch)
def SvnGit(self, rev, branch=""):
return self.step.GitSVNFindGitHash(rev, branch)
def RemoteMasterBranch(self):
return "svn/bleeding_edge"
def RemoteCandidateBranch(self):
return "svn/trunk"
def RemoteBranch(self, name):
return "svn/%s" % name
def Land(self):
return self.step.GitSVNDCommit()
def CLLand(self):
return self.step.GitDCommit()
def Tag(self, tag):
self.step.GitSVNTag(tag)
class Step(GitRecipesMixin):
def __init__(self, text, number, config, state, options, handler):
self._text = text
......@@ -263,6 +355,8 @@ class Step(GitRecipesMixin):
self._state = state
self._options = options
self._side_effect_handler = handler
self.vc = GitSvnInterface()
self.vc.InjectStep(self)
# The testing configuration might set a different default cwd.
self.default_cwd = self._config.get("DEFAULT_CWD") or DEFAULT_CWD
......@@ -422,7 +516,7 @@ class Step(GitRecipesMixin):
self["current_branch"] = self.GitCurrentBranch()
# Fetch unfetched revisions.
self.GitSVNFetch()
self.vc.Fetch()
def PrepareBranch(self):
# Delete the branch that will be created later if it exists already.
......@@ -493,7 +587,7 @@ class Step(GitRecipesMixin):
# Non-patched versions only have three numbers followed by the "(based
# on...) comment."
push_pattern += " (based"
branch = "" if parent_hash else branch or "svn/trunk"
branch = "" if parent_hash else branch or self.vc.RemoteCandidateBranch()
return self.GitLog(n=1, format="%H", grep=push_pattern,
parent_hash=parent_hash, branch=branch)
......
......@@ -45,6 +45,7 @@ class Preparation(Step):
self.InitialEnvironmentChecks(self.default_cwd)
if self._options.revert_bleeding_edge:
# FIXME(machenbach): Make revert bleeding_edge obsolete?
self["merge_to_branch"] = "bleeding_edge"
elif self._options.branch:
self["merge_to_branch"] = self._options.branch
......@@ -60,7 +61,7 @@ class CreateBranch(Step):
def RunStep(self):
self.GitCreateBranch(self.Config("BRANCHNAME"),
"svn/%s" % self["merge_to_branch"])
self.vc.RemoteBranch(self["merge_to_branch"]))
class SearchArchitecturePorts(Step):
......@@ -74,9 +75,9 @@ class SearchArchitecturePorts(Step):
# Search for commits which matches the "Port rXXX" pattern.
git_hashes = self.GitLog(reverse=True, format="%H",
grep="Port r%d" % int(revision),
branch="svn/bleeding_edge")
branch=self.vc.RemoteMasterBranch())
for git_hash in git_hashes.splitlines():
svn_revision = self.GitSVNFindSVNRev(git_hash, "svn/bleeding_edge")
svn_revision = self.vc.GitSvn(git_hash, self.vc.RemoteMasterBranch())
if not svn_revision: # pragma: no cover
self.Die("Cannot determine svn revision for %s" % git_hash)
revision_title = self.GitLog(n=1, format="%s", git_hash=git_hash)
......@@ -104,7 +105,7 @@ class FindGitRevisions(Step):
def RunStep(self):
self["patch_commit_hashes"] = []
for revision in self["full_revision_list"]:
next_hash = self.GitSVNFindGitHash(revision, "svn/bleeding_edge")
next_hash = self.vc.SvnGit(revision, self.vc.RemoteMasterBranch())
if not next_hash: # pragma: no cover
self.Die("Cannot determine git hash for r%s" % revision)
self["patch_commit_hashes"].append(next_hash)
......@@ -209,22 +210,7 @@ class CommitRepository(Step):
self.GitCheckout(self.Config("BRANCHNAME"))
self.WaitForLGTM()
self.GitPresubmit()
self.GitDCommit()
class PrepareSVN(Step):
MESSAGE = "Determine svn commit revision."
def RunStep(self):
if self._options.revert_bleeding_edge:
return
self.GitSVNFetch()
commit_hash = self.GitLog(n=1, format="%H", grep=self["new_commit_msg"],
branch="svn/%s" % self["merge_to_branch"])
if not commit_hash: # pragma: no cover
self.Die("Unable to map git commit to svn revision.")
self["svn_revision"] = self.GitSVNFindSVNRev(commit_hash)
print "subversion revision number is r%s" % self["svn_revision"]
self.vc.CLLand()
class TagRevision(Step):
......@@ -234,15 +220,7 @@ class TagRevision(Step):
if self._options.revert_bleeding_edge:
return
print "Creating tag svn/tags/%s" % self["version"]
if self["merge_to_branch"] == "trunk":
self["to_url"] = "trunk"
else:
self["to_url"] = "branches/%s" % self["merge_to_branch"]
self.SVN("copy -r %s https://v8.googlecode.com/svn/%s "
"https://v8.googlecode.com/svn/tags/%s -m "
"\"Tagging version %s\""
% (self["svn_revision"], self["to_url"],
self["version"], self["version"]))
self.vc.Tag(self["version"])
class CleanUp(Step):
......@@ -253,8 +231,7 @@ class CleanUp(Step):
if not self._options.revert_bleeding_edge:
print "*** SUMMARY ***"
print "version: %s" % self["version"]
print "branch: %s" % self["to_url"]
print "svn revision: %s" % self["svn_revision"]
print "branch: %s" % self["merge_to_branch"]
if self["revision_list"]:
print "patches: %s" % self["revision_list"]
......@@ -319,7 +296,6 @@ class MergeToBranch(ScriptsBase):
CommitLocal,
UploadStep,
CommitRepository,
PrepareSVN,
TagRevision,
CleanUp,
]
......
......@@ -56,7 +56,8 @@ class FreshBranch(Step):
MESSAGE = "Create a fresh branch."
def RunStep(self):
self.GitCreateBranch(self.Config("BRANCHNAME"), "svn/bleeding_edge")
self.GitCreateBranch(self.Config("BRANCHNAME"),
self.vc.RemoteMasterBranch())
class PreparePushRevision(Step):
......@@ -64,7 +65,7 @@ class PreparePushRevision(Step):
def RunStep(self):
if self._options.revision:
self["push_hash"] = self.GitSVNFindGitHash(self._options.revision)
self["push_hash"] = self.vc.SvnGit(self._options.revision)
else:
self["push_hash"] = self.GitLog(n=1, format="%H", git_hash="HEAD")
if not self["push_hash"]: # pragma: no cover
......@@ -95,7 +96,7 @@ class DetectLastPush(Step):
if not last_push_be_svn: # pragma: no cover
self.Die("Could not retrieve bleeding edge revision for trunk push %s"
% last_push)
last_push_bleeding_edge = self.GitSVNFindGitHash(last_push_be_svn)
last_push_bleeding_edge = self.vc.SvnGit(last_push_be_svn)
if not last_push_bleeding_edge: # pragma: no cover
self.Die("Could not retrieve bleeding edge git hash for trunk push %s"
% last_push)
......@@ -116,7 +117,7 @@ class GetCurrentBleedingEdgeVersion(Step):
MESSAGE = "Get latest bleeding edge version."
def RunStep(self):
self.GitCheckoutFile(VERSION_FILE, "svn/bleeding_edge")
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
# Store latest version.
self.ReadAndPersistVersion("latest_")
......@@ -140,7 +141,7 @@ class IncrementVersion(Step):
if SortingKey(self["trunk_version"]) < SortingKey(self["latest_version"]):
# If the version on bleeding_edge is newer than on trunk, use it.
self.GitCheckoutFile(VERSION_FILE, "svn/bleeding_edge")
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteMasterBranch())
self.ReadAndPersistVersion()
if self.Confirm(("Automatically increment BUILD_NUMBER? (Saying 'n' will "
......@@ -249,8 +250,8 @@ class StragglerCommits(Step):
"started.")
def RunStep(self):
self.GitSVNFetch()
self.GitCheckout("svn/bleeding_edge")
self.vc.Fetch()
self.GitCheckout(self.vc.RemoteMasterBranch())
class SquashCommits(Step):
......@@ -259,7 +260,8 @@ class SquashCommits(Step):
def RunStep(self):
# Instead of relying on "git rebase -i", we'll just create a diff, because
# that's easier to automate.
TextToFile(self.GitDiff("svn/trunk", self["push_hash"]),
TextToFile(self.GitDiff(self.vc.RemoteCandidateBranch(),
self["push_hash"]),
self.Config("PATCH_FILE"))
# Convert the ChangeLog entry to commit message format.
......@@ -270,7 +272,7 @@ class SquashCommits(Step):
# Retrieve svn revision for showing the used bleeding edge revision in the
# commit message.
self["svn_revision"] = self.GitSVNFindSVNRev(self["push_hash"])
self["svn_revision"] = self.vc.GitSvn(self["push_hash"])
suffix = PUSH_MESSAGE_SUFFIX % int(self["svn_revision"])
text = MSub(r"^(Version \d+\.\d+\.\d+)$", "\\1%s" % suffix, text)
......@@ -290,7 +292,8 @@ class NewBranch(Step):
MESSAGE = "Create a new branch from trunk."
def RunStep(self):
self.GitCreateBranch(self.Config("TRUNKBRANCH"), "svn/trunk")
self.GitCreateBranch(self.Config("TRUNKBRANCH"),
self.vc.RemoteCandidateBranch())
class ApplyChanges(Step):
......@@ -308,7 +311,8 @@ class AddChangeLog(Step):
# The change log has been modified by the patch. Reset it to the version
# on trunk and apply the exact changes determined by this PrepareChangeLog
# step above.
self.GitCheckoutFile(self.Config("CHANGELOG_FILE"), "svn/trunk")
self.GitCheckoutFile(self.Config("CHANGELOG_FILE"),
self.vc.RemoteCandidateBranch())
changelog_entry = FileToText(self.Config("CHANGELOG_ENTRY_FILE"))
old_change_log = FileToText(self.Config("CHANGELOG_FILE"))
new_change_log = "%s\n\n\n%s" % (changelog_entry, old_change_log)
......@@ -322,7 +326,7 @@ class SetVersion(Step):
def RunStep(self):
# The version file has been modified by the patch. Reset it to the version
# on trunk and apply the correct version.
self.GitCheckoutFile(VERSION_FILE, "svn/trunk")
self.GitCheckoutFile(VERSION_FILE, self.vc.RemoteCandidateBranch())
self.SetVersion(os.path.join(self.default_cwd, VERSION_FILE), "new_")
......@@ -350,7 +354,8 @@ class CommitSVN(Step):
MESSAGE = "Commit to SVN."
def RunStep(self):
result = self.GitSVNDCommit()
result = self.vc.Land()
# TODO(machenbach): Remove/improve this logic before the git switch.
if not result: # pragma: no cover
self.Die("'git svn dcommit' failed.")
result = filter(lambda x: re.search(r"^Committed r[0-9]+", x),
......@@ -374,7 +379,7 @@ class TagRevision(Step):
MESSAGE = "Tag the new revision."
def RunStep(self):
self.GitSVNTag(self["version"])
self.vc.Tag(self["version"])
class CleanUp(Step):
......
......@@ -141,7 +141,7 @@ class RetrieveV8Releases(Step):
def GetReleaseDict(
self, git_hash, bleeding_edge_rev, branch, version, patches, cl_body):
revision = self.GitSVNFindSVNRev(git_hash)
revision = self.vc.GitSvn(git_hash)
return {
# The SVN revision on the branch.
"revision": revision,
......@@ -187,7 +187,7 @@ class RetrieveV8Releases(Step):
tag_text = self.SVN("log https://v8.googlecode.com/svn/tags -v --limit 20")
releases = []
for (tag, revision) in re.findall(BLEEDING_EDGE_TAGS_RE, tag_text):
git_hash = self.GitSVNFindGitHash(revision)
git_hash = self.vc.SvnGit(revision)
# Add bleeding edge release. It does not contain patches or a code
# review link, as tags are not uploaded.
......@@ -196,7 +196,8 @@ class RetrieveV8Releases(Step):
return releases
def GetReleasesFromBranch(self, branch):
self.GitReset("svn/%s" % branch)
self.GitReset(self.vc.RemoteBranch(branch))
# TODO(machenbach): Rename this when switching to the git mirror.
if branch == 'bleeding_edge':
return self.GetReleasesFromBleedingEdge()
......@@ -230,12 +231,7 @@ class RetrieveV8Releases(Step):
def RunStep(self):
self.GitCreateBranch(self._config["BRANCHNAME"])
# Get relevant remote branches, e.g. "svn/3.25".
branches = filter(lambda s: re.match(r"^svn/\d+\.\d+$", s),
self.GitRemotes())
# Remove 'svn/' prefix.
branches = map(lambda s: s[4:], branches)
branches = self.vc.GetBranches()
releases = []
if self._options.branch == 'recent':
# Get only recent development on trunk, beta and stable.
......
......@@ -1144,13 +1144,7 @@ LOG=N
Cmd("git cl presubmit", "Presubmit successfull\n"),
Cmd("git cl dcommit -f --bypass-hooks", "Closing issue\n",
cb=VerifySVNCommit),
Cmd("git svn fetch", ""),
Cmd(("git log -1 --format=%%H --grep=\"%s\" svn/trunk"
% msg.replace("\"", "\\\"")), "hash6"),
Cmd("git svn find-rev hash6", "1324"),
Cmd(("svn copy -r 1324 https://v8.googlecode.com/svn/trunk "
"https://v8.googlecode.com/svn/tags/3.22.5.1 -m "
"\"Tagging version 3.22.5.1\""), ""),
Cmd("git svn tag 3.22.5.1 -m \"Tagging version 3.22.5.1\"", ""),
Cmd("git checkout -f some_branch", ""),
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