Version control 是否可以从Perforce changelist获得更改的文件列表和修改的行列表

Version control 是否可以从Perforce changelist获得更改的文件列表和修改的行列表,version-control,diff,perforce,Version Control,Diff,Perforce,我的目标是生成一个JSON文件,其中包含变更列表中所有文件的列表以及每个文件的相关行号。看起来像这样的东西: [ { "name":"file1.cpp", "lines":[[1,3],[5,7]] }, { "name":"file2.h", "lines":[9,14] } ] Change 2238074 by user@client on 2014/09/02 11:23:44 Change description Affe

我的目标是生成一个JSON文件,其中包含变更列表中所有文件的列表以及每个文件的相关行号。看起来像这样的东西:

[
 {
  "name":"file1.cpp",
  "lines":[[1,3],[5,7]]
 },
 {
  "name":"file2.h",
  "lines":[9,14]
 }
]
    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'
          }
“p4 descripe”为我们提供了参与给定变更列表的文件列表。但是,我对每个文件中更改的行集感兴趣

就本问题而言,工作假设如下:

  • 具有所有权限的本地(个人)沙箱
  • 已使用“p4更改”创建更改集
  • 对变更集信息进行操作的后处理实用程序也可以
  • 可以使用“p4 diff”作为备份选项

p4描述的格式化标志-d[格式化选项]在这里应该有所帮助。例如,p4 descripe-dc1[changelist]将提供如下格式:

[
 {
  "name":"file1.cpp",
  "lines":[[1,3],[5,7]]
 },
 {
  "name":"file2.h",
  "lines":[9,14]
 }
]
    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'
          }
因此,您可以获得每次更改的行号和起始列。(格式标志末尾的“1”限制每个差异打印的上下文行数,因为您只需要行号)

有关其他选项,请参阅“p4帮助描述”


由于要进行大量的解析和输出格式化,因此可能需要查看其中一个Performce API而不是命令行来获取更改数据。

我将上下文缩减为0,并对该输出进行操作。