Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue5 #6

Merged
merged 19 commits into from Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 37 additions & 19 deletions README.md
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
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
PatrickFerber marked this conversation as resolved.
Show resolved Hide resolved
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just got the following output when I accidentally ran cleanup on a repository that was already cleaned:

Looking for missing commits
comparing with http://hg.fast-downward.org/
searching for changes
abort: repository is unrelated
Cloning official repository

It looks like the error (abort: repository is unrelated) still had the exit code of 0 (no commits to pull) and the script continued with cloning the official repository. Should we check for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't bother. This is not a script meant to be run by many people many times, and we cannot predict all user errors. I think users that make this error are likely to find out eventually what went wrong, so all this would do is potentially save them a bit of time.

Also, we should merge this soon; as far as I understand, the main branch is still on code that does no reordering and is not likely to work.

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
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
@@ -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.