2005-07-15 02:55:09 +02:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Eric Biederman, 2005
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
|
|
|
|
2005-07-29 11:01:26 +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++) {
|
2006-02-19 05:31:05 +01:00
|
|
|
printf("%s=%s\n", ptr->name, ptr->read(0));
|
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) {
|
2006-02-19 05:31:05 +01:00
|
|
|
val = ptr->read(1);
|
2005-07-15 02:55:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2005-10-12 03:47:34 +02:00
|
|
|
static int show_config(const char *var, const char *value)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
printf("%s=%s\n", var, value);
|
|
|
|
else
|
|
|
|
printf("%s\n", var);
|
|
|
|
return git_default_config(var, value);
|
|
|
|
}
|
|
|
|
|
2005-07-15 02:55:09 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *val;
|
|
|
|
if (argc != 2) {
|
|
|
|
usage(var_usage);
|
|
|
|
}
|
2005-11-24 10:31:01 +01:00
|
|
|
|
|
|
|
setup_git_directory();
|
2005-07-15 02:55:09 +02:00
|
|
|
val = NULL;
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "-l") == 0) {
|
2005-10-12 03:47:34 +02:00
|
|
|
git_config(show_config);
|
2005-07-15 02:55:09 +02:00
|
|
|
list_vars();
|
|
|
|
return 0;
|
|
|
|
}
|
2005-10-12 03:47:34 +02:00
|
|
|
git_config(git_default_config);
|
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;
|
|
|
|
}
|