builtin: stop using the_repository
PATCH 1/1 builtin: stop using the_repository
The builtins use the_repository global variable which might not work well when running many repos in the same process at once.
Stop using the_repository in these builtins to align with the goal of libification of Git.
--- builtin/bugreport.c | 13 ++++++------- builtin/bundle.c | 13 ++++++------- builtin/check-attr.c | 26 +++++++++++++------------- builtin/check-ignore.c | 27 +++++++++++++++------------ 4 files changed, 40 insertions(+), 39 deletions(-)
builtin/bugreport.c +6 -7
@@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "abspath.h" #include "editor.h"
@@ -37,7 +36,7 @@ static void get_system_info(struct strbuf *sys_info) shell ? shell : "<unset>"); } -static void get_populated_hooks (struct strbuf *hook_info,int nongit) +static void get_populated_hooks (struct repository *repo,struct strbuf *hook_info,int nongit) {const char **p;
@@ -50,7 +49,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)for (p = hook_name_list; *p; p++) {const char *hook = *p; -if (hook_exists (the_repository, hook)) +if (hook_exists (repo, hook))strbuf_addf (hook_info,"%s\n" , hook); } }
@@ -93,7 +92,7 @@ static void get_header(struct strbuf *buf, const char *title)int cmd_bugreport (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) +struct repository *repo) {struct strbuf buffer =STRBUF_INIT ;struct strbuf report_path =STRBUF_INIT ;
@@ -141,7 +140,7 @@ int cmd_bugreport(int argc, }strbuf_addstr (&report_path,".txt" ); -switch (safe_create_leading_directories (the_repository, report_path.buf)) { +switch (safe_create_leading_directories (repo, report_path.buf)) {case SCLD_OK :case SCLD_EXISTS :break ;
@@ -158,7 +157,7 @@ int cmd_bugreport(int argc,strbuf_addftime (&zip_path, option_suffix,localtime_r (&now, &tm),0 ,0 );strbuf_addstr (&zip_path,".zip" ); -if (create_diagnostics_archive (the_repository, &zip_path, diagnose)) +if (create_diagnostics_archive (repo, &zip_path, diagnose))die_errno (_ ("unable to create diagnostics archive %s" ), zip_path.buf);strbuf_release (&zip_path);
@@ -171,7 +170,7 @@ int cmd_bugreport(int argc,get_system_info (&buffer);get_header (&buffer,_ ("Enabled Hooks" )); -get_populated_hooks (&buffer, !startup_info->have_repository); +get_populated_hooks (repo, &buffer, !startup_info->have_repository);/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */ report =xopen (report_path.buf,O_CREAT |O_EXCL |O_WRONLY ,0666 );
builtin/bundle.c +6 -7
@@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "abspath.h" #include "gettext.h"
@@ -68,7 +67,7 @@ static int parse_options_cmd_bundle(int argc, }static int cmd_bundle_create (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) { +struct repository *repo) {struct strvec pack_opts =STRVEC_INIT ;int version =-1 ;int ret;
@@ -101,7 +100,7 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix,if (!startup_info->have_repository)die (_ ("Need a repository to create a bundle." )); - ret = !!create_bundle (the_repository, bundle_file, argc, argv, &pack_opts, version); + ret = !!create_bundle (repo, bundle_file, argc, argv, &pack_opts, version);strvec_clear (&pack_opts);free (bundle_file);return ret;
@@ -125,7 +124,7 @@ static int open_bundle(const char *path, struct bundle_header *header, }static int cmd_bundle_verify (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) { +struct repository *repo) {struct bundle_header header =BUNDLE_HEADER_INIT ;int bundle_fd =-1 ;int quiet =0 ;
@@ -152,7 +151,7 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix, goto cleanup; }close (bundle_fd); -if (verify_bundle (the_repository, &header, +if (verify_bundle (repo, &header, quiet ?VERIFY_BUNDLE_QUIET :VERIFY_BUNDLE_VERBOSE )) { ret =1 ; goto cleanup;
@@ -193,7 +192,7 @@ static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix }static int cmd_bundle_unbundle (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) { +struct repository *repo) {struct bundle_header header =BUNDLE_HEADER_INIT ;int bundle_fd =-1 ;int ret;
@@ -221,7 +220,7 @@ static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix,if (progress)strvec_pushl (&extra_index_pack_args,"-v" ,"--progress-title" ,_ ("Unbundling objects" ),NULL ); - ret = !!unbundle (the_repository, &header, bundle_fd, + ret = !!unbundle (repo, &header, bundle_fd, &extra_index_pack_args,NULL ) ||list_bundle_refs (&header, argc, argv);bundle_header_release (&header);
builtin/check-attr.c +13 -13
@@ -61,7 +61,7 @@ static void output_attr(struct attr_check *check, const char *file) } } -static void check_attr (const char *prefix,struct attr_check *check, +static void check_attr (struct repository *repo,const char *prefix,struct attr_check *check,int collect_all,const char *file)
@@ -70,16 +70,16 @@ static void check_attr(const char *prefix, struct attr_check *check,prefix_path (prefix, prefix ?strlen (prefix) :0 , file);if (collect_all) { -git_all_attrs (the_repository->index, full_path, check); +git_all_attrs (repo->index, full_path, check); }else { -git_check_attr (the_repository->index, full_path, check); +git_check_attr (repo->index, full_path, check); }output_attr (check, file);free (full_path); } -static void check_attr_stdin_paths (const char *prefix,struct attr_check *check, +static void check_attr_stdin_paths (struct repository *repo,const char *prefix,struct attr_check *check,int collect_all) {struct strbuf buf =STRBUF_INIT ;
@@ -94,7 +94,7 @@ static void check_attr_stdin_paths(const char *prefix, struct attr_check *check,die ("line is badly quoted" );strbuf_swap (&buf, &unquoted); } -check_attr (prefix, check, collect_all, buf.buf); +check_attr (repo, prefix, check, collect_all, buf.buf);maybe_flush_or_die (stdout,"attribute to stdout" ); }strbuf_release (&buf);
@@ -110,7 +110,7 @@ static NORETURN void error_with_usage(const char *msg)int cmd_check_attr (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) +struct repository *repo) {struct attr_check *check;struct object_id initialized_oid;
@@ -119,15 +119,15 @@ int cmd_check_attr(int argc,if (!is_bare_repository ())setup_work_tree (); -repo_config (the_repository, git_default_config,NULL ); +repo_config (repo, git_default_config,NULL ); argc =parse_options (argc, argv, prefix, check_attr_options, check_attr_usage,PARSE_OPT_KEEP_DASHDASH ); -prepare_repo_settings (the_repository); - the_repository->settings.command_requires_full_index =0 ; +prepare_repo_settings (repo); + repo->settings.command_requires_full_index =0 ; -if (repo_read_index (the_repository) <0 ) { +if (repo_read_index (repo) <0 ) {die ("invalid cache" ); }
@@ -189,16 +189,16 @@ int cmd_check_attr(int argc, }if (source) { -if (repo_get_oid_tree (the_repository, source, &initialized_oid)) +if (repo_get_oid_tree (repo, source, &initialized_oid))die ("%s: not a valid tree-ish source" , source);set_git_attr_source (source); }if (stdin_paths) -check_attr_stdin_paths (prefix, check, all_attrs); +check_attr_stdin_paths (repo, prefix, check, all_attrs);else {for (i = filei; i < argc; i++) -check_attr (prefix, check, all_attrs, argv[i]); +check_attr (repo, prefix, check, all_attrs, argv[i]);maybe_flush_or_die (stdout,"attribute to stdout" ); }
builtin/check-ignore.c +15 -12
@@ -70,8 +70,10 @@ static void output_pattern(const char *path, struct path_pattern *pattern) } } -static int check_ignore (struct dir_struct *dir, -const char *prefix,int argc,const char **argv) +static int check_ignore (struct repository *repo, +struct dir_struct *dir, +const char *prefix, +int argc,const char **argv) {const char *full_path;char *seen;
@@ -95,21 +97,21 @@ static int check_ignore(struct dir_struct *dir,PATHSPEC_KEEP_ORDER , prefix, argv); -die_path_inside_submodule (the_repository->index, &pathspec); +die_path_inside_submodule (repo->index, &pathspec);/* * look for pathspecs matching entries in the index, since these * should not be ignored, in order to be consistent with * 'git status', 'git add' etc. */ - seen =find_pathspecs_matching_against_index (&pathspec, the_repository->index, + seen =find_pathspecs_matching_against_index (&pathspec, repo->index,PS_HEED_SKIP_WORKTREE );for (i =0 ; i < pathspec.nr; i++) { full_path = pathspec.items[i].match; pattern =NULL ;if (!seen[i]) {int dtype =DT_UNKNOWN ; - pattern =last_matching_pattern (dir, the_repository->index, + pattern =last_matching_pattern (dir, repo->index, full_path, &dtype);if (!verbose && pattern && pattern->flags &PATTERN_FLAG_NEGATIVE )
@@ -126,7 +128,8 @@ static int check_ignore(struct dir_struct *dir,return num_ignored; } -static int check_ignore_stdin_paths (struct dir_struct *dir,const char *prefix) +static int check_ignore_stdin_paths (struct repository *repo, +struct dir_struct *dir,const char *prefix) {struct strbuf buf =STRBUF_INIT ;struct strbuf unquoted =STRBUF_INIT ;
@@ -143,7 +146,7 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)strbuf_swap (&buf, &unquoted); } pathspec[0 ] = buf.buf; - num_ignored +=check_ignore (dir, prefix, + num_ignored +=check_ignore (repo, dir, prefix,1 , (const char **)pathspec);maybe_flush_or_die (stdout,"check-ignore to stdout" ); }
@@ -155,12 +158,12 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)int cmd_check_ignore (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) +struct repository *repo) {int num_ignored;struct dir_struct dir =DIR_INIT ; -repo_config (the_repository, git_default_config,NULL ); +repo_config (repo, git_default_config,NULL ); argc =parse_options (argc, argv, prefix, check_ignore_options, check_ignore_usage,0 );
@@ -184,15 +187,15 @@ int cmd_check_ignore(int argc,die (_ ("--non-matching is only valid with --verbose" ));/* read_cache() is only necessary so we can watch out for submodules. */ -if (!no_index &&repo_read_index (the_repository) <0 ) +if (!no_index &&repo_read_index (repo) <0 )die (_ ("index file corrupt" ));setup_standard_excludes (&dir);if (stdin_paths) { - num_ignored =check_ignore_stdin_paths (&dir, prefix); + num_ignored =check_ignore_stdin_paths (repo, &dir, prefix); }else { - num_ignored =check_ignore (&dir, prefix, argc, argv); + num_ignored =check_ignore (repo, &dir, prefix, argc, argv);maybe_flush_or_die (stdout,"ignore to stdout" ); }
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 2 lines · Abraham Samuel Adekunle
The builtins use
the_repositoryglobal variable which might not work well when running many repos in the same process at once.
This is true, but ...
Quoted 2 lines
Stop using
the_repositoryin these builtins to align with the goal of libification of Git.
... in general, each file under builtin/ is about a single command that _uses_ libified part of Git. So it is perfectly fine for the libification goal to include "libified functions should not assume that it works on the_repository, but they should accept a repo parameter to tell them which repository to work with". But it is not necessary, and I would say it is harmful, to subject builtin/*.c to the same criteria. The builtin command implementations can call libified function by passing the_repository to libified API function that expects a repo parameter.
Quoted 27 lines
Signed-off-by Abraham Samuel Adekunle <[email protected]>--- builtin/bugreport.c | 13 ++++++------- builtin/bundle.c | 13 ++++++------- builtin/check-attr.c | 26 +++++++++++++------------- builtin/check-ignore.c | 27 +++++++++++++++------------ 4 files changed, 40 insertions(+), 39 deletions(-)builtin/bugreport.c +1
-2@@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "abspath.h" #include "editor.h" @@ -37,7 +36,7 @@ static void get_system_info(struct strbuf *sys_info) shell ? shell : "<unset>"); } -static void get_populated_hooks (struct strbuf *hook_info,int nongit) +static void get_populated_hooks (struct repository *repo,struct strbuf *hook_info,int nongit) {const char **p;
builtin/bugreport.c static void get_populated_hooks(struct strbuf *hook_info, int nongit) · line 55
Quoted 8 lines
builtin/bugreport.c +1
-1@@ -50,7 +49,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)for (p = hook_name_list; *p; p++) {const char *hook = *p; -if (hook_exists (the_repository, hook)) +if (hook_exists (repo, hook))strbuf_addf (hook_info,"%s\n" , hook); } }
It is not strictly necessary to churn a file-scope static function like this one into taking an arbitrary repo parameter, as the only caller of the function, presumably cmd_foo() in the builtin/foo.c file, would pass the_repository anyway, whether it explicitly names the_repository or passes the repo parameter that it got from its caller, git.c:run_builtin(). We _can_ consider a change like the above as a preparation to potentially move these functions to the libified part of Git, so even though I said it is not necessary, it is also OK to perform such a change.
Quoted 28 lines
builtin/bugreport.c +3
-3@@ -93,7 +92,7 @@ static void get_header(struct strbuf *buf, const char *title)int cmd_bugreport (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) +struct repository *repo) {struct strbuf buffer =STRBUF_INIT ;struct strbuf report_path =STRBUF_INIT ;@@ -141,7 +140,7 @@ int cmd_bugreport(int argc, }strbuf_addstr (&report_path,".txt" ); -switch (safe_create_leading_directories (the_repository, report_path.buf)) { +switch (safe_create_leading_directories (repo, report_path.buf)) {case SCLD_OK :case SCLD_EXISTS :break ;@@ -158,7 +157,7 @@ int cmd_bugreport(int argc,strbuf_addftime (&zip_path, option_suffix,localtime_r (&now, &tm),0 ,0 );strbuf_addstr (&zip_path,".zip" ); -if (create_diagnostics_archive (the_repository, &zip_path, diagnose)) +if (create_diagnostics_archive (repo, &zip_path, diagnose))die_errno (_ ("unable to create diagnostics archive %s" ), zip_path.buf);strbuf_release (&zip_path);
builtin/bugreport.c int cmd_bugreport(int argc, · line 176
Quoted 8 lines
builtin/bugreport.c +1
-1@@ -171,7 +170,7 @@ int cmd_bugreport(int argc,get_system_info (&buffer);get_header (&buffer,_ ("Enabled Hooks" )); -get_populated_hooks (&buffer, !startup_info->have_repository); +get_populated_hooks (repo, &buffer, !startup_info->have_repository);/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */ report =xopen (report_path.buf,O_CREAT |O_EXCL |O_WRONLY ,0666 );
All of the above look fine.
builtin/bundle.c
Quoted 4 lines
builtin/bundle.c +0
-0
Is this patch meant as a microproject in preparation for applying for GSoC? If so, we ask to limit one quality focused one per applicant.
Quoted 11 lines · Junio C Hamano
Quoted 2 lines · Abraham Samuel Adekunle
The builtins use
the_repositoryglobal variable which might not work well when running many repos in the same process at once.This is true, but ...
Quoted 2 lines
Stop using
the_repositoryin these builtins to align with the goal of libification of Git.
Quoted 9 lines
... in general, each file under builtin/ is about a single command that _uses_ libified part of Git. So it is perfectly fine for the libification goal to include "libified functions should not assume that it works on
the_repository, but they should accept a repo parameter to tell them which repository to work with". But it is not necessary, and I would say it is harmful, to subject builtin/*.c to the same criteria. The builtin command implementations can call libified function by passingthe_repositoryto libified API function that expects a repo parameter.
Oh thank you Junio for clarifying
Quoted 31 lines
Quoted 31 lines
Signed-off-by Abraham Samuel Adekunle <[email protected]>--- builtin/bugreport.c | 13 ++++++------- builtin/bundle.c | 13 ++++++------- builtin/check-attr.c | 26 +++++++++++++------------- builtin/check-ignore.c | 27 +++++++++++++++------------ 4 files changed, 40 insertions(+), 39 deletions(-)builtin/bugreport.c +1
-2@@ -1,4 +1,3 @@ -#define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "abspath.h" #include "editor.h" @@ -37,7 +36,7 @@ static void get_system_info(struct strbuf *sys_info) shell ? shell : "<unset>"); } -static void get_populated_hooks (struct strbuf *hook_info,int nongit) +static void get_populated_hooks (struct repository *repo,struct strbuf *hook_info,int nongit) {const char **p;@@ -50,7 +49,7 @@ static void get_populated_hooks(struct strbuf *hook_info, int nongit)for (p = hook_name_list; *p; p++) {const char *hook = *p;
Quoted 15 lines
builtin/bugreport.c static void get_populated_hooks(struct strbuf *hook_info, int nongit) · line 55
Quoted 5 lines
builtin/bugreport.c +1
-1-if (hook_exists (the_repository, hook)) +if (hook_exists (repo, hook))strbuf_addf (hook_info,"%s\n" , hook); } }It is not strictly necessary to churn a file-scope static function like this one into taking an arbitrary repo parameter, as the only caller of the function, presumably
cmd_foo()in thebuiltin/foo.cfile, would passthe_repositoryanyway, whether it explicitly namesthe_repositoryor passes the repo parameter that it got from its caller, git.c:run_builtin(). We _can_ consider a change like the above as a preparation to potentially move these functions to the libified part of Git, so even though I said it is not necessary, it is also OK to perform such a change.
Okay thank you
Quoted 49 lines
Quoted 29 lines
builtin/bugreport.c +3
-3@@ -93,7 +92,7 @@ static void get_header(struct strbuf *buf, const char *title)int cmd_bugreport (int argc,const char **argv,const char *prefix, - struct repository *repo UNUSED) +struct repository *repo) {struct strbuf buffer =STRBUF_INIT ;struct strbuf report_path =STRBUF_INIT ;@@ -141,7 +140,7 @@ int cmd_bugreport(int argc, }strbuf_addstr (&report_path,".txt" ); -switch (safe_create_leading_directories (the_repository, report_path.buf)) { +switch (safe_create_leading_directories (repo, report_path.buf)) {case SCLD_OK :case SCLD_EXISTS :break ;@@ -158,7 +157,7 @@ int cmd_bugreport(int argc,strbuf_addftime (&zip_path, option_suffix,localtime_r (&now, &tm),0 ,0 );strbuf_addstr (&zip_path,".zip" ); -if (create_diagnostics_archive (the_repository, &zip_path, diagnose)) +if (create_diagnostics_archive (repo, &zip_path, diagnose))die_errno (_ ("unable to create diagnostics archive %s" ), zip_path.buf);strbuf_release (&zip_path);builtin/bugreport.c int cmd_bugreport(int argc, · line 176
Quoted 8 lines
builtin/bugreport.c +1
-1@@ -171,7 +170,7 @@ int cmd_bugreport(int argc,get_system_info (&buffer);get_header (&buffer,_ ("Enabled Hooks" )); -get_populated_hooks (&buffer, !startup_info->have_repository); +get_populated_hooks (repo, &buffer, !startup_info->have_repository);/* fopen doesn't offer us an O_EXCL alternative, except with glibc. */ report =xopen (report_path.buf,O_CREAT |O_EXCL |O_WRONLY ,0666 );All of the above look fine.
builtin/bundle.c
Quoted 4 lines
builtin/bundle.c +0
-0Is this patch meant as a microproject in preparation for applying for GSoC? If so, we ask to limit one quality focused one per applicant.
Quoted 1 line
No, this patch is not meant as a microproject.
I previously read in the General-Microproject-Information section "After it's done, work on different things"
that we can keep contributing after a micoproject if we are itching to do more. So I just want to keep contributing.
Do I drop the "GSoC" tag and send a v2?
I will not include the tag in subsequent patches.
Thanks
Abraham.