Skip to content

Commit 5e3d39b

Browse files
committed
Merge branch 'va/p4'
* va/p4: git-p4: Add copy detection support git-p4: Improve rename detection support
2 parents 8d3a362 + 4fddb41 commit 5e3d39b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

contrib/fast-import/git-p4

Lines changed: 31 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,22 @@ 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+
626+
if gitConfig("git-p4.detectCopies").lower() == "true":
627+
diffOpts += " -C"
628+
629+
if gitConfig("git-p4.detectCopiesHarder").lower() == "true":
630+
diffOpts += " --find-copies-harder"
631+
617632
diff = read_pipe_lines("git diff-tree -r %s \"%s^\" \"%s\"" % (diffOpts, id, id))
618633
filesToAdd = set()
619634
filesToDelete = set()
@@ -637,11 +652,23 @@ class P4Submit(Command):
637652
filesToDelete.add(path)
638653
if path in filesToAdd:
639654
filesToAdd.remove(path)
655+
elif modifier == "C":
656+
src, dest = diff['src'], diff['dst']
657+
p4_system("integrate -Dt \"%s\" \"%s\"" % (src, dest))
658+
if diff['src_sha1'] != diff['dst_sha1']:
659+
p4_system("edit \"%s\"" % (dest))
660+
if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
661+
p4_system("edit \"%s\"" % (dest))
662+
filesToChangeExecBit[dest] = diff['dst_mode']
663+
os.unlink(dest)
664+
editedFiles.add(dest)
640665
elif modifier == "R":
641666
src, dest = diff['src'], diff['dst']
642667
p4_system("integrate -Dt \"%s\" \"%s\"" % (src, dest))
643-
p4_system("edit \"%s\"" % (dest))
668+
if diff['src_sha1'] != diff['dst_sha1']:
669+
p4_system("edit \"%s\"" % (dest))
644670
if isModeExecChanged(diff['src_mode'], diff['dst_mode']):
671+
p4_system("edit \"%s\"" % (dest))
645672
filesToChangeExecBit[dest] = diff['dst_mode']
646673
os.unlink(dest)
647674
editedFiles.add(dest)

0 commit comments

Comments
 (0)