Skip to content

Implement the git add --patch backend in C #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
63b571f
built-in add -i: start implementing the `patch` functionality in C
dscho Mar 11, 2019
03feb2f
built-in add -i: wire up the new C code for the `patch` command
dscho Mar 12, 2019
438e651
built-in add -p: show colored hunks by default
dscho Mar 12, 2019
ab94f43
built-in add -p: adjust hunk headers as needed
dscho Mar 21, 2019
7d3a59d
built-in add -p: color the prompt and the help text
dscho Mar 12, 2019
9ef0db2
built-in add -p: offer a helpful error message when hunk navigation f…
dscho Mar 17, 2019
0cd1522
built-in add -p: support multi-file diffs
dscho Mar 15, 2019
5566043
built-in add -p: handle deleted empty files
dscho Mar 15, 2019
a3624d7
built-in app -p: allow selecting a mode change as a "hunk"
dscho Mar 15, 2019
8d58889
built-in add -p: show different prompts for mode changes and deletions
dscho Mar 23, 2019
2cd9855
built-in add -p: implement the hunk splitting feature
dscho Mar 17, 2019
da950fd
built-in add -p: coalesce hunks after splitting them
dscho Mar 19, 2019
18c008f
strbuf: add a helper function to call the editor "on an strbuf"
dscho Aug 26, 2019
1e23fcd
built-in add -p: implement hunk editing
dscho Mar 19, 2019
9a2cf7e
built-in add -p: implement the 'g' ("goto") command
dscho Mar 21, 2019
e7d2187
built-in add -p: implement the '/' ("search regex") command
dscho Mar 21, 2019
6c33fbb
built-in add -p: implement the 'q' ("quit") command
dscho Mar 22, 2019
0c95067
built-in add -p: only show the applicable parts of the help text
dscho Mar 24, 2019
a5bbd28
built-in add -p: show helpful hint when nothing can be staged
dscho Mar 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@ LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentat

LIB_OBJS += abspath.o
LIB_OBJS += add-interactive.o
LIB_OBJS += add-patch.o
LIB_OBJS += advice.o
LIB_OBJS += alias.o
LIB_OBJS += alloc.o
Expand Down
29 changes: 15 additions & 14 deletions add-interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@
#include "dir.h"
#include "run-command.h"

struct add_i_state {
struct repository *r;
int use_color;
char header_color[COLOR_MAXLEN];
char help_color[COLOR_MAXLEN];
char prompt_color[COLOR_MAXLEN];
char error_color[COLOR_MAXLEN];
char reset_color[COLOR_MAXLEN];
};

static void init_color(struct repository *r, struct add_i_state *s,
const char *slot_name, char *dst,
const char *default_color)
Expand All @@ -36,7 +26,7 @@ static void init_color(struct repository *r, struct add_i_state *s,
free(key);
}

static void init_add_i_state(struct add_i_state *s, struct repository *r)
void init_add_i_state(struct add_i_state *s, struct repository *r)
{
const char *value;

Expand All @@ -54,6 +44,14 @@ static void init_add_i_state(struct add_i_state *s, struct repository *r)
init_color(r, s, "prompt", s->prompt_color, GIT_COLOR_BOLD_BLUE);
init_color(r, s, "error", s->error_color, GIT_COLOR_BOLD_RED);
init_color(r, s, "reset", s->reset_color, GIT_COLOR_RESET);
init_color(r, s, "fraginfo", s->fraginfo_color,
diff_get_color(s->use_color, DIFF_FRAGINFO));
init_color(r, s, "context", s->context_color,
diff_get_color(s->use_color, DIFF_CONTEXT));
init_color(r, s, "old", s->file_old_color,
diff_get_color(s->use_color, DIFF_FILE_OLD));
init_color(r, s, "new", s->file_new_color,
diff_get_color(s->use_color, DIFF_FILE_NEW));
}

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

argv_array_pushl(&args, "git", "add--interactive", "--patch",
"--", NULL);
for (i = 0; i < files->items.nr; i++)
if (files->selected[i])
argv_array_push(&args,
files->items.items[i].string);
res = run_command_v_opt(args.argv, 0);
parse_pathspec(&ps_selected,
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_LITERAL_PATH, "", args.argv);
res = run_add_p(s->r, &ps_selected);
argv_array_clear(&args);
clear_pathspec(&ps_selected);
}

return res;
Expand Down
19 changes: 19 additions & 0 deletions add-interactive.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
#ifndef ADD_INTERACTIVE_H
#define ADD_INTERACTIVE_H

#include "color.h"

struct add_i_state {
struct repository *r;
int use_color;
char header_color[COLOR_MAXLEN];
char help_color[COLOR_MAXLEN];
char prompt_color[COLOR_MAXLEN];
char error_color[COLOR_MAXLEN];
char reset_color[COLOR_MAXLEN];
char fraginfo_color[COLOR_MAXLEN];
char context_color[COLOR_MAXLEN];
char file_old_color[COLOR_MAXLEN];
char file_new_color[COLOR_MAXLEN];
};

void init_add_i_state(struct add_i_state *s, struct repository *r);

struct repository;
struct pathspec;
int run_add_i(struct repository *r, const struct pathspec *ps);
int run_add_p(struct repository *r, const struct pathspec *ps);

#endif
Loading