git-clone: Allow cloning into directories other than child of current dir.
[git/gitweb.git] / var.c
blob51cf86a5843acc3b6bc3d8c4be9fec0fdd0a0df5
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
5 */
6 #include "cache.h"
7 #include <stdio.h>
8 #include <errno.h>
9 #include <string.h>
11 static const char var_usage[] = "git-var [-l | <variable>]";
13 struct git_var {
14 const char *name;
15 char *(*read)(void);
17 static struct git_var git_vars[] = {
18 { "GIT_COMMITTER_IDENT", git_committer_info },
19 { "GIT_AUTHOR_IDENT", git_author_info },
20 { "", NULL },
23 static void list_vars(void)
25 struct git_var *ptr;
26 for(ptr = git_vars; ptr->read; ptr++) {
27 printf("%s=%s\n", ptr->name, ptr->read());
31 static const char *read_var(const char *var)
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;
42 return val;
45 static int show_config(const char *var, const char *value)
47 if (value)
48 printf("%s=%s\n", var, value);
49 else
50 printf("%s\n", var);
51 return git_default_config(var, value);
54 int main(int argc, char **argv)
56 const char *val;
57 if (argc != 2) {
58 usage(var_usage);
60 setup_ident();
61 val = NULL;
63 if (strcmp(argv[1], "-l") == 0) {
64 git_config(show_config);
65 list_vars();
66 return 0;
68 git_config(git_default_config);
69 val = read_var(argv[1]);
70 if (!val)
71 usage(var_usage);
73 printf("%s\n", val);
75 return 0;