git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Usman Akinyemi <usmanakinyemi202@gmail.com>
To: gitster@pobox.com, christian.couder@gmail.com, git@vger.kernel.org
Cc: me@ttaylorr.com, chriscool@tuxfamily.org, johncai86@gmail.com,
	ps@pks.im, shejialuo@gmail.com
Subject: [PATCH v2 00/12][Outreachy] stop using the_repository global variable.
Date: Thu, 20 Feb 2025 02:02:48 +0530	[thread overview]
Message-ID: <20250219203349.787173-1-usmanakinyemi202@gmail.com> (raw)
In-Reply-To: <20250214230210.1460111-1-usmanakinyemi202@gmail.com>

Remove `the_repository` global variable in favor of the repository
argument that gets passed in builtin commands. 

These sets of commands are commands that use only RUN_SETUP macro in "git.c".
Basically, When `-h` is passed to any of this command outside a Git repository,
the `run_builtin()` will call the `cmd_x()` function (where `x` is any
of the command from the sets of builtin commands that `the_repository` is removed
from) with `repo` set to NULL and then early in the function, `parse_options()`
or show_usage_with_options_if_asked() call will give the options help and exit,
without having to consult much of the configuration file.

As there exist some builtin commands where the `repository` variable is accessed
before options is given exit and fail, we will move the functions which
accessed the `repository` below the `usage_with_options()` and it
variants which will exit before getting to the function accessing the `repository`
variable. We will do this in a preparatory patches.

Some, functions also uses `the_repository` global internally, so, let's
let's refactor them and pass `struct repo` as one of the argument. 

I picked some of this files based on the above explanation, how easy they are to
resolve and how easy easy to review. 

[1]: https://public-inbox.org/git/20250210181103.3609495-1-usmanakinyemi202@gmail.com/

Changes since v1
================
- Add some new preparatory patches to move the `git_config()` below the
`usage_with_options()`.
- Fix some errors in the commit messages.

Usman Akinyemi (12):
  builtin/verify-tag: refactor `cmd_verify_tag()`
  builtin/verify-tag: stop using `the_repository`
  builtin/verify-commit: refactor `cmd_verify_commit()`
  builtin/verify-commit: stop using `the_repository`
  builtin/send-pack: refactor `cmd_send_pack()`
  builtin/send-pack: stop using `the_repository`
  builtin/pack-refs: refactor `cmd_pack_refs()`
  builtin/pack-refs: stop using `the_repository`
  builtin/ls-files: stop using `the_repository`
  builtin/for-each-ref: refactor `cmd_for_each_ref()`
  builtin/for-each-ref: stop using `the_repository`
  builtin/checkout-index: stop using `the_repository`

 builtin/checkout-index.c | 43 ++++++++++++++++++++--------------------
 builtin/for-each-ref.c   |  6 ++----
 builtin/ls-files.c       | 32 +++++++++++++++---------------
 builtin/pack-refs.c      |  9 ++++-----
 builtin/send-pack.c      |  8 ++++----
 builtin/verify-commit.c  | 15 +++++++-------
 builtin/verify-tag.c     |  9 ++++-----
 7 files changed, 58 insertions(+), 64 deletions(-)

