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

Re: [PATCH v6] diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 17, 2013, 19:29 UTC
Message-ID
<xmqqmwm71ysp.fsf@gitster.dls.corp.google.com>
In-Reply-To
<89A4E8C6-C233-49E2-8141-837ABDBBC976@gmail.com>
Yoshioka Tsuneo <yoshiokatsuneo@gmail.com> writes:
Show 15 quoted lines
> "git diff -M --stat" can detect rename and show renamed file name like
> "foofoofoo => barbarbar".
> Before this commit, this output is shortened always by omitting left most
> part like "...foo => barbarbar". So, if the destination filename is too long,
> source filename putting left or arrow can be totally omitted like
> "...barbarbar", without including any of "foofoofoo =>".
> In such a case where arrow symbol is omitted, there is no way to know
> whether the file is renamed or existed in the original.
> Make sure there is always an arrow, like "...foo => ...bar".
> The output can contain curly braces('{','}') for grouping.
> So, in general, the output format is "<pfx>{<mid_a> => <mid_b>}<sfx>"
> To keep arrow("=>"), try to omit <pfx> as long as possible at first
> because later part or changing part will be the more important part.
> If it is not enough, shorten <mid_a>, <mid_b>, and <sfx> trying to
> have the maximum length the same because those will be equally important.

I somehow find this solid wall of text extremely hard to read. Adding a blank line as a paragraph break may make it easier to read, perhaps.

Also it is customary in our history to omit the full-stop from the patch title on the Subject: line.

Show 7 quoted lines
> +	name_len = pfx->len + a_mid->len + b_mid->len + sfx->len + strlen(arrow)
> +		+ (use_curly_braces ? 2 : 0);
> +
> +	if (name_len <= name_width) {
> +		/* Everthing fits in name_width */
> +		return;
> +	}

Logic up to this point seems good; drop {} around a single statement "return;", i.e.

	if (name_len <= name_width)
        	return; /* everything fits */
Show 9 quoted lines
> +		} else {
> +			if (pfx->len > strlen(dots)) {
> +				/*
> +				 * Just omitting left of '{' is not enough
> +				 * name will be "...{SOMETHING}SOMETHING"
> +				 */
> +				strbuf_reset(pfx);
> +				strbuf_addstr(pfx, dots);
> +			}

(mental note) ... otherwise, i.e. with a short common prefix, the final result will be "ab{SOMETHING}SOMETHING", which is also fine for the purpose of the remainder of this function.

Show 13 quoted lines
> +		}
> +	}
> +
> +	/* available length for a_mid, b_mid and sfx */
> +	len = name_width - strlen(arrow) - (use_curly_braces ? 2 : 0);
> +
> +	/* a_mid, b_mid, sfx will be have the same max, including ellipsis("..."). */
> +	part_length[0] = a_mid->len;
> +	part_length[1] = b_mid->len;
> +	part_length[2] = sfx->len;
> +
> +	qsort(part_length, sizeof(part_length)/sizeof(part_length[0]), sizeof(part_length[0])
> +		  , compare_size_t_descending_order);

In our code, comma does not come at the beginning of continued line.

Show 6 quoted lines
> +	if (part_length[1] + part_length[1] + part_length[2] <= len) {
> +		/*
> +		 * "{...foofoo => barbar}file"
> +		 * There is only one omitted part.
> +		 */
> +		max_part_len = len - part_length[1] - part_length[2];

It would be clearer to explicitly set remainder to zero here, and omit the initialization of the variable. That would make what the three parts of if/elseif/else do more consistent.

Show 15 quoted lines
> +	} else if (part_length[2] + part_length[2] + part_length[2] <= len) {
> +		/*
> +		 * "{...foofoo => ...barbar}file"
> +		 * There are 2 omitted parts.
> +		 */
> +		max_part_len = (len - part_length[2]) / 2;
> +		remainder_part_len = (len - part_length[2]) - max_part_len * 2;
> +	} else {
> +		/*
> +		 * "{...ofoo => ...rbar}...file"
> +		 * There are 3 omitted parts.
> +		 */
> +		max_part_len = len / 3;
> +		remainder_part_len = len - (max_part_len) * 3;
> +	}

I am not sure if distributing the burden of truncation equally to three parts so that the resulting pieces are of similar lengths is really a good idea. Between these two

	{...SourceDirectory => ...nationDirectory}...ileThatWasMoved 
	{...ceDirectory => ...ionDirectory}nameOfTheFileThatWasMoved

that attempt to show that the file nameOfTheFileThatWasMoved was moved from the longSourceDirectory to the DestinationDirectory, the latter is much more informative, I would think.

Show 18 quoted lines
> diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh
> index 2f327b7..03d6371 100755
> --- a/t/t4001-diff-rename.sh
> +++ b/t/t4001-diff-rename.sh
> @@ -156,4 +156,16 @@ test_expect_success 'rename pretty print common prefix and suffix overlap' '
>  	test_i18ngrep " d/f/{ => f}/e " output
>  '
>  
> +test_expect_success 'rename of very long path shows =>' '
> +	mkdir long_dirname_that_does_not_fit_in_a_single_line &&
> +	mkdir another_extremely_long_path_but_not_the_same_as_the_first &&
> +	cp path1 long_dirname*/ &&
> +	git add long_dirname*/path1 &&
> +	test_commit add_long_pathname &&
> +	git mv long_dirname*/path1 another_extremely_*/ &&
> +	test_commit move_long_pathname &&
> +	git diff -M --stat HEAD^ HEAD >output &&
> +	test_i18ngrep "=>.*path1" output

Does this have to be i18ngrep? I had a feeling that we would not want this part of the output localized, in which case "grep" may be more appropriate.

> +'
> +
>  test_done
Previous: Yoshioka TsuneoNext: Yoshioka Tsuneo
Message 19 of 31 in “diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.”
  1. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 11, 2013
  2. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 11, 2013
  3. Sam VilainOct 11, 2013
  4. Keshav KiniOct 12, 2013
  5. Yoshioka TsuneoOct 12, 2013
  6. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 12, 2013
  7. Thomas RastOct 13, 2013
  8. Yoshioka TsuneoOct 15, 2013
  9. Duy NguyenOct 14, 2013
  10. Yoshioka TsuneoOct 15, 2013
  11. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 15, 2013
  12. Felipe ContrerasOct 15, 2013
  13. Yoshioka TsuneoOct 15, 2013
  14. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 15, 2013
  15. Junio C HamanoOct 15, 2013
  16. Keshav KiniOct 15, 2013
  17. Yoshioka TsuneoOct 16, 2013
  18. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 16, 2013
  19. Junio C HamanoOct 17, 2013
  20. Yoshioka TsuneoOct 17, 2013
  21. Junio C HamanoOct 17, 2013
  22. Yoshioka TsuneoOct 18, 2013
  23. Junio C HamanoOct 17, 2013
  24. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visibleYoshioka Tsuneo, Oct 17, 2013
  25. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visibleYoshioka Tsuneo, Oct 18, 2013
  26. Thomas RastOct 19, 2013
  27. Yoshioka TsuneoOct 20, 2013
  28. Junio C HamanoOct 22, 2013
  29. Yoshioka TsuneoOct 22, 2013
  30. Junio C HamanoOct 22, 2013
  31. diff.c: keep arrow(=>) on show_stats()'s shortened filename part to make rename visible.Yoshioka Tsuneo, Oct 12, 2013

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.