2011-02-01 Ojan Vafai <ojan@chromium.org>
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Feb 2011 04:29:50 +0000 (04:29 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Feb 2011 04:29:50 +0000 (04:29 +0000)
        Reviewed by Adam Roben.

        include svn revisions in git diffs for the code review tool to use
        https://bugs.webkit.org/show_bug.cgi?id=53569

        * Scripts/webkitpy/common/checkout/scm.py:
        * Scripts/webkitpy/common/checkout/scm_unittest.py:
2011-02-01  Ojan Vafai  <ojan@chromium.org>

        Reviewed by Adam Roben.

        include svn revisions in git diffs for the code review tool to use
        https://bugs.webkit.org/show_bug.cgi?id=53569

        * PrettyPatch/PrettyPatch.rb:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@77889 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/checkout/scm.py
Tools/Scripts/webkitpy/common/checkout/scm_unittest.py
Websites/bugs.webkit.org/ChangeLog
Websites/bugs.webkit.org/PrettyPatch/PrettyPatch.rb

index de7f023..5d88efb 100644 (file)
@@ -1,3 +1,13 @@
+2011-02-01  Ojan Vafai  <ojan@chromium.org>
+
+        Reviewed by Adam Roben.
+
+        include svn revisions in git diffs for the code review tool to use
+        https://bugs.webkit.org/show_bug.cgi?id=53569
+
+        * Scripts/webkitpy/common/checkout/scm.py:
+        * Scripts/webkitpy/common/checkout/scm_unittest.py:
+
 2011-02-03  MORITA Hajime  <morrita@google.com>
 
         Reviewed by Darin Fisher.
index 421c0dc..6decdca 100644 (file)
@@ -746,6 +746,22 @@ class Git(SCM):
     def display_name(self):
         return "git"
 
+    def prepend_svn_revision(self, diff):
+        revision = None
+        tries = 0
+        while not revision and tries < 10:
+            # If the git checkout is not tracking an SVN repo, then svn_revision_from_git_commit throws.
+            try:
+                revision = self.svn_revision_from_git_commit('HEAD~' + str(tries))
+            except:
+                return diff
+            tries += 1
+
+        if not revision:
+            return diff
+
+        return "Subversion Revision: " + str(revision) + '\n' + diff
+
     def create_patch(self, git_commit=None, changed_files=None):
         """Returns a byte array (str()) representing the patch file.
         Patch files are effectively binary since they may contain
@@ -753,7 +769,7 @@ class Git(SCM):
         command = ['git', 'diff', '--binary', "--no-ext-diff", "--full-index", "-M", self.merge_base(git_commit), "--"]
         if changed_files:
             command += changed_files
-        return self.run(command, decode_output=False, cwd=self.checkout_root)
+        return self.prepend_svn_revision(self.run(command, decode_output=False, cwd=self.checkout_root))
 
     def _run_git_svn_find_rev(self, arg):
         # git svn find-rev always exits 0, even when the revision or commit is not found.
index 64122b4..decfae0 100644 (file)
@@ -810,6 +810,16 @@ class GitTest(SCMTest):
         run_command(['git', 'config', '--add', 'svn-remote.svn.fetch', 'trunk:remote2'])
         self.assertEqual(self.tracking_scm.remote_branch_ref(), 'remote1')
 
+    def test_create_patch(self):
+        write_into_file_at_path('test_file_commit1', 'contents')
+        run_command(['git', 'add', 'test_file_commit1'])
+        scm = detect_scm_system(self.untracking_checkout_path)
+        scm.commit_locally_with_message('message')
+
+        patch = scm.create_patch()
+        self.assertFalse(re.search(r'Subversion Revision:', patch))
+
+
 class GitSVNTest(SCMTest):
 
     def _setup_git_checkout(self):
@@ -1126,6 +1136,7 @@ class GitSVNTest(SCMTest):
         patch = scm.create_patch()
         self.assertTrue(re.search(r'test_file_commit2', patch))
         self.assertTrue(re.search(r'test_file_commit1', patch))
+        self.assertTrue(re.search(r'Subversion Revision: 5', patch))
 
     def test_create_patch_with_changed_files(self):
         self._one_local_commit_plus_working_copy_changes()
index f40eea6..3eef3c1 100644 (file)
@@ -1,5 +1,14 @@
 2011-02-01  Ojan Vafai  <ojan@chromium.org>
 
+        Reviewed by Adam Roben.
+
+        include svn revisions in git diffs for the code review tool to use
+        https://bugs.webkit.org/show_bug.cgi?id=53569
+
+        * PrettyPatch/PrettyPatch.rb:
+
+2011-02-01  Ojan Vafai  <ojan@chromium.org>
+
         Reviewed by Adam Barth.
 
         make draft comments focusable
index 6ac98d2..3ca5db3 100644 (file)
@@ -15,6 +15,17 @@ public
         fileDiffs = FileDiff.parse(string)
 
         str = HEADER + "\n"
+
+        # Just look at the first line to see if it is an SVN revision number as added
+        # by webkit-patch for git checkouts.
+        string.each_line do |line|
+            match = /^Subversion\ Revision: (\d*)$/.match(line)
+            unless match.nil?
+              str += "<span class='revision'>" + match[1] + "</span>\n"
+            end
+            break
+        end
+
         str += fileDiffs.collect{ |diff| diff.to_html }.join
     end