| 936 | } |
| 937 | |
| 938 | static 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 | |
| 983 | static int run_help(struct add_i_state *s, const struct pathspec *ps UNUSED, |
| 984 | struct prefix_item_list *files UNUSED, |
nothing calls this directly
no test coverage detected