Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- usage() {
- exec >&2
- echo "Usage: $0 [-d|-v] [-R regex] [-A regex]"
- echo "Options:"
- local optfmt="\t%-10s %s\n"
- printf "$optfmt" "-d" "Debug. Output all lines without processing."
- printf "$optfmt" "-v" "Verbose. Show ignore status for each hunk."
- printf "$optfmt" "-A regex" "Ignore additions matching regex."
- printf "$optfmt" "-R regex" "Ignore removals matching regex."
- exit 1
- }
- addignore=
- rmignore=
- verbose=0
- while getopts A:dR:v flag; do
- case "$flag" in
- A) addignore="$OPTARG" ;;
- d) debug=1 ;;
- R) rmignore="$OPTARG" ;;
- v) verbose=1 ;;
- *) usage
- esac
- done
- shift $(( $OPTIND - 1 ))
- svn diff -x -p | awk \
- -v addignore="$addignore" \
- -v debug="$debug" \
- -v rmignore="$rmignore" \
- -v verbose="$verbose" ' # START-AWK
- debug { print; next }
- /^--- / { file++; getline; files[file] = $2; hunk = 0; next }
- /^@@ / { hunks[file] = ++hunk; rm = add = 0; next }
- /^-/ { if (!rmignore || $0 !~ rmignore) rms[file,hunk] = ++rm }
- /^\+/ { if (!addignore || $0 !~ addignore) adds[file,hunk] = ++add }
- END { for (f = 1; f <= file; f++) {
- if (verbose) printf "%4s > %s (%u hunks)\n", "#" f, files[f], hunks[f]
- for (h = 1; h <= hunks[f]; h++) {
- if (verbose) printf "%6s Hunk %3u = -%u/+%u",
- "", h, rms[f,h], adds[f,h]
- ignore = (rms[f,h] < 1 && adds[f,h] < 1)
- if (verbose) printf " %s\n", ignore ? "**IGNORED**" : ""
- else if (ignore) print "ignore", files[f]
- }
- }}' # END-AWK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement