Skip to content

Commit 7c6bfb1

Browse files
committed
Merge pull request #5965
5ff94c6 Add git-subtree-check.sh script (Pieter Wuille)
2 parents 91cba1a + 5ff94c6 commit 7c6bfb1

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

contrib/devtools/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,16 @@ It will do the following automatically:
8181

8282
See doc/translation-process.md for more information.
8383

84+
git-subtree-check.sh
85+
====================
86+
87+
Run this script from the root of the repository to verify that a subtree matches the contents of
88+
the commit it claims to have been updated to.
89+
90+
To use, make sure that you have fetched the upstream repository branch in which the subtree is
91+
maintained:
92+
* for src/secp256k1: https://github.com/bitcoin/secp256k1.git (branch master)
93+
* for sec/leveldb: https://github.com/bitcoin/leveldb.git (branch bitcoin-fork)
94+
95+
Usage: git-subtree-check.sh DIR COMMIT
96+
COMMIT may be omitted, in which case HEAD is used.

contrib/devtools/git-subtree-check.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
3+
DIR="$1"
4+
COMMIT="$2"
5+
if [ -z "$COMMIT" ]; then
6+
COMMIT=HEAD
7+
fi
8+
9+
# Taken from git-subtree (Copyright (C) 2009 Avery Pennarun <[email protected]>)
10+
find_latest_squash()
11+
{
12+
dir="$1"
13+
sq=
14+
main=
15+
sub=
16+
git log --grep="^git-subtree-dir: $dir/*\$" \
17+
--pretty=format:'START %H%n%s%n%n%b%nEND%n' "$COMMIT" |
18+
while read a b junk; do
19+
case "$a" in
20+
START) sq="$b" ;;
21+
git-subtree-mainline:) main="$b" ;;
22+
git-subtree-split:) sub="$b" ;;
23+
END)
24+
if [ -n "$sub" ]; then
25+
if [ -n "$main" ]; then
26+
# a rejoin commit?
27+
# Pretend its sub was a squash.
28+
sq="$sub"
29+
fi
30+
echo "$sq" "$sub"
31+
break
32+
fi
33+
sq=
34+
main=
35+
sub=
36+
;;
37+
esac
38+
done
39+
}
40+
41+
latest_squash="$(find_latest_squash "$DIR")"
42+
if [ -z "$latest_squash" ]; then
43+
echo "ERROR: $DIR is not a subtree" >&2
44+
exit 2
45+
fi
46+
47+
set $latest_squash
48+
old=$1
49+
rev=$2
50+
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then
51+
echo "ERROR: subtree commit $rev unavailable. Fetch/update the subtree repository" >&2
52+
exit 2
53+
fi
54+
tree_subtree=$(git show -s --format="%T" $rev)
55+
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
56+
tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1)
57+
if [ -z "$tree_actual" ]; then
58+
echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2
59+
exit 1
60+
fi
61+
set $tree_actual
62+
tree_actual_type=$2
63+
tree_actual_tree=$3
64+
echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree"
65+
if [ "d$tree_actual_type" != "dtree" ]; then
66+
echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2
67+
exit 1
68+
fi
69+
if [ "$tree_actual_tree" != "$tree_subtree" ]; then
70+
git diff-tree $tree_actual_tree $tree_subtree >&2
71+
echo "FAIL: subtree directory tree doesn't match subtree commit tree" >&2
72+
exit 1
73+
fi
74+
echo "GOOD"

0 commit comments

Comments
 (0)