glandium / git-cinnabar

git remote helper to interact with mercurial repositories
GNU General Public License v2.0
295 stars 61 forks source link
git mercurial

git-cinnabar 0.7

cinnabar is the common natural form in which mercury can be found on Earth. It contains mercury sulfide and its powder is used to make the vermillion pigment.

git-cinnabar is a git remote helper to interact with mercurial repositories. Contrary to other such helpers ([1] [2] [3] [4] [5] [6]), it doesn't use a local mercurial clone under the hood.

The main focus at the moment is to make it work with mozilla-central and related mercurial repositories and support Mozilla workflows (try server, etc.).

Repositories last used with versions lower than 0.5.0 are not supported. Please run git cinnabar upgrade with version 0.5.0 first.

License:

The git-cinnabar source code is distributed under the terms of the Mozilla Public License version 2.0 (see the MPL-2.0 file), with parts (the git-core subdirectory) distributed under the terms of the GNU General Public License version 2.0 (see the git-core/COPYING file).

As a consequence, git-cinnabar binary executables are distributed under the terms of the GNU General Public License version 2.0.

Requirements:

Setup:

Prebuilt binaries

Cargo

Build manually

Usage:

$ git clone hg::<mercurial repo>

where <mercurial repo> can be a path to a local directory containing a mercurial repository, or a http, https or ssh url.

Essentially, use git like you would for a git repository, but use a hg:: url where you would use a git:// url.

See https://github.com/glandium/git-cinnabar/wiki/Mozilla:-A-git-workflow-for-Gecko-development for an example workflow for Mozilla repositories.

Remote refs styles:

Mercurial has two different ways to handle what git would call branches: branches and bookmarks. Mercurial branches are permanent markers on each changeset that belongs to them, and bookmarks are similar to git branches.

You may choose how to interact with those with the cinnabar.refs configuration. The following values are supported, either individually or combined in a comma-separated list:

When these values are used in combinations, the branch mappings are varied accordingly to make the type of each remote ref explicit and to avoid name collisions.

The shorthand all (also the default), is the combination of bookmarks, heads, and tips.

The refs style can also be configured per remote with the remote.$remote.cinnabar-refs configuration. It is also possible to use cinnabar.pushrefs or remote.$remote.cinnabar-pushrefs to use a different scheme for pushes only.

Tags:

You can get/update tags with the following command:

$ git cinnabar fetch --tags

Fetching a specific mercurial changeset:

It can sometimes be useful to fetch a specific mercurial changeset from a remote server, without fetching the entire repository. This can be done with a command line such as:

$ git cinnabar fetch hg::<mercurial repo> <changeset sha1>

Translating git commits to mercurial changesets and vice-versa:

When dealing with a remote repository that doesn't use the same identifiers, things can easily get complicated. Git-cinnabar comes with commands to know the mercurial changeset a git commit represents and the other way around.

The following command will give you the git commit corresponding to the given mercurial changeset sha1:

$ git cinnabar hg2git <changeset>

The following command will give you the mercurial changeset corresponding to the given git commit sha1:

$ git cinnabar git2hg <commit>

Both commands allow abbreviated forms, as long as they are unambiguous (no need for all the 40 hex digits of the sha1).

Avoiding metadata:

In some cases, it is not desirable to have git-cinnabar create metadata for all pushed commits. Notably, for volatile commits such as those used on the Mozilla try repository.

By default, git-cinnabar doesn't store metadata when pushing to non-publishing repositories. It does otherwise.

This behavior can be changed per-remote with a remote.$remote.cinnabar-data preference with one of the following values:

phase is the default described above. always and never are self-explanatory. force has the same meaning as always, but also forces git push --dry-run to store metadata.

Cinnabar clone:

For large repositories, an initial clone can take a large amount of time. A Mercurial server operator can install the extension provided in mercurial/cinnabarclone.py, and point to a git repository or bundle containing pre-generated git-cinnabar metadata. See details in the extension file.

Users cloning the repository would automatically get the metadata from the git repository or bundle, and then pull the missing changesets from the Mercurial repository.

Limitations:

At the moment, push is limited to non-merge commits.

There is no support for the following mercurial features:

Checking corruptions:

Git-cinnabar is still in early infancy, and its metadata might get corrupted for some reason.

The following command allows to detect various types of metadata corruption:

git cinnabar fsck

This command will fix the corruptions it can, as well as adjust some of the metadata that contains items that became unnecessary in newer versions.

The --full option may be added for a more thorough validation of the metadata contents. Using this option adds a significant amount of work, and the command can take more than half an hour on repositories the size of mozilla-central.

hg:// urls:

The msys shell (not msys2) doesn't keep hg::url intact when crossing the msys/native boundary, so when running cinnabar in a msys shell with a native git, the url is munged as hg;;proto;\host\path\, which git doesn't understand and doesn't even start redirecting to git-remote-hg.

To allow such setups to still work, hg:// urls are supported. But since mercurial can be either on many different protocols, we abuse the port in the given url to pass the protocol.

A hg:// url thus looks like:

hg://<host>[:[<port>.]<protocol>]/<path>

The default protocol is https, and the port can be omitted.

Compatibility:

As of version 0.7, some corner cases in Mercurial repositories will generate different git commits than with prior versions of git-cinnabar. This means a fresh clone might have different git SHA-1s than existing clones, but this doesn't impact the use of existing clones with newer versions of git-cinnabar.

Most repositories should remain non-affected by the change.

You can set the cinnabar.compat git configuration to 0.6 to keep the previous behavior.

Experimental features:

Git-cinnabar has a set of experimental features that can be enabled independently. You can set the cinnabar.experiments git configuration to a comma-separated list of those features to enable the selected ones.

The available features are: