From 44451a2e5eec5360378be23e2cdbd9ecee49e14e Mon Sep 17 00:00:00 2001 From: John Cai Date: Sat, 6 May 2023 04:15:29 +0000 Subject: attr: teach "--attr-source=" global option to "git" Earlier, 47cfc9bd (attr: add flag `--source` to work with tree-ish, 2023-01-14) taught "git check-attr" the "--source=" option to allow it to read attribute files from a tree-ish, but did so only for the command. Just like "check-attr" users wanted a way to use attributes from a tree-ish and not from the working tree files, users of other commands (like "git diff") would benefit from the same. Undo most of the UI change the commit made, while keeping the internal logic to read attributes from a given tree-ish. Expose the internal logic via a new "--attr-source=" command line option given to "git", so that it can be used with any git command that runs as part of the main git process. Additionally, add an environment variable GIT_ATTR_SOURCE that is set when --attr-source is passed in, so that subprocesses use the same value for the attributes source tree. Signed-off-by: John Cai Signed-off-by: Junio C Hamano --- git.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'git.c') diff --git a/git.c b/git.c index 45899be826..2f42da20f4 100644 --- a/git.c +++ b/git.c @@ -9,6 +9,7 @@ #include "alias.h" #include "replace-object.h" #include "setup.h" +#include "attr.h" #include "shallow.h" #include "trace.h" #include "trace2.h" @@ -314,6 +315,21 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) } else { exit(list_cmds(cmd)); } + } else if (!strcmp(cmd, "--attr-source")) { + if (*argc < 2) { + fprintf(stderr, _("no attribute source given for --attr-source\n" )); + usage(git_usage_string); + } + setenv(GIT_ATTR_SOURCE_ENVIRONMENT, (*argv)[1], 1); + if (envchanged) + *envchanged = 1; + (*argv)++; + (*argc)--; + } else if (skip_prefix(cmd, "--attr-source=", &cmd)) { + set_git_attr_source(cmd); + setenv(GIT_ATTR_SOURCE_ENVIRONMENT, cmd, 1); + if (envchanged) + *envchanged = 1; } else { fprintf(stderr, _("unknown option: %s\n"), cmd); usage(git_usage_string); -- cgit v1.2.3