From: Junio C Hamano Date: Wed, 08 Apr 2020 00:26:08 GMT Subject: Re: [PATCH v5 08/22] rebase: use read_oneliner() Message-ID: In-Reply-To: <0cc279fc14dd27ed2606064d236115aa72551dce.1586269543.git.liu.denton@gmail.com> Denton Liu writes: > Since in sequencer.c, read_one() basically duplicates the functionality > of read_oneliner(), reduce code duplication by replacing read_one() with > read_oneliner(). > > This was done with the following Coccinelle script > > @@ > expression a, b; > @@ > - read_one(a, b) > + !read_oneliner(b, a, READ_ONELINER_WARN_NON_EXISTENCE) WARN_MISSING, you mean? > -/* Read one file, then strip line endings */ > -static int read_one(const char *path, struct strbuf *buf) > -{ > - if (strbuf_read_file(buf, path, 0) < 0) > - return error_errno(_("could not read '%s'"), path); > - strbuf_trim_trailing_newline(buf); > - return 0; > -} > - OK. Both functions trim the end-of-line marker from the end of the string, so this is truly a no-op that reduces the code. Good.