blob: 64b2867c41e5e4890042281b68252ddcbfa1fc80 [file] [log] [blame]
#!/bin/sh
# Copyright 2018 Fairphone B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Exported globals:
# DEBUG
# SHELL_LIBS
# VERBOSE
set -e
export SHELL_LIBS="$(dirname $(readlink -f $0))/../shell-libs"
. "${SHELL_LIBS}/utils.sh"
_usage() {
cat <<heredoc
Grep git logs for issues references. To be used in conjunction with the
manifest project security branch.
To set things up run:
```
repo init -u ssh://review.fairphone.software/manifest -b security
repo sync --current-branch
```
Usage:
$0 [--patterns "pattern1 pattern2"] [--projects "project1 project2"]
[--update] [-v|--verbose] [-d|--debug] [-h|--help]
Options:
--patterns "pattern ..." : Quote enclosed, space separated, list of
patterns to grep for. This includes Qcom Create
Point, Android bug IDs, CVE numbers, etc.
E.g. --patterns "2139907 2087428"
--projects "project ..." : Quote enclosed, space separated, list of
projects to `git log --grep` over.
E.g. --projects "kernel/caf/msm hardware/qcom/wlan"
--update : Update projects.
-v, --verbose : Show additional logging.
-d, --debug : Show commands being run. I.e. set -x.
-h, --help : Print this help message.
Example:
$0 --patterns "2087428 2139907" --projects "kernel/aosp/msm kernel/caf/msm"
heredoc
}
while [ $# -gt 0 ]; do
case "$1" in
--patterns)
if [ $# -lt 2 ]; then
_usage >&2
exit 1
fi
PATTERNS="$2"
shift 2
;;
--projects)
if [ $# -lt 2 ]; then
_usage >&2
exit 1
fi
REPO_PROJECTS="$2"
shift 2
;;
--update)
UPDATE="true"
shift 1
;;
-v|--verbose)
export VERBOSE="--verbose"
shift 1
;;
-d|--debug)
set -x
export DEBUG="true"
shift 1
;;
-h|--help)
_usage
exit 0
;;
*)
echo "Unknown option $*" >&2
_usage >&2
exit 1
;;
esac
done
REPO_FORALL_FUNCTIONS="${SHELL_LIBS}/repo-forall-functions.sh"
if [ ! -f "${REPO_FORALL_FUNCTIONS}" ] ; then
log_e "Unable to find repo-forall-functions.sh"
fi
# Navigate to the Android's root
croot
[ -n "${UPDATE}" ] && repo sync --network-only
if [ -n "${PATTERNS}" ] ; then
repo_forall='repo --no-pager forall --abort-on-errors --verbose'
${repo_forall} ${REPO_PROJECTS} --command \
'. $1; \
git_grep $2' \
"${REPO_FORALL_FUNCTIONS}" "${PATTERNS}"
fi