threads / patch / 15254

patchgit-commit: '--no-status' Allow suppression of status summary in commit msg

Subject: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

## tl;dr

7 messages between Aug 28, 2008 and Aug 29, 2008. Diffs are folded; open one to read it.

replies: 6people: 4as markdown or json

Marcus Griep· Aug 28, 2008, 18:46 UTC · lore

Currently, using any editor to edit a commit message for 'git commit' kicks of a 'git status' which is then included as comments to give the commit author some context. However, in some situations, such as having a working tree of many hundred thousand files or on an inefficient filesystem, a 'git status' can take a long time to process before displaying the commit for editing.

This patch provides an option to disable the status summary, documents it and provides test cases for its operation.

Signed-off-by: Marcus Griep <marcus@griep.us>
---
 Documentation/git-commit.txt |    9 +++++++++
 builtin-commit.c             |   16 +++++++++++-----
 t/t7500-commit.sh            |   32 ++++++++++++++++++++++++++++++++
 t/t7500/check-for-status     |    9 +++++++++
 4 files changed, 61 insertions(+), 5 deletions(-)
 create mode 100755 t/t7500/check-for-status
Show changes to 4 files +61 −5

Documentation/git-commit.txt, builtin-commit.c, t/t7500-commit.sh, t/t7500/check-for-status

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 0e25bb8..0d5d35c 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -190,6 +190,15 @@ specified.
 --quiet::
 	Suppress commit summary message.
 
+-S::
+--no-status::
+	Suppress inclusion of the git status summary comments
+	that are normally included when the commit message
+	editor is invoked. This can be helpful if `git status`
+	is an expensive operation on your machine, and you
+	don't wish to incur that cost when editing a commit
+	message.
+
 \--::
 	Do not interpret any more arguments as options.
 
diff --git a/builtin-commit.c b/builtin-commit.c
index 649c8be..153f436 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -51,7 +51,7 @@ static const char *template_file;
 static char *edit_message, *use_message;
 static char *author_name, *author_email, *author_date;
 static int all, edit_flag, also, interactive, only, amend, signoff;
-static int quiet, verbose, no_verify, allow_empty;
+static int quiet, verbose, no_verify, no_status, allow_empty;
 static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
@@ -103,6 +103,7 @@ static struct option builtin_commit_options[] = {
 	OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
 	OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
 	OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
+	OPT_BOOLEAN('S', "no-status", &no_status, "don't include status summary comments in editor"),
 	OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
 	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 	OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
@@ -590,10 +591,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
 		if (ident_shown)
 			fprintf(fp, "#\n");
 
-		saved_color_setting = wt_status_use_color;
-		wt_status_use_color = 0;
-		commitable = run_status(fp, index_file, prefix, 1);
-		wt_status_use_color = saved_color_setting;
+		if (!no_status) {
+			saved_color_setting = wt_status_use_color;
+			wt_status_use_color = 0;
+			commitable = run_status(fp, index_file, prefix, 1);
+			wt_status_use_color = saved_color_setting;
+		}
 	} else {
 		struct rev_info rev;
 		unsigned char sha1[20];
@@ -893,6 +896,9 @@ static int git_commit_config(const char *k, const char *v, void *cb)
 	if (!strcmp(k, "commit.template"))
 		return git_config_string(&template_file, k, v);
 
+	if (!strcmp(k, "commit.nostatus"))
+		return git_config_bool_or_int(k, v, &no_status);
+
 	return git_status_config(k, v, cb);
 }
 
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 7ae0bd0..5579463 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -186,4 +186,36 @@ test_expect_success 'commit message from stdin' '
 	commit_msg_is "Log with foo word"
 '
 
