From: Phillip Wood Date: Fri, 18 Oct 2019 09:04:46 GMT Subject: Re: [RFC PATCH 2/7] autostash: extract read_one() from rebase Message-ID: <49b1ed2e-b1b9-b593-2657-e59f61925e20@gmail.com> In-Reply-To: Hi Denton On 16/10/2019 18:26, Denton Liu wrote: > Begin the process of lib-ifying the autostash code. In a future commit, > this will be used to implement `--autostash` in other builtins. > > This patch is best viewed with `--color-moved` and > `--color-moved-ws=allow-indentation-change`. > > Signed-off-by: Denton Liu > --- > autostash.c | 12 ++++++++++++ > autostash.h | 9 +++++++++ > builtin/rebase.c | 10 +--------- > 3 files changed, 22 insertions(+), 9 deletions(-) > create mode 100644 autostash.c > create mode 100644 autostash.h > > diff --git a/autostash.c b/autostash.c > new file mode 100644 > index 0000000000..a6898e0fda > --- /dev/null > +++ b/autostash.c > @@ -0,0 +1,12 @@ > +#include "git-compat-util.h" > +#include "autostash.h" > +#include "gettext.h" > +#include "strbuf.h" > + > +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; > +} This looks like it's doing a similar job to read_oneliner() in sequencer.c, is it possible to make that public and use it instead? (There may be a difference if the file is missing but that function already takes a flag so it could probably be modified easily enough.) Best Wishes Phillip > diff --git a/autostash.h b/autostash.h > new file mode 100644 > index 0000000000..4a8f504f12 > --- /dev/null > +++ b/autostash.h > @@ -0,0 +1,9 @@ > +#ifndef AUTOSTASH_H > +#define AUTOSTASH_H > + > +#include "strbuf.h" > + > +/* Read one file, then strip line endings */ > +int read_one(const char *path, struct strbuf *buf); > + > +#endif > diff --git a/builtin/rebase.c b/builtin/rebase.c > index 4a20582e72..9fd7de6b2f 100644 > --- a/builtin/rebase.c > +++ b/builtin/rebase.c > @@ -27,6 +27,7 @@ > #include "branch.h" > #include "sequencer.h" > #include "rebase-interactive.h" > +#include "autostash.h" > > static char const * const builtin_rebase_usage[] = { > N_("git rebase [-i] [options] [--exec ] " > @@ -561,15 +562,6 @@ static const char *state_dir_path(const char *filename, struct rebase_options *o > return path.buf; > } > > -/* 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; > -} > - > /* Initialize the rebase options from the state directory. */ > static int read_basic_state(struct rebase_options *opts) > { >