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

5 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:42

Marius Storm-Olsen [off-list ref] writes:
quoted hunk
diff --git a/builtin-commit.c b/builtin-commit.c
index b294c1f..1f4986b 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -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. (Default: all)", PARSE_OPT_OPTARG, NULL, (int)"all" },
Hmm.

$ make
builtin-commit.c:106: error: initializer element is not constant
builtin-commit.c:106: error: (near initialization for 'builtin_commit_options[18].defval')
make: *** [builtin-commit.o] Error 1

I also have to wonder what the funny cast of (int)"all"  is doing.

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

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:44:42

Junio C Hamano said the following on 07.06.2008 03:55:
Marius Storm-Olsen [off-list ref] writes:
quoted
diff --git a/builtin-commit.c b/builtin-commit.c
index b294c1f..1f4986b 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -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. (Default: all)", PARSE_OPT_OPTARG, NULL, (int)"all" },
Hmm.

$ make
builtin-commit.c:106: error: initializer element is not constant
builtin-commit.c:106: error: (near initialization for 'builtin_commit_options[18].defval')
make: *** [builtin-commit.o] Error 1
 >
I also have to wonder what the funny cast of (int)"all"  is doing.
Ops, obviously it should have been s@\(int\)@(intptr_t)@. Sorry about 
that, I'll resend the patch series.

(The option struct in parse_options.h uses intptr_t for the default 
value of an option, thus a normal const char * would make the compiler 
complain (verified with both Windows MinGW 3.4.5 and Linux GCC 4.1.2))

BTW, which compiler version are you using?

-- 
.marius [@trolltech.com]
'if you know what you're doing, it's not research'

[PATCH 3/3] Add configuration option for default untracked files mode

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:44:42

By default, the untracked files mode for commit/status is 'normal'

Signed-off-by: Marius Storm-Olsen <redacted>
---
 Documentation/config.txt     |   19 +++++++++++++++++++
 Documentation/git-commit.txt |    4 ++++
 t/t7502-status.sh            |   18 ++++++++++++++++++
 wt-status.c                  |   13 +++++++++++++
 4 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index c298dc2..7ce7816 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1010,6 +1010,25 @@ 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:
++
+--
+		- 'no'     - 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 a6db831..1235aae 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -161,6 +161,10 @@ the handling of untracked files. The possible options are:
 		- 'normal' - Shows untracked files and directories
 		- 'all'    - Also shows individual files in untracked directories.
 --
++
+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/t/t7502-status.sh b/t/t7502-status.sh
index d84bda1..38a48b5 100755
--- a/t/t7502-status.sh
+++ b/t/t7502-status.sh
@@ -89,6 +89,12 @@ test_expect_success 'status -uno' '
 	test_cmp expect output
 '
 
+test_expect_success 'status (status.showUntrackedFiles no)' '
+	git config status.showuntrackedfiles no
+	git status >output &&
+	test_cmp expect output
+'
+
 cat >expect <<EOF
 # On branch master
 # Changes to be committed:
@@ -117,6 +123,12 @@ test_expect_success 'status -unormal' '
 	test_cmp expect output
 '
 
+test_expect_success 'status (status.showUntrackedFiles normal)' '
+	git config status.showuntrackedfiles normal
+	git status >output &&
+	test_cmp expect output
+'
+
 cat >expect <<EOF
 # On branch master
 # Changes to be committed:
@@ -143,7 +155,13 @@ cat >expect <<EOF
 EOF
 test_expect_success 'status -uall' '
 	git status -uall >output &&
+	test_cmp expect output
+'
+test_expect_success 'status (status.showUntrackedFiles all)' '
+	git config status.showuntrackedfiles all
+	git status >output &&
 	rm -rf dir3 &&
+	git config --unset status.showuntrackedfiles &&
 	test_cmp expect output
 '
 
