Re: [PATCH 1/9] tmp_objdir: add a helper function for discarding all contained objects
- From
Elijah Newren <newren@gmail.com>
- Date
- Dec 21, 2021, 23:51 UTC
- Message-ID
- <CABPp-BEuzorQkesgyNCvS05wsfqaH4Yv5JDFgy+AenrAC+JJNQ@mail.gmail.com>
- In-Reply-To
- <xmqqmtkto7yf.fsf@gitster.g>
On Tue, Dec 21, 2021 at 3:26 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 33 quoted lines
>
> "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Elijah Newren <newren@gmail.com>
> >
> > Signed-off-by: Elijah Newren <newren@gmail.com>
> > ---
> > tmp-objdir.c | 5 +++++
> > tmp-objdir.h | 6 ++++++
> > 2 files changed, 11 insertions(+)
> >
> > diff --git a/tmp-objdir.c b/tmp-objdir.c
> > index 3d38eeab66b..adf6033549e 100644
> > --- a/tmp-objdir.c
> > +++ b/tmp-objdir.c
> > @@ -79,6 +79,11 @@ static void remove_tmp_objdir_on_signal(int signo)
> > raise(signo);
> > }
> >
> > +void tmp_objdir_discard_objects(struct tmp_objdir *t)
> > +{
> > + remove_dir_recursively(&t->path, REMOVE_DIR_KEEP_TOPLEVEL);
> > +}
> > +
>
> OK.
>
> Without a caller, it is a bit hard to judge if a separate helper
> makes the caller easier to read and understand, or becomes an extra
> layer of abstraction that obscures the logic. Hopefully, having a
> more specific function name with "tmp" and "discard" in it makes the
> intent at callers more clear than the function that is named after
> the detail of the operation.This isn't just a convenience; since tmp_objdir is defined in tmp-objdir.c rather than tmp-objdir.h, t->path is not accessible outside of tmp-objdir.c. Because of this, some kind of helper function is necessary.