git p4: refactor diffOpts calculation
authorGary Gibbons <ggibbons@perforce.com>
Wed, 4 Jul 2012 13:40:19 +0000 (09:40 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 Jul 2012 06:23:28 +0000 (23:23 -0700)
P4Submit.applyCommit()

To avoid recalculating the same diffOpts for each commit, move it
out of applyCommit() and into the top-level run(). Also fix a bug
in that code which interpreted the value of detectRenames as a
string rather than as a boolean.

[pw: fix documentation, rearrange code a bit]

Signed-off-by: Gary Gibbons <ggibbons@perforce.com>
Signed-off-by: Pete Wyckoff <pw@padd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-p4.txt
git-p4.py
index fe1f49bc6f26950987bc5520267663f4f335dab0..8228f33e3fdf0e6ec9c66dd3f55ad8094dfeb6aa 100644 (file)
@@ -255,7 +255,7 @@ These options can be used to modify 'git p4 submit' behavior.
        p4.  By default, this is the most recent p4 commit reachable
        from 'HEAD'.
 
        p4.  By default, this is the most recent p4 commit reachable
        from 'HEAD'.
 
--M[<n>]::
+-M::
        Detect renames.  See linkgit:git-diff[1].  Renames will be
        represented in p4 using explicit 'move' operations.  There
        is no corresponding option to detect copies, but there are
        Detect renames.  See linkgit:git-diff[1].  Renames will be
        represented in p4 using explicit 'move' operations.  There
        is no corresponding option to detect copies, but there are
@@ -465,13 +465,15 @@ git-p4.useClientSpec::
 Submit variables
 ~~~~~~~~~~~~~~~~
 git-p4.detectRenames::
 Submit variables
 ~~~~~~~~~~~~~~~~
 git-p4.detectRenames::
-       Detect renames.  See linkgit:git-diff[1].
+       Detect renames.  See linkgit:git-diff[1].  This can be true,
+       false, or a score as expected by 'git diff -M'.
 
 git-p4.detectCopies::
 
 git-p4.detectCopies::
-       Detect copies.  See linkgit:git-diff[1].
+       Detect copies.  See linkgit:git-diff[1].  This can be true,
+       false, or a score as expected by 'git diff -C'.
 
 git-p4.detectCopiesHarder::
 
 git-p4.detectCopiesHarder::
-       Detect copies harder.  See linkgit:git-diff[1].
+       Detect copies harder.  See linkgit:git-diff[1].  A boolean.
 
 git-p4.preserveUser::
        On submit, re-author changes to reflect the git author,
 
 git-p4.preserveUser::
        On submit, re-author changes to reflect the git author,
index f895a2412bd5723d72f3bcfdcddbce495070d5e6..5fe509f6f8655affacca304dcacfb3f77d7ac7cf 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -1046,27 +1046,8 @@ def applyCommit(self, id):
 
         (p4User, gitEmail) = self.p4UserForCommit(id)
 
 
         (p4User, gitEmail) = self.p4UserForCommit(id)
 
-        if not self.detectRenames:
-            # If not explicitly set check the config variable
-            self.detectRenames = gitConfig("git-p4.detectRenames")
-
-        if self.detectRenames.lower() == "false" or self.detectRenames == "":
-            diffOpts = ""
-        elif self.detectRenames.lower() == "true":
-            diffOpts = "-M"
-        else:
-            diffOpts = "-M%s" % self.detectRenames
-
-        detectCopies = gitConfig("git-p4.detectCopies")
-        if detectCopies.lower() == "true":
-            diffOpts += " -C"
-        elif detectCopies != "" and detectCopies.lower() != "false":
-            diffOpts += " -C%s" % detectCopies
 
 
-        if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
-            diffOpts += " --find-copies-harder"
-
-        diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (diffOpts, id, id))
+        diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (self.diffOpts, id, id))
         filesToAdd = set()
         filesToDelete = set()
         editedFiles = set()
         filesToAdd = set()
         filesToDelete = set()
         editedFiles = set()
@@ -1433,6 +1414,37 @@ def run(self, args):
         if self.preserveUser:
             self.checkValidP4Users(commits)
 
         if self.preserveUser:
             self.checkValidP4Users(commits)
 
+        #
+        # Build up a set of options to be passed to diff when
+        # submitting each commit to p4.
+        #
+        if self.detectRenames:
+            # command-line -M arg
+            self.diffOpts = "-M"
+        else:
+            # If not explicitly set check the config variable
+            detectRenames = gitConfig("git-p4.detectRenames")
+
+            if detectRenames.lower() == "false" or detectRenames == "":
+                self.diffOpts = ""
+            elif detectRenames.lower() == "true":
+                self.diffOpts = "-M"
+            else:
+                self.diffOpts = "-M%s" % detectRenames
+
+        # no command-line arg for -C or --find-copies-harder, just
+        # config variables
+        detectCopies = gitConfig("git-p4.detectCopies")
+        if detectCopies.lower() == "false" or detectCopies == "":
+            pass
+        elif detectCopies.lower() == "true":
+            self.diffOpts += " -C"
+        else:
+            self.diffOpts += " -C%s" % detectCopies
+
+        if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
+            self.diffOpts += " --find-copies-harder"
+
         while len(commits) > 0:
             commit = commits[0]
             commits = commits[1:]
         while len(commits) > 0:
             commit = commits[0]
             commits = commits[1:]