threads / patch / 13780

patchAdd configuration option for default untracked files mode

Subject: [PATCH] Add configuration option for default untracked files mode

## tl;dr

11 messages between Jun 3, 2008 and Jun 6, 2008. Diffs are folded; open one to read it.

replies: 10people: 5as markdown or json

Marius Storm-Olsen· Jun 3, 2008, 13:09 UTC · lore

[PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Determining untracked files can be a very slow operation on large trees.
This commit adds a <mode> argument, which allows you to avoid showing the
untracked files in a repository. Possible options are:
    none   - Show no untracked files
    normal - Show untracked files and directories
    all    - Show all untracked files
If the optional argument is not specified, the option defaults to 'all'.
Signed-off-by: Marius Storm-Olsen <marius@trolltech.com>
---
 Documentation/git-commit.txt |   15 +++++++++------
 builtin-commit.c             |   18 +++++++++++++++---
 wt-status.c                  |    8 +++++++-
 wt-status.h                  |    7 +++++++
 4 files changed, 38 insertions(+), 10 deletions(-)
Show changes to 4 files +38 −10

Documentation/git-commit.txt, builtin-commit.c, wt-status.c, wt-status.h

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index c3c9f5b..d8a3aa3 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -150,12 +150,15 @@ but can be used to amend a merge commit.
 	the last commit without committing changes that have
 	already been staged.
 
--u|--untracked-files::
-	Show all untracked files, also those in uninteresting
-	directories, in the "Untracked files:" section of commit
-	message template.  Without this option only its name and
-	a trailing slash are displayed for each untracked
-	directory.
+-u[<mode>]|--untracked-files[=<mode>]::
+	Show all untracked files.
+	The mode parameter is optional, and is used to specify
+	the handling of untracked files. The possible options are:
+		none   - Show no untracked files
+		normal - Shows untracked files and directories
+		all    - Also shows individual files in untracked directories.
+	If the mode parameter is not specified, the defaults is
+	'all'.
 
 -v|--verbose::
 	Show unified diff between the HEAD commit and what
diff --git a/builtin-commit.c b/builtin-commit.c
index 90200ed..28db2ba 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -49,7 +49,8 @@ static char *logfile, *force_author, *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, untracked_files, no_verify, allow_empty;
+static int quiet, verbose, no_verify, allow_empty;
+static char *untracked_files_arg;
 /*
  * The default commit message cleanup mode will remove the lines
  * beginning with # (shell comments) and leading and trailing
@@ -102,7 +103,7 @@ static struct option builtin_commit_options[] = {
 	OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
 	OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
 	OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
-	OPT_BOOLEAN('u', "untracked-files", &untracked_files, "show all untracked files"),
+	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, none. (Default: all)", PARSE_OPT_OPTARG, NULL, (int)"all" },
 	OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
 	OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
 
@@ -347,7 +348,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 		s.reference = "HEAD^1";
 	}
 	s.verbose = verbose;
-	s.untracked = untracked_files;
+	s.untracked = (show_untracked_files == ALL_UNTRACKED);
 	s.index_file = index_file;
 	s.fp = fp;
 	s.nowarn = nowarn;
@@ -795,6 +796,17 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	else
 		die("Invalid cleanup mode %s", cleanup_arg);
 
+	if (!untracked_files_arg)
+		; /* default already initialized */
+	else if (!strcmp(untracked_files_arg, "none"))
+		show_untracked_files = NONE_UNTRACKED;
+	else if (!strcmp(untracked_files_arg, "normal"))
+		show_untracked_files = NORMAL_UNTRACKED;
+	else if (!strcmp(untracked_files_arg, "all"))
+		show_untracked_files = ALL_UNTRACKED;
+	else
+		die("Invalid untracked files mode '%s'", untracked_files_arg);
+
 	if (all && argc > 0)
 		die("Paths with -a does not make sense.");
 	else if (interactive && argc > 0)
diff --git a/wt-status.c b/wt-status.c
index 5b4d74c..742a474 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -27,6 +27,7 @@ static const char use_add_rm_msg[] =
 "use \"git add/rm <file>...\" to update what will be committed";
 static const char use_add_to_include_msg[] =
 "use \"git add <file>...\" to include in what will be committed";
+enum untracked_status_type show_untracked_files = NORMAL_UNTRACKED;
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -347,7 +348,10 @@ void wt_status_print(struct wt_status *s)
 	wt_status_print_changed(s);
 	if (wt_status_submodule_summary)
 		wt_status_print_submodule_summary(s);
-	wt_status_print_untracked(s);
+	if (show_untracked_files)
+		wt_status_print_untracked(s);
+	else if (s->commitable)
+		fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
 
 	if (s->verbose && !s->is_initial)
 		wt_status_print_verbose(s);
@@ -362,6 +366,8 @@ void wt_status_print(struct wt_status *s)
 			printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
 		else if (s->is_initial)
 			printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
+		else if (!show_untracked_files)
+			printf("nothing to commit (use -u to show untracked files)\n");
 		else
 			printf("nothing to commit (working directory clean)\n");
 	}
