2006-04-24 07:20:25 +04:00
|
|
|
#include "cache.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "cache-tree.h"
|
|
|
|
|
2006-04-28 03:22:45 +04: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",
|
|
|
|
sha1_to_hex(it->sha1), x, pfx,
|
|
|
|
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 07:20:25 +04:00
|
|
|
{
|
|
|
|
int i;
|
2006-04-28 03:22:45 +04:00
|
|
|
int errs = 0;
|
|
|
|
|
2006-05-04 02:32:54 +04:00
|
|
|
if (!it || !ref)
|
|
|
|
/* missing in either */
|
|
|
|
return 0;
|
2006-04-28 03:22:45 +04:00
|
|
|
|
|
|
|
if (it->entry_count < 0) {
|
2014-07-08 04:33:43 +04:00
|
|
|
/* invalid */
|
2006-04-28 03:22:45 +04:00
|
|
|
dump_one(it, pfx, "");
|
|
|
|
dump_one(ref, pfx, "#(ref) ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dump_one(it, pfx, "");
|
2006-08-17 22:54:57 +04:00
|
|
|
if (hashcmp(it->sha1, ref->sha1) ||
|
2006-04-28 03:22:45 +04:00
|
|
|
ref->entry_count != it->entry_count ||
|
|
|
|
ref->subtree_nr != it->subtree_nr) {
|
2014-07-08 04:33:43 +04:00
|
|
|
/* claims to be valid but is lying */
|
2006-04-28 03:22:45 +04:00
|
|
|
dump_one(ref, pfx, "#(ref) ");
|
|
|
|
errs = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-24 07:20:25 +04:00
|
|
|
for (i = 0; i < it->subtree_nr; i++) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
struct cache_tree_sub *down = it->down[i];
|
2006-04-28 03:22:45 +04:00
|
|
|
struct cache_tree_sub *rdwn;
|
|
|
|
|
|
|
|
rdwn = cache_tree_sub(ref, down->name);
|
2015-09-25 00:06:03 +03:00
|
|
|
xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name);
|
2006-04-28 03:22:45 +04:00
|
|
|
if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path))
|
|
|
|
errs = 1;
|
2006-04-24 07:20:25 +04:00
|
|
|
}
|
2006-04-28 03:22:45 +04:00
|
|
|
return errs;
|
2006-04-24 07:20:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int ac, char **av)
|
|
|
|
{
|
2014-06-13 16:19:32 +04:00
|
|
|
struct index_state istate;
|
2006-04-28 03:22:45 +04:00
|
|
|
struct cache_tree *another = cache_tree();
|
2006-04-25 08:18:58 +04:00
|
|
|
if (read_cache() < 0)
|
2006-04-24 07:20:25 +04:00
|
|
|
die("unable to read index file");
|
2014-06-13 16:19:32 +04:00
|
|
|
istate = the_index;
|
|
|
|
istate.cache_tree = another;
|
|
|
|
cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
|
2006-04-28 03:22:45 +04:00
|
|
|
return dump_cache_tree(active_cache_tree, another, "");
|
2006-04-24 07:20:25 +04:00
|
|
|
}
|