【问题标题】:mercurial (hg) equivalent of git describe --contains <commit> to find tag that has <commit> as an ancestor in its historygit describe --contains <commit> 的 mercurial (hg) 等效项以查找在其历史中具有 <commit> 作为祖先的标签
【发布时间】:2022-08-19 20:33:56
【问题描述】:

我正在尝试使用 mercurial 为我提供包含特定提交的标签,就像git describe --contains 一样,如documentation 中所述:

--contains

Instead of finding the tag that predates the commit, find
the tag that comes after the commit, and thus contains it.
Automatically implies --tags.

hg log -r &lt;rev&gt; --template \'{latesttag}\\n\' 不符合要求,因为它返回可从 &lt;rev&gt; 访问的最新标签。

是否有一种简单的方法来查找包含 rev 的标签?

    标签: mercurial mercurial-revsets


    【解决方案1】:

    mercurial 有一种简单的方法来查找包含 rev 的标签吗?

    是的,搜索关键字是“revsets”

    虽然您(和 git-doc)的定义相当肮脏(哪个可能的集合中的标签),我将展示案例“第一个标签包括变更集 CSID”的分步解决方案

    试验场

    条件

    为了满足任务的大部分要求,对于这样一个标签列表(完整标签的一部分),我决定使用 2084 和 2089 之间的变更集,并希望有 1.0.0b1 作为结果

    hg-git> hg tags
    tip                             2167:b963d11cc1c8
    1.0.0                           2137:6f22e3887d82
    1.0.0b2.post1                   2106:ff6274c7c614
    1.0.0b2                         2104:d31a72cf70bd
    1.0.0b1                         2089:311e9a57959e
    0.10.4                          2084:bc5339fcea1e
    ...
    

    我们的范围

    hg-git> hg log -r 2084:2089 -T compact
    2084[0.10.4]:2082   bc5339fcea1e   2022-01-26 18:40 +0100   danchr
      NEWS: 0.10.4 release
    
    2085   da261c503c13   2022-01-26 18:40 +0100   danchr
      Added tag 0.10.4 for changeset bc5339fcea1e
    
    2086   ec721ee0f93b   2022-01-26 18:40 +0100   danchr
      Added signature for changeset bc5339fcea1e
    
    2087:2083,2086   729775377f6b   2022-01-26 18:49 +0100   danchr
      merge with branch 0.10.x
    
    2088   08347725306b   2021-12-24 13:23 +0100   danchr
      versioning: create branch 1.0.x
    
    2089[1.0.0b1]   311e9a57959e   2021-12-24 13:21 +0100   danchr
      NEWS: 1.0b1 release
    

    我将使用 2086 作为 CSID

    解决方案

    得到所有的后代CSID 的

    hg log -r "descendants(2086)" 或者它可以更短 hg log -r 2086:,但我希望从一开始就进行修订(由于结果的明显性而错过了输出)

    缩短输出,只留下标签

    hg-git> hg log -r "descendants(2086) and tag()" -T compact
    2089[1.0.0b1]   311e9a57959e   2021-12-24 13:21 +0100   danchr
      NEWS: 1.0b1 release
    
    2104[1.0.0b2]   d31a72cf70bd   2022-03-10 15:58 +0100   danchr
      NEWS: 1.0b2 release
    
    2106[1.0.0b2.post1]   ff6274c7c614   2022-03-10 16:11 +0100   danchr
      Added signature for changeset d31a72cf70bd
    
    2137[1.0.0]   6f22e3887d82   2022-04-01 16:54 +0200   danchr
      NEWS: 1.0.0 release!
    

    缩短输出,只留下第一个标签

    hg-git> hg log -r "first(descendants(2086) and tag())" -T compact
    2089[1.0.0b1]   311e9a57959e   2021-12-24 13:21 +0100   danchr
      NEWS: 1.0b1 release
    

    缩短输出,只留下需要的数据(changeset+tag+date f.e)

    hg-git> hg log -r "first(descendants(2086) and tag())" -T "{node|short}:{tags} {date|shortdate}\n"
    311e9a57959e:1.0.0b1 2021-12-24
    

    奖金游戏

    缩短命令以便以后重用:

    revset(-r 选项的数据)移至 repo-hgrc 或全局配置(hg help revsets)的[revsetalias] 部分(hg help revsets),并添加了一个参数cs 以用于任何 CSID

      [revsetalias]
      ft(cs) = first(descendants(cs) and tag())
    

    输出模板(-T 选项的数据)移至...的[templates] (hg help templating) 部分

      [templates]
      tagid = "{node|short}:{tags} {date|shortdate}\n"
    

    最后的命令变成了类似的东西

    hg log -r "ft(ec721ee0f93b)" -T tagid
    

    附言使用 TortoiseHG,您可以轻松调试和可视化您的 revsets,使用过滤器工具栏手动定义 revsets 和|或 GUI 的可视化查询编辑器

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 2019-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 2021-05-06
      相关资源
      最近更新 更多