简体   繁体   English

Mercurial Subrepos - 你如何创建它们以及它们如何工作?

[英]Mercurial Subrepos - How do you create them and how do they work?

Situation 情况

I have two .NET solutions ( Foo and Bar ) and a common library that contains ProjectA, ProjectB, and ProjectC. 我有两个.NET解决方案( FooBar )和一个包含ProjectA,ProjectB和ProjectC的公共库。 Foo and Bar reference one or more library projects, but the library projects are not located within the Foo and Bar Solution folders. FooBar引用一个或多个库项目,但库项目不在FooBar Solution文件夹中。

Directory structure: 目录结构:

-- My Documents*
   -- Development
      -- Libraries
         -- ProjectA
         -- ProjectB
         -- ProjectC
   -- Projects
      -- Foo
         -- Solution
            -- .hg
            -- .hgignore
            -- Foo { Project Folder }
            -- FooTests { Project Folder }
            -- Foo.sln { References ProjectA }
            -- Foo.suo
      -- Bar
         -- Solution
            -- .hg
            -- .hgignore
            -- Bar { Project Folder }
            -- BarTests { Project Folder }
            -- Bar.sln { References ProjectA and ProjectB }
            -- Bar.suo

*alas, I'm still using Windows XP... *唉,我还在使用Windows XP ......

Mercurial Subrepositories Mercurial子库

Goal - I want to set up subrepos so that I can store the source code for any referenced library projects in my Foo and Bar repositories. 目标 - 我想设置子目录,以便我可以在我的FooBar存储库中存储任何引用的库项目的源代码。

According to this page (which is literally the only documentation I can find on subrepos), setting up a subrepo requires executing the following commands from a DOS console window: 根据这个页面 (这是我在subrepos上可以找到的唯一文档),设置subrepo需要从DOS控制台窗口执行以下命令:

1| $ hg init main
2| $ cd main
3| $ hg init nested
4| $ echo test > nested/foo
5| $ hg -R nested add nested/foo
6| $ echo nested = nested > .hgsub
7| $ hg add .hgsub
8| $ ci -m "initial commit"

Questions 问题

  1. Can any or all of these steps be executed with TortoiseHG, as of version 0.9.2? 从版本0.9.2开始,可以使用TortoiseHG执行任何或所有这些步骤吗? If yes, how? 如果有,怎么样? I'm pretty sure lines 1-3 can, but I don't know about lines 4-7. 我很确定第1-3行可以,但我不知道第4-7行。 None of this seems to be documented in TortoiseHG. 在TortoiseHG中似乎没有记录这些内容。
  2. What does the above code do (a line-by-line explanation would be much appreciated). 上面的代码做了什么(逐行解释将非常感激)。 Here are some specific questions that came to mind as I was trying to decipher it: 以下是我试图破译时想到的一些具体问题:
    • What does > do? 做什么>做什么? I tried searching through the Mercurial docs for > , but didn't find anything. 我尝试在Mercurial文档中搜索> ,但没有找到任何内容。
    • In line 5, I don't understand what nested/foo is. 在第5行,我不明白nested/foo是什么。 Where did foo come from? foo来自哪里? What is foo ? 什么是foo A repository? 存储库? A folder? 一个文件夹?
    • Line 6 - this one completely baffles me. 第6行 - 这个完全让我困惑。
    • In line 7, I assume .hgsub is being added to main ? 在第7行,我假设.hgsub被添加到main Or is it being added to nested ? 或者它是否被添加到nested
  3. Let's say I get my subrepos set up, and my Bar repository is now up to revision 10. If I attempt to update my working directory to revision 7, will this cause my library folders ( My Documents/Development/Libraries/ProjectA and .../Libraries/ProjectB ) to update to whatever is stored in revision 7 as well? 假设我设置了subrepos,我的Bar存储库现在达到了修订版10.如果我尝试将我的工作目录更新到版本7,这将导致我的库文件夹( My Documents/Development/Libraries/ProjectA.../Libraries/ProjectB )更新到版本7中存储的内容?

Update 更新

