Skip to content

Commit

Permalink
Merge pull request #1027 from frej/update-hg-fast-export-info
Browse files Browse the repository at this point in the history
Update Ch9 section about Mercurial imports to match current hg-fast-export release
  • Loading branch information
ben authored Mar 27, 2018
2 parents c87e21a + 7f501cb commit 54bf454
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions book/09-git-and-other-scms/sections/import-hg.asc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Since Mercurial and Git have fairly similar models for representing versions, an

[source,console]
----
$ git clone http://repo.or.cz/r/fast-export.git /tmp/fast-export
$ git clone https://github.com/frej/fast-export.git
----

The first step in the conversion is to get a full clone of the Mercurial repository you want to convert:
Expand Down Expand Up @@ -38,18 +38,22 @@ Joe Smith <[email protected]>
----

In this example, the same person (Bob) has created changesets under four different names, one of which actually looks correct, and one of which would be completely invalid for a Git commit.
Hg-fast-export lets us fix this by adding `={new name and email address}` at the end of every line we want to change, and removing the lines for any usernames that we want to leave alone.
Hg-fast-export lets us fix this by turning each line into a rule: `"<input>"="<output>"`, mapping an `<input>` to an `<output>`.
Inside the `<input>` and `<output>` strings, all escape sequences understood by the python `string_escape` encoding are supported.
If the author mapping file does not contain a matching `<input>`, that author will be sent on to Git unmodified.
If all the usernames look fine, we won't need this file at all.
In this example, we want our file to look like this:

[source]
----
bob=Bob Jones <[email protected]>
bob@localhost=Bob Jones <[email protected]>
bob <[email protected]>=Bob Jones <[email protected]>
bob jones <bob <AT> company <DOT> com>=Bob Jones <[email protected]>
"bob"="Bob Jones <[email protected]>"
"bob@localhost"="Bob Jones <[email protected]>"
"bob <[email protected]>"="Bob Jones <[email protected]>"
"bob jones <bob <AT> company <DOT> com>"="Bob Jones <[email protected]>"
----

The same kind of mapping file can be used to rename branches and tags when the Mercurial name is not allowed by Git.

The next step is to create our new Git repository, and run the export script:

[source,console]
Expand All @@ -59,7 +63,7 @@ $ cd /tmp/converted
$ /tmp/fast-export/hg-fast-export.sh -r /tmp/hg-repo -A /tmp/authors
----

The `-r` flag tells hg-fast-export where to find the Mercurial repository we want to convert, and the `-A` flag tells it where to find the author-mapping file.
The `-r` flag tells hg-fast-export where to find the Mercurial repository we want to convert, and the `-A` flag tells it where to find the author-mapping file (branch and tag mapping files are specified by the `-B` and `-T` flags respectively).
The script parses Mercurial changesets and converts them into a script for Git's "fast-import" feature (which we'll discuss in detail a bit later on).
This takes a bit (though it's _much_ faster than it would be over the network), and the output is fairly verbose:

Expand Down

0 comments on commit 54bf454

Please sign in to comment.