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

git-p4 support for perforce renames.

The current git-p4 implementation does support file renames. However, because it does not use the "p4 integrate" command, the history for the renamed file is not linked to the new file. This changeset adds support for perforce renames with the integrate command. Currently this feature is only enabled when calling git-p4 submit with the -M option. This is intended to look and behave similar to the "detect renames" feature of other git commands. The following sequence is used for renamed files: p4 integrate -Dt x x' p4 edit x' rm x' git apply p4 delete x By default, perforce will not allow an integration with a target file that has been deleted. That is, if x' in the example above is the name of a previously deleted file then perforce will fail the integrate. The -Dt option tells perforce to allow the target of integrate to be a previously deleted file. Signed-off-by: Chris Pettitt <cpettitt@gmail.com> Signed-off-by: Simon Hausmann <simon@lst.de>

Chris Pettitt committed Oct 15, 2007 at 22:15 UTC d9a5f25b67951eb68e80d872611542b58ce5aa33
1 file changed +11 -1
contrib/fast-import/git-p4
+11 -1
@@ -399,6 +399,7 @@ class P4Submit(Command):
399 optparse.make_option("--dry-run", action="store_true"),
400 optparse.make_option("--direct", dest="directSubmit", action="store_true"),
401 optparse.make_option("--trust-me-like-a-fool", dest="trustMeLikeAFool", action="store_true"),
402 + optparse.make_option("-M", dest="detectRename", action="store_true"),
403 ]
404 self.description = "Submit changes from git to the perforce depot."
405 self.usage += " [name of git branch to submit into perforce depot]"
@@ -411,6 +412,7 @@ class P4Submit(Command):
412 self.origin = ""
413 self.directSubmit = False
414 self.trustMeLikeAFool = False
415 + self.detectRename = False
416 self.verbose = False
417 self.isWindows = (platform.system() == "Windows")
418
@@ -491,7 +493,8 @@ class P4Submit(Command):
493 diff = self.diffStatus
494 else:
495 print "Applying %s" % (read_pipe("git log --max-count=1 --pretty=oneline %s" % id))
494 - diff = read_pipe_lines("git diff-tree -r --name-status \"%s^\" \"%s\"" % (id, id))
496 + diffOpts = ("", "-M")[self.detectRename]
497 + diff = read_pipe_lines("git diff-tree -r --name-status %s \"%s^\" \"%s\"" % (diffOpts, id, id))
498 filesToAdd = set()
499 filesToDelete = set()
500 editedFiles = set()
@@ -509,6 +512,13 @@ class P4Submit(Command):
512 filesToDelete.add(path)
513 if path in filesToAdd:
514 filesToAdd.remove(path)
515 + elif modifier == "R":
516 + src, dest = line.strip().split("\t")[1:3]
517 + system("p4 integrate -Dt \"%s\" \"%s\"" % (src, dest))
518 + system("p4 edit \"%s\"" % (dest))
519 + os.unlink(dest)
520 + editedFiles.add(dest)
521 + filesToDelete.add(src)
522 else:
523 die("unknown modifier %s for %s" % (modifier, path))
524