Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Daniel Barkalow <barkalow@iabervon.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/5] Use the matching function to generate the match results
Date: Fri, 06 Mar 2009 00:18:34 -0800	[thread overview]
Message-ID: <7vy6vjt679.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: alpine.LNX.1.00.0903052355240.19665@iabervon.org

Daniel Barkalow <barkalow@iabervon.org> writes:

> This puts all of the interpretation of the pattern representation in a
> single function for easy manipulation.
>
> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>

I think this makes sense, but the helper function is not about "does this
name match the pattern?" boolean anymore, and may want to be renamed to
e.g. map_name_with_pattern().

> -static int name_fits_pattern(const char *key, const char *name)
> +static int name_fits_pattern(const char *key, const char *name,
> +			     const char *value, char **result)
>  {
> -	int ret = !prefixcmp(key, name);
> +	size_t klen = strlen(key);
> +	int ret = !strncmp(key, name, klen);
> +	if (ret && value) {
> +		size_t vlen = strlen(value);
> +		*result = xmalloc(vlen +
> +				  strlen(name) -
> +				  klen + 1);
> +		strcpy(*result, value);
> +		strcpy(*result + vlen, name + klen);
> +	}

> @@ -1080,11 +1085,9 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
>  
>  		} else {
>  			const char *dst_side = pat->dst ? pat->dst : pat->src;
> -			dst_name = xmalloc(strlen(dst_side) +
> -					   strlen(src->name) -
> -					   strlen(pat->src) + 2);
> -			strcpy(dst_name, dst_side);
> -			strcat(dst_name, src->name + strlen(pat->src));
> +			if (!name_fits_pattern(pat->src, src->name,
> +					       dst_side, &dst_name))
> +				die("Didn't think it matches any more");
>  		}

Hmm, we have been overallocating and nobody noticed so far?

  reply	other threads:[~2009-03-06  8:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-06  4:56 [PATCH 3/5] Use the matching function to generate the match results Daniel Barkalow
2009-03-06  8:18 ` Junio C Hamano [this message]
2009-03-06 17:21   ` Daniel Barkalow
2009-03-07  6:11 ` [PATCH v2 " Daniel Barkalow

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=7vy6vjt679.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=barkalow@iabervon.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox