builtin-check-attr.con commit threaded delta search: specify number of threads at run time (367f4a4)
   1#include "builtin.h"
   2#include "cache.h"
   3#include "attr.h"
   4#include "quote.h"
   5
   6static const char check_attr_usage[] =
   7"git-check-attr attr... [--] pathname...";
   8
   9int cmd_check_attr(int argc, const char **argv, const char *prefix)
  10{
  11        struct git_attr_check *check;
  12        int cnt, i, doubledash;
  13
  14        if (read_cache() < 0) {
  15                die("invalid cache");
  16        }
  17
  18        doubledash = -1;
  19        for (i = 1; doubledash < 0 && i < argc; i++) {
  20                if (!strcmp(argv[i], "--"))
  21                        doubledash = i;
  22        }
  23
  24        /* If there is no double dash, we handle only one attribute */
  25        if (doubledash < 0) {
  26                cnt = 1;
  27                doubledash = 1;
  28        } else
  29                cnt = doubledash - 1;
  30        doubledash++;
  31
  32        if (cnt <= 0 || argc < doubledash)
  33                usage(check_attr_usage);
  34        check = xcalloc(cnt, sizeof(*check));
  35        for (i = 0; i < cnt; i++) {
  36                const char *name;
  37                struct git_attr *a;
  38                name = argv[i + 1];
  39                a = git_attr(name, strlen(name));
  40                if (!a)
  41                        return error("%s: not a valid attribute name", name);
  42                check[i].attr = a;
  43        }
  44
  45        for (i = doubledash; i < argc; i++) {
  46                int j;
  47                if (git_checkattr(argv[i], cnt, check))
  48                        die("git_checkattr died");
  49                for (j = 0; j < cnt; j++) {
  50                        const char *value = check[j].value;
  51
  52                        if (ATTR_TRUE(value))
  53                                value = "set";
  54                        else if (ATTR_FALSE(value))
  55                                value = "unset";
  56                        else if (ATTR_UNSET(value))
  57                                value = "unspecified";
  58
  59                        write_name_quoted("", 0, argv[i], 1, stdout);
  60                        printf(": %s: %s\n", argv[j+1], value);
  61                }
  62        }
  63        return 0;
  64}