diff --git a/wt-status.h b/wt-status.h
index 597c7ea..343d975 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -11,6 +11,13 @@ enum color_wt_status {
 	WT_STATUS_NOBRANCH,
 };
 
+enum untracked_status_type {
+	NONE_UNTRACKED,
+	NORMAL_UNTRACKED,
+	ALL_UNTRACKED
+};
+extern enum untracked_status_type show_untracked_files;
+
 struct wt_status {
 	int is_initial;
 	char *branch;
-- 
1.5.5.GIT
Marius Storm-Olsen· Jun 3, 2008, 13:12 UTC · re: Marius Storm-Olsen · lore
By default, the untracked files mode for commit/status is 'normal'.
Signed-off-by: Marius Storm-Olsen <marius@trolltech.com>
---
 Documentation/config.txt     |   15 +++++++++++++++
 Documentation/git-commit.txt |    4 +++-
 wt-status.c                  |   13 +++++++++++++
 3 files changed, 31 insertions(+), 1 deletions(-)
Show changes to 3 files +31 −1

Documentation/config.txt, Documentation/git-commit.txt, wt-status.c

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 5331b45..12c0be3 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1013,6 +1013,21 @@ status.relativePaths::
 	relative to the repository root (this was the default for git
 	prior to v1.5.4).
 
+status.showUntrackedFiles::
+	By default, linkgit:git-status[1] and linkgit:git-commit[1] show
+	files which are not currently tracked by Git. Directories which
+	contain only untracked files, are shown with the directory name
+	only. Showing untracked files means that Git needs to lstat() all
+	all the files in the whole repository, which might be slow on some
+	systems. So, this variable controls how the commands displays
+	the untracked files. Possible values are:
+		none   - Show no untracked files
+		normal - Shows untracked files and directories
+		all    - Shows also individual files in untracked directories.
+	If this variable is not specified, it defaults to 'normal'.
+	This variable can be overridden with the -u|--untracked-files option
+	of linkgit:git-status[1] and linkgit:git-commit[1].
+
 tar.umask::
 	This variable can be used to restrict the permission bits of
 	tar archive entries.  The default is 0002, which turns off the
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index d8a3aa3..bcbc2c2 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -158,7 +158,9 @@ but can be used to amend a merge commit.
 		normal - Shows untracked files and directories
 		all    - Also shows individual files in untracked directories.
 	If the mode parameter is not specified, the defaults is
-	'all'.
+	'all'. See linkgit:git-config[1] for configuration variable
+	used to change the default for when the option is not
+	specified.
 
 -v|--verbose::
 	Show unified diff between the HEAD commit and what
diff --git a/wt-status.c b/wt-status.c
index 742a474..9ffe1c3 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -397,5 +397,18 @@ int git_status_config(const char *k, const char *v, void *cb)
 		wt_status_relative_paths = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "status.showuntrackedfiles")) {
+		if (!v)
+			return config_error_nonbool(v);
+		else if (!strcmp(v, "none"))
+			show_untracked_files = NONE_UNTRACKED;
+		else if (!strcmp(v, "normal"))
+			show_untracked_files = NORMAL_UNTRACKED;
+		else if (!strcmp(v, "all"))
+			show_untracked_files = ALL_UNTRACKED;
+		else
+			return error("Invalid untracked files mode '%s'", v);
+		return 0;
+	}
 	return git_color_default_config(k, v, cb);
 }
