git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-p4: changelist template with p4 -G change -o
@ 2017-06-20 12:19 Miguel Torroja
  2017-06-22 17:32 ` Junio C Hamano
  0 siblings, 1 reply; 31+ messages in thread
From: Miguel Torroja @ 2017-06-20 12:19 UTC (permalink / raw)
  To: git; +Cc: Miguel Torroja

The option -G of p4 (python marshal output) gives more context about the
data being output. That's useful when using the command "change -o" as
we can distinguish between warning/error line and real change description.

Some p4 plugin/hooks in the server side generates some warnings when
executed. Unfortunately those messages are mixed with the output of
"p4 change -o". Those extra warning lines are reported as {'code':'info'}
in python marshal output (-G). The real change output is reported as
{'code':'stat'}

Signed-off-by: Miguel Torroja <miguel.torroja@gmail.com>
---
 git-p4.py | 77 ++++++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 51 insertions(+), 26 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index 8d151da..a300474 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1526,37 +1526,62 @@ class P4Submit(Command, P4UserMap):
 
         [upstream, settings] = findUpstreamBranchPoint()
 
-        template = ""
+        template = """\
+# A Perforce Change Specification.
+#
+#  Change:      The change number. 'new' on a new changelist.
+#  Date:        The date this specification was last modified.
+#  Client:      The client on which the changelist was created.  Read-only.
+#  User:        The user who created the changelist.
+#  Status:      Either 'pending' or 'submitted'. Read-only.
+#  Type:        Either 'public' or 'restricted'. Default is 'public'.
+#  Description: Comments about the changelist.  Required.
+#  Jobs:        What opened jobs are to be closed by this changelist.
+#               You may delete jobs from this list.  (New changelists only.)
+#  Files:       What opened files from the default changelist are to be added
+#               to this changelist.  You may delete files from this list.
+#               (New changelists only.)
+"""
+        files_list = []
         inFilesSection = False
+        change_entry = None
         args = ['change', '-o']
         if changelist:
             args.append(str(changelist))
-
-        for line in p4_read_pipe_lines(args):
-            if line.endswith("\r\n"):
-                line = line[:-2] + "\n"
-            if inFilesSection:
-                if line.startswith("\t"):
-                    # path starts and ends with a tab
-                    path = line[1:]
-                    lastTab = path.rfind("\t")
-                    if lastTab != -1:
-                        path = path[:lastTab]
-                        if settings.has_key('depot-paths'):
-                            if not [p for p in settings['depot-paths']
-                                    if p4PathStartsWith(path, p)]:
-                                continue
-                        else:
-                            if not p4PathStartsWith(path, self.depotPath):
-                                continue
+        for entry in p4CmdList(args):
+            if not entry.has_key('code'):
+                continue
+            if entry['code'] == 'stat':
+                change_entry = entry
+                break
+        if not change_entry:
+            die('Failed to decode output of p4 change -o')
+        for key, value in change_entry.iteritems():
+            if key.startswith('File'):
+                if settings.has_key('depot-paths'):
+                    if not [p for p in settings['depot-paths']
+                            if p4PathStartsWith(value, p)]:
+                        continue
                 else:
-                    inFilesSection = False
-            else:
-                if line.startswith("Files:"):
-                    inFilesSection = True
-
-            template += line
-
+                    if not p4PathStartsWith(value, self.depotPath):
+                        continue
+                files_list.append(value)
+                continue
+        # Output in the order expected by prepareLogMessage
+        for key in ['Change','Client','User','Status','Description','Jobs']:
+            if not change_entry.has_key(key):
+                continue
+            template += '\n'
+            template += key + ':'
+            if key == 'Description':
+                template += '\n'
+            for field_line in change_entry[key].splitlines():
+                template += '\t'+field_line+'\n'
+        if len(files_list) > 0:
+            template += '\n'
+            template += 'Files:\n'
+        for path in files_list:
+            template += '\t'+path+'\n'
         return template
 
     def edit_template(self, template_file):
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2017-07-13 19:30 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-20 12:19 [PATCH] git-p4: changelist template with p4 -G change -o Miguel Torroja
2017-06-22 17:32 ` Junio C Hamano
2017-06-24 11:49   ` Luke Diamand
2017-06-24 12:38     ` miguel torroja
2017-06-24 17:36     ` Lars Schneider
     [not found]       ` <CAKYtbVbGekXGAyPd7HeLot_MdZkp7-1Ss-iAi7o8ze2b+sNB6Q@mail.gmail.com>
2017-06-27  9:20         ` miguel torroja
2017-06-27 19:17           ` [PATCH] git-p4: parse marshal output "p4 -G" in p4 changes Miguel Torroja
2017-06-28  4:08             ` Junio C Hamano
2017-06-28  9:54               ` Luke Diamand
2017-06-28 13:14                 ` miguel torroja
     [not found]                   ` <CAE5ih7-x45MD1H6Ahr5oCVtTjgbBkeP4GbKCGB-Cwk6BSQwTcw@mail.gmail.com>
2017-06-29 22:41                     ` miguel torroja
2017-06-30  7:56                       ` Luke Diamand
2017-06-30  8:22                         ` miguel torroja
2017-06-29 22:46                     ` Miguel Torroja
2017-06-30  8:26                       ` Lars Schneider
2017-06-30  9:41                         ` Miguel Torroja
2017-06-30 10:13                           ` Lars Schneider
2017-06-30 16:02                             ` Miguel Torroja
2017-07-03 22:53                               ` Miguel Torroja
2017-07-03 22:57                             ` Miguel Torroja
2017-07-11  8:35                               ` Luke Diamand
2017-07-11 22:35                                 ` Miguel Torroja
2017-07-11 22:53                                 ` Miguel Torroja
2017-07-12  8:25                                   ` Luke Diamand
2017-07-12 10:16                                     ` Miguel Torroja
2017-07-12 17:13                                       ` Junio C Hamano
2017-07-13  7:00                                         ` [PATCH 1/3] git-p4: git-p4 tests with p4 triggers Miguel Torroja
2017-07-13  7:00                                           ` [PATCH 2/3] git-p4: parse marshal output "p4 -G" in p4 changes Miguel Torroja
2017-07-13  7:00                                           ` [PATCH 3/3] git-p4: filter for {'code':'info'} in p4CmdList Miguel Torroja
2017-07-13  7:12                                         ` [PATCH] git-p4: parse marshal output "p4 -G" in p4 changes Miguel Torroja
2017-07-13 19:30                                           ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).