All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Heiko Voigt <hvoigt@hvoigt.net>
Cc: Sergey Sharybin <sergey.vfx@gmail.com>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Jeff King <peff@peff.net>, Git List <git@vger.kernel.org>
Subject: Re: [RFC/WIP PATCH 3/4] teach add -f option for ignored submodules
Date: Fri, 06 Dec 2013 15:10:31 -0800	[thread overview]
Message-ID: <xmqqob4t1spk.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20131204222156.GD7326@sandbox-ub> (Heiko Voigt's message of "Wed, 4 Dec 2013 23:21:56 +0100")

Heiko Voigt <hvoigt@hvoigt.net> writes:

> When the user wants to bypass the ignored status configured by
> submodule.<name>.ignore=all it is now allowed by using the -f option.
>
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> ---
>  builtin/add.c | 49 +++++++++++++++++++++++++++++++++++++------------
>  submodule.c   | 10 ++++++++++
>  submodule.h   |  1 +
>  3 files changed, 48 insertions(+), 12 deletions(-)
>
> diff --git a/builtin/add.c b/builtin/add.c
> index 2d0d2ef..d6cab7f 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -16,6 +16,7 @@
>  #include "revision.h"
>  #include "bulk-checkin.h"
>  #include "submodule.h"
> +#include "string-list.h"
>  
>  static const char * const builtin_add_usage[] = {
>  	N_("git add [options] [--] <pathspec>..."),
> @@ -37,6 +38,20 @@ struct update_callback_data {
>  static const char *option_with_implicit_dot;
>  static const char *short_option_with_implicit_dot;
>  
> +static struct lock_file lock_file;
> +
> +static const char ignore_error[] =
> +N_("The following paths are ignored by one of your .gitignore files:\n");
> +static const char submodule_ignore_error[] =
> +N_("The following paths are ignored submodules:\n");
> +
> +static int verbose, show_only, ignored_too, refresh_only;
> +static int ignore_add_errors, intent_to_add, ignore_missing;
> +
> +#define ADDREMOVE_DEFAULT 0 /* Change to 1 in Git 2.0 */
> +static int addremove = ADDREMOVE_DEFAULT;
> +static int addremove_explicit = -1; /* unspecified */
> +
>  static void warn_pathless_add(void)
>  {
>  	static int shown;
> @@ -140,6 +155,9 @@ static void update_callback(struct diff_queue_struct *q,
>  			warn_pathless_add();
>  			continue;
>  		}
> +		if (is_ignored_submodule(path) && !ignored_too)
> +			continue;
> +
>  		switch (fix_unmerged_status(p, data)) {
>  		default:
>  			die(_("unexpected diff status %c"), p->status);
> @@ -174,6 +192,7 @@ static void update_files_in_cache(const char *prefix,
>  	struct rev_info rev;
>  
>  	init_revisions(&rev, prefix);
> +	enforce_no_complete_ignore_submodule(&rev.diffopt);
>  	setup_revisions(0, NULL, &rev, NULL);
>  	if (pathspec)
>  		copy_pathspec(&rev.prune_data, pathspec);
> @@ -332,18 +351,6 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
>  	return 0;
>  }
>  
> -static struct lock_file lock_file;
> -
> -static const char ignore_error[] =
> -N_("The following paths are ignored by one of your .gitignore files:\n");
> -
> -static int verbose, show_only, ignored_too, refresh_only;
> -static int ignore_add_errors, intent_to_add, ignore_missing;
> -
> -#define ADDREMOVE_DEFAULT 0 /* Change to 1 in Git 2.0 */
> -static int addremove = ADDREMOVE_DEFAULT;
> -static int addremove_explicit = -1; /* unspecified */
> -
>  static int ignore_removal_cb(const struct option *opt, const char *arg, int unset)
>  {
>  	/* if we are told to ignore, we are not adding removals */
> @@ -407,6 +414,17 @@ static int add_files(struct dir_struct *dir, int flags)
>  	return exit_status;
>  }
>  
> +static void die_ignored_submodules(struct string_list *ignored_submodules)
> +{
> +	struct string_list_item *path;
> +
> +	fprintf(stderr, _(submodule_ignore_error));
> +	for_each_string_list_item(path, ignored_submodules)
> +		fprintf(stderr, "%s\n", path->string);
> +	fprintf(stderr, _("Use -f if you really want to add them.\n"));
> +	die(_("no files added"));
> +}
> +
>  int cmd_add(int argc, const char **argv, const char *prefix)
>  {
>  	int exit_status = 0;
> @@ -419,6 +437,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  	char *seen = NULL;
>  	int implicit_dot = 0;
>  	struct update_callback_data update_data;
> +	struct string_list ignored_submodules = STRING_LIST_INIT_NODUP;
>  
>  	gitmodules_config();
>  	git_config(add_config, NULL);
> @@ -550,6 +569,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  
>  		for (i = 0; i < pathspec.nr; i++) {
>  			const char *path = pathspec.items[i].match;
> +			char path_copy[PATH_MAX];
>  			if (!seen[i] &&
>  			    ((pathspec.items[i].magic &
>  			      (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
> @@ -562,6 +582,9 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  					die(_("pathspec '%s' did not match any files"),
>  					    pathspec.items[i].original);
>  			}
> +			normalize_path_copy(path_copy, path);
> +			if (is_ignored_submodule(path_copy))
> +				string_list_insert(&ignored_submodules, path);
>  		}
>  		free(seen);
>  	}
> @@ -583,6 +606,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  	update_files_in_cache(prefix, &pathspec, &update_data);
>  
>  	exit_status |= !!update_data.add_errors;
> +	if (!ignored_too && ignored_submodules.nr)
> +		die_ignored_submodules(&ignored_submodules);

Why is this done so late in the process?  Shouldn't it be done
immediately after we have finished iterating over the pathspecs,
checking with is_ignored_submodule() and stuffing them into
ignored_submodules string list, not waiting for plugging bulk
checkin or updating paths already tracked in the index?

>  	if (add_new_files)
>  		exit_status |= add_files(&dir, flags);
>  
> diff --git a/submodule.c b/submodule.c
> index e0719b6..c28a926 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -199,6 +199,16 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
>  	}
>  }
>  
> +int is_ignored_submodule(const char *path)
> +{
> +	struct diff_options diffopt;
> +	memset(&diffopt, 0, sizeof(diffopt));
> +	set_diffopt_flags_from_submodule_config(&diffopt, path);
> +	if (DIFF_OPT_TST(&diffopt, IGNORE_SUBMODULES))
> +		return 1;
> +	return 0;
> +}
> +
>  int submodule_config(const char *var, const char *value, void *cb)
>  {
>  	if (!prefixcmp(var, "submodule."))
> diff --git a/submodule.h b/submodule.h
> index 2c8087e..e067580 100644
> --- a/submodule.h
> +++ b/submodule.h
> @@ -17,6 +17,7 @@ int remove_path_from_gitmodules(const char *path);
>  void stage_updated_gitmodules(void);
>  void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
>  		const char *path);
> +int is_ignored_submodule(const char *path);
>  int submodule_config(const char *var, const char *value, void *cb);
>  void gitmodules_config(void);
>  int parse_submodule_config_option(const char *var, const char *value);

  reply	other threads:[~2013-12-06 23:10 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-22  7:53 Git issues with submodules Sergey Sharybin
2013-11-22 11:16 ` Ramkumar Ramachandra
2013-11-22 11:35   ` Sergey Sharybin
2013-11-22 13:08     ` Ramkumar Ramachandra
2013-11-22 15:11       ` Jeff King
2013-11-22 15:42         ` Sergey Sharybin
2013-11-22 16:35           ` Ramkumar Ramachandra
2013-11-22 17:01             ` Sergey Sharybin
2013-11-22 17:40               ` Sergey Sharybin
2013-11-22 18:11                 ` Ramkumar Ramachandra
2013-11-22 21:01                   ` Jens Lehmann
2013-11-22 21:46                     ` Sergey Sharybin
2013-11-22 21:54                     ` Heiko Voigt
2013-11-22 22:09                       ` Jonathan Nieder
2013-11-23 20:10                         ` Jens Lehmann
2013-11-24  0:52                           ` Heiko Voigt
2013-11-24 16:29                             ` Jens Lehmann
2013-11-25  9:02                               ` Sergey Sharybin
2013-11-25 17:49                                 ` Heiko Voigt
2013-11-25 17:57                                   ` Sergey Sharybin
2013-11-25 18:15                                     ` Heiko Voigt
2013-12-04 22:16                                     ` [RFC/WIP PATCH 0/4] less ignorance of submodules for ignore=all Heiko Voigt
2013-12-04 22:19                                       ` [RFC/WIP PATCH 1/4] disable complete ignorance of submodules for index <-> HEAD diff Heiko Voigt
2013-12-04 22:21                                       ` [RFC/WIP PATCH 2/4] fix 'git add' to skip submodules configured as ignored Heiko Voigt
2013-12-04 22:21                                       ` [RFC/WIP PATCH 3/4] teach add -f option for ignored submodules Heiko Voigt
2013-12-06 23:10                                         ` Junio C Hamano [this message]
2013-12-09 21:51                                           ` Heiko Voigt
2013-12-04 22:23                                       ` [RFC/WIP PATCH 4/4] always show committed submodules in summary after commit Heiko Voigt
2013-12-04 22:26                                       ` [RFC/WIP PATCH 0/4] less ignorance of submodules for ignore=all Heiko Voigt
2013-12-04 22:32                                       ` Junio C Hamano
2013-12-04 23:19                                         ` Heiko Voigt
2013-12-05 20:51                                           ` Jens Lehmann
2013-12-09 21:41                                             ` Heiko Voigt
2013-12-09 22:25                                             ` Junio C Hamano
2013-11-25 21:01                               ` Git issues with submodules Junio C Hamano
2013-11-26 18:44                                 ` Jens Lehmann
2013-11-26 19:33                                   ` Junio C Hamano
2013-11-26 19:51                                     ` Jonathan Nieder
2013-11-26 22:19                                       ` Junio C Hamano
2013-11-23  1:11                       ` [RFC PATCH] disable complete ignorance of submodules for index <-> HEAD diff Heiko Voigt
2013-11-25  9:01                         ` Sergey Sharybin
2013-11-28  7:10                           ` Heiko Voigt
2013-11-29 23:11                             ` [RFC/WIP PATCH v2] " Heiko Voigt
2013-11-23  7:04                       ` Re: Git issues with submodules Ramkumar Ramachandra
2013-11-23 20:32                       ` Jens Lehmann
2013-11-24  1:06                         ` Heiko Voigt
2013-11-25 20:53                       ` Junio C Hamano
2013-11-29 22:50                         ` Heiko Voigt
2013-11-23  6:53                     ` Ramkumar Ramachandra
2013-11-22 16:12         ` Ramkumar Ramachandra
2013-11-22 20:20           ` Jens Lehmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqob4t1spk.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Jens.Lehmann@web.de \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hvoigt@hvoigt.net \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sergey.vfx@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.