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

Function reuse_worktree_file

diff.c:4388–4468  ·  view source on GitHub ↗

* Given a name and sha1 pair, if the index tells us the file in * the work tree has that object contents, return true, so that * prepare_temp_file() does not have to inflate and extract. */

Source from the content-addressed store, hash-verified

4386 * prepare_temp_file() does not have to inflate and extract.
4387 */
4388static int reuse_worktree_file(struct index_state *istate,
4389 const char *name,
4390 const struct object_id *oid,
4391 int want_file)
4392{
4393 const struct cache_entry *ce;
4394 struct stat st;
4395 int pos, len;
4396
4397 /*
4398 * We do not read the cache ourselves here, because the
4399 * benchmark with my previous version that always reads cache
4400 * shows that it makes things worse for diff-tree comparing
4401 * two linux-2.6 kernel trees in an already checked out work
4402 * tree. This is because most diff-tree comparisons deal with
4403 * only a small number of files, while reading the cache is
4404 * expensive for a large project, and its cost outweighs the
4405 * savings we get by not inflating the object to a temporary
4406 * file. Practically, this code only helps when we are used
4407 * by diff-cache --cached, which does read the cache before
4408 * calling us.
4409 */
4410 if (!istate->cache)
4411 return 0;
4412
4413 /* We want to avoid the working directory if our caller
4414 * doesn't need the data in a normal file, this system
4415 * is rather slow with its stat/open/mmap/close syscalls,
4416 * and the object is contained in a pack file. The pack
4417 * is probably already open and will be faster to obtain
4418 * the data through than the working directory. Loose
4419 * objects however would tend to be slower as they need
4420 * to be individually opened and inflated.
4421 */
4422 if (!FAST_WORKING_DIRECTORY && !want_file &&
4423 has_object_pack(istate->repo, oid))
4424 return 0;
4425
4426 /*
4427 * Similarly, if we'd have to convert the file contents anyway, that
4428 * makes the optimization not worthwhile.
4429 */
4430 if (!want_file && would_convert_to_git(istate, name))
4431 return 0;
4432
4433 /*
4434 * If this path does not match our sparse-checkout definition,
4435 * then the file will not be in the working directory.
4436 */
4437 if (!path_in_sparse_checkout(name, istate))
4438 return 0;
4439
4440 len = strlen(name);
4441 pos = index_name_pos(istate, name, len);
4442 if (pos < 0)
4443 return 0;
4444 ce = istate->cache[pos];
4445

Callers 2

diff_populate_filespecFunction · 0.85
prepare_temp_fileFunction · 0.85

Calls 6

has_object_packFunction · 0.85
would_convert_to_gitFunction · 0.85
path_in_sparse_checkoutFunction · 0.85
index_name_posFunction · 0.85
oideqFunction · 0.85
ie_match_statFunction · 0.85

Tested by

no test coverage detected