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

Re: [RFC/PATCH v2 3/3] status: introduce status.displayCommentChar to disable display of #

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Aug 28, 2013, 20:59 UTC
Message-ID
<vpq61up5y5s.fsf@anie.imag.fr>
In-Reply-To
<xmqq1u5da8dp.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 17 quoted lines
> Matthieu Moy <Matthieu.Moy@imag.fr> writes:
>
>> diff --git a/Documentation/config.txt b/Documentation/config.txt
>> index ec57a15..dacf4b9 100644
>> --- a/Documentation/config.txt
>> +++ b/Documentation/config.txt
>> @@ -2118,6 +2118,11 @@ status.branch::
>>  	Set to true to enable --branch by default in linkgit:git-status[1].
>>  	The option --no-branch takes precedence over this variable.
>>  
>> +status.displayCommentChar::
>> +	If set to false, linkgit:git-status[1] will not prefix each
>> +	line with the comment char (`core.commentchar`, i.e. `#` by
>> +	default). Defaults to true.
>
> We prefix core.commentchar followed by a single space for non-empty
> lines; is that worth mentioning, I wonder?
(and sometimes # is followed by a tab)

I don't think it's worth the trouble. The goal is not to document the format precisely, but to explain the user how to use the variable.

> Also I envision that we would extend core.commentchar to be more
> than a single character.  Is "displayCommentChar" still a good name
> for this setting?
It is as good as core.commentChar ;-).

I chose the variable name to remind commentChar (after finding commentChar, one can grep it and find status.displayCommentChar). I tend to think that it's better than omitCommentPrefix, but I can change is people think it's better.

> What are our plans to help existing scripts people have written over
> time, especially before "status -s" was invented, that will be
> broken by use of this?

I don't know what's the best plan, but I think any sensible plan starts by waiting for a few releases, so that Git version not implementing status.displayCommentChar become rare enough. So we can delay the actual plan until next year I guess.

That said, I had an idea that may help the transition: allow "auto" as a value, just like we did for colors. A patch implementing this (on top of the previous series) is below. Good point: "auto" is a safe value, as it won't break scripts. There is one drawback, though: "auto" is not a really good default value in the long run, since newcommers may wonder why there are differences between "git status" and "git status | cat".

I still find this tempting, and it would make the transition so much easier. I would even argue to flip the default to "auto" for Git 2.0 then (after all, we didn't even wait for this to change color.ui).

Maybe, later, a transition from "auto" to "never" could be done. Or perhaps it's not so terrible to keep auto (my "ls" and "ls | cat" produce very different outputs, and it never bugged me).

diff --git a/builtin/commit.c b/builtin/commit.c
index d4cfced..00e9487 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -163,6 +163,21 @@ static void determine_whence(struct wt_status *s)
 		s->whence = whence;
 }
 
+static void determine_comment_mode(struct wt_status *s)
+{
+	if (s->display_comment_char == COMMENT_AUTO) {
+		/*
+		 * determine_comment_mode is used only for cmd_status,
+		 * which always prints to stdout.
+		 */
+		if (isatty(1) || pager_in_use()) {
+			s->display_comment_char = COMMENT_NEVER;
+		} else {
+			s->display_comment_char = COMMENT_ALWAYS;
+		}
+	}
+}
+
 static void rollback_index_files(void)
 {
 	switch (commit_style) {
@@ -1183,6 +1198,20 @@ static int git_status_config(const char *k, const char *v, void *cb)
 		return 0;
 	}
 	if (!strcmp(k, "status.displaycommentchar")) {
+		if (v) {
+			if (!strcasecmp(v, "never")) {
+				s->display_comment_char = COMMENT_NEVER;
+				return 0;
+			}
+			if (!strcasecmp(v, "always")) {
+				s->display_comment_char = COMMENT_ALWAYS;
+				return 0;
+			}
+			if (!strcasecmp(v, "auto")) {
+				s->display_comment_char = COMMENT_AUTO;
+				return 0;
+			}
+		}
 		s->display_comment_char = git_config_bool(k, v);
 		return 0;
 	}
@@ -1254,6 +1283,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	gitmodules_config();
 	git_config(git_status_config, &s);
 	determine_whence(&s);
+	determine_comment_mode(&s);
 	argc = parse_options(argc, argv, prefix,
 			     builtin_status_options,
 			     builtin_status_usage, 0);
@@ -1504,7 +1534,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	 * Ignore status.displayCommentChar: we do need comments in
 	 * COMMIT_EDITMSG.
 	 */
-	s.display_comment_char = 1;
+	s.display_comment_char = COMMENT_ALWAYS;
 	determine_whence(&s);
 	s.colopts = 0;
 
diff --git a/wt-status.h b/wt-status.h
index ac02c64..dbc706e 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -40,6 +40,12 @@ struct wt_status_change_data {
 	unsigned new_submodule_commits : 1;
 };
 
+enum comment_mode {
+	COMMENT_NEVER = 0,
+	COMMENT_ALWAYS = 1,
+	COMMENT_AUTO
+};
+
 struct wt_status {
 	int is_initial;
 	char *branch;
@@ -50,7 +56,7 @@ struct wt_status {
 	enum commit_whence whence;
 	int nowarn;
 	int use_color;
-	int display_comment_char;
+	enum comment_mode display_comment_char;
 	int relative_paths;
 	int submodule_summary;
 	int show_ignored_files;
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: brian m. carlsonNext: Junio C Hamano
Message 17 of 21 in “status: introduce status.displayCommentChar to disable display of #”
  1. status: introduce status.displayCommentChar to disable display of #Matthieu Moy, Aug 28, 2013
  2. Johannes SixtAug 28, 2013
  3. Matthieu MoyAug 28, 2013
  4. 1/3 builtin/stripspace.c: fix broken indentationMatthieu Moy, Aug 28, 2013
  5. 2/3 submodule: introduce --[no-]display-comment-charMatthieu Moy, Aug 28, 2013
  6. Jens LehmannAug 28, 2013
  7. Matthieu MoyAug 29, 2013
  8. 3/3 status: introduce status.displayCommentChar to disable display of #Matthieu Moy, Aug 28, 2013
  9. Junio C HamanoAug 28, 2013
  10. Junio C HamanoAug 28, 2013
  11. Jeff KingAug 28, 2013
  12. Junio C HamanoAug 28, 2013
  13. David AguilarAug 28, 2013
  14. Junio C HamanoAug 28, 2013
  15. Matthieu MoyAug 29, 2013
  16. brian m. carlsonAug 31, 2013
  17. Matthieu MoyAug 28, 2013
  18. Junio C HamanoAug 28, 2013
  19. Junio C HamanoAug 28, 2013
  20. Jonathan NiederAug 28, 2013
  21. Matthieu MoyAug 29, 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.