git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jeff Hostetler <git@jeffhostetler.com>, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 00/11] git add -i: add a rudimentary version in C (supporting only status and help  so far)
Date: Mon, 13 May 2019 10:27:52 -0700 (PDT)	[thread overview]
Message-ID: <pull.170.v2.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.170.git.gitgitgadget@gmail.com>

This is the first leg on the long journey to a fully built-in git add -i 
(next up: parts 2 [https://github.com/gitgitgadget/git/pull/171], 3
[https://github.com/gitgitgadget/git/pull/172], 4
[https://github.com/gitgitgadget/git/pull/173], 5
[https://github.com/gitgitgadget/git/pull/174], and 6
[https://github.com/gitgitgadget/git/pull/175]). Note: the latter PRs are
not necessarily up to date, and will be re-targeted to the appropriate
branches in https://github.com/gitster/git as soon as Junio picks them up.

This here patch series reflects the part that was submitted a couple of
times (see https://github.com/gitgitgadget/git/pull/103) during the
Outreachy project by Slavica Ðukic that continued the journey based on an
initial patch series by Daniel Ferreira.

It only implements the status and the help part, in the interest of making
the review remotely more reviewable.

As I am a heavy user of git add -p myself and use a patched version for
weeks already (it is so nice to not suffer over one second startup until the
MSYS2 Perl finally shows me anything, instead it feels instantaneous), I
integrated these patch series into Git for Windows' master already, as an
opt-in feature guarded by the config variable add.interactive.useBuiltin 
(and Git for Windows' installer is prepared to detect this version and offer
the option in the graphical user interface).

I had planned on submitting this before v2.22.0-rc0, but there was such a
backlog of builds from a big pushout that I had to wait ;-)

Changes since v1:

 * The config machinery was reworked completely, to not use a callback to 
   git_config(), but instead to query the config via the repo_config_get_*() 
   functions. This also prevents a future "Huh???" moment: the internal add
   --interactive API accepts a parameter of type struct repository *r, but
   the previous configuration did not use that to query the config (and
   could in the future be a repository other than the_repository).
   
   
 * As a consequence, the color sequences are no longer stored in file-local
   variables, but passed around via a struct.
   
   
 * Instead of using the magical constant -2 to quit the main loop, it is now
   defined as LIST_AND_CHOOSE_QUIT (and likewise, LIST_AND_CHOOSE_ERROR is
   defined as -1 and used where appropriate).
   
   
 * Improved the add_prefix_item() function by avoiding buffer overruns, not
   reusing the struct that is used for lookup also for adding the new item,
   and by strengthening the bug check.

Daniel Ferreira (2):
  diff: export diffstat interface
  built-in add -i: implement the `status` command

Johannes Schindelin (6):
  Start to implement a built-in version of `git add --interactive`
  built-in add -i: refresh the index before running `status`
  built-in add -i: color the header in the `status` command
  built-in add -i: implement the main loop
  built-in add -i: support `?` (prompt help)
  built-in add -i: implement the `help` command

Slavica Djukic (3):
  Add a function to determine unique prefixes for a list of strings
  built-in add -i: show unique prefixes of the commands
  built-in add -i: use color in the main loop

 Documentation/config/add.txt |   5 +
 Makefile                     |   3 +
 add-interactive.c            | 558 +++++++++++++++++++++++++++++++++++
 add-interactive.h            |   8 +
 builtin/add.c                |  10 +
 diff.c                       |  37 +--
 diff.h                       |  19 ++
 prefix-map.c                 | 109 +++++++
 prefix-map.h                 |  40 +++
 repository.c                 |  19 ++
 repository.h                 |   7 +
 t/README                     |   4 +
 t/helper/test-prefix-map.c   |  58 ++++
 t/helper/test-tool.c         |   1 +
 t/helper/test-tool.h         |   1 +
 t/t0016-prefix-map.sh        |  10 +
 t/t3701-add-interactive.sh   |  24 ++
 17 files changed, 891 insertions(+), 22 deletions(-)
 create mode 100644 add-interactive.c
 create mode 100644 add-interactive.h
 create mode 100644 prefix-map.c
 create mode 100644 prefix-map.h
 create mode 100644 t/helper/test-prefix-map.c
 create mode 100755 t/t0016-prefix-map.sh


base-commit: 8104ec994ea3849a968b4667d072fedd1e688642
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-170%2Fdscho%2Fadd-i-in-c-status-and-help-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-170/dscho/add-i-in-c-status-and-help-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/170

Range-diff vs v1:

  1:  12978dc248 !  1:  ed53346b92 Start to implement a built-in version of `git add --interactive`
     @@ -62,12 +62,6 @@
      @@
      +#include "cache.h"
      +#include "add-interactive.h"
     -+#include "config.h"
     -+
     -+int add_i_config(const char *var, const char *value, void *cb)
     -+{
     -+	return git_default_config(var, value, cb);
     -+}
      +
      +int run_add_i(struct repository *r, const struct pathspec *ps)
      +{
     @@ -82,8 +76,6 @@
      +#ifndef ADD_INTERACTIVE_H
      +#define ADD_INTERACTIVE_H
      +
     -+int add_i_config(const char *var, const char *value, void *cb);
     -+
      +struct repository;
      +struct pathspec;
      +int run_add_i(struct repository *r, const struct pathspec *ps);
     @@ -102,50 +94,28 @@
       static const char * const builtin_add_usage[] = {
       	N_("git add [<options>] [--] <pathspec>..."),
      @@
     - static int patch_interactive, add_interactive, edit_interactive;
     - static int take_worktree_changes;
     - static int add_renormalize;
     -+static int use_builtin_add_i;
     - 
     - struct update_callback_data {
     - 	int flags;
     -@@
     + {
       	int status, i;
       	struct argv_array argv = ARGV_ARRAY_INIT;
     - 
     -+	if (use_builtin_add_i && !patch_mode)
     -+		return !!run_add_i(the_repository, pathspec);
     ++	int use_builtin_add_i =
     ++		git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
     ++	if (use_builtin_add_i < 0)
     ++		git_config_get_bool("add.interactive.usebuiltin",
     ++				    &use_builtin_add_i);
      +
     ++	if (use_builtin_add_i == 1 && !patch_mode)
     ++		return !!run_add_i(the_repository, pathspec);
     + 
       	argv_array_push(&argv, "add--interactive");
       	if (patch_mode)
     - 		argv_array_push(&argv, patch_mode);
      @@
       		ignore_add_errors = git_config_bool(var, value);
       		return 0;
       	}
     --	return git_default_config(var, value, cb);
     -+	if (!strcmp(var, "add.interactive.usebuiltin")) {
     -+		use_builtin_add_i = git_config_bool(var, value);
     -+		return 0;
     -+	}
      +
     -+	return add_i_config(var, value, cb);
     + 	return git_default_config(var, value, cb);
       }
       
     - static const char embedded_advice[] = N_(
     -@@
     - 	int require_pathspec;
     - 	char *seen = NULL;
     - 	struct lock_file lock_file = LOCK_INIT;
     -+	int use_builtin_add_i_env =
     -+		git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1);
     - 
     - 	git_config(add_config, NULL);
     -+	if (use_builtin_add_i_env >= 0)
     -+		use_builtin_add_i = use_builtin_add_i_env;
     - 
     - 	argc = parse_options(argc, argv, prefix, builtin_add_options,
     - 			  builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
      
       diff --git a/t/README b/t/README
       --- a/t/README
  2:  06ba1ae344 =  2:  bc99009fbf diff: export diffstat interface
  3:  be9ab904d1 !  3:  5e23c0756b built-in add -i: implement the `status` command
     @@ -30,16 +30,10 @@
      @@
       #include "cache.h"
       #include "add-interactive.h"
     - #include "config.h"
      +#include "diffcore.h"
      +#include "revision.h"
      +#include "refs.h"
     - 
     - int add_i_config(const char *var, const char *value, void *cb)
     - {
     - 	return git_default_config(var, value, cb);
     - }
     - 
     ++
      +struct item {
      +	const char *name;
      +};
     @@ -276,7 +270,7 @@
      +
      +	return 0;
      +}
     -+
     + 
       int run_add_i(struct repository *r, const struct pathspec *ps)
       {
      -	die(_("No commands are available in the built-in `git add -i` yet!"));
  4:  a512e14609 =  4:  8cafc6ae8d built-in add -i: refresh the index before running `status`
  5:  f7c8df058c <  -:  ---------- built-in add -i: color the header in the `status` command
  -:  ---------- >  5:  83d92a9762 built-in add -i: color the header in the `status` command
  6:  93b3151b6c !  6:  3eec219124 built-in add -i: implement the main loop
     @@ -53,8 +53,8 @@
       	void (*print_item)(int i, struct item *item, void *print_item_data);
       	void *print_item_data;
      @@
     - 
     - static void list(struct item **list, size_t nr, struct list_options *opts)
     + static void list(struct item **list, size_t nr,
     + 		 struct add_i_state *s, struct list_options *opts)
       {
      -	int i;
      +	int i, last_lf = 0;
     @@ -85,28 +85,35 @@
      +	const char *prompt;
      +};
      +
     ++#define LIST_AND_CHOOSE_ERROR (-1)
     ++#define LIST_AND_CHOOSE_QUIT  (-2)
     ++
      +/*
      + * Returns the selected index.
     ++ *
     ++ * If an error occurred, returns `LIST_AND_CHOOSE_ERROR`. Upon EOF,
     ++ * `LIST_AND_CHOOSE_QUIT` is returned.
      + */
      +static ssize_t list_and_choose(struct item **items, size_t nr,
     ++			       struct add_i_state *s,
      +			       struct list_and_choose_options *opts)
      +{
      +	struct strbuf input = STRBUF_INIT;
     -+	ssize_t res = -1;
     ++	ssize_t res = LIST_AND_CHOOSE_ERROR;
      +
      +	for (;;) {
      +		char *p, *endp;
      +
      +		strbuf_reset(&input);
      +
     -+		list(items, nr, &opts->list_opts);
     ++		list(items, nr, s, &opts->list_opts);
      +
      +		printf("%s%s", opts->prompt, "> ");
      +		fflush(stdout);
      +
      +		if (strbuf_getline(&input, stdin) == EOF) {
      +			putchar('\n');
     -+			res = -2;
     ++			res = LIST_AND_CHOOSE_QUIT;
      +			break;
      +		}
      +		strbuf_trim(&input);
     @@ -143,7 +150,7 @@
      +			p += sep + 1;
      +		}
      +
     -+		if (res >= 0)
     ++		if (res != LIST_AND_CHOOSE_ERROR)
      +			break;
       	}
      +
     @@ -164,12 +171,13 @@
      +
      +struct command_item {
      +	struct item item;
     -+	int (*command)(struct repository *r, const struct pathspec *ps,
     ++	int (*command)(struct add_i_state *s, const struct pathspec *ps,
      +		       struct file_list *files, struct list_options *opts);
      +};
      +
       int run_add_i(struct repository *r, const struct pathspec *ps)
       {
     + 	struct add_i_state s = { NULL };
      +	struct list_and_choose_options main_loop_opts = {
      +		{ 4, N_("*** Commands ***"), print_command_item, NULL },
      +		N_("What now")
     @@ -192,21 +200,21 @@
      +	ssize_t i;
       	int res = 0;
       
     - 	strbuf_addstr(&header, "      ");
     + 	if (init_add_i_state(r, &s))
      @@
     - 	if (run_status(r, ps, &files, &opts) < 0)
     + 	if (run_status(&s, ps, &files, &opts) < 0)
       		res = -1;
       
      +	for (;;) {
      +		i = list_and_choose((struct item **)commands,
     -+				    ARRAY_SIZE(commands), &main_loop_opts);
     -+		if (i < -1) {
     ++				    ARRAY_SIZE(commands), &s, &main_loop_opts);
     ++		if (i == LIST_AND_CHOOSE_QUIT) {
      +			printf(_("Bye.\n"));
      +			res = 0;
      +			break;
      +		}
     -+		if (i >= 0)
     -+			res = commands[i]->command(r, ps, &files, &opts);
     ++		if (i != LIST_AND_CHOOSE_ERROR)
     ++			res = commands[i]->command(&s, ps, &files, &opts);
      +	}
      +
       	release_file_list(&files);
  7:  db1ede3636 !  7:  e02a52c3ac Add a function to determine unique prefixes for a list of strings
     @@ -92,40 +92,40 @@
      +static void add_prefix_item(struct prefix_map *prefix_map,
      +			    struct prefix_item *item)
      +{
     -+	struct prefix_map_entry *e = xmalloc(sizeof(*e)), *e2;
     ++	struct prefix_map_entry e = { { NULL } }, *e2;
      +	int j;
      +
     -+	e->item = item;
     -+	e->name = e->item->name;
     ++	e.item = item;
     ++	e.name = item->name;
      +
     -+	for (j = prefix_map->min_length; j <= prefix_map->max_length; j++) {
     -+		if (!isascii(e->name[j])) {
     -+			free(e);
     ++	for (j = prefix_map->min_length;
     ++	     j <= prefix_map->max_length && e.name[j]; j++) {
     ++		/* Avoid breaking UTF-8 multi-byte sequences */
     ++		if (!isascii(e.name[j]))
      +			break;
     -+		}
      +
     -+		e->prefix_length = j;
     -+		hashmap_entry_init(e, memhash(e->name, j));
     -+		e2 = hashmap_get(&prefix_map->map, e, NULL);
     ++		e.prefix_length = j;
     ++		hashmap_entry_init(&e, memhash(e.name, j));
     ++		e2 = hashmap_get(&prefix_map->map, &e, NULL);
      +		if (!e2) {
     -+			/* prefix is unique so far */
     -+			e->item->prefix_length = j;
     -+			hashmap_add(&prefix_map->map, e);
     ++			/* prefix is unique at this stage */
     ++			item->prefix_length = j;
     ++			add_prefix_entry(&prefix_map->map, e.name, j, item);
      +			break;
      +		}
      +
      +		if (!e2->item)
      +			continue; /* non-unique prefix */
      +
     -+		if (j != e2->item->prefix_length)
     -+			BUG("unexpected prefix length: %d != %d",
     -+			    (int)j, (int)e2->item->prefix_length);
     ++		if (j != e2->item->prefix_length || memcmp(e.name, e2->name, j))
     ++			BUG("unexpected prefix length: %d != %d (%s != %s)",
     ++			    j, (int)e2->item->prefix_length, e.name, e2->name);
      +
      +		/* skip common prefix */
     -+		for (; j < prefix_map->max_length && e->name[j]; j++) {
     -+			if (e->item->name[j] != e2->item->name[j])
     ++		for (; j < prefix_map->max_length && e.name[j]; j++) {
     ++			if (e.item->name[j] != e2->item->name[j])
      +				break;
     -+			add_prefix_entry(&prefix_map->map, e->name, j + 1,
     ++			add_prefix_entry(&prefix_map->map, e.name, j + 1,
      +					 NULL);
      +		}
      +
     @@ -140,16 +140,14 @@
      +			e2->item->prefix_length = 0;
      +		e2->item = NULL;
      +
     -+		if (j < prefix_map->max_length && e->name[j]) {
     ++		if (j < prefix_map->max_length && e.name[j]) {
      +			/* found a unique prefix for the item */
     -+			e->item->prefix_length = j + 1;
     -+			add_prefix_entry(&prefix_map->map, e->name, j + 1,
     -+					 e->item);
     -+		} else {
     ++			e.item->prefix_length = j + 1;
     ++			add_prefix_entry(&prefix_map->map, e.name, j + 1,
     ++					 e.item);
     ++		} else
      +			/* item has no (short enough) unique prefix */
     -+			e->item->prefix_length = 0;
     -+			free(e);
     -+		}
     ++			e.item->prefix_length = 0;
      +
      +		break;
      +	}
  8:  56acc31e96 !  8:  ced9b6aced built-in add -i: show unique prefixes of the commands
     @@ -22,10 +22,10 @@
       #include "refs.h"
      +#include "prefix-map.h"
       
     - static int use_color = -1;
     - 
     + struct add_i_state {
     + 	struct repository *r;
      @@
     - 	return git_color_default_config(var, value, cb);
     + 	return 0;
       }
       
      -struct item {
     @@ -57,22 +57,22 @@
       	void *print_item_data;
       };
       
     --static void list(struct item **list, size_t nr, struct list_options *opts)
     +-static void list(struct item **list, size_t nr,
      +static void list(struct prefix_item **list, size_t nr,
     -+		 struct list_options *opts)
     + 		 struct add_i_state *s, struct list_options *opts)
       {
       	int i, last_lf = 0;
     - 
      @@
     - /*
     -  * Returns the selected index.
     +  * If an error occurred, returns `LIST_AND_CHOOSE_ERROR`. Upon EOF,
     +  * `LIST_AND_CHOOSE_QUIT` is returned.
        */
      -static ssize_t list_and_choose(struct item **items, size_t nr,
      +static ssize_t list_and_choose(struct prefix_item **items, size_t nr,
     + 			       struct add_i_state *s,
       			       struct list_and_choose_options *opts)
       {
       	struct strbuf input = STRBUF_INIT;
     - 	ssize_t res = -1;
     + 	ssize_t res = LIST_AND_CHOOSE_ERROR;
       
      +	find_unique_prefixes(items, nr, 1, 4);
      +
     @@ -133,8 +133,8 @@
       		return -1;
       
       	if (files->nr)
     --		list((struct item **)files->file, files->nr, opts);
     -+		list((struct prefix_item **)files->file, files->nr, opts);
     +-		list((struct item **)files->file, files->nr, s, opts);
     ++		list((struct prefix_item **)files->file, files->nr, s, opts);
       	putchar('\n');
       
       	return 0;
     @@ -157,7 +157,7 @@
       struct command_item {
      -	struct item item;
      +	struct prefix_item item;
     - 	int (*command)(struct repository *r, const struct pathspec *ps,
     + 	int (*command)(struct add_i_state *s, const struct pathspec *ps,
       		       struct file_list *files, struct list_options *opts);
       };
      @@
     @@ -166,6 +166,6 @@
       	for (;;) {
      -		i = list_and_choose((struct item **)commands,
      +		i = list_and_choose((struct prefix_item **)commands,
     - 				    ARRAY_SIZE(commands), &main_loop_opts);
     - 		if (i < -1) {
     + 				    ARRAY_SIZE(commands), &s, &main_loop_opts);
     + 		if (i == LIST_AND_CHOOSE_QUIT) {
       			printf(_("Bye.\n"));
  9:  ddd0ee51f6 !  9:  7378af60ad built-in add -i: support `?` (prompt help)
     @@ -12,41 +12,35 @@
       --- a/add-interactive.c
       +++ b/add-interactive.c
      @@
     - 
     - enum color_add_i {
     - 	COLOR_HEADER = 0,
     -+	COLOR_HELP,
     - };
     - 
     - static char list_colors[][COLOR_MAXLEN] = {
     - 	GIT_COLOR_BOLD,      /* Header */
     -+	GIT_COLOR_BOLD_RED,  /* Help */
     + 	struct repository *r;
     + 	int use_color;
     + 	char header_color[COLOR_MAXLEN];
     ++	char help_color[COLOR_MAXLEN];
       };
       
     - static const char *get_add_i_color(enum color_add_i ix)
     + static void init_color(struct repository *r, struct add_i_state *s,
      @@
     - {
     - 	if (!strcasecmp(slot, "header"))
     - 		return COLOR_HEADER;
     -+	if (!strcasecmp(slot, "help"))
     -+		return COLOR_HELP;
     + 	s->use_color = want_color(s->use_color);
     + 
     + 	init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD);
     ++	init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED);
       
     - 	return -1;
     + 	return 0;
       }
      @@
       	struct list_options list_opts;
       
       	const char *prompt;
     -+	void (*print_help)(void);
     ++	void (*print_help)(struct add_i_state *s);
       };
       
     - /*
     + #define LIST_AND_CHOOSE_ERROR (-1)
      @@
       		if (!input.len)
       			break;
       
      +		if (!strcmp(input.buf, "?")) {
     -+			opts->print_help();
     ++			opts->print_help(s);
      +			continue;
      +		}
      +
     @@ -57,9 +51,9 @@
       		       struct file_list *files, struct list_options *opts);
       };
       
     -+static void command_prompt_help(void)
     ++static void command_prompt_help(struct add_i_state *s)
      +{
     -+	const char *help_color = get_add_i_color(COLOR_HELP);
     ++	const char *help_color = s->help_color;
      +	color_fprintf_ln(stdout, help_color, "%s", _("Prompt help:"));
      +	color_fprintf_ln(stdout, help_color, "1          - %s",
      +			 _("select a numbered item"));
     @@ -71,6 +65,7 @@
      +
       int run_add_i(struct repository *r, const struct pathspec *ps)
       {
     + 	struct add_i_state s = { NULL };
       	struct list_and_choose_options main_loop_opts = {
       		{ 4, N_("*** Commands ***"), print_command_item, NULL },
      -		N_("What now")
 10:  3e1a88d9c0 ! 10:  36edef85e6 built-in add -i: use color in the main loop
     @@ -12,51 +12,31 @@
       --- a/add-interactive.c
       +++ b/add-interactive.c
      @@
     - enum color_add_i {
     - 	COLOR_HEADER = 0,
     - 	COLOR_HELP,
     -+	COLOR_PROMPT,
     -+	COLOR_ERROR,
     -+	COLOR_RESET,
     + 	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 char list_colors[][COLOR_MAXLEN] = {
     - 	GIT_COLOR_BOLD,      /* Header */
     - 	GIT_COLOR_BOLD_RED,  /* Help */
     -+	GIT_COLOR_BOLD_BLUE, /* Prompt */
     -+	GIT_COLOR_BOLD_RED,  /* Error */
     -+	GIT_COLOR_RESET,     /* Reset */
     - };
     - 
     - static const char *get_add_i_color(enum color_add_i ix)
     + static void init_color(struct repository *r, struct add_i_state *s,
      @@
     - 		return COLOR_HEADER;
     - 	if (!strcasecmp(slot, "help"))
     - 		return COLOR_HELP;
     -+	if (!strcasecmp(slot, "prompt"))
     -+		return COLOR_PROMPT;
     -+	if (!strcasecmp(slot, "error"))
     -+		return COLOR_ERROR;
     -+	if (!strcasecmp(slot, "reset"))
     -+		return COLOR_RESET;
       
     - 	return -1;
     - }
     -@@
     - static ssize_t list_and_choose(struct prefix_item **items, size_t nr,
     - 			       struct list_and_choose_options *opts)
     - {
     -+	const char *prompt_color = get_add_i_color(COLOR_PROMPT);
     -+	const char *error_color = get_add_i_color(COLOR_ERROR);
     - 	struct strbuf input = STRBUF_INIT;
     - 	ssize_t res = -1;
     + 	init_color(r, s, "header", s->header_color, GIT_COLOR_BOLD);
     + 	init_color(r, s, "help", s->help_color, GIT_COLOR_BOLD_RED);
     ++	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);
       
     + 	return 0;
     + }
      @@
       
     - 		list(items, nr, &opts->list_opts);
     + 		list(items, nr, s, &opts->list_opts);
       
      -		printf("%s%s", opts->prompt, "> ");
     -+		color_fprintf(stdout, prompt_color, "%s", opts->prompt);
     ++		color_fprintf(stdout, s->prompt_color, "%s", opts->prompt);
      +		fputs("> ", stdout);
       		fflush(stdout);
       
     @@ -66,7 +46,7 @@
       
       			if (index < 0 || index >= nr)
      -				printf(_("Huh (%s)?\n"), p);
     -+				color_fprintf_ln(stdout, error_color,
     ++				color_fprintf_ln(stdout, s->error_color,
      +						 _("Huh (%s)?"), p);
       			else {
       				res = index;
     @@ -96,20 +76,32 @@
       }
       
      @@
     - 
       int run_add_i(struct repository *r, const struct pathspec *ps)
       {
     -+	struct print_command_item_data data = {
     -+		/*
     -+		 * When color was asked for, use the prompt color for
     -+		 * highlighting, otherwise use square brackets.
     -+		 */
     -+		want_color(use_color) ? get_add_i_color(COLOR_PROMPT) : "[",
     -+		want_color(use_color) ? get_add_i_color(COLOR_RESET) : "]"
     -+	};
     + 	struct add_i_state s = { NULL };
     ++	struct print_command_item_data data;
       	struct list_and_choose_options main_loop_opts = {
      -		{ 4, N_("*** Commands ***"), print_command_item, NULL },
      +		{ 4, N_("*** Commands ***"), print_command_item, &data },
       		N_("What now"), command_prompt_help
       	};
       	struct command_item
     +@@
     + 	if (init_add_i_state(r, &s))
     + 		return error("could not parse `add -i` config");
     + 
     ++	/*
     ++	 * When color was asked for, use the prompt color for
     ++	 * highlighting, otherwise use square brackets.
     ++	 */
     ++	if (s.use_color) {
     ++		data.color = s.prompt_color;
     ++		data.reset = s.reset_color;
     ++	} else {
     ++		data.color = "[";
     ++		data.reset = "]";
     ++	}
     ++
     + 	strbuf_addstr(&header, "      ");
     + 	strbuf_addf(&header, print_file_item_data.modified_fmt,
     + 		    _("staged"), _("unstaged"), _("path"));
 11:  481e3316d5 ! 11:  266dbf2a6b built-in add -i: implement the `help` command
     @@ -18,10 +18,10 @@
       	return 0;
       }
       
     -+static int run_help(struct repository *r, const struct pathspec *ps,
     ++static int run_help(struct add_i_state *s, const struct pathspec *ps,
      +		    struct file_list *files, struct list_options *opts)
      +{
     -+	const char *help_color = get_add_i_color(COLOR_HELP);
     ++	const char *help_color = s->help_color;
      +
      +	color_fprintf_ln(stdout, help_color, "status        - %s",
      +			 _("show paths with changes"));

-- 
gitgitgadget

  parent reply	other threads:[~2019-05-13 17:27 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-10 17:37 [PATCH " Johannes Schindelin via GitGitGadget
2019-04-10 17:37 ` [PATCH 01/11] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-04-18 14:31   ` Jeff Hostetler
2019-04-18 16:06     ` Jeff King
2019-04-30 23:40       ` Johannes Schindelin
2019-05-01  2:21         ` Jeff King
2019-05-13 11:14           ` Johannes Schindelin
2019-04-10 17:37 ` [PATCH 02/11] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-04-10 17:37 ` [PATCH 03/11] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-04-10 17:37 ` [PATCH 04/11] built-in add -i: refresh the index before running `status` Johannes Schindelin via GitGitGadget
2019-04-10 17:37 ` [PATCH 05/11] built-in add -i: color the header in the `status` command Johannes Schindelin via GitGitGadget
2019-04-10 17:37 ` [PATCH 06/11] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-04-18 16:49   ` Jeff Hostetler
2019-05-13 12:04     ` Johannes Schindelin
2019-04-10 17:37 ` [PATCH 07/11] Add a function to determine unique prefixes for a list of strings Slavica Djukic via GitGitGadget
2019-04-18 17:57   ` Jeff Hostetler
2019-05-13 12:48     ` Johannes Schindelin
2019-04-10 17:37 ` [PATCH 08/11] built-in add -i: show unique prefixes of the commands Slavica Djukic via GitGitGadget
2019-04-10 17:37 ` [PATCH 09/11] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-04-10 17:37 ` [PATCH 10/11] built-in add -i: use color in the main loop Slavica Djukic via GitGitGadget
2019-04-10 17:37 ` [PATCH 11/11] built-in add -i: implement the `help` command Johannes Schindelin via GitGitGadget
2019-05-13 17:27 ` Johannes Schindelin via GitGitGadget [this message]
2019-05-13 17:27   ` [PATCH v2 01/11] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 02/11] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 03/11] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 04/11] built-in add -i: refresh the index before running `status` Johannes Schindelin via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 06/11] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 05/11] built-in add -i: color the header in the `status` command Johannes Schindelin via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 07/11] Add a function to determine unique prefixes for a list of strings Slavica Djukic via GitGitGadget
2019-05-13 17:27   ` [PATCH v2 08/11] built-in add -i: show unique prefixes of the commands Slavica Djukic via GitGitGadget
2019-05-13 17:28   ` [PATCH v2 09/11] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-05-13 17:28   ` [PATCH v2 10/11] built-in add -i: use color in the main loop Slavica Djukic via GitGitGadget
2019-05-13 17:28   ` [PATCH v2 11/11] built-in add -i: implement the `help` command Johannes Schindelin via GitGitGadget
2019-07-16 14:58   ` [PATCH v3 00/11] git add -i: add a rudimentary version in C (supporting only status and help so far) Johannes Schindelin via GitGitGadget
2019-07-16 14:58     ` [PATCH v3 01/11] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-07-31 17:52       ` Junio C Hamano
2019-08-26 21:26         ` Johannes Schindelin
2019-08-27 22:25           ` Junio C Hamano
2019-08-28 15:06             ` Johannes Schindelin
2019-08-28 15:37               ` Junio C Hamano
2019-07-16 14:58     ` [PATCH v3 03/11] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-07-31 18:12       ` Junio C Hamano
2019-08-27 10:04         ` Johannes Schindelin
2019-07-16 14:58     ` [PATCH v3 02/11] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-07-31 17:59       ` Junio C Hamano
2019-08-27  9:22         ` Johannes Schindelin
2019-07-16 14:58     ` [PATCH v3 04/11] built-in add -i: refresh the index before running `status` Johannes Schindelin via GitGitGadget
2019-07-16 14:58     ` [PATCH v3 05/11] built-in add -i: color the header in the `status` command Johannes Schindelin via GitGitGadget
2019-07-16 14:58     ` [PATCH v3 06/11] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-07-31 18:14       ` Junio C Hamano
2019-07-16 14:58     ` [PATCH v3 07/11] Add a function to determine unique prefixes for a list of strings Slavica Djukic via GitGitGadget
2019-07-31 18:39       ` Junio C Hamano
2019-08-24 12:38       ` SZEDER Gábor
2019-08-27 12:14         ` Johannes Schindelin
2019-08-28 16:30           ` SZEDER Gábor
2019-08-28 16:34             ` [PATCH] [PoC] A simpler find_unique_prefixes() implementation SZEDER Gábor
2019-08-30 20:12               ` Johannes Schindelin
2019-07-16 14:58     ` [PATCH v3 08/11] built-in add -i: show unique prefixes of the commands Slavica Djukic via GitGitGadget
2019-07-16 14:58     ` [PATCH v3 09/11] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-07-16 14:58     ` [PATCH v3 10/11] built-in add -i: use color in the main loop Slavica Djukic via GitGitGadget
2019-07-16 14:58     ` [PATCH v3 11/11] built-in add -i: implement the `help` command Johannes Schindelin via GitGitGadget
2019-08-02 21:04       ` Junio C Hamano
2019-08-02 22:26         ` Jeff King
2019-07-16 18:38     ` [PATCH v3 00/11] git add -i: add a rudimentary version in C (supporting only status and help so far) Johannes Schindelin
2019-08-02 21:06       ` Junio C Hamano
2019-08-27 12:57     ` [PATCH v4 " Johannes Schindelin via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 01/11] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 02/11] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 03/11] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 04/11] built-in add -i: refresh the index before running `status` Johannes Schindelin via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 05/11] built-in add -i: color the header in the `status` command Johannes Schindelin via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 06/11] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 07/11] Add a function to determine unique prefixes for a list of strings Slavica Djukic via GitGitGadget
2019-08-27 12:57       ` [PATCH v4 08/11] built-in add -i: show unique prefixes of the commands Slavica Djukic via GitGitGadget
2019-08-27 12:58       ` [PATCH v4 09/11] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-08-27 12:58       ` [PATCH v4 10/11] built-in add -i: use color in the main loop Slavica Djukic via GitGitGadget
2019-08-27 12:58       ` [PATCH v4 11/11] built-in add -i: implement the `help` command Johannes Schindelin via GitGitGadget
2019-11-04 12:15       ` [PATCH v5 0/9] git add -i: add a rudimentary version in C (supporting only status and help so far) Johannes Schindelin via GitGitGadget
2019-11-04 12:15         ` [PATCH v5 1/9] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-11-08  4:49           ` Junio C Hamano
2019-11-09 11:06             ` Johannes Schindelin
2019-11-10  7:18               ` Junio C Hamano
2019-11-11  9:15                 ` Johannes Schindelin
2019-11-11 12:09                   ` Junio C Hamano
2019-11-12 15:03                     ` Johannes Schindelin
2019-11-13  3:54                       ` Junio C Hamano
2019-11-13 12:30                         ` Johannes Schindelin
2019-11-13 14:01                           ` Junio C Hamano
2019-11-04 12:15         ` [PATCH v5 2/9] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-11-08  4:56           ` Junio C Hamano
2019-11-04 12:15         ` [PATCH v5 3/9] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-11-08  5:01           ` Junio C Hamano
2019-11-04 12:15         ` [PATCH v5 4/9] built-in add -i: color the header in " Slavica Đukić via GitGitGadget
2019-11-04 12:15         ` [PATCH v5 5/9] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-11-08  5:17           ` Junio C Hamano
2019-11-09 11:21             ` Johannes Schindelin
2019-11-04 12:15         ` [PATCH v5 6/9] built-in add -i: show unique prefixes of the commands Johannes Schindelin via GitGitGadget
2019-11-04 12:15         ` [PATCH v5 7/9] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-11-04 12:15         ` [PATCH v5 8/9] built-in add -i: use color in the main loop Slavica Đukić via GitGitGadget
2019-11-04 12:15         ` [PATCH v5 9/9] built-in add -i: implement the `help` command Slavica Đukić via GitGitGadget
2019-11-13 12:40         ` [PATCH v6 0/9] git add -i: add a rudimentary version in C (supporting only status and help so far) Johannes Schindelin via GitGitGadget
2019-11-13 12:40           ` [PATCH v6 1/9] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-11-14  2:15             ` Junio C Hamano
2019-11-14 15:07               ` Johannes Schindelin
2019-11-15  4:35                 ` Junio C Hamano
2019-11-13 12:40           ` [PATCH v6 2/9] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-11-13 12:40           ` [PATCH v6 3/9] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-11-13 12:41           ` [PATCH v6 4/9] built-in add -i: color the header in " Slavica Đukić via GitGitGadget
2019-11-13 12:41           ` [PATCH v6 5/9] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-11-13 12:41           ` [PATCH v6 6/9] built-in add -i: show unique prefixes of the commands Johannes Schindelin via GitGitGadget
2019-11-13 12:41           ` [PATCH v6 7/9] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-11-13 12:41           ` [PATCH v6 8/9] built-in add -i: use color in the main loop Slavica Đukić via GitGitGadget
2019-11-13 12:41           ` [PATCH v6 9/9] built-in add -i: implement the `help` command Slavica Đukić via GitGitGadget
2019-11-13 12:46           ` [PATCH v6 0/9] git add -i: add a rudimentary version in C (supporting only status and help so far) Johannes Schindelin
2019-11-15 11:11           ` [PATCH v7 " Johannes Schindelin via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 1/9] Start to implement a built-in version of `git add --interactive` Johannes Schindelin via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 2/9] diff: export diffstat interface Daniel Ferreira via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 3/9] built-in add -i: implement the `status` command Daniel Ferreira via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 4/9] built-in add -i: color the header in " Slavica Đukić via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 5/9] built-in add -i: implement the main loop Johannes Schindelin via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 6/9] built-in add -i: show unique prefixes of the commands Johannes Schindelin via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 7/9] built-in add -i: support `?` (prompt help) Johannes Schindelin via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 8/9] built-in add -i: use color in the main loop Slavica Đukić via GitGitGadget
2019-11-15 11:11             ` [PATCH v7 9/9] built-in add -i: implement the `help` command Slavica Đukić via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.170.v2.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --subject='Re: [PATCH v2 00/11] git add -i: add a rudimentary version in C (supporting only status and help  so far)' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).