Skip to content

Instantly share code, notes, and snippets.

@jwakely
Forked from siddhesh/update-glibc.sh
Last active September 26, 2021 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwakely/47fe07ec15c123e6c6a797b16cf6753c to your computer and use it in GitHub Desktop.
Save jwakely/47fe07ec15c123e6c6a797b16cf6753c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Update Patchwork patch list from commits in the upstream repo.
# Intended for use with glibc and gcc.
#
# [pw]
# server = https://patchwork.sourceware.org/api/1.2/
# project = gcc
# token = <API token>
# states = committed,accepted,superseded,deferred,rejected
#
# Set this to your patchwork repo path
PWROOT=$HOME/src/patchwork
# And this to the clone of the project
PROJROOT=$HOME/src/gcc/gcc
# A local Git tag to track the last commit you processed with this script.
PWLAST_TAG=patchwork-last
STATES="--state accepted --state new --state under-review"
STATES="$STATES --state changes-requested"
STATES="$STATES --state committed"
# Print the Git diff for a commit, filtering out generated files,
# then use patchwork's hasher to create the hash to identify it in pw.
diff_hash()
{
git show --pretty=format: $1 |
filterdiff -x '*/ChangeLog' -x '*/Makefile.in' -x '*/configure' -x '*/config.h.in' -x '*/doc/html/*' |
python "$PWROOT"/patchwork/hasher.py
}
cd "$PROJROOT" || exit
if [ $# -ne 0 ]; then
# If $1 is a positive integer, process the last $1 commits.
if [ "$1" -gt 0 ]; then
START=origin/master~$1
else
echo "$0: Invalid argument: $1" >&2
exit 1
fi
else
# Otherwise, resume from the $PWLAST_TAG tag, if set.
START=$(git tag -l "$PWLAST_TAG")
if [ -z "$START" ]; then
# Otherwise, process the last 100 commits.
START=origin/master~100
fi
fi
git fetch origin
git log --reverse --pretty=format:%H%n "$START"..origin/master |
while read gh; do
[ -z "$gh" ] && continue
h=$(diff_hash $gh)
pwid=$(git-pw patch list --hash $h $STATES -f simple --column ID | grep -v -e ID -e "\--")
if [ -n "$pwid" ]; then
echo "$(git log --pretty=oneline -1 $gh): OK"
git-pw patch update --commit-ref $gh --state committed $pwid
else
echo "$(git log --pretty=oneline -1 $gh): MISSING"
fi
# If $gh is not an ancestor of $PWLAST_TAG, update the tag.
if ! git tag --list "$PWLAST_TAG" --contains $gh | grep --silent .
then
git tag --force "$PWLAST_TAG" "$gh" >/dev/null
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment