Created
February 25, 2017 07:44
-
-
Save dougn/ba2e4f299571632d0c7ac1ef09aaacbd to your computer and use it in GitHub Desktop.
Get the file diff's included in the perforce P4Python api structured data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## The Perforce P4Python api and p4 -G (marshalled data) do not return the diff data shown when you use the 'p4 describe' | |
## command to describe a changeset. You need to run the P4Python API in untagged mode. But then you have to parse things yourself. | |
## But the untagged data is partially structured. Each piece of data is included with embedded newlines. The file diff section has each | |
## header and then the diff data. The tagged data returned from the P4Python API has each file's data split into independent lists. | |
## So you get the file names and revisions each as independent lists. But the file diff section may not include all files. Some | |
## might be binary, some might be too large to diff (by server settings), etc. So you want to add two new lists to the tagged | |
## output, one for the headers and one for the diff raw data, but you want them to be aligned with the depotFiles listing. | |
## and using '' has sentinal place holders. So here we go: | |
import P4 | |
import itertools | |
p4 = P4.P4() # assume P4PORT, etc set in env. | |
p4.connect() | |
desc = p4.run_describe(12345)[0] | |
with p4.while_tagged(False): | |
result = p4.run_describe(12345) | |
# 5 lines of simple text processing. | |
r = itertools.dropwhile(lambda x: x!='\nDifferences ...\n', result) | |
r.next() # drop off the sentinal | |
rr = {x.split(' ',1)[1].rsplit('#',1)[0] : (x,y) for x,y in itertools.izip(r,r)} | |
desc['diffHeader'] = [ rr.get(df, ('',''))[0] for df in desc['depotFile'] ] | |
desc['diffData'] = [ rr.get(df, ('',''))[1] for df in desc['depotFile'] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment