Reviewers: jarin, hinoka,

Message:
PTAL. Code partially borrowed from roll-dep from depot_tools.

Description:
Teach v8rel script to read git hashes from DEPS.

The chromium DEPS file can refer to v8 git hashes now. These
are converted back into svn revision numbers for the v8
releases spreadsheet.

The DEPS file's quotation mark policy changed which affects
the regexp for retrieving the v8 revision ("->').

Please review this at https://codereview.chromium.org/500023003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+56, -7 lines):
  M tools/push-to-trunk/git_recipes.py
  M tools/push-to-trunk/releases.py
  M tools/push-to-trunk/test_scripts.py


Index: tools/push-to-trunk/git_recipes.py
diff --git a/tools/push-to-trunk/git_recipes.py b/tools/push-to-trunk/git_recipes.py index 6ffb2da83405d85322471607e126624021d1abbb..1cbd8f5149802498e3d91fecc2d5f50a9c595ca9 100644
--- a/tools/push-to-trunk/git_recipes.py
+++ b/tools/push-to-trunk/git_recipes.py
@@ -28,6 +28,9 @@

 import re

+SHA1_RE = re.compile('^[a-fA-F0-9]{40}$')
+GIT_SVN_ID_RE = re.compile('^git-svn-id: .*@([0-9]+) .*$')
+

 class GitFailedException(Exception):
   pass
@@ -185,6 +188,20 @@ class GitRecipesMixin(object):
   def GitPull(self):
     self.Git("pull")

+  def GitFetchOrigin(self):
+    self.Git("fetch origin")
+
+  def GitConvertToSVNRevision(self, git_hash):
+    result = self.Git(MakeArgs(["rev-list", "-n", "1", git_hash]))
+    if not result or not SHA1_RE.match(result):
+      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())
+      if match:
+        return match.group(1)
+    raise GitFailedException("Couldn't convert %s to SVN." % git_hash)
+
   def GitSVNFetch(self):
     self.Git("svn fetch")

Index: tools/push-to-trunk/releases.py
diff --git a/tools/push-to-trunk/releases.py b/tools/push-to-trunk/releases.py index 586cbc1fde9732d1e7c004d9109e0003ec8bac1b..bdefaaed6218738fd6b823a34c4c58d314896dee 100755
--- a/tools/push-to-trunk/releases.py
+++ b/tools/push-to-trunk/releases.py
@@ -47,10 +47,10 @@ REVIEW_LINK_RE = re.compile(r"^Review URL: (.+)$", re.M)

# Expression with three versions (historical) for extracting the v8 revision
 # from the chromium DEPS file.
-DEPS_RE = re.compile(r'^\s*(?:"v8_revision": "'
-                      '|\(Var\("googlecode_url"\) % "v8"\) \+ "\/trunk@'
-                      '|"http\:\/\/v8\.googlecode\.com\/svn\/trunk@)'
-                      '([0-9]+)".*$', re.M)
+DEPS_RE = re.compile('^\\s*(?:(?:"|\')v8_revision(?:"|\'): (?:"|\')'
+ '|\\(Var\\("googlecode_url"\\) % "v8"\\) \\+ "\\/trunk@'
+                     '|"http\\:\\/\\/v8\\.googlecode\\.com\\/svn\\/trunk@)'
+                     '([^"\']+)(?:"|\').*$', re.M)

# Expression to pick tag and revision for bleeding edge tags. To be used with
 # output of 'svn log'.
@@ -374,6 +374,18 @@ class UpdateChromiumCheckout(Step):
     self.GitCreateBranch(self.Config(BRANCHNAME))


+def ConvertToCommitNumber(step, revision):
+  if len(revision) > 6:
+    # Simple check for git hashes.
+    try:
+      # TODO(machenbach): Add cwd to git calls.
+      os.chdir(os.path.join(step["chrome_path"], "v8"))
+      return step.GitConvertToSVNRevision(revision)
+    finally:
+      os.chdir(step["chrome_path"])
+  return revision
+
+
 class RetrieveChromiumV8Releases(Step):
   MESSAGE = "Retrieve V8 releases from Chromium DEPS."
   REQUIRES = "chrome_path"