diff --git a/wt-status.c b/wt-status.c
index 23017e4..28c9e63 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, "no"))
+			show_untracked_files = SHOW_NO_UNTRACKED_FILES;
+		else if (!strcmp(v, "normal"))
+			show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+		else if (!strcmp(v, "all"))
+			show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+		else
+			return error("Invalid untracked files mode '%s'", v);
+		return 0;
+	}
 	return git_color_default_config(k, v, cb);
 }
-- 
1.5.6.rc0.160.gf7c043.dirty

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

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:44:42

This lets you specify how you want untracked files to be listed. The possible
options are:
    normal - Show untracked files and directories
    all    - Show all untracked files

The 'all' mode is used, if the mode is not specified.

Signed-off-by: Marius Storm-Olsen <redacted>
---
 Documentation/git-commit.txt |   18 +++++++-----
 builtin-commit.c             |   16 +++++++++--
 t/t7502-status.sh            |   61 ++++++++++++++++++++++++++++++++++++++++++
 wt-status.c                  |    1 +
 wt-status.h                  |    6 ++++
 5 files changed, 92 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index c3c9f5b..cc4374a 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository
 SYNOPSIS
 --------
 [verse]
-'git-commit' [-a | --interactive] [-s] [-v] [-u]
+'git-commit' [-a | --interactive] [-s] [-v] [-u[<mode>]]
 	   [(-c | -C) <commit> | -F <file> | -m <msg> | --amend]
 	   [--allow-empty] [--no-verify] [-e] [--author <author>]
 	   [--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -150,12 +150,16 @@ 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 untracked files (Default: 'all').
++
+The mode parameter is optional, and is used to specify
+the handling of untracked files. The possible options are:
++
+--
+		- 'normal' - Shows untracked files and directories
+		- 'all'    - Also shows individual files in untracked directories.
+--
 
 -v|--verbose::
 	Show unified diff between the HEAD commit and what
diff --git a/builtin-commit.c b/builtin-commit.c
index b294c1f..95cdb82 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. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"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 == SHOW_ALL_UNTRACKED_FILES);
 	s.index_file = index_file;
 	s.fp = fp;
 	s.nowarn = nowarn;
@@ -795,6 +796,15 @@ 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, "normal"))
+		show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
+	else if (!strcmp(untracked_files_arg, "all"))
+		show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
+	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/t/t7502-status.sh b/t/t7502-status.sh
index 80a438d..0d24e25 100755
--- a/t/t7502-status.sh
+++ b/t/t7502-status.sh
@@ -67,6 +67,67 @@ test_expect_success 'status (2)' '
 
 '
 
+cat >expect <<EOF
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#	new file:   dir2/added
+#
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#
+#	modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#	dir1/untracked
+#	dir2/modified
+#	dir2/untracked
+#	dir3/
+#	expect
+#	output
+#	untracked
+EOF
+test_expect_success 'status -unormal' '
+	mkdir dir3 &&
+	: > dir3/untracked1 &&
+	: > dir3/untracked2 &&
+	git status -unormal >output &&
+	test_cmp expect output
+'
+
+cat >expect <<EOF
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#	new file:   dir2/added
+#
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#
+#	modified:   dir1/modified
+#
+# Untracked files:
+#   (use "git add <file>..." to include in what will be committed)
+#
+#	dir1/untracked
+#	dir2/modified
+#	dir2/untracked
+#	dir3/untracked1
+#	dir3/untracked2
+#	expect
+#	output
+#	untracked
+EOF
+test_expect_success 'status -uall' '
+	git status -uall >output &&
+	rm -rf dir3 &&
+	test_cmp expect output
+'
+
 cat > expect << \EOF
 # On branch master
 # Changes to be committed:
