From: Erik Faye-Lund <kusmabite@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Theo Niessink <theo@taletn.com>, Johannes Sixt <j6t@kdbg.org>,
git@vger.kernel.org, johannes.schindelin@gmx.de
Subject: Re: [PATCH 3/3] verify_path: consider dos drive prefix
Date: Tue, 7 Jun 2011 12:07:49 +0200 [thread overview]
Message-ID: <BANLkTi=eC37opWnN4nmC5AP66M+m5nZ86Q@mail.gmail.com> (raw)
In-Reply-To: <7v39jm8fs0.fsf@alter.siamese.dyndns.org>
On Tue, Jun 7, 2011 at 5:46 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Erik Faye-Lund <kusmabite@gmail.com> writes:
>
>>> Nitpick: If you already know that c != '\0' and !is_dir_sep(c), then why do
>>> continue? It will check for '\0' and is_dir_sep(c) again, but you already
>>> know that both ifs will be false. So you could just as easy jump straight to
>>> c = *path++, which IMHO also makes the code easier to follow:
>>
>> Very good point, thanks for noticing. I just rewrote the logic from
>> switch/case to if/else, but with the rewrite these redundant compares
>> became more obvious. I think your version is better, indeed.
>
> Let's not add an unnecessary goto while at it. How about this on top
> instead?
>
> read-cache.c | 13 +++----------
> 1 files changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 31cf0b5..3593291 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -784,16 +784,9 @@ int verify_path(const char *path)
> if (is_dir_sep(c)) {
> inside:
> c = *path++;
> - switch (c) {
> - default:
> - continue;
> - case '/': case '\0':
> - break;
> - case '.':
> - if (verify_dotfile(path))
> - continue;
> - }
> - return 0;
> + if ((c == '.' && !verify_dotfile(path)) ||
> + is_dir_sep(c) || c == '\0')
> + return 0;
> }
> c = *path++;
> }
This change the "c == '.' && verify_dotfile(path)"-case to eat the '.'
character without testing it against is_dir_sep, which is exactly what
we want. The other cases return 0, as they used to. Good.
Indeed, this is a cleaner approach. Thanks!
next prev parent reply other threads:[~2011-06-07 10:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-27 16:00 [PATCH maint 0/3] do not write files outside of work-dir Erik Faye-Lund
2011-05-27 16:00 ` [PATCH 1/3] A Windows path starting with a backslash is absolute Erik Faye-Lund
2011-05-27 16:00 ` [PATCH 2/3] real_path: do not assume '/' is the path seperator Erik Faye-Lund
2011-05-27 16:00 ` [PATCH 3/3] verify_path: consider dos drive prefix Erik Faye-Lund
2011-05-27 18:58 ` Johannes Sixt
2011-05-30 9:32 ` Erik Faye-Lund
2011-05-30 10:58 ` Theo Niessink
2011-05-30 11:17 ` Erik Faye-Lund
2011-06-07 3:46 ` Junio C Hamano
2011-06-07 10:07 ` Erik Faye-Lund [this message]
2011-06-07 19:09 ` Erik Faye-Lund
2011-06-07 19:22 ` Junio C Hamano
2011-06-07 19:32 ` Erik Faye-Lund
2011-06-07 11:46 ` Theo Niessink
2011-05-30 20:23 ` Johannes Sixt
2011-05-27 17:57 ` [PATCH maint 0/3] do not write files outside of work-dir Junio C Hamano
2011-05-27 18:09 ` Johannes Schindelin
2011-05-27 19:16 ` Junio C Hamano
2011-06-01 4:14 ` Tait
2011-06-01 6:31 ` Johannes Sixt
-- strict thread matches above, loose matches on Subject: below --
2011-06-08 9:55 [PATCH 3/3] verify_path: consider dos drive prefix Theo Niessink
2011-06-08 10:45 ` Erik Faye-Lund
2011-06-08 12:04 ` Theo Niessink
2011-06-08 12:15 ` Erik Faye-Lund
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='BANLkTi=eC37opWnN4nmC5AP66M+m5nZ86Q@mail.gmail.com' \
--to=kusmabite@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=johannes.schindelin@gmx.de \
--cc=theo@taletn.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.
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).