diff --git a/README.md b/README.md index 5970b52..4129370 100644 --- a/README.md +++ b/README.md @@ -11,66 +11,71 @@ repository is compatible with the official Fast Downward Git repository. - Git ## Usage - To prepare your repository for the conversion pull all changes from - `http://hg.fast-downward.org`. Then run the script with the following - command where MERCURIAL_REPOSITORY is the path to the - repository you want to convert and CONVERTED_GIT_REPOSITORY is the location where the - resulting Git repository will be written to. The optional parameter can be used to - redirect the output of fast-export to a file. - - ./run-all-steps.sh MERCURIAL_REPOSITORY CONVERTED_GIT_REPOSITORY \ - [--redirect-fast-export-stderr FILE] - The conversion is done in two steps that can also be run individually. In this case - ORDERED_REPOSITORY is an intermediate repository that ensures that the history - contains all commits in the same order as the Fast Downward master repository. - The CLEANED_MERCURIAL_REPOSITORY is a location where the intermediate cleaned - up Mercurial repository will be written to: - - ./run-cleanup.sh MERCURIAL_REPOSITORY ORDERED_REPOSITORY CLEANED_MERCURIAL_REPOSITORY +To prepare your repository for the conversion pull all changes from +`http://hg.fast-downward.org`. Then run the script with the following +command where MERCURIAL_REPOSITORY is the path to the repository you +want to convert and CONVERTED_GIT_REPOSITORY is the location where the +resulting Git repository will be written to. The optional parameter +can be used to redirect the output of fast-export to a file. + + ./run-all-steps.sh MERCURIAL_REPOSITORY CONVERTED_GIT_REPOSITORY \ + [--redirect-fast-export-stderr FILE] + +The conversion is done in two steps that can also be run individually. +CLEANED_MERCURIAL_REPOSITORY is the location for the cleaned-up +Mercurial repository, which is the output of the first step and the +input of the second step. + + ./run-cleanup.sh MERCURIAL_REPOSITORY CLEANED_MERCURIAL_REPOSITORY ./run-conversion.sh CLEANED_MERCURIAL_REPOSITORY CONVERTED_GIT_REPOSITORY \ [--redirect-fast-export-stderr FILE] - The scripts will automatically set up the required tools (a virtual - environment with compatible versions of Mercurial and the fast-export tool - https://github.com/frej/fast-export.git). +The scripts will automatically set up the required tools (a virtual +environment with compatible versions of Mercurial and the fast-export tool +https://github.com/frej/fast-export.git). ## Limitations - - Multiple Mercurial heads with the same branch name are not supported. If your - repository has those, you will see - `Error: repository has at least one unnamed head: hg rXXX`. - - If you have closed and merged a branch "subfeature" into a branch "feature" - and "feature" is not yet merged into "main", you will receive: - `error: The branch 'BRANCH' is not fully merged.` - Don't worry. You might want to delete "subfeature" - branch from the resulting Git repository by running `git branch -D subfeature`. + +- Multiple Mercurial heads with the same branch name are not supported. If your + repository has those, you will see + `Error: repository has at least one unnamed head: hg rXXX`. +- If you have closed and merged a branch "subfeature" into a branch "feature" + and "feature" is not yet merged into "main", you will receive: + `error: The branch 'BRANCH' is not fully merged.` + Don't worry. You might want to delete "subfeature" branch from the + resulting Git repository by running `git branch -D subfeature`. ## Warnings - - The `run-cleanup.sh` and `run-conversion.sh` scripts generate a lot of output - on stdout and stderr. If you want to analyze it, better redirect it into files. - - The cleanup script generates repeated warnings about missing or invalid tags. - These are caused by moved or broken tags and can be ignored. + +- The scripts generate a lot of output on stdout and stderr. If you + want to analyze it, better redirect it into files. +- It is normal behavior that the cleanup script generates some + warnings about missing or invalid tags. ## Troubleshooting - If you have problems with the `run-all-steps.sh` script, try to run the steps - individually and carefully inspect the output of each step. - + +If you have problems with the `run-all-steps.sh` script, try to run the steps +individually and carefully inspect the output of each step. + ## Details of the cleanup process - - clone the (Mercurial) Fast Downward master repository - - pull your repository in the master repository - - fix and unify author names in commit message - - fix typos in branch names - - remove large files from history that should not have been added - - change commit message to follow the new convention which is to start with - "`[BRANCH NAME] `" - - strip the open branches `issue323` and `ipc-2011-fixes` + +- clone the official (Mercurial) Fast Downward repository +- pull the changes from your repository into the clone +- strip the open branches `issue323` and `ipc-2011-fixes` +- fix and unify author names in commit message +- fix typos in branch names +- remove files from history that should not have been added +- change commit messages to follow the new convention which is to + start with "`[BRANCH NAME] `" ## Details of the conversion process - - convert a Mercurial repository to Git with `fast-export` - - delete all Git branches that belong to Mercurial branches which have been - merged and closed - - remove empty commits - - run garbage collections + +- convert a Mercurial repository to Git with `fast-export` +- delete all Git branches that belong to Mercurial branches which have been + merged and closed +- remove empty commits +- run garbage collection Let's rewrite history! diff --git a/run-all-steps.sh b/run-all-steps.sh index ff0a4fd..962c856 100755 --- a/run-all-steps.sh +++ b/run-all-steps.sh @@ -23,9 +23,8 @@ if [[ -e "${CONVERTED_REPOSITORY}" ]]; then fi TEMP_DIR="$(mktemp -d)" -echo "Storing intermediate repository under ${TEMP_DIR}" +echo "Storing intermediate cleaned-up repository under ${TEMP_DIR}" # Generate a path to a non-existing temporary directory. -ORDERED_REPOSITORY="${TEMP_DIR}/ordered" CLEANED_REPOSITORY="${TEMP_DIR}/cleaned" BASE="$(realpath "$(dirname "$(readlink -f "$0")")")" SETUP_MERCURIAL="${BASE}/setup-mercurial.sh" @@ -43,7 +42,7 @@ if ! /bin/bash "${SETUP_FAST_EXPORT}"; then exit 2 fi -if ! "${RUN_CLEANUP}" "${SRC_REPOSITORY}" "${ORDERED_REPOSITORY}" "${CLEANED_REPOSITORY}"; then +if ! "${RUN_CLEANUP}" "${SRC_REPOSITORY}" "${CLEANED_REPOSITORY}"; then echo "Cleanup failed." exit 2 fi @@ -53,5 +52,5 @@ if ! "${RUN_CONVERSION}" "${CLEANED_REPOSITORY}" "${CONVERTED_REPOSITORY}" $@; t exit 2 fi -echo "Removing intermediate repository." +echo "Removing intermediate cleaned-up repository." rm -r "${TEMP_DIR}" diff --git a/run-cleanup.sh b/run-cleanup.sh index cb54a9e..f98f3bf 100755 --- a/run-cleanup.sh +++ b/run-cleanup.sh @@ -2,31 +2,28 @@ set -euo pipefail -if [[ $# -ne 3 ]]; then - echo "Invalid arguments. Use: $0 SRC TMP DST" +if [[ $# -ne 2 ]]; then + echo "Invalid arguments. Use: $0 SRC DST" exit 1 fi SRC_REPOSITORY="$1" -ORDERED_REPOSITORY="$2" -CLEANED_REPOSITORY="$3" -shift 3 +CLEANED_REPOSITORY="$2" +shift 2 if [[ ! -d "${SRC_REPOSITORY}" ]]; then echo "Invalid argument. ${SRC_REPOSITORY} has to be a directory." exit 1 fi -if [[ -e "${ORDERED_REPOSITORY}" ]]; then - echo "Invalid argument. ${ORDERED_REPOSITORY} may not exist." - exit 1 -fi - if [[ -e "${CLEANED_REPOSITORY}" ]]; then echo "Invalid argument. ${CLEANED_REPOSITORY} may not exist." exit 1 fi +ORDERED_REPOSITORY="$(mktemp -d)" +echo "Storing intermediate reordered repository under ${ORDERED_REPOSITORY}" + BASE="$(dirname "$(readlink -f "$0")")" SETUP_MERCURIAL="${BASE}/setup-mercurial.sh" @@ -42,20 +39,21 @@ source "${VIRTUALENV}/bin/activate" export HGRCPATH= export HGPLAIN= +echo "Looking for missing commits" -echo "Cloning official repository" -hg clone "http://hg.fast-downward.org" "${ORDERED_REPOSITORY}" - -if hg -R "${SRC_REPOSITORY}" incoming "${ORDERED_REPOSITORY}"; then +if hg -R "${SRC_REPOSITORY}" incoming http://hg.fast-downward.org; then echo 1>&2 "Your repository is missing commits from http://hg.fast-downward.org." echo 1>&2 "You must pull from http://hg.fast-downward.org first." exit 3 fi -echo "Enforce commit order" +echo "Cloning official repository" +hg clone http://hg.fast-downward.org "${ORDERED_REPOSITORY}" + +echo "Pulling own commits" hg -R "${ORDERED_REPOSITORY}" pull "${SRC_REPOSITORY}" -echo "Clean up repository" +echo "Creating cleaned-up repository" hg \ --config extensions.renaming_mercurial_source="${BASE}/renaming_mercurial_source.py" \ --config extensions.hgext.convert= \ @@ -67,6 +65,11 @@ hg \ --splicemap "${BASE}/data/downward_splicemap.txt" \ --branchmap "${BASE}/data/downward_branchmap.txt" -cd "${CLEANED_REPOSITORY}" -hg --config extensions.strip= strip "branch(issue323)" --nobackup -hg --config extensions.strip= strip "branch(ipc-2011-fixes)" --nobackup +echo "Stripping extraneous branches" +hg -R "${CLEANED_REPOSITORY}" \ + --config extensions.strip= \ + strip "branch(issue323)" "branch(ipc-2011-fixes)" \ + --nobackup + +echo "Removing intermediate reordered repository." +rm -r "${ORDERED_REPOSITORY}" diff --git a/run-conversion.sh b/run-conversion.sh index c901e40..a65a87f 100755 --- a/run-conversion.sh +++ b/run-conversion.sh @@ -2,6 +2,11 @@ set -euo pipefail +if [[ $# -lt 2 ]]; then + echo "Invalid arguments. Use: $0 SRC DST [optional args for fast-export]" + exit 1 +fi + INTERMEDIATE_REPOSITORY="$1" CONVERTED_REPOSITORY="$2" shift 2 @@ -20,4 +25,4 @@ source "${VIRTUALENV}/bin/activate" export HGRCPATH= export HGPLAIN= -python3 "${CONVERT}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" $@ +python3 "${CONVERT}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" "$@"