@matheusbsbs / matheus-bagliano / commits / 47a130b7bf
Fork 0

Use git format-patch and git apply --apply when extracting patches from git and applying them to a Perforce checkout. This should make it possible to apply git commits with binary files that cannot be handled by path.

Use git format-patch and git apply --apply when extracting patches from git and applying them to a Perforce checkout. This should make it possible to apply git commits with binary files that cannot be handled by path. Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed May 20, 2007 at 16:33 UTC 47a130b7bf74b8f61d9fee01f5dbb745d8f44b29
1 file changed +8 -5
contrib/fast-import/git-p4
+8 -5
@@ -213,10 +213,13 @@ class P4Submit(Command):
213 else:
214 die("unknown modifier %s for %s" % (modifier, path))
215
216 - diffcmd = "git diff-tree -p --diff-filter=ACMRTUXB \"%s^\" \"%s\"" % (id, id)
217 - patchcmd = diffcmd + " | patch -p1"
216 + diffcmd = "git format-patch -k --stdout \"%s^\"..\"%s\"" % (id, id)
217 + patchcmd = diffcmd + " | git apply "
218 + tryPatchCmd = diffcmd + "--check -"
219 + applyPatchCmd = diffcmd + "--check --apply -"
220 + print mypopen(diffcmd).read()
221
219 - if os.system(patchcmd + " --dry-run --silent") != 0:
222 + if os.system(tryPatchCmd) != 0:
223 print "Unfortunately applying the change failed!"
224 print "What do you want to do?"
225 response = "x"
@@ -226,7 +229,7 @@ class P4Submit(Command):
229 print "Skipping! Good luck with the next patches..."
230 return
231 elif response == "a":
229 - os.system(patchcmd)
232 + os.system(applyPatchCmd)
233 if len(filesToAdd) > 0:
234 print "You may also want to call p4 add on the following files:"
235 print " ".join(filesToAdd)
@@ -239,7 +242,7 @@ class P4Submit(Command):
242 print "Patch saved to patch.txt in %s !" % self.clientPath
243 die("Please resolve and submit the conflict manually and continue afterwards with git-p4 submit --continue")
244
242 - system(patchcmd)
245 + system(applyPatchCmd)
246
247 for f in filesToAdd:
248 system("p4 add %s" % f)