2018-03-24 08:44:39 +01:00
|
|
|
#include "test-tool.h"
|
2006-04-24 05:20:25 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "cache-tree.h"
|
|
|
|
|
2006-04-28 01:22:45 +02:00
|
|
|
|
|
|
|
static void dump_one(struct cache_tree *it, const char *pfx, const char *x)
|
|
|
|
{
|
|
|
|
if (it->entry_count < 0)
|
|
|
|
printf("%-40s %s%s (%d subtrees)\n",
|
|
|
|
"invalid", x, pfx, it->subtree_nr);
|
|
|
|
else
|
|
|
|
printf("%s %s%s (%d entries, %d subtrees)\n",
|
2017-05-01 04:28:56 +02:00
|
|
|
oid_to_hex(&it->oid), x, pfx,
|
2006-04-28 01:22:45 +02:00
|
|
|
it->entry_count, it->subtree_nr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dump_cache_tree(struct cache_tree *it,
|
|
|
|
struct cache_tree *ref,
|
|
|
|
const char *pfx)
|
2006-04-24 05:20:25 +02:00
|
|
|
{
|
|
|
|
int i;
|
2006-04-28 01:22:45 +02:00
|
|
|
int errs = 0;
|
|
|
|
|
2006-05-04 00:32:54 +02:00
|
|
|
if (!it || !ref)
|
|
|
|
/* missing in either */
|
|
|
|
return 0;
|
2006-04-28 01:22:45 +02:00
|
|
|
|
|
|
|
if (it->entry_count < 0) {
|
2014-07-08 02:33:43 +02:00
|
|
|
/* invalid */
|
2006-04-28 01:22:45 +02:00
|
|
|
dump_one(it, pfx, "");
|
|
|
|
dump_one(ref, pfx, "#(ref) ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dump_one(it, pfx, "");
|
2017-05-01 04:28:56 +02:00
|
|
|
if (oidcmp(&it->oid, &ref->oid) ||
|
2006-04-28 01:22:45 +02:00
|
|
|
ref->entry_count != it->entry_count ||
|
|
|
|
ref->subtree_nr != it->subtree_nr) {
|
2014-07-08 02:33:43 +02:00
|
|
|
/* claims to be valid but is lying */
|
2006-04-28 01:22:45 +02:00
|
|
|
dump_one(ref, pfx, "#(ref) ");
|
|
|
|
errs = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-24 05:20:25 +02:00
|
|
|
for (i = 0; i < it->subtree_nr; i++) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
struct cache_tree_sub *down = it->down[i];
|
2006-04-28 01:22:45 +02:00
|
|
|
struct cache_tree_sub *rdwn;
|
|
|
|
|
|
|
|
rdwn = cache_tree_sub(ref, down->name);
|
2015-09-24 23:06:03 +02:00
|
|
|
xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
|
2006-04-28 01:22:45 +02:00
|
|
|
if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
|
|
|
|
errs = 1;
|
2006-04-24 05:20:25 +02:00
|
|
|
}
|
2006-04-28 01:22:45 +02:00
|
|
|
return errs;
|
2006-04-24 05:20:25 +02:00
|
|
|
}
|
|
|
|
|
2018-03-24 08:44:39 +01:00
|
|
|
int cmd__dump_cache_tree(int ac, const char **av)
|
2006-04-24 05:20:25 +02:00
|
|
|
{
|
2014-06-13 14:19:32 +02:00
|
|
|
struct index_state istate;
|
2006-04-28 01:22:45 +02:00
|
|
|
struct cache_tree *another = cache_tree();
|
2016-10-20 08:16:59 +02:00
|
|
|
setup_git_directory();
|
2006-04-25 06:18:58 +02:00
|
|
|
if (read_cache() < 0)
|
2006-04-24 05:20:25 +02:00
|
|
|
die("unable to read index file");
|
2014-06-13 14:19:32 +02:00
|
|
|
istate = the_index;
|
|
|
|
istate.cache_tree = another;
|
|
|
|
cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
|
2006-04-28 01:22:45 +02:00
|
|
|
return dump_cache_tree(active_cache_tree, another, "");
|
2006-04-24 05:20:25 +02:00
|
|
|
}
|