git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/4] apply: remove the_repository global variable

From
John Cai <johncai86@gmail.com>
Date
Sep 26, 2024, 18:59 UTC
Message-ID
<CAOCgCU+hv07+FCupr2Ok9LJm6HYT6n6t+ZpifAhwrRnMzOnnWA@mail.gmail.com>
In-Reply-To
<xmqq7cb0ucm0.fsf@gitster.g>
Hi Junio,
On Tue, Sep 24, 2024 at 2:32 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 48 quoted lines
>
> "John Cai via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: John Cai <johncai86@gmail.com>
> >
> > Remove the_repository global variable in favor of the repository
> > argument that gets passed in through the builtin function.
> >
> > Signed-off-by: John Cai <johncai86@gmail.com>
> > ---
> >  builtin/apply.c | 9 ++++-----
> >  1 file changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/builtin/apply.c b/builtin/apply.c
> > index 84f1863d3ac..d0bafbec7e4 100644
> > --- a/builtin/apply.c
> > +++ b/builtin/apply.c
> > @@ -1,4 +1,3 @@
> > -#define USE_THE_REPOSITORY_VARIABLE
> >  #include "builtin.h"
> >  #include "gettext.h"
> >  #include "hash.h"
> > @@ -12,14 +11,14 @@ static const char * const apply_usage[] = {
> >  int cmd_apply(int argc,
> >             const char **argv,
> >             const char *prefix,
> > -           struct repository *repo UNUSED)
> > +           struct repository *repo)
> >  {
> >       int force_apply = 0;
> >       int options = 0;
> >       int ret;
> >       struct apply_state state;
> >
> > -     if (init_apply_state(&state, the_repository, prefix))
> > +     if (init_apply_state(&state, repo, prefix))
> >               exit(128);
>
> Hmph, the reason why we do not segfault with this patch is because
> repo will _always_ be the_repository due to the previous change.
>
> I am not sure if [1/4] is an improvement, though.  We used to be
> able to tell if we were running in a repository, or we were running
> in "nongit" mode, by looking at the NULL-ness of repo (which was
> UNUSED because we weren't taking advantage of that).
>
> With [1/4], it no longer is possible.  From the point of view of API
> to call into builtin implementations, it smells like a regression.

I see your point here. However, I was wondering about this because we are passing in the_repository through run_builtin() as repo--so wouldn't this be equivalent to using the_repository and hence the same API contract can remain that looks at the NULL-ness of repo?

But I could be missing something here.

thanks! John

Show 14 quoted lines
>
> A more honest change for this hunk would rather be something like:
>
>         -       if (init_apply_state(&state, the_repository, prefix))
>         +       if (!repo)
>         +               repo = the_repository;
>         +       if (init_apply_state(&state, repo, prefix))
>
> without [1/4].  This change does not address "apply still depends on
> having access to the_repository even when it is being used as a better
> GNU patch" issue at all.
>
> So, no, while I earlier said I was happy with [1/4], I no longer am
> enthused by the change.
Previous: Junio C HamanoNext: Junio C Hamano
Message 12 of 44 in “Remove the_repository global for am, annotate, apply, archive builtins”
  1. 0/4 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Sep 24, 2024
  2. 1/4 git: pass in repo for RUN_SETUP_GENTLYJohn Cai via GitGitGadget, Sep 24, 2024
  3. shejialuoSep 24, 2024
  4. Junio C HamanoSep 24, 2024
  5. Junio C HamanoSep 24, 2024
  6. Patrick SteinhardtSep 26, 2024
  7. Junio C HamanoSep 26, 2024
  8. 2/4 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Sep 24, 2024
  9. 3/4 apply: remove the_repository global variableJohn Cai via GitGitGadget, Sep 24, 2024
  10. Junio C HamanoSep 24, 2024
  11. Junio C HamanoSep 24, 2024
  12. John CaiSep 26, 2024
  13. Junio C HamanoSep 26, 2024
  14. 4/4 archive: remove the_repository global variableJohn Cai via GitGitGadget, Sep 24, 2024
  15. Junio C HamanoSep 24, 2024
  16. 0/4 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Sep 30, 2024
  17. 1/4 git: pass in repo for RUN_SETUP_GENTLYJohn Cai via GitGitGadget, Sep 30, 2024
  18. Junio C HamanoSep 30, 2024
  19. shejialuoOct 1, 2024
  20. 2/4 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Sep 30, 2024
  21. Junio C HamanoSep 30, 2024
  22. 4/4 archive: remove the_repository global variableJohn Cai via GitGitGadget, Sep 30, 2024
  23. Junio C HamanoSep 30, 2024
  24. johncai86@gmail.comOct 4, 2024
  25. 3/4 apply: remove the_repository global variableJohn Cai via GitGitGadget, Sep 30, 2024
  26. Junio C HamanoSep 30, 2024
  27. shejialuoOct 1, 2024
  28. Patrick SteinhardtOct 1, 2024
  29. shejialuoOct 1, 2024
  30. Patrick SteinhardtOct 1, 2024
  31. Junio C HamanoOct 1, 2024
  32. johncai86@gmail.comOct 3, 2024
  33. 0/3 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Oct 5, 2024
  34. 1/3 git: pass in repo to builtin based on setup_git_directory_gentlyJohn Cai via GitGitGadget, Oct 5, 2024
  35. shejialuoOct 5, 2024
  36. 2/3 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Oct 5, 2024
  37. 3/3 archive: remove the_repository global variableJohn Cai via GitGitGadget, Oct 5, 2024
  38. shejialuoOct 5, 2024
  39. johncai86@gmail.comOct 10, 2024
  40. 0/3 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Oct 10, 2024
  41. 1/3 git: pass in repo to builtin based on setup_git_directory_gentlyJohn Cai via GitGitGadget, Oct 10, 2024
  42. 2/3 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Oct 10, 2024
  43. 3/3 archive: remove the_repository global variableJohn Cai via GitGitGadget, Oct 10, 2024
  44. Junio C HamanoOct 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.