如何获取待处理的 Perforce 变更列表中所有文件的差异?

发布于 2024-07-26 09:12:46 字数 195 浏览 5 评论 0原文

我想获取特定待定更改列表中文件的差异。 我希望我能做到这一点:

p4 diff -c 999

有人可以帮我组合一些 csh 魔法来实现这一点吗?

也许可以将 p4 opens -c 999 的输出通过管道传输到 p4 diff 吗?

I want to get diffs on files in a specific pending changelist. I wish I could do this:

p4 diff -c 999

Can someone help me string together some csh magic to make this happen?

Maybe take the output of p4 opened -c 999 and piping it to p4 diff?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

佞臣 2024-08-02 09:12:46

将更改搁置到挂起的更改列表中,然后运行

p4 describe -S -du 999

Shelve the changes in the pending changelist, then run

p4 describe -S -du 999
谁对谁错谁最难过 2024-08-02 09:12:46

最简单的方法是在 p4v 或 p4win 中,但这不是您要问的。

尝试这个:

p4 opened -c 999 | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | csh

当然,您需要确保子 shell 的路径中有 p4,并且 $P4CLIENT 等...都已设置。

The easiest way is in p4v or p4win, but that's not what you were asking about.

Try this:

p4 opened -c 999 | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | csh

You, of course, need to make sure that the sub shell has p4 in its path, and $P4CLIENT, etc... are all set up.

燕归巢 2024-08-02 09:12:46

解决方案

p4 opened -c 999 | sed -e 's/#.*//' | p4 -x - diff

说明

p4 -x 为您提供 xargs 类似的能力,而无需使用 xargs。 来自p4 help utils

-x 标志指示 p4 从
指定文件。 如果指定“-”,则读取标准输入。

因此,您几乎可以按照问题中的建议“获取 p4 opening -c 999 的输出并将其通过管道传输到 p4 diff”。 一个棘手的部分是 p4 opening 的输出在每个打开文件的名称后面包含修订号和解释文本,例如

//depot/example#123 - edit change 999 (text) by day@office
//depot/new-example#1 - add change 999 (text) by day@office

但我们可以通过简单的 sed -e 's/# 来运行它.*//' 删除从 # 开始的所有内容,只留下路径:

//depot/example
//depot/new-example

然后可以从标准输入中使用这些路径并馈送到 p4 diff感谢p4 -x -

如果任何文件的名称中包含 #,那么您需要更巧妙地使用 sed 命令。 并去看心理医生。

Solution

p4 opened -c 999 | sed -e 's/#.*//' | p4 -x - diff

Explanation

p4 -x gives you xargs like ability without having to use xargs. From p4 help utils:

The -x flag instructs p4 to read arguments, one per line, from the
specified file. If you specify '-', standard input is read.

So you can almost just "take the output of p4 opened -c 999 and pipe it to p4 diff" as suggested in the question. The one tricky part is that the output of p4 opened contains revision numbers and explanatory text after the name of each open file e.g.

//depot/example#123 - edit change 999 (text) by day@office
//depot/new-example#1 - add change 999 (text) by day@office

But we can run this through a simple sed -e 's/#.*//' to strip off everything from the # onwards to leave just the paths:

//depot/example
//depot/new-example

which can then be consumed from standard input and fed to p4 diff thanks to p4 -x -.

If you have # in the names of any files then you'll need to get more clever with the sed command. And see a psychiatrist.

醉梦枕江山 2024-08-02 09:12:46

p4 描述 999 | grep '#' | | grep '#' | 剪切-d"#" -f1|剪切-d" " -f2 | xargs p4 差异

p4 describe 999 | grep '#' | cut -d"#" -f1|cut -d" " -f2 | xargs p4 diff

鸩远一方 2024-08-02 09:12:46

您可以像这样使用 shell 脚本:

#!/bin/sh

list=`p4 opened -c $1 | cut -d# -f1`

