git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 25, 2018, 18:36 UTC
Message-ID
<xmqqo9clpgox.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<21214cc321f80cf2e9eb0cdb1ec3ebb869ea496d.1537542952.git.gitgitgadget@gmail.com>
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +files=$(git diff --name-only $V1 $V2 -- *.c)

You'd want to quote that *.c from the shell, i.e. either one of these

	files=$(git diff --name-only $V1 $V2 -- \*.c)
	files=$(git diff --name-only $V1 $V2 -- '*.c')
otherwise you'd lose things like "builtin/am.c", I'd think.
> +
> +for file in $files
> +do

I know this is only for running in _our_ source tree, and we do not have a source with $IFS in it, so I'd declare that this is OK. It would be good to document that assumption in red capital letters at the beginning of this loop, though ;-)

	# Note: this script is only for our codebase and we rely on
	# the fact that the pathnames of our source files do not
	# have any funny characters---letting the shell split $files
	# list at $IFS boundary is very much intentional, and not
	# quoting "$file" in the code below also is.  Don't imitate
	# this in scripts that are meant to handle random end-user
	# repositories!
	for file in $files
	do
		...
> +	git diff $V1 $V2 -- $file \
> +		| diff_lines \
> +		| sort >new_lines.txt

I do not see a strong reason why we would want to limit $V1 and $V2 to branch names and raw commit object names, and quoting them in dq pair is a cheap fix to allow things like

	$ contrib/coverage-diff.sh master 'pu^{/^### match next}'
so let's do so.
Could you cut lines _after_ typing a pipe and omit backslashes, i.e.
	git diff "$V1" "$V2" -- $file |
	diff_lines |
	sort >new_lines.txt

It seems to be personal taste whether to indent the second and subsequent lines; I do not care if you indent or if you align too much either way (but I have moderate perference to align).

But I do not want to see people type unnecessary backslashes. This is not limited to just this pipeline but elsewhere in the script.

Show 17 quoted lines
> +	if ! test -s new_lines.txt
> +	then
> +		continue
> +	fi
> +
> +	hash_file=$(echo $file | sed "s/\//\#/")
> +	sed -ne '/#####:/{
> +			s/    #####://
> +			s/:.*//
> +			s/ //g
> +			p
> +		}' "$hash_file.gcov" \
> +		| sort >uncovered_lines.txt
> +
> +	comm -12 uncovered_lines.txt new_lines.txt \
> +		| sed -e 's/$/\)/' \
> +		| sed -e 's/^/\t/' \
Do you need two sed invocations for this, or would
	sed -e 's/$/\)/' -e '/^/	/'

work as well? By the way """The meaning of an unescaped <backslash> immediately followed by any character other than '&', <backslash>, a digit, <newline>, or the delimiter character used for this command, is unspecified."""[*1*] so '\t' on the replacement side is a no-no in the portability department.

	Reference. *1*
	http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
> +		>uncovered_new_lines.txt
> +
> +	grep -q '[^[:space:]]' < uncovered_new_lines.txt && \

Lose the backslash at the end. The shell knows that you haven't finished your sentence when it sees a line that ends with &&, || or a pipe |, so there is no need to tell it redundantly that you have more things to say with the backslash.

Show 6 quoted lines
> +		echo $file && \
> +		git blame -c $file \
> +			| grep -f uncovered_new_lines.txt
> +
> +	rm -f new_lines.txt uncovered_lines.txt uncovered_new_lines.txt
> +done

Near the begininng (like just before the "for file in $files" loop), you can probably have a trap to make sure these are removed upon exit, e.g.

    trap 'rm -f new_lines.txt uncovered_lines.txt uncovered_new_lines.txt' 0
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee
Message 17 of 22 in “contrib: Add script to show uncovered "new" lines”
  1. 0/1 contrib: Add script to show uncovered "new" linesDerrick Stolee via GitGitGadget, Sep 12, 2018
  2. 1/1 contrib: add coverage-diff scriptDerrick Stolee via GitGitGadget, Sep 12, 2018
  3. Junio C HamanoSep 12, 2018
  4. Junio C HamanoSep 12, 2018
  5. Derrick StoleeSep 13, 2018
  6. Junio C HamanoSep 13, 2018
  7. Derrick StoleeSep 12, 2018
  8. Ben PeartSep 12, 2018
  9. Junio C HamanoSep 12, 2018
  10. 0/1 contrib: Add script to show uncovered "new" linesDerrick Stolee via GitGitGadget, Sep 13, 2018
  11. 1/1 contrib: add coverage-diff scriptDerrick Stolee via GitGitGadget, Sep 13, 2018
  12. Junio C HamanoSep 13, 2018
  13. Derrick StoleeSep 13, 2018
  14. Eric SunshineSep 13, 2018
  15. 0/1 contrib: Add script to show uncovered "new" linesDerrick Stolee via GitGitGadget, Sep 21, 2018
  16. 1/1 contrib: add coverage-diff scriptDerrick Stolee via GitGitGadget, Sep 21, 2018
  17. Junio C HamanoSep 25, 2018
  18. Derrick StoleeSep 21, 2018
  19. 0/1 contrib: Add script to show uncovered "new" linesDerrick Stolee via GitGitGadget, Oct 8, 2018
  20. 1/1 contrib: add coverage-diff scriptDerrick Stolee via GitGitGadget, Oct 8, 2018
  21. Junio C HamanoOct 12, 2018
  22. Derrick StoleeOct 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.