-- 
1.5.5.GIT
Junio C Hamano· Jun 3, 2008, 20:02 UTC · re: Marius Storm-Olsen · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Marius Storm-Olsen <marius@trolltech.com> writes:
Show 8 quoted lines
> Determining untracked files can be a very slow operation on large trees.
> This commit adds a <mode> argument, which allows you to avoid showing the
> untracked files in a repository. Possible options are:
>     none   - Show no untracked files
>     normal - Show untracked files and directories
>     all    - Show all untracked files
>
> If the optional argument is not specified, the option defaults to 'all'.

You got me worried. You are defaulting the parameter of "-u" to 'all', not making the command default (in the absense of -u anything) to "-u all", which was what I misunderstood on my first reading. "the optional parameter defaults to 'all'" is what you meant...

enum {NONE,NORMAL,ALL}_UNTRACKED are named (1) too generic, in a sense that it is not clear _what_ is done to the class of untracked worktree entities, and/or (2) opposite from other enums where common prefix is followed by differing part.

Perhaps renaming them to SHOW_{NONE,NORMAL,ALL}_UNTRACKED would make it easier to read.

It would have been nicer if this patch was further split into two; the first one to introduce NORMAL and ALL without changing any behaviour, then the second one to add NONE to introduce a new behaviour, with tests so that other people will not break this new feature in their later changes.

Show 19 quoted lines
> @@ -150,12 +150,15 @@ but can be used to amend a merge commit.
>  	the last commit without committing changes that have
>  	already been staged.
>  
> --u|--untracked-files::
> -	Show all untracked files, also those in uninteresting
> -	directories, in the "Untracked files:" section of commit
> -	message template.  Without this option only its name and
> -	a trailing slash are displayed for each untracked
> -	directory.
> +-u[<mode>]|--untracked-files[=<mode>]::
> +	Show all untracked files.
> +	The mode parameter is optional, and is used to specify
> +	the handling of untracked files. The possible options are:
> +		none   - Show no untracked files
> +		normal - Shows untracked files and directories
> +		all    - Also shows individual files in untracked directories.
> +	If the mode parameter is not specified, the defaults is
> +	'all'.
Does this mark-up actually work?
Marius Storm-Olsen· Jun 3, 2008, 21:00 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Junio C Hamano said the following on 03.06.2008 22:02:
Show 15 quoted lines
> Marius Storm-Olsen <marius@trolltech.com> writes:
> 
>> Determining untracked files can be a very slow operation on large trees.
>> This commit adds a <mode> argument, which allows you to avoid showing the
>> untracked files in a repository. Possible options are:
>>     none   - Show no untracked files
>>     normal - Show untracked files and directories
>>     all    - Show all untracked files
>>
>> If the optional argument is not specified, the option defaults to 'all'.
> 
> You got me worried.  You are defaulting the parameter of "-u" to 'all',
> not making the command default (in the absense of -u anything) to "-u
> all", which was what I misunderstood on my first reading.  "the optional
> parameter defaults to 'all'" is what you meant...
Ok, I'll rewrite it to make it more clear.
Show 7 quoted lines
> enum {NONE,NORMAL,ALL}_UNTRACKED are named (1) too generic, in a sense
> that it is not clear _what_ is done to the class of untracked worktree
> entities, and/or (2) opposite from other enums where common prefix is
> followed by differing part.
> 
> Perhaps renaming them to SHOW_{NONE,NORMAL,ALL}_UNTRACKED would make it
> easier to read.
Sure.
> It would have been nicer if this patch was further split into two; the
> first one to introduce NORMAL and ALL without changing any behaviour, then
> the second one to add NONE to introduce a new behaviour, with tests so
> that other people will not break this new feature in their later changes.
Ok, will do.
Show 21 quoted lines
>> @@ -150,12 +150,15 @@ but can be used to amend a merge commit.
>>  	the last commit without committing changes that have
>>  	already been staged.
>>  
>> --u|--untracked-files::
>> -	Show all untracked files, also those in uninteresting
>> -	directories, in the "Untracked files:" section of commit
>> -	message template.  Without this option only its name and
>> -	a trailing slash are displayed for each untracked
>> -	directory.
>> +-u[<mode>]|--untracked-files[=<mode>]::
>> +	Show all untracked files.
>> +	The mode parameter is optional, and is used to specify
>> +	the handling of untracked files. The possible options are:
>> +		none   - Show no untracked files
>> +		normal - Shows untracked files and directories
>> +		all    - Also shows individual files in untracked directories.
>> +	If the mode parameter is not specified, the defaults is
>> +	'all'.
> 
> Does this mark-up actually work?

