通过管道传递 subversion 修订版号以进行 diff

发布于 2024-12-28 18:30:15 字数 526 浏览 2 评论 0原文

好的,所以我可以运行这样的命令来获取在特定日期或日期范围内制作的修订号列表:

svn log -q -r{2012-01-25}:HEAD | grep '^r[0-9]' | cut -d\| -f1 | cut -b2-

这工作正常并给我一个像这样的列表

12345
12346
12347

现在,我想将这些修订号传递给 diff 命令,因此在修订号上手动运行简单的 svn diff 可以按预期工作,即

svn diff -c12345

但是,如果我尝试像这样将修订列表通过管道传输到 diff 命令,

svn log -q -r{2012-01-25}:HEAD | grep '^r[0-9]' | cut -d\| -f1 | cut -b2- | xargs svn diff -c

它会返回一个错误,指出未找到节点 - 在我看来,我正在传递论点错误。

OK, so I can run a command like this to get a list of revision numbers made on a certain date or date range:

svn log -q -r{2012-01-25}:HEAD | grep '^r[0-9]' | cut -d\| -f1 | cut -b2-

This works fine and gives me a list like this

12345
12346
12347

Now, I would like to pass these revision numbers to the diff command, so running a simple svn diff on a revision number manually works as expected i.e.

svn diff -c12345

But, if I attempt to pipe the revision list to the diff command like this

svn log -q -r{2012-01-25}:HEAD | grep '^r[0-9]' | cut -d\| -f1 | cut -b2- | xargs svn diff -c

it returns an error that the node was not found - looks to me like I am passing the arguments wrong.

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

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

发布评论

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

评论(2

指尖上的星空 2025-01-04 18:30:15

看起来,在管道的最后一部分,xargs 正在尝试执行:

svn diff -c 12345 12346 12347

当它应该尝试时:

svn diff -c 12345
svn diff -c 12346
svn diff -c 12347

因为 -c 选项只接受一个参数。

要解决此问题,请尝试将 xargs 替换为 xargs -n1

It looks like, in the last part of the pipe, xargs is trying to execute:

svn diff -c 12345 12346 12347

when it should try:

svn diff -c 12345
svn diff -c 12346
svn diff -c 12347

because the -c option only accepts one argument.

To fix that, try to replace xargs with xargs -n1.

胡大本事 2025-01-04 18:30:15

问题是 123451234612347 中的每一个都作为单独的参数传递;您需要将其与 -c 连接成单个参数。

假设您使用的是 xargs 的 GNU findutils 版本,则可以使用 -I 选项。不使用 svn 的示例:

$ printf "12345\n12346\n12347\n" | xargs -n 1 -I{} echo svn diff -c{}
svn diff -c12345
svn diff -c12346
svn diff -c12347

请注意,这将为每个版本号调用一次 svn diff。您的命令使用多个版本号调用 svn 一次。如果您想为多个版本号调用一次 svn:

svn diff -c12345 12346 12347

那么就需要不同的解决方案。

编辑:

阅读其他答案和 svn 文档,看起来您可以在 -c 之后有一个空格,因此 svn diff -c12345或 svn diff -c 12345 有效。在这种情况下,只需使用 -n 1 就可以解决问题。

The problem is that each of 12345, 12346, 12347 is passed as a separate argument; you need it to be joined with the -c into a single argument.

Assuming you're using the GNU findutils version of xargs, you can use the -I option. An example not using svn:

$ printf "12345\n12346\n12347\n" | xargs -n 1 -I{} echo svn diff -c{}
svn diff -c12345
svn diff -c12346
svn diff -c12347

Note that this invokes svn diff once for each version number. Your command invokes svn once with multiple version numbers. If you want to invoke svn once for multiple version numbers:

svn diff -c12345 12346 12347

then a different solution will be necessary.

EDIT :

Reading the other answer and the svn documentation, it looks like you can have a space after -c, so either svn diff -c12345 or svn diff -c 12345 is valid. In that case, just using -n 1 should do the trick.

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