2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
8 static const char var_usage
[] = "git var (-l | <variable>)";
10 static const char *editor(int flag
)
12 const char *pgm
= git_editor();
14 if (!pgm
&& flag
& IDENT_ERROR_ON_NO_NAME
)
15 die("Terminal is dumb, but EDITOR unset");
20 static const char *pager(int flag
)
22 const char *pgm
= git_pager(1);
31 const char *(*read
)(int);
33 static struct git_var git_vars
[] = {
34 { "GIT_COMMITTER_IDENT", git_committer_info
},
35 { "GIT_AUTHOR_IDENT", git_author_info
},
36 { "GIT_EDITOR", editor
},
37 { "GIT_PAGER", pager
},
41 static void list_vars(void)
46 for (ptr
= git_vars
; ptr
->read
; ptr
++)
47 if ((val
= ptr
->read(0)))
48 printf("%s=%s\n", ptr
->name
, val
);
51 static const char *read_var(const char *var
)
56 for (ptr
= git_vars
; ptr
->read
; ptr
++) {
57 if (strcmp(var
, ptr
->name
) == 0) {
58 val
= ptr
->read(IDENT_ERROR_ON_NO_NAME
);
65 static int show_config(const char *var
, const char *value
, void *cb
)
68 printf("%s=%s\n", var
, value
);
71 return git_default_config(var
, value
, cb
);
74 int cmd_var(int argc
, const char **argv
, const char *prefix
)
76 const char *val
= NULL
;
80 if (strcmp(argv
[1], "-l") == 0) {
81 git_config(show_config
, NULL
);
85 git_config(git_default_config
, NULL
);
86 val
= read_var(argv
[1]);