| 111 | } |
| 112 | |
| 113 | static int do_invalidate_path(struct cache_tree *it, const char *path) |
| 114 | { |
| 115 | /* a/b/c |
| 116 | * ==> invalidate self |
| 117 | * ==> find "a", have it invalidate "b/c" |
| 118 | * a |
| 119 | * ==> invalidate self |
| 120 | * ==> if "a" exists as a subtree, remove it. |
| 121 | */ |
| 122 | const char *slash; |
| 123 | int namelen; |
| 124 | struct cache_tree_sub *down; |
| 125 | |
| 126 | #if DEBUG_CACHE_TREE |
| 127 | fprintf(stderr, "cache-tree invalidate <%s>\n", path); |
| 128 | #endif |
| 129 | |
| 130 | if (!it) |
| 131 | return 0; |
| 132 | slash = strchrnul(path, '/'); |
| 133 | namelen = slash - path; |
| 134 | it->entry_count = -1; |
| 135 | if (!*slash) { |
| 136 | int pos; |
| 137 | pos = cache_tree_subtree_pos(it, path, namelen); |
| 138 | if (0 <= pos) { |
| 139 | cache_tree_free(&it->down[pos]->cache_tree); |
| 140 | free(it->down[pos]); |
| 141 | /* 0 1 2 3 4 5 |
| 142 | * ^ ^subtree_nr = 6 |
| 143 | * pos |
| 144 | * move 4 and 5 up one place (2 entries) |
| 145 | * 2 = 6 - 3 - 1 = subtree_nr - pos - 1 |
| 146 | */ |
| 147 | MOVE_ARRAY(it->down + pos, it->down + pos + 1, |
| 148 | it->subtree_nr - pos - 1); |
| 149 | it->subtree_nr--; |
| 150 | } |
| 151 | return 1; |
| 152 | } |
| 153 | down = find_subtree(it, path, namelen, 0); |
| 154 | if (down) |
| 155 | do_invalidate_path(down->cache_tree, slash + 1); |
| 156 | return 1; |
| 157 | } |
| 158 | |
| 159 | void cache_tree_invalidate_path(struct index_state *istate, const char *path) |
| 160 | { |
no test coverage detected