+test_expect_success 'commit message in editor should include status' '
+	echo "Test status" > fooey &&
+	git add fooey &&
+	(
+		test_set_editor "$TEST_DIRECTORY"/t7500/check-for-status &&
+		git commit
+	) &&
+	commit_msg_is "Status"
+'
+
+test_expect_success 'no-status flag should suppress including status summary' '
+	echo "Test no-status" > fooey &&
+	git add fooey &&
+	(
+		test_set_editor "$TEST_DIRECTORY"/t7500/check-for-status &&
+		git commit --no-status
+	) &&
+	commit_msg_is "No Status"
+'
+
+test_expect_success 'no-status config should suppress status summary' '
+	echo "Test no-status config" > fooey &&
+	git add fooey &&
+	(
+		git config commit.nostatus true &&
+		test_set_editor "$TEST_DIRECTORY"/t7500/check-for-status &&
+		git commit &&
+		git config --unset commit.nostatus
+	) &&
+	commit_msg_is "No Status"
+'
+
 test_done
diff --git a/t/t7500/check-for-status b/t/t7500/check-for-status
new file mode 100755
index 0000000..5c6efdf
--- /dev/null
+++ b/t/t7500/check-for-status
@@ -0,0 +1,9 @@
+#!/bin/sh
+val=`sed -n 's/^# On branch .*$/1/p' "$1"`
+cat "$1"
+if [ $val ]; then
+	echo Status >> "$1"
+else
+	echo No Status >> "$1"
+fi
+exit 0
-- 
1.6.0.rc3.286.gd4df
Junio C Hamano· Aug 28, 2008, 19:09 UTC · re: Marcus Griep · lore

Re: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

Marcus Griep <marcus@griep.us> writes:
Show 5 quoted lines
> Currently, using any editor to edit a commit message for 'git commit'
> kicks of a 'git status' which is then included as comments to give
> the commit author some context. However, in some situations, such as
> having a working tree of many hundred thousand files or on an inefficient
> filesystem,

I am not interested in this particular patch, especially the part that hoards a short-and-nice -S flag that we could use for something more useful. Also calling the configuration variable "nostatus" is backwards; I'd name it to "showstatus" that defaults to "true" if I were doing this.

You did not mention exactly how the "hundred thousand files on an inefficient filesystem" is a problem, but if it is about listing untracked files, I thought Marius Storm-Olsen added a feature to address that with 4bfee30 (Add an optional <mode> argument to commit/status -u|--untracked-files option, 2008-06-05).

If that is not still enough for your particular use case, I think you can have a custom wrapper that does:

	#!/bin/sh
	: >.log-message-file &&
        vi .log-message-file &&
        git commit -F .log-message-file "$@" &&
        rm -f .log-message-file 
without touching git at all.
Alex Riesen· Aug 28, 2008, 19:34 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

Junio C Hamano, Thu, Aug 28, 2008 21:09:35 +0200:
Show 12 quoted lines
> Marcus Griep <marcus@griep.us> writes:
> 
> > Currently, using any editor to edit a commit message for 'git commit'
> > kicks of a 'git status' which is then included as comments to give
> > the commit author some context. However, in some situations, such as
> > having a working tree of many hundred thousand files or on an inefficient
> > filesystem,
> 
> I am not interested in this particular patch, especially the part that
> hoards a short-and-nice -S flag that we could use for something more
> useful.  Also calling the configuration variable "nostatus" is backwards;
> I'd name it to "showstatus" that defaults to "true" if I were doing this.

I like it (almost. I agree, it is not a very good idea to use up "-S" for such a thing). Not because of "inefficient filesystem" (I have proper systems at home), but because I more often need no file list in the commit message than I do need one. It is just annoyance. OTOH, maybe I'm just too used to put things in the index and trust that. Or maybe it is again that stupid user-friendliness.

Show 10 quoted lines
> If that is not still enough for your particular use case, I think you can
> have a custom wrapper that does:
> 
> 	#!/bin/sh
> 	: >.log-message-file &&
>         vi .log-message-file &&
>         git commit -F .log-message-file "$@" &&
>         rm -f .log-message-file 
> 
> without touching git at all.

That's not enough. Consider "-mMessage -e", "-t" or "-c" flags of git commit. The wrapper would have to catch them all! Not to mention the future flags in the same ballpark.