I added an 8th line of code: ci -m "initial commit" . 我添加了第8行代码: ci -m "initial commit" This does two things: (1) adds a .hgsubstate file to the main repo and (2) commits all changes, including the new subrepo into the main repository (with message "initial commit"). 这样做有两件事:(1)将.hgsubstate文件添加到主仓库,以及(2)将所有更改提交到主存储库(包括消息“initial commit”)。 The purpose of the .hgsubstate file is to keep track of the state of all subrepos, so if you return to an earlier revision, it will grab the correct revision from all subrepos as well. .hgsubstate文件的目的是跟踪所有子目录的状态,因此如果返回到早期版本,它也将从所有子目录中获取正确的修订版本。


Update 2 - some instructions 更新2 - 一些说明

After further experimentation, I think I can now provide the steps to solve my original problem (using mostly Windows Explorer and TortoiseHG): 经过进一步的实验,我我现在可以提供解决原始问题的步骤(主要使用Windows资源管理器和TortoiseHG):

Creating a subrepo 创建子参数

  1. Libraries/ProjectA , Libraries/ProjectB , and the main repositories ( Projects/Foo/Solution and Projects/Bar/Solution ) must be separate repositories. Libraries/ProjectALibraries/ProjectB和主存储库( Projects/Foo/SolutionProjects/Bar/Solution )必须是单独的存储库。
  2. Open Projects/Foo/Solution . 打开Projects/Foo/Solution
  3. Clone from Libraries/ProjectA to Projects/Foo/Solution . Libraries/ProjectA克隆到Projects/Foo/Solution
  4. Add ProjectA to the Foo repository. ProjectA添加到Foo存储库。
  5. Use a text editor to create a file called .hgsub , containing the following: 使用文本编辑器创建名为.hgsub的文件,其中包含以下内容:

     ProjectA = ProjectA 
  6. Open a DOS console window and enter the following commands (see note below) : 打开DOS控制台窗口并输入以下命令(请参阅下面的注释)

     cd c:\\...\\Projects\\Foo\\Solution hg ci -m "Committing subrepo "ProjectA" 
  7. For Bar , the steps are basically the same, except the .hgsub file should contain entries for both projects, like this: 对于Bar ,步骤基本相同,除了.hgsub文件应包含两个项目的条目,如下所示:

     ProjectA = ProjectA ProjectB = ProjectB 

Note: starting with TortoiseHG 0.10 (which is slated for March), you will be able to use the HG Commit shell command to do this, but for now, you have to use the command line. 注意:从TortoiseHG 0.10开始(定于3月),您将能够使用HG Commit shell命令执行此操作,但是现在,您必须使用命令行。

Once this is all set up, it gets a little easier. 一旦完成设置,它就会变得容易一些。

Committing changes - to commit changes to Foo or Bar , you do a Synchronize/Pull operation for each subrepo to get the subrepos in sync with the latest revisions in the library project repositories. 提交更改 - 提交对FooBar更改,您可以为每个子项执行Synchronize/Pull操作,以使子项目与库项目存储库中的最新修订同步。 Then you again use the command line to commit the changes (until version 0.10, when you can just use TortoiseHG to commit). 然后再次使用命令行提交更改(直到版本0.10,当您可以使用TortoiseHG提交时)。

Updating working directory to an earlier revision - This seems to work pretty normally with TortoiseHG and doesn't seem to require use of any DOS commands. 将工作目录更新到早期版本 - 这似乎与TortoiseHG一起正常工作,似乎不需要使用任何DOS命令。 To actually work with the earlier revision in Visual Studio, you will need to do a Synchronize/Push operation to put the older version of the library projects back into the Libraries/ProjectX folder. 若要实际使用Visual Studio中的早期版本,您需要执行“ Synchronize/Push操作以将旧版本的库项目放回Libraries/ProjectX文件夹中。

As much as I like TortoiseHG for simple tasks, it's probably better to write batch files for frequently used subrepo operations (especially updating). 尽管我喜欢TortoiseHG的简单任务,但为常用的subrepo操作(尤其是更新)编写批处理文件可能更好。

Hope this helps someone in the future. 希望这可以帮助将来的某个人。 If you see any mistakes, please let me know (or feel free to edit yourself if you are able). 如果您发现任何错误,请告诉我(如果您能够,请随时编辑自己)。

You could probably try this stuff out and learn it more quickly than writing up your question took, but I'll bite. 你可能会尝试这些东西并比写下你的问题更快地学习它,但我会咬人。

Can any or all of these steps be executed with TortoiseHG, as of version 0.9.2? 从版本0.9.2开始,可以使用TortoiseHG执行任何或所有这些步骤吗? If yes, how? 如果有,怎么样?

