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

Function run_patch

add-interactive.c:872–936  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

870}
871
872static int run_patch(struct add_i_state *s, const struct pathspec *ps,
873 struct prefix_item_list *files,
874 struct list_and_choose_options *opts)
875{
876 int res = 0;
877 ssize_t count, i, j;
878 size_t unmerged_count = 0, binary_count = 0;
879
880 if (get_modified_files(s->r, WORKTREE_ONLY, files, ps,
881 &unmerged_count, &binary_count) < 0)
882 return -1;
883
884 if (unmerged_count || binary_count) {
885 for (i = j = 0; i < files->items.nr; i++) {
886 struct file_item *item = files->items.items[i].util;
887
888 if (item->index.binary || item->worktree.binary) {
889 free(item);
890 free(files->items.items[i].string);
891 } else if (item->index.unmerged ||
892 item->worktree.unmerged) {
893 color_fprintf_ln(stderr, s->cfg.error_color,
894 _("ignoring unmerged: %s"),
895 files->items.items[i].string);
896 free(item);
897 free(files->items.items[i].string);
898 } else
899 files->items.items[j++] = files->items.items[i];
900 }
901 files->items.nr = j;
902 }
903
904 if (!files->items.nr) {
905 if (binary_count)
906 fprintf(stderr, _("Only binary files changed.\n"));
907 else
908 fprintf(stderr, _("No changes.\n"));
909 return 0;
910 }
911
912 opts->prompt = N_("Patch update");
913 count = list_and_choose(s, files, opts);
914 if (count > 0) {
915 struct interactive_options opts = {
916 .context = s->cfg.context,
917 .interhunkcontext = s->cfg.interhunkcontext,
918 .auto_advance = s->cfg.auto_advance,
919 };
920 struct strvec args = STRVEC_INIT;
921 struct pathspec ps_selected = { 0 };
922
923 for (i = 0; i < files->items.nr; i++)
924 if (files->selected[i])
925 strvec_push(&args,
926 files->items.items[i].string);
927 parse_pathspec(&ps_selected,
928 PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
929 PATHSPEC_LITERAL_PATH, "", args.v);

Callers

nothing calls this directly

Calls 8

get_modified_filesFunction · 0.85
color_fprintf_lnFunction · 0.85
strvec_pushFunction · 0.85
parse_pathspecFunction · 0.85
run_add_pFunction · 0.85
strvec_clearFunction · 0.85
clear_pathspecFunction · 0.85
list_and_chooseFunction · 0.70

Tested by

no test coverage detected