MCPcopy Index your code
hub / github.com/git/git / verify_cache

Function verify_cache

cache-tree.c:165–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static int verify_cache(struct index_state *istate, int flags)
166{
167 unsigned i, funny;
168 int silent = flags & WRITE_TREE_SILENT;
169
170 /* Verify that the tree is merged */
171 funny = 0;
172 for (i = 0; i < istate->cache_nr; i++) {
173 const struct cache_entry *ce = istate->cache[i];
174 if (ce_stage(ce)) {
175 if (silent)
176 return -1;
177 if (10 < ++funny) {
178 fprintf(stderr, "...\n");
179 break;
180 }
181 fprintf(stderr, "%s: unmerged (%s)\n",
182 ce->name, oid_to_hex(&ce->oid));
183 }
184 }
185 if (funny)
186 return -1;
187
188 /* Also verify that the cache does not have path and path/file
189 * at the same time. At this point we know the cache has only
190 * stage 0 entries.
191 */
192 funny = 0;
193 for (i = 0; i + 1 < istate->cache_nr; i++) {
194 /* path/file always comes after path because of the way
195 * the cache is sorted. Also path can appear only once,
196 * which means conflicting one would immediately follow.
197 */
198 const struct cache_entry *this_ce = istate->cache[i];
199 const struct cache_entry *next_ce = istate->cache[i + 1];
200 const char *this_name = this_ce->name;
201 const char *next_name = next_ce->name;
202 int this_len = ce_namelen(this_ce);
203 if (this_len < ce_namelen(next_ce) &&
204 next_name[this_len] == '/' &&
205 strncmp(this_name, next_name, this_len) == 0) {
206 if (10 < ++funny) {
207 fprintf(stderr, "...\n");
208 break;
209 }
210 fprintf(stderr, "You have both %s and %s\n",
211 this_name, next_name);
212 }
213 }
214 if (funny)
215 return -1;
216 return 0;
217}
218
219static void discard_unused_subtrees(struct cache_tree *it)
220{

Callers 1

cache_tree_updateFunction · 0.85

Calls 1

oid_to_hexFunction · 0.85

Tested by

no test coverage detected