简体   繁体   English

如何在将存储库从Mercurial转换为Subversion时保留修订时间戳?

[英]How to keep revision timestamps while converting a repository from Mercurial to Subversion?

Because of work policies, I'm forced to use Subversion. 由于工作策略,我被迫使用Subversion。 Currently I've developed some code using Mercurial, and I have to convert this repository to a new Subversion repository. 目前我已经使用Mercurial开发了一些代码,我必须将此存储库转换为新的Subversion存储库。 The current Mercurial repository also contains legacy code parts that I copied from another SVN repository (a HW driver), and this code contains keywords (like $Id: ...$ ) that were expanded while I copied the code. 当前的Mercurial存储库还包含我从另一个SVN存储库(一个HW驱动程序)复制的遗留代码部分,并且此代码包含在复制代码时扩展的关键字(如$Id: ...$ )。

My current approach to do the conversion is: 我目前进行转换的方法是:

hg convert --dest-type svn repository.hg repository.svn

This works, unfortunately it does not preserve the timestamps of Mercurial revisions. 遗憾的是,它不能保留Mercurial修订版的时间戳。 Additionally, it expands tags in some legacy code parts where someone wrote $Id: ...$ stuff. 此外,它扩展了一些遗留代码部分中的标签,其中有人写了$Id: ...$ stuff。

The questions: 问题:

  1. How can I export to Subversion, keeping the timestamps of revisions. 如何导出到Subversion,保留修订的时间戳。
  2. How can I convert without expanding $Id:$ style keywords, or, even better, delete the offending lines while converting. 如何在不扩展$ Id:$ style关键字的情况下进行转换,或者更好的是,在转换时删除有问题的行。 Is this possible, or do I have to modify the history of the Mercurial dump before converting to make sure no keywords are present? 这是可能的,还是我必须在转换之前修改Mercurial转储的历史记录以确保没有关键字存在?

Sorry if this question has been answered already, I've searched intensely with Google and on here, but I cannot find an answer for this problem. 很抱歉,如果这个问题已经得到解答,我已经在谷歌和这里进行了强烈的搜索,但我找不到这个问题的答案。 Especially the timestamp problem must be something that others have already run into. 特别是时间戳问题必须是其他人已经遇到的问题。

Cheers, H. 干杯,H

EDIT: I've since created a script that extracts timestamps from a Mercurial export file and updates a Subversion dumpfile, which is nothing more but a kludge, but it works. 编辑:我已经创建了一个脚本,从Mercurial导出文件中提取时间戳并更新Subversion转储文件,这只是一个kludge,但它的工作原理。 The $Id: problem is still unsolved, unfortunately. 遗憾的是, $Id:问题仍未得到解决。

It is a tricky issue. 这是一个棘手的问题。 Why aproaching the solution differently: 为什么不同地解决方案:

https://bitbucket.org/durin42/hgsubversion/wiki/Home https://bitbucket.org/durin42/hgsubversion/wiki/Home

This is an extension to Mercurial which allows you to access it as a SVN Client, could it work for you? 这是Mercurial的扩展,它允许您作为SVN客户端访问它,它可以为您工作吗?

I want to re-suggest hgsubversion as a solution. 我想重新建议将hgsubversion作为解决方案。 In the normal case, it is used to access a Subversion repository using hg , but you can use it to convert a Mercurial repository to Subversion as well if you are not afraid to work on your history of changesets. 在正常情况下,它用于使用hg访问Subversion存储库,但是如果您不害怕处理变更集的历史记录,则可以使用它将Mercurial存储库转换为Subversion。 (If you know how to work with changesets, you have quite a bit of control over the process.) (如果您知道如何使用变更集,则可以对该过程进行相当多的控制。)

