From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>
Subject: [PATCH 1/4 v4] submodules: make submodule-prefix option
Date: Mon, 26 Sep 2016 15:46:40 -0700 [thread overview]
Message-ID: <1474930003-83750-2-git-send-email-bmwill@google.com> (raw)
In-Reply-To: <1474930003-83750-1-git-send-email-bmwill@google.com>
Add a submodule-prefix environment variable
'GIT_INTERNAL_SUBMODULE_PREFIX' which can be used by commands which have
--recurse-submodule options to give context to submodules about how they
were invoked. This option is only allowed for builtins which have
submodule support.
Signed-off-by: Brandon Williams <bmwill@google.com>
---
Documentation/git.txt | 5 +++++
cache.h | 1 +
environment.c | 1 +
git.c | 19 +++++++++++++++++++
4 files changed, 26 insertions(+)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 7913fc2..d29967a 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -13,6 +13,7 @@ SYNOPSIS
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
+ [--submodule-prefix=<path>]
<command> [<args>]
DESCRIPTION
@@ -601,6 +602,10 @@ foo.bar= ...`) sets `foo.bar` to the empty string.
details. Equivalent to setting the `GIT_NAMESPACE` environment
variable.
+--submodule-prefix=<path>::
+ Set a prefix which gives submodules context about the superproject that
+ invoked it. Only allowed for commands which support submodules.
+
--bare::
Treat the repository as a bare repository. If GIT_DIR
environment is not set, it is set to the current working
diff --git a/cache.h b/cache.h
index 3556326..ae88a35 100644
--- a/cache.h
+++ b/cache.h
@@ -408,6 +408,7 @@ static inline enum object_type object_type(unsigned int mode)
#define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE"
#define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE"
#define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX"
+#define GIT_SUBMODULE_PREFIX_ENVIRONMENT "GIT_INTERNAL_SUBMODULE_PREFIX"
#define DEFAULT_GIT_DIR_ENVIRONMENT ".git"
#define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY"
#define INDEX_ENVIRONMENT "GIT_INDEX_FILE"
diff --git a/environment.c b/environment.c
index ca72464..7380815 100644
--- a/environment.c
+++ b/environment.c
@@ -120,6 +120,7 @@ const char * const local_repo_env[] = {
NO_REPLACE_OBJECTS_ENVIRONMENT,
GIT_REPLACE_REF_BASE_ENVIRONMENT,
GIT_PREFIX_ENVIRONMENT,
+ GIT_SUBMODULE_PREFIX_ENVIRONMENT,
GIT_SHALLOW_FILE_ENVIRONMENT,
GIT_COMMON_DIR_ENVIRONMENT,
NULL
diff --git a/git.c b/git.c
index 1c61151..b2b096a 100644
--- a/git.c
+++ b/git.c
@@ -164,6 +164,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
setenv(GIT_WORK_TREE_ENVIRONMENT, cmd, 1);
if (envchanged)
*envchanged = 1;
+ } else if (!strcmp(cmd, "--submodule-prefix")) {
+ if (*argc < 2) {
+ fprintf(stderr, "No prefix given for --submodule-prefix.\n" );
+ usage(git_usage_string);
+ }
+ setenv(GIT_SUBMODULE_PREFIX_ENVIRONMENT, (*argv)[1], 1);
+ if (envchanged)
+ *envchanged = 1;
+ (*argv)++;
+ (*argc)--;
+ } else if (skip_prefix(cmd, "--submodule-prefix=", &cmd)) {
+ setenv(GIT_SUBMODULE_PREFIX_ENVIRONMENT, cmd, 1);
+ if (envchanged)
+ *envchanged = 1;
} else if (!strcmp(cmd, "--bare")) {
char *cwd = xgetcwd();
is_bare_repository_cfg = 1;
@@ -310,6 +324,7 @@ static int handle_alias(int *argcp, const char ***argv)
* RUN_SETUP for reading from the configuration file.
*/
#define NEED_WORK_TREE (1<<3)
+#define SUPPORT_SUBMODULES (1<<4)
struct cmd_struct {
const char *cmd;
@@ -344,6 +359,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
}
commit_pager_choice();
+ if (!help && (getenv(GIT_SUBMODULE_PREFIX_ENVIRONMENT) &&
+ !(p->option & SUPPORT_SUBMODULES)))
+ die("%s doesn't support submodules", p->cmd);
+
if (!help && p->option & NEED_WORK_TREE)
setup_work_tree();
--
2.8.0.rc3.226.g39d4020
next prev parent reply other threads:[~2016-09-26 22:47 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-24 0:13 [PATCH 0/3] recursive support for ls-files Brandon Williams
2016-09-24 0:13 ` [PATCH 1/3 v3] submodules: make submodule-prefix option an envvar Brandon Williams
2016-09-25 23:34 ` Junio C Hamano
2016-09-24 0:13 ` [PATCH 2/3 v3] ls-files: optionally recurse into submodules Brandon Williams
2016-09-24 0:13 ` [PATCH 3/3 v3] ls-files: add pathspec matching for submodules Brandon Williams
2016-09-25 7:17 ` [PATCH 0/3] recursive support for ls-files Jeff King
2016-09-25 16:32 ` Brandon Williams
2016-09-25 18:38 ` Junio C Hamano
2016-09-26 17:04 ` Brandon Williams
2016-09-26 18:17 ` Junio C Hamano
2016-09-26 18:38 ` Brandon Williams
2016-09-26 18:48 ` Junio C Hamano
2016-09-26 22:46 ` [PATCH 0/4 v4] " Brandon Williams
2016-09-26 22:46 ` Brandon Williams [this message]
2016-09-27 18:17 ` [PATCH 1/4 v4] submodules: make submodule-prefix option Junio C Hamano
2016-09-27 20:29 ` Brandon Williams
2016-09-27 20:35 ` Junio C Hamano
2016-09-27 20:43 ` Brandon Williams
2016-09-26 22:46 ` [PATCH 2/4 v4] ls-files: optionally recurse into submodules Brandon Williams
2016-09-27 18:29 ` Junio C Hamano
2016-09-27 20:33 ` Brandon Williams
2016-09-26 22:46 ` [PATCH 3/4 v4] ls-files: pass through safe options for --recurse-submodules Brandon Williams
2016-09-27 18:40 ` Junio C Hamano
2016-09-27 20:11 ` Junio C Hamano
2016-09-27 20:52 ` Brandon Williams
2016-09-27 20:58 ` Junio C Hamano
2016-09-27 20:59 ` Stefan Beller
2016-09-28 17:24 ` Brandon Williams
2016-09-28 18:59 ` Junio C Hamano
2016-09-27 20:49 ` Brandon Williams
2016-09-27 18:43 ` Junio C Hamano
2016-09-27 20:44 ` Brandon Williams
2016-09-27 20:59 ` Junio C Hamano
2016-09-26 22:46 ` [PATCH 4/4 v4] ls-files: add pathspec matching for submodules Brandon Williams
2016-09-27 20:01 ` Junio C Hamano
2016-09-27 20:40 ` Brandon Williams
2016-09-28 21:50 ` [PATCH v5 0/4] recursive support for ls-files Brandon Williams
2016-09-28 21:50 ` [PATCH v5 1/4] git: make super-prefix option Brandon Williams
2016-09-28 22:01 ` Stefan Beller
2016-09-28 22:19 ` Junio C Hamano
2016-09-29 18:39 ` Jeff King
2016-09-29 18:44 ` Brandon Williams
2016-09-28 21:50 ` [PATCH v5 2/4] ls-files: optionally recurse into submodules Brandon Williams
2016-09-28 22:11 ` Stefan Beller
2016-09-28 22:22 ` Junio C Hamano
2016-09-28 21:50 ` [PATCH v5 3/4] ls-files: pass through safe options for --recurse-submodules Brandon Williams
2016-09-28 21:50 ` [PATCH v5 4/4] ls-files: add pathspec matching for submodules Brandon Williams
2016-09-29 21:48 ` [PATCH v6 0/4] recursive support for ls-files Brandon Williams
2016-09-29 21:48 ` [PATCH v6 1/4] git: make super-prefix option Brandon Williams
2016-10-04 17:31 ` Stefan Beller
2016-10-04 17:35 ` Junio C Hamano
2016-10-04 17:39 ` Jeff King
2016-09-29 21:48 ` [PATCH v6 2/4] ls-files: optionally recurse into submodules Brandon Williams
2016-09-29 21:48 ` [PATCH v6 3/4] ls-files: pass through safe options for --recurse-submodules Brandon Williams
2016-09-30 0:14 ` Junio C Hamano
2016-09-30 16:33 ` Brandon Williams
2016-09-30 17:01 ` Brandon Williams
2016-09-29 21:48 ` [PATCH v6 4/4] ls-files: add pathspec matching for submodules Brandon Williams
2016-10-04 17:56 ` Stefan Beller
2016-10-07 18:18 ` [PATCH v7 0/4] recursive support for ls-files Brandon Williams
2016-10-07 18:18 ` [PATCH v7 1/4] git: make super-prefix option Brandon Williams
2016-10-07 18:18 ` [PATCH v7 2/4] ls-files: optionally recurse into submodules Brandon Williams
2016-10-07 18:18 ` [PATCH v7 3/4] ls-files: pass through safe options for --recurse-submodules Brandon Williams
2016-10-07 18:18 ` [PATCH v7 4/4] ls-files: add pathspec matching for submodules Brandon Williams
2016-10-07 18:34 ` [PATCH v7 0/4] recursive support for ls-files Stefan Beller
2016-10-07 18:35 ` Stefan Beller
2016-10-07 18:45 ` Brandon Williams
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=1474930003-83750-2-git-send-email-bmwill@google.com \
--to=bmwill@google.com \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).