2005-07-15 00:55:09 +00:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Eric Biederman, 2005
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
2009-01-18 12:00:12 +00:00
|
|
|
#include "exec_cmd.h"
|
2005-07-15 00:55:09 +00:00
|
|
|
|
2010-02-14 11:55:53 +00:00
|
|
|
static const char var_usage[] = "git var (-l | <variable>)";
|
2005-07-15 00:55:09 +00:00
|
|
|
|
2009-11-12 00:01:27 +00:00
|
|
|
static const char *editor(int flag)
|
|
|
|
{
|
|
|
|
const char *pgm = git_editor();
|
|
|
|
|
|
|
|
if (!pgm && flag & IDENT_ERROR_ON_NO_NAME)
|
|
|
|
die("Terminal is dumb, but EDITOR unset");
|
|
|
|
|
|
|
|
return pgm;
|
|
|
|
}
|
|
|
|
|
2009-10-31 01:41:27 +00:00
|
|
|
static const char *pager(int flag)
|
|
|
|
{
|
2010-02-14 11:59:59 +00:00
|
|
|
const char *pgm = git_pager(1);
|
2009-10-31 01:41:27 +00:00
|
|
|
|
|
|
|
if (!pgm)
|
|
|
|
pgm = "cat";
|
|
|
|
return pgm;
|
|
|
|
}
|
|
|
|
|
2005-07-15 00:55:09 +00:00
|
|
|
struct git_var {
|
|
|
|
const char *name;
|
2006-02-19 04:31:05 +00:00
|
|
|
const char *(*read)(int);
|
2005-07-15 00:55:09 +00:00
|
|
|
};
|
|
|
|
static struct git_var git_vars[] = {
|
|
|
|
{ "GIT_COMMITTER_IDENT", git_committer_info },
|
|
|
|
{ "GIT_AUTHOR_IDENT", git_author_info },
|
2009-11-12 00:01:27 +00:00
|
|
|
{ "GIT_EDITOR", editor },
|
2009-10-31 01:41:27 +00:00
|
|
|
{ "GIT_PAGER", pager },
|
2005-07-15 00:55:09 +00:00
|
|
|
{ "", NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void list_vars(void)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
2009-11-12 00:01:27 +00:00
|
|
|
const char *val;
|
|
|
|
|
2009-09-01 05:35:10 +00:00
|
|
|
for (ptr = git_vars; ptr->read; ptr++)
|
2009-11-12 00:01:27 +00:00
|
|
|
if ((val = ptr->read(0)))
|
|
|
|
printf("%s=%s\n", ptr->name, val);
|
2005-07-15 00:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *read_var(const char *var)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
|
|
|
const char *val;
|
|
|
|
val = NULL;
|
2009-09-01 05:35:10 +00:00
|
|
|
for (ptr = git_vars; ptr->read; ptr++) {
|
2005-07-15 00:55:09 +00:00
|
|
|
if (strcmp(var, ptr->name) == 0) {
|
2007-12-09 01:32:08 +00:00
|
|
|
val = ptr->read(IDENT_ERROR_ON_NO_NAME);
|
2005-07-15 00:55:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-05-14 17:46:53 +00:00
|
|
|
static int show_config(const char *var, const char *value, void *cb)
|
2005-10-12 01:47:34 +00:00
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
printf("%s=%s\n", var, value);
|
|
|
|
else
|
|
|
|
printf("%s\n", var);
|
2008-05-14 17:46:53 +00:00
|
|
|
return git_default_config(var, value, cb);
|
2005-10-12 01:47:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-22 04:21:55 +00:00
|
|
|
int cmd_var(int argc, const char **argv, const char *prefix)
|
2005-07-15 00:55:09 +00:00
|
|
|
{
|
|
|
|
const char *val;
|
2008-03-14 17:29:27 +00:00
|
|
|
int nongit;
|
2005-07-15 00:55:09 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
usage(var_usage);
|
|
|
|
}
|
2005-11-24 09:31:01 +00:00
|
|
|
|
2008-03-14 17:29:27 +00:00
|
|
|
setup_git_directory_gently(&nongit);
|
2005-07-15 00:55:09 +00:00
|
|
|
val = NULL;
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "-l") == 0) {
|
2008-05-14 17:46:53 +00:00
|
|
|
git_config(show_config, NULL);
|
2005-07-15 00:55:09 +00:00
|
|
|
list_vars();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-14 17:46:53 +00:00
|
|
|
git_config(git_default_config, NULL);
|
2005-07-15 00:55:09 +00:00
|
|
|
val = read_var(argv[1]);
|
|
|
|
if (!val)
|
|
|
|
usage(var_usage);
|
2007-06-07 07:04:01 +00:00
|
|
|
|
2005-07-15 00:55:09 +00:00
|
|
|
printf("%s\n", val);
|
2007-06-07 07:04:01 +00:00
|
|
|
|
2005-07-15 00:55:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|