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

发布于 2024-08-18 08:28:52 字数 3955 浏览 3 评论 0原文

情况

我有两个 .NET 解决方案(FooBar)以及一个包含 ProjectA、ProjectB 和 ProjectC 的公共库。 FooBar 引用一个或多个库项目,但这些库项目不在 FooBar 内解决方案文件夹。

目录结构:

-- 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

*唉,我还在使用 Windows XP...

Mercurial Subrepositories

目标 - 我想设置子存​​储库,以便我可以将任何引用的库项目的源代码存储在我的 FooBar 存储库中。

根据此页面(这实际上是我在子存储库上可以找到的唯一文档),设置子存储库需要从 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"

问题

  1. 从版本 0.9.2 开始,可以使用 TortoiseHG 执行所有这些步骤吗?如果是,怎么办?我很确定第 1-3 行可以,但我不知道第 4-7 行。 TortoiseHG 中似乎没有记录这些内容。
  2. 上面的代码做了什么(逐行解释将不胜感激)。以下是我在尝试解读它时想到的一些具体问题:
    • > 的作用是什么?我尝试在 Mercurial 文档中搜索 >,但没有找到任何内容。
    • 在第 5 行中,我不明白 nested/foo 是什么。 foo 从哪里来?什么是foo?存储库?文件夹?
    • 第 6 行 - 这一条完全让我困惑。
    • 在第 7 行中,我假设 .hgsub 已添加到 main 中?或者它是否被添加到嵌套中?
  3. 假设我设置了子存储库,并且我的 Bar 存储库现在已达到修订版 10。如果我尝试将我的工作目录更新到修订版 7,这是否会导致我的库文件夹(My Documents/Development/Libraries/ProjectA.../Libraries/ProjectB) 也更新到修订版 7 中存储的内容吗?

更新

我添加了第8行代码:ci -m "initial commit"。这会执行两件事:(1) 将 .hgsubstate 文件添加到主存储库,以及 (2) 将所有更改(包括新的子存储库)提交到主存储库(带有消息“初始提交”)。 .hgsubstate 文件的目的是跟踪所有子存储库的状态,因此如果您返回到较早的版本,它也会从所有子存储库中获取正确的版本。


更新 2 - 一些说明

经过进一步的实验,我认为现在可以提供解决原始问题的步骤(主要使用 Windows 资源管理器和 TortoiseHG):

创建一个subrepo

  1. Libraries/ProjectALibraries/ProjectB 和主存储库(Projects/Foo/SolutionProjects/ Bar/Solution)必须是单独的存储库。
  2. 打开Projects/Foo/Solution
  3. Libraries/ProjectA 克隆到 Projects/Foo/Solution
  4. ProjectA 添加到 Foo 存储库。
  5. 使用文本编辑器创建一个名为 .hgsub 的文件,其中包含以下内容:

    项目A = 项目A
    
  6. 打开 DOS 控制台窗口并输入以下命令(请参阅注释如下)

    cd c:\...\Projects\Foo\Solution
    hg ci -m“提交子存储库“ProjectA”
    
  7. 对于 Bar,步骤基本相同,但 .hgsub 文件应包含两个项目的条目,如下所示:

    项目A = 项目A  
    项目B = 项目B
    

注意:开始对于 TortoiseHG 0.10(预计于 3 月发布),您将能够使用 HG Commit shell 命令来执行此操作,但目前您必须使用命令行。

一旦这一切都设置完毕,事情就会变得容易一些。

提交更改 - 要提交对 FooBar 的更改,您可以对每个子存储库执行 Synchronize/Pull 操作使子存储库与库项目存储库中的最新修订同步。然后你再次使用命令行来提交更改(直到版本 0.10,此时你可以只使用 TortoiseHG 来提交)。

将工作目录更新到早期版本 - 这似乎在 TortoiseHG 中工作得相当正常,并且似乎不需要使用任何 DOS 命令。要在 Visual Studio 中实际使用早期版本,您需要执行 Synchronize/Push 操作,将旧版本的库项目放回 Libraries/ProjectX文件夹。

尽管我喜欢使用 TortoiseHG 来完成简单的任务,但为经常使用的子存储库操作(尤其是更新)编写批处理文件可能会更好。

希望这对将来的人有帮助。如果您发现任何错误,请告诉我(或者如果可以的话,请自行编辑)。

Situation

I have two .NET solutions (Foo and Bar) and a common library that contains ProjectA, ProjectB, and ProjectC. Foo and Bar reference one or more library projects, but the library projects are not located within the Foo and Bar Solution folders.

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...

Mercurial Subrepositories

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.

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:

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? If yes, how? I'm pretty sure lines 1-3 can, but I don't know about lines 4-7. None of this seems to be documented in 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.
    • In line 5, I don't understand what nested/foo is. Where did foo come from? What is foo? A repository? A folder?
    • Line 6 - this one completely baffles me.
    • In line 7, I assume .hgsub is being added to main? Or is it being added to 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?

