]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/a-commands-without-the-repo'
authorTaylor Blau <me@ttaylorr.com>
Fri, 25 Oct 2024 18:02:36 +0000 (14:02 -0400)
committerTaylor Blau <me@ttaylorr.com>
Fri, 25 Oct 2024 18:02:36 +0000 (14:02 -0400)
Commands that can also work outside Git have learned to take the
repository instance "repo" when we know we are in a repository, and
NULL when we are not, in a parameter.  The uses of the_repository
variable in a few of them have been removed using the new calling
convention.

* jc/a-commands-without-the-repo:
  archive: remove the_repository global variable
  annotate: remove usage of the_repository global
  git: pass in repo to builtin based on setup_git_directory_gently

1  2 
builtin/annotate.c
git.c

index 03413c7df8d86c5b267e01a8eb6efb0f80d80b7c,ce3dfaafb28ab0ab8a4806e87b3865b4bb659e25..7f754f2309b66222db7ebf6f7605119d1e39122e
  int cmd_annotate(int argc,
                 const char **argv,
                 const char *prefix,
-                struct repository *repo UNUSED)
+                struct repository *repo)
  {
        struct strvec args = STRVEC_INIT;
 -      int i;
 +      const char **args_copy;
 +      int ret;
  
        strvec_pushl(&args, "annotate", "-c", NULL);
 -
 -      for (i = 1; i < argc; i++) {
 +      for (int i = 1; i < argc; i++)
                strvec_push(&args, argv[i]);
 -      }
  
 -      return cmd_blame(args.nr, args.v, prefix, repo);
 +      /*
 +       * `cmd_blame()` ends up modifying the array, which causes memory leaks
 +       * if we didn't copy the array here.
 +       */
 +      CALLOC_ARRAY(args_copy, args.nr + 1);
 +      COPY_ARRAY(args_copy, args.v, args.nr);
 +
-       ret = cmd_blame(args.nr, args_copy, prefix, the_repository);
++      ret = cmd_blame(args.nr, args_copy, prefix, repo);
 +
 +      strvec_clear(&args);
 +      free(args_copy);
 +      return ret;
  }
diff --cc git.c
Simple merge