2 * GIT - The information manager from hell
4 * Copyright (C) Eric Biederman, 2005
13 static const char var_usage
[] = "git var (-l | <variable>)";
15 static const char *editor(int flag
)
20 static const char *sequence_editor(int flag
)
22 return git_sequence_editor();
25 static const char *pager(int flag
)
27 const char *pgm
= git_pager(1);
34 static const char *default_branch(int flag
)
36 return git_default_branch_name(1);
41 const char *(*read
)(int);
43 static struct git_var git_vars
[] = {
44 { "GIT_COMMITTER_IDENT", git_committer_info
},
45 { "GIT_AUTHOR_IDENT", git_author_info
},
46 { "GIT_EDITOR", editor
},
47 { "GIT_SEQUENCE_EDITOR", sequence_editor
},
48 { "GIT_PAGER", pager
},
49 { "GIT_DEFAULT_BRANCH", default_branch
},
53 static void list_vars(void)
58 for (ptr
= git_vars
; ptr
->read
; ptr
++)
59 if ((val
= ptr
->read(0)))
60 printf("%s=%s\n", ptr
->name
, val
);
63 static const struct git_var
*get_git_var(const char *var
)
66 for (ptr
= git_vars
; ptr
->read
; ptr
++) {
67 if (strcmp(var
, ptr
->name
) == 0) {
74 static int show_config(const char *var
, const char *value
, void *cb
)
77 printf("%s=%s\n", var
, value
);
80 return git_default_config(var
, value
, cb
);
83 int cmd_var(int argc
, const char **argv
, const char *prefix
)
85 const struct git_var
*git_var
;
91 if (strcmp(argv
[1], "-l") == 0) {
92 git_config(show_config
, NULL
);
96 git_config(git_default_config
, NULL
);
98 git_var
= get_git_var(argv
[1]);
102 val
= git_var
->read(IDENT_STRICT
);