简体   繁体   English

如何将变更集从hg存储库导出到svn存储库

[英]How do I export changesets from hg repository to svn repository

I know there is hgsubversion extension for mercurial. 我知道mercurial有hgsubversion扩展名。 But before I knew how it works, I maintain two separate repositories, one is SVN repo and one is Hg repo. 但在我知道它是如何工作之前,我维护了两个独立的存储库,一个是SVN repo,一个是Hg repo。 I made most of my recent changes in the Hg repository and I need to "push" them to the svn repository. 我最近在Hg存储库中进行了大部分更改,我需要将它们“推送”到svn存储库。

The most straight forward way to do this is to get one revision from svn which is in sync with one revision from hg. 最直接的方法是从svn获得一个与hg中的一个修订版同步的修订版。

From there, I update to the next revision (from Hg), then commit it (to svn). 从那里,我更新到下一个版本(从Hg),然后提交它(到svn)。 Repeating these steps for many changesets is rather inconvenient. 对许多变更集重复这些步骤是相当不方便的。 Are there more convenient ways to do this? 有更方便的方法吗?

And if possible, solution that works in Windows OS. 如果可能,可以在Windows操作系统中使用的解决方案。

Regards, 问候,

Afriza Afriza

If you're talking about a linear series of changesets (no merges) you could employ a shell for loop 如果你在谈论线性系列的变更集(没有合并),你可以使用shell for循环

for therev in $(seq $(hg id -n -r .) $(hg id -n -r tip)) ; do
  hg update $therev
  svn commit -m "$(hg log --template '{desc}' -r .)"
done

That loops from the checkedout revision to the tip and commits each in turn preserving the commit message. 它从签出修订版循环到提示,并依次提交每个提交保留提交消息。 You probably need to do something fancy arround added/removes files. 你可能需要做一些花哨的arround添加/删除文件。

No there are not. 不是,没有。

You might have already seen this link. 您可能已经看过这个链接。 Currently interacting with svn repos is not officially supported yet. 目前尚未正式支持与svn repos交互。 I would not write a shell script to automate this. 我不会写一个shell脚本来自动执行此操作。 This may yield unexpected results screw up the repos (however take a look at following workflow) 这可能会产生意想不到的结果搞砸了回购(但请看下面的工作流程)

https://www.mercurial-scm.org/wiki/WorkingWithSubversion . https://www.mercurial-scm.org/wiki/WorkingWithSubversion

I currently do something similar to what you do. 我目前做的事与你的做法类似。

  1. checkout from svn repos save it under $HOME/svnhgrepos/project1 从svn repos结账保存在$ HOME / svnhgrepos / project1下
  2. goto $HOME/svnhgrepos/project1, hg init, hg commit 转到$ HOME / svnhgrepos / project1,hg init,hg commit
  3. change $HOME/svnhgrepos/project1/.hg/hgrc to automatically update on push 更改$ HOME / svnhgrepos / project1 / .hg / hgrc以在推送时自动更新
  4. clone $HOME/svnhgrepos/project1 to $HOME/code/project1-clone. 将$ HOME / svnhgrepos / project1克隆到$ HOME / code / project1-clone。
  5. goto $HOME/code/project1-clone, hg qinit (mercurial queues) 转到$ HOME / code / project1-clone,hg qinit(mercurial queues)
  6. do all the development, commit it (just one changeset per feature/bugfix) and push it to $HOME/svnhgrepos/project1 做所有的开发,提交它(每个功能/ bugfix只需一个变更集)并将其推送到$ HOME / svnhgrepos / project1
  7. Goto $HOME/svnhgrepos/project1, and perform 'svn ci' 转到$ HOME / svnhgrepos / project1,然后执行'svn ci'
  8. I have not done this step in my setup. 我没有在我的设置中执行此步骤。 Now you may write a hg hook, to automatically peform a 'hg update' and a 'svn commit' 现在你可以写一个hg钩子,自动执行'hg update'和'svn commit'
    \neg (i have not tested this) in $HOME/svnhgrepos/project1/.hg/hgrc [hooks] changegroup.hg-update = hg update >&2 changegroup.svn-commit = svn commit -m "hg log --template '{desc}' -r ."   \neg (i have not tested this) in $HOME/svnhgrepos/project1/.hg/hgrc [hooks] changegroup.hg-update = hg update >&2 changegroup.svn-commit = svn commit -m "hg log --template '{desc}' -r ." 

I took Ry4an's answer and added add/remove handling. 我接受了Ry4an的回答并添加了添加/删除处理。 Here it is: 这里是:

for therev in $(seq $(hg id -n -r .) $(hg id -n -r tip)) ; do
  hg update -C $therev
  svn st | perl -lne 'if (/^([?!])\s*(\S*)/) { my $command = ($1 eq "?") ? "add" : "rm"; my $fname=$2; $fname =~ s[\\][\/]g; system(qq(svn $command $fname));}'
  svn commit -m "$(hg log --template '{desc}' -r .)"
done

