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

Re: [PATCH 3/3] builtin-add: simplify (and increase accuracy of) exclude handling

From
Jonas Fonseca <fonseca@diku.dk>
Date
Jun 11, 2007, 15:01 UTC
Message-ID
<20070611150122.GA11020@diku.dk>
In-Reply-To
<20070611133956.GC7008@coredump.intra.peff.net>
Hej Jeff,
Thanks for looking into this and making these patches. :)
Jeff King <peff@peff.net> wrote Mon, Jun 11, 2007:
Show 55 quoted lines
>  builtin-add.c |   89 ++++++++++++++++++++++++++++++--------------------------
>  dir.c         |    1 -
>  dir.h         |    4 +--
>  3 files changed, 49 insertions(+), 45 deletions(-)
> 
> diff --git a/builtin-add.c b/builtin-add.c
> index 1591171..8988930 100644
> --- a/builtin-add.c
> +++ b/builtin-add.c
> @@ -160,6 +166,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  	const char **pathspec;
>  	struct dir_struct dir;
>  	int add_interactive = 0;
> +	int has_ignored;
>  
>  	for (i = 1; i < argc; i++) {
>  		if (!strcmp("--interactive", argv[i]) ||
> @@ -237,25 +242,19 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  	if (read_cache() < 0)
>  		die("index file corrupt");
>  
> -	if (!ignored_too) {
> -		int has_ignored = 0;
> -		for (i = 0; i < dir.nr; i++)
> -			if (dir.entries[i]->ignored)
> -				has_ignored = 1;
> -		if (has_ignored) {
> -			fprintf(stderr, ignore_warning);
> -			for (i = 0; i < dir.nr; i++) {
> -				if (!dir.entries[i]->ignored)
> -					continue;
> -				fprintf(stderr, "%s", dir.entries[i]->name);
> -				if (dir.entries[i]->ignored_dir)
> -					fprintf(stderr, " (directory)");
> -				fputc('\n', stderr);
> -			}
> -			fprintf(stderr,
> -				"Use -f if you really want to add them.\n");
> -			exit(1);
> +	has_ignored = 0;
> +	for (i = 0; i < dir.ignored_nr; i++) {
> +		if (dir.ignored[i])
> +			has_ignored = 1;
> +	}
> +	if (has_ignored) {
> +		fprintf(stderr, ignore_warning);
> +		for (i = 0; i < dir.ignored_nr; i++) {
> +			if (dir.ignored[i])
> +				fprintf(stderr, "%s\n", dir.ignored[i]->name);
>  		}
> +		fprintf(stderr, "Use -f if you really want to add them.\n");
> +		exit(1);
>  	}
>  
>  	for (i = 0; i < dir.nr; i++)
I think you could even get rid of has_ignored with something like this.
diff --git a/builtin-add.c b/builtin-add.c
index 8988930..da6ab11 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -166,7 +166,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	const char **pathspec;
 	struct dir_struct dir;
 	int add_interactive = 0;
-	int has_ignored;
 
 	for (i = 1; i < argc; i++) {
 		if (!strcmp("--interactive", argv[i]) ||
@@ -242,12 +241,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	if (read_cache() < 0)
 		die("index file corrupt");
 
-	has_ignored = 0;
-	for (i = 0; i < dir.ignored_nr; i++) {
-		if (dir.ignored[i])
-			has_ignored = 1;
-	}
-	if (has_ignored) {
+	if (dir.ignored_nr) {
 		fprintf(stderr, ignore_warning);
 		for (i = 0; i < dir.ignored_nr; i++) {
 			if (dir.ignored[i])
-- 
Jonas Fonseca
Previous: Jeff KingNext: Jeff King
Message 12 of 16 in “Adding empty directory gives bogus error message”
  1. Jonas FonsecaJun 10, 2007
  2. Jeff KingJun 11, 2007
  3. 1/3 refactor dir_add_nameJeff King, Jun 11, 2007
  4. Johannes SchindelinJun 11, 2007
  5. Junio C HamanoJun 11, 2007
  6. Jeff KingJun 11, 2007
  7. Junio C HamanoJun 12, 2007
  8. Jeff KingJun 12, 2007
  9. Jonas FonsecaJun 12, 2007
  10. 2/3 dir_struct: add collect_ignored optionJeff King, Jun 11, 2007
  11. 3/3 builtin-add: simplify (and increase accuracy of) exclude handlingJeff King, Jun 11, 2007
  12. Jonas FonsecaJun 11, 2007
  13. Jeff KingJun 11, 2007
  14. Jonas FonsecaJun 11, 2007
  15. Jeff KingJun 11, 2007
  16. Jonas FonsecaJun 12, 2007

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.