This feature was missing, and made it cumbersome for third-party tools to reset a lot of paths in one go. Support for --stdin has been added, following builtin/checkout-index.c's example. Changes since v2: - the documentation clarifies that --stdin does not treat the input as pathspecs - the code now uses struct argv_array instead of rolling its own Johannes Schindelin (1): reset: support the --stdin option Documentation/git-reset.txt | 10 ++++++++++ builtin/reset.c | 47 ++++++++++++++++++++++++++++++++++++++++++++- t/t7107-reset-stdin.sh | 33 +++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100755 t/t7107-reset-stdin.sh base-commit: 4e59582ff70d299f5a88449891e78d15b4b3fabe Published-As: https://github.com/dscho/git/releases/tag/reset-stdin-v3 Fetch-It-Via: git fetch https://github.com/dscho/git reset-stdin-v3 Interdiff vs v2: diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt index abb71bb805..d319ed9b20 100644 --- a/Documentation/git-reset.txt +++ b/Documentation/git-reset.txt @@ -100,7 +100,8 @@ OPTIONS --stdin:: Instead of taking list of paths from the command line, - read list of paths from the standard input. Paths are + read list of paths from the standard input. The paths are + read verbatim, i.e. not handled as pathspecs. Paths are separated by LF (i.e. one path per line) by default. -z:: diff --git a/builtin/reset.c b/builtin/reset.c index 1d3075b7ee..fe7723c179 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -23,6 +23,7 @@ #include "cache-tree.h" #include "strbuf.h" #include "quote.h" +#include "argv-array.h" static const char * const git_reset_usage[] = { N_("git reset [--mixed | --soft | --hard | --merge | --keep] [-q] [<commit>]"), @@ -271,8 +272,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) { int reset_type = NONE, update_ref_status = 0, quiet = 0; int patch_mode = 0, nul_term_line = 0, read_from_stdin = 0, unborn; - char **stdin_paths = NULL; - int stdin_nr = 0, stdin_alloc = 0; + struct argv_array stdin_paths = ARGV_ARRAY_INIT; const char *rev; struct object_id oid; struct pathspec pathspec; @@ -325,18 +325,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix) die(_("line is badly quoted")); strbuf_swap(&buf, &unquoted); } - ALLOC_GROW(stdin_paths, stdin_nr + 1, stdin_alloc); - stdin_paths[stdin_nr++] = xstrdup(buf.buf); + argv_array_push(&stdin_paths, buf.buf); strbuf_reset(&buf); } strbuf_release(&unquoted); strbuf_release(&buf); - ALLOC_GROW(stdin_paths, stdin_nr + 1, stdin_alloc); - stdin_paths[stdin_nr++] = NULL; flags |= PATHSPEC_LITERAL_PATH; parse_pathspec(&pathspec, 0, flags, prefix, - (const char **)stdin_paths); + stdin_paths.argv); } else if (nul_term_line) die(_("-z requires --stdin")); @@ -431,11 +428,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (!pathspec.nr) remove_branch_state(); - if (stdin_paths) { - while (stdin_nr) - free(stdin_paths[--stdin_nr]); - free(stdin_paths); - } + argv_array_clear(&stdin_paths); return update_ref_status; } -- 2.11.1.windows.prerelease.2.9.g3014b57