]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tools: support unclean working directory
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 14 Dec 2017 20:41:37 +0000 (15:41 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 20 Dec 2017 17:54:10 +0000 (12:54 -0500)
Adds ability to still work even when the user's base FRR directory is
not clean by caching index, working directory and deletion state in
various locations then restoring after done.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
tools/checkpatch.sh

index da23d266a11e973c5d5aa176342d425e2bfe0539..a8de999089e731d1afab618236b14c7b9abb3f6a 100755 (executable)
@@ -3,16 +3,41 @@
 # Usage:
 #      ./checkpatch.sh <patch>
 checkpatch="./checkpatch.pl --no-tree -f"
+ignore="ldpd\|babeld"
+cwd=${PWD##*/}
+dirty=0
 
-git status | grep "working directory clean"
-if [ $? -ne 0 ]; then
-       echo "[!] git working directory must be clean."
-       exit 1
+# check running from frr/tools/
+if [[ $cwd != *"tools"* ]]; then
+  echo "[!] script must be run from tools/ directory"
+  exit 1
 fi
 
+# save working tree
+cd ..
+if git status --porcelain | egrep --silent '^(\?\?|.[DM])'; then
+  echo "Detected dirty tree, caching state..."
+  dirty=1
+  git config gc.auto 0;
+  td=$(git status -z | grep -z "^[ARM]D" | cut -z -d' ' -f2- | tr '\0' '\n')
+  INDEX=`git write-tree`
+  git add -f .
+  WORKTREE=`git write-tree`
+  echo "Saved index to $INDEX"
+  echo "Saved working tree to $WORKTREE"
+fi
+
+# double check
+if git status --porcelain | egrep --silent '^(\?\?|.[DM])'; then
+  echo "[!] git working directory must be clean."
+  exit 1
+fi
+
+git reset --hard
+git apply $1 2> /dev/null
+cd tools
 mkdir -p f1 f2
-bash -c "cd .. && git apply $1 2> /dev/null"
-mod=$(git ls-files -m .. | grep ".*\.[ch]")
+mod=$(git ls-files -m .. | grep ".*\.[ch]" | grep -v $ignore)
 cp $mod f1/
 git reset --hard
 cp $mod f2/
@@ -23,6 +48,22 @@ for file in f2/*; do
   $checkpatch $file > "$file"_cp 2> /dev/null
 done
 for file in f1/*_cp; do
-  diff $file f2/$(basename $file) | grep -A3 "ERROR\|WARNING"
+  if [ -a f2/$(basename $file) ]; then
+    diff $file f2/$(basename $file) | grep -A3 "ERROR\|WARNING"
+  else
+    cat $file
+  fi
 done
 rm -rf f1 f2
+cd ..
+
+# restore working tree
+if [ $dirty -eq 1 ]; then
+  git read-tree $WORKTREE;
+  git checkout-index -af;
+  git read-tree $INDEX;
+  if [ -n "$td" ]; then
+    rm $td
+  fi
+  git config --unset gc.auto;
+fi