Skip to content

Commit

Permalink
builtin-add: refactor the meat of interactive_add()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Aug 14, 2009
1 parent b319ef7 commit 46b5139
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
43 changes: 29 additions & 14 deletions builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,27 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
return pathspec;
}

int interactive_add(int argc, const char **argv, const char *prefix)
int run_add_interactive(const char *revision, const char *patch_mode,
const char **pathspec)
{
int status, ac;
int status, ac, pc = 0;
const char **args;
const char **pathspec = NULL;

if (argc) {
pathspec = validate_pathspec(argc, argv, prefix);
if (!pathspec)
return -1;
}
if (pathspec)
while (pathspec[pc])
pc++;

args = xcalloc(sizeof(const char *), (argc + 4));
args = xcalloc(sizeof(const char *), (pc + 5));
ac = 0;
args[ac++] = "add--interactive";
if (patch_interactive)
args[ac++] = "--patch";
if (patch_mode)
args[ac++] = patch_mode;
if (revision)
args[ac++] = revision;
args[ac++] = "--";
if (argc) {
memcpy(&(args[ac]), pathspec, sizeof(const char *) * argc);
ac += argc;
if (pc) {
memcpy(&(args[ac]), pathspec, sizeof(const char *) * pc);
ac += pc;
}
args[ac] = NULL;

Expand All @@ -160,6 +160,21 @@ int interactive_add(int argc, const char **argv, const char *prefix)
return status;
}

int interactive_add(int argc, const char **argv, const char *prefix)
{
const char **pathspec = NULL;

if (argc) {
pathspec = validate_pathspec(argc, argv, prefix);
if (!pathspec)
return -1;
}

return run_add_interactive(NULL,
patch_interactive ? "--patch" : NULL,
pathspec);
}

static int edit_patch(int argc, const char **argv, const char *prefix)
{
char *file = xstrdup(git_path("ADD_EDIT.patch"));
Expand Down
2 changes: 2 additions & 0 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ int is_descendant_of(struct commit *, struct commit_list *);
int in_merge_bases(struct commit *, struct commit **, int);

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)
{
Expand Down

0 comments on commit 46b5139

Please sign in to comment.