Last active
August 25, 2020 22:25
-
-
Save bb010g/6042b1f5d2f958f5d3b057c612cba07c to your computer and use it in GitHub Desktop.
RETRO Forth mirror script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env dash | |
set -eu | |
## print argument, but shell quoted | |
quote() { #{{{1 | |
local arg; for arg; do | |
alias __quote_tmp_alias_arg="$arg" | |
arg="$(alias __quote_tmp_alias_arg)" | |
arg="${arg##*__quote_tmp_alias_arg=}" | |
printf '%s\n' "$arg" | |
done | |
unalias __quote_tmp_alias_arg 2>/dev/null || true | |
} #}}}1 | |
fossil_uri='http://forthworks.com:8080/retro12' | |
fossil_repo='./retro.fossil' | |
git_repo='./retro' | |
git_remote_name='origin' | |
git_remote_url='git@github.com:bb010g/retro' | |
git_historical_remote_name='historical' | |
git_historical_remote_url='https://github.com/crcx/retro12/' | |
git_historical_end='58fa921' | |
execute_with_substitution() { #{{{1 | |
local cmd="$1" needle="x$2" subst="$3" arg | |
shift 3 | |
for arg; do | |
if test "x$arg" = "$needle" | |
then cmd="$cmd $subst"; needle= | |
else cmd="$cmd $(quote "$arg")" | |
fi | |
done | |
eval "$cmd" | |
} #}}}1 | |
alias fossil_="execute_with_substitution 'fossil' '--' '-R \"\$fossil_repo\"' " | |
alias git_='git -C "$git_repo" ' | |
test_fossil_extant() { | |
test -f "$fossil_repo" && fossil_ info -- | |
} | |
test_git_extant() { | |
test -d "$git_repo" && git_ rev-parse --is-bare-repository >/dev/null | |
} | |
if ! test_fossil_extant; then | |
fossil clone "$fossil_uri" "$fossil_repo" | |
test_fossil_extant | |
else | |
fossil_ pull -- | |
fi | |
if ! test_git_extant; then | |
git init "$git_repo" | |
test_git_extant | |
fi | |
git_ remote -v | |
git_ branch -v | |
fossil_ git export -- "$git_repo" | |
fossil_ git status -- | |
git_ reset --hard master | |
# errexit doesn't disarm through parameter assignment | |
set +e | |
if ! current_git_remote_url="$(git_ remote get-url "$git_remote_name")"; then | |
set -e | |
git_ remote add "$git_remote_name" "$git_remote_url" | |
current_git_remote_url="$(git_ remote get-url "$git_remote_name")" | |
fi | |
set -e | |
test "$current_git_remote_url" = "$git_remote_url" | |
set +e | |
if ! current_git_remote_url="$( \ | |
git_ remote get-url "$git_historical_remote_name")"; then | |
set -e | |
git_ remote add "$git_historical_remote_name" "$git_historical_remote_url" | |
current_git_remote_url="$(git_ remote get-url "$git_historical_remote_name")" | |
fi | |
set -e | |
test "$current_git_remote_url" = "$git_historical_remote_url" | |
unset current_git_remote_url | |
git_ fetch --all -t | |
if ! git_ merge-base --is-ancestor "$git_historical_end" master; then | |
git_replace_ref=$(git_ rev-parse "master^{/\ | |
Initial checkin \\(from $git_historical_end in the old git repo\\)\ | |
}") | |
git_ replace -d "$git_replace_ref" || true | |
git_ replace --graft "$git_replace_ref" "$git_historical_end" | |
unset git_replace_target | |
fi | |
git_ filter-repo --force --partial --refs master \ | |
--mailmap ../200-fossil.mailmap | |
git_ branch --set-upstream-to="$git_remote_name/master" master | |
git_ push | |
# vim:et:sw=2:tw=78:fdm=marker:fdl=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Charles Childers <crc@forthworks.com> crc <crc@noemail.net> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> { } }: | |
let retro-forth-mirror = ( | |
{ lib, stdenvNoCC, makeWrapper | |
, dash, fossil, git, git-filter-repo ? gitAndTools.git-filter-repo | |
, gitAndTools ? null | |
}: | |
stdenvNoCC.mkDerivation rec { | |
pname = "retro-forth-mirror"; | |
version = "2020-03-02"; | |
src = ./100-retro-forth-mirror.sh; | |
nativeBuildInputs = [ | |
makeWrapper | |
]; | |
buildInputs = [ | |
dash | |
fossil | |
git | |
git-filter-repo | |
]; | |
unpackPhase = '' | |
runHook preUnpack | |
runHook postUnpack | |
''; | |
installPhase = '' | |
runHook preInstall | |
install -Dm755 "$src" "$out/bin/retro-forth-mirror" | |
wrapProgram "$out/bin/retro-forth-mirror" --prefix PATH : ${ | |
lib.makeBinPath buildInputs | |
} | |
runHook postInstall | |
''; | |
preferLocalBuild = true; | |
allowSubstitutes = false; | |
} | |
); | |
in { | |
# `nix run -f ./500-mirror.nix retro-forth-mirror -c retro-forth-mirror` | |
# (if git-filter-repo is not present, | |
# you may need `--arg pkgs 'import <nixos-unstable> { }' or similar.) | |
retro-forth-mirror = pkgs.callPackage retro-forth-mirror { }; | |
} | |
# vim:et:sw=2:tw=78:fdm=marker:fdl=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment