Mercurial - 使用类似于货架的队列?

发布于 2024-12-12 11:45:31 字数 831 浏览 0 评论 0原文

我最近开始使用 MQ,因为我喜欢处理独立补丁并在不影响存储库的情况下提交的想法,直到变更集足够完善为止。在此之前,我曾经使用过 Mercurial 的书架扩展,但发现它有点不稳定。我仍在 MQ 中尝试弄清楚如何使补丁彼此分离,并以不特定的顺序以及跨不同的分支应用它们。这是我的正常流程 -

1. 开始开发新补丁:

hg qnew fix-bug-1234 -m "fix bug 1234"
# do some work
hg qrefresh

2. 获取要处理的新功能/错误:

hg qpop fix-bug-1234
hg qnew some-feature -m "implement feature X"
# some work on feature X (perhaps in a different branch)
hg qrefresh

3. 在此时,我想重新开始修复错误,并把功能工作放在一边。我认为这很简单:

hg qpop some-feature
hg qpush fix-bug-1234
# wrap up bug fix
hg qfinish fix-bug-1234
# get back to work on feature

但是,MQ 似乎总是使用该系列中创建的最新补丁,并且无论我使用的 qpop/qpush 命令如何都应用它。我应该注意到,我处理的文件也是完全独立的(尽管它们有时可能是相同的)。

我在这里错过了什么吗?我应该为此使用 hg qqueue 吗?谢谢。

I've recently started working with MQ as I like the idea of working on isolated patches and committing without affecting the repo until the changeset is refined enough. Before that, I used to work with Mercurial's shelves extension, but found it a bit unstable. What I'm still trying to figure out in MQ is how to keep patches separate from each other and apply them in no particular order, and across different branches. Here's my normal flow -

1. Start working on a new patch:

hg qnew fix-bug-1234 -m "fix bug 1234"
# do some work
hg qrefresh

2. Get a new feature/bug to work on:

hg qpop fix-bug-1234
hg qnew some-feature -m "implement feature X"
# some work on feature X (perhaps in a different branch)
hg qrefresh

3. At this point, I'd like to get back to working on bugfix, and put aside the feature work. I thought it's as simple as:

hg qpop some-feature
hg qpush fix-bug-1234
# wrap up bug fix
hg qfinish fix-bug-1234
# get back to work on feature

However, MQ seems to always use the latest patch created in the series, and apply it regardless of the qpop/qpush command I'm using. I should note that the files I work on are completely separate as well (though they can sometimes be the same).

Am I missing something here? Should I be using hg qqueue for this? Thanks.

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

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

发布评论

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

评论(3

×纯※雪 2024-12-19 11:45:31

您可以使用守卫。它们允许您维护补丁的顺序,而无需重新排列您的系列文件,并有选择地仅应用补丁的子集,仍然以堆栈排序的方式。

您的情况的一个例子是:

hg qnew bugfix
# ..hack hack..
hg qrefresh
# want to switch over to working on some feature now
hg qpop
hg qnew feature
# ..hack hack..
hg qrefresh

此时,您处于这样的情况:补丁 feature 位于堆栈中的 bugfix 之前。现在,您可以使用守卫来选择其中之一,并在两者之间切换:

hg qpop -a
hg qguard feature +featureguard
hg qguard bugfix +bugfixguard

如果您想使用 feature

hg qselect featureguard
hg qpush
applying feature
now at: feature

如果您想使用 bugfix

hg qpop -a
hg qselect bugfixguard
hg qpush
applying bugfix
now at: bugfix

请注意由于您选择了正向防护 bugfixguard,MQ 跳过了功能(因为它的正向防护与所选的不同)并应用了改为补丁 bugfix (这确实匹配选定的后卫)。

使用防护时,一些有用的工具是 hg qseries -v,对于受防护的未应用补丁,它将显示 G 而不是通常的 U ,和 hg qselect -l ,它将显示与每个补丁关联的防护。

You could use guards. They allow you to maintain an ordering of patches without rearranging your series file, and selectively apply only a subset of patches, still in a stack-ordered fashion.

An example in your case would be:

hg qnew bugfix
# ..hack hack..
hg qrefresh
# want to switch over to working on some feature now
hg qpop
hg qnew feature
# ..hack hack..
hg qrefresh

At this point, you're in a situation where patch feature comes before bugfix in your stack. Now you can use guards to select one or the other, and switch between the two:

hg qpop -a
hg qguard feature +featureguard
hg qguard bugfix +bugfixguard

If you want to work on feature:

hg qselect featureguard
hg qpush
applying feature
now at: feature

If you want to work on bugfix:

hg qpop -a
hg qselect bugfixguard
hg qpush
applying bugfix
now at: bugfix

Note that since you selected the positive guard bugfixguard, MQ leap-frogged over feature (because it's positive guard was different than the one selected) and applied the patch bugfix instead (which did match the selected guard).

Some useful tools when working with guards are hg qseries -v, which will display a G instead of the usual U for a guarded, unapplied patch, and hg qselect -l which will display the guards associated with each patch.

因为看清所以看轻 2024-12-19 11:45:31
  1. 执行 hg qpop -a 从堆栈中删除所有补丁
  2. 执行 hg qpush --move some-patch 以应用“some-patch”,而不应用之前可能存在的任何其他补丁它在补丁堆栈中
  1. Execute hg qpop -a to remove all patches from the stack
  2. Execute hg qpush --move some-patch to apply "some-patch" without applying whatever other patches may be before it in the patch stack
掌心的温暖 2024-12-19 11:45:31

不,你没有错过任何东西。 mq 扩展确实做出了一个非常强有力的假设,即补丁队列是线性的。如果您要创建多补丁功能/修复,那么 qqueue 就可以了……但是如果您的功能/修复只是单个补丁,并且您希望能够应用一个补丁而不应用其他补丁,重新排列 .hg/patches/series (它存储补丁的应用顺序)可能会更容易。

我这样做(和手动编辑补丁)足够多,以至于我有一个 shell 别名:

alias viq='vim $(hg root)/.hg/patches/series'

或者,如果您不介意同时应用多个补丁,您可以使用 qgoto:

$ hg qser
0 U bug-1234
1 U feature-4321
$ hg qgoto feature-4321
$ hg qser
0 A bug-1234
1 A feature-4321

No, you aren't missing anything. The mq extension does make a pretty strong assumption that patch queues are linear. If you're going to be creating multi-patch features/fixes then qqueue would work… But if your features/fixes are just single patches and you want to be able to apply one with out applying the others, it might be easier to just re-arrange .hg/patches/series (which stores the order that patches will be applied).

I do this (and hand-editing patches) enough that I've got a shell alias:

alias viq='vim $(hg root)/.hg/patches/series'

Alternately, if you don't mind applying multiple patches at the same time, you could use qgoto:

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