Merge branch 'mt/p4-parse-G-output'
Use "p4 -G" to make "p4 changes" output more Python-friendly to parse. * mt/p4-parse-G-output: git-p4: filter for {'code':'info'} in p4CmdList git-p4: parse marshal output "p4 -G" in p4 changes git-p4: git-p4 tests with p4 triggers
This commit is contained in:
commit
4f0b213699
86
git-p4.py
86
git-p4.py
@ -313,7 +313,7 @@ def p4_move(src, dest):
|
|||||||
p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])
|
p4_system(["move", "-k", wildcard_encode(src), wildcard_encode(dest)])
|
||||||
|
|
||||||
def p4_last_change():
|
def p4_last_change():
|
||||||
results = p4CmdList(["changes", "-m", "1"])
|
results = p4CmdList(["changes", "-m", "1"], skip_info=True)
|
||||||
return int(results[0]['change'])
|
return int(results[0]['change'])
|
||||||
|
|
||||||
def p4_describe(change):
|
def p4_describe(change):
|
||||||
@ -321,7 +321,7 @@ def p4_describe(change):
|
|||||||
the presence of field "time". Return a dict of the
|
the presence of field "time". Return a dict of the
|
||||||
results."""
|
results."""
|
||||||
|
|
||||||
ds = p4CmdList(["describe", "-s", str(change)])
|
ds = p4CmdList(["describe", "-s", str(change)], skip_info=True)
|
||||||
if len(ds) != 1:
|
if len(ds) != 1:
|
||||||
die("p4 describe -s %d did not return 1 result: %s" % (change, str(ds)))
|
die("p4 describe -s %d did not return 1 result: %s" % (change, str(ds)))
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ def isModeExec(mode):
|
|||||||
def isModeExecChanged(src_mode, dst_mode):
|
def isModeExecChanged(src_mode, dst_mode):
|
||||||
return isModeExec(src_mode) != isModeExec(dst_mode)
|
return isModeExec(src_mode) != isModeExec(dst_mode)
|
||||||
|
|
||||||
def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None):
|
def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False):
|
||||||
|
|
||||||
if isinstance(cmd,basestring):
|
if isinstance(cmd,basestring):
|
||||||
cmd = "-G " + cmd
|
cmd = "-G " + cmd
|
||||||
@ -545,6 +545,9 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None):
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
entry = marshal.load(p4.stdout)
|
entry = marshal.load(p4.stdout)
|
||||||
|
if skip_info:
|
||||||
|
if 'code' in entry and entry['code'] == 'info':
|
||||||
|
continue
|
||||||
if cb is not None:
|
if cb is not None:
|
||||||
cb(entry)
|
cb(entry)
|
||||||
else:
|
else:
|
||||||
@ -879,8 +882,12 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
|
|||||||
cmd += ["%s...@%s" % (p, revisionRange)]
|
cmd += ["%s...@%s" % (p, revisionRange)]
|
||||||
|
|
||||||
# Insert changes in chronological order
|
# Insert changes in chronological order
|
||||||
for line in reversed(p4_read_pipe_lines(cmd)):
|
for entry in reversed(p4CmdList(cmd)):
|
||||||
changes.add(int(line.split(" ")[1]))
|
if entry.has_key('p4ExitCode'):
|
||||||
|
die('Error retrieving changes descriptions ({})'.format(entry['p4ExitCode']))
|
||||||
|
if not entry.has_key('change'):
|
||||||
|
continue
|
||||||
|
changes.add(int(entry['change']))
|
||||||
|
|
||||||
if not block_size:
|
if not block_size:
|
||||||
break
|
break
|
||||||
@ -1526,37 +1533,62 @@ class P4Submit(Command, P4UserMap):
|
|||||||
|
|
||||||
[upstream, settings] = findUpstreamBranchPoint()
|
[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
|
inFilesSection = False
|
||||||
|
change_entry = None
|
||||||
args = ['change', '-o']
|
args = ['change', '-o']
|
||||||
if changelist:
|
if changelist:
|
||||||
args.append(str(changelist))
|
args.append(str(changelist))
|
||||||
|
for entry in p4CmdList(args):
|
||||||
for line in p4_read_pipe_lines(args):
|
if not entry.has_key('code'):
|
||||||
if line.endswith("\r\n"):
|
continue
|
||||||
line = line[:-2] + "\n"
|
if entry['code'] == 'stat':
|
||||||
if inFilesSection:
|
change_entry = entry
|
||||||
if line.startswith("\t"):
|
break
|
||||||
# path starts and ends with a tab
|
if not change_entry:
|
||||||
path = line[1:]
|
die('Failed to decode output of p4 change -o')
|
||||||
lastTab = path.rfind("\t")
|
for key, value in change_entry.iteritems():
|
||||||
if lastTab != -1:
|
if key.startswith('File'):
|
||||||
path = path[:lastTab]
|
|
||||||
if settings.has_key('depot-paths'):
|
if settings.has_key('depot-paths'):
|
||||||
if not [p for p in settings['depot-paths']
|
if not [p for p in settings['depot-paths']
|
||||||
if p4PathStartsWith(path, p)]:
|
if p4PathStartsWith(value, p)]:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
if not p4PathStartsWith(path, self.depotPath):
|
if not p4PathStartsWith(value, self.depotPath):
|
||||||
continue
|
continue
|
||||||
else:
|
files_list.append(value)
|
||||||
inFilesSection = False
|
continue
|
||||||
else:
|
# Output in the order expected by prepareLogMessage
|
||||||
if line.startswith("Files:"):
|
for key in ['Change', 'Client', 'User', 'Status', 'Description', 'Jobs']:
|
||||||
inFilesSection = True
|
if not change_entry.has_key(key):
|
||||||
|
continue
|
||||||
template += line
|
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
|
return template
|
||||||
|
|
||||||
def edit_template(self, template_file):
|
def edit_template(self, template_file):
|
||||||
|
103
t/t9831-git-p4-triggers.sh
Executable file
103
t/t9831-git-p4-triggers.sh
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='git p4 with server triggers'
|
||||||
|
|
||||||
|
. ./lib-git-p4.sh
|
||||||
|
|
||||||
|
test_expect_success 'start p4d' '
|
||||||
|
start_p4d
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'init depot' '
|
||||||
|
(
|
||||||
|
cd "$cli" &&
|
||||||
|
echo file1 >file1 &&
|
||||||
|
p4 add file1 &&
|
||||||
|
p4 submit -d "change 1"
|
||||||
|
echo file2 >file2 &&
|
||||||
|
p4 add file2 &&
|
||||||
|
p4 submit -d "change 2"
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'clone with extra info lines from verbose p4 trigger' '
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
p4 triggers -i <<-EOF
|
||||||
|
Triggers: p4triggertest-command command pre-user-change "echo verbose trigger"
|
||||||
|
EOF
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
p4 change -o | grep -s "verbose trigger"
|
||||||
|
) &&
|
||||||
|
git p4 clone --dest="$git" //depot/@all &&
|
||||||
|
(
|
||||||
|
p4 triggers -i <<-EOF
|
||||||
|
Triggers:
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'import with extra info lines from verbose p4 trigger' '
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$cli" &&
|
||||||
|
echo file3 >file3 &&
|
||||||
|
p4 add file3 &&
|
||||||
|
p4 submit -d "change 3"
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
p4 triggers -i <<-EOF
|
||||||
|
Triggers: p4triggertest-command command pre-user-describe "echo verbose trigger"
|
||||||
|
EOF
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
p4 describe 1 | grep -s "verbose trigger"
|
||||||
|
) &&
|
||||||
|
git p4 clone --dest="$git" //depot/@all &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
git p4 sync
|
||||||
|
)&&
|
||||||
|
(
|
||||||
|
p4 triggers -i <<-EOF
|
||||||
|
Triggers:
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submit description with extra info lines from verbose p4 change trigger' '
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
p4 triggers -i <<-EOF
|
||||||
|
Triggers: p4triggertest-command command pre-user-change "echo verbose trigger"
|
||||||
|
EOF
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
p4 change -o | grep -s "verbose trigger"
|
||||||
|
) &&
|
||||||
|
git p4 clone --dest="$git" //depot &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
git config git-p4.skipSubmitEdit true &&
|
||||||
|
echo file4 >file4 &&
|
||||||
|
git add file4 &&
|
||||||
|
git commit -m file4 &&
|
||||||
|
git p4 submit
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
p4 triggers -i <<-EOF
|
||||||
|
Triggers:
|
||||||
|
EOF
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
cd "$cli" &&
|
||||||
|
test_path_is_file file4
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'kill p4d' '
|
||||||
|
kill_p4d
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue
Block a user