TortiseHG doesn't yet put GUI wrappers around sub-repo creation, but TortiseHG has always done a great job of working with the command line. TortiseHG还没有围绕子仓库创建GUI包装,但TortiseHG在使用命令行方面做得非常出色。 Use the command line to create and them and you're good to go. 使用命令行创建它们,你很高兴。

What does the above code do (a line-by-line explanation would be much appreciated). 上面的代码做了什么(逐行解释将非常感激)。

hg init main  # creates the main repo
cd main # enter the main repo
hg init nested # create the nested. internal repo
echo test > nested/foo # put the word test into the file foo in the nested repo
hg -R nested add nested/foo # do an add in the nested repo of file foo
echo nested = nested > .hgsub # put the string "nested = nested" into a file (in main) named .hgsub
hg add .hgsub # add the file .hgsub into the main repo

Here are some specific questions that came to mind as I was trying to decipher it: What does > do? 以下是我试图破译时会想到的一些具体问题:做什么?

That has nothing to do with mercurial it's standard shell (unix and dos) for "put the result into a file named X" 这与mercurial无关,它的标准shell(unix和dos)用于“将结果放入名为X的文件”

In line 5, I don't understand what nested/foo is. 在第5行,我不明白嵌套/ foo是什么。 Where did foo come from? foo来自哪里? What is foo? 什么是foo? A repository? 存储库? A folder? 一个文件夹?

It's a file in the subrepo. 它是subrepo中的一个文件。 Foo is a traditional arbitrary name, and the arbitrary contents are the string "test" Foo是一个传统的任意名称,任意内容都是字符串“test”

Line 6 - this one completely baffles me. 第6行 - 这个完全让我困惑。

It's putting the contents in .hgsub necessary to say that nested is a nested repo named nested and located at nested. 它将内容放在.hgsub中,必须说嵌套是一个嵌套的repo,名为嵌套并位于嵌套状态。

In line 7, I assume .hgsub is being added to main? 在第7行,我假设.hgsub被添加到main? Or is it being added to nested? 或者它是否被添加到嵌套?

main 主要

Let's say I get my subrepos set up, and my Bar repository is now up to revision 10. If I attempt to update to revision 7, will this cause my library folders (My Documents/Development/Libraries/ProjectA and .../Libraries/ProjectB) to update to whatever is stored in revision 7 as well? 假设我设置了subrepos,我的Bar存储库现在达到了修订版10.如果我尝试更新到版本7,这会导致我的库文件夹(My Documents / Development / Libraries / ProjectA和... / Libraries) / ProjectB)更新到版本7中存储的内容? Given that Foo also refers to Libraries/ProjectA, this could get interesting! 鉴于Foo也提到了Libraries / ProjectA,这可能会变得有趣!

Revision numbers won't carry across, but you have control by editing the .hgsubstate file. 版本号不会传递,但您可以通过编辑.hgsubstate文件来控制。

Just a quick update, after the release of TortoiseHg 1.0. 在TortoiseHg 1.0发布后快速更新。

The subrepo support in THG 1 is good enough to do let you do example steps from Windows Explorer. THG 1中的subrepo支持足以让您从Windows资源管理器中执行示例步骤。 The only one I couldn't do from Explorer was step 6: 我从Explorer无法做到的唯一一步是第6步:

echo nested = nested > .hgsub

Windows explorer (in XP at least) reports a rename error "You must type a file name." Windows资源管理器(至少在XP中)报告重命名错误“您必须键入文件名”。 if you try to rename "New Text Document.txt" to ".hgsub". 如果您尝试将“New Text Document.txt”重命名为“.hgsub”。 *8') * 8' )

Edit: Incidentally, if you use both hg via TortoiseHg and the command line and you don't already have Microsofts "Command Here" PowerTool installed, I can highly recommend it. 编辑:顺便说一句,如果您通过TortoiseHg和命令行同时使用hg并且您还没有安装微软“Command Here” PowerTool ,我强烈推荐它。 It adds an "Open Command Window Here" context menu entry to every directory in Windows Explorer, making it very easy to open command windows any where you need them. 它在Windows资源管理器中为每个目录添加了一个“Open Command Window Here”上下文菜单条目,使您可以在任何需要的地方打开命令窗口。

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

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