【问题标题】:Is it possible to get a list of files changed and a list of lines modified from Perforce changelist是否可以从 Perforce 更改列表中获取更改的文件列表和修改的行列表
【发布时间】:2015-03-15 07:31:47
【问题描述】:

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

[
 {
  "name":"file1.cpp",
  "lines":[[1,3],[5,7]]
 },
 {
  "name":"file2.h",
  "lines":[9,14]
 }
]

'p4 describe' 为我们提供了参与给定更改列表的文件列表。但是,我有兴趣了解每个文件中更改的行集。

就这个问题而言,工作假设是

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

【问题讨论】:

    标签: version-control diff perforce


    【解决方案1】:

    p4 describe 的格式化标志 -d[formatting option] 在这里应该有所帮助。例如, p4 describe -dc1 [changelist] 将为您提供如下格式:

        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 帮助描述”。

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

    【讨论】:

    • 我将上下文减少到 0 并对该输出进行操作。
    猜你喜欢
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    相关资源
    最近更新 更多