python - P4 Python - 描述搁置的文件更改

标签 python perforce

当对搁置的文件使用以下 p4 命令时,差异也会附加在输出的末尾。

> p4 describe -S 1529307
Change 1529307 by who@client on 2015/09/10 14:03:56 *pending*

Comment 

Shelved files ...
... //depot/projects/afile.py#4 edit

Differences ...

==== //depot/projects/afile.py#4 (text) ====
1c1
< testing1-2-3-4-5-6-7
---
> testing1-2-3-4-5-6-7-8-9-10

但是,在 P4Python 中执行类似操作时,从 run('describe -S') 函数返回的数据不包含版本差异。

{
'status': 'pending', 
'code': 'stat', 
'depotFile0': '//depot/projects/afile.py', 
'changeType': 'public', 
'action0': 'edit', 
'fileSize0': '28', 
'shelved': '', 
'client': 'client', 
'user': 'who', 
'time': '144036', 
'rev0': '4', 
'digest0': '8C425B5CF', 
'data': '', 
'type0': 'text',
'change': '1529307', 
'desc': 'Comment\n'
}

我能想到的唯一解决方法是使用此处的软件仓库路径来查找文件,然后将其与软件仓库中的先前版本进行比较。不过我仍然认为应该有一种更简单的方法将该信息嵌入到 P4Python 中。

谢谢!

最佳答案

我目前提出的解决方案如下。我希望 P4Python 尽快提供一种自动化的方式,以可视化搁置更改的差异。 如果您有更好的解决方案,请随时告诉我。

data = p4obj.run('describe -S ' + str(changelist))[0]

files = []
i = 0
while data.has_key('depotFile'+str(i)):
    files.append((data['depotFile'+str(i)],data['rev'+str(i)],data['action'+str(i)]))
    i += 1
for f in files:
    name = f[0]
    oldRev = str(int(f[1]))
    oldFile = tempfile.mktemp()
    oldFilespec = '%s#%s' % (name, oldRev)
    p4.runinteractive('print -q %s > %s' %(oldFilespec, oldFile))
    editedFile = tempfile.mktemp()
    editedFilespec = '%s@=%s'%(name, changelist)
    p4.runinteractive('print -q %s > %s' %(editedFilespec, editedFile))
    DiffTwoFiles(oldFile, editedFile, label1=oldFilespec, label2=editedFilespec)

关于python - P4 Python - 描述搁置的文件更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32512302/

相关文章:

python - 将 C++ copyTo 转换为 Python

python - Pytorch:为什么 print(model) 不显示激活函数?

python - Pandas 在相似的列上合并 2 个数据帧(即索引)

python - 在 django 应用程序中保存静态文件的位置,如何从 nginx 的多个位置提供静态文件

debugging - 关于 ECLIM 的简短 HOW TO

p4 diff 上的 Python 代码覆盖率

python - 使用 python 字典处理 keyerror

version-control - 如何配置 Beyond Compare 以忽略评论中的 SCCM 替换文本?

full-text-search - Perforce 全文搜索

python - 如何让 Python 看到 librt?