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

Re: [PATCH 1/3] builtin: add a repository parameter for builtin functions

From
John Cai <johncai86@gmail.com>
Date
Sep 9, 2024, 21:08 UTC
Message-ID
<CAOCgCUJWrOeYK1ugVVe3wdj23+KgBWtMD0XH0EZHc2rZgRGVtg@mail.gmail.com>
In-Reply-To
<ZtrdljxBJtnaUEla@pks.im>
Hi Patrick,
On Fri, Sep 6, 2024 at 6:46 AM Patrick Steinhardt <ps@pks.im> wrote:
Show 71 quoted lines
>
> On Thu, Sep 05, 2024 at 04:57:45PM +0000, John Cai via GitGitGadget wrote:
> > From: John Cai <johncai86@gmail.com>
> > diff --git a/builtin/add.c b/builtin/add.c
> > index 40b61ef90d9..3b9bc93ed9a 100644
> > --- a/builtin/add.c
> > +++ b/builtin/add.c
> > @@ -358,7 +358,7 @@ static int add_files(struct dir_struct *dir, int flags)
> >       return exit_status;
> >  }
> >
> > -int cmd_add(int argc, const char **argv, const char *prefix)
> > +int cmd_add(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
> >  {
> >       int exit_status = 0;
> >       struct pathspec pathspec;
>
> Nit: all of these are now overly long as we typically wrap at 80
> characters.
>
> > diff --git a/git.c b/git.c
> > index 9a618a2740f..0ea6e351dfd 100644
> > --- a/git.c
> > +++ b/git.c
> > @@ -31,7 +31,7 @@
> >
> >  struct cmd_struct {
> >       const char *cmd;
> > -     int (*fn)(int, const char **, const char *);
> > +     int (*fn)(int, const char **, const char *, struct repository *);
> >       unsigned int option;
> >  };
> >
> > @@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
> >       return ret;
> >  }
> >
> > -static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
> > +static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
> >  {
> >       int status, help;
> >       struct stat st;
> > @@ -479,9 +479,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
> >       trace_argv_printf(argv, "trace: built-in: git");
> >       trace2_cmd_name(p->cmd);
> >
> > -     validate_cache_entries(the_repository->index);
> > -     status = p->fn(argc, argv, prefix);
> > -     validate_cache_entries(the_repository->index);
> > +     validate_cache_entries(repo->index);
> > +
> > +     status = p->fn(argc, argv, prefix, startup_info->have_repository? repo: NULL) ;
> > +
> > +     validate_cache_entries(repo->index);
> >
> >       if (status)
> >               return status;
>
> Looks sensible.
>
> > @@ -736,7 +738,7 @@ static void handle_builtin(int argc, const char **argv)
> >
> >       builtin = get_builtin(cmd);
> >       if (builtin)
> > -             exit(run_builtin(builtin, argc, argv));
> > +             exit(run_builtin(builtin, argc, argv, the_repository));
> >       strvec_clear(&args);
> >  }
> >
>
> Why don't we need a check for `startup_info->have_repository` here?

We do the check inside of run_builtin(), which calls the fn() directly. There's a call to validate_cache_entries(repo->index) in run_builtin(), so if we passed in NULL then we would need another guard to prevent a segfault in run_builtin().

Show 15 quoted lines
>
> > diff --git a/help.c b/help.c
> > index c03863f2265..e7cdfab6432 100644
> > --- a/help.c
> > +++ b/help.c
> > @@ -16,6 +16,7 @@
> >  #include "parse-options.h"
> >  #include "prompt.h"
> >  #include "fsmonitor-ipc.h"
> > +#include "repository.h"
> >
> >  #ifndef NO_CURL
> >  #include "git-curl-compat.h" /* For LIBCURL_VERSION only */
>
> The include shouldn't be necessary. You can instead add a forward declaration.
indeed, I'll remove this in the next version.
Show 12 quoted lines
>
> > @@ -775,7 +776,7 @@ void get_version_info(struct strbuf *buf, int show_build_options)
> >       }
> >  }
> >
> > -int cmd_version(int argc, const char **argv, const char *prefix)
> > +int cmd_version(int argc, const char **argv, const char *prefix, struct repository *repository UNUSED)
> >  {
> >       struct strbuf buf = STRBUF_INIT;
> >       int build_options = 0;
>
> Patrick
Previous: Patrick SteinhardtNext: John Cai via GitGitGadget
Message 8 of 32 in “Add repository parameter to builtins”
  1. 0/3 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 5, 2024
  2. 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 5, 2024
  3. Junio C HamanoSep 5, 2024
  4. Patrick SteinhardtSep 6, 2024
  5. Junio C HamanoSep 6, 2024
  6. 1/3 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 5, 2024
  7. Patrick SteinhardtSep 6, 2024
  8. John CaiSep 9, 2024
  9. 3/3 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 5, 2024
  10. Patrick SteinhardtSep 6, 2024
  11. Junio C HamanoSep 5, 2024
  12. 0/3 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 10, 2024
  13. 3/3 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 10, 2024
  14. Junio C HamanoSep 11, 2024
  15. 2/3 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 10, 2024
  16. Junio C HamanoSep 11, 2024
  17. John CaiSep 13, 2024
  18. 1/3 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 10, 2024
  19. Junio C HamanoSep 10, 2024
  20. Junio C HamanoSep 11, 2024
  21. Patrick SteinhardtSep 12, 2024
  22. Jeff KingSep 12, 2024
  23. Jeff KingSep 12, 2024
  24. Patrick SteinhardtSep 12, 2024
  25. John CaiSep 13, 2024
  26. 0/4 Add repository parameter to builtinsJohn Cai via GitGitGadget, Sep 13, 2024
  27. 1/4 builtin: add a repository parameter for builtin functionsJohn Cai via GitGitGadget, Sep 13, 2024
  28. 3/4 builtin: remove USE_THE_REPOSITORY for those without the_repositoryJohn Cai via GitGitGadget, Sep 13, 2024
  29. 2/4 builtin: remove USE_THE_REPOSITORY_VARIABLE from builtin.hJohn Cai via GitGitGadget, Sep 13, 2024
  30. Junio C HamanoSep 13, 2024
  31. 4/4 add: pass in repo variable instead of global the_repositoryJohn Cai via GitGitGadget, Sep 13, 2024
  32. Junio C HamanoSep 13, 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.