All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Coste <frrrwww@gmail.com>
To: git@vger.kernel.org
Subject: [PATCH] git-p4: Do not include diff in spec file when just preparing p4
Date: Fri, 10 Jan 2014 18:18:07 +0000	[thread overview]
Message-ID: <20140110181807.GA29164@nekage> (raw)

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.
---
 git-p4.py | 70 +++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 5ea8bb8..7c65340 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1397,38 +1397,14 @@ class P4Submit(Command, P4UserMap):
             submitTemplate += "######## Use option --preserve-user to modify authorship.\n"
             submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n"
 
-        separatorLine = "######## everything below this line is just the diff #######\n"
-
-        # 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.close()
-
         if self.prepare_p4_only:
+            (handle, fileName) = tempfile.mkstemp()
+            tmpFile = os.fdopen(handle, "w+")
+            if self.isWindows:
+                submitTemplate = submitTemplate.replace("\n", "\r\n")
+            tmpFile.write(submitTemplate)
+            tmpFile.close()
+
             #
             # Leave the p4 tree prepared, and the submit template around
             # and let the user decide what to do next
@@ -1463,6 +1439,38 @@ class P4Submit(Command, P4UserMap):
             print
             return True
 
+        else:
+            separatorLine = "######## everything below this line is just the diff #######\n"
+
+            # 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.close()
+
         #
         # Let the user edit the change description, then submit it.
         #
-- 
1.8.5.2

             reply	other threads:[~2014-01-10 18:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10 18:18 Maxime Coste [this message]
2014-01-12 22:29 ` [PATCH] git-p4: Do not include diff in spec file when just preparing p4 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
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=20140110181807.GA29164@nekage \
    --to=frrrwww@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.