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

Re: [PATCH v2 3/4] add--helper: implement interactive status command

From
Junio C Hamano <gitster@pobox.com>
Date
May 16, 2017, 04:39 UTC
Message-ID
<xmqqinl12z5d.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1494907234-28903-4-git-send-email-bnmvco@gmail.com>
Daniel Ferreira <bnmvco@gmail.com> writes:
Show 8 quoted lines
> +	if (!q->nr)
> +		return;
> +
> +	for (i = 0; i < q->nr; i++) {
> +		struct diff_filepair *p;
> +		p = q->queue[i];
> +		diff_flush_stat(p, options, &stat);
> +	}

Commenting just on the part that interacts with the diff machinery, without/before carefully reading the remainder of the patches.

I suspect that refactoring this part out of diff_flush() into a helper function "compute_diffstat()", like this:

diff --git a/diff.c b/diff.c
index 74283d9001..a42ff42e92 100644
--- a/diff.c
+++ b/diff.c
@@ -4770,12 +4770,7 @@ void diff_flush(struct diff_options *options)
 	    dirstat_by_line) {
 		struct diffstat_t diffstat;
 
-		memset(&diffstat, 0, sizeof(struct diffstat_t));
-		for (i = 0; i < q->nr; i++) {
-			struct diff_filepair *p = q->queue[i];
-			if (check_pair_status(p))
-				diff_flush_stat(p, options, &diffstat);
-		}
+		compute_diffstat(&options, &diffstat);
 		if (output_format & DIFF_FORMAT_NUMSTAT)
 			show_numstat(&diffstat, options);
 		if (output_format & DIFF_FORMAT_DIFFSTAT)

and then exporting that function and "struct diffstat_t" to your
helper, may make it a better API, rather than having the callers to
call diff_flush_stat() for each and every path.
Previous: Daniel FerreiraNext: Daniel Ferreira
Message 5 of 7 in “Port git-add--interactive.perl:status_cmd to C”
  1. 0/4 Port git-add--interactive.perl:status_cmd to CDaniel Ferreira, May 16, 2017
  2. 1/4 diff: export diffstat interfaceDaniel Ferreira, May 16, 2017
  3. 2/4 add--helper: create builtin helper for interactive addDaniel Ferreira, May 16, 2017
  4. 3/4 add--helper: implement interactive status commandDaniel Ferreira, May 16, 2017
  5. Junio C HamanoMay 16, 2017
  6. 4/4 add--interactive: use add-interactive--helper for status_cmdDaniel Ferreira, May 16, 2017
  7. Slavica DjukicNov 26, 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.