I found the -C was required when branches were involved. 我发现在涉及分支时需要-C。 This gets pretty ugly, though, since files get removed and re-added when switching between branches. 但是,这非常难看,因为文件在分支之间切换时会被删除并重新添加。 Also generally, renames info is lost, as well as the dates and identity of original commiter, of course. 通常,重命名信息也会丢失,当然还有原始提交者的日期和身份。

It looks like you could use hg convert to do what you want retroactively. 看起来你可以使用hg convert来追溯你想要的东西。 Enable the ConvertExtension and then just do hg convert -d svn file/path/to/mercurial/repo svn://repo/path/ though I've not tried it. 启用ConvertExtension,然后执行hg convert -d svn file/path/to/mercurial/repo svn://repo/path/虽然我没试过。

This might not be exactly what you want, but I think you might find this of use at some point. 这可能不是你想要的,但我想你可能会在某些时候发现它的使用。 And, others may as well... 而且,其他人也可能......

I work on Windows 7 OS, and I use both Mercurial (TortoiseHg) and Subversion (TortoiseSVN) for source control. 我在Windows 7操作系统上工作,我使用Mercurial(TortoiseHg)和Subversion(TortoiseSVN)进行源代码控制。 Why? 为什么? Well, what we have found, on our very small team of about 8 people, is that Mercurial is very convenient to use as a "personal" safety net, but is very confusing to some of our folks (eg, the FPGA engineers working in Verilog). 好吧,我们在约8人的小团队中发现,Mercurial非常方便用作“个人”安全网,但对我们的一些人来说非常困惑(例如,工作的FPGA工程师Verilog的)。 The whole "push" and "pull" think with the requirement to merge a whole stack of other people's changes into yours was not welcomed with open arms. 整个“推动”和“拉动”认为需要将一大堆其他人的变化合并到你的中并不是张开双臂欢迎的。 It seemed burdensome, and in one case, an engineer lost all of her work due to misunderstanding some of the nuances of how Mercurial does these things. 这看起来很麻烦,在一个案例中,由于误解了Mercurial如何做这些事情的一些细微差别,工程师失去了所有的工作。 There was fortunately another copy (she's a smart engineer!) so all was not lost, but it demonstrated how Mercurial's operations could be confusing and difficult to predict, at least for some people. 幸运的是,另一个副本(她是一个聪明的工程师!)所以一切都没有丢失,但它证明了Mercurial的操作如何令人困惑和难以预测,至少对某些人来说如此。

Mercurial's strength (IMO) is the ease with which you can switch between various development branches, and with the TortoiseHg tool, visualize the version tree and pick what you want to work on. Mercurial的优势(IMO)是您可以轻松地在各种开发分支之间切换,并使用TortoiseHg工具,可视化版本树并选择您想要处理的内容。 You can very easily (and quickly!) save your work, grab another branch or start a new one, to do some experiments or pursue an alternative approach. 您可以非常轻松(并且快速!)保存您的工作,抓住另一个分支或开始新的分支,进行一些实验或寻求替代方法。 As a convenient personal safety net and branch-switching workbench tool, it is superb. 作为一个方便的个人安全网和分支切换工作台工具,它是一流的。 I use it all the time as I'm developing and testing my code. 我一直在使用它,因为我正在开发和测试我的代码。

Subversion, on the other hand, makes a very easy to use "team" server. 另一方面,Subversion是一个非常容易使用的“团队”服务器。 People find it easy to understand how it works. 人们发现它很容易理解它是如何工作的。 Tagging and branching are not as intuitive, but we don't do this very often. 标记和分支不是那么直观,但我们不经常这样做。 Updates, merges, and checkins seem more intuitive and easier to manage. 更新,合并和签入似乎更直观,更易于管理。

It turns out, you can actually manage a single working copy using BOTH Mercurial and Subversion -- simultaneously! 事实证明,你可以同时使用BOTH Mercurial和Subversion管理一个工作副本! You can either checkout from SVN, then use Mercurial to "create repository here", or do it the other way around. 你可以从SVN结帐,然后使用Mercurial“在这里创建存储库”,或者反过来做。 You have to edit the ignore settings of SVN to ignore all the .hgxxxx files in your working copy folder, and have Mercurial ignore the .svn directory. 您必须编辑SVN的忽略设置以忽略工作副本文件夹中的所有.hgxxxx文件,并让Mercurial忽略.svn目录。 Once you've done that, the command line or shell extension tools for either system continue to work just as they have, and you are now managing your code in two different repositories! 完成后,任一系统的命令行或shell扩展工具都会继续正常工作,您现在可以在两个不同的存储库中管理代码!

I was skeptical at first, but I really wanted the convenience of day to day Mercurial, with the central-server compliance of Subversion, which is what our team has chosen for the shared code repository. 起初我对此持怀疑态度,但我真的想要日常Mercurial的便利性,以及Subversion的中央服务器合规性,这是我们的团队为共享代码库选择的。 This way of working gives you the best of both worlds with no downsides that I have noticed so far. 这种工作方式为您提供了两个世界中最好的,没有任何缺点我到目前为止已经注意到了。

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

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