ATM, I just use that "--cached" (from the patch I mentioned in the other mail) with "--cleanup=verbatim" to get the commit message just how I like them.

Alex Riesen· Aug 28, 2008, 19:13 UTC · re: Marcus Griep · lore

Re: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

Marcus Griep, Thu, Aug 28, 2008 20:46:55 +0200:
Show 9 quoted lines
> Currently, using any editor to edit a commit message for 'git commit'
> kicks of a 'git status' which is then included as comments to give
> the commit author some context. However, in some situations, such as
> having a working tree of many hundred thousand files or on an inefficient
> filesystem, a 'git status' can take a long time to process before
> displaying the commit for editing.
> 
> This patch provides an option to disable the status summary, documents it
> and provides test cases for its operation.
There is prior art:
    http://thread.gmane.org/gmane.comp.version-control.git/66183/focus=66251
and resolution (in the thread, somewhat unclear).
Marcus Griep· Aug 28, 2008, 19:24 UTC · re: Alex Riesen · lore

Re: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

Using --untracked-files=no cuts the time to display the editor from down to 12 seconds, so that is perfectly fine. The patch can be ignored. However, would config option to change the default --untracked-files value be entertained? Allowing:

[commit]
	untrackedfiles=no
which defaults (as stated in the documentation for --untracked-files) to all?
Alex Riesen wrote:
Show 20 quoted lines
> Marcus Griep, Thu, Aug 28, 2008 20:46:55 +0200:
>> Currently, using any editor to edit a commit message for 'git commit'
>> kicks of a 'git status' which is then included as comments to give
>> the commit author some context. However, in some situations, such as
>> having a working tree of many hundred thousand files or on an inefficient
>> filesystem, a 'git status' can take a long time to process before
>> displaying the commit for editing.
>>
>> This patch provides an option to disable the status summary, documents it
>> and provides test cases for its operation.
> 
> There is prior art:
> 
>     http://thread.gmane.org/gmane.comp.version-control.git/66183/focus=66251
> 
> and resolution (in the thread, somewhat unclear).
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Marcus Griep
GPG Key ID: 0x5E968152
——
http://www.boohaunt.net
את.ψο´
Marius Storm-Olsen· Aug 29, 2008, 05:39 UTC · re: Marcus Griep · lore

Re: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

Marcus Griep said the following on 28.08.2008 21:24:
Show 8 quoted lines
> Using --untracked-files=no cuts the time to display the editor from down to 12 seconds,
> so that is perfectly fine.  The patch can be ignored.  However, would config option to
> change the default --untracked-files value be entertained?  Allowing:
> 
> [commit]
> 	untrackedfiles=no
> 
> which defaults (as stated in the documentation for --untracked-files) to all?
That was already added in the commit d6293d. Just set
     status.showUntrackedFiles=no
-- 
.marius [@trolltech.com]
'if you know what you're doing, it's not research'
Marius Storm-Olsen· Aug 29, 2008, 05:49 UTC · re: Marius Storm-Olsen · lore

Re: [PATCH] git-commit: '--no-status' Allow suppression of status summary in commit msg

Marius Storm-Olsen said the following on 29.08.2008 07:39:
Show 12 quoted lines
> Marcus Griep said the following on 28.08.2008 21:24:
>> Using --untracked-files=no cuts the time to display the editor from down to 12 seconds,
>> so that is perfectly fine.  The patch can be ignored.  However, would config option to
>> change the default --untracked-files value be entertained?  Allowing:
>>
>> [commit]
>> 	untrackedfiles=no
>>
>> which defaults (as stated in the documentation for --untracked-files) to all?
> 
> That was already added in the commit d6293d. Just set
>      status.showUntrackedFiles=no
With that, I of course mean:
[status]
	showUntrackedFiles=no
-- 
.marius [@trolltech.com]
'if you know what you're doing, it's not research'

← back to recent threads