【问题标题】:How do I make a revset alias for tags whose names follow a pattern?如何为名称遵循模式的标签创建 revset 别名?
【发布时间】:2015-06-17 21:01:52
【问题描述】:

在我的存储库中,我有version-1.2.3 形式的标签。我想创建一个 revset 别名 new(),这样调用:

hg log -r 'new(1.2.3, 1.2.4)'

...并扩展为:

hg log -r '::version-1.2.4 - ::version-1.2.3'  # What's new in 1.2.4?

当我尝试这样做时:

[revsetalias]
new($1, $2) = ::version-$2 - ::version-$1

...Mercurial 将其解释为从修订版 version 中减去修订版 $2(例如 1.2.3),这不是我的意图。

我也试过这个,使用## 连接运算符:

new($1, $2) = ::"version-" ## $2 - ::"version-" ## $1

然后hg log -r 'new(1.2.3, 1.2.4)' 给了我这个错误:

hg: parse error at 13: syntax error

我也尝试使用ancestors() 而不是:: 语法,但仍然出现语法错误。这可以吗?

【问题讨论】:

    标签: mercurial mercurial-revsets


    【解决方案1】:

    我测试了以下可行的方法:

    new($1, $2) = (::"version-" ## $2) - (::"version-" ## $1)
    

    供参考$1::$2不会给你同样的东西,它意味着$1$2之间的修订 我更喜欢的等效修订集是:

    new($1, $2) = only("version-" ## $2, "version-" ## $1)
    

    根据文档,它严格等同于您想要的:

    "only(set, [set])"
          Changesets that are ancestors of the first set that are not ancestors of
          any other head in the repo. If a second set is specified, the result is
          ancestors of the first set that are not ancestors of the second set
          (i.e. ::<set1> - ::<set2>).
    

    【讨论】:

    • $1::$2 不是严格形式的“修订之间”——它是 1 美元和 2 美元之间的 DAG——当它与 only() 不同时,我无法想象真正的用例。来自 $1 的远祖的悬空合并集?
    • 考虑相同基数的两个版本:pastebin.com/kBqniLt8 hg log -r "e2b7d1::aedc1a" 不返回任何内容 hg log -r "only(e2b7d1,aedc1a)" 返回 b 和 c跨度>
    • @LazyBadger:$1 不是 $2 的祖先。它们都是树干的分支。 $1::$2 不适合我
    • 好吧,好吧 - 你赢了。但我使用并测试了来自现实世界的真实存储库,而不是来自“...为犀牛”课程的教程中的用例,这些课程的工作流程脑部受损
    • @LazyBadger 这只是standard branching,每个版本都有一个单独的分支。
    【解决方案2】:

    旁注$1::$2 将更具可读性,并为您提供 DAG 的相同部分只有only() 提供正确的结果在所有情况下 strong>,根据@lc2817 回答中的讨论,DAG 可能会失败)

    我几乎成功地得到了答案,但在最后一步遇到了一些麻烦(并且不知道如何调试):在 [revsetalias] 中聚合所有

    前言

    因为参数是标签,而 tag() 谓词允许在参数中使用正则表达式 - 我将使用它们

    Revset tag("re:version\-") 显示所有标签,以“version-”开头

    使用硬编码数字作为字符串的修订集显示单个变更集

    hg log -r "tag('re:version\-1.7$')
    changeset:   2912:454a12f024f3
    

    (尾随$是必须的,否则都是1.7*标签)

    我在 revsetalias 中的最佳尝试是 tag('re:version\-\$1$') - 没有错误也没有输出:我无法获得完全扩展的命令来查看所有处理和替换并使用参数化的 revsetalias 检测我的错误

    HTH

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 1970-01-01
      • 2022-11-11
      • 2015-05-27
      • 1970-01-01
      • 2015-01-12
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多