hooks: add some hooks for pre-submit

Install via hooks/install

Bug: 90469941
diff --git a/hooks/install b/hooks/install
new file mode 100755
index 0000000..23e0637
--- /dev/null
+++ b/hooks/install
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+if [ $(basename "$0") != "install" ]; then
+  if [ -x "$0.local" ]; then
+    "$0.local" "$@" || exit $?
+  fi
+  if [ -x hooks/$(basename $0) ]; then
+    hooks/$(basename $0) "$0" || exit $?
+  fi
+else
+  pushd "$(git rev-parse --show-toplevel)"
+  python <<\EOF
+import os, os.path
+TOP = os.path.realpath(".")
+HOOKS = os.path.realpath(".git/hooks")
+src = os.path.join(TOP, "hooks", "install")
+for hook in os.listdir("hooks"):
+  if hook != "install":
+    tgt = HOOKS + os.sep + hook
+    # there is a file there
+    if os.path.isfile(tgt) and os.access(tgt, os.X_OK):
+      if os.path.realpath(tgt) != src:
+        print("hook " + hook + " is already installed. Moving to " + hook + ".local")
+        os.rename(tgt, tgt + ".local")
+    if os.path.lexists(tgt):
+      os.unlink(tgt)
+    os.symlink(os.path.relpath(os.path.realpath("hooks/install"), os.path.realpath(".git/hooks/")), tgt)
+EOF
+  popd
+fi
diff --git a/hooks/pre-commit b/hooks/pre-commit
new file mode 100755
index 0000000..b840cc7
--- /dev/null
+++ b/hooks/pre-commit
@@ -0,0 +1,51 @@
+#!/bin/sh
+#
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+# disallow ALOGW and ALOGE
+if git diff --cached | grep "^\(+\| +\)" | grep -w 'ALOG[WE]\(_IF\)\?' > /dev/null; then
+  cat <<\EOF
+ERROR: Attempt to add ALOGW or ALOGE. These should be used only if something
+       is truly catastrophic to the running application. Use ALOGI for
+       important errors, ALOGD for mundane errors, and ALOGV for unimportant
+       logs (don't use ALOGV for errors so they can be debugged).
+
+If you are confident that the following uses are justified, commit this change with
+
+  git commit --no-verify
+
+EOF
+  git diff --cached --diff-filter AM --color -G 'ALOG[WE](_IF)?' -- | awk '
+  BEGIN { found=0 }
+  /^\033\[[0-9]+m(@@|\+\+\+|\-\-\-)/ {
+    if (found) { print substr(chunk, 2); found=0; chunk="" }
+    if (match($1, "[-+]")) { print }
+    else { chunk="\n" $0 }
+    next
+  }
+  /^\033\[[0-9]+m ?\+/ {
+    if (match($0, "\\<(ALOG[WE](_IF)?)\\>")) {
+      found=1;
+      chunk=chunk "\n" gensub("\\<(ALOG[WE](_IF)?)\\>", "\033[7m\\1\033[27m", "g")
+    } else {
+      chunk=chunk "\n" $0
+    }
+    next
+  }
+  {
+    chunk=chunk "\n" $0
+  }
+  END { if (found) { print substr(chunk, 2) } }
+'
+  exit 1
+fi
+
+# If there are whitespace errors, print the offending file names and fail.
+exec git diff-index --check --cached $against --