From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Daniel Ferreira" <bnmvco@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>,
"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH 2/3] add--interactive: add builtin helper for interactive add
Date: Fri, 5 May 2017 20:16:21 +0000 [thread overview]
Message-ID: <20170505201621.25560-1-avarab@gmail.com> (raw)
In-Reply-To: <1494009820-2090-3-git-send-email-bnmvco@gmail.com>
On Fri, May 5, 2017 at 8:43 PM, Daniel Ferreira <bnmvco@gmail.com> wrote:
> Create a builtin helper for git-add--interactive, which right now is
> only able to reproduce git-add--interactive.perl's status_cmd()
> function, providing a summarized diff numstat to the user.
I'm not a user of add -i and didn't review the main logic in detail,
but I ran this, and aside from two issues this LGTM:
* You missed a trailing \n in the output, so your formatting is
different from the current behavior.
* You should be using the getopt API instead of rolling your own.
Fixes for both below, thanks a lot for hacking on this. As you pointed
out this doesn't help with removing any of the perl code for now, but
after replacing a few more command modes we can start chopping away at
the perl code.
diff --git a/builtin/add-interactive--helper.c b/builtin/add-interactive--helper.c
index 97ca1b38dc..ea0f790bd3 100644
--- a/builtin/add-interactive--helper.c
+++ b/builtin/add-interactive--helper.c
@@ -226,6 +226,7 @@ static void print_modified(void)
printf(modified_fmt, index_changes, worktree_changes, f.path);
printf("\n");
}
+ printf("\n");
}
static void status_cmd(void)
@@ -233,26 +234,31 @@ static void status_cmd(void)
print_modified();
}
-static const char add_interactive_helper_usage[] =
-"git add-interactive--helper <command>";
+static const char * const builtin_add_interactive_helper_usage[] = {
+ N_("git add-interactive--helper <command>"),
+ NULL
+};
int cmd_add_interactive__helper(int argc, const char **argv, const char *prefix)
{
- int i, found_opt = 0;
-
- git_config(git_add_interactive_config, NULL);
+ int opt_status = 0;
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
+ struct option options[] = {
+ OPT_BOOL(0, "status", &opt_status,
+ N_("print status information with diffstat")),
+ OPT_END()
+ };
- if (!strcmp(arg, "--status")) {
- status_cmd();
- found_opt = 1;
- }
- }
-
- if (!found_opt)
- usage(add_interactive_helper_usage);
+ git_config(git_add_interactive_config, NULL);
+ argc = parse_options(argc, argv, NULL, options,
+ builtin_add_interactive_helper_usage,
+ PARSE_OPT_KEEP_ARGV0);
+
+ if (opt_status)
+ status_cmd();
+ else
+ usage_with_options(builtin_add_interactive_helper_usage,
+ options);
return 0;
}
--
2.11.0
next prev parent reply other threads:[~2017-05-05 20:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-05 18:43 [PATCH 0/3] Port git-add--interactive.perl:status_cmd to C Daniel Ferreira
2017-05-05 18:43 ` [PATCH 1/3] diff: export diffstat interface Daniel Ferreira
2017-05-05 21:28 ` Johannes Schindelin
2017-05-05 18:43 ` [PATCH 2/3] add--interactive: add builtin helper for interactive add Daniel Ferreira
2017-05-05 20:16 ` Ævar Arnfjörð Bjarmason [this message]
2017-05-05 21:21 ` Johannes Schindelin
2017-05-05 22:09 ` Ævar Arnfjörð Bjarmason
2017-05-05 22:30 ` Johannes Schindelin
2017-05-05 22:49 ` Ævar Arnfjörð Bjarmason
2017-05-08 11:35 ` Johannes Schindelin
2017-05-05 23:13 ` Daniel Ferreira (theiostream)
2017-05-05 23:28 ` Ævar Arnfjörð Bjarmason
2017-05-08 12:15 ` Johannes Schindelin
2017-05-05 18:43 ` [PATCH 3/3] add--interactive: use add-interactive--helper for status_cmd Daniel Ferreira
2017-05-05 22:32 ` Johannes Schindelin
2017-05-05 19:31 ` [PATCH 0/3] Port git-add--interactive.perl:status_cmd to C Ævar Arnfjörð Bjarmason
2017-05-05 22:33 ` Johannes Schindelin
2017-05-05 22:35 ` Jonathan Nieder
2017-05-05 22:38 ` Johannes Schindelin
2017-05-05 23:37 ` Daniel Ferreira (theiostream)
2017-05-08 12:23 ` Johannes Schindelin
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170505201621.25560-1-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=bnmvco@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).