Reputation: 527
My goal is to produce a JSON file that contains a list of all the files in a changelist and associated line numbers for each file. Something that looks like this:
[
{
"name":"file1.cpp",
"lines":[[1,3],[5,7]]
},
{
"name":"file2.h",
"lines":[9,14]
}
]
'p4 describe' gives us a list of files participating in the given changelist. But, I am interested in getting to the set of lines changed in each file.
For the purpose of this question, the working assumptions are
Upvotes: 2
Views: 531
Reputation: 21160
The formatting flag -d[formatting option] for p4 describe should help here. For example, p4 describe -dc1 [changelist] will give you a format like this:
Change 2238074 by user@client on 2014/09/02 11:23:44
Change description
Affected files ...
... //depot/path/file1.java#3 edit
Differences ...
==== //depot/path/file1.java#3 (text) ====
***************
*** 8,11 ****
credentials {
! username 'olduser'
! password 'oldpass'
}
--- 8,11 ----
credentials {
! username 'newuser'
! password 'newpass'
}
So you get the line numbers and starting columns for each change. (The "1" at the end of the format flag limits the number of context lines printed per diff, as you only want the line numbers).
See "p4 help describe" for other options.
Since you're doing a lot of parsing and output formatting, you might want to look at one of the Perforce APIs rather than the command line to get the change data.
Upvotes: 2