Re: [PATCH v3 14/25] setup.c: convert is_git_directory() to use strbuf
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Feb 19, 2014, 20:17 UTC
- Message-ID
- <xmqqppmi97s3.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1392730814-19656-15-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> > ---
(Only minor nits first during this round of review)
Show 9 quoted lines
> diff --git a/strbuf.h b/strbuf.h
> index 73e80ce..aec9fdb 100644
> --- a/strbuf.h
> +++ b/strbuf.h
> @@ -116,6 +116,10 @@ extern void strbuf_add(struct strbuf *, const void *, size_t);
> static inline void strbuf_addstr(struct strbuf *sb, const char *s) {
> strbuf_add(sb, s, strlen(s));
> }
> +static inline void strbuf_addstr_at(struct strbuf *sb, size_t len, const char *s) {Please have the opening "{" on its own line.Surrounding existing functions are all offenders, but that is not an excuse to make it worse (cleaning them up will need to be done in a separate patch).
> + strbuf_setlen(sb, len); > + strbuf_add(sb, s, strlen(s));
I am not sure addstr_at() gives us a good abstraction, or at least the name conveys what it does well not to confuse readers.
At first after only seeing its name, I would have expected that it would splice the given string into an existing strbuf at the location, not chopping the existing strbuf at the location and appending.
> +}
> static inline void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2) {
> strbuf_grow(sb, sb2->len);
> strbuf_add(sb, sb2->buf, sb2->len);