Skip to content

Commit ddc8a97

Browse files
committed
Merge branch 'add-p-in-c'
Out of all the patch series on the journey to provide `git add --interactive` and `git add --patch` in a built-in versions, this is the big one, as can be expected from the fact that the `git add --patch` functionality makes up over half of the 1,800+ lines of `git-add--interactive.perl`. The two patches that stick out are of course the ones to implement hunk splitting and hunk editing: these operations are fundamentally more complicated, and less obvious, than the rest of the operations. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 15f3dba + e6b1b18 commit ddc8a97

File tree

6 files changed

+1361
-16
lines changed

6 files changed

+1361
-16
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ LIB_H = $(shell $(FIND) . \
850850

851851
LIB_OBJS += abspath.o
852852
LIB_OBJS += add-interactive.o
853+
LIB_OBJS += add-patch.o
853854
LIB_OBJS += advice.o
854855
LIB_OBJS += alias.o
855856
LIB_OBJS += alloc.o

add-interactive.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
#include "argv-array.h"
1313
#include "run-command.h"
1414

15-
struct add_i_state {
16-
struct repository *r;
17-
int use_color;
18-
char header_color[COLOR_MAXLEN];
19-
char help_color[COLOR_MAXLEN];
20-
char prompt_color[COLOR_MAXLEN];
21-
char error_color[COLOR_MAXLEN];
22-
char reset_color[COLOR_MAXLEN];
23-
};
24-
2515
static void init_color(struct repository *r, struct add_i_state *s,
2616
const char *slot_name, char *dst,
2717
const char *default_color)
@@ -38,7 +28,7 @@ static void init_color(struct repository *r, struct add_i_state *s,
3828
free(key);
3929
}
4030

41-
static int init_add_i_state(struct repository *r, struct add_i_state *s)
31+
int init_add_i_state(struct repository *r, struct add_i_state *s)
4232
{
4333
const char *value;
4434

@@ -57,6 +47,16 @@ static int init_add_i_state(struct repository *r, struct add_i_state *s)
5747
init_color(r, s, "error", s->error_color, GIT_COLOR_BOLD_RED);
5848
init_color(r, s, "reset", s->reset_color, GIT_COLOR_RESET);
5949

50+
strlcpy(s->fraginfo_color,
51+
diff_get_color(s->use_color, DIFF_FRAGINFO), COLOR_MAXLEN);
52+
strlcpy(s->context_color,
53+
diff_get_color(s->use_color, DIFF_CONTEXT), COLOR_MAXLEN);
54+
strlcpy(s->file_old_color,
55+
diff_get_color(s->use_color, DIFF_FILE_OLD), COLOR_MAXLEN);
56+
strlcpy(s->file_new_color,
57+
diff_get_color(s->use_color, DIFF_FILE_NEW), COLOR_MAXLEN);
58+
59+
6060
return 0;
6161
}
6262

@@ -831,14 +831,17 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
831831
count = list_and_choose(items, selected, files->nr, s, opts);
832832
if (count >= 0) {
833833
struct argv_array args = ARGV_ARRAY_INIT;
834+
struct pathspec ps_selected = { 0 };
834835

835-
argv_array_pushl(&args, "git", "add--interactive", "--patch",
836-
"--", NULL);
837836
for (i = 0; i < files->nr; i++)
838837
if (selected[i])
839838
argv_array_push(&args, items[i]->name);
840-
res = run_command_v_opt(args.argv, 0);
839+
parse_pathspec(&ps_selected,
840+
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
841+
PATHSPEC_LITERAL_PATH, "", args.argv);
842+
res = run_add_p(s->r, &ps_selected);
841843
argv_array_clear(&args);
844+
clear_pathspec(&ps_selected);
842845
}
843846

844847
free(selected);

add-interactive.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
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+
int init_add_i_state(struct repository *r, struct add_i_state *s);
21+
22+
enum color_add_i {
23+
COLOR_HEADER = 0,
24+
COLOR_HELP,
25+
COLOR_PROMPT,
26+
COLOR_ERROR,
27+
COLOR_RESET,
28+
};
29+
const char *get_add_i_color(enum color_add_i ix);
30+
431
struct repository;
532
struct pathspec;
633
int run_add_i(struct repository *r, const struct pathspec *ps);
34+
int run_add_p(struct repository *r, const struct pathspec *ps);
735

836
#endif

0 commit comments

Comments
 (0)