Update

I added an 8th line of code: 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"). 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.


Update 2 - some instructions

After further experimentation, I think I can now provide the steps to solve my original problem (using mostly Windows Explorer and TortoiseHG):

Creating a subrepo

  1. Libraries/ProjectA, Libraries/ProjectB, and the main repositories (Projects/Foo/Solution and Projects/Bar/Solution) must be separate repositories.
  2. Open Projects/Foo/Solution.
  3. Clone from Libraries/ProjectA to Projects/Foo/Solution.
  4. Add ProjectA to the Foo repository.
  5. Use a text editor to create a file called .hgsub, containing the following:

    ProjectA = ProjectA
    
  6. Open a DOS console window and enter the following commands (see note below):

    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:

    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.

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. Then you again use the command line to commit the changes (until version 0.10, when you can just use TortoiseHG to commit).

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. 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.

As much as I like TortoiseHG for simple tasks, it's probably better to write batch files for frequently used subrepo operations (especially updating).

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).

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

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

发布评论

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

评论(2

心如荒岛 2024-08-25 08:28:52

你也许可以尝试一下这些东西,并且比写下你的问题更快地学会它,但我会咬牙切齿。

这些步骤中的任何一个或全部都可以吗?
使用 TortoiseHG 执行,截至
版本0.9.2?如果是,怎么办?

TortiseHG 还没有为子存储库的创建提供 GUI 包装器,但 TortiseHG 在使用命令行方面一直做得很好。使用命令行来创建它们,然后就可以开始了。

什么是
上面的代码做(逐行
解释会很多
赞赏)。

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

这里有一些具体的
我当时想到的问题
试图破译它:是什么 >做什么?

这与 Mercurial 无关,它是标准 shell(unix 和 dos),用于“将结果放入名为 X 的文件中”

在第 5 行,我不
理解什么是nested/foo。在哪里
foo 是从哪里来的?什么是 foo?一个
存储库?文件夹?

这是子存储库中的一个文件。 Foo是传统的任意名称,任意内容是字符串“test”

第 6 行 - 这
一个让我完全困惑。

它将内容放入 .hgsub 中,有必要说明nested是一个名为nested且位于nested的嵌套存储库。

在第 7 行中,
我假设 .hgsub 被添加到
主要的?或者它是否被添加到嵌套中?

主要的

假设我设置了子存储库,
我的 Bar 存储库现在已达到
修订版 10。如果我尝试更新到
修订版 7,这会导致我的图书馆
文件夹(我的
文档/开发/库/ProjectA
和.../Libraries/ProjectB) 进行更新
修订版 7 中存储的内容为
出色地?鉴于 Foo 还指
图书馆/项目A,这可以得到
有趣!

修订号不会保留,但您可以通过编辑 .hgsubstate 文件进行控制。

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? 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. 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"

In line 5, I don't
understand what nested/foo is. Where
did foo come from? What is foo? A
repository? A folder?

It's a file in the subrepo. Foo is a traditional arbitrary name, and the arbitrary contents are the string "test"

Line 6 - this
one completely baffles me.

It's putting the contents in .hgsub necessary to say that nested is a nested repo named nested and located at nested.

In line 7,
I assume .hgsub is being added to
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? Given that Foo also refers to
Libraries/ProjectA, this could get
interesting!

Revision numbers won't carry across, but you have control by editing the .hgsubstate file.

笑,眼淚并存 2024-08-25 08:28:52

TortoiseHg 1.0 发布后,只是一个快速更新。

THG 1 中的子存储库支持足以让您从 Windows 资源管理器执行示例步骤。我在资源管理器中唯一无法执行的操作是第 6 步:

echo nested = nested > .hgsub

Windows 资源管理器(至少在 XP 中)报告重命名错误“您必须键入文件名”。如果您尝试将“New Text Document.txt”重命名为“.hgsub”。 *8')

编辑:顺便说一句,如果您通过 TortoiseHg 和命令行同时使用 hg,并且您还没有 Microsoft 的“Command Here”PowerTool 已安装,我强烈推荐它。它向 Windows 资源管理器中的每个目录添加了一个“在此处打开命令窗口”上下文菜单条目,从而可以轻松地在任何需要的地方打开命令窗口。

Just a quick update, after the release of TortoiseHg 1.0.

The subrepo support in THG 1 is good enough to do let you do example steps from Windows Explorer. The only one I couldn't do from Explorer was step 6:

echo nested = nested > .hgsub

Windows explorer (in XP at least) reports a rename error "You must type a file name." if you try to rename "New Text Document.txt" to ".hgsub". *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. 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.

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