#! /usr/bin/awk -f function do_empty() { if (diff!="" && deleted!="" && indx!="") { printf("Make patch give the file 1 line\n"); printf("--- %s\n",diff); printf("+++ %s\n",diff); printf("@@ -0,0 +1 @@\n+\n"); printf("Make patch delete the 1 line file\n"); printf("--- %s\t\n",diff); printf("+++ /dev/null\t1970-01-01 01:00:00.000000000\n"); printf("@@ -1 +0,0 @@\n-\n"); } if (diff!="" && created!="" && indx!="") { printf("Make patch create the file with 1 line\n"); printf("--- %s\n",diff); printf("+++ %s\n",diff); printf("@@ -0,0 +1 @@\n+\n"); printf("Make patch create delete the line but keep the file\n"); printf("--- %s\n",diff); printf("+++ %s\n",diff); printf("@@ -1 +0,0 @@\n-\n"); } no_empty(); } function no_empty() { diff=""; deleted=""; created=""; indx=""; } { if (in_hunk > 0) in_hunk--; } /^diff --git / { do_empty(); if (! in_hunk) diff=$3; } /^deleted file mode / { if (! in_hunk && diff!="") deleted=$0; } /^new file mode / { if (! in_hunk && diff!="") created=$0; } /^index / { if (! in_hunk && diff!="") indx=$0; } /^--- / { no_empty(); } /^@@ / { # read the hunk size p=index($2,","); if (p==0) c1=1; else c1=strtonum(substr($2, p+1)); p=index($3,","); if (p==0) in_hunk=1; else in_hunk=strtonum(substr($2, p+1)); if (c1 > in_hunk) in_hunk=c1; } { print; } END { do_empty(); }