From: "Rose via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Rose <83477269+AtariDreams@users.noreply.github.com>,
Seija Kijin <doremylover123@gmail.com>
Subject: [PATCH] diff: use strncmp to check for "diff." prefix
Date: Mon, 19 Dec 2022 16:33:43 +0000 [thread overview]
Message-ID: <pull.1403.git.git.1671467624143.gitgitgadget@gmail.com> (raw)
From: Seija Kijin <doremylover123@gmail.com>
This would be a lot more efficient than
checking for the full string, as
so many of the accepted values
begin with "diff."
This allows the computer to skip most checks
if var did not start with diff at all.
It would also let us add more "diff." strings
in the future without having to duplicate
these 5 character so many times.
Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
diff: use strncmp to check for "diff." prefix
This would be a lot more efficient than checking for the full string, as
so many of the accepted values begin with "diff."
This allows the computer to skip most checks if var did not start with
diff at all.
It would also let us add more "diff." strings in the future without
having to duplicate these 5 character so many times.
Signed-off-by: Seija Kijin doremylover123@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1403%2FAtariDreams%2Fdiff-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1403/AtariDreams/diff-v1
Pull-Request: https://github.com/git/git/pull/1403
diff.c | 158 +++++++++++++++++++++++++++++++--------------------------
1 file changed, 87 insertions(+), 71 deletions(-)
diff --git a/diff.c b/diff.c
index 4dfe824c858..e0fddbe6009 100644
--- a/diff.c
+++ b/diff.c
@@ -345,82 +345,98 @@ static unsigned parse_color_moved_ws(const char *arg)
int git_diff_ui_config(const char *var, const char *value, void *cb)
{
- if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
+ if (!strcmp(var, "color.diff")) {
diff_use_color_default = git_config_colorbool(var, value);
return 0;
}
- if (!strcmp(var, "diff.colormoved")) {
- int cm = parse_color_moved(value);
- if (cm < 0)
- return -1;
- diff_color_moved_default = cm;
- return 0;
- }
- if (!strcmp(var, "diff.colormovedws")) {
- unsigned cm = parse_color_moved_ws(value);
- if (cm & COLOR_MOVED_WS_ERROR)
- return -1;
- diff_color_moved_ws_default = cm;
- return 0;
- }
- if (!strcmp(var, "diff.context")) {
- diff_context_default = git_config_int(var, value);
- if (diff_context_default < 0)
- return -1;
- return 0;
- }
- if (!strcmp(var, "diff.interhunkcontext")) {
- diff_interhunk_context_default = git_config_int(var, value);
- if (diff_interhunk_context_default < 0)
- return -1;
- return 0;
- }
- if (!strcmp(var, "diff.renames")) {
- diff_detect_rename_default = git_config_rename(var, value);
- return 0;
- }
- if (!strcmp(var, "diff.autorefreshindex")) {
- diff_auto_refresh_index = git_config_bool(var, value);
- return 0;
- }
- if (!strcmp(var, "diff.mnemonicprefix")) {
- diff_mnemonic_prefix = git_config_bool(var, value);
- return 0;
- }
- if (!strcmp(var, "diff.noprefix")) {
- diff_no_prefix = git_config_bool(var, value);
- return 0;
- }
- if (!strcmp(var, "diff.relative")) {
- diff_relative = git_config_bool(var, value);
- return 0;
- }
- if (!strcmp(var, "diff.statgraphwidth")) {
- diff_stat_graph_width = git_config_int(var, value);
- return 0;
- }
- if (!strcmp(var, "diff.external"))
- return git_config_string(&external_diff_cmd_cfg, var, value);
- if (!strcmp(var, "diff.wordregex"))
- return git_config_string(&diff_word_regex_cfg, var, value);
- if (!strcmp(var, "diff.orderfile"))
- return git_config_pathname(&diff_order_file_cfg, var, value);
- if (!strcmp(var, "diff.ignoresubmodules"))
- handle_ignore_submodules_arg(&default_diff_options, value);
-
- if (!strcmp(var, "diff.submodule")) {
- if (parse_submodule_params(&default_diff_options, value))
- warning(_("Unknown value for 'diff.submodule' config variable: '%s'"),
- value);
- return 0;
- }
+ if (!strncmp(var, "diff.", 5)) {
+ const char *tmp = var + 5;
+ if (!strcmp(var, "color")) {
+ diff_use_color_default =
+ git_config_colorbool(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "colormoved")) {
+ int cm = parse_color_moved(value);
+ if (cm < 0)
+ return -1;
+ diff_color_moved_default = cm;
+ return 0;
+ }
+ if (!strcmp(tmp, "colormovedws")) {
+ unsigned cm = parse_color_moved_ws(value);
+ if (cm & COLOR_MOVED_WS_ERROR)
+ return -1;
+ diff_color_moved_ws_default = cm;
+ return 0;
+ }
+ if (!strcmp(tmp, "context")) {
+ diff_context_default = git_config_int(var, value);
+ if (diff_context_default < 0)
+ return -1;
+ return 0;
+ }
+ if (!strcmp(tmp, "interhunkcontext")) {
+ diff_interhunk_context_default =
+ git_config_int(var, value);
+ if (diff_interhunk_context_default < 0)
+ return -1;
+ return 0;
+ }
+ if (!strcmp(tmp, "renames")) {
+ diff_detect_rename_default =
+ git_config_rename(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "autorefreshindex")) {
+ diff_auto_refresh_index = git_config_bool(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "mnemonicprefix")) {
+ diff_mnemonic_prefix = git_config_bool(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "noprefix")) {
+ diff_no_prefix = git_config_bool(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "relative")) {
+ diff_relative = git_config_bool(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "statgraphwidth")) {
+ diff_stat_graph_width = git_config_int(var, value);
+ return 0;
+ }
+ if (!strcmp(tmp, "external"))
+ return git_config_string(&external_diff_cmd_cfg, var,
+ value);
+ if (!strcmp(tmp, "wordregex"))
+ return git_config_string(&diff_word_regex_cfg, var,
+ value);
+ if (!strcmp(tmp, "orderfile"))
+ return git_config_pathname(&diff_order_file_cfg, var,
+ value);
+
+ if (!strcmp(tmp, "ignoresubmodules"))
+ handle_ignore_submodules_arg(&default_diff_options,
+ value);
+
+ if (!strcmp(tmp, "submodule")) {
+ if (parse_submodule_params(&default_diff_options,
+ value))
+ warning(_("Unknown value for 'diff.submodule' config variable: '%s'"),
+ value);
+ return 0;
+ }
- if (!strcmp(var, "diff.algorithm")) {
- diff_algorithm = parse_algorithm_value(value);
- if (diff_algorithm < 0)
- return -1;
- return 0;
+ if (!strcmp(tmp, "algorithm")) {
+ diff_algorithm = parse_algorithm_value(value);
+ if (diff_algorithm < 0)
+ return -1;
+ return 0;
+ }
}
if (git_color_config(var, value, cb) < 0)
base-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7
--
gitgitgadget
next reply other threads:[~2022-12-19 16:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 16:33 Rose via GitGitGadget [this message]
2022-12-19 18:26 ` [PATCH] diff: use strncmp to check for "diff." prefix Ævar Arnfjörð Bjarmason
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=pull.1403.git.git.1671467624143.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=83477269+AtariDreams@users.noreply.github.com \
--cc=doremylover123@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox