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

Re: [PATCH v2] git status: Show detailed dirty status of submodules in long format

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 8, 2010, 08:33 UTC
Message-ID
<7vvdd7yzzb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4B9406A5.2090300@web.de>
Jens Lehmann <Jens.Lehmann@web.de> writes:
Show 5 quoted lines
> I was planning a cleanup patch anyway to get rid of the test for
> DIFF_FORMAT_PATCH by setting DIFF_OPT_DIRTY_SUBMODULES at the appropriate
> call sites and then only test for DIFF_OPT_DIRTY_SUBMODULES here. Putting
> the duplicated code into a new function is a good idea, so I'll do that
> in the cleanup patch, o.k.?
Sounds sensible, thanks.
Show 23 quoted lines
> diff --git a/wt-status.c b/wt-status.c
> index 5807fc3..c028afd 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -153,6 +157,21 @@ static void wt_status_print_change_data(struct wt_status *s,
>  			one_name = d->head_path;
>  		break;
>  	case WT_STATUS_CHANGED:
> +		if (d->new_submodule_commits || d->dirty_submodule) {
> +			const char *sep = "";
> +			strbuf_addstr(&extra, " (");
> +			if (d->new_submodule_commits) {
> +				strbuf_addf(&extra, "new commits");
> +				sep = ", ";
> +			}
> +			if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) {
> +				strbuf_addf(&extra, "%smodified content", sep);
> +				sep = ", ";
> +			}
> +			if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
> +				strbuf_addf(&extra, "%suntracked content",sep);
> +			strbuf_addch(&extra, ')');
> +		}

This may be easier to read and maintain if you always added ", " at each step, and then backed up by two places before closing the thing with ')', without doing the sep = ", " in the middle.

Show 8 quoted lines
> @@ -189,6 +208,10 @@ static void wt_status_print_change_data(struct wt_status *s,
>  	default:
>  		die("bug: unhandled diff status %c", status);
>  	}
> +	if (extra.len) {
> +		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), extra.buf);
> +		strbuf_release(&extra);
> +	}
This needs to be touched up as:
	color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);

just in case we may start adding some more free strings in extra.buf later. Also we tell the compiler that the third parameter to the function quacks like printf format string, and get a warning for passing an arbitrary string extra.buf to it.

Previous: Jens LehmannNext: Jens Lehmann
Message 4 of 5 in “git status: Show detailed dirty status of submodules in long format”
  1. git status: Show detailed dirty status of submodules in long formatJens Lehmann, Mar 5, 2010
  2. Junio C HamanoMar 7, 2010
  3. git status: Show detailed dirty status of submodules in long formatJens Lehmann, Mar 7, 2010
  4. Junio C HamanoMar 8, 2010
  5. git status: Show detailed dirty status of submodules in long formatJens Lehmann, Mar 8, 2010

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.