1 # git diff | awk -f thisfile.awk
  2 
  3 function printHunk() {
  4     if (!diff_header_has_been_output) {
  5         diff_header_has_been_output = 1
  6         print diff_header
  7     }
  8     if (!index_header_has_been_output) {
  9         index_header_has_been_output = 1
 10         print index_header
 11     }
 12     if (!plus_header_has_been_output) {
 13         plus_header_has_been_output = 1
 14         print plus_header
 15     }
 16     if (!minus_header_has_been_output) {
 17         minus_header_has_been_output = 1
 18         print minus_header
 19     }
 20     for(n=0; n < iHunkLines; n++) {
 21         print hunk_lines[n]
 22     }
 23 }
 24 
 25 function forgetHunk() {
 26     delete hunk_lines
 27     delete additions
 28     delete deletions
 29     iAdditions=0
 30     iDeletions=0
 31     iHunkLines=0
 32 }
 33 
 34 function checkcasediff() {
 35     print_this_hunk = 0
 36     if (iAdditions == iDeletions) {
 37         is_case_only = 1
 38         for( n = 0; n < iDeletions; n++ ) {
 39             if (tolower(additions[n]) != tolower(deletions[n])) {
 40                 is_case_only = 0
 41             }
 42         }
 43         if (is_case_only) {
 44             print_this_hunk = 0
 45         } else {
 46             print_this_hunk = 1
 47         }
 48     } else {
 49         print_this_hunk = 1
 50     }
 51     if (print_this_hunk) {
 52         printHunk()
 53     } else {
 54         forgetHunk()
 55     }
 56 }
 57  
 58 /^@@/ {
 59     if (!previous_hunk_exists) {
 60         # Before first hunk. Store header and move on
 61         previous_hunk_exists = 1
 62     } else {
 63         checkcasediff()
 64     }
 65     hunk_lines[iHunkLines++] = $0
 66     next
 67 }
 68 
 69 /^---/ {
 70     minus_header_has_been_output = 0
 71     minus_header = $0
 72     next
 73 }
 74 
 75 /^\+\+\+/ {
 76     plus_header_has_been_output = 0
 77     plus_header = $0
 78     print plus_header
 79     next
 80 }
 81 
 82 /^diff/ {
 83     diff_header_has_been_output = 0
 84     diff_header = $0
 85     next
 86 }
 87 
 88 /^index/ {
 89     index_header_has_been_output = 0
 90     index_header = $0
 91     next
 92 }
 93 
 94 /^\+[^\+]/ {
 95     hunk_lines[iHunkLines++] = $0
 96     # Strip off + or -
 97     additions[iAdditions++] = substr($0, 2)
 98     next
 99 }
100 
101 /^-[^-]/ {
102     hunk_lines[iHunkLines++] = $0
103     # Strip off + or -
104     deletions[iDeletions++] = substr($0, 2)
105     next
106 }
107 
108 {
109     hunk_lines[iHunkLines++] = $0
110     next
111 }
112 
113 END {
114     checkcasediff()
115 }