From e1d0cc23a9f09007c716d27874e3296cb81149da Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 24 Sep 2017 18:28:51 -0700 Subject: [PATCH 1/2] Improve git-subtree-check.sh We have several pieces of information about subtrees: 1) What their current directory contents is 2) What their directory contents was at the time of the last subtree merge 3) What the directory contents of the upstream project is in the commit referred to by the subtree merge. Normally, all 3 should be identical. git-subtree-check.sh so far only compared (1) with (3) however. Fix this by comparing all three, and give some more useful diff output in the case of mismatch. The added benefit is that (1) and (2) can be compared without needing to see the upstream repository. --- contrib/devtools/git-subtree-check.sh | 35 ++++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/contrib/devtools/git-subtree-check.sh b/contrib/devtools/git-subtree-check.sh index 2384d66ca..00ea7fb85 100755 --- a/contrib/devtools/git-subtree-check.sh +++ b/contrib/devtools/git-subtree-check.sh @@ -41,21 +41,17 @@ find_latest_squash() done } +# find latest subtree update latest_squash="$(find_latest_squash "$DIR")" if [ -z "$latest_squash" ]; then echo "ERROR: $DIR is not a subtree" >&2 exit 2 fi - set $latest_squash old=$1 rev=$2 -if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then - echo "ERROR: subtree commit $rev unavailable. Fetch/update the subtree repository" >&2 - exit 2 -fi -tree_subtree=$(git show -s --format="%T" $rev) -echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)" + +# get the tree in the current commit tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1) if [ -z "$tree_actual" ]; then echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2 @@ -69,9 +65,30 @@ if [ "d$tree_actual_type" != "dtree" ]; then echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2 exit 1 fi + +# get the tree at the time of the last subtree update +tree_commit=$(git show -s --format="%T" $old) +echo "$DIR in $COMMIT was last updated in commit $old (tree $tree_commit)" + +# ... and compare the actual tree with it +if [ "$tree_actual_tree" != "$tree_commit" ]; then + git diff $tree_commit $tree_actual_tree >&2 + echo "FAIL: subtree directory was touched without subtree merge" >&2 + exit 1 +fi + +# get the tree in the subtree commit referred to +if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then + echo "subtree commit $rev unavailable: cannot compare" >&2 + exit +fi +tree_subtree=$(git show -s --format="%T" $rev) +echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)" + +# ... and compare the actual tree with it if [ "$tree_actual_tree" != "$tree_subtree" ]; then - git diff-tree $tree_actual_tree $tree_subtree >&2 - echo "FAIL: subtree directory tree doesn't match subtree commit tree" >&2 + echo "FAIL: subtree update commit differs from upstream tree!" >&2 exit 1 fi + echo "GOOD" From 487aff42184117ae3b8be4381b77587448e297a5 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 24 Sep 2017 18:32:57 -0700 Subject: [PATCH 2/2] Check subtree consistency in Travis --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0de7ca6f7..2c9f239a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,10 @@ install: - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi before_script: - if [ "$CHECK_DOC" = 1 -a "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then contrib/devtools/commit-script-check.sh $TRAVIS_COMMIT_RANGE; fi + - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/git-subtree-check.sh src/crypto/ctaes; fi + - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/git-subtree-check.sh src/secp256k1; fi + - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/git-subtree-check.sh src/univalue; fi + - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/git-subtree-check.sh src/leveldb; fi - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/check-doc.py; fi - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/check-rpc-mappings.py .; fi - if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/lint-all.sh; fi