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

Function reset_tree

builtin/stash.c:334–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334static int reset_tree(struct object_id *i_tree, int update, int reset)
335{
336 int nr_trees = 1;
337 struct unpack_trees_options opts;
338 struct tree_desc t[MAX_UNPACK_TREES];
339 struct tree *tree;
340 struct lock_file lock_file = LOCK_INIT;
341
342 repo_read_index_preload(the_repository, NULL, 0);
343 if (refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL))
344 return -1;
345
346 repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR);
347
348 memset(&opts, 0, sizeof(opts));
349
350 tree = repo_parse_tree_indirect(the_repository, i_tree);
351 if (repo_parse_tree(the_repository, tree))
352 return -1;
353
354 init_tree_desc(t, &tree->object.oid, tree->buffer, tree->size);
355
356 opts.head_idx = 1;
357 opts.src_index = the_repository->index;
358 opts.dst_index = the_repository->index;
359 opts.merge = 1;
360 opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
361 opts.update = update;
362 if (update)
363 opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
364 opts.fn = oneway_merge;
365
366 if (unpack_trees(nr_trees, t, &opts))
367 return -1;
368
369 if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
370 return error(_("unable to write new index file"));
371
372 return 0;
373}
374
375static int create_index_from_tree(const struct object_id *tree_id,
376 const char *index_path)

Callers 2

do_apply_stashFunction · 0.70
stash_working_treeFunction · 0.70

Calls 9

repo_read_index_preloadFunction · 0.85
refresh_indexFunction · 0.85
repo_hold_locked_indexFunction · 0.85
repo_parse_tree_indirectFunction · 0.85
repo_parse_treeFunction · 0.85
init_tree_descFunction · 0.85
unpack_treesFunction · 0.85
write_locked_indexFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected