Blame


1 0f4372e2 2022-10-03 op # diffstat
2 0f4372e2 2022-10-03 op
3 0f4372e2 2022-10-03 op Show diff statistics.
4 0f4372e2 2022-10-03 op
5 0f4372e2 2022-10-03 op #!/usr/bin/awk -f
6 0f4372e2 2022-10-03 op
7 0f4372e2 2022-10-03 op maybe not 100% correct, but it's one case where being simple yet
8 0f4372e2 2022-10-03 op slightly wrong is way easier than correct. It's not a catastrophe to
9 0f4372e2 2022-10-03 op count some extra lines, while parsing the diff (possibly enclosed in a
10 0f4372e2 2022-10-03 op mail) is hard.
11 0f4372e2 2022-10-03 op
12 0f4372e2 2022-10-03 op /^\+/ { a++ }
13 0f4372e2 2022-10-03 op /^\-/ { m++ }
14 0f4372e2 2022-10-03 op
15 0f4372e2 2022-10-03 op Don't be a sink! Continue the pipeline so we can further save or apply
16 0f4372e2 2022-10-03 op the diff.
17 0f4372e2 2022-10-03 op
18 0f4372e2 2022-10-03 op // { print $0 }
19 0f4372e2 2022-10-03 op
20 0f4372e2 2022-10-03 op At the end, print the stats to standard error to avoid mangling the
21 0f4372e2 2022-10-03 op input. Unfortunately, there doesn't seem to be a "built-in" way of
22 0f4372e2 2022-10-03 op printing to stderr other than using the pseudo-device.
23 0f4372e2 2022-10-03 op
24 0f4372e2 2022-10-03 op END {
25 0f4372e2 2022-10-03 op print "+", a > "/dev/stderr"
26 0f4372e2 2022-10-03 op print "-", m > "/dev/stderr"
27 0f4372e2 2022-10-03 op }
28 0f4372e2 2022-10-03 op
29 0f4372e2 2022-10-03 op some example usages:
30 0f4372e2 2022-10-03 op
31 0f4372e2 2022-10-03 op * cvs -q di | diffstat | tee /tmp/diff | less
32 0f4372e2 2022-10-03 op * git diff | diffstat > /tmp/diff
33 0f4372e2 2022-10-03 op * got di | diffstat | ssh foo 'cd xyz && got patch'