2005-07-15 08:55:09 +08:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Eric Biederman, 2005
|
|
|
|
*/
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 15:51:05 +08:00
|
|
|
#include "builtin.h"
|
2005-07-15 08:55:09 +08:00
|
|
|
|
2010-02-14 19:55:53 +08:00
|
|
|
static const char var_usage[] = "git var (-l | <variable>)";
|
2005-07-15 08:55:09 +08:00
|
|
|
|
2009-11-12 08:01:27 +08:00
|
|
|
static const char *editor(int flag)
|
|
|
|
{
|
|
|
|
const char *pgm = git_editor();
|
|
|
|
|
2012-05-25 07:28:40 +08:00
|
|
|
if (!pgm && flag & IDENT_STRICT)
|
2009-11-12 08:01:27 +08:00
|
|
|
die("Terminal is dumb, but EDITOR unset");
|
|
|
|
|
|
|
|
return pgm;
|
|
|
|
}
|
|
|
|
|
2009-10-31 09:41:27 +08:00
|
|
|
static const char *pager(int flag)
|
|
|
|
{
|
2010-02-14 19:59:59 +08:00
|
|
|
const char *pgm = git_pager(1);
|
2009-10-31 09:41:27 +08:00
|
|
|
|
|
|
|
if (!pgm)
|
|
|
|
pgm = "cat";
|
|
|
|
return pgm;
|
|
|
|
}
|
|
|
|
|
2005-07-15 08:55:09 +08:00
|
|
|
struct git_var {
|
|
|
|
const char *name;
|
2006-02-19 12:31:05 +08:00
|
|
|
const char *(*read)(int);
|
2005-07-15 08:55:09 +08:00
|
|
|
};
|
|
|
|
static struct git_var git_vars[] = {
|
|
|
|
{ "GIT_COMMITTER_IDENT", git_committer_info },
|
|
|
|
{ "GIT_AUTHOR_IDENT", git_author_info },
|
2009-11-12 08:01:27 +08:00
|
|
|
{ "GIT_EDITOR", editor },
|
2009-10-31 09:41:27 +08:00
|
|
|
{ "GIT_PAGER", pager },
|
2005-07-15 08:55:09 +08:00
|
|
|
{ "", NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void list_vars(void)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
2009-11-12 08:01:27 +08:00
|
|
|
const char *val;
|
|
|
|
|
2009-09-01 13:35:10 +08:00
|
|
|
for (ptr = git_vars; ptr->read; ptr++)
|
2009-11-12 08:01:27 +08:00
|
|
|
if ((val = ptr->read(0)))
|
|
|
|
printf("%s=%s\n", ptr->name, val);
|
2005-07-15 08:55:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *read_var(const char *var)
|
|
|
|
{
|
|
|
|
struct git_var *ptr;
|
|
|
|
const char *val;
|
|
|
|
val = NULL;
|
2009-09-01 13:35:10 +08:00
|
|
|
for (ptr = git_vars; ptr->read; ptr++) {
|
2005-07-15 08:55:09 +08:00
|
|
|
if (strcmp(var, ptr->name) == 0) {
|
2012-05-25 07:28:40 +08:00
|
|
|
val = ptr->read(IDENT_STRICT);
|
2005-07-15 08:55:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2008-05-15 01:46:53 +08:00
|
|
|
static int show_config(const char *var, const char *value, void *cb)
|
2005-10-12 09:47:34 +08:00
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
printf("%s=%s\n", var, value);
|
|
|
|
else
|
|
|
|
printf("%s\n", var);
|
2008-05-15 01:46:53 +08:00
|
|
|
return git_default_config(var, value, cb);
|
2005-10-12 09:47:34 +08:00
|
|
|
}
|
|
|
|
|
2010-01-22 12:21:55 +08:00
|
|
|
int cmd_var(int argc, const char **argv, const char *prefix)
|
2005-07-15 08:55:09 +08:00
|
|
|
{
|
2010-08-06 11:21:40 +08:00
|
|
|
const char *val = NULL;
|
|
|
|
if (argc != 2)
|
2005-07-15 08:55:09 +08:00
|
|
|
usage(var_usage);
|
|
|
|
|
|
|
|
if (strcmp(argv[1], "-l") == 0) {
|
2008-05-15 01:46:53 +08:00
|
|
|
git_config(show_config, NULL);
|
2005-07-15 08:55:09 +08:00
|
|
|
list_vars();
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-15 01:46:53 +08:00
|
|
|
git_config(git_default_config, NULL);
|
2005-07-15 08:55:09 +08:00
|
|
|
val = read_var(argv[1]);
|
|
|
|
if (!val)
|
|
|
|
usage(var_usage);
|
2007-06-07 15:04:01 +08:00
|
|
|
|
2005-07-15 08:55:09 +08:00
|
|
|
printf("%s\n", val);
|
2007-06-07 15:04:01 +08:00
|
|
|
|
2005-07-15 08:55:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|