From: Taylor Blau Date: Fri, 25 Oct 2024 18:02:36 +0000 (-0400) Subject: Merge branch 'jc/a-commands-without-the-repo' X-Git-Tag: v2.48.0-rc0~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ab43ed95c6cf598ba6d02dabaa5959dfd48ecec;p=thirdparty%2Fgit.git Merge branch 'jc/a-commands-without-the-repo' 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 --- 0ab43ed95c6cf598ba6d02dabaa5959dfd48ecec diff --cc builtin/annotate.c index 03413c7df8,ce3dfaafb2..7f754f2309 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@@ -12,26 -11,16 +11,26 @@@ 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; }