2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
9 static const char var_usage
[] = "git var [-l | <variable>]";
11 static const char *editor(int flag
)
13 const char *pgm
= git_editor();
15 if (!pgm
&& flag
& IDENT_ERROR_ON_NO_NAME
)
16 die("Terminal is dumb, but EDITOR unset");
23 const char *(*read
)(int);
25 static struct git_var git_vars
[] = {
26 { "GIT_COMMITTER_IDENT", git_committer_info
},
27 { "GIT_AUTHOR_IDENT", git_author_info
},
28 { "GIT_EDITOR", editor
},
32 static void list_vars(void)
37 for (ptr
= git_vars
; ptr
->read
; ptr
++)
38 if ((val
= ptr
->read(0)))
39 printf("%s=%s\n", ptr
->name
, val
);
42 static const char *read_var(const char *var
)
47 for (ptr
= git_vars
; ptr
->read
; ptr
++) {
48 if (strcmp(var
, ptr
->name
) == 0) {
49 val
= ptr
->read(IDENT_ERROR_ON_NO_NAME
);
56 static int show_config(const char *var
, const char *value
, void *cb
)
59 printf("%s=%s\n", var
, value
);
62 return git_default_config(var
, value
, cb
);
65 int main(int argc
, char **argv
)
73 git_extract_argv0_path(argv
[0]);
75 setup_git_directory_gently(&nongit
);
78 if (strcmp(argv
[1], "-l") == 0) {
79 git_config(show_config
, NULL
);
83 git_config(git_default_config
, NULL
);
84 val
= read_var(argv
[1]);