Re: [PATCH] add post-fetch hook
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Dec 27, 2011, 21:27 UTC
- Message-ID
- <4EFA3833.80409@kdbg.org>
- In-Reply-To
- <20111226023154.GA3243@gnu.kitenet.net>
Am 26.12.2011 03:31, schrieb Joey Hess:
> +int feed_post_fetch_hook (int in, int out, void *data)
> +{
> + struct ref *ref;
> + struct strbuf buf = STRBUF_INIT;Is there a particular reason that you accumulate everything in a buffer?
If I read the loop below correctly, you should be able to run it using only the functions sha1_to_hex(), strlen() and write_in_full(). This would avoid any problems with concurrent calls to xmalloc().
> + int ret;
> +
> + for (ref = post_fetch_hook_refs; ref; ref = ref->next) {
> + strbuf_addstr(&buf, sha1_to_hex(ref->old_sha1));sha1_to_hex() works with a static buffer. Are you certain that it is not called concurrently in the main thread?
Show 10 quoted lines
> + strbuf_addch(&buf, ' '); > + strbuf_addstr(&buf, ref->merge ? "merge" : "not-for-merge"); > + strbuf_addch(&buf, ' '); > + if (ref->name) > + strbuf_addstr(&buf, ref->name); > + strbuf_addch(&buf, ' '); > + if (ref->peer_ref && ref->peer_ref->name) > + strbuf_addstr(&buf, ref->peer_ref->name); > + strbuf_addch(&buf, '\n'); > + }
-- Hannes