git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/5] Use the matching function to generate the match results

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Mar 6, 2009, 17:21 UTC
Message-ID
<alpine.LNX.1.00.0903061151130.19665@iabervon.org>
In-Reply-To
<7vy6vjt679.fsf@gitster.siamese.dyndns.org>
On Fri, 6 Mar 2009, Junio C Hamano wrote:
Show 10 quoted lines
> 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().

I'll just make it "match_name_with_pattern" from the beginning, which describes what it does whether or not the later arguments are NULL.

Show 31 quoted lines
> > -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?

Probably. I suspect that we're making sure to have room for the '\0's at the end of both the base and the part that matches the star. Looks like it's still how Alex Riesen wrote it, sort of arbitrarily one byte longer than the similar allocation.

	-Daniel
*This .sig left intentionally blank*
Previous: Junio C HamanoNext: Daniel Barkalow
Message 3 of 4 in “Use the matching function to generate the match results”
  1. 3/5 Use the matching function to generate the match resultsDaniel Barkalow, Mar 6, 2009
  2. Junio C HamanoMar 6, 2009
  3. Daniel BarkalowMar 6, 2009
  4. 3/5 Use the matching function to generate the match resultsDaniel Barkalow, Mar 7, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.