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