Skip to content

Commit c66c859

Browse files
committed
Merge branch 'js/add-p-in-c' into pu
* js/add-p-in-c: built-in add -p: show helpful hint when nothing can be staged built-in add -p: only show the applicable parts of the help text built-in add -p: implement the 'q' ("quit") command built-in add -p: implement the '/' ("search regex") command built-in add -p: implement the 'g' ("goto") command built-in add -p: implement hunk editing strbuf: add a helper function to call the editor "on an strbuf" built-in add -p: coalesce hunks after splitting them built-in add -p: implement the hunk splitting feature built-in add -p: show different prompts for mode changes and deletions built-in app -p: allow selecting a mode change as a "hunk" built-in add -p: handle deleted empty files built-in add -p: support multi-file diffs built-in add -p: offer a helpful error message when hunk navigation failed built-in add -p: color the prompt and the help text built-in add -p: adjust hunk headers as needed built-in add -p: show colored hunks by default built-in add -i: wire up the new C code for the `patch` command built-in add -i: start implementing the `patch` functionality in C
2 parents dc02b1e + 2e40831 commit c66c859

File tree

8 files changed

+1464
-19
lines changed

8 files changed

+1464
-19
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentat
825825

826826
LIB_OBJS += abspath.o
827827
LIB_OBJS += add-interactive.o
828+
LIB_OBJS += add-patch.o
828829
LIB_OBJS += advice.o
829830
LIB_OBJS += alias.o
830831
LIB_OBJS += alloc.o

add-interactive.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
#include "dir.h"
1111
#include "run-command.h"
1212

13-
struct add_i_state {
14-
struct repository *r;
15-
int use_color;
16-
char header_color[COLOR_MAXLEN];
17-
char help_color[COLOR_MAXLEN];
18-
char prompt_color[COLOR_MAXLEN];
19-
char error_color[COLOR_MAXLEN];
20-
char reset_color[COLOR_MAXLEN];
21-
};
22-
2313
static void init_color(struct repository *r, struct add_i_state *s,
2414
const char *slot_name, char *dst,
2515
const char *default_color)
@@ -36,7 +26,7 @@ static void init_color(struct repository *r, struct add_i_state *s,
3626
free(key);
3727
}
3828

39-
static void init_add_i_state(struct add_i_state *s, struct repository *r)
29+
void init_add_i_state(struct add_i_state *s, struct repository *r)
4030
{
4131
const char *value;
4232

@@ -54,6 +44,14 @@ static void init_add_i_state(struct add_i_state *s, struct repository *r)
5444
init_color(r, s, "prompt", s->prompt_color, GIT_COLOR_BOLD_BLUE);
5545
init_color(r, s, "error", s->error_color, GIT_COLOR_BOLD_RED);
5646
init_color(r, s, "reset", s->reset_color, GIT_COLOR_RESET);
47+
init_color(r, s, "fraginfo", s->fraginfo_color,
48+
diff_get_color(s->use_color, DIFF_FRAGINFO));
49+
init_color(r, s, "context", s->context_color,
50+
diff_get_color(s->use_color, DIFF_CONTEXT));
51+
init_color(r, s, "old", s->file_old_color,
52+
diff_get_color(s->use_color, DIFF_FILE_OLD));
53+
init_color(r, s, "new", s->file_new_color,
54+
diff_get_color(s->use_color, DIFF_FILE_NEW));
5755
}
5856

5957
/*
@@ -917,15 +915,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
917915
count = list_and_choose(s, files, opts);
918916
if (count >= 0) {
919917
struct argv_array args = ARGV_ARRAY_INIT;
918+
struct pathspec ps_selected = { 0 };
920919

921-
argv_array_pushl(&args, "git", "add--interactive", "--patch",
922-
"--", NULL);
923920
for (i = 0; i < files->items.nr; i++)
924921
if (files->selected[i])
925922
argv_array_push(&args,
926923
files->items.items[i].string);
927-
res = run_command_v_opt(args.argv, 0);
924+
parse_pathspec(&ps_selected,
925+
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
926+
PATHSPEC_LITERAL_PATH, "", args.argv);
927+
res = run_add_p(s->r, &ps_selected);
928928
argv_array_clear(&args);
929+
clear_pathspec(&ps_selected);
929930
}
930931

931932
return res;

add-interactive.h

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
#ifndef ADD_INTERACTIVE_H
22
#define ADD_INTERACTIVE_H
33

4+
#include "color.h"
5+
6+
struct add_i_state {
7+
struct repository *r;
8+
int use_color;
9+
char header_color[COLOR_MAXLEN];
10+
char help_color[COLOR_MAXLEN];
11+
char prompt_color[COLOR_MAXLEN];
12+
char error_color[COLOR_MAXLEN];
13+
char reset_color[COLOR_MAXLEN];
14+
char fraginfo_color[COLOR_MAXLEN];
15+
char context_color[COLOR_MAXLEN];
16+
char file_old_color[COLOR_MAXLEN];
17+
char file_new_color[COLOR_MAXLEN];
18+
};
19+
20+
void init_add_i_state(struct add_i_state *s, struct repository *r);
21+
422
struct repository;
523
struct pathspec;
624
int run_add_i(struct repository *r, const struct pathspec *ps);
25+
int run_add_p(struct repository *r, const struct pathspec *ps);
726

827
#endif

0 commit comments

Comments
 (0)