Added experimental but super-fast --apply-as-patch option to git-p4 submit
Signed-off-by: Simon Hausmann <hausmann@kde.org>
Simon Hausmann committed
Mar 21, 2007 at 10:11 UTC
04219c04b7554d13b049d4aba534ce02a12abeb4
1 file changed
+18
-11
contrib/fast-import/git-p4.py
+18
-11
@@ -115,7 +115,8 @@ class P4Sync(Command):
115
optparse.make_option("--master", dest="master"),
116
optparse.make_option("--log-substitutions", dest="substFile"),
117
optparse.make_option("--noninteractive", action="store_false"),
118
- optparse.make_option("--dry-run", action="store_true")
118
+ optparse.make_option("--dry-run", action="store_true"),
119
+ optparse.make_option("--apply-as-patch", action="store_true", dest="applyAsPatch")
120
]
121
self.description = "Submit changes from git to the perforce depot."
122
self.firstTime = True
@@ -126,6 +127,7 @@ class P4Sync(Command):
127
self.firstTime = True
128
self.origin = "origin"
129
self.master = ""
130
+ self.applyAsPatch = False
131
132
self.logSubstitutions = {}
133
self.logSubstitutions["<enter description here>"] = "%log%"
@@ -146,8 +148,9 @@ class P4Sync(Command):
148
149
self.config["commits"] = commits
150
149
- print "Creating temporary p4-sync branch from %s ..." % self.origin
150
- system("git checkout -f -b p4-sync %s" % self.origin)
151
+ if not self.applyAsPatch:
152
+ print "Creating temporary p4-sync branch from %s ..." % self.origin
153
+ system("git checkout -f -b p4-sync %s" % self.origin)
154
155
def prepareLogMessage(self, template, message):
156
result = ""
@@ -193,8 +196,11 @@ class P4Sync(Command):
196
else:
197
die("unknown modifier %s for %s" % (modifier, path))
198
196
- system("git-diff-files --name-only -z | git-update-index --remove -z --stdin")
197
- system("git cherry-pick --no-commit \"%s\"" % id)
199
+ if self.applyAsPatch:
200
+ system("git-diff-tree -p \"%s^\" \"%s\" | patch -p1" % (id, id))
201
+ else:
202
+ system("git-diff-files --name-only -z | git-update-index --remove -z --stdin")
203
+ system("git cherry-pick --no-commit \"%s\"" % id)
204
205
for f in filesToAdd:
206
system("p4 add %s" % f)
@@ -305,12 +311,13 @@ class P4Sync(Command):
311
print "No changes found to apply between %s and current HEAD" % self.origin
312
else:
313
print "All changes applied!"
308
- print "Deleting temporary p4-sync branch and going back to %s" % self.master
309
- system("git checkout %s" % self.master)
310
- system("git branch -D p4-sync")
311
- print "Cleaning out your perforce checkout by doing p4 edit ... ; p4 revert ..."
312
- system("p4 edit ... >/dev/null")
313
- system("p4 revert ... >/dev/null")
314
+ if not self.applyAsPatch:
315
+ print "Deleting temporary p4-sync branch and going back to %s" % self.master
316
+ system("git checkout %s" % self.master)
317
+ system("git branch -D p4-sync")
318
+ print "Cleaning out your perforce checkout by doing p4 edit ... ; p4 revert ..."
319
+ system("p4 edit ... >/dev/null")
320
+ system("p4 revert ... >/dev/null")
321
os.remove(self.configFile)
322
323
return True