Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/helper/test-dump-cache-tree.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / helper / test-dump-cache-tree.c` 79 lines ยท 1930 bytes Raw Blame History 1 #define USE_THE_REPOSITORY_VARIABLE 2 3 #include "test-tool.h" 4 #include "hash.h" 5 #include "hex.h" 6 #include "tree.h" 7 #include "cache-tree.h" 8 #include "read-cache-ll.h" 9 #include "repository.h" 10 #include "setup.h" 11 12 static void dump_one(struct cache_tree *it, const char *pfx, const char *x) 13 { 14 if (it->entry_count < 0) 15 printf("%-40s %s%s (%d subtrees)\n", 16 "invalid", x, pfx, it->subtree_nr); 17 else 18 printf("%s %s%s (%d entries, %d subtrees)\n", 19 oid_to_hex(&it->oid), x, pfx, 20 it->entry_count, it->subtree_nr); 21 } 22 23 static int dump_cache_tree(struct cache_tree *it, 24 struct cache_tree *ref, 25 const char *pfx) 26 { 27 int i; 28 int errs = 0; 29 30 if (!it || !ref) 31 /* missing in either */ 32 return 0; 33 34 if (it->entry_count < 0) { 35 /* invalid */ 36 dump_one(it, pfx, ""); 37 dump_one(ref, pfx, "#(ref) "); 38 } 39 else { 40 dump_one(it, pfx, ""); 41 if (!oideq(&it->oid, &ref->oid) || 42 ref->entry_count != it->entry_count || 43 ref->subtree_nr != it->subtree_nr) { 44 /* claims to be valid but is lying */ 45 dump_one(ref, pfx, "#(ref) "); 46 errs = 1; 47 } 48 } 49 50 for (i = 0; i < it->subtree_nr; i++) { 51 char path[PATH_MAX]; 52 struct cache_tree_sub *down = it->down[i]; 53 struct cache_tree_sub *rdwn; 54 55 rdwn = cache_tree_sub(ref, down->name); 56 xsnprintf(path, sizeof(path), "%s%.*s/", pfx, down->namelen, down->name); 57 if (dump_cache_tree(down->cache_tree, rdwn->cache_tree, path)) 58 errs = 1; 59 } 60 return errs; 61 } 62 63 int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED) 64 { 65 struct index_state istate; 66 struct cache_tree *another = cache_tree(); 67 int ret; 68 69 setup_git_directory(the_repository); 70 if (repo_read_index(the_repository) < 0) 71 die("unable to read index file"); 72 istate = *the_repository->index; 73 istate.cache_tree = another; 74 cache_tree_update(&istate, WRITE_TREE_DRY_RUN); 75 ret = dump_cache_tree(the_repository->index->cache_tree, another, ""); 76 cache_tree_free(&another); 77 78 return ret; 79 }