• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3
4if git rev-parse --verify HEAD >/dev/null 2>&1
5then
6 against=HEAD
7else
8 # Initial commit: diff against an empty tree object
9 against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
10fi
11
12# disallow ALOGW and ALOGE
13if git diff --cached | grep "^\(+\| +\)" | grep -w 'ALOG[WE]\(_IF\)\?' > /dev/null; then
14  cat <<\EOF
15ERROR: Attempt to add ALOGW or ALOGE. These should be used only if something
16       is truly catastrophic to the running application. Use ALOGI for
17       important errors, ALOGD for mundane errors, and ALOGV for unimportant
18       logs (don't use ALOGV for errors so they can be debugged).
19
20If you are confident that the following uses are justified, commit this change with
21
22  git commit --no-verify
23
24EOF
25  git diff --cached --diff-filter AM --color -G 'ALOG[WE](_IF)?' -- | awk '
26  BEGIN { found=0 }
27  /^\033\[[0-9]+m(@@|\+\+\+|\-\-\-)/ {
28    if (found) { print substr(chunk, 2); found=0; chunk="" }
29    if (match($1, "[-+]")) { print }
30    else { chunk="\n" $0 }
31    next
32  }
33  /^\033\[[0-9]+m ?\+/ {
34    if (match($0, "\\<(ALOG[WE](_IF)?)\\>")) {
35      found=1;
36      chunk=chunk "\n" gensub("\\<(ALOG[WE](_IF)?)\\>", "\033[7m\\1\033[27m", "g")
37    } else {
38      chunk=chunk "\n" $0
39    }
40    next
41  }
42  {
43    chunk=chunk "\n" $0
44  }
45  END { if (found) { print substr(chunk, 2) } }
46'
47  exit 1
48fi
49
50# If there are whitespace errors, print the offending file names and fail.
51exec git diff-index --check --cached $against --
52