All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Ripton <dripton@ripton.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [RFC/PATCH] Add --exclude-dir option to git grep
Date: Fri, 24 Sep 2010 22:07:40 -0400	[thread overview]
Message-ID: <4C9D596C.4060906@ripton.net> (raw)
In-Reply-To: <7v1v8iq3tu.fsf@alter.siamese.dyndns.org>

On 09/24/10 16:33, Junio C Hamano wrote:

> Thanks.

Thank you for the code review.

> Do you need to run this every time we visit a new directory, expanding
> directory components over and over?
>
> It is not like we are jumping around directory hierarchies, visiting
> "foo/bar" and then "xyzzy" and then "foo/baz", but rather we visit
> directories in a nicer order (i.e. after leaving "foo/bar" but before
> jumping to "xyzzy", we would visit "foo/baz"), don't we?

I agree that there's room for optimization here.

>>   	if (max_depth<  0)
>>   		return 1;
>
> Isn't this original check much cheaper than the new test based on many
> comparisons and should be at the beginning of the function?

Yes.

>> @@ -826,6 +886,25 @@ static int help_callback(const struct option *opt, const char *arg, int unset)
>>   	return -1;
>>   }
>>
>> +static int exclude_dir_callback(const struct option *opt, const char *arg,
>> +				int unset)
>> +{
>> +	struct string_list *exclude_dir_list = opt->value;
>> +	char *s1 = (char *)arg;
>
> What is this cast for?

It avoids:

"builtin/grep.c:893: warning: initialization discards qualifiers from 
pointer target type"

>> +	/* We do not want leading or trailing slashes. */
>> +	while (*s1 == '/') {
>> +		s1++;
>> +	}
>
> Can the result of this loop become an empty string, and what happens to
> the rest of the logic when it happens?

If the string is just forward slashes, then it will become an empty 
string, which will strdup successfully, and then that particular 
--exclude-dir will have no effect.  Just tested that case and did not 
find a bug.

>> +	char *s2 = strdup(s1);
>
> decl-after-statement.

Oops.

Sadly, "gcc -Wall -std=c89" does not warn for this.  ("-pedantic" does.)

> Use xstrdup().

Okay.

>> +	while (*s2&&  s2[strlen(s2)-1] == '/') {
>> +		s2[strlen(s2)-1] = '\0';
>> +	}
>
> Don't scan s2 repeatedly to find its end by calling strlen(s2) on it.
> Find its length once, and scan backwards from there yourself.

Okay.  I'll try to send out a revised version of this patch soon.

-- 
David Ripton    dripton@ripton.net

  reply	other threads:[~2010-09-25  2:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-24  4:26 [RFC/PATCH] Add --exclude-dir option to git grep David Ripton
2010-09-24 20:33 ` Junio C Hamano
2010-09-25  2:07   ` David Ripton [this message]
2010-09-25  5:51     ` Junio C Hamano
2010-09-25 13:14       ` David Ripton
2010-09-25  3:35   ` David Ripton
2010-09-27  4: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=4C9D596C.4060906@ripton.net \
    --to=dripton@ripton.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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 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.