Skip to content

Commit 118eafc

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 e213dbc + a261323 commit 118eafc

File tree

6 files changed

+1395
-16
lines changed

6 files changed

+1395
-16
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ LIB_H := $(sort $(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null
827827

828828
LIB_OBJS += abspath.o
829829
LIB_OBJS += add-interactive.o
830+
LIB_OBJS += add-patch.o
830831
LIB_OBJS += advice.o
831832
LIB_OBJS += alias.o
832833
LIB_OBJS += alloc.o

add-interactive.c

Lines changed: 15 additions & 14 deletions
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
/*
@@ -911,15 +909,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
911909
count = list_and_choose(s, files, opts);
912910
if (count >= 0) {
913911
struct argv_array args = ARGV_ARRAY_INIT;
912+
struct pathspec ps_selected = { 0 };
914913

915-
argv_array_pushl(&args, "git", "add--interactive", "--patch",
916-
"--", NULL);
917914
for (i = 0; i < files->items.nr; i++)
918915
if (files->selected[i])
919916
argv_array_push(&args,
920917
files->items.items[i].string);
921-
res = run_command_v_opt(args.argv, 0);
918+
parse_pathspec(&ps_selected,
919+
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
920+
PATHSPEC_LITERAL_PATH, "", args.argv);
921+
res = run_add_p(s->r, &ps_selected);
922922
argv_array_clear(&args);
923+
clear_pathspec(&ps_selected);
923924
}
924925

925926
return res;

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+
void init_add_i_state(struct add_i_state *s, struct repository *r);
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)