From: Maxime Coste <frrrwww@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Pete Wyckoff <pw@padd.com>
Subject: [PATCH] git-p4: Do not include diff in spec file when just preparing p4
Date: Sat, 24 May 2014 18:40:35 +0100 [thread overview]
Message-ID: <20140524174034.GA7560@nekage> (raw)
In-Reply-To: <20140524135215.GA9386@padd.com>
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 <frrrwww@gmail.com>
Acked-by: Pete Wyckoff <pw@padd.com>
---
git-p4.py | 49 +++++++++++++++++++++++++-----------------------
t/t9807-git-p4-submit.sh | 3 ++-
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 773cafc..7bb0f73 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1238,6 +1238,28 @@ class P4Submit(Command, P4UserMap):
if response == 'n':
return False
+ def get_diff_description(self, editedFiles):
+ # diff
+ if os.environ.has_key("P4DIFF"):
+ del(os.environ["P4DIFF"])
+ diff = ""
+ for editedFile in editedFiles:
+ diff += p4_read_pipe(['diff', '-du',
+ wildcard_encode(editedFile)])
+
+ # new file diff
+ newdiff = ""
+ for newFile in filesToAdd:
+ newdiff += "==== new file ====\n"
+ newdiff += "--- /dev/null\n"
+ newdiff += "+++ %s\n" % newFile
+ f = open(newFile, "r")
+ for line in f.readlines():
+ newdiff += "+" + line
+ f.close()
+
+ return diff + newdiff
+
def applyCommit(self, id):
"""Apply one commit, return True if it succeeded."""
@@ -1398,34 +1420,15 @@ class P4Submit(Command, P4UserMap):
submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"
separatorLine = "######## everything below this line is just the diff #######\n"
+ if not self.prepare_p4_only:
+ submitTemplate += separatorLine
+ submitTemplate += self.get_diff_description(editedFiles)
- # diff
- if os.environ.has_key("P4DIFF"):
- del(os.environ["P4DIFF"])
- diff = ""
- for editedFile in editedFiles:
- diff += p4_read_pipe(['diff', '-du',
- wildcard_encode(editedFile)])
-
- # new file diff
- newdiff = ""
- for newFile in filesToAdd:
- newdiff += "==== new file ====\n"
- newdiff += "--- /dev/null\n"
- newdiff += "+++ %s\n" % newFile
- f = open(newFile, "r")
- for line in f.readlines():
- newdiff += "+" + line
- f.close()
-
- # change description file: submitTemplate, separatorLine, diff, newdiff
(handle, fileName) = tempfile.mkstemp()
tmpFile = os.fdopen(handle, "w+")
if self.isWindows:
submitTemplate = submitTemplate.replace("\n", "\r\n")
- separatorLine = separatorLine.replace("\n", "\r\n")
- newdiff = newdiff.replace("\n", "\r\n")
- tmpFile.write(submitTemplate + separatorLine + diff + newdiff)
+ tmpFile.write(submitTemplate)
tmpFile.close()
if self.prepare_p4_only:
diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh
index 4caf36e..7fab2ed 100755
--- a/t/t9807-git-p4-submit.sh
+++ b/t/t9807-git-p4-submit.sh
@@ -403,7 +403,8 @@ test_expect_success 'submit --prepare-p4-only' '
git commit -m "prep only add" &&
git p4 submit --prepare-p4-only >out &&
test_i18ngrep "prepared for submission" out &&
- test_i18ngrep "must be deleted" out
+ test_i18ngrep "must be deleted" out &&
+ ! test_i18ngrep "everything below this line is just the diff" out
) &&
(
cd "$cli" &&
--
1.9.3
next prev parent reply other threads:[~2014-05-24 17:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-10 18:18 [PATCH] git-p4: Do not include diff in spec file when just preparing p4 Maxime Coste
2014-01-12 22:29 ` Pete Wyckoff
2014-01-13 12:10 ` Maxime Coste
2014-01-14 0:06 ` Pete Wyckoff
2014-05-24 1:39 ` Maxime Coste
2014-05-24 1:44 ` Maxime Coste
2014-05-24 13:52 ` Pete Wyckoff
2014-05-24 17:40 ` Maxime Coste [this message]
2014-06-10 12:14 ` [PATCH] Fix git-p4 submit in non --prepare-p4-only mode Maxime Coste
2014-06-10 22:39 ` Pete Wyckoff
2014-06-11 13:06 ` Maxime Coste
2014-06-11 13:36 ` Pete Wyckoff
2014-06-11 13:09 ` Maxime Coste
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140524174034.GA7560@nekage \
--to=frrrwww@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pw@padd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).