From: Junio C Hamano <gitster@pobox•com>
To: David Turner <dturner@twopensource•com>
Cc: Michael Haggerty <mhagger@alum•mit.edu>,
git@vger•kernel.org, David Turner <dturner@twitter•com>
Subject: Re: [PATCH v5 1/2] refs.c: optimize check_refname_component()
Date: Tue, 03 Jun 2014 11:08:24 -0700 [thread overview]
Message-ID: <xmqqzjhtx3vr.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1401690015-19191-1-git-send-email-dturner@twitter.com> (David Turner's message of "Mon, 2 Jun 2014 02:20:14 -0400")
David Turner <dturner@twopensource•com> writes:
> static int check_refname_component(const char *refname, int flags)
> {
> const char *cp;
> char last = '\0';
>
> for (cp = refname; ; cp++) {
> - char ch = *cp;
> - if (ch == '\0' || ch == '/')
> + unsigned char ch = (unsigned char) *cp;
Hmph, this cast bothers me. I am fine with either of these two, though.
int ch = *cp & 0377;
unsigned char ch = *((unsigned char *)cp);
> + unsigned char disp = refname_disposition[ch];
> + switch(disp) {
> + case 1:
> + goto out;
> + case 2:
> + if (last == '.')
> + return -1; /* Refname contains "..". */
> + break;
> + case 3:
> + if (last == '@')
> + return -1; /* Refname contains "@{". */
> break;
> - if (bad_ref_char(ch))
> - return -1; /* Illegal character in refname. */
> - if (last == '.' && ch == '.')
> - return -1; /* Refname contains "..". */
> - if (last == '@' && ch == '{')
> - return -1; /* Refname contains "@{". */
> + case 4:
> + return -1;
> + }
> last = ch;
> }
> +out:
> if (cp == refname)
> return 0; /* Component has zero length. */
> if (refname[0] == '.') {
> diff --git a/t/t5511-refspec.sh b/t/t5511-refspec.sh
> index c289322..1571176 100755
> --- a/t/t5511-refspec.sh
> +++ b/t/t5511-refspec.sh
> @@ -5,7 +5,6 @@ test_description='refspec parsing'
> . ./test-lib.sh
>
> test_refspec () {
> -
> kind=$1 refspec=$2 expect=$3
> git config remote.frotz.url "." &&
> git config --remove-section remote.frotz &&
> @@ -84,4 +83,9 @@ test_refspec push 'refs/heads/*/*/for-linus:refs/remotes/mine/*' invalid
> test_refspec fetch 'refs/heads/*/for-linus:refs/remotes/mine/*'
> test_refspec push 'refs/heads/*/for-linus:refs/remotes/mine/*'
>
> +good=$(echo -n '\0377')
I think we avoid "echo -n" and use "printf" to be portable across
different echo implementations.
Use of \0377, which most likely to be just half-a-character, does
not feel a particularly good example, by the way.
> +test_refspec fetch "refs/heads/${good}"
> +bad=$(echo -n '\011')
Likewise.
> +test_refspec fetch "refs/heads/${bad}" invalid
> +
> test_done
next prev parent reply other threads:[~2014-06-03 18:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-02 6:20 [PATCH v5 1/2] refs.c: optimize check_refname_component() David Turner
2014-06-02 6:20 ` [PATCH v5 2/2] refs.c: SSE4.2 optimizations for check_refname_component David Turner
2014-06-03 22:05 ` Junio C Hamano
2014-06-04 3:35 ` David Turner
2014-06-03 18:08 ` Junio C Hamano [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-06-03 18:21 [PATCH v5 1/2] refs.c: optimize check_refname_component() David Turner
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=xmqqzjhtx3vr.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=dturner@twitter$(echo .)com \
--cc=dturner@twopensource$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=mhagger@alum$(echo .)mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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