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

Re: [PATCH 3/4] apply: remove the_repository global variable

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 24, 2024, 18:50 UTC
Message-ID
<xmqqtte4sx7p.fsf@gitster.g>
In-Reply-To
<xmqq7cb0ucm0.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 14 quoted lines
>> -	if (init_apply_state(&state, the_repository, prefix))
>> +	if (init_apply_state(&state, repo, prefix))
>>  		exit(128);
>
> Hmph, the reason why we do not segfault with this patch is because
> repo will _always_ be the_repository due to the previous change.
>
> I am not sure if [1/4] is an improvement, though.  We used to be
> able to tell if we were running in a repository, or we were running
> in "nongit" mode, by looking at the NULL-ness of repo (which was
> UNUSED because we weren't taking advantage of that).  
>
> With [1/4], it no longer is possible.  From the point of view of API
> to call into builtin implementations, it smells like a regression.
We can avoid the regression by passing the discovered "nongit" (aka
"are we outside of a repository?") bit separately, perhaps like
this.  With such a change, I do not mind this change too much, but
pretending that we do not depend on the_repository (by removing the
textual mention of the_repository), but still depending on
the_repository (which points at the_repo) may be losing a bigger
picture, the true reason why we want to reduce the dependence on
the_repository.  We still need "if the hash-algo is not initialized
fall back to SHA-1" code here, but that is an overly broad fallback
that we would rather want to tighten to something like "we know we
have no reasonable value to initialize hash-algo in the_repository
if we are outside a repository, so initialize hash-algo if we are
outside any repository" (leaving it an error not have hash-algo in
"repo" if we _are_ in a repository).
   
diff --git c/git.c w/git.c
index 2fbea24ec9..579c6fa36d 100644
--- c/git.c
+++ w/git.c
@@ -447,6 +447,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
 	struct stat st;
 	const char *prefix;
 	int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY));
+	int nongit = 0;
 
 	help = argc == 2 && !strcmp(argv[1], "-h");
 	if (help && (run_setup & RUN_SETUP))
@@ -456,8 +457,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
 	if (run_setup & RUN_SETUP) {
 		prefix = setup_git_directory();
 	} else if (run_setup & RUN_SETUP_GENTLY) {
-		int nongit_ok;
-		prefix = setup_git_directory_gently(&nongit_ok);
+		prefix = setup_git_directory_gently(&nongit);
 	} else {
 		prefix = NULL;
 	}
@@ -480,7 +480,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
 	trace2_cmd_name(p->cmd);
 
 	validate_cache_entries(repo->index);
-	status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
+	status = p->fn(argc, argv, prefix, run_setup ? repo : NULL, nongit);
 	validate_cache_entries(repo->index);
 
 	if (status)
Previous: Junio C HamanoNext: John Cai
Message 11 of 44 in “Remove the_repository global for am, annotate, apply, archive builtins”
  1. 0/4 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Sep 24, 2024
  2. 1/4 git: pass in repo for RUN_SETUP_GENTLYJohn Cai via GitGitGadget, Sep 24, 2024
  3. shejialuoSep 24, 2024
  4. Junio C HamanoSep 24, 2024
  5. Junio C HamanoSep 24, 2024
  6. Patrick SteinhardtSep 26, 2024
  7. Junio C HamanoSep 26, 2024
  8. 2/4 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Sep 24, 2024
  9. 3/4 apply: remove the_repository global variableJohn Cai via GitGitGadget, Sep 24, 2024
  10. Junio C HamanoSep 24, 2024
  11. Junio C HamanoSep 24, 2024
  12. John CaiSep 26, 2024
  13. Junio C HamanoSep 26, 2024
  14. 4/4 archive: remove the_repository global variableJohn Cai via GitGitGadget, Sep 24, 2024
  15. Junio C HamanoSep 24, 2024
  16. 0/4 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Sep 30, 2024
  17. 1/4 git: pass in repo for RUN_SETUP_GENTLYJohn Cai via GitGitGadget, Sep 30, 2024
  18. Junio C HamanoSep 30, 2024
  19. shejialuoOct 1, 2024
  20. 2/4 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Sep 30, 2024
  21. Junio C HamanoSep 30, 2024
  22. 4/4 archive: remove the_repository global variableJohn Cai via GitGitGadget, Sep 30, 2024
  23. Junio C HamanoSep 30, 2024
  24. johncai86@gmail.comOct 4, 2024
  25. 3/4 apply: remove the_repository global variableJohn Cai via GitGitGadget, Sep 30, 2024
  26. Junio C HamanoSep 30, 2024
  27. shejialuoOct 1, 2024
  28. Patrick SteinhardtOct 1, 2024
  29. shejialuoOct 1, 2024
  30. Patrick SteinhardtOct 1, 2024
  31. Junio C HamanoOct 1, 2024
  32. johncai86@gmail.comOct 3, 2024
  33. 0/3 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Oct 5, 2024
  34. 1/3 git: pass in repo to builtin based on setup_git_directory_gentlyJohn Cai via GitGitGadget, Oct 5, 2024
  35. shejialuoOct 5, 2024
  36. 2/3 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Oct 5, 2024
  37. 3/3 archive: remove the_repository global variableJohn Cai via GitGitGadget, Oct 5, 2024
  38. shejialuoOct 5, 2024
  39. johncai86@gmail.comOct 10, 2024
  40. 0/3 Remove the_repository global for am, annotate, apply, archive builtinsJohn Cai via GitGitGadget, Oct 10, 2024
  41. 1/3 git: pass in repo to builtin based on setup_git_directory_gentlyJohn Cai via GitGitGadget, Oct 10, 2024
  42. 2/3 annotate: remove usage of the_repository globalJohn Cai via GitGitGadget, Oct 10, 2024
  43. 3/3 archive: remove the_repository global variableJohn Cai via GitGitGadget, Oct 10, 2024
  44. Junio C HamanoOct 11, 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.