Mercurial hook 用于设置标签名称策略

发布于 2024-11-25 12:41:58 字数 1479 浏览 1 评论 0原文

我编写(进程内)钩子以防止在本地添加 BAD 标记名称:

.hg/hgrc:

pretag.badtagname = python:.hg/hgcheck.py:localbadtag

.hg/hgcheck.py:

goodtag_re = r'(ver-\d+\.\d+\.\d+|tip)$'
def localbadtag(ui, repo, hooktype, node, **kwargs):
    assert(hooktype == 'pretag')
    re_ = re.compile(goodtag_re)
    if not re_.match(tag):
        ui.warn('Invalid tag name "%s".\n' % tag)
        ui.warn('Use one of tip, ver-xx.xx.xx\n')
        return True
    return False

How make this check for pretxnchangegroup 挂钩?

我尝试编写此代码:

def pushbadtag(ui, repo, hooktype, node, **kwargs):
    assert(hooktype == 'pretxnchangegroup')
    re_ = re.compile(goodtag_re)
    for rev in xrange(repo[node].rev(), len(repo)):
        ui.warn('rev: %d\n' % rev)
        for tag in repo[rev].tags():
            ui.warn('tag: ' + tag + '\n')
            if not re_.match(tag):
                ui.warn('Invalid tag name "%s" for rev: "%s".\n' % (tag, rev))
                ui.warn('Use one of tip, ver-xx.xx.xx\n')
                return True
    return False

但是当我(在启用上部 pretxnchangegroup 钩子的情况下推送到存储库时:

  $ hg tag gg
  $ hg push -f
pushing to /cygdrive/d/home/tmp/hg/good
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
rev: 35
tag: tip

您可以看到 rev.tags() 不返回 gg 标记!

I write (in-process) hook to prevent add BAD tag name locally:

.hg/hgrc:

pretag.badtagname = python:.hg/hgcheck.py:localbadtag

.hg/hgcheck.py:

goodtag_re = r'(ver-\d+\.\d+\.\d+|tip)

How make this check for pretxnchangegroup hook?

I try write this code:

def pushbadtag(ui, repo, hooktype, node, **kwargs):
    assert(hooktype == 'pretxnchangegroup')
    re_ = re.compile(goodtag_re)
    for rev in xrange(repo[node].rev(), len(repo)):
        ui.warn('rev: %d\n' % rev)
        for tag in repo[rev].tags():
            ui.warn('tag: ' + tag + '\n')
            if not re_.match(tag):
                ui.warn('Invalid tag name "%s" for rev: "%s".\n' % (tag, rev))
                ui.warn('Use one of tip, ver-xx.xx.xx\n')
                return True
    return False

but when I (push to repo with upper pretxnchangegroup hook enabled:

  $ hg tag gg
  $ hg push -f
pushing to /cygdrive/d/home/tmp/hg/good
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
rev: 35
tag: tip

you can see that rev.tags() do not return gg tag!

def localbadtag(ui, repo, hooktype, node, **kwargs): assert(hooktype == 'pretag') re_ = re.compile(goodtag_re) if not re_.match(tag): ui.warn('Invalid tag name "%s".\n' % tag) ui.warn('Use one of tip, ver-xx.xx.xx\n') return True return False

How make this check for pretxnchangegroup hook?

I try write this code:

but when I (push to repo with upper pretxnchangegroup hook enabled:

you can see that rev.tags() do not return gg tag!

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

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

发布评论

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

评论(1

山川志 2024-12-02 12:41:58

*解释问题:为什么 rev.tags() 不返回 gg 标签?

rev.tags() 不会返回 gg 标记,因为您推送的修订版上没有该标记。默认情况下,hg tag 将标记工作目录的父目录。新的变更集仅添加到 .hgtags 文件中。该标签已添加到两个存储库已有的变更集中。尝试进行一些更改并提交,然后对其进行标记,以便您推送 2 个更改集,其中一个将具有错误标记。

此外,由于标记的工作方式,您实际上不会知道哪个版本上有该标记。新的变更集可能会在更早的变更集上添加标签。也许查看某人是否推送了错误标签的更好方法是检查新变更集对 .hgtags 所做的任何添加。

如果您解析对 .hgtags 的更改,您将需要正确解析这些更改,以免从删除标签的条目中得到误报。您还需要收集不良标签的完整列表,而不是在第一次发现时就中断。您可能会发现一行将标签 gg 添加到变更集中,但后来有 2 行删除了它,这也应该删除您的发现并允许钩子成功通过,因为这意味着用户删除了他们的错误推送前标记。

*Interpreted question: Why doesn't rev.tags() return the gg tag?

rev.tags() doesn't return the gg tag because the revision you pushed doesn't have that tag on it. By default hg tag will tag the working directory's parent. The new changeset only adds to the .hgtags file. The tag was added to a changeset both repos already had. Try making some changes and commiting, then tagging that so that you're pushing 2 changesets and one will have the bad tag.

Also, because of the way tagging works, you won't actually know which revision has the tag on it. The new changsets could potentially have added a tag on a much earlier changeset. Perhaps a better way of seeing if somebody is pushing a bad tag is to examine any additions the new changesets make to .hgtags.

If you parse changes to .hgtags, you'll want to parse those changes correctly so that you don't get false positives from entries that are removing tags. You'll also want to gather a complete list of bad tags rather than breaking on the first find. You might find a line that adds tag gg to a changeset, but later are 2 lines that remove it, which should also remove your find and allow the hook to pass successfully since it means the user removed their bad tag before pushing.

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