2
* GIT - The information manager from hell
4
* Copyright (C) Eric Biederman, 2005
15
#include "run-command.h"
17
static const char var_usage[] = "git var (-l | <variable>)";
19
static char *committer(int ident_flag)
21
return xstrdup_or_null(git_committer_info(ident_flag));
24
static char *author(int ident_flag)
26
return xstrdup_or_null(git_author_info(ident_flag));
29
static char *editor(int ident_flag UNUSED)
31
return xstrdup_or_null(git_editor());
34
static char *sequence_editor(int ident_flag UNUSED)
36
return xstrdup_or_null(git_sequence_editor());
39
static char *pager(int ident_flag UNUSED)
41
const char *pgm = git_pager(1);
48
static char *default_branch(int ident_flag UNUSED)
50
return repo_default_branch_name(the_repository, 1);
53
static char *shell_path(int ident_flag UNUSED)
55
return git_shell_path();
58
static char *git_attr_val_system(int ident_flag UNUSED)
60
if (git_attr_system_is_enabled()) {
61
char *file = xstrdup(git_attr_system_file());
62
normalize_path_copy(file, file);
68
static char *git_attr_val_global(int ident_flag UNUSED)
70
char *file = xstrdup_or_null(git_attr_global_file());
72
normalize_path_copy(file, file);
78
static char *git_config_val_system(int ident_flag UNUSED)
80
if (git_config_system()) {
81
char *file = git_system_config();
82
normalize_path_copy(file, file);
88
static char *git_config_val_global(int ident_flag UNUSED)
90
struct strbuf buf = STRBUF_INIT;
94
git_global_config_paths(&user, &xdg);
96
normalize_path_copy(xdg, xdg);
97
strbuf_addf(&buf, "%s\n", xdg);
100
normalize_path_copy(user, user);
101
strbuf_addf(&buf, "%s\n", user);
105
strbuf_trim_trailing_newline(&buf);
107
strbuf_release(&buf);
110
return strbuf_detach(&buf, &unused);
118
static struct git_var git_vars[] = {
120
.name = "GIT_COMMITTER_IDENT",
124
.name = "GIT_AUTHOR_IDENT",
128
.name = "GIT_EDITOR",
132
.name = "GIT_SEQUENCE_EDITOR",
133
.read = sequence_editor,
140
.name = "GIT_DEFAULT_BRANCH",
141
.read = default_branch,
144
.name = "GIT_SHELL_PATH",
148
.name = "GIT_ATTR_SYSTEM",
149
.read = git_attr_val_system,
152
.name = "GIT_ATTR_GLOBAL",
153
.read = git_attr_val_global,
156
.name = "GIT_CONFIG_SYSTEM",
157
.read = git_config_val_system,
160
.name = "GIT_CONFIG_GLOBAL",
161
.read = git_config_val_global,
170
static void list_vars(void)
175
for (ptr = git_vars; ptr->read; ptr++)
176
if ((val = ptr->read(0))) {
177
if (ptr->multivalued && *val) {
178
struct string_list list = STRING_LIST_INIT_DUP;
181
string_list_split(&list, val, '\n', -1);
182
for (i = 0; i < list.nr; i++)
183
printf("%s=%s\n", ptr->name, list.items[i].string);
184
string_list_clear(&list, 0);
186
printf("%s=%s\n", ptr->name, val);
192
static const struct git_var *get_git_var(const char *var)
195
for (ptr = git_vars; ptr->read; ptr++) {
196
if (strcmp(var, ptr->name) == 0) {
203
static int show_config(const char *var, const char *value,
204
const struct config_context *ctx, void *cb)
207
printf("%s=%s\n", var, value);
210
return git_default_config(var, value, ctx, cb);
213
int cmd_var(int argc, const char **argv, const char *prefix UNUSED)
215
const struct git_var *git_var;
221
if (strcmp(argv[1], "-l") == 0) {
222
git_config(show_config, NULL);
226
git_config(git_default_config, NULL);
228
git_var = get_git_var(argv[1]);
232
val = git_var->read(IDENT_STRICT);