转换 Mercurial 存储库时重命名标签

发布于 2024-12-11 08:12:14 字数 514 浏览 0 评论 0原文

我有一个 Mercurial 存储库,并且只需要新 Mercurial 存储库中其内容的子集。我知道如何使用 转换扩展 和文件映射文件来执行此操作。

然而,我也喜欢过滤标签,即只保留一个特定于我想要包含的文件的标签。我将能够命名所有这些标签,并且还想重命名它们。换句话说,我还需要标签图功能。

我知道我可以排除 .hgtags ,然后手动添加所有标签或如何重命名标签,但我实际上喜欢保留原始标记日期和修订版本,因此转换后的存储库看起来“真实”。

有什么想法如何做到这一点?我也不介意编写一些 Python 代码。

I have a Mercurial repository and want only a subset from its content in a new Mercurial repository. I know how to do this using the Convert Extension with a filemap file.

However, I also like to filter the tags, i.e. only keep one specific to the files I like to include. I'm would be able to name all these tags and would also like to rename them. In other words I would need a tagmap feature as well.

I'm aware I just could exclude .hgtags and then add all tags manually or how to rename tags, but I actually like to keep the original tagging dates and revisions, so the converted repository looks "authentic".

Any ideas how to do this? I wouldn't mind writing some Python code as well.

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

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

发布评论

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

评论(1

赠意 2024-12-18 08:12:14

正如您所发现的,这个功能现在还不存在。编写它将是一个有趣的小练习:-) 您应该从 hg 接收器的源开始并更改 _rewritetags 函数。它解析data(当前正在转换的变更集的.hgtags文件的内容)并重写变更集哈希值以匹配新哈希值。

这是您重写或排除标签的机会!我像这样修改了文件,以排除 2.0 版本以下的标签,并稍微重写它们:

def _rewritetags(self, source, revmap, data):
    def keep(tag):
        try:
            version = map(int, tag.split('.'))
            return version >= [2, 0]
        except ValueError:
            return False

    def rename(tag):
        return tag + "-partial"

    fp = cStringIO.StringIO()
    for line in data.splitlines():
        s = line.split(' ', 1)
        if len(s) != 2:
            continue
        if not keep(s[1]):
            continue
        revid = revmap.get(source.lookuprev(s[0]))
        if not revid:
            continue
        fp.write('%s %s\n' % (revid, rename(s[1])))
    return fp.getvalue()

为了测试,我还将 self.filemapmode 无条件更改为 True。否则,convert 将不会检测并过滤掉空提交。由于您已经使用了文件映射,所以应该没问题。

最后,删除由转换添加的额外“更新标签”变更集,您将再次拥有不错的历史记录。

This feature does not exist today, as you've found out. Writing it will be a fun little exercise :-) You should start with the source for the hg sink and change the _rewritetags function. It parses the data (the content of the .hgtags file for the changeset that's currently being converted) and rewrites the changeset hashes to match the new hashes.

This is your opportunity to rewrite or exclude tags! I modified the file like this to exclude tags below version 2.0 and to rewrite them slightly:

def _rewritetags(self, source, revmap, data):
    def keep(tag):
        try:
            version = map(int, tag.split('.'))
            return version >= [2, 0]
        except ValueError:
            return False

    def rename(tag):
        return tag + "-partial"

    fp = cStringIO.StringIO()
    for line in data.splitlines():
        s = line.split(' ', 1)
        if len(s) != 2:
            continue
        if not keep(s[1]):
            continue
        revid = revmap.get(source.lookuprev(s[0]))
        if not revid:
            continue
        fp.write('%s %s\n' % (revid, rename(s[1])))
    return fp.getvalue()

For testing, I also change self.filemapmode to True unconditionally. Otherwise, convert wont detect and filter out empty commits. Since you use a filemap already, you should be fine.

Finally, strip the extra "update tags" changeset added by convert and you'll have a nice history again.

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