I haven't actually run it through AsciiDoc. I'll make sure that it handles the next version of the patch(es).

Thanks for checking the patches!

-- .marius

Jeff King· Jun 3, 2008, 20:14 UTC · re: Marius Storm-Olsen · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

On Tue, Jun 03, 2008 at 03:09:10PM +0200, Marius Storm-Olsen wrote:
Show 9 quoted lines
> +-u[<mode>]|--untracked-files[=<mode>]::
> +	Show all untracked files.
> +	The mode parameter is optional, and is used to specify
> +	the handling of untracked files. The possible options are:
> +		none   - Show no untracked files
> +		normal - Shows untracked files and directories
> +		all    - Also shows individual files in untracked directories.
> +	If the mode parameter is not specified, the defaults is
> +	'all'.

Hmm. Doesn't this change bundling semantics of "git commit -us"? Do we care?

-Peff
Marius Storm-Olsen· Jun 3, 2008, 21:17 UTC · re: Jeff King · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Jeff King said the following on 03.06.2008 22:14:
Show 14 quoted lines
> On Tue, Jun 03, 2008 at 03:09:10PM +0200, Marius Storm-Olsen wrote:
> 
>> +-u[<mode>]|--untracked-files[=<mode>]::
>> +	Show all untracked files.
>> +	The mode parameter is optional, and is used to specify
>> +	the handling of untracked files. The possible options are:
>> +		none   - Show no untracked files
>> +		normal - Shows untracked files and directories
>> +		all    - Also shows individual files in untracked directories.
>> +	If the mode parameter is not specified, the defaults is
>> +	'all'.
> 
> Hmm. Doesn't this change bundling semantics of "git commit -us"? Do we
> care?

You are right. This is the joy of the parse-options() handling of short-options with optional arguments.

-us before meant:
     1) commit
     2) show all untracked files
     3) sign-of the commit

I guess it would be possible to reparse the options without the -u, if the argument is not one of the three (none,normal,all), but I'm not sure it's _that_ critical. Opinions?

-- .marius

しらいしななこ· Jun 3, 2008, 22:26 UTC · re: Marius Storm-Olsen · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Quoting Marius Storm-Olsen <marius@trolltech.com> writes:
Show 27 quoted lines
> Jeff King said the following on 03.06.2008 22:14:
>> On Tue, Jun 03, 2008 at 03:09:10PM +0200, Marius Storm-Olsen wrote:
>>
>>> +-u[<mode>]|--untracked-files[=<mode>]::
>>> +	Show all untracked files.
>>> +	The mode parameter is optional, and is used to specify
>>> +	the handling of untracked files. The possible options are:
>>> +		none   - Show no untracked files
>>> +		normal - Shows untracked files and directories
>>> +		all    - Also shows individual files in untracked directories.
>>> +	If the mode parameter is not specified, the defaults is
>>> +	'all'.
>>
>> Hmm. Doesn't this change bundling semantics of "git commit -us"? Do we
>> care?
>
> You are right. This is the joy of the parse-options() handling of
> short-options with optional arguments.
>
> -us before meant:
>     1) commit
>     2) show all untracked files
>     3) sign-of the commit
>
> I guess it would be possible to reparse the options without the -u, if
> the argument is not one of the three (none,normal,all), but I'm not
> sure it's _that_ critical. Opinions?
Isn't the second bullet point in the description in:
    http://www.kernel.org/pub/software/scm/git/docs/gitcli.html