diff --git a/wt-status.c b/wt-status.c
index 5b4d74c..25d9985 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 = SHOW_NORMAL_UNTRACKED_FILES;
 
 static int parse_status_slot(const char *var, int offset)
 {
diff --git a/wt-status.h b/wt-status.h
index 597c7ea..54f756d 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -11,6 +11,12 @@ enum color_wt_status {
 	WT_STATUS_NOBRANCH,
 };
 
+enum untracked_status_type {
+	SHOW_NORMAL_UNTRACKED_FILES = 1,
+	SHOW_ALL_UNTRACKED_FILES
+};
+extern enum untracked_status_type show_untracked_files;
+
 struct wt_status {
 	int is_initial;
 	char *branch;
-- 
1.5.6.rc0.160.gf7c043.dirty

[PATCH 2/3] Add argument 'no' commit/status option -u|--untracked-files

From: Marius Storm-Olsen <hidden>
Date: 2016-06-15 22:44:42

This new argument teaches Git to not look for any untracked files,
saving cycles on slow file systems, or large repos.

Signed-off-by: Marius Storm-Olsen <redacted>
---
 Documentation/git-commit.txt |    1 +
 builtin-commit.c             |    4 +++-
 t/t7502-status.sh            |   25 ++++++++++++++++++++++---
 wt-status.c                  |    7 ++++++-
 wt-status.h                  |    3 ++-
 5 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index cc4374a..a6db831 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -157,6 +157,7 @@ The mode parameter is optional, and is used to specify
 the handling of untracked files. The possible options are:
 +
 --
+		- 'no'     - Show no untracked files
 		- 'normal' - Shows untracked files and directories
 		- 'all'    - Also shows individual files in untracked directories.
 --
diff --git a/builtin-commit.c b/builtin-commit.c
index 95cdb82..f3e524a 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -103,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"),
-	{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
+	{ 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"),
 	OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
 
@@ -798,6 +798,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
 
 	if (!untracked_files_arg)
 		; /* default already initialized */
+	else if (!strcmp(untracked_files_arg, "no"))
+		show_untracked_files = SHOW_NO_UNTRACKED_FILES;
 	else if (!strcmp(untracked_files_arg, "normal"))
 		show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
 	else if (!strcmp(untracked_files_arg, "all"))
diff --git a/t/t7502-status.sh b/t/t7502-status.sh
index 0d24e25..d84bda1 100755
--- a/t/t7502-status.sh
+++ b/t/t7502-status.sh
@@ -79,6 +79,28 @@ cat >expect <<EOF
 #
 #	modified:   dir1/modified
 #
+# Untracked files not listed (use -u option to show untracked files)
+EOF
+test_expect_success 'status -uno' '
+	mkdir dir3 &&
+	: > dir3/untracked1 &&
+	: > dir3/untracked2 &&
+	git status -uno >output &&
+	test_cmp expect output
+'
+
+cat >expect <<EOF
+# On branch master
+# Changes to be committed:
+#   (use "git reset HEAD <file>..." to unstage)
+#
+#	new file:   dir2/added
+#
+# Changed but not updated:
+#   (use "git add <file>..." to update what will be committed)
+#
+#	modified:   dir1/modified
+#
 # Untracked files:
 #   (use "git add <file>..." to include in what will be committed)
 #
@@ -91,9 +113,6 @@ cat >expect <<EOF
 #	untracked
 EOF
 test_expect_success 'status -unormal' '
-	mkdir dir3 &&
-	: > dir3/untracked1 &&
-	: > dir3/untracked2 &&
 	git status -unormal >output &&
 	test_cmp expect output
 '
diff --git a/wt-status.c b/wt-status.c
index 25d9985..23017e4 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -348,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);
@@ -363,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 54f756d..78add09 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -12,7 +12,8 @@ enum color_wt_status {
 };
 
 enum untracked_status_type {
-	SHOW_NORMAL_UNTRACKED_FILES = 1,
+	SHOW_NO_UNTRACKED_FILES,
+	SHOW_NORMAL_UNTRACKED_FILES,
 	SHOW_ALL_UNTRACKED_FILES
 };
 extern enum untracked_status_type show_untracked_files;
-- 
1.5.6.rc0.160.gf7c043.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help