Skip to content

Commit

Permalink
[issue5] fail early on incoming changes; make reordering implementati…
Browse files Browse the repository at this point in the history
…on detail
  • Loading branch information
maltehelmert committed Jul 28, 2020
1 parent 9c856a6 commit 16bbca3
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 71 deletions.
99 changes: 52 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
7 changes: 3 additions & 4 deletions run-all-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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}"
41 changes: 22 additions & 19 deletions run-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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= \
Expand All @@ -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}"
7 changes: 6 additions & 1 deletion run-conversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,4 +25,4 @@ source "${VIRTUALENV}/bin/activate"
export HGRCPATH=
export HGPLAIN=

python3 "${CONVERT}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" $@
python3 "${CONVERT}" "${INTERMEDIATE_REPOSITORY}" "${CONVERTED_REPOSITORY}" "$@"

0 comments on commit 16bbca3

Please sign in to comment.