From 33e56ef88938285be8fc0344f7b462e56249dff2 Mon Sep 17 00:00:00 2001 From: "machenbach@chromium.org" Date: Thu, 4 Sep 2014 08:42:21 +0000 Subject: [PATCH] Make auto_roll run with a pure git checkout. BUG=410721 LOG=n TBR=jarin@chromium.org Review URL: https://codereview.chromium.org/540513002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23672 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- tools/push-to-trunk/auto_roll.py | 9 ++-- tools/push-to-trunk/chromium_roll.py | 7 ++-- tools/push-to-trunk/common_includes.py | 5 ++- tools/push-to-trunk/git_recipes.py | 77 +++++++++++++++++++++++++++++++++- tools/push-to-trunk/releases.py | 73 +------------------------------- tools/push-to-trunk/test_scripts.py | 47 +++++++++++---------- 6 files changed, 115 insertions(+), 103 deletions(-) diff --git a/tools/push-to-trunk/auto_roll.py b/tools/push-to-trunk/auto_roll.py index 65fad92..b2ff2fa 100755 --- a/tools/push-to-trunk/auto_roll.py +++ b/tools/push-to-trunk/auto_roll.py @@ -50,8 +50,9 @@ class DetectLastPush(Step): MESSAGE = "Detect commit ID of the last push to trunk." def RunStep(self): - push_hash = self.FindLastTrunkPush(include_patches=True) - self["last_push"] = self.GitSVNFindSVNRev(push_hash) + push_hash = self.FindLastTrunkPush( + branch="origin/master", include_patches=True) + self["last_push"] = self.GetCommitPositionNumber(push_hash) class DetectLastRoll(Step): @@ -62,7 +63,9 @@ class DetectLastRoll(Step): Var = lambda var: '%s' exec(self.ReadURL(CR_DEPS_URL)) last_roll = vars['v8_revision'] - if last_roll >= self["last_push"]: + # FIXME(machenbach): When rolling from bleeding edge and from trunk there + # be different commit numbers here. Better use version? + if int(last_roll) >= int(self["last_push"]): print("There is no newer v8 revision than the one in Chromium (%s)." % last_roll) return True diff --git a/tools/push-to-trunk/chromium_roll.py b/tools/push-to-trunk/chromium_roll.py index e6c3086..a22a637 100755 --- a/tools/push-to-trunk/chromium_roll.py +++ b/tools/push-to-trunk/chromium_roll.py @@ -23,7 +23,8 @@ class Preparation(Step): MESSAGE = "Preparation." def RunStep(self): - self.CommonPrepare() + # Update v8 remote tracking branches. + self.GitFetchOrigin() class DetectLastPush(Step): @@ -31,8 +32,8 @@ class DetectLastPush(Step): def RunStep(self): self["last_push"] = self._options.last_push or self.FindLastTrunkPush( - include_patches=True) - self["trunk_revision"] = self.GitSVNFindSVNRev(self["last_push"]) + branch="origin/master", include_patches=True) + self["trunk_revision"] = self.GetCommitPositionNumber(self["last_push"]) self["push_title"] = self.GitLog(n=1, format="%s", git_hash=self["last_push"]) diff --git a/tools/push-to-trunk/common_includes.py b/tools/push-to-trunk/common_includes.py index a929985..d997959 100644 --- a/tools/push-to-trunk/common_includes.py +++ b/tools/push-to-trunk/common_includes.py @@ -471,13 +471,14 @@ class Step(GitRecipesMixin): except GitFailedException: self.WaitForResolvingConflicts(patch_file) - def FindLastTrunkPush(self, parent_hash="", include_patches=False): + def FindLastTrunkPush( + self, parent_hash="", branch="", include_patches=False): push_pattern = "^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*" if not include_patches: # Non-patched versions only have three numbers followed by the "(based # on...) comment." push_pattern += " (based" - branch = "" if parent_hash else "svn/trunk" + branch = "" if parent_hash else branch or "svn/trunk" return self.GitLog(n=1, format="%H", grep=push_pattern, parent_hash=parent_hash, branch=branch) diff --git a/tools/push-to-trunk/git_recipes.py b/tools/push-to-trunk/git_recipes.py index 96fa05a..4ea3b82 100644 --- a/tools/push-to-trunk/git_recipes.py +++ b/tools/push-to-trunk/git_recipes.py @@ -29,7 +29,49 @@ import re SHA1_RE = re.compile('^[a-fA-F0-9]{40}$') -GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$') +ROLL_DEPS_GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$') + +# Regular expression that matches a single commit footer line. +COMMIT_FOOTER_ENTRY_RE = re.compile(r'([^:]+):\s+(.+)') + +# Footer metadata key for commit position. +COMMIT_POSITION_FOOTER_KEY = 'Cr-Commit-Position' + +# Regular expression to parse a commit position +COMMIT_POSITION_RE = re.compile(r'(.+)@\{#(\d+)\}') + +# Key for the 'git-svn' ID metadata commit footer entry. +GIT_SVN_ID_FOOTER_KEY = 'git-svn-id' + +# e.g., git-svn-id: https://v8.googlecode.com/svn/trunk@23117 +# ce2b1a6d-e550-0410-aec6-3dcde31c8c00 +GIT_SVN_ID_RE = re.compile(r'((?:\w+)://[^@]+)@(\d+)\s+(?:[a-zA-Z0-9\-]+)') + + +# Copied from bot_update.py. +def GetCommitMessageFooterMap(message): + """Returns: (dict) A dictionary of commit message footer entries. + """ + footers = {} + + # Extract the lines in the footer block. + lines = [] + for line in message.strip().splitlines(): + line = line.strip() + if len(line) == 0: + del(lines[:]) + continue + lines.append(line) + + # Parse the footer + for line in lines: + m = COMMIT_FOOTER_ENTRY_RE.match(line) + if not m: + # If any single line isn't valid, the entire footer is invalid. + footers.clear() + return footers + footers[m.group(1)] = m.group(2).strip() + return footers class GitFailedException(Exception): @@ -199,11 +241,42 @@ class GitRecipesMixin(object): raise GitFailedException("Git hash %s is unknown." % git_hash) log = self.GitLog(n=1, format="%B", git_hash=git_hash) for line in reversed(log.splitlines()): - match = GIT_SVN_ID_RE.match(line.strip()) + match = ROLL_DEPS_GIT_SVN_ID_RE.match(line.strip()) if match: return match.group(1) raise GitFailedException("Couldn't convert %s to SVN." % git_hash) + @Strip + # Copied from bot_update.py and modified for svn-like numbers only. + def GetCommitPositionNumber(self, git_hash): + """Dumps the 'git' log for a specific revision and parses out the commit + position number. + + If a commit position metadata key is found, its number will be returned. + + Otherwise, we will search for a 'git-svn' metadata entry. If one is found, + its SVN revision value is returned. + """ + git_log = self.GitLog(format='%B', n=1, git_hash=git_hash) + footer_map = GetCommitMessageFooterMap(git_log) + + # Search for commit position metadata + value = footer_map.get(COMMIT_POSITION_FOOTER_KEY) + if value: + match = COMMIT_POSITION_RE.match(value) + if match: + return match.group(2) + + # Extract the svn revision from 'git-svn' metadata + value = footer_map.get(GIT_SVN_ID_FOOTER_KEY) + if value: + match = GIT_SVN_ID_RE.match(value) + if match: + return match.group(2) + return None + + ### Git svn stuff + def GitSVNFetch(self): self.Git("svn fetch") diff --git a/tools/push-to-trunk/releases.py b/tools/push-to-trunk/releases.py index 239189e..b6893fe 100755 --- a/tools/push-to-trunk/releases.py +++ b/tools/push-to-trunk/releases.py @@ -57,77 +57,6 @@ DEPS_RE = re.compile(r"""^\s*(?:["']v8_revision["']: ["']""" BLEEDING_EDGE_TAGS_RE = re.compile( r"A \/tags\/([^\s]+) \(from \/branches\/bleeding_edge\:(\d+)\)") -# Regular expression that matches a single commit footer line. -COMMIT_FOOTER_ENTRY_RE = re.compile(r'([^:]+):\s+(.+)') - -# Footer metadata key for commit position. -COMMIT_POSITION_FOOTER_KEY = 'Cr-Commit-Position' - -# Regular expression to parse a commit position -COMMIT_POSITION_RE = re.compile(r'(.+)@\{#(\d+)\}') - -# Key for the 'git-svn' ID metadata commit footer entry. -GIT_SVN_ID_FOOTER_KEY = 'git-svn-id' - -# e.g., git-svn-id: https://v8.googlecode.com/svn/trunk@23117 -# ce2b1a6d-e550-0410-aec6-3dcde31c8c00 -GIT_SVN_ID_RE = re.compile(r'((?:\w+)://[^@]+)@(\d+)\s+(?:[a-zA-Z0-9\-]+)') - - -# Copied from bot_update.py. -def GetCommitMessageFooterMap(message): - """Returns: (dict) A dictionary of commit message footer entries. - """ - footers = {} - - # Extract the lines in the footer block. - lines = [] - for line in message.strip().splitlines(): - line = line.strip() - if len(line) == 0: - del(lines[:]) - continue - lines.append(line) - - # Parse the footer - for line in lines: - m = COMMIT_FOOTER_ENTRY_RE.match(line) - if not m: - # If any single line isn't valid, the entire footer is invalid. - footers.clear() - return footers - footers[m.group(1)] = m.group(2).strip() - return footers - - -# Copied from bot_update.py and modified for svn-like numbers only. -def GetCommitPositionNumber(step, git_hash): - """Dumps the 'git' log for a specific revision and parses out the commit - position number. - - If a commit position metadata key is found, its number will be returned. - - Otherwise, we will search for a 'git-svn' metadata entry. If one is found, - its SVN revision value is returned. - """ - git_log = step.GitLog(format='%B', n=1, git_hash=git_hash) - footer_map = GetCommitMessageFooterMap(git_log) - - # Search for commit position metadata - value = footer_map.get(COMMIT_POSITION_FOOTER_KEY) - if value: - match = COMMIT_POSITION_RE.match(value) - if match: - return match.group(2) - - # Extract the svn revision from 'git-svn' metadata - value = footer_map.get(GIT_SVN_ID_FOOTER_KEY) - if value: - match = GIT_SVN_ID_RE.match(value) - if match: - return match.group(2) - return None - def SortBranches(branches): """Sort branches with version number names.""" @@ -419,7 +348,7 @@ class RetrieveChromiumV8Releases(Step): deps = FileToText(self.Config(DEPS_FILE)) match = DEPS_RE.search(deps) if match: - cr_rev = GetCommitPositionNumber(self, git_hash) + cr_rev = self.GetCommitPositionNumber(git_hash) if cr_rev: v8_rev = ConvertToCommitNumber(self, match.group(1)) cr_releases.append([cr_rev, v8_rev]) diff --git a/tools/push-to-trunk/test_scripts.py b/tools/push-to-trunk/test_scripts.py index bb41cf1..5499c6c 100644 --- a/tools/push-to-trunk/test_scripts.py +++ b/tools/push-to-trunk/test_scripts.py @@ -800,6 +800,18 @@ Performance and stability improvements on all platforms.""", commit) def testPushToTrunkForced(self): self._PushToTrunk(force=True) + C_V8_22624_LOG = """V8 CL. + +git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22624 123 + +""" + + C_V8_123456_LOG = """V8 CL. + +git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@123456 123 + +""" + def testChromiumRoll(self): googlers_mapping_py = "%s-mapping.py" % TEST_CONFIG[PERSISTFILE_BASENAME] with open(googlers_mapping_py, "w") as f: @@ -817,19 +829,17 @@ def get_list(): TextToFile("Some line\n \"v8_revision\": \"123444\",\n some line", TEST_CONFIG[DEPS_FILE]) def WriteDeps(): - TextToFile("Some line\n \"v8_revision\": \"123455\",\n some line", + TextToFile("Some line\n \"v8_revision\": \"22624\",\n some line", TEST_CONFIG[DEPS_FILE]) expectations = [ - Cmd("git status -s -uno", ""), - Cmd("git status -s -b -uno", "## some_branch\n"), - Cmd("git svn fetch", ""), + Cmd("git fetch origin", ""), Cmd(("git log -1 --format=%H --grep=" "\"^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\" " - "svn/trunk"), "push_hash\n"), - Cmd("git svn find-rev push_hash", "123455\n"), + "origin/master"), "push_hash\n"), + Cmd("git log -1 --format=%B push_hash", self.C_V8_22624_LOG), Cmd("git log -1 --format=%s push_hash", - "Version 3.22.5 (based on bleeding_edge revision r123454)\n"), + "Version 3.22.5 (based on bleeding_edge revision r22622)\n"), URL("https://chromium-build.appspot.com/p/chromium/sheriff_v8.js", "document.write('g_name')"), Cmd("git status -s -uno", ""), @@ -837,10 +847,10 @@ def get_list(): Cmd("gclient sync --nohooks", "syncing..."), Cmd("git pull", ""), Cmd("git fetch origin", ""), - Cmd("git checkout -b v8-roll-123455", ""), - Cmd("roll-dep v8 123455", "rolled", cb=WriteDeps), + Cmd("git checkout -b v8-roll-22624", ""), + Cmd("roll-dep v8 22624", "rolled", cb=WriteDeps), Cmd(("git commit -am \"Update V8 to version 3.22.5 " - "(based on bleeding_edge revision r123454).\n\n" + "(based on bleeding_edge revision r22622).\n\n" "Please reply to the V8 sheriff c_name@chromium.org in " "case of problems.\n\nTBR=c_name@chromium.org\" " "--author \"author@chromium.org \""), @@ -855,7 +865,7 @@ def get_list(): ChromiumRoll(TEST_CONFIG, self).Run(args) deps = FileToText(TEST_CONFIG[DEPS_FILE]) - self.assertTrue(re.search("\"v8_revision\": \"123455\"", deps)) + self.assertTrue(re.search("\"v8_revision\": \"22624\"", deps)) def testCheckLastPushRecently(self): self.Expect([ @@ -960,8 +970,8 @@ deps = { ("{\"results\": [{\"subject\": \"different\"}]}")), Cmd(("git log -1 --format=%H --grep=" "\"^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\" " - "svn/trunk"), "push_hash\n"), - Cmd("git svn find-rev push_hash", "123455\n"), + "origin/master"), "push_hash\n"), + Cmd("git log -1 --format=%B push_hash", self.C_V8_22624_LOG), URL("http://src.chromium.org/svn/trunk/src/DEPS", self.FAKE_DEPS), ]) @@ -980,8 +990,8 @@ deps = { ("{\"results\": [{\"subject\": \"different\"}]}")), Cmd(("git log -1 --format=%H --grep=" "\"^Version [[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*\" " - "svn/trunk"), "push_hash\n"), - Cmd("git svn find-rev push_hash", "123456\n"), + "origin/master"), "push_hash\n"), + Cmd("git log -1 --format=%B push_hash", self.C_V8_123456_LOG), URL("http://src.chromium.org/svn/trunk/src/DEPS", self.FAKE_DEPS), ]) @@ -1170,11 +1180,6 @@ git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4567 0039-1c4b git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3456 0039-1c4b """ - c_v8_22624_log = """V8 CL. - -git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22624 123 - -""" json_output = self.MakeEmptyTempFile() csv_output = self.MakeEmptyTempFile() TEST_CONFIG[VERSION_FILE] = self.MakeEmptyTempFile() @@ -1263,7 +1268,7 @@ git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22624 123 Cmd("git rev-list -n 1 0123456789012345678901234567890123456789", "0123456789012345678901234567890123456789"), Cmd("git log -1 --format=%B 0123456789012345678901234567890123456789", - c_v8_22624_log), + self.C_V8_22624_LOG), Cmd("git diff --name-only c_hash3 c_hash3^", TEST_CONFIG[DEPS_FILE]), Cmd("git checkout -f c_hash3 -- %s" % TEST_CONFIG[DEPS_FILE], "", cb=ResetDEPS(345)), -- 2.7.4