var.con commit fetch: Allow transport -v -v -v to set verbosity to 3 (cff7123)
   1/*
   2 * GIT - The information manager from hell
   3 *
   4 * Copyright (C) Eric Biederman, 2005
   5 */
   6#include "cache.h"
   7#include "exec_cmd.h"
   8
   9static const char var_usage[] = "git var [-l | <variable>]";
  10
  11struct git_var {
  12        const char *name;
  13        const char *(*read)(int);
  14};
  15static struct git_var git_vars[] = {
  16        { "GIT_COMMITTER_IDENT", git_committer_info },
  17        { "GIT_AUTHOR_IDENT",   git_author_info },
  18        { "", NULL },
  19};
  20
  21static void list_vars(void)
  22{
  23        struct git_var *ptr;
  24        for (ptr = git_vars; ptr->read; ptr++)
  25                printf("%s=%s\n", ptr->name, ptr->read(IDENT_WARN_ON_NO_NAME));
  26}
  27
  28static const char *read_var(const char *var)
  29{
  30        struct git_var *ptr;
  31        const char *val;
  32        val = NULL;
  33        for (ptr = git_vars; ptr->read; ptr++) {
  34                if (strcmp(var, ptr->name) == 0) {
  35                        val = ptr->read(IDENT_ERROR_ON_NO_NAME);
  36                        break;
  37                }
  38        }
  39        return val;
  40}
  41
  42static int show_config(const char *var, const char *value, void *cb)
  43{
  44        if (value)
  45                printf("%s=%s\n", var, value);
  46        else
  47                printf("%s\n", var);
  48        return git_default_config(var, value, cb);
  49}
  50
  51int main(int argc, char **argv)
  52{
  53        const char *val;
  54        int nongit;
  55        if (argc != 2) {
  56                usage(var_usage);
  57        }
  58
  59        git_extract_argv0_path(argv[0]);
  60
  61        setup_git_directory_gently(&nongit);
  62        val = NULL;
  63
  64        if (strcmp(argv[1], "-l") == 0) {
  65                git_config(show_config, NULL);
  66                list_vars();
  67                return 0;
  68        }
  69        git_config(git_default_config, NULL);
  70        val = read_var(argv[1]);
  71        if (!val)
  72                usage(var_usage);
  73
  74        printf("%s\n", val);
  75
  76        return 0;
  77}