2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
10 static const char var_usage
[] = "git var (-l | <variable>)";
12 static const char *editor(int flag
)
14 const char *pgm
= git_editor();
16 if (!pgm
&& flag
& IDENT_STRICT
)
17 die("Terminal is dumb, but EDITOR unset");
22 static const char *pager(int flag
)
24 const char *pgm
= git_pager(1);
31 static const char *default_branch(int flag
)
33 return git_default_branch_name(1);
38 const char *(*read
)(int);
40 static struct git_var git_vars
[] = {
41 { "GIT_COMMITTER_IDENT", git_committer_info
},
42 { "GIT_AUTHOR_IDENT", git_author_info
},
43 { "GIT_EDITOR", editor
},
44 { "GIT_PAGER", pager
},
45 { "GIT_DEFAULT_BRANCH", default_branch
},
49 static void list_vars(void)
54 for (ptr
= git_vars
; ptr
->read
; ptr
++)
55 if ((val
= ptr
->read(0)))
56 printf("%s=%s\n", ptr
->name
, val
);
59 static const char *read_var(const char *var
)
64 for (ptr
= git_vars
; ptr
->read
; ptr
++) {
65 if (strcmp(var
, ptr
->name
) == 0) {
66 val
= ptr
->read(IDENT_STRICT
);
73 static int show_config(const char *var
, const char *value
, void *cb
)
76 printf("%s=%s\n", var
, value
);
79 return git_default_config(var
, value
, cb
);
82 int cmd_var(int argc
, const char **argv
, const char *prefix
)
84 const char *val
= NULL
;
88 if (strcmp(argv
[1], "-l") == 0) {
89 git_config(show_config
, NULL
);
93 git_config(git_default_config
, NULL
);
94 val
= read_var(argv
[1]);