good enough?
-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/

----------------------------------------------------------------------
Find out how you can get spam free email.
http://www.bluebottle.com/tag/3
Jeff King· Jun 3, 2008, 22:27 UTC · re: Marius Storm-Olsen · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

On Tue, Jun 03, 2008 at 11:17:28PM +0200, Marius Storm-Olsen wrote:
Show 11 quoted lines
> You are right. This is the joy of the parse-options() handling of  
> short-options with optional arguments.
>
> -us before meant:
>     1) commit
>     2) show all untracked files
>     3) sign-of the commit
>
> I guess it would be possible to reparse the options without the -u, if  
> the argument is not one of the three (none,normal,all), but I'm not sure 
> it's _that_ critical. Opinions?

I think it would be reasonable to make "-u" mean the same as always, and for "--untracked-files" to have an optional argument. There isn't direct support for that construct in parse_options, but you could just make it two separate options that happen to tweak the same value (though I guess they would be displayed separately in the auto-generated usage).

Some GNU utils use this strategy to extend existing options. E.g., "ls -p" comes from XSI and takes no argument, but the long-option form of --indicator-style=<none|slash|file-type|classify> gives more options.

That makes it a little less pleasant to type the extended version, but compatibility is maintained. Though I tend to wonder about this option in particular...isn't this generally a user preference? Should it perhaps be found in the config file instead?

-Peff
Alex Riesen· Jun 6, 2008, 06:32 UTC · re: Marius Storm-Olsen · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Marius Storm-Olsen, Tue, Jun 03, 2008 15:09:10 +0200:
Show 8 quoted lines
> Determining untracked files can be a very slow operation on large trees.
> This commit adds a <mode> argument, which allows you to avoid showing the
> untracked files in a repository. Possible options are:
>     none   - Show no untracked files
>     normal - Show untracked files and directories
>     all    - Show all untracked files
> 
> If the optional argument is not specified, the option defaults to 'all'.
Looks very familiar:
    http://thread.gmane.org/gmane.comp.version-control.git/66183
Marius Storm-Olsen· Jun 6, 2008, 06:56 UTC · re: Alex Riesen · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

Alex Riesen said the following on 06.06.2008 08:32:
Show 13 quoted lines
> Marius Storm-Olsen, Tue, Jun 03, 2008 15:09:10 +0200:
>> Determining untracked files can be a very slow operation on large trees.
>> This commit adds a <mode> argument, which allows you to avoid showing the
>> untracked files in a repository. Possible options are:
>>     none   - Show no untracked files
>>     normal - Show untracked files and directories
>>     all    - Show all untracked files
>>
>> If the optional argument is not specified, the option defaults to 'all'.
> 
> Looks very familiar:
> 
>     http://thread.gmane.org/gmane.comp.version-control.git/66183

Similar, but not quite. This patch doesn't care about the index, just providing the option to avoid looking for untracked files.

Improving the index handling was done in the other patch
     Add shortcut in refresh_cache_ent() for marked entries.
(which is already in master, aa9349d4), so the core.ignoreStat option 
is more effective.
-- 
.marius [@trolltech.com]
'if you know what you're doing, it's not research'
Jeff King· Jun 3, 2008, 22:53 UTC · lore

Re: [PATCH] Add an optional <mode> argument to commit/status -u|--untracked-files option

On Wed, Jun 04, 2008 at 07:26:48AM +0900, しらいしななこ wrote:
Show 9 quoted lines
> > I guess it would be possible to reparse the options without the -u, if
> > the argument is not one of the three (none,normal,all), but I'm not
> > sure it's _that_ critical. Opinions?
> 
> Isn't the second bullet point in the description in:
> 
>     http://www.kernel.org/pub/software/scm/git/docs/gitcli.html
> 
> good enough?

Ah, that is a fair point. I failed to realize we were telling people that.

-Peff

← back to recent threads