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

Function run_diff

add-interactive.c:938–981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

936}
937
938static int run_diff(struct add_i_state *s, const struct pathspec *ps,
939 struct prefix_item_list *files,
940 struct list_and_choose_options *opts)
941{
942 int res = 0;
943 ssize_t count, i;
944
945 struct object_id oid;
946 int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(s->r),
947 "HEAD", RESOLVE_REF_READING,
948 &oid,
949 NULL);
950 if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0)
951 return -1;
952
953 if (!files->items.nr) {
954 putchar('\n');
955 return 0;
956 }
957
958 opts->prompt = N_("Review diff");
959 opts->flags = IMMEDIATE;
960 count = list_and_choose(s, files, opts);
961 opts->flags = 0;
962 if (count > 0) {
963 struct child_process cmd = CHILD_PROCESS_INIT;
964
965 strvec_pushl(&cmd.args, "git", "diff", "-p", "--cached", NULL);
966 if (s->cfg.context != -1)
967 strvec_pushf(&cmd.args, "--unified=%i", s->cfg.context);
968 if (s->cfg.interhunkcontext != -1)
969 strvec_pushf(&cmd.args, "--inter-hunk-context=%i", s->cfg.interhunkcontext);
970 strvec_pushl(&cmd.args, oid_to_hex(!is_initial ? &oid :
971 s->r->hash_algo->empty_tree), "--", NULL);
972 for (i = 0; i < files->items.nr; i++)
973 if (files->selected[i])
974 strvec_push(&cmd.args,
975 files->items.items[i].string);
976 res = run_command(&cmd);
977 }
978
979 putchar('\n');
980 return res;
981}
982
983static int run_help(struct add_i_state *s, const struct pathspec *ps UNUSED,
984 struct prefix_item_list *files UNUSED,

Callers

nothing calls this directly

Calls 9

refs_resolve_ref_unsafeFunction · 0.85
get_main_ref_storeFunction · 0.85
get_modified_filesFunction · 0.85
strvec_pushlFunction · 0.85
strvec_pushfFunction · 0.85
oid_to_hexFunction · 0.85
strvec_pushFunction · 0.85
run_commandFunction · 0.85
list_and_chooseFunction · 0.70

Tested by

no test coverage detected