git-send-email: Add --threaded option
[git/mingw.git] / var.c
blob4127031910c83987c8ef394e3711942e2db8a8f9
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
5 */
6 #include "cache.h"
8 static const char var_usage[] = "git-var [-l | <variable>]";
10 struct git_var {
11 const char *name;
12 const char *(*read)(int);
14 static struct git_var git_vars[] = {
15 { "GIT_COMMITTER_IDENT", git_committer_info },
16 { "GIT_AUTHOR_IDENT", git_author_info },
17 { "", NULL },
20 static void list_vars(void)
22 struct git_var *ptr;
23 for(ptr = git_vars; ptr->read; ptr++) {
24 printf("%s=%s\n", ptr->name, ptr->read(0));
28 static const char *read_var(const char *var)
30 struct git_var *ptr;
31 const char *val;
32 val = NULL;
33 for(ptr = git_vars; ptr->read; ptr++) {
34 if (strcmp(var, ptr->name) == 0) {
35 val = ptr->read(1);
36 break;
39 return val;
42 static int show_config(const char *var, const char *value)
44 if (value)
45 printf("%s=%s\n", var, value);
46 else
47 printf("%s\n", var);
48 return git_default_config(var, value);
51 int main(int argc, char **argv)
53 const char *val;
54 if (argc != 2) {
55 usage(var_usage);
58 setup_git_directory();
59 val = NULL;
61 if (strcmp(argv[1], "-l") == 0) {
62 git_config(show_config);
63 list_vars();
64 return 0;
66 git_config(git_default_config);
67 val = read_var(argv[1]);
68 if (!val)
69 usage(var_usage);
71 printf("%s\n", val);
73 return 0;