Mercurial 可以做反向补丁吗?

发布于 2024-10-05 01:01:05 字数 678 浏览 7 评论 0原文

场景:我“继承”了一个保留在 Mercurial 下的程序,该程序仅适用于我的系统,并对签入的某些文件进行了特定调整。我不想想要签入这些调整。

我的最新的解决方案是创建一个包含这些调整的 Mercurial 补丁文件(hg diff > patchfile);当我需要检查我的更改时,我只需反向应用补丁、提交并重新应用补丁。 (如果我完全控制源代码,我只需将所有这些小调整移动到不受版本控制的单个配置文件中,将“示例”配置文件置于版本控制下)

不幸的是,似乎虽然GNU patch 命令支持 --reverse 标志,它不支持 hg 的多文件 diff 格式作为单个补丁文件(或者也许它支持,但我只是不支持)不知道它的开关吗?)。 OTOH,hg 有自己的 patch 命令可以应用 diff,但不支持任何类型的 reverse 标志。

所以我的问题是双重的:

  1. 在 Mercurial 中应该如何完成?当然,坚持“调整补丁”并不是处理这种情况的唯一方法。也许 Mercurial 有一个插件或内置的东西来处理这种临时的、不可提交的更改。
  2. 除了应该如何完成事情之外,还有什么方法可以将这样的 Mercurial diff 补丁反向应用到像这样的 Mercurial 存储库中?在其他情况下,此类功能也很有用。

Scenario: I've "inherited" a program, kept under Mercurial, that only works on my system with specific tweaks to certain files that are checked in. I do not want to check these tweaks in.

My most recent solution to this is to create a mercurial patch file (hg diff > patchfile) containing these tweaks; when I need to check in my changes, I'll just reverse-apply the patch, commit, and re-apply the patch. (If I had full control of the source, I'd just move all these little tweaks to a single configuration file that isn't under version control, putting a "sample" config file under version control)

Unfortunately, it seems that while the GNU patch command supports the --reverse flag, it does not support hg's multi-file diff format as a single patch file (or maybe it does, and I just don't know the switches for it?). OTOH, hg has its own patch command that can apply the diff, but that doesn't support any kind of reverse flag.

So my question is twofold:

  1. How should this be done in mercurial? Surely hanging on to a "tweak patch" isn't the only way to handle this situation. Maybe mercurial has a plugin or something built in for such temporary, uncommittable changes.
  2. Aside from how things should be done, is there any way to reverse-apply such a mercurial diff-patch to a mercurial repo like this? There are other situations where such functionality would be useful.

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

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

发布评论

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

评论(2

智商已欠费 2024-10-12 01:01:05

Mercurial 的 patch 命令(实际上是 import)不支持反向操作,但 hg diff 支持。对其使用 --reverse ,您将获得 Mercurial 可以应用的反向补丁。

但是,您所描述的是一个非常常见的供应商分支样式工作流程,mercurial 可以更好地支持使用 diff 和 patch 之外的功能。

具体来说,Mercurial Queues 完全符合您的要求想。

Mercurial's patch command (really import) doesn't support reverse, but hg diff does. Use --reverse on that and you'll have a reversed patch that Mercurial can apply.

However, what you're describing is a very common vendor-branch style workflow, which mercurial can better support using features other than diff and patch.

Specfically, Mercurial Queues does exactly what you want.

混浊又暗下来 2024-10-12 01:01:05

我发现当你有子存储库时 --reverse 方法不起作用。 IE

 hg diff --reverse -S

。如果它对任何人有帮助,这个几乎没有经过测试的脚本似乎可以完成这项工作:

#!/bin/bash

DIRS="$*"

if [[ $DIRS = "" ]]; then
    DIRS=$(echo *)
fi

for arg in $DIRS; do
    arg=$(echo $arg | sed 's/^\.\/*//g')
    repo=$(echo $arg | cut -d'/' -f-1)

    grep -q "^$repo = " .hgsub 2>/dev/null
    if [ $? -eq 0 ]; then
        if [ -d $repo ]; then
            cd $repo
            hg diff --reverse | sed -e "s;--- a;--- a/$repo;g" -e "s;+++ b;--- b/$repo;g"
            cd ..
        else
            echo Error, unknown repo $repo
        fi
    else
        hg diff $arg --reverse
    fi
done

I found --reverse approach did not work when you have sub repos. i.e.

 hg diff --reverse -S

. In case it helps anyone, this barely tested script seems to do the job:

#!/bin/bash

DIRS="$*"

if [[ $DIRS = "" ]]; then
    DIRS=$(echo *)
fi

for arg in $DIRS; do
    arg=$(echo $arg | sed 's/^\.\/*//g')
    repo=$(echo $arg | cut -d'/' -f-1)

    grep -q "^$repo = " .hgsub 2>/dev/null
    if [ $? -eq 0 ]; then
        if [ -d $repo ]; then
            cd $repo
            hg diff --reverse | sed -e "s;--- a;--- a/$repo;g" -e "s;+++ b;--- b/$repo;g"
            cd ..
        else
            echo Error, unknown repo $repo
        fi
    else
        hg diff $arg --reverse
    fi
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文