@matheusbsbs / matheus-bagliano / commits / ae901090f7
Fork 0

git-p4: Improve rename detection support

Only open files for edit after integrating if the SHA1 of source and destination differ from each other. Add git config option detectRenames to allow permanent rename detection. This options should be set to a true/false value. Rename "detectRename" variable to "detectRenames" to make it more coherent with the description in git man pages, which always use plural. Signed-off-by: Vitor Antunes <vitor.hda@gmail.com> Acked-by: Pete Wyckoff <pw@padd.com> Acked-by: Tor Arvid Lund <torarvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vitor Antunes committed Feb 20, 2011 at 01:18 UTC ae901090f715fe6e5f589b4d92ec87b74429ed1b
1 file changed +15 -4
contrib/fast-import/git-p4
+15 -4
@@ -543,13 +543,13 @@ class P4Submit(Command):
543 self.options = [
544 optparse.make_option("--verbose", dest="verbose", action="store_true"),
545 optparse.make_option("--origin", dest="origin"),
546 - optparse.make_option("-M", dest="detectRename", action="store_true"),
546 + optparse.make_option("-M", dest="detectRenames", action="store_true"),
547 ]
548 self.description = "Submit changes from git to the perforce depot."
549 self.usage += " [name of git branch to submit into perforce depot]"
550 self.interactive = True
551 self.origin = ""
552 - self.detectRename = False
552 + self.detectRenames = False
553 self.verbose = False
554 self.isWindows = (platform.system() == "Windows")
555
@@ -613,7 +613,16 @@ class P4Submit(Command):
613
614 def applyCommit(self, id):
615 print "Applying %s" % (read_pipe("git log --max-count=1 --pretty=oneline %s" % id))
616 - diffOpts = ("", "-M")[self.detectRename]
616 +
617 + if not self.detectRenames:
618 + # If not explicitly set check the config variable
619 + self.detectRenames = gitConfig("git-p4.detectRenames").lower() == "true"
620 +
621 + if self.detectRenames:
622 + diffOpts = "-M"
623 + else:
624 + diffOpts = ""
625 +
626 diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (diffOpts, id, id))
627 filesToAdd = set()
628 filesToDelete = set()
@@ -640,8 +649,10 @@ class P4Submit(Command):
649 elif modifier == "R":
650 src, dest = diff['src'], diff['dst']
651 p4_system("integrate -Dt \"%s\" \"%s\"" % (src, dest))
643 - p4_system("edit \"%s\"" % (dest))
652 + if diff['src_sha1'] != diff['dst_sha1']:
653 + p4_system("edit \"%s\"" % (dest))
654 if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
655 + p4_system("edit \"%s\"" % (dest))
656 filesToChangeExecBit[dest] = diff['dst_mode']
657 os.unlink(dest)
658 editedFiles.add(dest)