Advertisement
devinteske

~/bin/diffnore

Jan 26th, 2016
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.41 KB | None | 0 0
  1. #!/bin/sh
  2. usage() {
  3.     exec >&2
  4.     echo "Usage: $0 [-d|-v] [-R regex] [-A regex]"
  5.     echo "Options:"
  6.     local optfmt="\t%-10s %s\n"
  7.     printf "$optfmt" "-d" "Debug. Output all lines without processing."
  8.     printf "$optfmt" "-v" "Verbose. Show ignore status for each hunk."
  9.     printf "$optfmt" "-A regex" "Ignore additions matching regex."
  10.     printf "$optfmt" "-R regex" "Ignore removals matching regex."
  11.     exit 1
  12. }
  13. addignore=
  14. rmignore=
  15. verbose=0
  16. while getopts A:dR:v flag; do
  17.     case "$flag" in
  18.     A) addignore="$OPTARG" ;;
  19.     d) debug=1 ;;
  20.     R) rmignore="$OPTARG" ;;
  21.     v) verbose=1 ;;
  22.     *) usage
  23.     esac
  24. done
  25. shift $(( $OPTIND - 1 ))
  26. svn diff -x -p | awk \
  27.     -v addignore="$addignore" \
  28.     -v debug="$debug" \
  29.     -v rmignore="$rmignore" \
  30.     -v verbose="$verbose" ' # START-AWK
  31. debug { print; next }
  32. /^--- / { file++; getline; files[file] = $2; hunk = 0; next }
  33. /^@@ / { hunks[file] = ++hunk; rm = add = 0; next }
  34. /^-/ { if (!rmignore || $0 !~ rmignore) rms[file,hunk] = ++rm }
  35. /^\+/ { if (!addignore || $0 !~ addignore) adds[file,hunk] = ++add }
  36. END { for (f = 1; f <= file; f++) {
  37.     if (verbose) printf "%4s > %s (%u hunks)\n", "#" f, files[f], hunks[f]
  38.     for (h = 1; h <= hunks[f]; h++) {
  39.         if (verbose) printf "%6s Hunk %3u = -%u/+%u",
  40.             "", h, rms[f,h], adds[f,h]
  41.         ignore = (rms[f,h] < 1 && adds[f,h] < 1)
  42.         if (verbose) printf " %s\n", ignore ? "**IGNORED**" : ""
  43.         else if (ignore) print "ignore", files[f]
  44.     }
  45. }}' # END-AWK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement