Web lists-archives.com

Re: [PATCH v2 1/1] contrib: add coverage-diff script

On 9/13/2018 1:40 PM, Junio C Hamano wrote:
"Derrick Stolee via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes:
+			then
+				line_num=$(($line_num + 1))
+			fi
+		fi
+	done
I have a feeling that a single Perl script instead of a shell loop
that runs many grep and awk as subprocesses performs better even on
Windows, and it would be more readable and maintainable.

perl -e '
	my $line_num;
	while (<>) {
		# Hunk header?  Grab the beginning in postimage.
		if (/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/) {
			$line_num = $1;

		# Have we seen a hunk?  Ignore "diff --git" etc.
		next unless defined $line_num;

		# Deleted line? Ignore.
		if (/^-/) {

		# Show only the line number of added lines.
		if (/^\+/) {
			print "$line_num\n";
		# Either common context or added line appear in
		# the postimage.  Count it.

or something like that, given that you seem to only need line
numbers in new_lines.txt anyway?

Thanks for the deep dive here, especially with the perl assistance. I've never written any perl, but it seems like the right tool here. I'll have time to revisit this next week.