Is hg clone equivalent to hg (init→pull)

强颜欢笑 提交于 2019-12-20 02:06:47

问题


At work I am using a svn repository shared among 7 people.

To avoid plaguing my mistakes with commits and breaking the builds for everyone and to avoid branching in svn, I have a created a hg repository in a part of the svn directory I am currently working on.

I perform local commits on hg as I work and since I have this all setup on a virtual machine, I am even pushing my hg repository to a private centralized location.

Recently I migrated to Mac OS X lion which broke my virtual machine, so I had to set it up again. So I checked out the project from my svn trunk and now want to get back hg change sets in the directory I was working on.

I have two options:

  • $ hg clone <remote repo>
  • $ hg init && hg pull <remote repo>

Is this equivalent?


回答1:


The only difference is that if you run hg init && hg pull <remote>, then you must also:

  1. Run hg update default to checkout a working copy
  2. Manually set up your default path for push and pull

hg clone does all this in one command.




回答2:


Well, yes and no.

I know that your question indicates you're using a remote repository as the source, but the title of the question is a bit broader, so I'm answering the broader question.

The seemingly apparent end-result is the same. Though the files inside the two repositories are not binary identical (note, I'm not talking about the files you track, I'm talking about the "database" that Mercurial uses to track those files in), the history, changesets, etc. are all the same.

So in that respect, yes, those two seem to do the same thing.

However, they do it in different ways.

If you do this:

hg clone REMOTE_URL
hg init && hg pull REMOTE_URL

Then there is no real difference.

However, if you do this:

hg clone LOCAL_PATH
hg init && hg pull LOCAL_PATH

(note, this clone/pull is from another repository already on your disk)

Then there might be a difference. A local clone will, if possible, use hardlinks for the repository. In other words, you're not making a new distinct copy of all the files in the repository, you're creating new links on disk for them, which runs vastly quicker and requires almost no space.

Then, when you start modifying the history, ie. committing new changesets, those files are unlinked and made full copies, on a on-demand basis.

Note that the exact heuristics for which files it does and does not make such hardlinks for is not known to me. You can read more about this feature in the Mercurial wiki, Hardlinked Clones.

Pulling will not do this. It will read from the other repository and create/update new files in the target repository. This takes more time, and more disk-space.

So to summarize:

  • hg clone LOCAL_PATH can use a lot less disk-space and run a whole lot quicker than a hg init && hg pull LOCAL_PATH
  • If you're cloning/pulling from a remote repository, there is no real difference


来源:https://stackoverflow.com/questions/6944981/is-hg-clone-equivalent-to-hg-init%e2%86%92pull

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!