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

Re: [PATCH v2 1/2] commit: fix --short and --porcelain options

From
Junio C Hamano <gitster@pobox.com>
Date
May 2, 2018, 05:50 UTC
Message-ID
<xmqq36zawqr3.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180426092524.25264-2-sxlijin@gmail.com>
Samuel Lijin <sxlijin@gmail.com> writes:
Show 12 quoted lines
> Mark the commitable flag in the wt_status object in the call to
> `wt_status_collect()`, instead of in `wt_longstatus_print_updated()`,
> and simplify the logic in the latter function to take advantage of the
> logic shifted to the former. This means that callers do not need to use
> `wt_longstatus_print_updated()` to collect the `commitable` flag;
> calling `wt_status_collect()` is sufficient.
>
> As a result, invoking `git commit` with `--short` or `--porcelain`
> (which imply `--dry-run`, but previously returned an inconsistent error
> code inconsistent with dry run behavior) correctly returns status code
> zero when there is something to commit. This fixes two bugs documented
> in the test suite.

Hmm, I couldn't quite get what the above two paragraphs were trying to say, but I think I figured out by looking at wt_status.c before applying this patch, so let me see if I correctly understand what this patch is about by thinking a bit aloud.

There are only two assignments to s->commitable in wt-status.c; one happens in wt_longstatus_print_updated(), when the function notices there is even one record to be shown (i.e. there is an "updated" path) and the other in show_merge_in_progress() which is called by wt_longstatus_prpint_state(). The latter codepath happens when we are in a merge and there is no remaining conflicted paths (the code allows the contents to be committed to be identical to HEAD). Both are called from wt_longstatus_print(), which in turn is called by wt_status_print().

The implication of the above observation is that we do not set commitable bit (by the way, shouldn't we spell it with two 'T's?) if we are not doing the long format status. The title hints at it but "fix" is too vague. It would be easier to understand if it began like this (i.e. state problem clearly first, before outlining the solution):

	[PATCH 1/2] commit: fix exit status under --short/--porcelain options
	In wt-status.c, s->commitable bit is set only in the
	codepaths reachable from wt_status_print() when output
	format is STATUS_FORMAT_LONG as a side effect of printing
	bits of status.  Consequently, when running with --short and
	--porcelain options, the bit is not set to reflect if there
	is anything to be committed, and "git commit --short" or
	"--porcelain" (both of which imply "--dry-run") failed to
	signal if there is anything to commit with its exit status.
	Instead, update s->commitable bit in wt_status_collect(),
	regardless of the output format. ...

Is that what is going on here? Yours made it sound as if moving the code to _collect() was done for the sake of moving code around and simplifying the logic, and bugfix fell out of the move merely as a side effect, which probably was the source of my confusion.

Show 12 quoted lines
> +static void wt_status_mark_commitable(struct wt_status *s) {
> +	int i;
> +
> +	for (i = 0; i < s->change.nr; i++) {
> +		struct wt_status_change_data *d = (s->change.items[i]).util;
> +
> +		if (d->index_status && d->index_status != DIFF_STATUS_UNMERGED) {
> +			s->commitable = 1;
> +			return;
> +		}
> +	}
> +}

I am not sure if this is sufficient. From a cursory look of the existing code (and vague recollection in my ageing brain ;-), I think we say it is committable if

 (1) when not merging, there is something to show in the "to be
     committed" section (i.e. there must be something changed since
     HEAD in the index).
 (2) when merging, no conflicting paths remain (i.e. change.nr being
     zero is fine).

So it is unclear to me how you are dealing with (2) under "--short" option, which does not call show_merge_in_progress() to catch that case.

Previous: Samuel LijinNext: Samuel Lijin
Message 8 of 26 in “Fix --short and --porcelain options for commit”
  1. 0/2 Fix --short and --porcelain options for commitSamuel Lijin, Apr 18, 2018
  2. 1/2 commit: fix --short and --porcelainSamuel Lijin, Apr 18, 2018
  3. Martin ÅgrenApr 18, 2018
  4. Eric SunshineApr 20, 2018
  5. 2/2 wt-status: const-ify all printf helper methodsSamuel Lijin, Apr 18, 2018
  6. 0/2 Fix --short and --porcelain options for commitSamuel Lijin, Apr 26, 2018
  7. 1/2 commit: fix --short and --porcelain optionsSamuel Lijin, Apr 26, 2018
  8. Junio C HamanoMay 2, 2018
  9. Samuel LijinMay 2, 2018
  10. 2/2 wt-status: const-ify all printf helper methodsSamuel Lijin, Apr 26, 2018
  11. 0/3 Fix --short/--porcelain options for git commitSamuel Lijin, Jul 15, 2018
  12. 0/4 Rerolling patch series to fix t7501Samuel Lijin, Jul 23, 2018
  13. Junio C HamanoJul 30, 2018
  14. 1/4 t7501: add coverage for flags which imply dry runsSamuel Lijin, Jul 23, 2018
  15. 4/4 commit: fix exit code when doing a dry runSamuel Lijin, Jul 23, 2018
  16. 2/4 wt-status: rename commitable to committableSamuel Lijin, Jul 23, 2018
  17. 3/4 wt-status: teach wt_status_collect about merges in progressSamuel Lijin, Jul 23, 2018
  18. 1/3 t7501: add merge conflict tests for dry runSamuel Lijin, Jul 15, 2018
  19. Junio C HamanoJul 17, 2018
  20. Junio C HamanoJul 17, 2018
  21. 3/3 commit: fix exit code for --short/--porcelainSamuel Lijin, Jul 15, 2018
  22. Junio C HamanoJul 17, 2018
  23. Samuel LijinJul 19, 2018
  24. 2/3 wt-status: teach wt_status_collect about merges in progressSamuel Lijin, Jul 15, 2018
  25. Junio C HamanoJul 17, 2018
  26. Samuel LijinApr 19, 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.