Essentially, you have to do the following steps: 基本上,您必须执行以下步骤:

  1. Make your Mercurial history linear (this is required for Subversion); 使Mercurial历史呈线性(这是Subversion所必需的); you can use the Collapse extension to collapse any non-linear area of the history into a single changeset 您可以使用“ 折叠”扩展将历史记录的任何非线性区域折叠为单个变更集
  2. Create a Subversion repository or directory and hg pull this SVN path (using hgsubversion) into your Mercurial repository. 创建一个Subversion存储库或目录, hg pull此SVN路径(使用hgsubversion) hg pull入Mercurial存储库。 The Subversion path may have to be non-empty for this, but as long as there is no overlap with the files in the Mercurial repository, this should be fine. Subversion路径可能必须非空,但只要Mercurial存储库中的文件没有重叠,这应该没问题。
  3. Rebase all of the changesets from the Mercurial history on top of the head of the Subversion history. 将Mercurial历史记录中的所有变更集重新基于Subversion历史记录。 This is done using the Rebase extension . 这是使用Rebase扩展完成的。 If there is no overlap, this should be an automatic operation. 如果没有重叠,则应该是自动操作。
  4. Use hg push to send the result back to Subversion. 使用hg push将结果发送回Subversion。 The linear set of changes that descend from the former head of the Subversion repository will be added to the Subversion path. 从Subversion存储库的前端开始的线性变化集将添加到Subversion路径中。

Check this blog article for some concrete command-line commands that you can use. 查看此博客文章,了解可以使用的一些具体命令行命令。

I tried the keyword substitution once on SVN and I had to add a svn:keywords property to the working folder indicating which keyword(s) to be substituted. 我在SVN上尝试了一次关键字替换 ,我不得不在工作文件夹中添加一个svn:keywords属性,指明要替换的关键字。 So, deleting this property should do the job. 因此,删除此属性应该可以完成这项工作。

This article on Stack Overflow is possibly related to this question. 关于Stack Overflow的这篇文章可能与这个问题有关。

As far as I understand your problem now: You have a Hg repository which was once converted from SVN, where keyword expansion had been used. 据我所知,你现在的问题是:你有一个Hg存储库,它曾经从SVN转换过,其中使用了关键字扩展。 Now the expanded keywords remain unchanged in the Hg repo. 现在,扩展的关键字在Hg仓库中保持不变。 You now want to strip those keywords (or just their expanded values) from the Hg history, preserving author, date/time, commit message and of course changed files. 您现在想要从Hg历史记录中删除这些关键字(或只是它们的扩展值),保留作者,日期/时间,提交消息,当然还有更改的文件。

This is just an idea, I have never done this in practical, but ... Speaking just of mercurial, I think it's possible to do this by a combination of usual mercurial behaviour, just for one branch and without tags and other branches: 这只是一个想法,我从来没有在实践中做到这一点,但是......只是说到mercurial,我认为可以通过常见的mercurial行为,只为一个分支和没有标签和其他分支的组合来做到这一点:

  1. Clone the intended source repository 克隆预期的源存储库
  2. Prepare an empty Hg repository 准备一个空的Hg存储库
  3. Perform hg log > logfile.txt over the source repo on that branch you want to change 在要更改的分支上的源存储库上执行hg log > logfile.txt
  4. Parse the file getting a structured list of all necessary information like changeset number, user, date and summary, store this into a data structure that allows easy iteration 解析文件获取所有必要信息(如变更集编号,用户,日期和摘要)的结构化列表,将其存储到允许轻松迭代的数据结构中
  5. Iterate through the list (or directly use the log file) and ... 遍历列表(或直接使用日志文件)和...
    • delete all working files from the destination repo 从目标仓库中删除所有工作文件
    • export a changeset from the source repo to the working copy of the destination repo 将变更集从源存储库导出到目标存储库的工作副本
    • change anything in the working files you want to do 更改您要执行的工作文件中的任何内容
    • hg addremove
    • hg commit -m ... -d ... -u ...
  6. Repeat step 5 as often as necessary 根据需要经常重复步骤5

The drawback is that the changesets will get new hash values, so tags and bookmarks need to be updated. 缺点是更改集将获得新的哈希值,因此需要更新标记和书签。

If there are other branches that have to be migrated: 如果还有其他分支需要迁移:

  1. Update the destination repo to that branch's starting point 将目标仓库更新为该分支的起点
  2. and the source repo, too 和源回购也
  3. insert steps 3 to 6 from the above list here 从上面的列表中插入步骤3到6

Perhaps there is some more work to be done, but I think this could work. 也许还有一些工作要做,但我认为这可行。 As told before, I've never done this. 如前所述,我从未这样做过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM