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

Re: [PATCH] Make git-fmt-merge-msg a builtin

From
THTimo Hirvonen <tihirvon@gmail.com>
Date
Jul 3, 2006, 14:17 UTC
Message-ID
<20060703171751.2ed33220.tihirvon@gmail.com>
In-Reply-To
<Pine.LNX.4.63.0607031530380.29667@wbgn013.biozentrum.uni-wuerzburg.de>
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
Show 5 quoted lines
> +struct list {
> +	char **list;
> +	void **payload;
> +	unsigned nr, alloc;
> +};

How about something like this instead to reduce mallocs to half and simplify the code?

struct item {
	char *value;
	void *payload;
};
struct list {
	struct item *items;
	unsigned int nr, alloc;
};
(But I realize this isn't performance critical)
> +static void append_to_list(struct list *list, char *value)
Add void *payload parameter too, would simplify the code.
Show 6 quoted lines
> +static void free_list(struct list *list)
> +{
> +	int i;
> +
> +	if (list->alloc == 0)
> +		return;
Unnecessary if nr is 0 too.
> +	for (i = 0; i < list->nr; i++) {
> +		free(list->list[i]);
> +		if (list->payload[i])
> +			free(list->payload[i]);
free(NULL) is safe.
Show 5 quoted lines
> +	}
> +	free(list->list);
> +	free(list->payload);
> +	list->nr = list->alloc = 0;
> +}
> +	if (!strncmp(line, "branch ", 7)) {
> +		origin = strdup(line + 7);
> +		append_to_list(&(src_data->branch), origin);
Parenthesis isn't needed.
> +	head->object.flags |= UNINTERESTING;
> +        prepare_revision_walk(rev);
Spaces..
Show 7 quoted lines
> +	if (merge_summary) {
> +		struct commit *head;
> +		struct rev_info rev;
> +
> +		head = lookup_commit(head_sha1);
> +parse_object(head->object.sha1);
> +head = head->parents->item;
Indentation.
-- 
http://onion.dynserv.net/~timo/
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 2 of 7 in “Make git-fmt-merge-msg a builtin”
  1. Make git-fmt-merge-msg a builtinJohannes Schindelin, Jul 3, 2006
  2. Timo HirvonenJul 3, 2006
  3. Johannes SchindelinJul 3, 2006
  4. Timo HirvonenJul 3, 2006
  5. Johannes SchindelinJul 3, 2006
  6. Timo HirvonenJul 3, 2006
  7. Johannes SchindelinJul 3, 2006

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.