Vaibhav Bajpai
Vaibhav Bajpai

Reputation: 16784

Is hg clone equivalent to hg (init→pull)

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:

Is this equivalent?

Upvotes: 3

Views: 1398

Answers (2)

Lasse V. Karlsen
Lasse V. Karlsen

Reputation: 391456

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

Upvotes: 4

Tim Henigan
Tim Henigan

Reputation: 62188

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.

Upvotes: 14

Related Questions