1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Eric Biederman, 2005
5 */
6#include "cache.h"
7
8static const char var_usage[] = "git-var [-l | <variable>]";
9
10struct git_var {
11 const char *name;
12 const char *(*read)(int);
13};
14static struct git_var git_vars[] = {
15 { "GIT_COMMITTER_IDENT", git_committer_info },
16 { "GIT_AUTHOR_IDENT", git_author_info },
17 { "", NULL },
18};
19
20static void list_vars(void)
21{
22 struct git_var *ptr;
23 for(ptr = git_vars; ptr->read; ptr++) {
24 printf("%s=%s\n", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));
25 }
26}
27
28static const char *read_var(const char *var)
29{
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(IDENT_ERROR_ON_NO_NAME);
36 break;
37 }
38 }
39 return val;
40}
41
42static int show_config(const char *var, const char *value)
43{
44 if (value)
45 printf("%s=%s\n", var, value);
46 else
47 printf("%s\n", var);
48 return git_default_config(var, value);
49}
50
51int main(int argc, char **argv)
52{
53 const char *val;
54 int nongit;
55 if (argc != 2) {
56 usage(var_usage);
57 }
58
59 setup_git_directory_gently(&nongit);
60 val = NULL;
61
62 if (strcmp(argv[1], "-l") == 0) {
63 git_config(show_config);
64 list_vars();
65 return 0;
66 }
67 git_config(git_default_config);
68 val = read_var(argv[1]);
69 if (!val)
70 usage(var_usage);
71
72 printf("%s\n", val);
73
74 return 0;
75}