From: Masahiro Yamada <masahiroy@kernel.org>
To: git@vger.kernel.org
Cc: Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH] dir: remove unneeded local variables from match_pathname()
Date: Fri, 10 Feb 2023 13:51:19 +0900 [thread overview]
Message-ID: <20230210045119.25190-1-masahiroy@kernel.org> (raw)
The local variables are unneeded - you can simply advance the 'pathname'
pointer.
IMHO, the variable 'name' is somewhat confusing. It is a relative path
to 'base', not a file name. It may contain slashes.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
dir.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/dir.c b/dir.c
index 4e99f0c868..06c6e7d79e 100644
--- a/dir.c
+++ b/dir.c
@@ -1251,9 +1251,6 @@ int match_pathname(const char *pathname, int pathlen,
const char *base, int baselen,
const char *pattern, int prefix, int patternlen)
{
- const char *name;
- int namelen;
-
/*
* match with FNM_PATHNAME; the pattern has base implicitly
* in front of it.
@@ -1273,35 +1270,37 @@ int match_pathname(const char *pathname, int pathlen,
fspathncmp(pathname, base, baselen))
return 0;
- namelen = baselen ? pathlen - baselen - 1 : pathlen;
- name = pathname + pathlen - namelen;
+ if (baselen > 0) {
+ pathname += baselen + 1;
+ pathlen -= baselen + 1;
+ }
if (prefix) {
/*
* if the non-wildcard part is longer than the
* remaining pathname, surely it cannot match.
*/
- if (prefix > namelen)
+ if (prefix > pathlen)
return 0;
- if (fspathncmp(pattern, name, prefix))
+ if (fspathncmp(pattern, pathname, prefix))
return 0;
pattern += prefix;
patternlen -= prefix;
- name += prefix;
- namelen -= prefix;
+ pathname += prefix;
+ pathlen -= prefix;
/*
* If the whole pattern did not have a wildcard,
* then our prefix match is all we need; we
* do not need to call fnmatch at all.
*/
- if (!patternlen && !namelen)
+ if (!patternlen && !pathlen)
return 1;
}
return fnmatch_icase_mem(pattern, patternlen,
- name, namelen,
+ pathname, pathlen,
WM_PATHNAME) == 0;
}
--
2.34.1
next reply other threads:[~2023-02-10 4:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 4:51 Masahiro Yamada [this message]
2023-02-10 21:51 ` [PATCH] dir: remove unneeded local variables from match_pathname() 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
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=20230210045119.25190-1-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--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.
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).