summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-07-01 02:30:58 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-07-01 02:30:58 -0400
commite4109fab0bece003dc53c78c7cc8608b68328312 (patch)
treebd8223216465f5d2b9f0468866c2153c17289186
parent2631b600d153aeda1d4201164dafc023dfdceedb (diff)
build git repo
-rw-r--r--Makefile5
-rwxr-xr-xbin/gitthing70
2 files changed, 74 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 5cb9fdc..12c5bb6 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,9 @@ dat/content-file/%:
content-file = $(foreach u,$(filter-out %/,$(index)),dat/content-file/$(call url2murl,$(u)))
download: $(content-file)
-.PHONY: all fix download
+git: download
+ gitthing dat/git < dat/index.txt
+
+.PHONY: all fix download git
.DELETE_ON_ERROR:
.SECONDARY:
diff --git a/bin/gitthing b/bin/gitthing
new file mode 100755
index 0000000..a54c017
--- /dev/null
+++ b/bin/gitthing
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+
+empty() {
+ [[ $(stat -c %s "$1") -eq 0 ]]
+}
+
+url2murl() {
+ local x
+ x=$1
+ x=${x//'^'/'^5E'}
+ x=${x//':'/'^3A'}
+ x=${x//'%'/'^25'}
+ printf '%s' "$x"
+}
+
+murl2url() {
+ local x
+ x=$1
+ x=${x//'^25'/'%'}
+ x=${x//'^3A'/':'}
+ x=${x//'^5E'/'^'}
+ printf '%s' "$x"
+}
+
+main() {
+ set -euE -o pipefail
+ top=$PWD
+
+ mkdir -p "$1"
+ cd "$1"
+ git init
+ echo 'ref: refs/heads/PROGRAMS/CVTUTF' > .git/HEAD
+ git commit --allow-empty -m 'initial commit'
+
+ while read -r time url; do
+ suffix="${url##*/Public/}"
+ dirpart="${suffix%/*}"
+ filepart="${suffix##*/}"
+
+ branch=$dirpart
+
+ git checkout PROGRAMS/CVTUTF
+ git checkout -b "$branch" || true
+ git checkout "$branch"
+
+ waurl="http://web.archive.org/web/$time/$url"
+ if [[ -n "$filepart" ]]; then
+ file="$top/dat/content-file/$(url2murl "${waurl#http://}")"
+ cp "$file" .
+ else
+ dir="$top/dat/content-dir/$(url2murl "${waurl#http://}")"
+ comm -23 \
+ <(git ls-files) \
+ <(< "$dir/metadata.txt" awk '{print $1}') \
+ | xargs -r0 rm -f --
+ if ! empty "$dir/readme.txt"; then
+ cp "$dir/readme.txt" .
+ fi
+ cp "$dir/metadata.txt" .metadata.txt
+ fi
+
+ if [[ -n "$(git status -s .)" ]]; then
+ gitdate="$(sed -r 's/(....)(..)(..)(..)(..)(..)/\1-\2-\3T\4:\5:\6/' <<<"$time")"
+ git add .
+ GIT_AUTHOR_DATE=$gitdate GIT_AUTHOR_DATE=$gitdate git commit -m "$time $url"
+ fi
+ done
+}
+
+main "$@"