@@ -387,6 +399,14 @@ class RetrieveChromiumV8Releases(Step):
       print "No releases detected. Skipping chromium history."
       return True

+    # Update v8 checkout in chromium.
+    try:
+      # TODO(machenbach): Add cwd to git calls.
+      os.chdir(os.path.join(self["chrome_path"], "v8"))
+      self.GitFetchOrigin()
+    finally:
+      os.chdir(self["chrome_path"])
+
     oldest_v8_rev = int(releases[-1]["revision"])

     cr_releases = []
@@ -401,7 +421,7 @@ class RetrieveChromiumV8Releases(Step):
         if match:
           cr_rev = GetCommitPositionNumber(self, git_hash)
           if cr_rev:
-            v8_rev = match.group(1)
+            v8_rev = ConvertToCommitNumber(self, match.group(1))
             cr_releases.append([cr_rev, v8_rev])

# Stop after reaching beyond the last v8 revision we want to update.
@@ -458,7 +478,7 @@ class RietrieveChromiumBranches(Step):
         deps = FileToText(self.Config(DEPS_FILE))
         match = DEPS_RE.search(deps)
         if match:
-          v8_rev = match.group(1)
+          v8_rev = ConvertToCommitNumber(self, match.group(1))
           cr_branches.append([str(branch), v8_rev])

# Stop after reaching beyond the last v8 revision we want to update.
Index: tools/push-to-trunk/test_scripts.py
diff --git a/tools/push-to-trunk/test_scripts.py b/tools/push-to-trunk/test_scripts.py index 7a40985201fcaab2ab090e81a872ca31bd9a789d..4b1f63846ec3f5ff9e3d2ddb60244840955f954b 100644
--- a/tools/push-to-trunk/test_scripts.py
+++ b/tools/push-to-trunk/test_scripts.py
@@ -1214,6 +1214,11 @@ 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()
@@ -1222,6 +1227,8 @@ git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3456 0039-1c4b
     TEST_CONFIG[DOT_GIT_LOCATION] = self.MakeEmptyTempFile()
     if not os.path.exists(TEST_CONFIG[CHROMIUM]):
       os.makedirs(TEST_CONFIG[CHROMIUM])
+    if not os.path.exists(os.path.join(TEST_CONFIG[CHROMIUM], "v8")):
+      os.makedirs(os.path.join(TEST_CONFIG[CHROMIUM], "v8"))
     def WriteDEPS(revision):
       TextToFile("Line\n   \"v8_revision\": \"%s\",\n  line\n" % revision,
                  TEST_CONFIG[DEPS_FILE])
@@ -1290,12 +1297,17 @@ git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3456 0039-1c4b
       Git("checkout -f master", ""),
       Git("pull", ""),
       Git("checkout -b %s" % TEST_CONFIG[BRANCHNAME], ""),
+      Git("fetch origin", ""),
       Git("log --format=%H --grep=\"V8\"", "c_hash1\nc_hash2\nc_hash3\n"),
       Git("diff --name-only c_hash1 c_hash1^", ""),
       Git("diff --name-only c_hash2 c_hash2^", TEST_CONFIG[DEPS_FILE]),
       Git("checkout -f c_hash2 -- %s" % TEST_CONFIG[DEPS_FILE], "",
-          cb=ResetDEPS(22624)),
+          cb=ResetDEPS("0123456789012345678901234567890123456789")),
       Git("log -1 --format=%B c_hash2", c_hash2_commit_log),
+      Git("rev-list -n 1 0123456789012345678901234567890123456789",
+          "0123456789012345678901234567890123456789"),
+      Git("log -1 --format=%B 0123456789012345678901234567890123456789",
+          c_v8_22624_log),
       Git("diff --name-only c_hash3 c_hash3^", TEST_CONFIG[DEPS_FILE]),
       Git("checkout -f c_hash3 -- %s" % TEST_CONFIG[DEPS_FILE], "",
           cb=ResetDEPS(345)),


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to