From 2dd5d9f07cb251f8d59bc6b90ba6e7b2d034d737 Mon Sep 17 00:00:00 2001
From: Scott Little <scott.little@windriver.com>
Date: Thu, 27 Aug 2020 14:21:47 -0400
Subject: [PATCH] Build contexts should not include .repo/repo

Build avoidance does not work reliably because directory
.repo/repo is being included in the build context.
This directory is the repo tool itself, not any of the
gits managed by the repo manifest.  The sha reported for
.repo/repo might not be available in users environmnet,
causing build avoidance to reject an otherwise valid
reference context.

Fix is in two parts.
1) Do not include .repo/repo in future build contexts.
2) Filter .repo/repo out of downloaded contexts before
use in build avoidance calculations.  This addresses
contexts that are already published.

Closes-Bug: 1893243
Change-Id: I7bd20597cb7bc5ee93ae49728176791c51e89c53
Signed-off-by: Scott Little <scott.little@windriver.com>
---
 build-tools/git-utils.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/build-tools/git-utils.sh b/build-tools/git-utils.sh
index 5058a9d7..a33bb503 100755
--- a/build-tools/git-utils.sh
+++ b/build-tools/git-utils.sh
@@ -27,7 +27,7 @@ git_ctx_root_dir () {
 git_list () {
     local DIR=${1}
 
-    find -L "${DIR}" -maxdepth 5 -type d -name '.git' -exec dirname {} \; | sort -V
+    find -L "${DIR}" -maxdepth 5 -type d -name '.git' -exec dirname {} \; | grep -v '[.]repo[/]repo$' | sort -V
 }
 
 
@@ -380,11 +380,12 @@ git_test_context () {
     # Limit search to last 500 commits in the interest of speed.
     # I don't expect to be using contexts more than a few weeks old.
     cat "$context" | \
-        sed "s#checkout -f \([a-e0-9]*\)#rev-list --max-count=500 HEAD | \
+        sed -e "s/\.repo\/repo/d" \
+            -e "s#checkout -f \([a-e0-9]*\)#rev-list --max-count=500 HEAD | \
         grep \1#" > $query
 
-    target_hits=$(cat "$context" | wc -l)
-    actual_hits=$(cd $(git_ctx_root_dir); source $query | wc -l)
+    target_hits=$(cat "$context" | grep -v '[.]repo[/]repo ' | wc -l)
+    actual_hits=$(cd $(git_ctx_root_dir); source $query 2> /dev/null | wc -l)
     \rm $query
 
     if [ $actual_hits -eq $target_hits ]; then