Skip to content

Instantly share code, notes, and snippets.

@hlandau

hlandau/gitqlog Secret

Last active September 8, 2023 15:09
Show Gist options
  • Save hlandau/60a399e453be6ac552d080c1b3efe161 to your computer and use it in GitHub Desktop.
Save hlandau/60a399e453be6ac552d080c1b3efe161 to your computer and use it in GitHub Desktop.
gitqlog
#!/usr/bin/env bash
set -eo pipefail
BRANCH="quic-qlog"
BASE_BRANCH="${BRANCH}-base"
#BASE="$(git show-ref -s quic-qlog-base)"
# MAINTAINER USE: REBASING THE BRANCH
qlog_rebase() {
echo >&2 "==> Rebasing on master..."
git -C ~/work/ossl/openssl-master pull
git rebase -i master "$@"
git branch -d "$BASE_BRANCH"
git branch "$BASE_BRANCH" master
}
# MAINTAINER USE: PUSHING THE BRANCH
qlog_push() {
echo >&2 "==> Publishing updated QLOG branch..."
git push --force self "$BASE_BRANCH" "$BRANCH"
}
have_qlog() {
if [[ "$(git log --oneline -n 1000 | { grep '^[^ ]* QLOG: ' || true; } | wc -l)" -gt 0 ]]; then
return 0
else
return 1
fi
}
# USER USE: USING THE BRANCH AND APPLYING IT
# Update local qlog-branch based on remote, silently overwriting any changes.
qlog_apply() {
if have_qlog; then
echo >&2 "ERROR: QLOG commits found, please drop them before attempting to apply an updated version."
exit 1
fi
echo >&2 "==> Fetching latest QLOG commits..."
git fetch git@github.com:hlandau/openssl.git +quic-qlog:TEMP-quic-qlog +quic-qlog-base:TEMP-quic-qlog-base
# Cherry-pick onto current branch. Make sure existing patches have been dropped
# first.
echo >&2 "==> Applying latest QLOG commits to the current branch..."
git cherry-pick --keep-redundant-commits TEMP-quic-qlog-base...TEMP-quic-qlog
echo >&2 ""
echo >&2 "==> Done"
echo >&2 ""
echo >&2 " Remember to use ./Configure enable-unstable-qlog"
echo >&2 " and set QLOGDIR=... QFILTER='*'"
}
# USER USE: DROPPING THE PATCHES
qlog_drop() {
if ! have_qlog; then
echo >&2 "ERROR: No QLOG commits found."
exit 1
fi
echo >&2 "==> Dropping all QLOG commits..."
OLDEST_QLOG_COMMIT=$(git log --grep='^QLOG: ' --pretty=tformat:'%H' | tail -n 1)
GIT_SEQUENCE_EDITOR="sed -i 's/^pick \([^ ]* QLOG: .*\)$/drop \1/'" git rebase -i "${OLDEST_QLOG_COMMIT}^"
}
# USER USE: UPDATING THE PATCHES
# Follow the instructions for dropping the patches, then follow the instructions
# for applying the patches.
# WARNING: Do not make commits starting with 'QLOG: ' or these will be dropped
# automatically.
case "$1" in
rebase)
shift
qlog_rebase "$@"
;;
push)
qlog_push
;;
apply)
qlog_apply
;;
drop)
qlog_drop
;;
*)
echo >&2 "usage: $0 {rebase|push|apply|drop}"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment