{"thread":{"id":"10303","subject":"[PATCH] git-p4 support for perforce renames.","startedAt":"2007-10-16T05:15:06Z","lastAt":"2007-10-16T05:15:06Z","messageCount":1,"participants":["Chris Pettitt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"55946","messageId":"1192511706-21929-1-git-send-email-cpettitt@gmail.com","threadId":"10303","inReplyTo":"de47e4420710152214k1e74bf5eh5ecbf48d0507322@mail.gmail.com","subject":"[PATCH] git-p4 support for perforce renames.","fromName":"Chris Pettitt","fromEmail":"cpettitt@gmail.com","sentAt":"2007-10-16T05:15:06Z","receivedAt":"2007-10-16T05:15:06Z","isPatch":true,"sender":{"key":"cpettitt@gmail.com","avatar":null},"body":"The current git-p4 implementation does support file renames. However, because\nit does not use the \"p4 integrate\" command, the history for the renamed file is\nnot linked to the new file.\n\nThis changeset adds support for perforce renames with the integrate command.\nCurrently this feature is only enabled when calling git-p4 submit with the -M\noption. This is intended to look and behave similar to the \"detect renames\"\nfeature of other git commands.\n\nThe following sequence is used for renamed files:\n\n    p4 integrate -Dt x x'\n    p4 edit x'\n    rm x'\n    git apply\n    p4 delete x\n\nBy default, perforce will not allow an integration with a target file that has\nbeen deleted. That is, if x' in the example above is the name of a previously\ndeleted file then perforce will fail the integrate. The -Dt option tells\nperforce to allow the target of integrate to be a previously deleted file.\n\nSigned-off-by: Chris Pettitt <cpettitt@gmail.com>\n---\n contrib/fast-import/git-p4 |   12 +++++++++++-\n 1 files changed, 11 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4\nindex 557649a..90945b7 100755\n--- a/contrib/fast-import/git-p4\n+++ b/contrib/fast-import/git-p4\n@@ -399,6 +399,7 @@ class P4Submit(Command):\n                 optparse.make_option(\"--dry-run\", action=\"store_true\"),\n                 optparse.make_option(\"--direct\", dest=\"directSubmit\", action=\"store_true\"),\n                 optparse.make_option(\"--trust-me-like-a-fool\", dest=\"trustMeLikeAFool\", action=\"store_true\"),\n+                optparse.make_option(\"-M\", dest=\"detectRename\", action=\"store_true\"),\n         ]\n         self.description = \"Submit changes from git to the perforce depot.\"\n         self.usage += \" [name of git branch to submit into perforce depot]\"\n@@ -411,6 +412,7 @@ class P4Submit(Command):\n         self.origin = \"\"\n         self.directSubmit = False\n         self.trustMeLikeAFool = False\n+        self.detectRename = False\n         self.verbose = False\n         self.isWindows = (platform.system() == \"Windows\")\n \n@@ -491,7 +493,8 @@ class P4Submit(Command):\n             diff = self.diffStatus\n         else:\n             print \"Applying %s\" % (read_pipe(\"git log --max-count=1 --pretty=oneline %s\" % id))\n-            diff = read_pipe_lines(\"git diff-tree -r --name-status \\\"%s^\\\" \\\"%s\\\"\" % (id, id))\n+            diffOpts = (\"\", \"-M\")[self.detectRename]\n+            diff = read_pipe_lines(\"git diff-tree -r --name-status %s \\\"%s^\\\" \\\"%s\\\"\" % (diffOpts, id, id))\n         filesToAdd = set()\n         filesToDelete = set()\n         editedFiles = set()\n@@ -509,6 +512,13 @@ class P4Submit(Command):\n                 filesToDelete.add(path)\n                 if path in filesToAdd:\n                     filesToAdd.remove(path)\n+            elif modifier == \"R\":\n+                src, dest = line.strip().split(\"\\t\")[1:3]\n+                system(\"p4 integrate -Dt \\\"%s\\\" \\\"%s\\\"\" % (src, dest))\n+                system(\"p4 edit \\\"%s\\\"\" % (dest))\n+                os.unlink(dest)\n+                editedFiles.add(dest)\n+                filesToDelete.add(src)\n             else:\n                 die(\"unknown modifier %s for %s\" % (modifier, path))\n \n-- \n1.5.3.4.206.g58ba4\n"}]}