当使用破折号定位标签时,Mercurial -r 选项无法按预期工作
Mercurial -r option not working as intended when targeting a tag with dashes
我注意到在构建脚本以自动执行发布过程时,mercurial 中的 -r 选项表现得有点意外。发布过程使用 hg archive -r 但行为与 hg update -r ..
相同
我制作了一个非常基本的 Mercurial 存储库来展示行为:
https://bitbucket.org/daang/mercurial-revision-problem-example
问题是,当您使用 -r 选项时,标签不存在,并用破折号 (-) 分隔数字,mercurial 会将修订更新为标签中的第一个数字。
因此,如果使用提供的存储库,我会这样做:
hg update -r 0-2-2 ( this tag does not exist)
Mercurial 会将存储库更新为初始提交(修订版 0)
如果我这样做:
hg update -r 1-2-2 ( this tag does not exist )
会更新到修订版1
hg update -r 5-2-2 ( this tag does not exist )
将更新到修订版 5
但是,如果我使用带点的标记约定,它将按预期工作,如果提供的标记不存在,它将抛出错误 'empty revision'
hg update -r 2.2.2 ( this will not work)
为什么 mercurial 的行为是这样的,当使用带有破折号 (1-0-0) 的标签约定时,如果标签不存在但带有点 (1.0.0.0),它只需要第一个数字并更新到该版本。 0) 找不到标签时失败(我认为这是正确的行为)?
当 Mercurial 无法将修订解释为标记、书签、分支、修订号(绝对或相对)或哈希,并且它不是特殊修订之一时 .
、tip
,或 null
(参见 hg help revisions
),它将尝试将其解析为 revset (hg help revsets
)。在 revset 表示法中,-
运算符实现集合差异,即左侧的修订,但右侧的修订除外。因此,例如,1-2-2
被解析为 (((1)-2)-2)
,这与修订版 1 相同。
您可以使用明确的 revset 语法来避免这种解释,例如:
hg update -r 'tag("1-2-2")'
您也可以引用修订描述以避免运算符的解释,例如:
hg update -r '"1-2-2"'
请注意,您需要两层引号,因为 shell 会去除外层。
我注意到在构建脚本以自动执行发布过程时,mercurial 中的 -r 选项表现得有点意外。发布过程使用 hg archive -r 但行为与 hg update -r ..
相同我制作了一个非常基本的 Mercurial 存储库来展示行为: https://bitbucket.org/daang/mercurial-revision-problem-example
问题是,当您使用 -r 选项时,标签不存在,并用破折号 (-) 分隔数字,mercurial 会将修订更新为标签中的第一个数字。
因此,如果使用提供的存储库,我会这样做:
hg update -r 0-2-2 ( this tag does not exist)
Mercurial 会将存储库更新为初始提交(修订版 0)
如果我这样做:
hg update -r 1-2-2 ( this tag does not exist )
会更新到修订版1
hg update -r 5-2-2 ( this tag does not exist )
将更新到修订版 5
但是,如果我使用带点的标记约定,它将按预期工作,如果提供的标记不存在,它将抛出错误 'empty revision'
hg update -r 2.2.2 ( this will not work)
为什么 mercurial 的行为是这样的,当使用带有破折号 (1-0-0) 的标签约定时,如果标签不存在但带有点 (1.0.0.0),它只需要第一个数字并更新到该版本。 0) 找不到标签时失败(我认为这是正确的行为)?
当 Mercurial 无法将修订解释为标记、书签、分支、修订号(绝对或相对)或哈希,并且它不是特殊修订之一时 .
、tip
,或 null
(参见 hg help revisions
),它将尝试将其解析为 revset (hg help revsets
)。在 revset 表示法中,-
运算符实现集合差异,即左侧的修订,但右侧的修订除外。因此,例如,1-2-2
被解析为 (((1)-2)-2)
,这与修订版 1 相同。
您可以使用明确的 revset 语法来避免这种解释,例如:
hg update -r 'tag("1-2-2")'
您也可以引用修订描述以避免运算符的解释,例如:
hg update -r '"1-2-2"'
请注意,您需要两层引号,因为 shell 会去除外层。