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