From: Wincent Colaiuta <win@wincent.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, peff@peff.net, Wincent Colaiuta <win@wincent.com>
Subject: [PATCH 7/7] Teach builtin-add to handle "--patch" option
Date: Fri, 23 Nov 2007 20:20:50 +0100 [thread overview]
Message-ID: <1195845650-85962-8-git-send-email-win@wincent.com> (raw)
In-Reply-To: <1195845650-85962-7-git-send-email-win@wincent.com>
Now builtin-add can take a "--patch" option; when found, it passes control
over to git-add--interactive, passing the --patch switch and the supplied
pathspecs.
Signed-off-by: Wincent Colaiuta <win@wincent.com>
---
Documentation/git-add.txt | 5 +++++
builtin-add.c | 13 ++++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt
index 0b0ab1d..1acf10f 100644
--- a/Documentation/git-add.txt
+++ b/Documentation/git-add.txt
@@ -65,6 +65,11 @@ OPTIONS
operation to a subset of the files in the working tree.
See ``Interactive mode'' for details.
+-p, \--patch:
+ Similar to Interactive mode but the initial command loop is
+ bypassed and the 'patch' subcommand is invoked using each of
+ the specified filepatterns before exiting.
+
-u::
Update only files that git already knows about. This is similar
to what "git commit -a" does in preparation for making a commit,
diff --git a/builtin-add.c b/builtin-add.c
index 3646a45..c8335f1 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -19,6 +19,7 @@ static const char * const builtin_add_usage[] = {
"git-add [options] [--] <filepattern>...",
NULL
};
+static int patch_interactive = 0, add_interactive = 0;
static int take_worktree_changes;
@@ -138,10 +139,12 @@ static void refresh(int verbose, const char **pathspec)
int interactive_add(int argc, const char **argv)
{
int status;
- const char **args = xmalloc(sizeof(const char *) * (argc + 1));
+ int pre_argc = patch_interactive ? 2 : 1;
+ const char **args = xmalloc(sizeof(const char *) * (argc + pre_argc + 1));
args[0] = "add--interactive";
- memcpy((void *)args + sizeof(const char *), argv, sizeof(const char *) * argc);
- args[argc + 1] = NULL;
+ args[1] = "--patch";
+ memcpy((void *)args + sizeof(const char *) * pre_argc, argv, sizeof(const char *) * argc);
+ args[argc + pre_argc] = NULL;
status = run_command_v_opt(args, RUN_GIT_CMD);
free(args);
@@ -154,13 +157,13 @@ static const char ignore_error[] =
"The following paths are ignored by one of your .gitignore files:\n";
static int verbose = 0, show_only = 0, ignored_too = 0, refresh_only = 0;
-static int add_interactive = 0;
static struct option builtin_add_options[] = {
OPT__DRY_RUN(&show_only),
OPT__VERBOSE(&verbose),
OPT_GROUP(""),
OPT_BOOLEAN('i', "interactive", &add_interactive, "interactive picking"),
+ OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"),
OPT_BOOLEAN('f', NULL, &ignored_too, "allow adding otherwise ignored files"),
OPT_BOOLEAN('u', NULL, &take_worktree_changes, "update tracked files"),
OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"),
@@ -175,7 +178,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, builtin_add_options,
builtin_add_usage, 0);
- if (add_interactive)
+ if (add_interactive || patch_interactive)
exit(interactive_add(argc, argv));
git_config(git_default_config);
--
1.5.3.6.886.g3364
next prev parent reply other threads:[~2007-11-23 19:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-23 19:20 [PATCH v2] git-add--interactive pathspec and patch additions Wincent Colaiuta
2007-11-23 19:20 ` [PATCH 1/7] Add -q/--quiet switch to git-ls-files Wincent Colaiuta
2007-11-23 19:20 ` [PATCH 2/7] Rename patch_update_file function to patch_update_pathspec Wincent Colaiuta
2007-11-23 19:20 ` [PATCH 3/7] Add path-limiting to git-add--interactive Wincent Colaiuta
2007-11-23 19:20 ` [PATCH 4/7] Bail if user supplies an invalid pathspec Wincent Colaiuta
2007-11-23 19:20 ` [PATCH 5/7] Teach builtin-add to pass path arguments to git-add--interactive Wincent Colaiuta
2007-11-23 19:20 ` [PATCH 6/7] Add "--patch" option " Wincent Colaiuta
2007-11-23 19:20 ` Wincent Colaiuta [this message]
2007-11-23 19:25 ` [PATCH 1/7] Add -q/--quiet switch to git-ls-files Wincent Colaiuta
2007-11-23 21:07 ` [PATCH v2] git-add--interactive pathspec and patch additions Junio C Hamano
2007-11-23 22:20 ` Wincent Colaiuta
2007-11-24 12:55 ` [PATCH 0/3] Updates to git-add--interactive Wincent Colaiuta
2007-11-24 12:55 ` [PATCH 1/3] Rename patch_update_file function to patch_update_pathspec Wincent Colaiuta
2007-11-24 12:55 ` [PATCH 2/3] Move pathspec validation into interactive_add Wincent Colaiuta
2007-11-24 12:55 ` [PATCH 3/3] Add "--patch" option to git-add--interactive Wincent Colaiuta
2007-11-24 19:15 ` [PATCH 2/3] Move pathspec validation into interactive_add Junio C Hamano
2007-11-24 21:50 ` Wincent Colaiuta
2007-11-24 22:34 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1195845650-85962-8-git-send-email-win@wincent.com \
--to=win@wincent.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).