@@ -2,16 +2,18 @@
#include "cache.h"
#include "config.h"
-static void print_cache_entry(struct cache_entry *ce)
+static void print_cache_entry(struct cache_entry *ce, unsigned stat)
{
- /* stat info */
- printf("%08x %08x %08x %08x %08x %08x ",
- ce->ce_stat_data.sd_ctime.sec,
- ce->ce_stat_data.sd_ctime.nsec,
- ce->ce_stat_data.sd_mtime.sec,
- ce->ce_stat_data.sd_mtime.nsec,
- ce->ce_stat_data.sd_dev,
- ce->ce_stat_data.sd_ino);
+ if (stat) {
+ /* stat info */
+ printf("%08x %08x %08x %08x %08x %08x ",
+ ce->ce_stat_data.sd_ctime.sec,
+ ce->ce_stat_data.sd_ctime.nsec,
+ ce->ce_stat_data.sd_mtime.sec,
+ ce->ce_stat_data.sd_mtime.nsec,
+ ce->ce_stat_data.sd_dev,
+ ce->ce_stat_data.sd_ino);
+ }
/* mode in binary */
printf("0b%d%d%d%d ",
@@ -28,48 +30,52 @@ static void print_cache_entry(struct cache_entry *ce)
printf("%s\n", ce->name);
}
-static void print_cache(struct index_state *cache)
+static void print_cache(struct index_state *cache, unsigned stat)
{
int i;
for (i = 0; i < the_index.cache_nr; i++)
- print_cache_entry(the_index.cache[i]);
+ print_cache_entry(the_index.cache[i], stat);
}
int cmd__read_cache(int argc, const char **argv)
{
+ struct repository *r = the_repository;
int i, cnt = 1;
const char *name = NULL;
int table = 0;
+ int stat = 1;
for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) {
if (skip_prefix(*argv, "--print-and-refresh=", &name))
continue;
- if (!strcmp(*argv, "--table")) {
+ if (!strcmp(*argv, "--table"))
table = 1;
- }
+ else if (!strcmp(*argv, "--no-stat"))
+ stat = 0;
}
if (argc == 1)
cnt = strtol(argv[0], NULL, 0);
setup_git_directory();
git_config(git_default_config, NULL);
+
for (i = 0; i < cnt; i++) {
- read_cache();
+ repo_read_index(r);
if (name) {
int pos;
- refresh_index(&the_index, REFRESH_QUIET,
+ refresh_index(r->index, REFRESH_QUIET,
NULL, NULL, NULL);
- pos = index_name_pos(&the_index, name, strlen(name));
+ pos = index_name_pos(r->index, name, strlen(name));
if (pos < 0)
die("%s not in index", name);
printf("%s is%s up to date\n", name,
- ce_uptodate(the_index.cache[pos]) ? "" : " not");
+ ce_uptodate(r->index->cache[pos]) ? "" : " not");
write_file(name, "%d\n", i);
}
if (table)
- print_cache(&the_index);
- discard_cache();
+ print_cache(r->index, stat);
+ discard_index(r->index);
}
return 0;
}
@@ -132,7 +132,7 @@ test_sparse_match () {
test_expect_success 'expanded in-memory index matches full index' '
init_repos &&
- test_sparse_match test-tool read-cache --expand --table-no-stat
+ test_sparse_match test-tool read-cache --expand --table --no-stat
'
test_expect_success 'status with options' '