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

P4 Python - describe shelved file changes

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

> 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 中执行类似操作时,从 运行('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 的错,而是因为 Perforce 服务器本身不会 return 如果 'describe' 命令是 运行 在 'tagged'模式。

我认为另一种解决方法是从您的 Python 程序执行 "run describe",但不幸的是,您必须自己解析输出。

我相信 Perforce 已经在文件中提出了改进此行为的增强请求,但您当然可以向 Perforce 提出此请求,看看他们是否会改进它。 https://swarm.workshop.perforce.com/docs/contact.html

您可以使输出不带标签。

这里有一个例子:

希望这对您有所帮助, 珍.

我想出的当前解决方案如下。我希望 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)