forked from libbtc/libbtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_subtrees.sh
executable file
·60 lines (50 loc) · 2.08 KB
/
update_subtrees.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env sh
update_subtree() {
# set parameters
REMOTE="$1"
LOCAL_SUBDIR="$2"
REMOTE_SUBDIR="$3"
# get content from repository
git fetch "$REMOTE"
FETCH_HEAD="$(git describe --always FETCH_HEAD)"
SOURCE_HEAD="$FETCH_HEAD"
# if a remote subdir is set, split the content to only have that subdir
if test "x$REMOTE_SUBDIR" != "x"
then
touch "$REMOTE_SUBDIR" # this hack lets git-subtree split a non-worktree branch
SOURCE_HEAD="$(git subtree split --prefix "$REMOTE_SUBDIR" "$FETCH_HEAD")"
fi
MESSAGE="Merge subtree $LOCAL_SUBDIR from $REMOTE $REMOTE_SUBDIR $FETCH_HEAD"
# merge or add the subtree into the worktree
git subtree merge --squash --prefix src/"$LOCAL_SUBDIR" "$SOURCE_HEAD" --message "$MESSAGE" ||
git subtree add --squash --prefix src/"$LOCAL_SUBDIR" "$SOURCE_HEAD" --message "$MESSAGE"
}
copy_headers()
{
# set single parameter
SRCDIR="src/$1"
DSTDIR="include/btc"
shift 1
# for each header, mutate it to be like libbtc, and copy it in with a commit
for HEADER in "$@"
do
HEADERNAME=$(basename "$HEADER")
{ sed -f /dev/stdin "$SRCDIR"/"$HEADER" > "$DSTDIR"/"$HEADERNAME" <<HEADER_MUTATION_END
# prefix ifndef/define guard symbols with LIBBTC_ and add LIBBTCL_BEGIN_DECL
s/^\(#ifndef _\)_*\([^_]*.*[^_]\)_*_$/\1_LIBBTC_\2__/
s/^\(#define _\)_*\([^_]*.*[^_]\)_*_\(\s.*$\|$\)/\1_LIBBTC_\2__\n&\n\n#include "btc.h"\n\nLIBBTC_BEGIN_DECL/
# prefix functions with LIBBTC_API
s/^\(int\|void\|char\|bool\)/LIBBTC_API \1/
# add LIBBTC_END_DECL before end
$ s/^\(#endif\)$/LIBBTC_END_DECL\n\n\1/
HEADER_MUTATION_END
} &&
git add "$DSTDIR"/"$HEADERNAME" &&
git commit -m "Update $DSTDIR/$HEADERNAME from $SRCDIR/$HEADER"
done
}
# subtrees
update_subtree https://github.com/bitcoin-core/secp256k1 secp256k1
update_subtree https://github.com/trezor/trezor-firmware trezor-crypto crypto
# headers copied from subtrees
copy_headers trezor-crypto hmac.h sha2.h segwit_addr.h