Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Mercurial via a USB flash drive

In short:
How can I use Hg to synchronize repositories between two computers using a flash drive as intermediary?

With more detail:
I often develop code on computers that aren't networked in any way, and I transfer files between these machines using a USB flash drive. Now I would like to develop some software across these machines using Hg repositories on each machine that I can frequently sync-up using the flash drive transfer mechanism.

I'm slightly familiar with Hg, as I use it in the most simple way possible for versioning only my own work on independent machines, but am uncertain as to exactly what I should do to use it to synchronize repositories between two computers using a flash drive as intermediary. Maybe, for example, I need to create a temporary repository on the flash drive (using “clone”) from which I then sync to (using “push” and “pull”), and do this by A→flash, flash→B, B→flash, flash→A? The more specificity in your answer regarding the sequence of actions and commands, the more useful to me.

Finally, how do I get this process started? Do I need to do something so Hg knows these are all part of one code base? For example, each of my current repositories on the different computers was created independently from a time before I started using Hg, and although all the code is similar, independent changes have been made to each, and the repositories know nothing about each other. If what I need to do with this is different than what I need to do for the ongoing case once I have everything unified, spelling this process out for me as well would also help.

In case it's important, these machines can be running any of Windows, Mac, or Linux, and my versions of Mercurial are slightly different on each machine (though the Mercurial versions could be unified if needed).

like image 482
tom10 Avatar asked Oct 01 '10 16:10

tom10


2 Answers

What you have described above in terms of using the flash drive as an intermediate storage location should work. My process would be:

initial setup

  1. create repo on computer A (using hg init)
  2. clone the repo from computer A to flash drive

    hg clone C:/path/to/repo/A X:/path/to/flash/drive/repo

  3. clone the repo from flash drive to computer B

    hg clone X:/path/to/flash/drive/repo C:/path/to/repo/B

working process

  1. edit/commit to repo on computer A
  2. push from computer A to flash drive

    hg push X:/path/to/flash/drive/repo

  3. pull from flash drive to computer B

    hg pull X:/path/to/flash/drive/repo

  4. edit/commit repo on computer B

  5. push from computer B to flash drive (same commands as above)
  6. pull from flash drive to computer A (same commands as above)

Finally, how do I get this process started? Do I need to do something so Hg knows these are all part of one code base?

Mercurial knows if two arbitrary repositories have a common ancestor by looking at the SHA1 hash keys of the commits in each repo. In other words, assuming both repos have at least one common hash key in their histories, Mercurial will attempt to merge them. In your specific case, where both repos are initially un-versioned, Mercurial will need some help. The best thing to do would be to get to a place where both repos are identical and then perform your hg init. Mercurial should handle sharing from this point on.

like image 198
dls Avatar answered Sep 17 '22 11:09

dls


When working offline on different machines. It is better to use the bundle command that comes with Mercurial. So echoing what dls wrote but a slight change process.

Initial setup as mentioned by dls. or

  1. Go to your Mercurial repository top directory
  2. Create bundle: hg bundle --base null ../project.hg
  3. Copy the project.hg file to your other computer
  4. Create a directory there
  5. Make it an Mercurial repository : hg init
  6. Incorporate the bundle: hg pull <path/project.hg>
  7. hg update
  8. Check hg log, both the repository will show same base revisions and tip

Workflow using bundle

I use a slightly different workflow. I keep these repositories as distinct repositories. I mention them as repo1 and repo2.

Suppose that the current tip of repo1 is 4f45839f613c.

  1. You make changes and commit them in repo1
  2. Create a bundle of the changes :

Command : This bundle contains all changes since the specified base version.

hg bundle --base 4f45839f613c changes.bundle
  1. Take it to repo2 by copying the bundle.
  2. You can simply pull the bundle to repo2 :

Command :

hg pull changes.bundle

If the bundle contains changes that are already present in repo2, then these will be ignored when pulling. As long as the bundle doesn't grow to large, this allows to use the bundle command with the same --base revision again and again to create bundles including further changes.

About bundles: these are (very well) compressed.

creates a (compressed) backup of the repository

hg bundle --base null backup.bundle

[Edit : Adding some links on this topic]

  • http://blog.experimentalworks.net/2010/09/review-remote-changes-offline-in-mercurial/
  • https://www.mercurial-scm.org/wiki/Bundle

[Edit: What I think is advantage of using bundle]

Bundles can be created offline, copied or sent via mail. Using push to repo on flash drive, requires it to be connected. Bundles are easier since it does not maintain that the two repo from which you push and pull have to be available at the same time.

Apart from that, bundles can also be of two types : Changesets and Incremental. Changeset bundles are complete standalone bundles. You can also use bundles for backup as a single file.

like image 24
pyfunc Avatar answered Sep 18 '22 11:09

pyfunc