2022-11-19 13:07:37 +00:00
|
|
|
#define USE_THE_INDEX_VARIABLE
|
2018-03-24 07:44:39 +00:00
|
|
|
#include "test-tool.h"
|
2023-04-22 20:17:20 +00:00
|
|
|
#include "hash.h"
|
2023-02-24 00:09:27 +00:00
|
|
|
#include "hex.h"
|
2006-04-24 03:20:25 +00:00
|
|
|
#include "tree.h"
|
|
|
|
#include "cache-tree.h"
|
2023-05-16 06:33:56 +00:00
|
|
|
#include "read-cache-ll.h"
|
2023-04-22 20:17:20 +00:00
|
|
|
#include "repository.h"
|
2023-03-21 06:26:05 +00:00
|
|
|
#include "setup.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",
|
2017-05-01 02:28:56 +00:00
|
|
|
oid_to_hex(&it->oid), x, pfx,
|
2006-04-27 23:22:45 +00: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 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, "");
|
2018-08-28 21:22:48 +00:00
|
|
|
if (!oideq(&it->oid, &ref->oid) ||
|
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
|
|
|
}
|
|
|
|
|
2023-03-28 20:57:25 +00:00
|
|
|
int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
|
2006-04-24 03:20:25 +00:00
|
|
|
{
|
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();
|
2022-07-01 10:37:34 +00:00
|
|
|
int ret;
|
|
|
|
|
2016-10-20 06:16:59 +00:00
|
|
|
setup_git_directory();
|
2022-11-19 13:07:35 +00:00
|
|
|
if (repo_read_index(the_repository) < 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);
|
2022-11-19 13:07:34 +00:00
|
|
|
ret = dump_cache_tree(the_index.cache_tree, another, "");
|
2022-07-01 10:37:34 +00:00
|
|
|
cache_tree_free(&another);
|
|
|
|
|
|
|
|
return ret;
|
2006-04-24 03:20:25 +00:00
|
|
|
}
|