Skip to content

Commit ae90109

Browse files
vhdagitster
authored andcommitted
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 <[email protected]> Acked-by: Pete Wyckoff <[email protected]> Acked-by: Tor Arvid Lund <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ed863a commit ae90109

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

contrib/fast-import/git-p4

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,13 @@ class P4Submit(Command):
543543
self.options = [
544544
optparse.make_option("--verbose", dest="verbose", action="store_true"),
545545
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"),
547547
]
548548
self.description = "Submit changes from git to the perforce depot."
549549
self.usage += " [name of git branch to submit into perforce depot]"
550550
self.interactive = True
551551
self.origin = ""
552-
self.detectRename = False
552+
self.detectRenames = False
553553
self.verbose = False
554554
self.isWindows = (platform.system() == "Windows")
555555

@@ -613,7 +613,16 @@ class P4Submit(Command):
613613

614614
def applyCommit(self, id):
615615
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+
617626
diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (diffOpts, id, id))
618627
filesToAdd = set()
619628
filesToDelete = set()
@@ -640,8 +649,10 @@ class P4Submit(Command):
640649
elif modifier == "R":
641650
src, dest = diff['src'], diff['dst']
642651
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))
644654
if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
655+
p4_system("edit \"%s\"" % (dest))
645656
filesToChangeExecBit[dest] = diff['dst_mode']
646657
os.unlink(dest)
647658
editedFiles.add(dest)

0 commit comments

Comments
 (0)