You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
1.8 KiB
100 lines
1.8 KiB
20 years ago
|
/*
|
||
|
* GIT - The information manager from hell
|
||
|
*
|
||
|
* Copyright (C) Eric Biederman, 2005
|
||
|
*/
|
||
|
#include "cache.h"
|
||
16 years ago
|
#include "exec_cmd.h"
|
||
20 years ago
|
|
||
15 years ago
|
static const char var_usage[] = "git var (-l | <variable>)";
|
||
20 years ago
|
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
|
||
15 years ago
|
static const char *pager(int flag)
|
||
|
{
|
||
15 years ago
|
const char *pgm = git_pager(1);
|
||
15 years ago
|
|
||
|
if (!pgm)
|
||
|
pgm = "cat";
|
||
|
return pgm;
|
||
|
}
|
||
|
|
||
20 years ago
|
struct git_var {
|
||
|
const char *name;
|
||
19 years ago
|
const char *(*read)(int);
|
||
20 years ago
|
};
|
||
|
static struct git_var git_vars[] = {
|
||
|
{ "GIT_COMMITTER_IDENT", git_committer_info },
|
||
|
{ "GIT_AUTHOR_IDENT", git_author_info },
|
||
15 years ago
|
{ "GIT_EDITOR", editor },
|
||
15 years ago
|
{ "GIT_PAGER", pager },
|
||
20 years ago
|
{ "", NULL },
|
||
|
};
|
||
|
|
||
|
static void list_vars(void)
|
||
|
{
|
||
|
struct git_var *ptr;
|
||
15 years ago
|
const char *val;
|
||
|
|
||
16 years ago
|
for (ptr = git_vars; ptr->read; ptr++)
|
||
15 years ago
|
if ((val = ptr->read(0)))
|
||
|
printf("%s=%s\n", ptr->name, val);
|
||
20 years ago
|
}
|
||
|
|
||
|
static const char *read_var(const char *var)
|
||
|
{
|
||
|
struct git_var *ptr;
|
||
|
const char *val;
|
||
|
val = NULL;
|
||
16 years ago
|
for (ptr = git_vars; ptr->read; ptr++) {
|
||
20 years ago
|
if (strcmp(var, ptr->name) == 0) {
|
||
17 years ago
|
val = ptr->read(IDENT_ERROR_ON_NO_NAME);
|
||
20 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
return val;
|
||
|
}
|
||
|
|
||
17 years ago
|
static int show_config(const char *var, const char *value, void *cb)
|
||
19 years ago
|
{
|
||
|
if (value)
|
||
|
printf("%s=%s\n", var, value);
|
||
|
else
|
||
|
printf("%s\n", var);
|
||
17 years ago
|
return git_default_config(var, value, cb);
|
||
19 years ago
|
}
|
||
|
|
||
15 years ago
|
int cmd_var(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
|
const char *val;
|
||
17 years ago
|
int nongit;
|
||
20 years ago
|
if (argc != 2) {
|
||
|
usage(var_usage);
|
||
|
}
|
||
19 years ago
|
|
||
17 years ago
|
setup_git_directory_gently(&nongit);
|
||
20 years ago
|
val = NULL;
|
||
|
|
||
|
if (strcmp(argv[1], "-l") == 0) {
|
||
17 years ago
|
git_config(show_config, NULL);
|
||
20 years ago
|
list_vars();
|
||
|
return 0;
|
||
|
}
|
||
17 years ago
|
git_config(git_default_config, NULL);
|
||
20 years ago
|
val = read_var(argv[1]);
|
||
|
if (!val)
|
||
|
usage(var_usage);
|
||
18 years ago
|
|
||
20 years ago
|
printf("%s\n", val);
|
||
18 years ago
|
|
||
20 years ago
|
return 0;
|
||
|
}
|