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

Function run_revert

add-interactive.c:702–787  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

700}
701
702static int run_revert(struct add_i_state *s, const struct pathspec *ps,
703 struct prefix_item_list *files,
704 struct list_and_choose_options *opts)
705{
706 int res = 0, fd;
707 size_t count, i, j;
708
709 struct object_id oid;
710 int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(s->r),
711 "HEAD", RESOLVE_REF_READING,
712 &oid,
713 NULL);
714 struct lock_file index_lock;
715 const char **paths;
716 struct tree *tree;
717 struct diff_options diffopt = { NULL };
718
719 if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0)
720 return -1;
721
722 if (!files->items.nr) {
723 putchar('\n');
724 return 0;
725 }
726
727 opts->prompt = N_("Revert");
728 count = list_and_choose(s, files, opts);
729 if (count <= 0)
730 goto finish_revert;
731
732 fd = repo_hold_locked_index(s->r, &index_lock, LOCK_REPORT_ON_ERROR);
733 if (fd < 0) {
734 res = -1;
735 goto finish_revert;
736 }
737
738 if (is_initial)
739 oidcpy(&oid, s->r->hash_algo->empty_tree);
740 else {
741 tree = repo_parse_tree_indirect(s->r, &oid);
742 if (!tree) {
743 res = error(_("Could not parse HEAD^{tree}"));
744 goto finish_revert;
745 }
746 oidcpy(&oid, &tree->object.oid);
747 }
748
749 ALLOC_ARRAY(paths, count + 1);
750 for (i = j = 0; i < files->items.nr; i++)
751 if (files->selected[i])
752 paths[j++] = files->items.items[i].string;
753 paths[j] = NULL;
754
755 parse_pathspec(&diffopt.pathspec, 0,
756 PATHSPEC_PREFER_FULL | PATHSPEC_LITERAL_PATH,
757 NULL, paths);
758
759 diffopt.output_format = DIFF_FORMAT_CALLBACK;

Callers

nothing calls this directly

Calls 15

refs_resolve_ref_unsafeFunction · 0.85
get_main_ref_storeFunction · 0.85
get_modified_filesFunction · 0.85
repo_hold_locked_indexFunction · 0.85
oidcpyFunction · 0.85
repo_parse_tree_indirectFunction · 0.85
errorFunction · 0.85
parse_pathspecFunction · 0.85
do_diff_cacheFunction · 0.85
diff_freeFunction · 0.85
diffcore_stdFunction · 0.85
diff_flushFunction · 0.85

Tested by

no test coverage detected