1#!/bin/sh
2
3# git branch -D upstream/rewritten-prev upstream/master upstream/rewritten filter-state      
4
5set -e
6
7export SCRIPTS=$(dirname $(readlink -f $0))
8
9export FILTER_BRANCH_SQUELCH_WARNING=1
10
11UPSTREAM_MASTER=upstream/master
12UPSTREAM_REWRITTEN=upstream/dts
13
14LAST=$(git show-ref -s refs/heads/$UPSTREAM_MASTER||true)
15if [ -n "$LAST" ] ; then
16    RANGE="$LAST..$UPSTREAM_REWRITTEN"
17else
18    # This must be a new conversion...
19    RANGE="$UPSTREAM_REWRITTEN"
20fi
21
22FETCH_HEAD=$(git rev-parse FETCH_HEAD)
23if [ "$LAST" = "$FETCH_HEAD" ] ; then
24	echo "Nothing new in FETCH_HEAD: $FETCH_HEAD"
25	exit 0
26fi
27
28rm -f .git/refs/original/refs/heads/${UPSTREAM_REWRITTEN}
29
30git branch -f $UPSTREAM_REWRITTEN FETCH_HEAD
31
32git filter-branch --force \
33	--index-filter ${SCRIPTS}/index-filter.sh \
34	--msg-filter 'cat && /bin/echo -e "\n[ upstream commit: $GIT_COMMIT ]"' \
35	--tag-name-filter 'while read t ; do /bin/echo -n $t-dts-raw ; done' \
36	--parent-filter 'sed "s/-p //g" | xargs -r git show-branch --independent | sed "s/\</-p /g"' \
37	--prune-empty --state-branch refs/heads/filter-state \
38	-- $RANGE
39
40git branch -f $UPSTREAM_MASTER FETCH_HEAD
41