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