2005-07-15 02:55:09 +02:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Eric Biederman, 2005
|
|
|
|
*/
|
|
|
|
#include "cache.h"
|
2009-01-18 13:00:12 +01:00
|
|
|
#include "exec_cmd.h"
|
2005-07-15 02:55:09 +02:00
|
|
|
|
2010-02-14 12:55:53 +01:00
|
|
|
static const char var_usage[] = "git var (-l | <variable>)";
|
2005-07-15 02:55:09 +02:00
|
|
|
|
2009-11-12 01:01:27 +01: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 02:41:27 +01:00
|
|
|
static const char *pager(int flag)
|
|
|
|
{
|
2010-02-14 12:59:59 +01:00
|
|
|
const char *pgm = git_pager(1);
|
2009-10-31 02:41:27 +01:00
|
|
|
|
|
|
|
if (!pgm)
|
|
|
|
pgm = "cat";
|
|
|
|
return pgm;
|
|
|
|
}
|
|
|
|
|
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 },
|
2009-11-12 01:01:27 +01:00
|
|
|
{ "GIT_EDITOR", editor },
|
2009-10-31 02:41:27 +01:00
|
|
|
{ "GIT_PAGER", pager },
|
2005-07-15 02:55:09 +02:00
|
|
|
{ "", NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void list_vars(void)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
2009-11-12 01:01:27 +01:00
|
|
|
const char *val;
|
|
|
|
|
2009-09-01 07:35:10 +02:00
|
|
|
for (ptr = git_vars; ptr->read; ptr++)
|
2009-11-12 01:01:27 +01:00
|
|
|
if ((val = ptr->read(0)))
|
|
|
|
printf("%s=%s\n", ptr->name, val);
|
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;
|
2009-09-01 07:35:10 +02:00
|
|
|
for (ptr = git_vars; ptr->read; ptr++) {
|
2005-07-15 02:55:09 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-01-22 05:21:55 +01:00
|
|
|
int cmd_var(int argc, const char **argv, const char *prefix)
|
2005-07-15 02:55:09 +02:00
|
|
|
{
|
2010-08-06 05:21:40 +02:00
|
|
|
const char *val = NULL;
|
|
|
|
if (argc != 2)
|
2005-07-15 02:55:09 +02:00
|
|
|
usage(var_usage);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|