Commit b596b3b9 authored by Miguel Torroja's avatar Miguel Torroja Committed by Junio C Hamano

git-p4: parse marshal output "p4 -G" in p4 changes

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.

This fixes the case where a p4 trigger for  "p4 change" is set and the command git-p4 submit is run.
Signed-off-by: default avatarMiguel Torroja <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent c625bf0e
......@@ -879,8 +879,12 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
cmd += ["%[email protected]%s" % (p, revisionRange)]
# Insert changes in chronological order
for line in reversed(p4_read_pipe_lines(cmd)):
changes.add(int(line.split(" ")[1]))
for entry in reversed(p4CmdList(cmd)):
if entry.has_key('p4ExitCode'):
die('Error retrieving changes descriptions ({})'.format(entry['p4ExitCode']))
if not entry.has_key('change'):
if not block_size:
......@@ -1526,37 +1530,62 @@ def prepareSubmitTemplate(self, changelist=None):
[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:
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)]:
if not p4PathStartsWith(path, self.depotPath):
for entry in p4CmdList(args):
if not entry.has_key('code'):
if entry['code'] == 'stat':
change_entry = entry
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)]:
inFilesSection = False
if line.startswith("Files:"):
inFilesSection = True
template += line
if not p4PathStartsWith(value, self.depotPath):
# Output in the order expected by prepareLogMessage
for key in ['Change', 'Client', 'User', 'Status', 'Description', 'Jobs']:
if not change_entry.has_key(key):
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):
......@@ -66,7 +66,7 @@ test_expect_failure 'import with extra info lines from verbose p4 trigger' '
test_expect_failure 'submit description with extra info lines from verbose p4 change trigger' '
test_expect_success 'submit description with extra info lines from verbose p4 change trigger' '
test_when_finished cleanup_git &&
p4 triggers -i <<-EOF
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment