mirror of
https://github.com/git/git
synced 2024-08-28 12:09:19 +00:00
convert run_add_interactive to use struct pathspec
This passes the pathspec, more or less unmodified, to git-add--interactive. The command itself does not process pathspec. It simply passes the pathspec to other builtin commands. So if all those commands support pathspec, we're good. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5ab2a2dabd
commit
480ca6449e
|
@ -244,16 +244,12 @@ static void refresh(int verbose, const char **pathspec)
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_add_interactive(const char *revision, const char *patch_mode,
|
int run_add_interactive(const char *revision, const char *patch_mode,
|
||||||
const char **pathspec)
|
const struct pathspec *pathspec)
|
||||||
{
|
{
|
||||||
int status, ac, pc = 0;
|
int status, ac, i;
|
||||||
const char **args;
|
const char **args;
|
||||||
|
|
||||||
if (pathspec)
|
args = xcalloc(sizeof(const char *), (pathspec->nr + 6));
|
||||||
while (pathspec[pc])
|
|
||||||
pc++;
|
|
||||||
|
|
||||||
args = xcalloc(sizeof(const char *), (pc + 5));
|
|
||||||
ac = 0;
|
ac = 0;
|
||||||
args[ac++] = "add--interactive";
|
args[ac++] = "add--interactive";
|
||||||
if (patch_mode)
|
if (patch_mode)
|
||||||
|
@ -261,11 +257,9 @@ int run_add_interactive(const char *revision, const char *patch_mode,
|
||||||
if (revision)
|
if (revision)
|
||||||
args[ac++] = revision;
|
args[ac++] = revision;
|
||||||
args[ac++] = "--";
|
args[ac++] = "--";
|
||||||
if (pc) {
|
for (i = 0; i < pathspec->nr; i++)
|
||||||
memcpy(&(args[ac]), pathspec, sizeof(const char *) * pc);
|
/* pass original pathspec, to be re-parsed */
|
||||||
ac += pc;
|
args[ac++] = pathspec->items[i].original;
|
||||||
}
|
|
||||||
args[ac] = NULL;
|
|
||||||
|
|
||||||
status = run_command_v_opt(args, RUN_GIT_CMD);
|
status = run_command_v_opt(args, RUN_GIT_CMD);
|
||||||
free(args);
|
free(args);
|
||||||
|
@ -280,17 +274,17 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
|
||||||
* git-add--interactive itself does not parse pathspec. It
|
* git-add--interactive itself does not parse pathspec. It
|
||||||
* simply passes the pathspec to other builtin commands. Let's
|
* simply passes the pathspec to other builtin commands. Let's
|
||||||
* hope all of them support all magic, or we'll need to limit
|
* hope all of them support all magic, or we'll need to limit
|
||||||
* the magic here. There is still a problem with prefix. But
|
* the magic here.
|
||||||
* that'll be worked on later on.
|
|
||||||
*/
|
*/
|
||||||
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
|
parse_pathspec(&pathspec, PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
|
||||||
PATHSPEC_PREFER_FULL |
|
PATHSPEC_PREFER_FULL |
|
||||||
PATHSPEC_SYMLINK_LEADING_PATH,
|
PATHSPEC_SYMLINK_LEADING_PATH |
|
||||||
|
PATHSPEC_PREFIX_ORIGIN,
|
||||||
prefix, argv);
|
prefix, argv);
|
||||||
|
|
||||||
return run_add_interactive(NULL,
|
return run_add_interactive(NULL,
|
||||||
patch ? "--patch" : NULL,
|
patch ? "--patch" : NULL,
|
||||||
pathspec.raw);
|
&pathspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int edit_patch(int argc, const char **argv, const char *prefix)
|
static int edit_patch(int argc, const char **argv, const char *prefix)
|
||||||
|
|
|
@ -257,7 +257,7 @@ static int checkout_paths(const struct checkout_opts *opts,
|
||||||
|
|
||||||
if (opts->patch_mode)
|
if (opts->patch_mode)
|
||||||
return run_add_interactive(revision, "--patch=checkout",
|
return run_add_interactive(revision, "--patch=checkout",
|
||||||
opts->pathspec.raw);
|
&opts->pathspec);
|
||||||
|
|
||||||
lock_file = xcalloc(1, sizeof(struct lock_file));
|
lock_file = xcalloc(1, sizeof(struct lock_file));
|
||||||
|
|
||||||
|
@ -1159,10 +1159,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
|
||||||
* cannot handle. Magic mask is pretty safe to be
|
* cannot handle. Magic mask is pretty safe to be
|
||||||
* lifted for new magic when opts.patch_mode == 0.
|
* lifted for new magic when opts.patch_mode == 0.
|
||||||
*/
|
*/
|
||||||
parse_pathspec(&opts.pathspec,
|
parse_pathspec(&opts.pathspec, 0,
|
||||||
opts.patch_mode == 0 ? 0 :
|
opts.patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0,
|
||||||
(PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP),
|
prefix, argv);
|
||||||
0, prefix, argv);
|
|
||||||
|
|
||||||
if (!opts.pathspec.nr)
|
if (!opts.pathspec.nr)
|
||||||
die(_("invalid path specification"));
|
die(_("invalid path specification"));
|
||||||
|
|
|
@ -219,9 +219,9 @@ static void parse_args(struct pathspec *pathspec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*rev_ret = rev;
|
*rev_ret = rev;
|
||||||
parse_pathspec(pathspec,
|
parse_pathspec(pathspec, 0,
|
||||||
patch_mode ? PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP : 0,
|
PATHSPEC_PREFER_FULL |
|
||||||
PATHSPEC_PREFER_FULL,
|
(patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
|
||||||
prefix, argv);
|
prefix, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
|
||||||
if (patch_mode) {
|
if (patch_mode) {
|
||||||
if (reset_type != NONE)
|
if (reset_type != NONE)
|
||||||
die(_("--patch is incompatible with --{hard,mixed,soft}"));
|
die(_("--patch is incompatible with --{hard,mixed,soft}"));
|
||||||
return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", pathspec.raw);
|
return run_add_interactive(sha1_to_hex(sha1), "--patch=reset", &pathspec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* git reset tree [--] paths... can be used to
|
/* git reset tree [--] paths... can be used to
|
||||||
|
|
2
commit.h
2
commit.h
|
@ -194,7 +194,7 @@ int in_merge_bases_many(struct commit *, int, struct commit **);
|
||||||
|
|
||||||
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
|
extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
|
||||||
extern int run_add_interactive(const char *revision, const char *patch_mode,
|
extern int run_add_interactive(const char *revision, const char *patch_mode,
|
||||||
const char **pathspec);
|
const struct pathspec *pathspec);
|
||||||
|
|
||||||
static inline int single_parent(struct commit *commit)
|
static inline int single_parent(struct commit *commit)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue