t / helper / test-read-cache.con commit userdiff: add a builtin pattern for dts files (3c81760)
   1#include "test-tool.h"
   2#include "cache.h"
   3#include "config.h"
   4
   5int cmd__read_cache(int argc, const char **argv)
   6{
   7        int i, cnt = 1, namelen;
   8        const char *name = NULL;
   9
  10        if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {
  11                namelen = strlen(name);
  12                argc--;
  13                argv++;
  14        }
  15
  16        if (argc == 2)
  17                cnt = strtol(argv[1], NULL, 0);
  18        setup_git_directory();
  19        git_config(git_default_config, NULL);
  20        for (i = 0; i < cnt; i++) {
  21                read_cache();
  22                if (name) {
  23                        int pos;
  24
  25                        refresh_index(&the_index, REFRESH_QUIET,
  26                                      NULL, NULL, NULL);
  27                        pos = index_name_pos(&the_index, name, namelen);
  28                        if (pos < 0)
  29                                die("%s not in index", name);
  30                        printf("%s is%s up to date\n", name,
  31                               ce_uptodate(the_index.cache[pos]) ? "" : " not");
  32                        write_file(name, "%d\n", i);
  33                }
  34                discard_cache();
  35        }
  36        return 0;
  37}