Skip to content

Commit b4073bb

Browse files
mawwwgitster
authored andcommitted
git-p4: Do not include diff in spec file when just preparing p4
The diff information render the spec file unusable as is by p4, do not include it when run with --prepare-p4-only so that the given file can be directly passed to p4. With --prepare-p4-only, git-p4 already tells the user it can use p4 submit with the generated spec file. This fails because of the diff being present in the file. Not including the diff fixes that. Without --prepare-p4-only, keeping the diff makes sense for a quick review of the patch before submitting it. And does not cause problems with p4 as we remove it programmatically. Signed-off-by: Maxime Coste <[email protected]> Acked-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a28f16 commit b4073bb

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

git-p4.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,28 @@ def edit_template(self, template_file):
12381238
if response == 'n':
12391239
return False
12401240

1241+
def get_diff_description(self, editedFiles):
1242+
# diff
1243+
if os.environ.has_key("P4DIFF"):
1244+
del(os.environ["P4DIFF"])
1245+
diff = ""
1246+
for editedFile in editedFiles:
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"
1254+
newdiff += "--- /dev/null\n"
1255+
newdiff += "+++ %s\n" % newFile
1256+
f = open(newFile, "r")
1257+
for line in f.readlines():
1258+
newdiff += "+" + line
1259+
f.close()
1260+
1261+
return diff + newdiff
1262+
12411263
def applyCommit(self, id):
12421264
"""Apply one commit, return True if it succeeded."""
12431265

@@ -1398,34 +1420,15 @@ def applyCommit(self, id):
13981420
submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"
13991421

14001422
separatorLine = "######## everything below this line is just the diff #######\n"
1423+
if not self.prepare_p4_only:
1424+
submitTemplate += separatorLine
1425+
submitTemplate += self.get_diff_description(editedFiles)
14011426

1402-
# diff
1403-
if os.environ.has_key("P4DIFF"):
1404-
del(os.environ["P4DIFF"])
1405-
diff = ""
1406-
for editedFile in editedFiles:
1407-
diff += p4_read_pipe(['diff', '-du',
1408-
wildcard_encode(editedFile)])
1409-
1410-
# new file diff
1411-
newdiff = ""
1412-
for newFile in filesToAdd:
1413-
newdiff += "==== new file ====\n"
1414-
newdiff += "--- /dev/null\n"
1415-
newdiff += "+++ %s\n" % newFile
1416-
f = open(newFile, "r")
1417-
for line in f.readlines():
1418-
newdiff += "+" + line
1419-
f.close()
1420-
1421-
# change description file: submitTemplate, separatorLine, diff, newdiff
14221427
(handle, fileName) = tempfile.mkstemp()
14231428
tmpFile = os.fdopen(handle, "w+")
14241429
if self.isWindows:
14251430
submitTemplate = submitTemplate.replace("\n", "\r\n")
1426-
separatorLine = separatorLine.replace("\n", "\r\n")
1427-
newdiff = newdiff.replace("\n", "\r\n")
1428-
tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
1431+
tmpFile.write(submitTemplate)
14291432
tmpFile.close()
14301433

14311434
if self.prepare_p4_only:

t/t9807-git-p4-submit.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ test_expect_success 'submit --prepare-p4-only' '
403403
git commit -m "prep only add" &&
404404
git p4 submit --prepare-p4-only >out &&
405405
test_i18ngrep "prepared for submission" out &&
406-
test_i18ngrep "must be deleted" out
406+
test_i18ngrep "must be deleted" out &&
407+
! test_i18ngrep "everything below this line is just the diff" out
407408
) &&
408409
(
409410
cd "$cli" &&

0 commit comments

Comments
 (0)