2005-07-15 04:55:09 +04:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Eric Biederman, 2005
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
2009-01-18 15:00:12 +03:00
|
|
|
#include "exec_cmd.h"
|
2005-07-15 04:55:09 +04:00
|
|
|
|
2008-07-30 21:48:33 +04:00
|
|
|
static const char var_usage[] = "git var [-l | <variable>]";
|
2005-07-15 04:55:09 +04:00
|
|
|
|
|
|
|
struct git_var {
|
|
|
|
const char *name;
|
2006-02-19 07:31:05 +03:00
|
|
|
const char *(*read)(int);
|
2005-07-15 04:55:09 +04:00
|
|
|
};
|
|
|
|
static struct git_var git_vars[] = {
|
|
|
|
{ "GIT_COMMITTER_IDENT", git_committer_info },
|
|
|
|
{ "GIT_AUTHOR_IDENT", git_author_info },
|
|
|
|
{ "", NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void list_vars(void)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
|
|
|
for(ptr = git_vars; ptr->read; ptr++) {
|
2007-12-09 04:32:08 +03:00
|
|
|
printf("%s=%s\n", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));
|
2005-07-15 04:55:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *read_var(const char *var)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
|
|
|
const char *val;
|
|
|
|
val = NULL;
|
|
|
|
for(ptr = git_vars; ptr->read; ptr++) {
|
|
|
|
if (strcmp(var, ptr->name) == 0) {
|
2007-12-09 04:32:08 +03:00
|
|
|
val = ptr->read(IDENT_ERROR_ON_NO_NAME);
|
2005-07-15 04:55:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-05-14 21:46:53 +04:00
|
|
|
static int show_config(const char *var, const char *value, void *cb)
|
2005-10-12 05:47:34 +04:00
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
printf("%s=%s\n", var, value);
|
|
|
|
else
|
|
|
|
printf("%s\n", var);
|
2008-05-14 21:46:53 +04:00
|
|
|
return git_default_config(var, value, cb);
|
2005-10-12 05:47:34 +04:00
|
|
|
}
|
|
|
|
|
2005-07-15 04:55:09 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *val;
|
2008-03-14 20:29:27 +03:00
|
|
|
int nongit;
|
2005-07-15 04:55:09 +04:00
|
|
|
if (argc != 2) {
|
|
|
|
usage(var_usage);
|
|
|
|
}
|
2005-11-24 12:31:01 +03:00
|
|
|
|
2009-01-18 15:00:12 +03:00
|
|
|
git_extract_argv0_path(argv[0]);
|
|
|
|
|
2008-03-14 20:29:27 +03:00
|
|
|
setup_git_directory_gently(&nongit);
|
2005-07-15 04:55:09 +04:00
|
|
|
val = NULL;
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "-l") == 0) {
|
2008-05-14 21:46:53 +04:00
|
|
|
git_config(show_config, NULL);
|
2005-07-15 04:55:09 +04:00
|
|
|
list_vars();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-14 21:46:53 +04:00
|
|
|
git_config(git_default_config, NULL);
|
2005-07-15 04:55:09 +04:00
|
|
|
val = read_var(argv[1]);
|
|
|
|
if (!val)
|
|
|
|
usage(var_usage);
|
2007-06-07 11:04:01 +04:00
|
|
|
|
2005-07-15 04:55:09 +04:00
|
|
|
printf("%s\n", val);
|
2007-06-07 11:04:01 +04:00
|
|
|
|
2005-07-15 04:55:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|