From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 11/12] diff.c: convert diff_scoreopt_parse to use skip_prefix()
Date: Wed, 18 Dec 2013 21:53:56 +0700 [thread overview]
Message-ID: <1387378437-20646-12-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1387378437-20646-1-git-send-email-pclouds@gmail.com>
While at there, partly fix the reporting as well. The reported value
with "arg+2" is only correct with -C/-B/-M, not with long option names.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
diff.c | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/diff.c b/diff.c
index 4da77fd..d629cc5 100644
--- a/diff.c
+++ b/diff.c
@@ -3367,7 +3367,7 @@ static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *va
return 1;
}
-static int diff_scoreopt_parse(const char *opt);
+static int diff_scoreopt_parse(const char **opt);
static inline int short_opt(char opt, const char **argv,
const char **optarg)
@@ -3627,13 +3627,13 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
/* renames options */
else if (starts_with(arg, "-B") || starts_with(arg, "--break-rewrites=") ||
!strcmp(arg, "--break-rewrites")) {
- if ((options->break_opt = diff_scoreopt_parse(arg)) == -1)
- return error("invalid argument to -B: %s", arg+2);
+ if ((options->break_opt = diff_scoreopt_parse(&arg)) == -1)
+ return error("invalid argument to -B: %s", arg);
}
else if (starts_with(arg, "-M") || starts_with(arg, "--find-renames=") ||
!strcmp(arg, "--find-renames")) {
- if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
- return error("invalid argument to -M: %s", arg+2);
+ if ((options->rename_score = diff_scoreopt_parse(&arg)) == -1)
+ return error("invalid argument to -M: %s", arg);
options->detect_rename = DIFF_DETECT_RENAME;
}
else if (!strcmp(arg, "-D") || !strcmp(arg, "--irreversible-delete")) {
@@ -3643,8 +3643,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
!strcmp(arg, "--find-copies")) {
if (options->detect_rename == DIFF_DETECT_COPY)
DIFF_OPT_SET(options, FIND_COPIES_HARDER);
- if ((options->rename_score = diff_scoreopt_parse(arg)) == -1)
- return error("invalid argument to -C: %s", arg+2);
+ if ((options->rename_score = diff_scoreopt_parse(&arg)) == -1)
+ return error("invalid argument to -C: %s", arg);
options->detect_rename = DIFF_DETECT_COPY;
}
else if (!strcmp(arg, "--no-renames"))
@@ -3879,29 +3879,29 @@ int parse_rename_score(const char **cp_p)
return (int)((num >= scale) ? MAX_SCORE : (MAX_SCORE * num / scale));
}
-static int diff_scoreopt_parse(const char *opt)
+static int diff_scoreopt_parse(const char **opt_p)
{
+ const char *opt = *opt_p;
int opt1, opt2, cmd;
if (*opt++ != '-')
return -1;
cmd = *opt++;
+ *opt_p = opt;
if (cmd == '-') {
/* convert the long-form arguments into short-form versions */
- if (starts_with(opt, "break-rewrites")) {
- opt += strlen("break-rewrites");
+ if ((opt = skip_prefix_defval(opt, "break-rewrites", *opt_p)) != *opt_p) {
if (*opt == 0 || *opt++ == '=')
cmd = 'B';
- } else if (starts_with(opt, "find-copies")) {
- opt += strlen("find-copies");
+ } else if ((opt = skip_prefix_defval(opt, "find-copies", *opt_p)) != *opt_p) {
if (*opt == 0 || *opt++ == '=')
cmd = 'C';
- } else if (starts_with(opt, "find-renames")) {
- opt += strlen("find-renames");
+ } else if ((opt = skip_prefix_defval(opt, "find-renames", *opt_p)) != *opt_p) {
if (*opt == 0 || *opt++ == '=')
cmd = 'M';
}
}
+ *opt_p = opt;
if (cmd != 'M' && cmd != 'C' && cmd != 'B')
return -1; /* that is not a -M, -C nor -B option */
--
1.8.5.1.208.g019362e
next prev parent reply other threads:[~2013-12-18 14:55 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-18 14:53 [PATCH 00/12] Hard coded string length cleanup Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 01/12] Make starts_with() a wrapper of skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 17:50 ` Junio C Hamano
2013-12-18 18:16 ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 02/12] Convert starts_with() to skip_prefix() for option parsing Nguyễn Thái Ngọc Duy
2013-12-20 6:51 ` Johannes Sixt
2013-12-20 7:04 ` Jeff King
2013-12-20 8:46 ` Christian Couder
2013-12-20 10:43 ` René Scharfe
2013-12-20 21:31 ` Junio C Hamano
2013-12-21 4:44 ` Duy Nguyen
2013-12-26 19:27 ` Junio C Hamano
2013-12-28 9:54 ` Jeff King
2013-12-18 14:53 ` [PATCH 03/12] Add and use skip_prefix_defval() Nguyễn Thái Ngọc Duy
2013-12-18 16:27 ` Kent R. Spillner
2013-12-18 17:51 ` Junio C Hamano
2013-12-18 14:53 ` [PATCH 04/12] Replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 05/12] Convert a lot of starts_with() to skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 06/12] fetch.c: replace some use of starts_with() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 07/12] connect.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 08/12] refs.c: " Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 09/12] diff.c: reduce code duplication in --stat-xxx parsing Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` [PATCH 10/12] environment.c: replace starts_with() in strip_namespace() with skip_prefix() Nguyễn Thái Ngọc Duy
2013-12-18 14:53 ` Nguyễn Thái Ngọc Duy [this message]
2013-12-18 14:53 ` [PATCH 12/12] refs.c: use skip_prefix() in prune_ref() Nguyễn Thái Ngọc Duy
2013-12-18 18:06 ` [PATCH 00/12] Hard coded string length cleanup Junio C Hamano
2013-12-19 23:32 ` René Scharfe
2013-12-19 23:50 ` Duy Nguyen
2013-12-20 1:06 ` René Scharfe
2013-12-20 2:29 ` Duy Nguyen
2013-12-20 16:53 ` 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=1387378437-20646-12-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.