aboutsummaryrefslogtreecommitdiff
path: root/builtin-add.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-09-07 15:24:38 -0700
committerJunio C Hamano <gitster@pobox.com>2009-09-07 15:24:38 -0700
commit54f0bdc81103f45f12978b385a9519a235b03cc2 (patch)
treeee239eeafe0f59af72eca683e5e264b0c2a6fff5 /builtin-add.c
parent8e4384fd4438a143af7125eb0f03312a318319fb (diff)
parent3c2eb80fe3f3c7efbb25e929df9f70d7c896a5ef (diff)
downloadgit-54f0bdc81103f45f12978b385a9519a235b03cc2.tar.gz
git-54f0bdc81103f45f12978b385a9519a235b03cc2.tar.xz
Merge branch 'tr/reset-checkout-patch'
* tr/reset-checkout-patch: stash: simplify defaulting to "save" and reject unknown options Make test case number unique tests: disable interactive hunk selection tests if perl is not available DWIM 'git stash save -p' for 'git stash -p' Implement 'git stash save --patch' Implement 'git checkout --patch' Implement 'git reset --patch' builtin-add: refactor the meat of interactive_add() Add a small patch-mode testing library git-apply--interactive: Refactor patch mode code Make 'git stash -k' a short form for 'git stash save --keep-index'
Diffstat (limited to 'builtin-add.c')
-rw-r--r--builtin-add.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/builtin-add.c b/builtin-add.c
index 006fd0876..a5714735e 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -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;
@@ -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"));