From 8ce694428b0e985a585afd430e420451e8f9857c Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Tue, 27 Mar 2018 12:54:58 +0200 Subject: [PATCH 1/3] import-hg: Update location for hg-fast-export The canonical location for the hg-fast-export tool has been on gihub since 2011. --- book/09-git-and-other-scms/sections/import-hg.asc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/09-git-and-other-scms/sections/import-hg.asc b/book/09-git-and-other-scms/sections/import-hg.asc index 728399877..5ba6c602d 100644 --- a/book/09-git-and-other-scms/sections/import-hg.asc +++ b/book/09-git-and-other-scms/sections/import-hg.asc @@ -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: From ebf4b28dc4ae7fdd09ced3e258e33e613e9bcd67 Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Tue, 27 Mar 2018 13:17:00 +0200 Subject: [PATCH 2/3] import-hg: Update example to work with a current hg-fast-export Version 171002 of hg-fast-export changed the format of mapping files to allow arbitrary strings as input and output. Therefore update the example and the description of the format to avoid user confusion (frej/fast-export#116). --- book/09-git-and-other-scms/sections/import-hg.asc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/book/09-git-and-other-scms/sections/import-hg.asc b/book/09-git-and-other-scms/sections/import-hg.asc index 5ba6c602d..edaee0e91 100644 --- a/book/09-git-and-other-scms/sections/import-hg.asc +++ b/book/09-git-and-other-scms/sections/import-hg.asc @@ -38,16 +38,18 @@ Joe Smith ---- 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: `""=""`, mapping an `` to an ``. +Inside the `` and `` strings, all escape sequences understood by the python `string_escape` encoding are supported. +If the author mapping file does not contain a matching ``, 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 -bob@localhost=Bob Jones -bob =Bob Jones -bob jones company com>=Bob Jones +"bob"="Bob Jones " +"bob@localhost"="Bob Jones " +"bob "="Bob Jones " +"bob jones company com>"="Bob Jones " ---- The next step is to create our new Git repository, and run the export script: From 7f501cb28cc3460b288818f5f8ee90c478921424 Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Tue, 27 Mar 2018 13:34:06 +0200 Subject: [PATCH 3/3] import-hg: Mention tag and branch mapping files Users frequently submit summarily rejected patches doing some magit branch and tag name munging to the hg-fast-export project instead of using a mapping file. Try to prevent wasted work by mentioning the existence of mapping files for branches and tags when author mapping files are covered. --- book/09-git-and-other-scms/sections/import-hg.asc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/book/09-git-and-other-scms/sections/import-hg.asc b/book/09-git-and-other-scms/sections/import-hg.asc index edaee0e91..132fa8c0f 100644 --- a/book/09-git-and-other-scms/sections/import-hg.asc +++ b/book/09-git-and-other-scms/sections/import-hg.asc @@ -52,6 +52,8 @@ In this example, we want our file to look like this: "bob jones company com>"="Bob Jones " ---- +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] @@ -61,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: