git p4: rearrange submit template construction
Put all items in order as they appear, and add comments. Signed-off-by: Pete Wyckoff <pw@padd.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Sep 9, 2012 at 16:16 UTC
55ac2ed6f56c153bc71dc80eb7634e2df2747670
1 file changed
+21
-8
git-p4.py
+21
-8
@@ -1202,6 +1202,9 @@ class P4Submit(Command, P4UserMap):
1202
p4_revert(f)
1203
return False
1204
1205
+ #
1206
+ # Apply the patch for real, and do add/delete/+x handling.
1207
+ #
1208
system(applyPatchCmd)
1209
1210
for f in filesToAdd:
@@ -1215,6 +1218,10 @@ class P4Submit(Command, P4UserMap):
1218
mode = filesToChangeExecBit[f]
1219
setP4ExecBit(f, mode)
1220
1221
+ #
1222
+ # Build p4 change description, starting with the contents
1223
+ # of the git commit message.
1224
+ #
1225
logMessage = extractLogMessageFromGitCommit(id)
1226
logMessage = logMessage.strip()
1227
(logMessage, jobs) = self.separate_jobs_from_description(logMessage)
@@ -1223,8 +1230,16 @@ class P4Submit(Command, P4UserMap):
1230
submitTemplate = self.prepareLogMessage(template, logMessage, jobs)
1231
1232
if self.preserveUser:
1226
- submitTemplate = submitTemplate + ("\n######## Actual user %s, modified after commit\n" % p4User)
1233
+ submitTemplate += "\n######## Actual user %s, modified after commit\n" % p4User
1234
+
1235
+ if self.checkAuthorship and not self.p4UserIsMe(p4User):
1236
+ submitTemplate += "######## git author %s does not match your p4 account.\n" % gitEmail
1237
+ submitTemplate += "######## Use option --preserve-user to modify authorship.\n"
1238
+ submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"
1239
+
1240
+ separatorLine = "######## everything below this line is just the diff #######\n"
1241
1242
+ # diff
1243
if os.environ.has_key("P4DIFF"):
1244
del(os.environ["P4DIFF"])
1245
diff = ""
@@ -1232,6 +1247,7 @@ class P4Submit(Command, P4UserMap):
1247
diff += p4_read_pipe(['diff', '-du',
1248
wildcard_encode(editedFile)])
1249
1250
+ # new file diff
1251
newdiff = ""
1252
for newFile in filesToAdd:
1253
newdiff += "==== new file ====\n"
@@ -1242,13 +1258,7 @@ class P4Submit(Command, P4UserMap):
1258
newdiff += "+" + line
1259
f.close()
1260
1245
- if self.checkAuthorship and not self.p4UserIsMe(p4User):
1246
- submitTemplate += "######## git author %s does not match your p4 account.\n" % gitEmail
1247
- submitTemplate += "######## Use option --preserve-user to modify authorship.\n"
1248
- submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"
1249
-
1250
- separatorLine = "######## everything below this line is just the diff #######\n"
1251
-
1261
+ # change description file: submitTemplate, separatorLine, diff, newdiff
1262
(handle, fileName) = tempfile.mkstemp()
1263
tmpFile = os.fdopen(handle, "w+")
1264
if self.isWindows:
@@ -1258,6 +1268,9 @@ class P4Submit(Command, P4UserMap):
1268
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
1269
tmpFile.close()
1270
1271
+ #
1272
+ # Let the user edit the change description, then submit it.
1273
+ #
1274
if self.edit_template(fileName):
1275
# read the edited message and submit
1276
ret = True