Skip to content

Commit

Permalink
Merge pull request #6 from aibasel/issue5
Browse files Browse the repository at this point in the history
Issue5
  • Loading branch information
PatrickFerber authored Aug 6, 2020
2 parents 10e17f8 + 16bbca3 commit 8f4a459
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 43 deletions.
56 changes: 37 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@ repository is compatible with the official Fast Downward Git repository.
- Git

## Usage
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-cleanup-and-conversion.sh MERCURIAL_REPOSITORY CONVERTED_GIT_REPOSITORY \
[--redirect-fast-export-stderr FILE]
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
CLEANED_MERCURIAL_REPOSITORY is a location where the intermediate cleaned up Mercurial
repository will be written to:
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 \
Expand All @@ -32,32 +36,46 @@ 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 might want to delete "subfeature"
branch from the resulting Git repository by running `git branch -D subfeature`.
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
- Both 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.

## Details of the cleanup process

- 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 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] `"
- 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
- run garbage collection


Let's rewrite history!
22 changes: 11 additions & 11 deletions run-cleanup-and-conversion.sh → run-all-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ 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.
INTERMEDIATE_REPOSITORY="${TEMP_DIR}/intermediate"
CLEANED_REPOSITORY="${TEMP_DIR}/cleaned"
BASE="$(realpath "$(dirname "$(readlink -f "$0")")")"
SETUP_CLEANUP="${BASE}/setup-cleanup.sh"
SETUP_CONVERSION="${BASE}/setup-conversion.sh"
SETUP_MERCURIAL="${BASE}/setup-mercurial.sh"
SETUP_FAST_EXPORT="${BASE}/setup-fast-export.sh"
RUN_CLEANUP="${BASE}/run-cleanup.sh"
RUN_CONVERSION="${BASE}/run-conversion.sh"

if ! /bin/bash "${SETUP_CLEANUP}"; then
echo "Error during the setup for the cleaning script."
if ! /bin/bash "${SETUP_MERCURIAL}"; then
echo "Error during the Mercurial setup."
exit 2
fi

if ! /bin/bash "${SETUP_CONVERSION}"; then
echo "Error during the setup for the conversion script."
if ! /bin/bash "${SETUP_FAST_EXPORT}"; then
echo "Error during the 'fast-export' setup."
exit 2
fi

if ! "${RUN_CLEANUP}" "${SRC_REPOSITORY}" "${INTERMEDIATE_REPOSITORY}"; then
if ! "${RUN_CLEANUP}" "${SRC_REPOSITORY}" "${CLEANED_REPOSITORY}"; then
echo "Cleanup failed."
exit 2
fi

if ! "${RUN_CONVERSION}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" $@; then
if ! "${RUN_CONVERSION}" "${CLEANED_REPOSITORY}" "${CONVERTED_REPOSITORY}" $@; then
echo "Conversion failed."
exit 2
fi

echo "Removing intermediate repository."
echo "Removing intermediate cleaned-up repository."
rm -r "${TEMP_DIR}"
41 changes: 33 additions & 8 deletions run-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,55 @@ if [[ -e "${CLEANED_REPOSITORY}" ]]; then
exit 1
fi

ORDERED_REPOSITORY="$(mktemp -d)"
echo "Storing intermediate reordered repository under ${ORDERED_REPOSITORY}"


BASE="$(dirname "$(readlink -f "$0")")"
SETUP_CLEANUP="${BASE}/setup-cleanup.sh"
SETUP_MERCURIAL="${BASE}/setup-mercurial.sh"
VIRTUALENV="${BASE}/data/py3-env"

if ! /bin/bash "${SETUP_CLEANUP}"; then
if ! /bin/bash "${SETUP_MERCURIAL}"; then
echo "Error during setup."
exit 2
fi
source "${VIRTUALENV}/bin/activate"

# Disable all extensions.
# (https://stackoverflow.com/questions/46612210/mercurial-disable-all-the-extensions-from-the-command-line)
HGRCPATH= hg \
export HGRCPATH=
export HGPLAIN=

echo "Looking for missing commits"

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 "Cloning official repository"
hg clone http://hg.fast-downward.org "${ORDERED_REPOSITORY}"

echo "Pulling own commits"
hg -R "${ORDERED_REPOSITORY}" pull "${SRC_REPOSITORY}"

echo "Creating cleaned-up repository"
hg \
--config extensions.renaming_mercurial_source="${BASE}/renaming_mercurial_source.py" \
--config extensions.hgext.convert= \
--config format.sparse-revlog=0 \
convert "${SRC_REPOSITORY}" "${CLEANED_REPOSITORY}" \
convert "${ORDERED_REPOSITORY}" "${CLEANED_REPOSITORY}" \
--source-type renaming_mercurial_source \
--authormap "${BASE}/data/downward_authormap.txt" \
--filemap "${BASE}/data/downward_filemap.txt" \
--splicemap "${BASE}/data/downward_splicemap.txt" \
--branchmap "${BASE}/data/downward_branchmap.txt"

cd "${CLEANED_REPOSITORY}"
HGRCPATH= hg --config extensions.strip= strip "branch(issue323)" --nobackup
HGRCPATH= 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}"
13 changes: 10 additions & 3 deletions run-conversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@

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

BASE="$(dirname "$(readlink -f "$0")")"
SETUP_CONVERSION="${BASE}/setup-conversion.sh"
SETUP_FAST_EXPORT="${BASE}/setup-fast-export.sh"
CONVERT="${BASE}/convert.py"
VIRTUALENV="${BASE}/data/py3-env"

if ! /bin/bash "${SETUP_CONVERSION}"; then
if ! /bin/bash "${SETUP_FAST_EXPORT}"; then
echo "Error during setup."
exit 2
fi

source "${VIRTUALENV}/bin/activate"
export HGRCPATH=
export HGPLAIN=

HGRCPATH= python3 "${CONVERT}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" $@
python3 "${CONVERT}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" "$@"
4 changes: 2 additions & 2 deletions setup-conversion.sh → setup-fast-export.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

BASE="$(dirname "$(readlink -f "$0")")"
SETUP_CLEANUP="${BASE}/setup-cleanup.sh"
SETUP_MERCURIAL="${BASE}/setup-mercurial.sh"
FAST_EXPORT_REPO="${BASE}/data/fast-export"
FAST_EXPORT_VERSION="v200213-23-g44c50d0"


if ! /bin/bash "${SETUP_CLEANUP}"; then
if ! /bin/bash "${SETUP_MERCURIAL}"; then
echo "Error during Mercurial setup."
fi

Expand Down
File renamed without changes.

0 comments on commit 8f4a459

Please sign in to comment.