Range-diff versus v1:

 -:  ---------- >  1:  ceb03199e1 builtin/verify-tag: refactor `cmd_verify_tag()`
 1:  3e8d11ccfe !  2:  ecfb834600 builtin/verify-tag: stop using `the_repository`
    @@ Commit message
         `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set
         to NULL and then early in the function, `parse_options()` call will give
         the options help and exit, without having to consult much of the
    -    configuration file. So it is safe to omit reading the config when `repo`
    -    argument the caller gave us is NULL.
    +    configuration file.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
    @@ builtin/verify-tag.c: static const char * const verify_tag_usage[] = {
      	int i = 1, verbose = 0, had_error = 0;
      	unsigned flags = 0;
     @@ builtin/verify-tag.c: int cmd_verify_tag(int argc,
    - 		OPT_END()
    - 	};
    + 		flags |= GPG_VERIFY_OMIT_STATUS;
    + 	}
      
     -	git_config(git_default_config, NULL);
    -+	if (repo)
    -+		repo_config(repo, git_default_config, NULL);
    ++	repo_config(repo, git_default_config, NULL);
      
    - 	argc = parse_options(argc, argv, prefix, verify_tag_options,
    - 			     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
    -@@ builtin/verify-tag.c: int cmd_verify_tag(int argc,
    + 	while (i < argc) {
      		struct object_id oid;
      		const char *name = argv[i++];
      
 -:  ---------- >  3:  2f770824b1 builtin/verify-commit: refactor `cmd_verify_commit()`
 2:  88af56e220 !  4:  546588a6ae builtin/verify-commit.c: stop using `the_repository`
    @@ Metadata
     Author: Usman Akinyemi <usmanakinyemi202@gmail.com>
     
      ## Commit message ##
    -    builtin/verify-commit.c: stop using `the_repository`
    +    builtin/verify-commit: stop using `the_repository`
     
         Remove the_repository global variable in favor of the repository
    -    argument that gets passed in "builtin/verify-tag.c".
    +    argument that gets passed in "builtin/verify-commit.c".
     
         When `-h` is passed to the command outside a Git repository, the
         `run_builtin()` will call the `cmd_verify_commit()` function with `repo`
         set to NULL and then early in the function, `parse_options()` call will
         give the options help and exit, without having to consult much of the
    -    configuration file. So it is safe to omit reading the config when `repo`
    -    argument the caller gave us is NULL.
    +    configuration file.
     
    -    Let's pass `repository` argument to `verify_commit()` function to remove
    -    it's dependency on the global `the_repository` variable.
    +    Pass the repository available in the calling context to `verify_commit()`
    +    to remove it's dependency on the global `the_repository` variable.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
    @@ builtin/verify-commit.c: static int verify_commit(const char *name, unsigned fla
      	int i = 1, verbose = 0, had_error = 0;
      	unsigned flags = 0;
     @@ builtin/verify-commit.c: int cmd_verify_commit(int argc,
    - 		OPT_END()
    - 	};
    + 	if (verbose)
    + 		flags |= GPG_VERIFY_VERBOSE;
      
     -	git_config(git_default_config, NULL);
    -+	if (repo)
    -+		repo_config(repo, git_default_config, NULL);
    ++	repo_config(repo, git_default_config, NULL);
      
    - 	argc = parse_options(argc, argv, prefix, verify_commit_options,
    - 			     verify_commit_usage, PARSE_OPT_KEEP_ARGV0);
    -@@ builtin/verify-commit.c: int cmd_verify_commit(int argc,
    + 	/* sometimes the program was terminated because this signal
      	 * was received in the process of writing the gpg input: */
      	signal(SIGPIPE, SIG_IGN);
      	while (i < argc)
 -:  ---------- >  5:  99f10469bd builtin/send-pack: refactor `cmd_send_pack()`
 3:  39409ea113 !  6:  cb3886bc46 builtin/send-pack.c: stop using `the_repository`
    @@ Metadata
     Author: Usman Akinyemi <usmanakinyemi202@gmail.com>
     
      ## Commit message ##
    -    builtin/send-pack.c: stop using `the_repository`
    +    builtin/send-pack: stop using `the_repository`
     
         Remove the_repository global variable in favor of the repository
         argument that gets passed in "builtin/send-pack.c".
    @@ Commit message
         `run_builtin()` will call the `cmd_send_pack()` function with `repo` set
         to NULL and then early in the function, `parse_options()` call will give
         the options help and exit, without having to consult much of the
    -    configuration file. So it is safe to omit reading the config when `repo`
    -    argument the caller gave us is NULL.
    +    configuration file.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
    @@ builtin/send-pack.c: static int send_pack_config(const char *k, const char *v,
      	struct refspec rs = REFSPEC_INIT_PUSH;
      	const char *remote_name = NULL;
     @@ builtin/send-pack.c: int cmd_send_pack(int argc,
    - 		OPT_END()
    - 	};
    + 	if (!dest)
    + 		usage_with_options(send_pack_usage, options);
      
     -	git_config(send_pack_config, NULL);
    -+	if (repo)
    -+		repo_config(repo, send_pack_config, NULL);
    - 	argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
    - 	if (argc > 0) {
    - 		dest = argv[0];
    ++	repo_config(repo, send_pack_config, NULL);
    + 
    + 	args.verbose = verbose;
    + 	args.dry_run = dry_run;
     @@ builtin/send-pack.c: int cmd_send_pack(int argc,
      	set_ref_status_for_push(remote_refs, args.send_mirror,
      		args.force_update);
 -:  ---------- >  7:  d104522e30 builtin/pack-refs: refactor `cmd_pack_refs()`
 4:  6fd5f4727c !  8:  7f02e48663 builtin/pack-refs: stop using `the_repository`
    @@ Commit message
         `run_builtin()` will call the `cmd_pack_refs()` function with `repo` set
         to NULL and then early in the function, `parse_options()` call will give
         the options help and exit, without having to consult much of the
    -    configuration file. So it is safe to omit reading the config when `repo`
    -    argument the caller gave us is NULL.
    +    configuration file.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
    @@ builtin/pack-refs.c: static char const * const pack_refs_usage[] = {
      	struct ref_exclusions excludes = REF_EXCLUSIONS_INIT;
      	struct string_list included_refs = STRING_LIST_INIT_NODUP;
     @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,
    - 			N_("references to exclude")),
    - 		OPT_END(),
    - 	};
    --	git_config(git_default_config, NULL);
    -+	if (repo)
    -+		repo_config(repo, git_default_config, NULL);
      	if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
      		usage_with_options(pack_refs_usage, opts);
      
    +-	git_config(git_default_config, NULL);
    ++	repo_config(repo, git_default_config, NULL);
    + 	for_each_string_list_item(item, &option_excluded_refs)
    + 		add_ref_exclusion(pack_refs_opts.exclusions, item->string);
    + 
     @@ builtin/pack-refs.c: int cmd_pack_refs(int argc,
      	if (!pack_refs_opts.includes->nr)
      		string_list_append(pack_refs_opts.includes, "refs/tags/*");
 5:  c58f27988b !  9:  b706fab321 builtin/ls-files: stop using `the_repository`
    @@ Commit message
         call will give the options help and exit, without having to consult much
         of the configuration file.
     
    -    Let's pass `repository` argument to `expand_objectsize()`,
    -    `show_ru_info()` functions to remove their dependency on the global
    -    `the_repository` variable.
    +    Pass the repository available in the calling context to both
    +    `expand_objectsize()` and `show_ru_info()` to remove their
    +    dependency on the global `the_repository` variable.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
 -:  ---------- > 10:  d2fc527d51 builtin/for-each-ref: refactor `cmd_for_each_ref()`
 6:  4bbca37330 ! 11:  c3a3a6cff7 builtin/for-each-ref: stop using `the_repository`
    @@ Commit message
         `run_builtin()` will call the `cmd_for_each_ref()` function with `repo`
         set to NULL and then early in the function, `parse_options()` call will
         give the options help and exit, without having to consult much of the
    -    configuration file. So it is safe to omit reading the config when `repo`
    -    argument the caller gave us is NULL.
    +    configuration file.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
    @@ builtin/for-each-ref.c: static char const * const for_each_ref_usage[] = {
      	struct ref_sorting *sorting;
      	struct string_list sorting_options = STRING_LIST_INIT_DUP;
     @@ builtin/for-each-ref.c: int cmd_for_each_ref(int argc,
    - 
    - 	format.format = "%(objectname) %(objecttype)\t%(refname)";
    + 	if (verify_ref_format(&format))
    + 		usage_with_options(for_each_ref_usage, opts);
      
     -	git_config(git_default_config, NULL);
    -+	if (repo)
    -+		repo_config(repo, git_default_config, NULL);
    - 
    - 	/* Set default (refname) sorting */
    - 	string_list_append(&sorting_options, "refname");
    ++	repo_config(repo, git_default_config, NULL);
    + 	sorting = ref_sorting_options(&sorting_options);
    + 	ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase);
    + 	filter.ignore_case = icase;
 7:  369008d554 ! 12:  d3a18f857e builtin/checkout-index.c: stop using `the_repository`
    @@ Metadata
     Author: Usman Akinyemi <usmanakinyemi202@gmail.com>
     
      ## Commit message ##
    -    builtin/checkout-index.c: stop using `the_repository`
    +    builtin/checkout-index: stop using `the_repository`
     
         Remove the_repository global variable in favor of the repository
         argument that gets passed in "builtin/checkout-index.c".
    @@ Commit message
         call will give the options help and exit, without having to consult much
         of the configuration file.
     
    -    Let's pass `repository` argument to `checkout_all()` and `checkout_file()`
    -    functions to remove their dependency on the global `the_repository` variable.
    +    Pass the repository available in the calling context to both `checkout_all()`
    +    and `checkout_file()` to remove their dependency on the global
    +    `the_repository` variable.
     
         Mentored-by: Christian Couder <chriscool@tuxfamily.org>
         Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>

-- 
2.48.1


  parent reply	other threads:[~2025-02-19 20:33 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-14 22:57 [PATCH 0/7][Outreachy] stop using the_repository global variable Usman Akinyemi
2025-02-14 22:57 ` [PATCH 1/7] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-02-17  6:55   ` Patrick Steinhardt
2025-02-17 10:05     ` Usman Akinyemi
2025-02-17 10:22       ` Patrick Steinhardt
2025-02-17 10:42         ` Usman Akinyemi
2025-02-17 15:47           ` Patrick Steinhardt
2025-02-14 22:57 ` [PATCH 2/7] builtin/verify-commit.c: " Usman Akinyemi
2025-02-16  5:32   ` shejialuo
2025-02-17  8:55     ` Usman Akinyemi
2025-02-14 22:57 ` [PATCH 3/7] builtin/send-pack.c: " Usman Akinyemi
2025-02-14 22:57 ` [PATCH 4/7] builtin/pack-refs: " Usman Akinyemi
2025-02-14 22:57 ` [PATCH 5/7] builtin/ls-files: " Usman Akinyemi
2025-02-17  6:55   ` Patrick Steinhardt
2025-02-17  8:57     ` Usman Akinyemi
2025-02-14 22:57 ` [PATCH 6/7] builtin/for-each-ref: " Usman Akinyemi
2025-02-14 22:57 ` [PATCH 7/7] builtin/checkout-index.c: " Usman Akinyemi
2025-02-16  5:41 ` [PATCH 0/7][Outreachy] stop using the_repository global variable shejialuo
2025-02-17  8:56   ` Usman Akinyemi
2025-02-19 20:32 ` Usman Akinyemi [this message]
2025-02-19 20:32   ` [PATCH v2 01/12] builtin/verify-tag: refactor `cmd_verify_tag()` Usman Akinyemi
2025-02-20 15:32     ` Junio C Hamano
2025-02-19 20:32   ` [PATCH v2 02/12] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-02-20 15:43     ` Junio C Hamano
2025-02-27 17:56       ` Usman Akinyemi
2025-02-27 22:39         ` Junio C Hamano
2025-02-19 20:32   ` [PATCH v2 03/12] builtin/verify-commit: refactor `cmd_verify_commit()` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 04/12] builtin/verify-commit: stop using `the_repository` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 05/12] builtin/send-pack: refactor `cmd_send_pack()` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 06/12] builtin/send-pack: stop using `the_repository` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 07/12] builtin/pack-refs: refactor `cmd_pack_refs()` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 08/12] builtin/pack-refs: stop using `the_repository` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 09/12] builtin/ls-files: " Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 10/12] builtin/for-each-ref: refactor `cmd_for_each_ref()` Usman Akinyemi
2025-02-19 20:32   ` [PATCH v2 11/12] builtin/for-each-ref: stop using `the_repository` Usman Akinyemi
2025-02-19 20:33   ` [PATCH v2 12/12] builtin/checkout-index: " Usman Akinyemi
2025-03-06 14:35   ` [Outreachy PATCH v3 0/8] stop using the_repository global variable Usman Akinyemi
2025-03-06 14:35     ` [PATCH v3 1/8] config: teach repo_config to allow `repo` to be NULL Usman Akinyemi
2025-03-06 17:53       ` Junio C Hamano
2025-03-07  1:33         ` Usman Akinyemi
2025-03-07 10:37         ` Phillip Wood
2025-03-06 14:35     ` [PATCH v3 2/8] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-03-06 17:56       ` Junio C Hamano
2025-03-06 14:35     ` [PATCH v3 3/8] builtin/verify-commit: " Usman Akinyemi
2025-03-06 14:35     ` [PATCH v3 4/8] builtin/send-pack: " Usman Akinyemi
2025-03-06 14:35     ` [PATCH v3 5/8] builtin/pack-refs: " Usman Akinyemi
2025-03-06 14:35     ` [PATCH v3 6/8] builtin/ls-files: " Usman Akinyemi
2025-03-06 17:59       ` Junio C Hamano
2025-03-06 14:35     ` [PATCH v3 7/8] builtin/for-each-ref: " Usman Akinyemi
2025-03-06 14:35     ` [PATCH v3 8/8] builtin/checkout-index: " Usman Akinyemi
2025-03-06 18:18       ` Junio C Hamano
2025-03-07  1:15         ` Usman Akinyemi
2025-03-07 14:15           ` Junio C Hamano
2025-03-07 19:41             ` Usman Akinyemi
2025-03-07 23:34     ` [Outreachy PATCH v4 0/8] stop using the_repository global variable Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 1/8] config: teach repo_config to allow `repo` to be NULL Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 2/8] builtin/verify-tag: stop using `the_repository` Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 3/8] builtin/verify-commit: " Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 4/8] builtin/send-pack: " Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 5/8] builtin/pack-refs: " Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 6/8] builtin/ls-files: " Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 7/8] builtin/for-each-ref: " Usman Akinyemi
2025-03-07 23:35       ` [PATCH v4 8/8] builtin/checkout-index: " Usman Akinyemi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250219203349.787173-1-usmanakinyemi202@gmail.com \
    --to=usmanakinyemi202@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johncai86@gmail.com \
    --cc=me@ttaylorr.com \
    --cc=ps@pks.im \
    --cc=shejialuo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).