builtin-add: refactor the meat of interactive_add()
This moves the call setup for 'git add--interactive' to a separate function, as other users will call it without running validate_pathspec() first. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
b319ef70a9
commit
46b5139cae
@ -131,10 +131,37 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
|
|||||||
return pathspec;
|
return pathspec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int run_add_interactive(const char *revision, const char *patch_mode,
|
||||||
|
const char **pathspec)
|
||||||
|
{
|
||||||
|
int status, ac, pc = 0;
|
||||||
|
const char **args;
|
||||||
|
|
||||||
|
if (pathspec)
|
||||||
|
while (pathspec[pc])
|
||||||
|
pc++;
|
||||||
|
|
||||||
|
args = xcalloc(sizeof(const char *), (pc + 5));
|
||||||
|
ac = 0;
|
||||||
|
args[ac++] = "add--interactive";
|
||||||
|
if (patch_mode)
|
||||||
|
args[ac++] = patch_mode;
|
||||||
|
if (revision)
|
||||||
|
args[ac++] = revision;
|
||||||
|
args[ac++] = "--";
|
||||||
|
if (pc) {
|
||||||
|
memcpy(&(args[ac]), pathspec, sizeof(const char *) * pc);
|
||||||
|
ac += pc;
|
||||||
|
}
|
||||||
|
args[ac] = NULL;
|
||||||
|
|
||||||
|
status = run_command_v_opt(args, RUN_GIT_CMD);
|
||||||
|
free(args);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
int interactive_add(int argc, const char **argv, const char *prefix)
|
int interactive_add(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
int status, ac;
|
|
||||||
const char **args;
|
|
||||||
const char **pathspec = NULL;
|
const char **pathspec = NULL;
|
||||||
|
|
||||||
if (argc) {
|
if (argc) {
|
||||||
@ -143,21 +170,9 @@ int interactive_add(int argc, const char **argv, const char *prefix)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
args = xcalloc(sizeof(const char *), (argc + 4));
|
return run_add_interactive(NULL,
|
||||||
ac = 0;
|
patch_interactive ? "--patch" : NULL,
|
||||||
args[ac++] = "add--interactive";
|
pathspec);
|
||||||
if (patch_interactive)
|
|
||||||
args[ac++] = "--patch";
|
|
||||||
args[ac++] = "--";
|
|
||||||
if (argc) {
|
|
||||||
memcpy(&(args[ac]), pathspec, sizeof(const char *) * argc);
|
|
||||||
ac += argc;
|
|
||||||
}
|
|
||||||
args[ac] = NULL;
|
|
||||||
|
|
||||||
status = run_command_v_opt(args, RUN_GIT_CMD);
|
|
||||||
free(args);
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int edit_patch(int argc, const char **argv, const char *prefix)
|
static int edit_patch(int argc, const char **argv, const char *prefix)
|
||||||
|
2
commit.h
2
commit.h
@ -137,6 +137,8 @@ int is_descendant_of(struct commit *, struct commit_list *);
|
|||||||
int in_merge_bases(struct commit *, struct commit **, int);
|
int in_merge_bases(struct commit *, struct commit **, int);
|
||||||
|
|
||||||
extern int interactive_add(int argc, const char **argv, const char *prefix);
|
extern int interactive_add(int argc, const char **argv, const char *prefix);
|
||||||
|
extern int run_add_interactive(const char *revision, const char *patch_mode,
|
||||||
|
const char **pathspec);
|
||||||
|
|
||||||
static inline int single_parent(struct commit *commit)
|
static inline int single_parent(struct commit *commit)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user