From: Derrick Stolee <dstolee@xxxxxxxxxxxxx> The 'test-tool read-cache --table' output is helpful to understand the full contents of the index entries on-disk. This is particularly helpful when trying to diagnose issues with a real repository example. However, for test cases we might want to compare the index contents of two repositories that were updated in similar ways, but will not actually share the same stat data. Add the '--no-stat' option to remove the timestamps and other stat data from the output. This allows us to compare index contents directly. Signed-off-by: Derrick Stolee <dstolee@xxxxxxxxxxxxx> --- t/helper/test-read-cache.c | 44 ++++++++++++++---------- t/t1092-sparse-checkout-compatibility.sh | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index cd7d106a675..f858d0d0a0c 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -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; } diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 8876eae0fe3..3aa9b0d21b4 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -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' ' -- gitgitgadget