将 subversion 存储库转换为 Mercurial 在提交日志中转换修订 ID

发布于 2024-10-12 06:52:50 字数 1388 浏览 3 评论 0原文

我正在将一个大型(包含大约 9000 个变更集)Subversion 存储库转换为 Mercurial。它与 Trac 问题跟踪系统相结合,因此提交日志有许多对其他修订 ID 以及票号的交叉引用。

我正在尝试 hgsubversion 和转换扩展名。两者似乎都适用于我们的存储库,但提交日志中引用的修订 ID 未转换。

(Trac 部分相当简单——我们只需扫描数据库并转换所有出现的修订 ID 引用即可。)

因此,我修改了转换扩展的源代码,如下所示:

(hg 中的mercurial_sink 类.py)

def _rewritedesc(self, desc, source, revmap):
    # Only for subversion source.
    # We assume that no future revision is mentioned in commit logs.
    rx_revision = re.compile(r'(r(\d+)|\[(\d+)\])') # it's actually defined in module header.
    def replacer(m):
        if m is None:
            return m.group(0)
        new_revid = revmap.get(source.source.revid(m.group(2) or m.group(3)))
        print 'converting commit log : %s -> [%s]' % (m.group(0), new_revid)
        if new_revid is None:
            return m.group(0)
        return '[%s]' % new_revid[:12]
    return rx_revision.sub(replacer, desc)

def putcommit(self, files, copies, parents, commit, source, revmap):
    ...
    text = self._rewritedesc(commit.desc, source, revmap)
    ...

它似乎有效,但问题是转换过程不会扫描变更集的提交顺序。有许多缺失的转换结果。

实际上,convert 扩展提供了多种排序选项,包括“sourcesort”,它按提交顺序处理变更集,但仅支持 Mercurial 源。 “datesort”似乎比“branchsort”以这种方式工作得更好,但没有我想要的那么好。

我调查了转换过程完成后是否可以修改提交日志(当时,我们有扩展生成的完整修订 ID 映射),但这是不可能的——有已知的黑客使用 mq 和 histedit 扩展,但它们更改了修订ID。

有没有人尝试过这样做或帮助我?

I'm converting a big (with about 9000 changesets) Subversion repository to Mercurial. It is coupled with Trac issue tracking system, so the commit logs have many cross-references to other revision IDs as well as ticket numbers.

I'm trying hgsubversion and convert extension. Both seems to work well with our repository, but the revision IDs referred in commit logs are not converted.

(The Trac part is rather simple -- we can just scan the database and convert all occurrences of revision ID reference.)

So, I modified the source code of convert extension like this:

(mercurial_sink class in hg.py)

def _rewritedesc(self, desc, source, revmap):
    # Only for subversion source.
    # We assume that no future revision is mentioned in commit logs.
    rx_revision = re.compile(r'(r(\d+)|\[(\d+)\])') # it's actually defined in module header.
    def replacer(m):
        if m is None:
            return m.group(0)
        new_revid = revmap.get(source.source.revid(m.group(2) or m.group(3)))
        print 'converting commit log : %s -> [%s]' % (m.group(0), new_revid)
        if new_revid is None:
            return m.group(0)
        return '[%s]' % new_revid[:12]
    return rx_revision.sub(replacer, desc)

def putcommit(self, files, copies, parents, commit, source, revmap):
    ...
    text = self._rewritedesc(commit.desc, source, revmap)
    ...

It seems to work, but the problem is that conversion process does not scan changesets in which order they are committed. There are many missing conversion results.

Actually, convert extension provides several sorting options including "sourcesort" which processes the changesets in the commit order, but it's supported only for mercurial sources. "datesort" seems to work better in this way than "branchsort", but not as good as I want.

I surveyed whether I can modify commit logs after conversion process is complete (at that time, we have a complete revision ID map generated by the extension), but it's impossible--there are known hacks using mq and histedit extension but they changes the reivision ID.

Is there any folk who tried to do this or help me?

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

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

发布评论

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

评论(1

帅冕 2024-10-19 06:52:50

进行两步转换怎么样?首先将存储库从 SVN 转换为 Mercurial。然后在新的 Hg 存储库上再次运行转换扩展以转换所有描述?那么您应该能够使用 sourcesort

How about doing a two-step conversion? First convert the repository to Mercurial from SVN. Then run the convert extension again on your new Hg repository to convert all the descriptions? You should be able to use sourcesort then.

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