for file in $list ;
do
  p4 diff -dwbu $file
done

使用更改列表编号调用它,您将在标准输出中获得补丁。

You can use shell script like this:

#!/bin/sh

list=`p4 opened -c $1 | cut -d# -f1`

for file in $list ;
do
  p4 diff -dwbu $file
done

call it with changelist number and you'll get patch in stdout.

萌能量女王 2024-08-02 09:12:46

我使用了与 Mark 类似的方法,但我使用 Perl 而不是 Awk,以及 shell 函数(在 zsh 中):

p4dc() { p4 opened -c $* | perl -ne 's/#.*//; system("p4", "diff", $_)' }

请注意,除了更改列表名称/编号之外,您还可以提供文件路径:

p4dc default | less
p4dc default ... | less

I used a similar approach as Mark, but I used Perl instead of Awk, and a shell function (in zsh):

p4dc() { p4 opened -c $* | perl -ne 's/#.*//; system("p4", "diff", $_)' }

Note that you can provide a file path too, in addition to just the changelist name/number:

p4dc default | less
p4dc default ... | less
几味少女 2024-08-02 09:12:46

对于在 Windows cmd shell 中工作的单行代码,请尝试以下操作:

for /f "usebackq delims=#" %F in (`p4 opened -c 999`) do @p4 diff %F

要在批处理文件中执行此操作,您需要使用 %%F 而不仅仅是 %F

请注意,如果您安装了类似 UNIX 的实用程序包,例如 cygwin 或 unixutils,但是这个单行代码没有外部依赖项。

For a one-liner that works from the Windows cmd shell, try this:

for /f "usebackq delims=#" %F in (`p4 opened -c 999`) do @p4 diff %F

To do this in a batch file you need to use %%F instead of just %F.

Note that some of the solution above will work under Windows if you have installed a unix-like utilities package such as cygwin or unixutils, but this one-liner has no external dependencies.

爱已欠费 2024-08-02 09:12:46

上面回答了您的问题,但是,如果将tile读取为比较更改列表上的目录,则可以用以下内容回答:

p4 filelog ... | awk '
BEGIN {FS="[ /]";tc=999}
/^\/\// {fn=$NF;o=1;if (system("test -w " fn)) h=0; else h=""}
/^\.\.\.\ \#/ {if (h==0) h=$2;
  if ($4<=tc && o==1) {print "p4 diff -db -dw " fn h " " fn $2 " ;#"  $4;o=0}}' \
| sh

这将根据更改列表999将目录中的所有文件进行比较,如果它有,则使用“有”版本进行检查,否则它使用最新版本。

这是用 GNU Awk 3.1.3 测试的

The above answers your question but, if tile is read as diffing a directory on a change list it can be answered with the following:

p4 filelog ... | awk '
BEGIN {FS="[ /]";tc=999}
/^\/\// {fn=$NF;o=1;if (system("test -w " fn)) h=0; else h=""}
/^\.\.\.\ \#/ {if (h==0) h=$2;
  if ($4<=tc && o==1) {print "p4 diff -db -dw " fn h " " fn $2 " ;#"  $4;o=0}}' \
| sh

This will diff all the files in the directory against the changelist 999 it uses the "have" version if it has be checked out otherwise it uses the latest version.

this was tested with GNU Awk 3.1.3

电影里的梦 2024-08-02 09:12:46

对于未搁置的更改(尚未在软件仓库中的更改)

p4 opened -c 999 | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | bash

对于搁置的更改(在软件仓库中的更改(p4 shelve -c 999)

p4 describe -S -du3 -O 999

For Unshelved Changes( Changes still not in depot)

p4 opened -c 999 | awk 'BEGIN { FS = "#" } // { print "p4 diff " $1 }' | bash

For Shelved Changes( Changes that in depot ( p4 shelve -c 999)

p4 describe -S -du3 -O 999
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文