MCPcopy Create free account
hub / github.com/git/git / try_update_sparse_directory

Function try_update_sparse_directory

builtin/checkout.c:149–191  ·  view source on GitHub ↗

* Handle a tree object and determine if we need to recurse into the * tree (READ_TREE_RECURSIVE) or skip it (0). */

Source from the content-addressed store, hash-verified

147 * tree (READ_TREE_RECURSIVE) or skip it (0).
148 */
149static int try_update_sparse_directory(const struct object_id *oid,
150 struct strbuf *base,
151 const char *pathname,
152 int overlay_mode)
153{
154 struct strbuf dirpath = STRBUF_INIT;
155 struct cache_entry *old;
156 int pos, result = READ_TREE_RECURSIVE;
157
158 if (!the_repository->index->sparse_index)
159 return result;
160
161 strbuf_addbuf(&dirpath, base);
162 strbuf_addstr(&dirpath, pathname);
163 strbuf_addch(&dirpath, '/');
164
165 pos = index_name_pos_sparse(the_repository->index,
166 dirpath.buf, dirpath.len);
167 if (pos < 0)
168 goto cleanup;
169
170 old = the_repository->index->cache[pos];
171 if (!S_ISSPARSEDIR(old->ce_mode))
172 goto cleanup;
173
174 if (oideq(oid, &old->oid)) {
175 /* Tree content already matches; no need to descend. */
176 result = 0;
177 } else if (!overlay_mode) {
178 /*
179 * In non-overlay mode (e.g., restore --staged), replace the
180 * sparse directory OID directly since files not present in
181 * the source tree should be removed anyway.
182 */
183 oidcpy(&old->oid, oid);
184 old->ce_flags |= CE_UPDATE;
185 result = 0;
186 }
187
188cleanup:
189 strbuf_release(&dirpath);
190 return result;
191}
192
193static int update_some(const struct object_id *oid, struct strbuf *base,
194 const char *pathname, unsigned mode, void *context)

Callers 1

update_someFunction · 0.85

Calls 7

strbuf_addbufFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addchFunction · 0.85
index_name_pos_sparseFunction · 0.85
oideqFunction · 0.85
oidcpyFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected