Stop using `the_repository` in "config.c"
cover Stop using `the_repository` in "config.c"
Hi,
I found that there had been a bunch of callsites in code
not marked with USE_THE_REPOSITORY_VARIABLE that still implicitly relied on the_repository due to calling interfaces of "config.c". This patch series has the goal of fixing that and making the dependency implicit. This is done by making "config.c" stop using the_repository while moving its interfaces that do use it into "config.h", guarded by the USE_THE_REPOSITORY_VARIABLE macro.
The series is structured as follows:
- Patches 1 to 7 adapt "path.{c,h}" to become the_repository-clean. This is required because "config.c" relies on the "path" subsystem quite a lot.
- Patches 8 and 9 introduce functions that take a struct repository where we didn't yet equivalents for the repo-less variants.
- Patches 10 to 16 adapt various functions to take a struct repository as input.
- Patches 17 and 18 fix up some functions that take a struct repository, but still rely on the_repository.
- Patches 19 and 20 then hide config functions that rely on the_repository behind USE_THE_REPOSITORY_VARIABLE.
The series is built on top of master at 406f326d27 (The second batch, 2024-08-01) with ps/refs-wo-the-repository at 9d36dbd1ff (refs/reftable:
stop using the_repository, 2024-07-30) merged into it.
Thanks!
Patrick
Patrick Steinhardt (20):
path: expose do_git_path() as repo_git_pathv()
path: expose do_git_common_path() as strbuf_git_common_pathv()
editor: do not rely on the_repository for interactive edits
hooks: remove implicit dependency on the_repository
path: stop relying on the_repository when reporting garbage
path: stop relying on the_repository in worktree_git_path()
path: hide functions using the_repository by default
config: introduce missing setters that take repo as parameter
config: expose repo_config_clear()
config: pass repo to git_config_get_index_threads()
config: pass repo to git_config_get_split_index()
config: pass repo to git_config_get_max_percent_split_change()
config: pass repo to git_config_get_expiry()
config: pass repo to git_config_get_expiry_in_days()
config: pass repo to git_die_config()
config: pass repo to functions that rename or copy sections
config: don't have setters depend on the_repository
config: don't depend on the_repository with branch conditions
global: prepare for hiding away repo-less config functions
config: hide functions using the_repository by default
add-patch.c | 3 +- builtin/am.c | 9 +- builtin/branch.c | 7 +- builtin/bugreport.c | 2 +- builtin/checkout.c | 2 +- builtin/clone.c | 2 +- builtin/config.c | 16 +- builtin/count-objects.c | 2 +- builtin/fast-import.c | 4 +- builtin/fsck.c | 2 +- builtin/gc.c | 8 +- builtin/hook.c | 2 +- builtin/merge.c | 2 +- builtin/notes.c | 2 +- builtin/rebase.c | 2 +- builtin/receive-pack.c | 10 +- builtin/remote.c | 4 +- builtin/submodule--helper.c | 2 +- builtin/update-index.c | 4 +- builtin/worktree.c | 6 +- commit.c | 2 +- compat/fsmonitor/fsm-ipc-darwin.c | 2 + compat/precompose_utf8.c | 1 + config.c | 225 ++++++++--------------- config.h | 285 +++++++++++++++++++++--------- connect.c | 2 + credential.c | 2 + daemon.c | 2 + editor.c | 14 +- editor.h | 3 +- fsmonitor.c | 2 + gpg-interface.c | 2 + graph.c | 2 + hook.c | 21 +-- hook.h | 13 +- imap-send.c | 2 + mailinfo.c | 2 + merge-ll.c | 2 + parallel-checkout.c | 2 + path.c | 97 +++------- path.h | 167 +++++++++++------ protocol.c | 2 + read-cache.c | 22 +-- refs.c | 4 +- refs/packed-backend.c | 2 + refs/reftable-backend.c | 2 + rerere.c | 4 +- reset.c | 2 +- revision.c | 2 +- sequencer.c | 6 +- sideband.c | 2 + submodule.c | 2 +- t/helper/test-advise.c | 2 + t/helper/test-config.c | 2 + t/helper/test-userdiff.c | 2 + trailer.c | 2 + transport.c | 2 +- versioncmp.c | 2 + worktree.c | 2 +- wt-status.c | 14 +- 60 files changed, 564 insertions(+), 455 deletions(-)
Signature · 1 line
2.46.0.dirty
PATCH 1/20 path: expose `do_git_path()` as `repo_git_pathv()`
We're about to move functions of the "path" subsytem that do not use a struct repository into "path.h" as static inlined functions. This will require us to call do_git_path(), which is internal to "path.c".
Expose the function as repo_git_pathv() to prepare for the change.
--- path.c | 20 ++++++++++---------- path.h | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-)
path.c +10 -10
@@ -417,9 +417,9 @@ static void strbuf_worktree_gitdir(struct strbuf *buf,strbuf_git_common_path (buf, repo,"worktrees/%s" , wt->id); } -static void do_git_path (const struct repository *repo, -const struct worktree *wt,struct strbuf *buf, -const char *fmt,va_list args) +void repo_git_pathv (const struct repository *repo, +const struct worktree *wt,struct strbuf *buf, +const char *fmt,va_list args) {int gitdir_len;strbuf_worktree_gitdir (buf, repo, wt);
@@ -438,7 +438,7 @@ char *repo_git_path(const struct repository *repo,struct strbuf path =STRBUF_INIT ;va_list args;va_start (args, fmt); -do_git_path (repo,NULL , &path, fmt, args); +repo_git_pathv (repo,NULL , &path, fmt, args);va_end (args);return strbuf_detach (&path,NULL ); }
@@ -449,7 +449,7 @@ void strbuf_repo_git_path(struct strbuf *sb, {va_list args;va_start (args, fmt); -do_git_path (repo,NULL , sb, fmt, args); +repo_git_pathv (repo,NULL , sb, fmt, args);va_end (args); }
@@ -458,7 +458,7 @@ char *git_path_buf(struct strbuf *buf, const char *fmt, ...)va_list args;strbuf_reset (buf);va_start (args, fmt); -do_git_path (the_repository,NULL , buf, fmt, args); +repo_git_pathv (the_repository,NULL , buf, fmt, args);va_end (args);return buf->buf; }
@@ -467,7 +467,7 @@ void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) {va_list args;va_start (args, fmt); -do_git_path (the_repository,NULL , sb, fmt, args); +repo_git_pathv (the_repository,NULL , sb, fmt, args);va_end (args); }
@@ -476,7 +476,7 @@ const char *git_path(const char *fmt, ...)struct strbuf *pathname =get_pathname ();va_list args;va_start (args, fmt); -do_git_path (the_repository,NULL , pathname, fmt, args); +repo_git_pathv (the_repository,NULL , pathname, fmt, args);va_end (args);return pathname->buf; }
@@ -486,7 +486,7 @@ char *git_pathdup(const char *fmt, ...)struct strbuf path =STRBUF_INIT ;va_list args;va_start (args, fmt); -do_git_path (the_repository,NULL , &path, fmt, args); +repo_git_pathv (the_repository,NULL , &path, fmt, args);va_end (args);return strbuf_detach (&path,NULL ); }
@@ -517,7 +517,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)struct strbuf *pathname =get_pathname ();va_list args;va_start (args, fmt); -do_git_path (the_repository, wt, pathname, fmt, args); +repo_git_pathv (the_repository, wt, pathname, fmt, args);va_end (args);return pathname->buf; }
path.h +8 -0
@@ -66,6 +66,14 @@ char *repo_git_path(const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 2, 3))); +/* +* Print a path into the git directory of repository `repo` into the provided +* buffer. +*/ +void repo_git_pathv (const struct repository *repo, +const struct worktree *wt,struct strbuf *buf, +const char *fmt,va_list args); +/* * Construct a path into the git directory of repository `repo` and append it * to the provided buffer `sb`.
Signature · 1 line
2.46.0.dirty
Re: [PATCH 01/20] path: expose `do_git_path()` as `repo_git_pathv()`
Quoted 1 line · Patrick Steinhardt
We're about to move functions of the "path" subsytem that do not use a
s/subsytem/subsystem/
Quoted 2 lines
struct repositoryinto "path.h" as static inlined functions. This will require us to calldo_git_path(), which is internal to "path.c".
So in other words, functions leveraging the_repository in "path.c" are going to be moved to "path.h". Since these functions depend on do_git_path(), we need to expose it. Makes sense so far.
Quoted 3 lines
Expose the function as
repo_git_pathv()to prepare for the change.Signed-off-by Patrick Steinhardt <[email protected]>
[snip]
path.h char *repo_git_path(const struct repository *repo, · line 76
Quoted 8 lines
path.h +8
-0+/* +* Print a path into the git directory of repository `repo` into the provided +* buffer. +*/ +void repo_git_pathv (const struct repository *repo, +const struct worktree *wt,struct strbuf *buf, +const char *fmt,va_list args); +
Out of curiousity, do we have a preferred convention for how functions accepting va_list are named? Searching through the codebase, I don't see a ton of consistency, but I have noticed examples prefixed with "v".
Re: [PATCH 01/20] path: expose `do_git_path()` as `repo_git_pathv()`
Quoted 11 lines · Justin Tobler
Quoted 1 line · Patrick Steinhardt
We're about to move functions of the "path" subsytem that do not use a
s/subsytem/subsystem/
Quoted 2 lines
struct repositoryinto "path.h" as static inlined functions. This will require us to calldo_git_path(), which is internal to "path.c".So in other words, functions leveraging
the_repositoryin "path.c" are going to be moved to "path.h". Since these functions depend ondo_git_path(), we need to expose it. Makes sense so far.
Yup.
Quoted 4 lines
Quoted 3 lines
Expose the function as
repo_git_pathv()to prepare for the change.Signed-off-by Patrick Steinhardt <[email protected]>[snip]
Quoted 12 lines
path.h char *repo_git_path(const struct repository *repo, · line 76
Quoted 8 lines
path.h +8
-0+/* +* Print a path into the git directory of repository `repo` into the provided +* buffer. +*/ +void repo_git_pathv (const struct repository *repo, +const struct worktree *wt,struct strbuf *buf, +const char *fmt,va_list args); +Out of curiousity, do we have a preferred convention for how functions accepting
va_listare named? Searching through the codebase, I don't see a ton of consistency, but I have noticed examples prefixed with "v".
We of course have strbuf_vaddf() and the likes of vsnprintf() and xstrvmt(), which indeed have the "v" as a prefix. But is repo_git_vpath() better than repo_git_pathv() in this case here? I dunno.
In any case, we already have strbuf_git_common_pathv(). So I'm leaning more towards local consistency as opposed to global consistency. Even if naming in our config interface feels like the wild west anyway.
Patrick
PATCH 2/20 path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`
In reply to Patrick SteinhardtWith the same reasoning as the preceding commit, expose the function do_git_common_path() as strbuf_git_common_pathv().
--- path.c | 22 +++++++++++----------- path.h | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-)
path.c +11 -11
@@ -617,16 +617,16 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path,return err; } -static void do_git_common_path (const struct repository *repo, -struct strbuf *buf, -const char *fmt, -va_list args) +void strbuf_git_common_pathv (struct strbuf *sb, +const struct repository *repo, +const char *fmt, +va_list args) { -strbuf_addstr (buf, repo->commondir); -if (buf->len && !is_dir_sep (buf->buf[buf->len -1 ])) -strbuf_addch (buf,'/' ); -strbuf_vaddf (buf, fmt, args); -strbuf_cleanup_path (buf); +strbuf_addstr (sb, repo->commondir); +if (sb->len && !is_dir_sep (sb->buf[sb->len -1 ])) +strbuf_addch (sb,'/' ); +strbuf_vaddf (sb, fmt, args); +strbuf_cleanup_path (sb); }const char *git_common_path (const char *fmt, ...)
@@ -634,7 +634,7 @@ const char *git_common_path(const char *fmt, ...)struct strbuf *pathname =get_pathname ();va_list args;va_start (args, fmt); -do_git_common_path (the_repository, pathname, fmt, args); +strbuf_git_common_pathv (pathname, the_repository, fmt, args);va_end (args);return pathname->buf; }
@@ -645,7 +645,7 @@ void strbuf_git_common_path(struct strbuf *sb, {va_list args;va_start (args, fmt); -do_git_common_path (repo, sb, fmt, args); +strbuf_git_common_pathv (sb, repo, fmt, args);va_end (args); }
path.h +4 -1
@@ -37,6 +37,10 @@ void strbuf_git_common_path(struct strbuf *sb,const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 3, 4))); +void strbuf_git_common_pathv (struct strbuf *sb, +const struct repository *repo, +const char *fmt, +va_list args);/* * Return a statically allocated path into the main repository's
@@ -45,7 +49,6 @@ void strbuf_git_common_path(struct strbuf *sb,const char *git_common_path (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); -/* * The `git_path` family of functions will construct a path into a repository's * git directory.
Signature · 1 line
2.46.0.dirty
Re: [PATCH 02/20] path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`
Quoted 15 lines · Patrick Steinhardt
With the same reasoning as the preceding commit, expose the function
do_git_common_path()asstrbuf_git_common_pathv().Signed-off-by Patrick Steinhardt <[email protected]>--- path.c | 22 +++++++++++----------- path.h | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-)path.c +0
-0@@ -617,16 +617,16 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path,return err;
path.c int strbuf_git_path_submodule(struct strbuf *buf, const char *path, · line 623
Quoted 10 lines
path.c +4
-4} -static void do_git_common_path (const struct repository *repo, -struct strbuf *buf, -const char *fmt, -va_list args) +void strbuf_git_common_pathv (struct strbuf *sb, +const struct repository *repo, +const char *fmt, +va_list args)
Here we reorder the arguments to make strbuf first. I assume we are do this to align with the preexisting strbuf_git_common_path() and use the "strbuf_" prefix in the function name.
In the previous commit we used the "repo_" prefix for repo_git_pathv(). Would it make sense to be consistent here? All these functions are operating on the provided buffer, but for a given repository. Not sure what would be most appropriate here.
Quoted 12 lines
path.c +5
-5{ -strbuf_addstr (buf, repo->commondir); -if (buf->len && !is_dir_sep (buf->buf[buf->len -1 ])) -strbuf_addch (buf,'/' ); -strbuf_vaddf (buf, fmt, args); -strbuf_cleanup_path (buf); +strbuf_addstr (sb, repo->commondir); +if (sb->len && !is_dir_sep (sb->buf[sb->len -1 ])) +strbuf_addch (sb,'/' ); +strbuf_vaddf (sb, fmt, args); +strbuf_cleanup_path (sb); }
Re: [PATCH 02/20] path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`
Quoted 4 lines · Justin Tobler
Quoted 4 lines
path.c +0
-4-static void do_git_common_path (const struct repository *repo, -struct strbuf *buf, -const char *fmt, -va_list args)
Quoted 8 lines
path.c int strbuf_git_path_submodule(struct strbuf *buf, const char *path, · line 623
Quoted 4 lines
path.c +4
-0+void strbuf_git_common_pathv (struct strbuf *sb, +const struct repository *repo, +const char *fmt, +va_list args)Here we reorder the arguments to make
strbuffirst. I assume we are do this to align with the preexistingstrbuf_git_common_path()and use the "strbuf_" prefix in the function name.
I thought that we already established as a general guideline that "strbuf_" should be cleaned up so that functions that happen to use strbuf merely as a way to carry parameters into or results out of them but are not primarily about string manipulation are renamed out of the "strbuf_" namespace.
https://lore.kernel.org/git/ZqiLA0bGYZfH1OWD@tanuki/
And this is about getting a path, which is communicated via a "struct strbuf", and not the standard "char *". That is a prime example of a function that we do *not* want to stress strbuf-ness of the function.
Quoted 4 lines
In the previous commit we used the "
repo_" prefix forrepo_git_pathv(). Would it make sense to be consistent here? All these functions are operating on the provided buffer, but for a given repository. Not sure what would be most appropriate here.
Yes, if the function is about obtaining the path for a file in a given repository's metadata directory, and its association with "strbuf" is that it merely happens to use it instead of "char *", it should not be named as if "strbuf_" ness is the primary characteristics of the function.
strbuf_cleanup_path() should also be renamed for the same reason.
Quoted 12 lines
Quoted 12 lines
{
path.c +5
-5-strbuf_addstr (buf, repo->commondir); -if (buf->len && !is_dir_sep (buf->buf[buf->len -1 ])) -strbuf_addch (buf,'/' ); -strbuf_vaddf (buf, fmt, args); -strbuf_cleanup_path (buf); +strbuf_addstr (sb, repo->commondir); +if (sb->len && !is_dir_sep (sb->buf[sb->len -1 ])) +strbuf_addch (sb,'/' ); +strbuf_vaddf (sb, fmt, args); +strbuf_cleanup_path (sb); }
Re: [PATCH 02/20] path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`
Quoted 33 lines · Junio C Hamano
Quoted 4 lines · Justin Tobler
Quoted 4 lines
path.c +0
-4-static void do_git_common_path (const struct repository *repo, -struct strbuf *buf, -const char *fmt, -va_list args)Quoted 8 lines
path.c int strbuf_git_path_submodule(struct strbuf *buf, const char *path, · line 623
Quoted 4 lines
path.c +4
-0+void strbuf_git_common_pathv (struct strbuf *sb, +const struct repository *repo, +const char *fmt, +va_list args)Here we reorder the arguments to make
strbuffirst. I assume we are do this to align with the preexistingstrbuf_git_common_path()and use the "strbuf_" prefix in the function name.I thought that we already established as a general guideline that "
strbuf_" should be cleaned up so that functions that happen to use strbuf merely as a way to carry parameters into or results out of them but are not primarily about string manipulation are renamed out of the "strbuf_" namespace.https://lore.kernel.org/git/ZqiLA0bGYZfH1OWD@tanuki/
And this is about getting a path, which is communicated via a "struct strbuf", and not the standard "char *". That is a prime example of a function that we do *not* want to stress strbuf-ness of the function.
Quoted 4 lines
In the previous commit we used the "
repo_" prefix forrepo_git_pathv(). Would it make sense to be consistent here? All these functions are operating on the provided buffer, but for a given repository. Not sure what would be most appropriate here.
Quoted 7 lines
Yes, if the function is about obtaining the path for a file in a given repository's metadata directory, and its association with "strbuf" is that it merely happens to use it instead of "char *", it should not be named as if "
strbuf_" ness is the primary characteristics of the function.
strbuf_cleanup_path()should also be renamed for the same reason.
Agreed. I was doing it for consistency's sake in this case, but let's rather not make the overall interface any weirder than it already is.
Patrick
Re: [PATCH 02/20] path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`
Quoted 10 lines · Patrick Steinhardt
Quoted 7 lines
Yes, if the function is about obtaining the path for a file in a given repository's metadata directory, and its association with "strbuf" is that it merely happens to use it instead of "char *", it should not be named as if "
strbuf_" ness is the primary characteristics of the function.
strbuf_cleanup_path()should also be renamed for the same reason.Agreed. I was doing it for consistency's sake in this case, but let's rather not make the overall interface any weirder than it already is.
Thanks, then we are in agreement.
PATCH 3/20 editor: do not rely on `the_repository` for interactive edits
In reply to Patrick SteinhardtWe implicitly rely on the_repository when editing a file interactively because we call git_path(). Adapt the function to instead take a sturct repository as parameter so that we can remove this hidden dependency.
--- add-patch.c | 3 ++- editor.c | 12 +++++++----- editor.h | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-)
add-patch.c +2 -1
@@ -1140,7 +1140,8 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)"removed, then the edit is\n" "aborted and the hunk is left unchanged.\n")); -if (strbuf_edit_interactively (&s->buf,"addp-hunk-edit.diff" ,NULL ) <0 ) +if (strbuf_edit_interactively (&s->buf,"addp-hunk-edit.diff" ,NULL , + the_repository) <0 )return -1 ;/* strip out commented lines */
editor.c +7 -5
@@ -134,13 +134,15 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer, }int strbuf_edit_interactively (struct strbuf *buffer,const char *path, -const char *const *env) +const char *const *env,struct repository *r) { -char *path2 =NULL ; +struct strbuf sb =STRBUF_INIT ;int fd, res =0 ; -if (!is_absolute_path (path)) - path = path2 =xstrdup (git_path ("%s" , path)); +if (!is_absolute_path (path)) { +strbuf_repo_git_path (&sb, r,"%s" , path); + path = sb.buf; + } fd =open (path,O_WRONLY |O_CREAT |O_TRUNC ,0666 );if (fd <0 )
@@ -157,6 +159,6 @@ int strbuf_edit_interactively(struct strbuf *buffer, const char *path,unlink (path); } -free (path2); +strbuf_release (&sb);return res; }
editor.h +2 -1
@@ -1,6 +1,7 @@#ifndef EDITOR_H #define EDITOR_H +struct repository ;struct strbuf ;const char *git_editor (void );
@@ -29,6 +30,6 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,* If `path` is relative, it refers to a file in the `.git` directory. */ int strbuf_edit_interactively (struct strbuf *buffer,const char *path, -const char *const *env); +const char *const *env,struct repository *r);#endif
Signature · 1 line
2.46.0.dirty
Re: [PATCH 03/20] editor: do not rely on `the_repository` for interactive edits
Quoted 3 lines · Patrick Steinhardt
We implicitly rely on
the_repositorywhen editing a file interactively because we callgit_path(). Adapt the function to instead take asturct repositoryas parameter so that we can remove this hidden
s/sturct/struct/
s/parameter/a parameter/
Quoted 34 lines
dependency.
Signed-off-by Patrick Steinhardt <[email protected]>--- add-patch.c | 3 ++- editor.c | 12 +++++++----- editor.h | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-)add-patch.c +2
-1@@ -1140,7 +1140,8 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)"removed, then the edit is\n" "aborted and the hunk is left unchanged.\n")); -if (strbuf_edit_interactively (&s->buf,"addp-hunk-edit.diff" ,NULL ) <0 ) +if (strbuf_edit_interactively (&s->buf,"addp-hunk-edit.diff" ,NULL , + the_repository) <0 )return -1 ;/* strip out commented lines */ editor.c +1
-1@@ -134,13 +134,15 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer, }int strbuf_edit_interactively (struct strbuf *buffer,const char *path, -const char *const *env) +const char *const *env,struct repository *r) {
editor.c int launch_sequence_editor(const char *path, struct strbuf *buffer, · line 145
Quoted 10 lines
editor.c +5
-3-char *path2 =NULL ; +struct strbuf sb =STRBUF_INIT ;int fd, res =0 ; -if (!is_absolute_path (path)) - path = path2 =xstrdup (git_path ("%s" , path)); +if (!is_absolute_path (path)) { +strbuf_repo_git_path (&sb, r,"%s" , path); + path = sb.buf; + }
By switching from git_path() to strbuf_repo_git_path(), strbuf_edit_interactively() no longer implicitly depends on the_repository. This requires a struct repository be injected into strbuf_edit_interactively(). The function signature is updated along with the single call site. The small cleanup also looks good. Makes sense to me.
Non-blocking: Instead of appending struct repository as the last argument, it might be nicer to match strbuf_repo_git_path() and place it as the second argument.
Quoted 33 lines
editor.c +1
-1fd =open (path,O_WRONLY |O_CREAT |O_TRUNC ,0666 );if (fd <0 )@@ -157,6 +159,6 @@ int strbuf_edit_interactively(struct strbuf *buffer, const char *path,unlink (path); } -free (path2); +strbuf_release (&sb);return res; }editor.h +2
-1@@ -1,6 +1,7 @@#ifndef EDITOR_H #define EDITOR_H +struct repository ;struct strbuf ;const char *git_editor (void );@@ -29,6 +30,6 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,* If `path` is relative, it refers to a file in the `.git` directory. */ int strbuf_edit_interactively (struct strbuf *buffer,const char *path, -const char *const *env); +const char *const *env,struct repository *r);#endif Signature · 1 line
2.46.0.dirty
PATCH 4/20 hooks: remove implicit dependency on `the_repository`
In reply to Patrick SteinhardtWe implicitly depend on the_repository in our hook subsystem because we use strbuf_git_path() to compute hook paths. Remove this dependency by accepting a struct repository as parameter instead.
--- builtin/am.c | 9 +++++---- builtin/bugreport.c | 2 +- builtin/checkout.c | 2 +- builtin/clone.c | 2 +- builtin/gc.c | 2 +- builtin/hook.c | 2 +- builtin/merge.c | 2 +- builtin/rebase.c | 2 +- builtin/receive-pack.c | 10 +++++----- builtin/worktree.c | 2 +- commit.c | 2 +- hook.c | 21 +++++++++++---------- hook.h | 13 ++++++++----- read-cache.c | 6 +++--- refs.c | 2 +- reset.c | 2 +- sequencer.c | 6 +++--- transport.c | 2 +- 18 files changed, 47 insertions(+), 42 deletions(-)
builtin/am.c +5 -4
@@ -490,7 +490,8 @@ static int run_applypatch_msg_hook(struct am_state *state)assert (state->msg);if (!state->no_verify) - ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL ); + ret =run_hooks_l (the_repository,"applypatch-msg" , +am_path (state,"final-commit" ),NULL );if (!ret) {FREE_AND_NULL (state->msg);
@@ -512,7 +513,7 @@ static int run_post_rewrite_hook(const struct am_state *state)strvec_push (&opt.args,"rebase" ); opt.path_to_stdin =am_path (state,"rewritten" ); -return run_hooks_opt ("post-rewrite" , &opt); +return run_hooks_opt (the_repository,"post-rewrite" , &opt); }/**
@@ -1663,7 +1664,7 @@ static void do_commit(const struct am_state *state)const char *reflog_msg, *author, *committer =NULL ;struct strbuf sb =STRBUF_INIT ; -if (!state->no_verify &&run_hooks ("pre-applypatch" )) +if (!state->no_verify &&run_hooks (the_repository,"pre-applypatch" ))exit (1 );if (write_index_as_tree (&tree, the_repository->index,get_index_file (),0 ,NULL ))
@@ -1716,7 +1717,7 @@ static void do_commit(const struct am_state *state)fclose (fp); } -run_hooks ("post-applypatch" ); +run_hooks (the_repository,"post-applypatch" );free_commit_list (parents);strbuf_release (&sb);
builtin/bugreport.c +1 -1
@@ -58,7 +58,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 (hook)) +if (hook_exists (the_repository, hook))strbuf_addf (hook_info,"%s\n" , hook); } }
builtin/checkout.c +1 -1
@@ -125,7 +125,7 @@ static void branch_info_release(struct branch_info *info)static int post_checkout_hook (struct commit *old_commit,struct commit *new_commit,int changed) { -return run_hooks_l ("post-checkout" , +return run_hooks_l (the_repository,"post-checkout" ,oid_to_hex (old_commit ? &old_commit->object.oid :null_oid ()),oid_to_hex (new_commit ? &new_commit->object.oid :null_oid ()), changed ?"1" :"0" ,NULL );
builtin/clone.c +1 -1
@@ -788,7 +788,7 @@ static int checkout(int submodule_progress, int filter_submodules)if (write_locked_index (the_repository->index, &lock_file,COMMIT_LOCK ))die (_ ("unable to write new index file" )); - err |=run_hooks_l ("post-checkout" ,oid_to_hex (null_oid ()), + err |=run_hooks_l (the_repository,"post-checkout" ,oid_to_hex (null_oid ()),oid_to_hex (&oid),"1" ,NULL );if (!err && (option_recurse_submodules.nr >0 )) {
builtin/gc.c +1 -1
@@ -463,7 +463,7 @@ static int need_to_gc(void)else return 0 ; -if (run_hooks ("pre-auto-gc" )) +if (run_hooks (the_repository,"pre-auto-gc" ))return 0 ;return 1 ; }
builtin/hook.c +1 -1
@@ -58,7 +58,7 @@ static int run(int argc, const char **argv, const char *prefix) hook_name = argv[0 ];if (!ignore_missing) opt.error_if_missing =1 ; - ret =run_hooks_opt (hook_name, &opt); + ret =run_hooks_opt (the_repository, hook_name, &opt);if (ret <0 )/* error() return */ ret =1 ;return ret;
builtin/merge.c +1 -1
@@ -478,7 +478,7 @@ static void finish(struct commit *head_commit, }/* Run a post-merge hook */ -run_hooks_l ("post-merge" , squash ?"1" :"0" ,NULL ); +run_hooks_l (the_repository,"post-merge" , squash ?"1" :"0" ,NULL );if (new_head)apply_autostash_ref (the_repository,"MERGE_AUTOSTASH" );
builtin/rebase.c +1 -1
@@ -1774,7 +1774,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)/* If a hook exists, give it a chance to interrupt*/ if (!ok_to_skip_pre_rebase && -run_hooks_l ("pre-rebase" , options.upstream_arg, +run_hooks_l (the_repository,"pre-rebase" , options.upstream_arg, argc ? argv[0 ] :NULL ,NULL ))die (_ ("The pre-rebase hook refused to rebase." ));
builtin/receive-pack.c +5 -5
@@ -792,7 +792,7 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,struct child_process proc =CHILD_PROCESS_INIT ;struct async muxer;int code; -const char *hook_path =find_hook (hook_name); +const char *hook_path =find_hook (the_repository, hook_name);if (!hook_path)return 0 ;
@@ -922,7 +922,7 @@ static int run_update_hook(struct command *cmd) {struct child_process proc =CHILD_PROCESS_INIT ;int code; -const char *hook_path =find_hook ("update" ); +const char *hook_path =find_hook (the_repository,"update" );if (!hook_path)return 0 ;
@@ -1098,7 +1098,7 @@ static int run_proc_receive_hook(struct command *commands,int hook_use_push_options =0 ;int version =0 ;int code; -const char *hook_path =find_hook ("proc-receive" ); +const char *hook_path =find_hook (the_repository,"proc-receive" );if (!hook_path) {rp_error ("cannot find hook 'proc-receive'" );
@@ -1409,7 +1409,7 @@ static const char *push_to_checkout(unsigned char *hash,strvec_pushf (env,"GIT_WORK_TREE=%s" ,absolute_path (work_tree));strvec_pushv (&opt.env, env->v);strvec_push (&opt.args,hash_to_hex (hash)); -if (run_hooks_opt (push_to_checkout_hook, &opt)) +if (run_hooks_opt (the_repository, push_to_checkout_hook, &opt))return "push-to-checkout hook declined" ;else return NULL ;
@@ -1618,7 +1618,7 @@ static void run_update_post_hook(struct command *commands)struct child_process proc =CHILD_PROCESS_INIT ;const char *hook; - hook =find_hook ("post-update" ); + hook =find_hook (the_repository,"post-update" );if (!hook)return ;
builtin/worktree.c +1 -1
@@ -573,7 +573,7 @@ static int add_worktree(const char *path, const char *refname, NULL); opt.dir = path; - ret =run_hooks_opt ("post-checkout" , &opt); + ret =run_hooks_opt (the_repository,"post-checkout" , &opt); }strvec_clear (&child_env);
commit.c +1 -1
@@ -1960,5 +1960,5 @@ int run_commit_hook(int editor_is_used, const char *index_file,va_end (args); opt.invoked_hook = invoked_hook; -return run_hooks_opt (name, &opt); +return run_hooks_opt (the_repository, name, &opt); }
hook.c +11 -10
@@ -10,14 +10,14 @@#include "environment.h" #include "setup.h" -const char *find_hook (const char *name) +const char *find_hook (struct repository *r,const char *name) {static struct strbuf path =STRBUF_INIT ;int found_hook;strbuf_reset (&path); -strbuf_git_path (&path,"hooks/%s" , name); +strbuf_repo_git_path (&path, r,"hooks/%s" , name); found_hook =access (path.buf,X_OK ) >=0 ;#ifdef STRIP_EXTENSION if (!found_hook) {
@@ -48,9 +48,9 @@ const char *find_hook(const char *name)return path.buf; } -int hook_exists (const char *name) +int hook_exists (struct repository *r,const char *name) { -return !!find_hook (name); +return !!find_hook (r, name); } static int pick_next_hook(struct child_process *cp,
@@ -121,7 +121,8 @@ static void run_hooks_opt_clear(struct run_hooks_opt *options)strvec_clear (&options->args); } -int run_hooks_opt (const char *hook_name,struct run_hooks_opt *options) +int run_hooks_opt (struct repository *r,const char *hook_name, +struct run_hooks_opt *options) {struct strbuf abs_path =STRBUF_INIT ;struct hook_cb_data cb_data = {
@@ -129,7 +130,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) .hook_name = hook_name, .options = options, }; -const char *const hook_path =find_hook (hook_name); +const char *const hook_path =find_hook (r, hook_name);int ret =0 ;const struct run_process_parallel_opts opts = { .tr2_category ="hook" ,
@@ -173,14 +174,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)return ret; } -int run_hooks (const char *hook_name) +int run_hooks (struct repository *r,const char *hook_name) {struct run_hooks_opt opt =RUN_HOOKS_OPT_INIT ; -return run_hooks_opt (hook_name, &opt); +return run_hooks_opt (r, hook_name, &opt); } -int run_hooks_l (const char *hook_name, ...) +int run_hooks_l (struct repository *r,const char *hook_name, ...) {struct run_hooks_opt opt =RUN_HOOKS_OPT_INIT ;va_list ap;
@@ -191,5 +192,5 @@ int run_hooks_l(const char *hook_name, ...)strvec_push (&opt.args, arg);va_end (ap); -return run_hooks_opt (hook_name, &opt); +return run_hooks_opt (r, hook_name, &opt); }
hook.h +8 -5
@@ -2,6 +2,8 @@#define HOOK_H #include "strvec.h" +struct repository ; +struct run_hooks_opt {/* Environment vars to be set for each hook */
@@ -55,12 +57,12 @@ struct hook_cb_data {* or disabled. Note that this points to static storage that will be * overwritten by further calls to find_hook and run_hook_*. */ -const char *find_hook (const char *name); +const char *find_hook (struct repository *r,const char *name);/** * A boolean version of find_hook() */ -int hook_exists (const char *hookname); +int hook_exists (struct repository *r,const char *hookname);/** * Takes a `hook_name`, resolves it to a path with find_hook(), and
@@ -70,13 +72,14 @@ int hook_exists(const char *hookname);* Returns the status code of the run hook, or a negative value on * error(). */ -int run_hooks_opt (const char *hook_name,struct run_hooks_opt *options); +int run_hooks_opt (struct repository *r,const char *hook_name, +struct run_hooks_opt *options);/** * A wrapper for run_hooks_opt() which provides a dummy "struct * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT". */ -int run_hooks (const char *hook_name); +int run_hooks (struct repository *r,const char *hook_name);/** * Like run_hooks(), a wrapper for run_hooks_opt().
@@ -87,5 +90,5 @@ int run_hooks(const char *hook_name);* hook. This function behaves like the old run_hook_le() API. */ LAST_ARG_MUST_BE_NULL -int run_hooks_l(const char *hook_name, ...); +int run_hooks_l(struct repository *r, const char *hook_name, ...);#endif
read-cache.c +3 -3
@@ -3156,9 +3156,9 @@ static int do_write_locked_index(struct index_state *istate,else ret =close_lock_file_gently (lock); -run_hooks_l ("post-index-change" , - istate->updated_workdir ?"1" :"0" , - istate->updated_skipworktree ?"1" :"0" ,NULL ); +run_hooks_l (the_repository,"post-index-change" , + istate->updated_workdir ?"1" :"0" , + istate->updated_skipworktree ?"1" :"0" ,NULL ); istate->updated_workdir =0 ; istate->updated_skipworktree =0 ;
refs.c +1 -1
@@ -2132,7 +2132,7 @@ static int run_transaction_hook(struct ref_transaction *transaction,const char *hook;int ret =0 , i; - hook =find_hook ("reference-transaction" ); + hook =find_hook (transaction->ref_store->repo,"reference-transaction" );if (!hook)return ret;
reset.c +1 -1
@@ -79,7 +79,7 @@ static int update_refs(const struct reset_head_opts *opts, reflog_head); }if (!ret && run_hook) -run_hooks_l ("post-checkout" , +run_hooks_l (the_repository,"post-checkout" ,oid_to_hex (head ? head :null_oid ()),oid_to_hex (oid),"1" ,NULL );strbuf_release (&msg);
sequencer.c +3 -3
@@ -1316,7 +1316,7 @@ static int run_rewrite_hook(const struct object_id *oldoid,struct child_process proc =CHILD_PROCESS_INIT ;int code;struct strbuf sb =STRBUF_INIT ; -const char *hook_path =find_hook ("post-rewrite" ); +const char *hook_path =find_hook (the_repository,"post-rewrite" );if (!hook_path)return 0 ;
@@ -1614,7 +1614,7 @@ static int try_to_commit(struct repository *r, } } -if (hook_exists ("prepare-commit-msg" )) { +if (hook_exists (r,"prepare-commit-msg" )) { res =run_prepare_commit_msg_hook (r, msg, hook_commit);if (res) goto out;
@@ -5149,7 +5149,7 @@ static int pick_commits(struct repository *r, hook_opt.path_to_stdin =rebase_path_rewritten_list ();strvec_push (&hook_opt.args,"rebase" ); -run_hooks_opt ("post-rewrite" , &hook_opt); +run_hooks_opt (r,"post-rewrite" , &hook_opt); }apply_autostash (rebase_path_autostash ());
transport.c +1 -1
@@ -1271,7 +1271,7 @@ static int run_pre_push_hook(struct transport *transport,struct ref *r;struct child_process proc =CHILD_PROCESS_INIT ;struct strbuf buf; -const char *hook_path =find_hook ("pre-push" ); +const char *hook_path =find_hook (the_repository,"pre-push" );if (!hook_path)return 0 ;
Signature · 1 line
2.46.0.dirty
PATCH 5/20 path: stop relying on `the_repository` when reporting garbage
In reply to Patrick SteinhardtWe access the_repository in report_linked_checkout_garbage() both directly and indirectly via get_git_dir(). Remove this dependency by instead passing a struct repository as parameter.
--- builtin/count-objects.c | 2 +- path.c | 6 +++--- path.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
builtin/count-objects.c +1 -1
@@ -113,7 +113,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)usage_with_options (count_objects_usage, opts);if (verbose) { report_garbage = real_report_garbage; -report_linked_checkout_garbage (); +report_linked_checkout_garbage (the_repository); } for_each_loose_file_in_objdir(get_object_directory(),
path.c +3 -3
@@ -365,15 +365,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,strbuf_addstr (buf,LOCK_SUFFIX ); } -void report_linked_checkout_garbage (void ) +void report_linked_checkout_garbage (struct repository *r) {struct strbuf sb =STRBUF_INIT ;const struct common_dir *p;int len; -if (!the_repository->different_commondir) +if (!r->different_commondir)return ; -strbuf_addf (&sb,"%s/" ,get_git_dir ()); +strbuf_addf (&sb,"%s/" , r->gitdir); len = sb.len;for (p = common_list; p->path; p++) {const char *path = p->path;
path.h +1 -1
@@ -158,7 +158,7 @@ int strbuf_git_path_submodule(struct strbuf *sb, const char *path, const char *fmt, ...) __attribute__((format (printf, 3, 4))); -void report_linked_checkout_garbage (void ); +void report_linked_checkout_garbage (struct repository *r);/* * You can define a static memoized git path like:
Signature · 1 line
2.46.0.dirty
PATCH 6/20 path: stop relying on `the_repository` in `worktree_git_path()`
In reply to Patrick SteinhardtWhen not provided a worktree, then worktree_git_path() will fall back to returning a path relative to the main repository. In this case, we implicitly rely on the_repository to derive the path. Remove this dependency by passing a struct repository as parameter.
--- builtin/fsck.c | 2 +- builtin/worktree.c | 4 ++-- path.c | 9 +++++++-- path.h | 5 +++-- revision.c | 2 +- worktree.c | 2 +- wt-status.c | 14 +++++++------- 7 files changed, 22 insertions(+), 16 deletions(-)
builtin/fsck.c +1 -1
@@ -1050,7 +1050,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)* and may get overwritten by other calls * while we're examining the index. */ - path =xstrdup (worktree_git_path (wt,"index" )); + path =xstrdup (worktree_git_path (the_repository, wt,"index" ));read_index_from (&istate, path,get_worktree_git_dir (wt));fsck_index (&istate, path, wt->is_current);discard_index (&istate);
builtin/worktree.c +2 -2
@@ -1146,14 +1146,14 @@ static void validate_no_submodules(const struct worktree *wt)struct strbuf path =STRBUF_INIT ;int i, found_submodules =0 ; -if (is_directory (worktree_git_path (wt,"modules" ))) { +if (is_directory (worktree_git_path (the_repository, wt,"modules" ))) {/* * There could be false positives, e.g. the "modules" * directory exists but is empty. But it's a rare case and * this simpler check is probably good enough for now. */ found_submodules =1 ; - }else if (read_index_from (&istate,worktree_git_path (wt,"index" ), + }else if (read_index_from (&istate,worktree_git_path (the_repository, wt,"index" ),get_worktree_git_dir (wt)) >0 ) {for (i =0 ; i < istate.cache_nr; i++) {struct cache_entry *ce = istate.cache[i];
path.c +7 -2
@@ -512,12 +512,17 @@ const char *mkpath(const char *fmt, ...)return cleanup_path (pathname->buf); } -const char *worktree_git_path (const struct worktree *wt,const char *fmt, ...) +const char *worktree_git_path (struct repository *r, +const struct worktree *wt,const char *fmt, ...) {struct strbuf *pathname =get_pathname ();va_list args; + +if (wt && wt->repo != r) +BUG ("worktree not connected to expected repository" ); +va_start (args, fmt); -repo_git_pathv (the_repository, wt, pathname, fmt, args); +repo_git_pathv (r, wt, pathname, fmt, args);va_end (args);return pathname->buf; }
path.h +3 -2
@@ -97,9 +97,10 @@ const char *git_path(const char *fmt, ...)* Similar to git_path() but can produce paths for a specified * worktree instead of current one */ -const char *worktree_git_path (const struct worktree *wt, +const char *worktree_git_path (struct repository *r, +const struct worktree *wt,const char *fmt, ...) - __attribute__((format (printf,2 ,3 ))); + __attribute__((format (printf,3 ,4 )));/* * Return a path into the main repository's (the_repository) git directory.
revision.c +1 -1
@@ -1872,7 +1872,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)continue ;/* current index already taken care of */ if (read_index_from (&istate, -worktree_git_path (wt,"index" ), +worktree_git_path (the_repository, wt,"index" ),get_worktree_git_dir (wt)) >0 )do_add_index_objects_to_pending (revs, &istate, flags);discard_index (&istate);
worktree.c +1 -1
@@ -252,7 +252,7 @@ const char *worktree_lock_reason(struct worktree *wt)if (!wt->lock_reason_valid) {struct strbuf path =STRBUF_INIT ; -strbuf_addstr (&path,worktree_git_path (wt,"locked" )); +strbuf_addstr (&path,worktree_git_path (the_repository, wt,"locked" ));if (file_exists (path.buf)) {struct strbuf lock_reason =STRBUF_INIT ;if (strbuf_read_file (&lock_reason, path.buf,0 ) <0 )
wt-status.c +7 -7
@@ -1618,7 +1618,7 @@ static char *get_branch(const struct worktree *wt, const char *path)struct object_id oid;const char *branch_name; -if (strbuf_read_file (&sb,worktree_git_path (wt,"%s" , path),0 ) <=0 ) +if (strbuf_read_file (&sb,worktree_git_path (the_repository, wt,"%s" , path),0 ) <=0 ) goto got_nothing;while (sb.len && sb.buf[sb.len -1 ] =='\n' )
@@ -1716,18 +1716,18 @@ int wt_status_check_rebase(const struct worktree *wt, {struct stat st; -if (!stat (worktree_git_path (wt,"rebase-apply" ), &st)) { -if (!stat (worktree_git_path (wt,"rebase-apply/applying" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"rebase-apply" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"rebase-apply/applying" ), &st)) { state->am_in_progress =1 ; -if (!stat (worktree_git_path (wt,"rebase-apply/patch" ), &st) && !st.st_size) +if (!stat (worktree_git_path (the_repository, wt,"rebase-apply/patch" ), &st) && !st.st_size) state->am_empty_patch =1 ; }else { state->rebase_in_progress =1 ; state->branch =get_branch (wt,"rebase-apply/head-name" ); state->onto =get_branch (wt,"rebase-apply/onto" ); } - }else if (!stat (worktree_git_path (wt,"rebase-merge" ), &st)) { -if (!stat (worktree_git_path (wt,"rebase-merge/interactive" ), &st)) + }else if (!stat (worktree_git_path (the_repository, wt,"rebase-merge" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"rebase-merge/interactive" ), &st)) state->rebase_interactive_in_progress =1 ;else state->rebase_in_progress =1 ;
@@ -1743,7 +1743,7 @@ int wt_status_check_bisect(const struct worktree *wt, {struct stat st; -if (!stat (worktree_git_path (wt,"BISECT_LOG" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"BISECT_LOG" ), &st)) { state->bisect_in_progress =1 ; state->bisecting_from =get_branch (wt,"BISECT_START" );return 1 ;
Signature · 1 line
2.46.0.dirty
Re: [PATCH 06/20] path: stop relying on `the_repository` in `worktree_git_path()`
Quoted 4 lines · Patrick Steinhardt
When not provided a worktree, then
worktree_git_path()will fall back to returning a path relative to the main repository. In this case, we implicitly rely onthe_repositoryto derive the path. Remove this dependency by passing astruct repositoryas parameter.
Are there many situations where worktree_git_path() would expect to not be provided a worktree? I wonder whether this implicit behavior is really necessary to begin with.
Quoted 2 lines
Signed-off-by Patrick Steinhardt <[email protected]>---
[snip]
path.c const char *mkpath(const char *fmt, ...) · line 522
Quoted 9 lines
path.c +5
-1-const char *worktree_git_path (const struct worktree *wt,const char *fmt, ...) +const char *worktree_git_path (struct repository *r, +const struct worktree *wt,const char *fmt, ...) {struct strbuf *pathname =get_pathname ();va_list args; + +if (wt && wt->repo != r) +BUG ("worktree not connected to expected repository" );
So if we receive a worktree, we expect that it should always match the main repostiory. Makes sense.
Quoted 12 lines
path.c +2
-1+va_start (args, fmt); -repo_git_pathv (the_repository, wt, pathname, fmt, args); +repo_git_pathv (r, wt, pathname, fmt, args);va_end (args);return pathname->buf; }path.h +0
-0
path.h const char *git_path(const char *fmt, ...) · line 99
Quoted 3 lines
path.h +0
-0@@ -97,9 +97,10 @@ const char *git_path(const char *fmt, ...)* Similar to git_path() but can produce paths for a specified * worktree instead of current one */
Now that the previously implicit behavior is more explicit, it might be update the comment to explain that the provided repository is used as a fallback.
path.h const char *git_path(const char *fmt, ...) · line 103
Quoted 6 lines
path.h +3
-2-const char *worktree_git_path (const struct worktree *wt, +const char *worktree_git_path (struct repository *r, +const struct worktree *wt,const char *fmt, ...) - __attribute__((format (printf,2 ,3 ))); + __attribute__((format (printf,3 ,4 )));
Overall, I quite like how this series is bubbling up the_repository usages from the bottom up. :)
Re: [PATCH 06/20] path: stop relying on `the_repository` in `worktree_git_path()`
Quoted 9 lines · Justin Tobler
Quoted 4 lines · Patrick Steinhardt
When not provided a worktree, then
worktree_git_path()will fall back to returning a path relative to the main repository. In this case, we implicitly rely onthe_repositoryto derive the path. Remove this dependency by passing astruct repositoryas parameter.Are there many situations where
worktree_git_path()would expect to not be provided a worktree? I wonder whether this implicit behavior is really necessary to begin with.
Yeah, there are cases. I found that to be somewhat weird at first, but I does make the logic easier to handle because you don't need to special case whether you do or don't have a worktree.
Quoted 4 lines
Quoted 4 lines
path.h +0
-0
Quoted 8 lines
path.h const char *git_path(const char *fmt, ...) · line 99
Quoted 4 lines
path.h +0
-0@@ -97,9 +97,10 @@ const char *git_path(const char *fmt, ...)* Similar to git_path() but can produce paths for a specified * worktree instead of current one */ Now that the previously implicit behavior is more explicit, it might be update the comment to explain that the provided repository is used as a fallback.
Good idea.
Patrick
PATCH 7/20 path: hide functions using `the_repository` by default
In reply to Patrick SteinhardtThe path subsytem provides a bunch of legacy functions that compute paths relative to the "gitdir" and "commondir" directories of the global the_repository variable. Use of those functions is discouraged, and it is easy to miss the implicit dependency on the_repository that calls to those functions may cause.
With USE_THE_REPOSITORY_VARIABLE, we have recently introduced a tool that allows us to get rid of such functions over time. With this define, we can hide away functions that have such implicit dependency such that other subsystems that want to be free of the_repository will not use them by accident.
Move all path-related functions that use the_repository into a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "path.c", allowing us to remove the definition of said preprocessor macro.
--- path.c | 52 +------------------- path.h | 147 ++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 100 insertions(+), 99 deletions(-)
path.c +1 -51
@@ -2,8 +2,6 @@* Utilities for paths and pathnames */ -#define USE_THE_REPOSITORY_VARIABLE -#include "git-compat-util.h" #include "abspath.h" #include "environment.h"
@@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode)return 0 ; } -static struct strbuf *get_pathname (void ) +struct strbuf *get_pathname (void ) {static struct strbuf pathname_array[4 ] = {STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT
@@ -453,44 +451,6 @@ void strbuf_repo_git_path(struct strbuf *sb,va_end (args); } -char *git_path_buf (struct strbuf *buf,const char *fmt, ...) -{ -va_list args; -strbuf_reset (buf); -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , buf, fmt, args); -va_end (args); -return buf->buf; -} - -void strbuf_git_path (struct strbuf *sb,const char *fmt, ...) -{ -va_list args; -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , sb, fmt, args); -va_end (args); -} - -const char *git_path (const char *fmt, ...) -{ -struct strbuf *pathname =get_pathname (); -va_list args; -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , pathname, fmt, args); -va_end (args); -return pathname->buf; -} - -char *git_pathdup (const char *fmt, ...) -{ -struct strbuf path =STRBUF_INIT ; -va_list args; -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , &path, fmt, args); -va_end (args); -return strbuf_detach (&path,NULL ); -} -char *mkpathdup (const char *fmt, ...) {struct strbuf sb =STRBUF_INIT ;
@@ -634,16 +594,6 @@ void strbuf_git_common_pathv(struct strbuf *sb,strbuf_cleanup_path (sb); } -const char *git_common_path (const char *fmt, ...) -{ -struct strbuf *pathname =get_pathname (); -va_list args; -va_start (args, fmt); -strbuf_git_common_pathv (pathname, the_repository, fmt, args); -va_end (args); -return pathname->buf; -} -void strbuf_git_common_path (struct strbuf *sb,const struct repository *repo,const char *fmt, ...)
path.h +99 -48
184 lines not on this page · raw message
Signature · 1 line
2.46.0.dirty
Re: [PATCH 07/20] path: hide functions using `the_repository` by default
Quoted 1 line · Patrick Steinhardt
The path subsytem provides a bunch of legacy functions that compute
s/subsytem/subsystem/
Quoted 7 lines
paths relative to the "gitdir" and "commondir" directories of the global
the_repositoryvariable. Use of those functions is discouraged, and it is easy to miss the implicit dependency onthe_repositorythat calls to those functions may cause.With
USE_THE_REPOSITORY_VARIABLE, we have recently introduced a tool that allows us to get rid of such functions over time. With this define,
s/define/defined/
Quoted 9 lines
we can hide away functions that have such implicit dependency such that other subsystems that want to be free of
the_repositorywill not use them by accident.Move all path-related functions that use
the_repositoryinto a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "path.c", allowing us to remove the definition of said preprocessor macro.
Nice! So now the "path.c" is the_repository free. Implicit use of the_repository is guarded behind USE_THE_REPOSITORY_VARIABLE. This is quite neat. :)
Quoted 21 lines
Signed-off-by Patrick Steinhardt <[email protected]>--- path.c | 52 +------------------- path.h | 147 ++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 100 insertions(+), 99 deletions(-)path.c +0
-2@@ -2,8 +2,6 @@* Utilities for paths and pathnames */ -#define USE_THE_REPOSITORY_VARIABLE -#include "git-compat-util.h" #include "abspath.h" #include "environment.h"
path.c static int get_st_mode_bits(const char *path, int *mode) · line 31
Quoted 5 lines
path.c +1
-1@@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode)return 0 ; } -static struct strbuf *get_pathname (void ) +struct strbuf *get_pathname (void )
Now that functions with implicit the_repository usage are static inlined we are required to expose get_pathname() for the same reason as some of the other functions in previous commits.
[snip]
path.c static int get_st_mode_bits(const char *path, int *mode) · line 34
Quoted 3 lines
path.c +3
-0+# ifdef USE_THE_REPOSITORY_VARIABLE +# include "strbuf.h" +# include "repository.h"
Naive question, what is the purpose of providing the include statements here? Wouldn't they always already be included?
Quoted 74 lines
path.c +74
-0+ +/* +* Return a statically allocated path into the main repository's +* (the_repository) common git directory. +*/ +__attribute__((format (printf,1 ,2 ))) +static inline const char *git_common_path (const char *fmt, ...) +{ +struct strbuf *pathname =get_pathname (); +va_list args; +va_start (args, fmt); +strbuf_git_common_pathv (pathname, the_repository, fmt, args); +va_end (args); +return pathname->buf; +} + +/* +* Construct a path into the main repository's (the_repository) git directory +* and place it in the provided buffer `buf`, the contents of the buffer will +* be overridden. +*/ +__attribute__((format (printf,2 ,3 ))) +static inline char *git_path_buf (struct strbuf *buf,const char *fmt, ...) +{ +va_list args; +strbuf_reset (buf); +va_start (args, fmt); +repo_git_pathv (the_repository,NULL , buf, fmt, args); +va_end (args); +return buf->buf; +} + +/* +* Construct a path into the main repository's (the_repository) git directory +* and append it to the provided buffer `sb`. +*/ +__attribute__((format (printf,2 ,3 ))) +static inline void strbuf_git_path (struct strbuf *sb,const char *fmt, ...) +{ +va_list args; +va_start (args, fmt); +repo_git_pathv (the_repository,NULL , sb, fmt, args); +va_end (args); +} + +/* +* Return a statically allocated path into the main repository's +* (the_repository) git directory. +*/ +__attribute__((format (printf,1 ,2 ))) +static inline const char *git_path (const char *fmt, ...) +{ +struct strbuf *pathname =get_pathname (); +va_list args; +va_start (args, fmt); +repo_git_pathv (the_repository,NULL , pathname, fmt, args); +va_end (args); +return pathname->buf; +} + +#define GIT_PATH_FUNC (func, filename) \ + const char *func(void) \ + { \ + static char *ret; \ + if (!ret) \ + ret = git_pathdup(filename); \ + return ret; \ + } + +/* +* Return a path into the main repository's (the_repository) git directory. +*/ +__attribute__((format (printf,1 ,2 ))) +static inline char *git_pathdup (const char *fmt, ...)
path.c static int get_st_mode_bits(const char *path, int *mode)
Quoted 10 lines
path.c +10
-0+{ +struct strbuf path =STRBUF_INIT ; +va_list args; +va_start (args, fmt); +repo_git_pathv (the_repository,NULL , &path, fmt, args); +va_end (args); +return strbuf_detach (&path,NULL ); +} + +# endif /* USE_THE_REPOSITORY_VARIABLE */
I like how it's all consolidated into this one block. Very nice! :)
Re: [PATCH 07/20] path: hide functions using `the_repository` by default
Quoted 7 lines · Justin Tobler
path.h char *xdg_cache_home(const char *filename); · line 228
Quoted 3 lines · Patrick Steinhardt
path.h +3
-0+# ifdef USE_THE_REPOSITORY_VARIABLE +# include "strbuf.h" +# include "repository.h" Naive question, what is the purpose of providing the include statements here? Wouldn't they always already be included?
Not necessarily, no. Most headers only have a forward declaration of struct strbuf and struct repository. For one this means that we cannot access the strbuf contents like we do in the function definitions in this header now. Second, it means that we cannot access the_repository.
Patrick
PATCH 8/20 config: introduce missing setters that take repo as parameter
In reply to Patrick SteinhardtWhile we already provide some of the config-setting interfaces with a struct repository as parameter, others only have a variant that implicitly depend on the_repository. Fill in those gaps such that we can start to deprecate the repo-less variants.
--- config.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------ config.h | 15 ++++++++- 2 files changed, 87 insertions(+), 21 deletions(-)
config.c +73 -20
@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store, *end_offset = store->parsed[store->parsed_nr -1 ].end; } +int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value) +{ +return repo_config_set_multivar_in_file_gently (r, config_filename, key, value,NULL , comment,0 ); +} +int git_config_set_in_file_gently (const char *config_filename,const char *key,const char *comment,const char *value) { -return git_config_set_multivar_in_file_gently (config_filename, key, value,NULL , comment,0 ); +return repo_config_set_in_file_gently (the_repository, config_filename, + key, comment, value); +} + +void repo_config_set_in_file (struct repository *r,const char *config_filename, +const char *key,const char *value) +{ +repo_config_set_multivar_in_file (r, config_filename, key, value,NULL ,0 ); }void git_config_set_in_file (const char *config_filename,const char *key,const char *value) { -git_config_set_multivar_in_file (config_filename, key, value,NULL ,0 ); +repo_config_set_in_file (the_repository, config_filename, key, value); +} + +int repo_config_set_gently (struct repository *r,const char *key,const char *value) +{ +return repo_config_set_multivar_gently (r, key, value,NULL ,0 ); }int git_config_set_gently (const char *key,const char *value) { -return git_config_set_multivar_gently (key, value,NULL ,0 ); +return repo_config_set_gently (the_repository, key, value); } int repo_config_set_worktree_gently(struct repository *r,
@@ -3209,13 +3227,18 @@ int repo_config_set_worktree_gently(struct repository *r,return repo_config_set_multivar_gently (r, key, value,NULL ,0 ); } -void git_config_set (const char *key,const char *value) +void repo_config_set (struct repository *r,const char *key,const char *value) { -git_config_set_multivar (key, value,NULL ,0 ); +repo_config_set_multivar (r, key, value,NULL ,0 );trace2_cmd_set_config (key, value); } +void git_config_set (const char *key,const char *value) +{ +repo_config_set (the_repository, key, value); +} +char *git_config_prepare_comment_string (const char *comment) {size_t leading_blanks;
@@ -3293,11 +3316,12 @@ static void validate_comment_string(const char *comment)* - the config file is removed and the lock file rename()d to it. * */ -int git_config_set_multivar_in_file_gently (const char *config_filename, -const char *key,const char *value, -const char *value_pattern, -const char *comment, -unsigned flags) +int repo_config_set_multivar_in_file_gently (struct repository *r, +const char *config_filename, +const char *key,const char *value, +const char *value_pattern, +const char *comment, +unsigned flags) {int fd =-1 , in_fd =-1 ;int ret;
@@ -3317,7 +3341,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, store.multi_replace = (flags &CONFIG_FLAGS_MULTI_REPLACE ) !=0 ;if (!config_filename) - config_filename = filename_buf =git_pathdup ("config" ); + config_filename = filename_buf =repo_git_path (r,"config" );/* * The lock serves a purpose in addition to locking: the new
@@ -3526,7 +3550,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, ret =0 ;/* Invalidate the config cache */ -git_config_clear (); +repo_config_clear (r); out_free:rollback_lock_file (&lock);
@@ -3543,12 +3567,24 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, goto out_free; } -void git_config_set_multivar_in_file (const char *config_filename, -const char *key,const char *value, -const char *value_pattern,unsigned flags) +int git_config_set_multivar_in_file_gently (const char *config_filename, +const char *key,const char *value, +const char *value_pattern, +const char *comment, +unsigned flags) { -if (!git_config_set_multivar_in_file_gently (config_filename, key, value, - value_pattern,NULL , flags)) +return repo_config_set_multivar_in_file_gently (the_repository, config_filename, + key, value, value_pattern, + comment, flags); +} + +void repo_config_set_multivar_in_file (struct repository *r, +const char *config_filename, +const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +if (!repo_config_set_multivar_in_file_gently (r, config_filename, key, value, + value_pattern,NULL , flags))return ;if (value)die (_ ("could not set '%s' to '%s'" ), key, value);
@@ -3556,6 +3592,14 @@ void git_config_set_multivar_in_file(const char *config_filename,die (_ ("could not unset '%s'" ), key); } +void git_config_set_multivar_in_file (const char *config_filename, +const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +repo_config_set_multivar_in_file (the_repository, config_filename, + key, value, value_pattern, flags); +} +int git_config_set_multivar_gently (const char *key,const char *value,const char *value_pattern,unsigned flags) {
@@ -3576,12 +3620,21 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key,return res; } +void repo_config_set_multivar (struct repository *r, +const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +char *file =repo_git_path (r,"config" ); +git_config_set_multivar_in_file (file, key, value, + value_pattern, flags); +free (file); +} +void git_config_set_multivar (const char *key,const char *value,const char *value_pattern,unsigned flags) { -git_config_set_multivar_in_file (git_path ("config" ), - key, value, value_pattern, - flags); +repo_config_set_multivar (the_repository, key, value, + value_pattern, flags); }static size_t section_name_match (const char *buf,const char *name)
config.h +14 -1
@@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);int git_config_expiry_date (timestamp_t *,const char *,const char *);int git_config_color (char *,const char *,const char *);int git_config_set_in_file_gently (const char *,const char *,const char *,const char *); +int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value);/** * write config values to a specific config file, takes a key/value pair as * parameter. */ void git_config_set_in_file (const char *,const char *,const char *); +void repo_config_set_in_file (struct repository *,const char *,const char *,const char *);int git_config_set_gently (const char *,const char *); +int repo_config_set_gently (struct repository *r,const char *,const char *);/** * Write a config value that should apply to the current worktree. If
@@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha* write config values to `.git/config`, takes a key/value pair as parameter. */ void git_config_set (const char *,const char *); +void repo_config_set (struct repository *,const char *,const char *);int git_config_parse_key (const char *,char **,size_t *);
@@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);#define CONFIG_FLAGS_FIXED_VALUE (1 << 1)int git_config_set_multivar_gently (const char *,const char *,const char *,unsigned ); -void git_config_set_multivar (const char *,const char *,const char *,unsigned );int repo_config_set_multivar_gently (struct repository *,const char *,const char *,const char *,unsigned ); +void git_config_set_multivar (const char *,const char *,const char *,unsigned ); +void repo_config_set_multivar (struct repository *r,const char *,const char *,const char *,unsigned );int git_config_set_multivar_in_file_gently (const char *,const char *,const char *,const char *,const char *,unsigned ); +int repo_config_set_multivar_in_file_gently (struct repository *,const char *,const char *,const char *,const char *,const char *,unsigned );char *git_config_prepare_comment_string (const char *);
@@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,const char *value, const char *value_pattern, unsigned flags); +void repo_config_set_multivar_in_file (struct repository *r, +const char *config_filename, +const char *key, +const char *value, +const char *value_pattern, +unsigned flags);/** * rename or remove sections in the config file
Signature · 1 line
2.46.0.dirty
Re: [PATCH 08/20] config: introduce missing setters that take repo as parameter
Quoted 3 lines · Patrick Steinhardt
While we already provide some of the config-setting interfaces with a
struct repositoryas parameter, others only have a variant that implicitly depend onthe_repository. Fill in those gaps such that we
s/depend/depends/
Quoted 13 lines
can start to deprecate the repo-less variants.
Signed-off-by Patrick Steinhardt <[email protected]>--- config.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------ config.h | 15 ++++++++- 2 files changed, 87 insertions(+), 21 deletions(-)config.c +0
-0
config.c static void maybe_remove_section(struct config_store_data *store, · line 3182
Quoted 5 lines
config.c +2
-0@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store, *end_offset = store->parsed[store->parsed_nr -1 ].end; } +int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value)
Instead of prefixing with repo_, should we instead use the config_ prefix? Maybe config_repo_? It might be nice for names to align with the config subsystem here.
[snip]
Quoted 47 lines
config.h +8
-1@@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);int git_config_expiry_date (timestamp_t *,const char *,const char *);int git_config_color (char *,const char *,const char *);int git_config_set_in_file_gently (const char *,const char *,const char *,const char *); +int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value);/** * write config values to a specific config file, takes a key/value pair as * parameter. */ void git_config_set_in_file (const char *,const char *,const char *); +void repo_config_set_in_file (struct repository *,const char *,const char *,const char *);int git_config_set_gently (const char *,const char *); +int repo_config_set_gently (struct repository *r,const char *,const char *);/** * Write a config value that should apply to the current worktree. If @@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha* write config values to `.git/config`, takes a key/value pair as parameter. */ void git_config_set (const char *,const char *); +void repo_config_set (struct repository *,const char *,const char *);int git_config_parse_key (const char *,char **,size_t *);@@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);#define CONFIG_FLAGS_FIXED_VALUE (1 << 1)int git_config_set_multivar_gently (const char *,const char *,const char *,unsigned ); -void git_config_set_multivar (const char *,const char *,const char *,unsigned );int repo_config_set_multivar_gently (struct repository *,const char *,const char *,const char *,unsigned ); +void git_config_set_multivar (const char *,const char *,const char *,unsigned ); +void repo_config_set_multivar (struct repository *r,const char *,const char *,const char *,unsigned );int git_config_set_multivar_in_file_gently (const char *,const char *,const char *,const char *,const char *,unsigned ); +int repo_config_set_multivar_in_file_gently (struct repository *,const char *,const char *,const char *,const char *,const char *,unsigned );char *git_config_prepare_comment_string (const char *);@@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,const char *value, const char *value_pattern,
config.h void git_config_set_multivar_in_file(const char *config_filename, · line 390
Quoted 10 lines
config.h +6
-0unsigned flags); +void repo_config_set_multivar_in_file (struct repository *r, +const char *config_filename, +const char *key, +const char *value, +const char *value_pattern, +unsigned flags);/** * rename or remove sections in the config file
The rest of this patch is simply implementing variations of existing functions that explicitly inject a repository and looks good to me.
Re: [PATCH 08/20] config: introduce missing setters that take repo as parameter
Quoted 9 lines · Justin Tobler
Quoted 8 lines · Patrick Steinhardt
config.c +0
-0@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store, *end_offset = store->parsed[store->parsed_nr -1 ].end; }
Quoted 6 lines
config.c static void maybe_remove_section(struct config_store_data *store, · line 3182
Quoted 2 lines
config.c +2
-0+int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value)Instead of prefixing with
repo_, should we instead use theconfig_prefix? Maybeconfig_repo_? It might be nice for names to align with the config subsystem here.
I think I agree, but we extensively use the repo_config_ prefix for all functions that take a repository as input in this subsystem. So in this case I think we should stick with that, but we may eventually want to revisit this.
Patrick
PATCH 9/20 config: expose `repo_config_clear()`
In reply to Patrick SteinhardtWhile we already have repo_config_clear() as an alternative to git_config_clear() that doesn't rely on the_repository, it is not exposed to callers outside of the config subsystem. Do so.
--- config.c | 2 +- config.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
config.c +1 -1
@@ -2564,7 +2564,7 @@ static void git_config_check_init(struct repository *repo)repo_read_config (repo); } -static void repo_config_clear (struct repository *repo) +void repo_config_clear (struct repository *repo) {if (!repo->config || !repo->config->hash_initialized)return ;
config.h +1 -0
@@ -651,6 +651,7 @@ int git_config_get_string_multi(const char *key,* Resets and invalidates the config cache. */ void git_config_clear (void ); +void repo_config_clear (struct repository *repo);/** * Allocates and copies the retrieved string into the `dest` parameter for
Signature · 1 line
2.46.0.dirty
PATCH 10/20 config: pass repo to `git_config_get_index_threads()`
In reply to Patrick SteinhardtRefactor git_config_get_index_threads() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
config.c +2 -2
@@ -2826,7 +2826,7 @@ int git_config_get_max_percent_split_change(void)return -1 ;/* default value */ } -int git_config_get_index_threads (int *dest) +int repo_config_get_index_threads (struct repository *r,int *dest) {int is_bool, val;
@@ -2836,7 +2836,7 @@ int git_config_get_index_threads(int *dest)return 0 ; } -if (!git_config_get_bool_or_int ("index.threads" , &is_bool, &val)) { +if (!repo_config_get_bool_or_int (r,"index.threads" , &is_bool, &val)) {if (is_bool) *dest = val ?0 :1 ;else
config.h +1 -1
@@ -710,7 +710,7 @@ int git_config_get_maybe_bool(const char *key, int *dest);*/ int git_config_get_pathname (const char *key,char **dest); -int git_config_get_index_threads (int *dest); +int repo_config_get_index_threads (struct repository *r,int *dest);int git_config_get_split_index (void );int git_config_get_max_percent_split_change (void );
read-cache.c +4 -4
@@ -2267,7 +2267,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset =sizeof (*hdr); -if (git_config_get_index_threads (&nr_threads)) +if (repo_config_get_index_threads (the_repository, &nr_threads)) nr_threads =1 ;/* TODO: does creating more threads than cores help? */
@@ -2787,7 +2787,7 @@ static int record_eoie(void)* used for threading is written by default if the user * explicitly requested threaded index reads. */ -return !git_config_get_index_threads (&val) && val !=1 ; +return !repo_config_get_index_threads (the_repository, &val) && val !=1 ; }static int record_ieot (void )
@@ -2802,7 +2802,7 @@ static int record_ieot(void)* written by default if the user explicitly requested * threaded index reads. */ -return !git_config_get_index_threads (&val) && val !=1 ; +return !repo_config_get_index_threads (the_repository, &val) && val !=1 ; }enum write_extensions {
@@ -2875,7 +2875,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,hashwrite (f, &hdr,sizeof (hdr)); -if (!HAVE_THREADS ||git_config_get_index_threads (&nr_threads)) +if (!HAVE_THREADS ||repo_config_get_index_threads (the_repository, &nr_threads)) nr_threads =1 ;if (nr_threads !=1 &&record_ieot ()) {
Signature · 1 line
2.46.0.dirty
PATCH 11/20 config: pass repo to `git_config_get_split_index()`
In reply to Patrick SteinhardtRefactor git_config_get_split_index() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- builtin/update-index.c | 4 ++-- config.c | 4 ++-- config.h | 2 +- read-cache.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
builtin/update-index.c +2 -2
@@ -1156,7 +1156,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)end_odb_transaction ();if (split_index >0 ) { -if (git_config_get_split_index () ==0 ) +if (repo_config_get_split_index (the_repository) ==0 )warning (_ ("core.splitIndex is set to false; " "remove or change it, if you really want to " "enable split index" ));
@@ -1165,7 +1165,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)else add_split_index (the_repository->index); }else if (!split_index) { -if (git_config_get_split_index () ==1 ) +if (repo_config_get_split_index (the_repository) ==1 )warning (_ ("core.splitIndex is set to true; " "remove or change it, if you really want to " "disable split index" ));
config.c +2 -2
@@ -2801,11 +2801,11 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamreturn -1 ;/* thing exists but cannot be parsed */ } -int git_config_get_split_index (void ) +int repo_config_get_split_index (struct repository *r) {int val; -if (!git_config_get_maybe_bool ("core.splitindex" , &val)) +if (!repo_config_get_maybe_bool (r,"core.splitindex" , &val))return val;return -1 ;/* default value */
config.h +1 -1
@@ -711,7 +711,7 @@ int git_config_get_maybe_bool(const char *key, int *dest);int git_config_get_pathname (const char *key,char **dest);int repo_config_get_index_threads (struct repository *r,int *dest); -int git_config_get_split_index (void ); +int repo_config_get_split_index (struct repository *r);int git_config_get_max_percent_split_change (void );/* This dies if the configured or default date is in the future */
read-cache.c +1 -1
@@ -1945,7 +1945,7 @@ static void tweak_untracked_cache(struct index_state *istate)static void tweak_split_index (struct index_state *istate) { -switch (git_config_get_split_index ()) { +switch (repo_config_get_split_index (the_repository)) {case -1 :/* unset: do nothing */ break ;case 0 :/* false */
Signature · 1 line
2.46.0.dirty
PATCH 12/20 config: pass repo to `git_config_get_max_percent_split_change()`
In reply to Patrick SteinhardtRefactor git_config_get_max_percent_split_change() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
config.c +2 -2
@@ -2811,11 +2811,11 @@ int repo_config_get_split_index(struct repository *r)return -1 ;/* default value */ } -int git_config_get_max_percent_split_change (void ) +int repo_config_get_max_percent_split_change (struct repository *r) {int val =-1 ; -if (!git_config_get_int ("splitindex.maxpercentchange" , &val)) { +if (!repo_config_get_int (r,"splitindex.maxpercentchange" , &val)) {if (0 <= val && val <=100 )return val;
config.h +1 -1
@@ -712,7 +712,7 @@ int git_config_get_pathname(const char *key, char **dest);int repo_config_get_index_threads (struct repository *r,int *dest);int repo_config_get_split_index (struct repository *r); -int git_config_get_max_percent_split_change (void ); +int repo_config_get_max_percent_split_change (struct repository *r);/* This dies if the configured or default date is in the future */ int git_config_get_expiry (const char *key,const char **output);
read-cache.c +1 -1
@@ -3275,7 +3275,7 @@ static const int default_max_percent_split_change = 20;static int too_many_not_shared_entries (struct index_state *istate) {int i, not_shared =0 ; -int max_split =git_config_get_max_percent_split_change (); +int max_split =repo_config_get_max_percent_split_change (the_repository);switch (max_split) {case -1 :
Signature · 1 line
2.46.0.dirty
PATCH 13/20 config: pass repo to `git_config_get_expiry()`
In reply to Patrick SteinhardtRefactor git_config_get_expiry() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- builtin/gc.c | 6 +++--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
builtin/gc.c +3 -3
@@ -167,9 +167,9 @@ static void gc_config(void)git_config_get_bool ("gc.autodetach" , &detach_auto);git_config_get_bool ("gc.cruftpacks" , &cruft_packs);git_config_get_ulong ("gc.maxcruftsize" , &max_cruft_size); -git_config_get_expiry ("gc.pruneexpire" , &prune_expire); -git_config_get_expiry ("gc.worktreepruneexpire" , &prune_worktrees_expire); -git_config_get_expiry ("gc.logexpiry" , &gc_log_expire); +repo_config_get_expiry (the_repository,"gc.pruneexpire" , &prune_expire); +repo_config_get_expiry (the_repository,"gc.worktreepruneexpire" , &prune_worktrees_expire); +repo_config_get_expiry (the_repository,"gc.logexpiry" , &gc_log_expire);git_config_get_ulong ("gc.bigpackthreshold" , &big_pack_threshold);git_config_get_ulong ("pack.deltacachesize" , &max_delta_cache_size);
config.c +2 -2
@@ -2766,9 +2766,9 @@ int git_config_get_pathname(const char *key, char **dest)return repo_config_get_pathname (the_repository, key, dest); } -int git_config_get_expiry (const char *key,const char **output) +int repo_config_get_expiry (struct repository *r,const char *key,const char **output) { -int ret =git_config_get_string (key, (char **)output); +int ret =repo_config_get_string (r, key, (char **)output);if (ret)return ret;if (strcmp (*output,"now" )) {
config.h +1 -1
@@ -715,7 +715,7 @@ int repo_config_get_split_index(struct repository *r);int repo_config_get_max_percent_split_change (struct repository *r);/* This dies if the configured or default date is in the future */ -int git_config_get_expiry (const char *key,const char **output); +int repo_config_get_expiry (struct repository *r,const char *key,const char **output);/* parse either "this many days" integer, or "5.days.ago" approxidate */ int git_config_get_expiry_in_days (const char *key,timestamp_t *,timestamp_t now);
read-cache.c +2 -2
@@ -3184,8 +3184,8 @@ static unsigned long get_shared_index_expire_date(void)static int shared_index_expire_date_prepared;if (!shared_index_expire_date_prepared) { -git_config_get_expiry ("splitindex.sharedindexexpire" , - &shared_index_expire); +repo_config_get_expiry (the_repository,"splitindex.sharedindexexpire" , + &shared_index_expire); shared_index_expire_date =approxidate (shared_index_expire); shared_index_expire_date_prepared =1 ; }
Signature · 1 line
2.46.0.dirty
PATCH 14/20 config: pass repo to `git_config_get_expiry_in_days()`
In reply to Patrick SteinhardtRefactor git_config_get_expiry_in_days() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- config.c | 5 +++-- config.h | 3 ++- rerere.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-)
config.c +3 -2
@@ -2779,13 +2779,14 @@ int repo_config_get_expiry(struct repository *r, const char *key, const char **oreturn ret; } -int git_config_get_expiry_in_days (const char *key,timestamp_t *expiry,timestamp_t now) +int repo_config_get_expiry_in_days (struct repository *r,const char *key, +timestamp_t *expiry,timestamp_t now) {const char *expiry_string;intmax_t days;timestamp_t when; -if (git_config_get_string_tmp (key, &expiry_string)) +if (repo_config_get_string_tmp (r, key, &expiry_string))return 1 ;/* no such thing */ if (git_parse_signed (expiry_string, &days,maximum_signed_value_of_type (int))) {
config.h +2 -1
@@ -718,7 +718,8 @@ int repo_config_get_max_percent_split_change(struct repository *r);int repo_config_get_expiry (struct repository *r,const char *key,const char **output);/* parse either "this many days" integer, or "5.days.ago" approxidate */ -int git_config_get_expiry_in_days (const char *key,timestamp_t *,timestamp_t now); +int repo_config_get_expiry_in_days (struct repository *r,const char *key, +timestamp_t *,timestamp_t now);/** * First prints the error message specified by the caller in `err` and then
rerere.c +2 -2
@@ -1203,8 +1203,8 @@ void rerere_gc(struct repository *r, struct string_list *rr)if (setup_rerere (r, rr,0 ) <0 )return ; -git_config_get_expiry_in_days ("gc.rerereresolved" , &cutoff_resolve, now); -git_config_get_expiry_in_days ("gc.rerereunresolved" , &cutoff_noresolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereresolved" , &cutoff_resolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereunresolved" , &cutoff_noresolve, now);git_config (git_default_config,NULL ); dir =opendir (git_path ("rr-cache" ));if (!dir)
Signature · 1 line
2.46.0.dirty
Re: [PATCH 14/20] config: pass repo to `git_config_get_expiry_in_days()`
Quoted 6 lines · Patrick Steinhardt
Refactor
git_config_get_expiry_in_days()to accept astruct repositorysuch that we can get rid of the implicit dependency onthe_repository. Rename the function accordingly.Signed-off-by Patrick Steinhardt <[email protected]>---
[snip]
rerere.c void rerere_gc(struct repository *r, struct string_list *rr) · line 1207
Quoted 4 lines
rerere.c +2
-2-git_config_get_expiry_in_days ("gc.rerereresolved" , &cutoff_resolve, now); -git_config_get_expiry_in_days ("gc.rerereunresolved" , &cutoff_noresolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereresolved" , &cutoff_resolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereunresolved" , &cutoff_noresolve, now);
non-blocking: Do we want to fold these lines?
Quoted 3 lines
rerere.c +0
-0git_config (git_default_config,NULL ); dir =opendir (git_path ("rr-cache" ));if (!dir)
Re: [PATCH 14/20] config: pass repo to `git_config_get_expiry_in_days()`
Quoted 7 lines · Justin Tobler
Quoted 6 lines · Patrick Steinhardt
Refactor
git_config_get_expiry_in_days()to accept astruct repositorysuch that we can get rid of the implicit dependency onthe_repository. Rename the function accordingly.Signed-off-by Patrick Steinhardt <[email protected]>---
Quoted 7 lines
[snip]
rerere.c void rerere_gc(struct repository *r, struct string_list *rr) · line 1207
Quoted 4 lines
rerere.c +2
-2-git_config_get_expiry_in_days ("gc.rerereresolved" , &cutoff_resolve, now); -git_config_get_expiry_in_days ("gc.rerereunresolved" , &cutoff_noresolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereresolved" , &cutoff_resolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereunresolved" , &cutoff_noresolve, now);non-blocking: Do we want to fold these lines?
Yes, if we are going to see another iteration for other reasons.
PATCH 15/20 config: pass repo to `git_die_config()`
In reply to Patrick SteinhardtRefactor git_die_config() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- builtin/fast-import.c | 4 ++-- builtin/notes.c | 2 +- config.c | 12 ++++++------ config.h | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-)
builtin/fast-import.c +2 -2
@@ -3481,8 +3481,8 @@ static void git_pack_config(void)if (!git_config_get_int ("pack.indexversion" , &indexversion_value)) { pack_idx_opts.version = indexversion_value;if (pack_idx_opts.version >2 ) -git_die_config ("pack.indexversion" , -"bad pack.indexVersion=%" PRIu32, pack_idx_opts.version); +git_die_config (the_repository,"pack.indexversion" , +"bad pack.indexVersion=%" PRIu32, pack_idx_opts.version); }if (!git_config_get_ulong ("pack.packsizelimit" , &packsizelimit_value)) max_packsize = packsizelimit_value;
builtin/notes.c +1 -1
@@ -868,7 +868,7 @@ static int git_config_get_notes_strategy(const char *key,if (git_config_get_string (key, &value))return 1 ;if (parse_notes_merge_strategy (value, strategy)) -git_die_config (key,_ ("unknown notes merge strategy %s" ), value); +git_die_config (the_repository, key,_ ("unknown notes merge strategy %s" ), value);free (value);return 0 ;
config.c +6 -6
@@ -2611,7 +2611,7 @@ int repo_config_get_string(struct repository *repo,git_config_check_init (repo); ret =git_configset_get_string (repo->config, key, dest);if (ret <0 ) -git_die_config (key,NULL ); +git_die_config (repo, key,NULL );return ret; }
@@ -2622,7 +2622,7 @@ int repo_config_get_string_tmp(struct repository *repo,git_config_check_init (repo); ret =git_configset_get_string_tmp (repo->config, key, dest);if (ret <0 ) -git_die_config (key,NULL ); +git_die_config (repo, key,NULL );return ret; }
@@ -2668,7 +2668,7 @@ int repo_config_get_pathname(struct repository *repo,git_config_check_init (repo); ret =git_configset_get_pathname (repo->config, key, dest);if (ret <0 ) -git_die_config (key,NULL ); +git_die_config (repo, key,NULL );return ret; }
@@ -2774,7 +2774,7 @@ int repo_config_get_expiry(struct repository *r, const char *key, const char **oif (strcmp (*output,"now" )) {timestamp_t now =approxidate ("now" );if (approxidate (*output) >= now) -git_die_config (key,_ ("Invalid %s: '%s'" ), key, *output); +git_die_config (r, key,_ ("Invalid %s: '%s'" ), key, *output); }return ret; }
@@ -2858,7 +2858,7 @@ void git_die_config_linenr(const char *key, const char *filename, int linenr) key, filename, linenr); } -void git_die_config (const char *key,const char *err, ...) +void git_die_config (struct repository *r,const char *key,const char *err, ...) {const struct string_list *values;struct key_value_info *kv_info;
@@ -2870,7 +2870,7 @@ void git_die_config(const char *key, const char *err, ...)error_fn (err, params);va_end (params); } -if (git_config_get_value_multi (key, &values)) +if (repo_config_get_value_multi (r, key, &values))BUG ("for key '%s' we must have a value to report on" , key); kv_info = values->items[values->nr -1 ].util;git_die_config_linenr (key, kv_info->filename, kv_info->linenr);
config.h +2 -1
@@ -726,7 +726,8 @@ int repo_config_get_expiry_in_days(struct repository *r, const char *key,* dies printing the line number and the file name of the highest priority * value for the configuration variable `key`. */ -NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); +NORETURN void git_die_config(struct repository *r, const char *key, const char *err, ...) + __attribute__((format (printf,3 ,4 )));/** * Helper function which formats the die error message according to the
Signature · 1 line
2.46.0.dirty
PATCH 16/20 config: pass repo to functions that rename or copy sections
In reply to Patrick SteinhardtRefactor functions that rename or copy config sections to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the functions accordingly.
--- builtin/branch.c | 7 ++++--- builtin/config.c | 16 ++++++++-------- builtin/remote.c | 4 ++-- builtin/submodule--helper.c | 2 +- config.c | 30 ++++++++++++++++-------------- config.h | 8 ++++---- submodule.c | 2 +- 7 files changed, 36 insertions(+), 33 deletions(-)
builtin/branch.c +4 -3
@@ -210,7 +210,7 @@ static void delete_branch_config(const char *branchname) {struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"branch.%s" , branchname); -if (git_config_rename_section (buf.buf,NULL ) <0 ) +if (repo_config_rename_section (the_repository, buf.buf,NULL ) <0 )warning (_ ("update of config-file failed" ));strbuf_release (&buf); }
@@ -659,9 +659,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, intstrbuf_addf (&oldsection,"branch.%s" , interpreted_oldname);strbuf_addf (&newsection,"branch.%s" , interpreted_newname); -if (!copy &&git_config_rename_section (oldsection.buf, newsection.buf) <0 ) +if (!copy &&repo_config_rename_section (the_repository, oldsection.buf, newsection.buf) <0 )die (_ ("branch is renamed, but update of config-file failed" )); -if (copy &&strcmp (interpreted_oldname, interpreted_newname) &&git_config_copy_section (oldsection.buf, newsection.buf) <0 ) +if (copy &&strcmp (interpreted_oldname, interpreted_newname) && +repo_config_copy_section (the_repository, oldsection.buf, newsection.buf) <0 )die (_ ("branch is copied, but update of config-file failed" ));strbuf_release (&oldref);strbuf_release (&newref);
builtin/config.c +8 -8
@@ -1026,8 +1026,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *prlocation_options_init (&location_opts, prefix);check_write (&location_opts.source); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ], argv[1 ]); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ], argv[1 ]);if (ret <0 ) goto out;else if (!ret)
@@ -1055,8 +1055,8 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *prlocation_options_init (&location_opts, prefix);check_write (&location_opts.source); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ],NULL ); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ],NULL );if (ret <0 ) goto out;else if (!ret)
@@ -1353,8 +1353,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)else if (actions ==ACTION_RENAME_SECTION ) {check_write (&location_opts.source);check_argc (argc,2 ,2 ); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ], argv[1 ]); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ], argv[1 ]);if (ret <0 ) goto out;else if (!ret)
@@ -1365,8 +1365,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)else if (actions ==ACTION_REMOVE_SECTION ) {check_write (&location_opts.source);check_argc (argc,1 ,1 ); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ],NULL ); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ],NULL );if (ret <0 ) goto out;else if (!ret)
builtin/remote.c +2 -2
@@ -736,7 +736,7 @@ static int mv(int argc, const char **argv, const char *prefix)strbuf_addf (&buf,"remote.%s" , rename.old_name);strbuf_addf (&buf2,"remote.%s" , rename.new_name); -if (git_config_rename_section (buf.buf, buf2.buf) <1 ) +if (repo_config_rename_section (the_repository, buf.buf, buf2.buf) <1 )return error (_ ("Could not rename config section '%s' to '%s'" ), buf.buf, buf2.buf);
@@ -944,7 +944,7 @@ static int rm(int argc, const char **argv, const char *prefix)if (!result) {strbuf_addf (&buf,"remote.%s" , remote->name); -if (git_config_rename_section (buf.buf,NULL ) <1 ) +if (repo_config_rename_section (the_repository, buf.buf,NULL ) <1 )return error (_ ("Could not remove config section '%s'" ), buf.buf);handle_push_default (remote->name,NULL );
builtin/submodule--helper.c +1 -1
@@ -1455,7 +1455,7 @@ static void deinit_submodule(const char *path, const char *prefix,* remove the whole section so we have a clean state when * the user later decides to init this submodule again */ -git_config_rename_section_in_file (NULL , sub_key,NULL ); +repo_config_rename_section_in_file (the_repository,NULL , sub_key,NULL );if (!(flags &OPT_QUIET ))printf (_ ("Submodule '%s' (%s) unregistered for path '%s'\n" ), sub->name, sub->url, displaypath);
config.c +16 -14
@@ -3697,9 +3697,11 @@ static int section_name_is_ok(const char *name)#define GIT_CONFIG_MAX_LINE_LEN (512 * 1024)/* if new_name == NULL, the section is removed instead */ -static int git_config_copy_or_rename_section_in_file (const char *config_filename, -const char *old_name, -const char *new_name,int copy) +static int repo_config_copy_or_rename_section_in_file ( +struct repository *r, +const char *config_filename, +const char *old_name, +const char *new_name,int copy) {int ret =0 , remove =0 ;char *filename_buf =NULL ;
@@ -3720,7 +3722,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename }if (!config_filename) - config_filename = filename_buf =git_pathdup ("config" ); + config_filename = filename_buf =repo_git_path (r,"config" ); out_fd =hold_lock_file_for_update (&lock, config_filename,0 );if (out_fd <0 ) {
@@ -3863,28 +3865,28 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filenamereturn ret; } -int git_config_rename_section_in_file (const char *config_filename, -const char *old_name,const char *new_name) +int repo_config_rename_section_in_file (struct repository *r,const char *config_filename, +const char *old_name,const char *new_name) { -return git_config_copy_or_rename_section_in_file (config_filename, +return repo_config_copy_or_rename_section_in_file (r, config_filename, old_name, new_name,0 ); } -int git_config_rename_section (const char *old_name,const char *new_name) +int repo_config_rename_section (struct repository *r,const char *old_name,const char *new_name) { -return git_config_rename_section_in_file (NULL , old_name, new_name); +return repo_config_rename_section_in_file (r,NULL , old_name, new_name); } -int git_config_copy_section_in_file (const char *config_filename, -const char *old_name,const char *new_name) +int repo_config_copy_section_in_file (struct repository *r,const char *config_filename, +const char *old_name,const char *new_name) { -return git_config_copy_or_rename_section_in_file (config_filename, +return repo_config_copy_or_rename_section_in_file (r, config_filename, old_name, new_name,1 ); } -int git_config_copy_section (const char *old_name,const char *new_name) +int repo_config_copy_section (struct repository *r,const char *old_name,const char *new_name) { -return git_config_copy_section_in_file (NULL , old_name, new_name); +return repo_config_copy_section_in_file (r,NULL , old_name, new_name); }/*
config.h +4 -4
@@ -392,11 +392,11 @@ void repo_config_set_multivar_in_file(struct repository *r,* If NULL is passed through `new_name` parameter, * the section will be removed from the config file. */ -int git_config_rename_section (const char *,const char *); +int repo_config_rename_section (struct repository *,const char *,const char *); -int git_config_rename_section_in_file (const char *,const char *,const char *); -int git_config_copy_section (const char *,const char *); -int git_config_copy_section_in_file (const char *,const char *,const char *); +int repo_config_rename_section_in_file (struct repository *,const char *,const char *,const char *); +int repo_config_copy_section (struct repository *,const char *,const char *); +int repo_config_copy_section_in_file (struct repository *,const char *,const char *,const char *);int git_config_system (void );int config_error_nonbool (const char *);#if defined(__GNUC__)
submodule.c +1 -1
@@ -159,7 +159,7 @@ int remove_path_from_gitmodules(const char *path) }strbuf_addstr (§,"submodule." );strbuf_addstr (§, submodule->name); -if (git_config_rename_section_in_file (GITMODULES_FILE , sect.buf,NULL ) <0 ) { +if (repo_config_rename_section_in_file (the_repository,GITMODULES_FILE , sect.buf,NULL ) <0 ) {/* Maybe the user already did that, don't error out here */ warning (_ ("Could not remove .gitmodules entry for %s" ), path);strbuf_release (§);
Signature · 1 line
2.46.0.dirty
PATCH 17/20 config: don't have setters depend on `the_repository`
In reply to Patrick SteinhardtSome of the setters that accept a struct repository still implicitly rely on the_repository via git_config_set_multivar_in_file(). While this function would typically use the caller-provided path, it knows to fall back to using the configuration path indicated by the_repository.
Adapt those functions to instead use the caller-provided repository.
--- config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
config.c +8 -8
@@ -3220,8 +3220,8 @@ int repo_config_set_worktree_gently(struct repository *r,/* Only use worktree-specific config if it is already enabled. */ if (r->repository_format_worktree_config) {char *file =repo_git_path (r,"config.worktree" ); -int ret =git_config_set_multivar_in_file_gently ( - file, key, value,NULL ,NULL ,0 ); +int ret =repo_config_set_multivar_in_file_gently ( + r, file, key, value,NULL ,NULL ,0 );free (file);return ret; }
@@ -3613,10 +3613,10 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key, const char *value_pattern, unsigned flags) { char *file = repo_git_path(r, "config"); -int res =git_config_set_multivar_in_file_gently (file, - key, value, - value_pattern, -NULL , flags); +int res =repo_config_set_multivar_in_file_gently (r, file, + key, value, + value_pattern, +NULL , flags);free (file);return res; }
@@ -3626,8 +3626,8 @@ void repo_config_set_multivar(struct repository *r, const char *value_pattern, unsigned flags) { char *file = repo_git_path(r, "config"); -git_config_set_multivar_in_file (file, key, value, - value_pattern, flags); +repo_config_set_multivar_in_file (r, file, key, value, + value_pattern, flags);free (file); }
Signature · 1 line
2.46.0.dirty
PATCH 18/20 config: don't depend on `the_repository` with branch conditions
In reply to Patrick SteinhardtWhen computing branch "includeIf" conditions we use the_repository to obtain the main ref store. We really shouldn't depend on this global repository though, but should instead use the repository that is being passed to us via struct config_include_data. Otherwise, when parsing configuration of e.g. submodules, we may end up evaluating the condition the via the wrong refdb.
Fix this.
--- config.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
config.c +5 -4
@@ -300,13 +300,14 @@ static int include_by_gitdir(const struct key_value_info *kvi,return ret; } -static int include_by_branch (const char *cond,size_t cond_len) +static int include_by_branch (struct config_include_data *data, +const char *cond,size_t cond_len) {int flags;int ret;struct strbuf pattern =STRBUF_INIT ; -const char *refname = !the_repository->gitdir ? -NULL :refs_resolve_ref_unsafe (get_main_ref_store (the_repository), +const char *refname = (!data->repo || !data->repo->gitdir) ? +NULL :refs_resolve_ref_unsafe (get_main_ref_store (data->repo),"HEAD" ,0 ,NULL , &flags);const char *shortname;
@@ -406,7 +407,7 @@ static int include_condition_is_true(const struct key_value_info *kvi,else if (skip_prefix_mem (cond, cond_len,"gitdir/i:" , &cond, &cond_len))return include_by_gitdir (kvi, opts, cond, cond_len,1 );else if (skip_prefix_mem (cond, cond_len,"onbranch:" , &cond, &cond_len)) -return include_by_branch (cond, cond_len); +return include_by_branch (inc, cond, cond_len);else if (skip_prefix_mem (cond, cond_len,"hasconfig:remote.*.url:" , &cond, &cond_len))return include_by_remote_url (inc, cond, cond_len);
Signature · 1 line
2.46.0.dirty
Re: [PATCH 18/20] config: don't depend on `the_repository` with branch conditions
Quoted 25 lines · Patrick Steinhardt
When computing branch "includeIf" conditions we use
the_repositoryto obtain the main ref store. We really shouldn't depend on this global repository though, but should instead use the repository that is being passed to us viastruct config_include_data. Otherwise, when parsing configuration of e.g. submodules, we may end up evaluating the condition the via the wrong refdb.Fix this.
Signed-off-by Patrick Steinhardt <[email protected]>--- config.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)config.c +2
-1@@ -300,13 +300,14 @@ static int include_by_gitdir(const struct key_value_info *kvi,return ret; } -static int include_by_branch (const char *cond,size_t cond_len) +static int include_by_branch (struct config_include_data *data, +const char *cond,size_t cond_len)
config.c static int include_by_gitdir(const struct key_value_info *kvi, · line 312
Quoted 10 lines
config.c +2
-2{int flags;int ret;struct strbuf pattern =STRBUF_INIT ; -const char *refname = !the_repository->gitdir ? -NULL :refs_resolve_ref_unsafe (get_main_ref_store (the_repository), +const char *refname = (!data->repo || !data->repo->gitdir) ? +NULL :refs_resolve_ref_unsafe (get_main_ref_store (data->repo),"HEAD" ,0 ,NULL , &flags);const char *shortname;
This works the same so long as config_include_data always has its repository set. I wonder if for !data->repo we should instead signal a BUG? Otherwise we would silently return NULL in such cases. Maybe that would be the desired behavior though?
Quoted 13 lines
config.c +1
-1@@ -406,7 +407,7 @@ static int include_condition_is_true(const struct key_value_info *kvi,else if (skip_prefix_mem (cond, cond_len,"gitdir/i:" , &cond, &cond_len))return include_by_gitdir (kvi, opts, cond, cond_len,1 );else if (skip_prefix_mem (cond, cond_len,"onbranch:" , &cond, &cond_len)) -return include_by_branch (cond, cond_len); +return include_by_branch (inc, cond, cond_len);else if (skip_prefix_mem (cond, cond_len,"hasconfig:remote.*.url:" , &cond, &cond_len))return include_by_remote_url (inc, cond, cond_len);Signature · 1 line
2.46.0.dirty
Re: [PATCH 18/20] config: don't depend on `the_repository` with branch conditions
Quoted 33 lines · Justin Tobler
Quoted 32 lines · Patrick Steinhardt
When computing branch "includeIf" conditions we use
the_repositoryto obtain the main ref store. We really shouldn't depend on this global repository though, but should instead use the repository that is being passed to us viastruct config_include_data. Otherwise, when parsing configuration of e.g. submodules, we may end up evaluating the condition the via the wrong refdb.Fix this.
Signed-off-by Patrick Steinhardt <[email protected]>--- config.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)config.c +3
-3@@ -300,13 +300,14 @@ static int include_by_gitdir(const struct key_value_info *kvi,return ret; } -static int include_by_branch (const char *cond,size_t cond_len) +static int include_by_branch (struct config_include_data *data, +const char *cond,size_t cond_len) {int flags;int ret;struct strbuf pattern =STRBUF_INIT ; -const char *refname = !the_repository->gitdir ? - NULL : refs_resolve_ref_unsafe(get_main_ref_store(the_repository), + const char *refname = (!data->repo || !data->repo->gitdir) ?
Quoted 8 lines
config.c static int include_by_gitdir(const struct key_value_info *kvi, · line 312
Quoted 3 lines
config.c +1
-0+ NULL : refs_resolve_ref_unsafe(get_main_ref_store(data->repo),"HEAD" ,0 ,NULL , &flags);const char *shortname;This works the same so long as
config_include_dataalways has its repository set. I wonder if for!data->repowe should instead signal a BUG? Otherwise we would silently return NULL in such cases. Maybe that would be the desired behavior though?
It is expected that the repository may not be set, namely when reading configuration via read_early_config() and read_very_early_config(). We wouldn't want to hit the refdb there, so that is fine.
We also have read_protected_config(), which requires a bit more thought. It does respect includes, so you may think we want to read the refdb there. But protected config is defined as having system, global or command scope, which to me means that we shouldn't end up reading config data from the current repository. So not hitting the refdb there also seems like the right thing to do.
Patrick
PATCH 19/20 global: prepare for hiding away repo-less config functions
In reply to Patrick SteinhardtWe're about to hide config functions that implicitly depend on the_repository behind the USE_THE_REPOSITORY_VARIABLE macro. This will uncover a bunch of dependents that transitively relied on the global variable, but didn'd define the macro yet.
Adapt them such that we define the macro to prepare for this change.
--- compat/fsmonitor/fsm-ipc-darwin.c | 2 ++ compat/precompose_utf8.c | 1 + connect.c | 2 ++ credential.c | 2 ++ daemon.c | 2 ++ editor.c | 2 ++ fsmonitor.c | 2 ++ gpg-interface.c | 2 ++ graph.c | 2 ++ imap-send.c | 2 ++ mailinfo.c | 2 ++ merge-ll.c | 2 ++ parallel-checkout.c | 2 ++ protocol.c | 2 ++ refs.c | 2 ++ refs/packed-backend.c | 2 ++ refs/reftable-backend.c | 2 ++ sideband.c | 2 ++ t/helper/test-advise.c | 2 ++ t/helper/test-config.c | 2 ++ t/helper/test-userdiff.c | 2 ++ trailer.c | 2 ++ versioncmp.c | 2 ++ 23 files changed, 45 insertions(+)
compat/fsmonitor/fsm-ipc-darwin.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "gettext.h"
compat/precompose_utf8.c +1 -0
@@ -4,6 +4,7 @@*/ #define PRECOMPOSE_UNICODE_C +#define USE_THE_REPOSITORY_VARIABLE #include "git-compat-util.h" #include "config.h"
connect.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "environment.h"
credential.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "abspath.h" #include "config.h"
daemon.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "abspath.h" #include "config.h"
editor.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "abspath.h" #include "advice.h"
fsmonitor.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "dir.h"
gpg-interface.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "commit.h" #include "config.h"
graph.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "gettext.h" #include "config.h"
imap-send.c +2 -0
@@ -21,6 +21,8 @@* along with this program; if not, see <https://www.gnu.org/licenses/>. */ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "credential.h"
mailinfo.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "gettext.h"
merge-ll.c +2 -0
@@ -4,6 +4,8 @@* Copyright (c) 2007 Junio C Hamano */ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "convert.h"
parallel-checkout.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "entry.h"
protocol.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "environment.h"
refs.c +2 -0
@@ -2,6 +2,8 @@* The backend-independent part of the reference module. */ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "advice.h" #include "config.h"
refs/packed-backend.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "../git-compat-util.h" #include "../config.h" #include "../dir.h"
refs/reftable-backend.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "../git-compat-util.h" #include "../abspath.h" #include "../chdir-notify.h"
sideband.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "color.h" #include "config.h"
t/helper/test-advise.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "test-tool.h" #include "advice.h" #include "config.h"
t/helper/test-config.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "test-tool.h" #include "config.h" #include "setup.h"
t/helper/test-userdiff.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "test-tool.h" #include "setup.h" #include "userdiff.h"
trailer.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "environment.h"
versioncmp.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "strbuf.h"
Signature · 1 line
2.46.0.dirty
Re: [PATCH 19/20] global: prepare for hiding away repo-less config functions
Quoted 4 lines · Patrick Steinhardt
We're about to hide config functions that implicitly depend on
the_repositorybehind theUSE_THE_REPOSITORY_VARIABLEmacro. This will uncover a bunch of dependents that transitively relied on the global variable, but didn'd define the macro yet.
s/didn'd/didn't/
Quoted 1 line
Adapt them such that we define the macro to prepare for this change.
Once config functions that rely implicitly on the_repository are guarded by USE_THE_REPOSITORY_VARIABLE, the macro will be required to use them. Now that the dependency is exposed they must be marked accordingly. Makes sense to me.
PATCH 20/20 config: hide functions using `the_repository` by default
In reply to Patrick SteinhardtThe config subsytem provides a bunch of legacy functions that read or set configuration for the_repository. The use of those functions is discouraged, and it is easy to miss the implicit dependency on the_repository that calls to those functions may cause.
Move all config-related functions that use the_repository into a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "config.c", allowing us to remove the definition of said preprocessor macro.
--- config.c | 130 ----------------------------- config.h | 249 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 171 insertions(+), 208 deletions(-)
config.c +0 -130
@@ -6,8 +6,6 @@* */ -#define USE_THE_REPOSITORY_VARIABLE -#include "git-compat-util.h" #include "abspath.h" #include "advice.h"
@@ -2695,78 +2693,6 @@ void git_protected_config(config_fn_t fn, void *data)configset_iter (&protected_config, fn, data); } -/* Functions used historically to read configuration from 'the_repository' */ -void git_config (config_fn_t fn,void *data) -{ -repo_config (the_repository, fn, data); -} - -void git_config_clear (void ) -{ -repo_config_clear (the_repository); -} - -int git_config_get (const char *key) -{ -return repo_config_get (the_repository, key); -} - -int git_config_get_value (const char *key,const char **value) -{ -return repo_config_get_value (the_repository, key, value); -} - -int git_config_get_value_multi (const char *key,const struct string_list **dest) -{ -return repo_config_get_value_multi (the_repository, key, dest); -} - -int git_config_get_string_multi (const char *key, -const struct string_list **dest) -{ -return repo_config_get_string_multi (the_repository, key, dest); -} - -int git_config_get_string (const char *key,char **dest) -{ -return repo_config_get_string (the_repository, key, dest); -} - -int git_config_get_string_tmp (const char *key,const char **dest) -{ -return repo_config_get_string_tmp (the_repository, key, dest); -} - -int git_config_get_int (const char *key,int *dest) -{ -return repo_config_get_int (the_repository, key, dest); -} - -int git_config_get_ulong (const char *key,unsigned long *dest) -{ -return repo_config_get_ulong (the_repository, key, dest); -} - -int git_config_get_bool (const char *key,int *dest) -{ -return repo_config_get_bool (the_repository, key, dest); -} - -int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest) -{ -return repo_config_get_bool_or_int (the_repository, key, is_bool, dest); -} - -int git_config_get_maybe_bool (const char *key,int *dest) -{ -return repo_config_get_maybe_bool (the_repository, key, dest); -} - -int git_config_get_pathname (const char *key,char **dest) -{ -return repo_config_get_pathname (the_repository, key, dest); -} -int repo_config_get_expiry (struct repository *r,const char *key,const char **output) {int ret =repo_config_get_string (r, key, (char **)output);
@@ -3186,35 +3112,17 @@ int repo_config_set_in_file_gently(struct repository *r, const char *config_filereturn repo_config_set_multivar_in_file_gently (r, config_filename, key, value,NULL , comment,0 ); } -int git_config_set_in_file_gently (const char *config_filename, -const char *key,const char *comment,const char *value) -{ -return repo_config_set_in_file_gently (the_repository, config_filename, - key, comment, value); -} -void repo_config_set_in_file (struct repository *r,const char *config_filename,const char *key,const char *value) {repo_config_set_multivar_in_file (r, config_filename, key, value,NULL ,0 ); } -void git_config_set_in_file (const char *config_filename, -const char *key,const char *value) -{ -repo_config_set_in_file (the_repository, config_filename, key, value); -} -int repo_config_set_gently (struct repository *r,const char *key,const char *value) {return repo_config_set_multivar_gently (r, key, value,NULL ,0 ); } -int git_config_set_gently (const char *key,const char *value) -{ -return repo_config_set_gently (the_repository, key, value); -} -int repo_config_set_worktree_gently (struct repository *r,const char *key,const char *value) {
@@ -3236,11 +3144,6 @@ void repo_config_set(struct repository *r, const char *key, const char *value)trace2_cmd_set_config (key, value); } -void git_config_set (const char *key,const char *value) -{ -repo_config_set (the_repository, key, value); -} -char *git_config_prepare_comment_string (const char *comment) {size_t leading_blanks;
@@ -3569,17 +3472,6 @@ int repo_config_set_multivar_in_file_gently(struct repository *r, goto out_free; } -int git_config_set_multivar_in_file_gently (const char *config_filename, -const char *key,const char *value, -const char *value_pattern, -const char *comment, -unsigned flags) -{ -return repo_config_set_multivar_in_file_gently (the_repository, config_filename, - key, value, value_pattern, - comment, flags); -} - void repo_config_set_multivar_in_file(struct repository *r, const char *config_filename, const char *key, const char *value,
@@ -3594,21 +3486,6 @@ void repo_config_set_multivar_in_file(struct repository *r,die (_ ("could not unset '%s'" ), key); } -void git_config_set_multivar_in_file (const char *config_filename, -const char *key,const char *value, -const char *value_pattern,unsigned flags) -{ -repo_config_set_multivar_in_file (the_repository, config_filename, - key, value, value_pattern, flags); -} - -int git_config_set_multivar_gently (const char *key,const char *value, -const char *value_pattern,unsigned flags) -{ -return repo_config_set_multivar_gently (the_repository, key, value, - value_pattern, flags); -} -int repo_config_set_multivar_gently (struct repository *r,const char *key,const char *value,const char *value_pattern,unsigned flags)
@@ -3632,13 +3509,6 @@ void repo_config_set_multivar(struct repository *r,free (file); } -void git_config_set_multivar (const char *key,const char *value, -const char *value_pattern,unsigned flags) -{ -repo_config_set_multivar (the_repository, key, value, - value_pattern, flags); -} -static size_t section_name_match (const char *buf,const char *name) {size_t i =0 , j =0 ;
config.h +171 -78
413 lines not on this page · raw message
Signature · 1 line
2.46.0.dirty
Re: [PATCH 20/20] config: hide functions using `the_repository` by default
Quoted 1 line · Patrick Steinhardt
The config subsytem provides a bunch of legacy functions that read or
s/subsytem/subsystem/
Quoted 9 lines
set configuration for
the_repository. The use of those functions is discouraged, and it is easy to miss the implicit dependency onthe_repositorythat calls to those functions may cause.Move all config-related functions that use
the_repositoryinto a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "config.c", allowing us to remove the definition of said preprocessor macro.
Here we are making the same change done earlier to "path.h". Use of config functions that rely on the_repository implicitly now require the caller to define USE_THE_REPOSITORY_VARIABLE explicitly. Thus improving visibility of use.
Quoted 2 lines
Signed-off-by Patrick Steinhardt <[email protected]>---
[snip]
Quoted 125 lines
config.h +125
-0+# ifdef USE_THE_REPOSITORY_VARIABLE +static inline void git_config (config_fn_t fn,void *data) +{ +repo_config (the_repository, fn, data); +} + +static inline void git_config_clear (void ) +{ +repo_config_clear (the_repository); +} + +static inline int git_config_get (const char *key) +{ +return repo_config_get (the_repository, key); +} + +static inline int git_config_get_value (const char *key,const char **value) +{ +return repo_config_get_value (the_repository, key, value); +} + +static inline int git_config_get_value_multi (const char *key,const struct string_list **dest) +{ +return repo_config_get_value_multi (the_repository, key, dest); +} + +static inline int git_config_get_string_multi (const char *key, +const struct string_list **dest) +{ +return repo_config_get_string_multi (the_repository, key, dest); +} + +static inline int git_config_get_string (const char *key,char **dest) +{ +return repo_config_get_string (the_repository, key, dest); +} + +static inline int git_config_get_string_tmp (const char *key,const char **dest) +{ +return repo_config_get_string_tmp (the_repository, key, dest); +} + +static inline int git_config_get_int (const char *key,int *dest) +{ +return repo_config_get_int (the_repository, key, dest); +} + +static inline int git_config_get_ulong (const char *key,unsigned long *dest) +{ +return repo_config_get_ulong (the_repository, key, dest); +} + +static inline int git_config_get_bool (const char *key,int *dest) +{ +return repo_config_get_bool (the_repository, key, dest); +} + +static inline int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest) +{ +return repo_config_get_bool_or_int (the_repository, key, is_bool, dest); +} + +static inline int git_config_get_maybe_bool (const char *key,int *dest) +{ +return repo_config_get_maybe_bool (the_repository, key, dest); +} + +static inline int git_config_get_pathname (const char *key,char **dest) +{ +return repo_config_get_pathname (the_repository, key, dest); +} + +static inline void git_config_set_in_file (const char *config_filename, +const char *key,const char *value) +{ +repo_config_set_in_file (the_repository, config_filename, key, value); +} + +static inline int git_config_set_gently (const char *key,const char *value) +{ +return repo_config_set_gently (the_repository, key, value); +} + +static inline void git_config_set (const char *key,const char *value) +{ +repo_config_set (the_repository, key, value); +} + +static inline int git_config_set_in_file_gently ( +const char *config_filename, +const char *key, +const char *comment, +const char *value) +{ +return repo_config_set_in_file_gently (the_repository, config_filename, + key, comment, value); +} + +static inline int git_config_set_multivar_in_file_gently ( +const char *config_filename, +const char *key,const char *value, +const char *value_pattern, +const char *comment, +unsigned flags) +{ +return repo_config_set_multivar_in_file_gently (the_repository, config_filename, + key, value, value_pattern, + comment, flags); +} + +static inline void git_config_set_multivar_in_file ( +const char *config_filename, +const char *key, +const char *value, +const char *value_pattern, +unsigned flags) +{ +repo_config_set_multivar_in_file (the_repository, config_filename, + key, value, value_pattern, flags); +} + +static inline int git_config_set_multivar_gently (const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ + return repo_config_set_multivar_gently(the_repository, key, value,
config.h NORETURN void git_die_config_linenr(const char *key, const char *filename, int l · line 835
Quoted 10 lines
config.h +10
-0+ value_pattern, flags); +} + +static inline void git_config_set_multivar (const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +repo_config_set_multivar (the_repository, key, value, + value_pattern, flags); +} +# endif /* USE_THE_REPOSITORY_VARIABLE */
Once again, very neat to see this guarded behindUSE_THE_REPOSITORY_VARIABLE now. :)
-Justin
Quoted 7 lines · Patrick Steinhardt
Hi,
I found that there had been a bunch of callsites in code
not marked withUSE_THE_REPOSITORY_VARIABLEthat still implicitly relied onthe_repositorydue to calling interfaces of "config.c". This patch series has the goal of fixing that and making the dependency implicit.
did you mean 'making the dependency explicit'?
Thanks.
Quoted 10 lines · Ghanshyam Thakkar
Quoted 7 lines · Patrick Steinhardt
Hi,
I found that there had been a bunch of callsites in code
not marked withUSE_THE_REPOSITORY_VARIABLEthat still implicitly relied onthe_repositorydue to calling interfaces of "config.c". This patch series has the goal of fixing that and making the dependency implicit.did you mean 'making the dependency explicit'?
D'oh, of course. Thanks!
Patrick
v2 cover Stop using `the_repository` in "config.c"
In reply to Patrick SteinhardtHi,
this is the second version of my patch series that drops the dependency on the_repository in both "path.c" and "config.c".
Changes compared to v1:
- Various typo fixes in commit messages.
- Rename strbuf_git_common_pathv() to repo_common_pathv().
- Reorder arguments of strbuf_edit_interactively() such that the struct repository gets passed as first argument.
- Document behaviour of worktree_git_path() when no worktree is given.
- Wrap some overly long lines.
Thanks!
Patrick
Patrick Steinhardt (20):
path: expose do_git_path() as repo_git_pathv()
path: expose do_git_common_path() as repo_common_pathv()
editor: do not rely on the_repository for interactive edits
hooks: remove implicit dependency on the_repository
path: stop relying on the_repository when reporting garbage
path: stop relying on the_repository in worktree_git_path()
path: hide functions using the_repository by default
config: introduce missing setters that take repo as parameter
config: expose repo_config_clear()
config: pass repo to git_config_get_index_threads()
config: pass repo to git_config_get_split_index()
config: pass repo to git_config_get_max_percent_split_change()
config: pass repo to git_config_get_expiry()
config: pass repo to git_config_get_expiry_in_days()
config: pass repo to git_die_config()
config: pass repo to functions that rename or copy sections
config: don't have setters depend on the_repository
config: don't depend on the_repository with branch conditions
global: prepare for hiding away repo-less config functions
config: hide functions using the_repository by default
add-patch.c | 3 +- builtin/am.c | 9 +- builtin/branch.c | 7 +- builtin/bugreport.c | 2 +- builtin/checkout.c | 2 +- builtin/clone.c | 2 +- builtin/config.c | 16 +- builtin/count-objects.c | 2 +- builtin/fast-import.c | 4 +- builtin/fsck.c | 2 +- builtin/gc.c | 8 +- builtin/hook.c | 2 +- builtin/merge.c | 2 +- builtin/notes.c | 2 +- builtin/rebase.c | 2 +- builtin/receive-pack.c | 10 +- builtin/remote.c | 4 +- builtin/submodule--helper.c | 2 +- builtin/update-index.c | 4 +- builtin/worktree.c | 6 +- commit.c | 2 +- compat/fsmonitor/fsm-ipc-darwin.c | 2 + compat/precompose_utf8.c | 1 + config.c | 225 ++++++++--------------- config.h | 285 +++++++++++++++++++++--------- connect.c | 2 + credential.c | 2 + daemon.c | 2 + editor.c | 15 +- editor.h | 5 +- fsmonitor.c | 2 + gpg-interface.c | 2 + graph.c | 2 + hook.c | 21 +-- hook.h | 13 +- imap-send.c | 2 + mailinfo.c | 2 + merge-ll.c | 2 + parallel-checkout.c | 2 + path.c | 97 +++------- path.h | 170 ++++++++++++------ protocol.c | 2 + read-cache.c | 22 +-- refs.c | 4 +- refs/packed-backend.c | 2 + refs/reftable-backend.c | 2 + rerere.c | 6 +- reset.c | 2 +- revision.c | 2 +- sequencer.c | 6 +- sideband.c | 2 + submodule.c | 2 +- t/helper/test-advise.c | 2 + t/helper/test-config.c | 2 + t/helper/test-userdiff.c | 2 + trailer.c | 2 + transport.c | 2 +- versioncmp.c | 2 + worktree.c | 2 +- wt-status.c | 14 +- 60 files changed, 570 insertions(+), 457 deletions(-)
Range-diff against v1:
1: 7ce3278f64 = 1: d0f5f2b17f path: expose `do_git_path()` as `repo_git_pathv()` 2: e7a143c30d ! 2: 2e3f474e5d path: expose `do_git_common_path()` as `strbuf_git_common_pathv()`
@@ Metadata
Author: Patrick Steinhardt <[email protected]>
## Commit message ##
- path: expose do_git_common_path() as strbuf_git_common_pathv()
+ path: expose do_git_common_path() as repo_common_pathv()
With the same reasoning as the preceding commit, expose the function
- do_git_common_path() as strbuf_git_common_pathv().
+ do_git_common_path() as repo_common_pathv(). While at it, reorder
+ parameters such that they match the order we have in repo_git_pathv().
@@ path.c: int strbuf_git_path_submodule(struct strbuf *buf, const char *path,
- struct strbuf *buf,
- const char *fmt,
- va_list args)
-+void strbuf_git_common_pathv(struct strbuf *sb,
-+ const struct repository *repo,
-+ const char *fmt,
-+ va_list args)
++void repo_common_pathv(const struct repository *repo,
++ struct strbuf *sb,
++ const char *fmt,
++ va_list args)
{
- strbuf_addstr(buf, repo->commondir);
- if (buf->len && !is_dir_sep(buf->buf[buf->len - 1]))
@@ path.c: const char *git_common_path(const char *fmt, ...)
va_list args;
va_start(args, fmt);
- do_git_common_path(the_repository, pathname, fmt, args);
-+ strbuf_git_common_pathv(pathname, the_repository, fmt, args);
++ repo_common_pathv(the_repository, pathname, fmt, args);
va_end(args);
return pathname->buf;
}
@@ path.c: void strbuf_git_common_path(struct strbuf *sb,
va_list args;
va_start(args, fmt);
- do_git_common_path(repo, sb, fmt, args);
-+ strbuf_git_common_pathv(sb, repo, fmt, args);
++ repo_common_pathv(repo, sb, fmt, args);
va_end(args);
}
@@ path.h: void strbuf_git_common_path(struct strbuf *sb,
const struct repository *repo, const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
-+void strbuf_git_common_pathv(struct strbuf *sb,
-+ const struct repository *repo,
-+ const char *fmt,
-+ va_list args);
++void repo_common_pathv(const struct repository *repo,
++ struct strbuf *buf,
++ const char *fmt,
++ va_list args);
/*
* Return a statically allocated path into the main repository's
3: c2556fff9e ! 3: 2f73e0efcd editor: do not rely on the_repository for interactive edits
@@ Commit message
We implicitly rely on the_repository when editing a file interactively because we call git_path(). Adapt the function to instead take a
- sturct repository as parameter so that we can remove this hidden
+ struct repository as a parameter so that we can remove this hidden
dependency.
@@ add-patch.c: static int edit_hunk_manually(struct add_p_state *s, struct hunk *h
"aborted and the hunk is left unchanged.\n"));
- if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL) < 0)
-+ if (strbuf_edit_interactively(&s->buf, "addp-hunk-edit.diff", NULL,
-+ the_repository) < 0)
++ if (strbuf_edit_interactively(the_repository, &s->buf,
++ "addp-hunk-edit.diff", NULL) < 0)
return -1;
/* strip out commented lines */
## editor.c ##
@@ editor.c: int launch_sequence_editor(const char *path, struct strbuf *buffer,
+ return launch_specified_editor(git_sequence_editor(), path, buffer, env);
}
- int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
-- const char *const *env)
-+ const char *const *env, struct repository *r)
+-int strbuf_edit_interactively(struct strbuf *buffer, const char *path, ++int strbuf_edit_interactively(struct repository *r,
++ struct strbuf *buffer, const char *path,
+ const char *const *env)
{
- char *path2 = NULL;
+ struct strbuf sb = STRBUF_INIT;
@@ editor.h
const char *git_editor(void);
@@ editor.h: int launch_sequence_editor(const char *path, struct strbuf *buffer,
+ *
* If path is relative, it refers to a file in the .git directory. */
- int strbuf_edit_interactively(struct strbuf *buffer, const char *path, +-int strbuf_edit_interactively(struct strbuf *buffer, const char *path,
- const char *const *env);
-+ const char *const *env, struct repository *r);
++int strbuf_edit_interactively(struct repository *r, struct strbuf *buffer,
++ const char *path, const char *const *env);
#endif
4: 9a0964aff3 = 4: 688d705179 hooks: remove implicit dependency on `the_repository` 5: 4368b32f65 = 5: bbaa85ebad path: stop relying on `the_repository` when reporting garbage 6: 67405dcd0a ! 6: 29302f4b14 path: stop relying on `the_repository` in `worktree_git_path()`
@@ path.c: const char *mkpath(const char *fmt, ...)
## path.h ##
@@ path.h: const char *git_path(const char *fmt, ...)
+
+ /*
* Similar to git_path() but can produce paths for a specified
- * worktree instead of current one
+- * worktree instead of current one
++ * worktree instead of current one. When no worktree is given, then the path is ++ * computed relative to main worktree of the given repository.
*/
-const char *worktree_git_path(const struct worktree *wt,
+const char *worktree_git_path(struct repository *r,
7: b4e973a280 ! 7: 1b6651770a path: hide functions using the_repository by default
@@ Metadata
## Commit message ##
path: hide functions using the_repository by default
- The path subsytem provides a bunch of legacy functions that compute
+ The path subsystem provides a bunch of legacy functions that compute
paths relative to the "gitdir" and "commondir" directories of the global the_repository variable. Use of those functions is discouraged, and it is easy to miss the implicit dependency on the_repository that calls to those functions may cause.
With USE_THE_REPOSITORY_VARIABLE, we have recently introduced a tool
- that allows us to get rid of such functions over time. With this define,
+ that allows us to get rid of such functions over time. With this macro,
we can hide away functions that have such implicit dependency such that other subsystems that want to be free of the_repository will not use them by accident.
@@ path.c: void strbuf_repo_git_path(struct strbuf *sb,
char *mkpathdup(const char *fmt, ...)
{
struct strbuf sb = STRBUF_INIT;
-@@ path.c: void strbuf_git_common_pathv(struct strbuf *sb,
+@@ path.c: void repo_common_pathv(const struct repository *repo,
strbuf_cleanup_path(sb);
}
@@ path.c: void strbuf_git_common_pathv(struct strbuf *sb,
- struct strbuf *pathname = get_pathname();
- va_list args;
- va_start(args, fmt);
-- strbuf_git_common_pathv(pathname, the_repository, fmt, args);
+- repo_common_pathv(the_repository, pathname, fmt, args);
- va_end(args);
- return pathname->buf;
-}
@@ path.h: char *mkpathdup(const char *fmt, ...)
* repository's common git directory, which is shared by all worktrees. */
-@@ path.h: void strbuf_git_common_pathv(struct strbuf *sb,
- va_list args);
+@@ path.h: void repo_common_pathv(const struct repository *repo,
+ va_list args);
/*
- * Return a statically allocated path into the main repository's
@@ path.h: void strbuf_repo_git_path(struct strbuf *sb,
-/*
- * Similar to git_path() but can produce paths for a specified
+ * Similar to repo_git_path() but can produce paths for a specified
- * worktree instead of current one
+ * worktree instead of current one. When no worktree is given, then the path is
+ * computed relative to main worktree of the given repository.
*/
- const char *worktree_git_path(struct repository *r,
@@ path.h: const char *worktree_git_path(struct repository *r,
const char *fmt, ...)
__attribute__((format (printf, 3, 4)));
@@ path.h: char *xdg_cache_home(const char *filename);
+ struct strbuf *pathname = get_pathname();
+ va_list args;
+ va_start(args, fmt);
-+ strbuf_git_common_pathv(pathname, the_repository, fmt, args);
++ repo_common_pathv(the_repository, pathname, fmt, args);
+ va_end(args);
+ return pathname->buf;
+}
8: feae2ad31a ! 8: e316491e56 config: introduce missing setters that take repo as parameter
@@ Commit message
While we already provide some of the config-setting interfaces with a struct repository as parameter, others only have a variant that
- implicitly depend on the_repository. Fill in those gaps such that we
+ implicitly depends on the_repository. Fill in those gaps such that we
can start to deprecate the repo-less variants.
9: 63da87696e = 9: 5e73ef6cec config: expose `repo_config_clear()`
10: 03df1277f7 = 10: 35e0f4579c config: pass repo to `git_config_get_index_threads()`
11: 85311d686e = 11: a88ed83b97 config: pass repo to `git_config_get_split_index()`
12: b95ed05f88 = 12: 17c5420d63 config: pass repo to `git_config_get_max_percent_split_change()`
13: 412cc514e8 = 13: f39d4a3244 config: pass repo to `git_config_get_expiry()`
14: cf7942479f ! 14: 111f77e653 config: pass repo to `git_config_get_expiry_in_days()`
@@ rerere.c: void rerere_gc(struct repository *r, struct string_list *rr)
- git_config_get_expiry_in_days("gc.rerereresolved", &cutoff_resolve, now);
- git_config_get_expiry_in_days("gc.rerereunresolved", &cutoff_noresolve, now);
-+ repo_config_get_expiry_in_days(the_repository, "gc.rerereresolved", &cutoff_resolve, now);
-+ repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved", &cutoff_noresolve, now);
++ repo_config_get_expiry_in_days(the_repository, "gc.rerereresolved",
++ &cutoff_resolve, now);
++ repo_config_get_expiry_in_days(the_repository, "gc.rerereunresolved",
++ &cutoff_noresolve, now);
git_config(git_default_config, NULL);
dir = opendir(git_path("rr-cache"));
if (!dir)
15: d70d9bfa7e = 15: 6adee5633a config: pass repo to `git_die_config()`
16: 980533972c = 16: b8c54b751c config: pass repo to functions that rename or copy sections
17: 1c1b27cbac = 17: 1e5cd92e8e config: don't have setters depend on `the_repository`
18: d8530a300b = 18: 96963364e7 config: don't depend on `the_repository` with branch conditions
19: f7617beaa5 ! 19: 124f5794e6 global: prepare for hiding away repo-less config functions @@ Commit message
We're about to hide config functions that implicitly depend on the_repository behind the USE_THE_REPOSITORY_VARIABLE macro. This will uncover a bunch of dependents that transitively relied on the
- global variable, but didn'd define the macro yet.
+ global variable, but didn't define the macro yet.
Adapt them such that we define the macro to prepare for this change.
20: 43757f3077 ! 20: 467cd481f5 config: hide functions using the_repository by default
@@ Metadata
## Commit message ##
config: hide functions using the_repository by default
- The config subsytem provides a bunch of legacy functions that read or
+ The config subsystem provides a bunch of legacy functions that read or
set configuration for the_repository. The use of those functions is discouraged, and it is easy to miss the implicit dependency on the_repository that calls to those functions may cause.
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 1/20 path: expose `do_git_path()` as `repo_git_pathv()`
We're about to move functions of the "path" subsytem that do not use a struct repository into "path.h" as static inlined functions. This will require us to call do_git_path(), which is internal to "path.c".
Expose the function as repo_git_pathv() to prepare for the change.
--- path.c | 20 ++++++++++---------- path.h | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-)
path.c +10 -10
@@ -417,9 +417,9 @@ static void strbuf_worktree_gitdir(struct strbuf *buf,strbuf_git_common_path (buf, repo,"worktrees/%s" , wt->id); } -static void do_git_path (const struct repository *repo, -const struct worktree *wt,struct strbuf *buf, -const char *fmt,va_list args) +void repo_git_pathv (const struct repository *repo, +const struct worktree *wt,struct strbuf *buf, +const char *fmt,va_list args) {int gitdir_len;strbuf_worktree_gitdir (buf, repo, wt);
@@ -438,7 +438,7 @@ char *repo_git_path(const struct repository *repo,struct strbuf path =STRBUF_INIT ;va_list args;va_start (args, fmt); -do_git_path (repo,NULL , &path, fmt, args); +repo_git_pathv (repo,NULL , &path, fmt, args);va_end (args);return strbuf_detach (&path,NULL ); }
@@ -449,7 +449,7 @@ void strbuf_repo_git_path(struct strbuf *sb, {va_list args;va_start (args, fmt); -do_git_path (repo,NULL , sb, fmt, args); +repo_git_pathv (repo,NULL , sb, fmt, args);va_end (args); }
@@ -458,7 +458,7 @@ char *git_path_buf(struct strbuf *buf, const char *fmt, ...)va_list args;strbuf_reset (buf);va_start (args, fmt); -do_git_path (the_repository,NULL , buf, fmt, args); +repo_git_pathv (the_repository,NULL , buf, fmt, args);va_end (args);return buf->buf; }
@@ -467,7 +467,7 @@ void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) {va_list args;va_start (args, fmt); -do_git_path (the_repository,NULL , sb, fmt, args); +repo_git_pathv (the_repository,NULL , sb, fmt, args);va_end (args); }
@@ -476,7 +476,7 @@ const char *git_path(const char *fmt, ...)struct strbuf *pathname =get_pathname ();va_list args;va_start (args, fmt); -do_git_path (the_repository,NULL , pathname, fmt, args); +repo_git_pathv (the_repository,NULL , pathname, fmt, args);va_end (args);return pathname->buf; }
@@ -486,7 +486,7 @@ char *git_pathdup(const char *fmt, ...)struct strbuf path =STRBUF_INIT ;va_list args;va_start (args, fmt); -do_git_path (the_repository,NULL , &path, fmt, args); +repo_git_pathv (the_repository,NULL , &path, fmt, args);va_end (args);return strbuf_detach (&path,NULL ); }
@@ -517,7 +517,7 @@ const char *worktree_git_path(const struct worktree *wt, const char *fmt, ...)struct strbuf *pathname =get_pathname ();va_list args;va_start (args, fmt); -do_git_path (the_repository, wt, pathname, fmt, args); +repo_git_pathv (the_repository, wt, pathname, fmt, args);va_end (args);return pathname->buf; }
path.h +8 -0
@@ -66,6 +66,14 @@ char *repo_git_path(const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 2, 3))); +/* +* Print a path into the git directory of repository `repo` into the provided +* buffer. +*/ +void repo_git_pathv (const struct repository *repo, +const struct worktree *wt,struct strbuf *buf, +const char *fmt,va_list args); +/* * Construct a path into the git directory of repository `repo` and append it * to the provided buffer `sb`.
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 2/20 path: expose `do_git_common_path()` as `repo_common_pathv()`
In reply to Patrick SteinhardtWith the same reasoning as the preceding commit, expose the function do_git_common_path() as repo_common_pathv(). While at it, reorder parameters such that they match the order we have in repo_git_pathv().
--- path.c | 22 +++++++++++----------- path.h | 5 ++++- 2 files changed, 15 insertions(+), 12 deletions(-)
path.c +11 -11
@@ -617,16 +617,16 @@ int strbuf_git_path_submodule(struct strbuf *buf, const char *path,return err; } -static void do_git_common_path (const struct repository *repo, -struct strbuf *buf, -const char *fmt, -va_list args) +void repo_common_pathv (const struct repository *repo, +struct strbuf *sb, +const char *fmt, +va_list args) { -strbuf_addstr (buf, repo->commondir); -if (buf->len && !is_dir_sep (buf->buf[buf->len -1 ])) -strbuf_addch (buf,'/' ); -strbuf_vaddf (buf, fmt, args); -strbuf_cleanup_path (buf); +strbuf_addstr (sb, repo->commondir); +if (sb->len && !is_dir_sep (sb->buf[sb->len -1 ])) +strbuf_addch (sb,'/' ); +strbuf_vaddf (sb, fmt, args); +strbuf_cleanup_path (sb); }const char *git_common_path (const char *fmt, ...)
@@ -634,7 +634,7 @@ const char *git_common_path(const char *fmt, ...)struct strbuf *pathname =get_pathname ();va_list args;va_start (args, fmt); -do_git_common_path (the_repository, pathname, fmt, args); +repo_common_pathv (the_repository, pathname, fmt, args);va_end (args);return pathname->buf; }
@@ -645,7 +645,7 @@ void strbuf_git_common_path(struct strbuf *sb, {va_list args;va_start (args, fmt); -do_git_common_path (repo, sb, fmt, args); +repo_common_pathv (repo, sb, fmt, args);va_end (args); }
path.h +4 -1
@@ -37,6 +37,10 @@ void strbuf_git_common_path(struct strbuf *sb,const struct repository *repo, const char *fmt, ...) __attribute__((format (printf, 3, 4))); +void repo_common_pathv (const struct repository *repo, +struct strbuf *buf, +const char *fmt, +va_list args);/* * Return a statically allocated path into the main repository's
@@ -45,7 +49,6 @@ void strbuf_git_common_path(struct strbuf *sb,const char *git_common_path (const char *fmt, ...) __attribute__((format (printf,1 ,2 ))); -/* * The `git_path` family of functions will construct a path into a repository's * git directory.
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 3/20 editor: do not rely on `the_repository` for interactive edits
In reply to Patrick SteinhardtWe implicitly rely on the_repository when editing a file interactively because we call git_path(). Adapt the function to instead take a struct repository as a parameter so that we can remove this hidden dependency.
--- add-patch.c | 3 ++- editor.c | 13 ++++++++----- editor.h | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-)
add-patch.c +2 -1
@@ -1140,7 +1140,8 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)"removed, then the edit is\n" "aborted and the hunk is left unchanged.\n")); -if (strbuf_edit_interactively (&s->buf,"addp-hunk-edit.diff" ,NULL ) <0 ) +if (strbuf_edit_interactively (the_repository, &s->buf, +"addp-hunk-edit.diff" ,NULL ) <0 )return -1 ;/* strip out commented lines */
editor.c +8 -5
@@ -133,14 +133,17 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,return launch_specified_editor (git_sequence_editor (), path, buffer, env); } -int strbuf_edit_interactively (struct strbuf *buffer,const char *path, +int strbuf_edit_interactively (struct repository *r, +struct strbuf *buffer,const char *path,const char *const *env) { -char *path2 =NULL ; +struct strbuf sb =STRBUF_INIT ;int fd, res =0 ; -if (!is_absolute_path (path)) - path = path2 =xstrdup (git_path ("%s" , path)); +if (!is_absolute_path (path)) { +strbuf_repo_git_path (&sb, r,"%s" , path); + path = sb.buf; + } fd =open (path,O_WRONLY |O_CREAT |O_TRUNC ,0666 );if (fd <0 )
@@ -157,6 +160,6 @@ int strbuf_edit_interactively(struct strbuf *buffer, const char *path,unlink (path); } -free (path2); +strbuf_release (&sb);return res; }
editor.h +3 -2
@@ -1,6 +1,7 @@#ifndef EDITOR_H #define EDITOR_H +struct repository ;struct strbuf ;const char *git_editor (void );
@@ -28,7 +29,7 @@ int launch_sequence_editor(const char *path, struct strbuf *buffer,* * If `path` is relative, it refers to a file in the `.git` directory. */ -int strbuf_edit_interactively (struct strbuf *buffer,const char *path, -const char *const *env); +int strbuf_edit_interactively (struct repository *r,struct strbuf *buffer, +const char *path,const char *const *env);#endif
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 4/20 hooks: remove implicit dependency on `the_repository`
In reply to Patrick SteinhardtWe implicitly depend on the_repository in our hook subsystem because we use strbuf_git_path() to compute hook paths. Remove this dependency by accepting a struct repository as parameter instead.
--- builtin/am.c | 9 +++++---- builtin/bugreport.c | 2 +- builtin/checkout.c | 2 +- builtin/clone.c | 2 +- builtin/gc.c | 2 +- builtin/hook.c | 2 +- builtin/merge.c | 2 +- builtin/rebase.c | 2 +- builtin/receive-pack.c | 10 +++++----- builtin/worktree.c | 2 +- commit.c | 2 +- hook.c | 21 +++++++++++---------- hook.h | 13 ++++++++----- read-cache.c | 6 +++--- refs.c | 2 +- reset.c | 2 +- sequencer.c | 6 +++--- transport.c | 2 +- 18 files changed, 47 insertions(+), 42 deletions(-)
builtin/am.c +5 -4
@@ -490,7 +490,8 @@ static int run_applypatch_msg_hook(struct am_state *state)assert (state->msg);if (!state->no_verify) - ret =run_hooks_l ("applypatch-msg" ,am_path (state,"final-commit" ),NULL ); + ret =run_hooks_l (the_repository,"applypatch-msg" , +am_path (state,"final-commit" ),NULL );if (!ret) {FREE_AND_NULL (state->msg);
@@ -512,7 +513,7 @@ static int run_post_rewrite_hook(const struct am_state *state)strvec_push (&opt.args,"rebase" ); opt.path_to_stdin =am_path (state,"rewritten" ); -return run_hooks_opt ("post-rewrite" , &opt); +return run_hooks_opt (the_repository,"post-rewrite" , &opt); }/**
@@ -1663,7 +1664,7 @@ static void do_commit(const struct am_state *state)const char *reflog_msg, *author, *committer =NULL ;struct strbuf sb =STRBUF_INIT ; -if (!state->no_verify &&run_hooks ("pre-applypatch" )) +if (!state->no_verify &&run_hooks (the_repository,"pre-applypatch" ))exit (1 );if (write_index_as_tree (&tree, the_repository->index,get_index_file (),0 ,NULL ))
@@ -1716,7 +1717,7 @@ static void do_commit(const struct am_state *state)fclose (fp); } -run_hooks ("post-applypatch" ); +run_hooks (the_repository,"post-applypatch" );free_commit_list (parents);strbuf_release (&sb);
builtin/bugreport.c +1 -1
@@ -58,7 +58,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 (hook)) +if (hook_exists (the_repository, hook))strbuf_addf (hook_info,"%s\n" , hook); } }
builtin/checkout.c +1 -1
@@ -125,7 +125,7 @@ static void branch_info_release(struct branch_info *info)static int post_checkout_hook (struct commit *old_commit,struct commit *new_commit,int changed) { -return run_hooks_l ("post-checkout" , +return run_hooks_l (the_repository,"post-checkout" ,oid_to_hex (old_commit ? &old_commit->object.oid :null_oid ()),oid_to_hex (new_commit ? &new_commit->object.oid :null_oid ()), changed ?"1" :"0" ,NULL );
builtin/clone.c +1 -1
@@ -788,7 +788,7 @@ static int checkout(int submodule_progress, int filter_submodules)if (write_locked_index (the_repository->index, &lock_file,COMMIT_LOCK ))die (_ ("unable to write new index file" )); - err |=run_hooks_l ("post-checkout" ,oid_to_hex (null_oid ()), + err |=run_hooks_l (the_repository,"post-checkout" ,oid_to_hex (null_oid ()),oid_to_hex (&oid),"1" ,NULL );if (!err && (option_recurse_submodules.nr >0 )) {
builtin/gc.c +1 -1
@@ -463,7 +463,7 @@ static int need_to_gc(void)else return 0 ; -if (run_hooks ("pre-auto-gc" )) +if (run_hooks (the_repository,"pre-auto-gc" ))return 0 ;return 1 ; }
builtin/hook.c +1 -1
@@ -58,7 +58,7 @@ static int run(int argc, const char **argv, const char *prefix) hook_name = argv[0 ];if (!ignore_missing) opt.error_if_missing =1 ; - ret =run_hooks_opt (hook_name, &opt); + ret =run_hooks_opt (the_repository, hook_name, &opt);if (ret <0 )/* error() return */ ret =1 ;return ret;
builtin/merge.c +1 -1
@@ -478,7 +478,7 @@ static void finish(struct commit *head_commit, }/* Run a post-merge hook */ -run_hooks_l ("post-merge" , squash ?"1" :"0" ,NULL ); +run_hooks_l (the_repository,"post-merge" , squash ?"1" :"0" ,NULL );if (new_head)apply_autostash_ref (the_repository,"MERGE_AUTOSTASH" );
builtin/rebase.c +1 -1
@@ -1774,7 +1774,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)/* If a hook exists, give it a chance to interrupt*/ if (!ok_to_skip_pre_rebase && -run_hooks_l ("pre-rebase" , options.upstream_arg, +run_hooks_l (the_repository,"pre-rebase" , options.upstream_arg, argc ? argv[0 ] :NULL ,NULL ))die (_ ("The pre-rebase hook refused to rebase." ));
builtin/receive-pack.c +5 -5
@@ -792,7 +792,7 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed,struct child_process proc =CHILD_PROCESS_INIT ;struct async muxer;int code; -const char *hook_path =find_hook (hook_name); +const char *hook_path =find_hook (the_repository, hook_name);if (!hook_path)return 0 ;
@@ -922,7 +922,7 @@ static int run_update_hook(struct command *cmd) {struct child_process proc =CHILD_PROCESS_INIT ;int code; -const char *hook_path =find_hook ("update" ); +const char *hook_path =find_hook (the_repository,"update" );if (!hook_path)return 0 ;
@@ -1098,7 +1098,7 @@ static int run_proc_receive_hook(struct command *commands,int hook_use_push_options =0 ;int version =0 ;int code; -const char *hook_path =find_hook ("proc-receive" ); +const char *hook_path =find_hook (the_repository,"proc-receive" );if (!hook_path) {rp_error ("cannot find hook 'proc-receive'" );
@@ -1409,7 +1409,7 @@ static const char *push_to_checkout(unsigned char *hash,strvec_pushf (env,"GIT_WORK_TREE=%s" ,absolute_path (work_tree));strvec_pushv (&opt.env, env->v);strvec_push (&opt.args,hash_to_hex (hash)); -if (run_hooks_opt (push_to_checkout_hook, &opt)) +if (run_hooks_opt (the_repository, push_to_checkout_hook, &opt))return "push-to-checkout hook declined" ;else return NULL ;
@@ -1618,7 +1618,7 @@ static void run_update_post_hook(struct command *commands)struct child_process proc =CHILD_PROCESS_INIT ;const char *hook; - hook =find_hook ("post-update" ); + hook =find_hook (the_repository,"post-update" );if (!hook)return ;
builtin/worktree.c +1 -1
@@ -573,7 +573,7 @@ static int add_worktree(const char *path, const char *refname, NULL); opt.dir = path; - ret =run_hooks_opt ("post-checkout" , &opt); + ret =run_hooks_opt (the_repository,"post-checkout" , &opt); }strvec_clear (&child_env);
commit.c +1 -1
@@ -1960,5 +1960,5 @@ int run_commit_hook(int editor_is_used, const char *index_file,va_end (args); opt.invoked_hook = invoked_hook; -return run_hooks_opt (name, &opt); +return run_hooks_opt (the_repository, name, &opt); }
hook.c +11 -10
@@ -10,14 +10,14 @@#include "environment.h" #include "setup.h" -const char *find_hook (const char *name) +const char *find_hook (struct repository *r,const char *name) {static struct strbuf path =STRBUF_INIT ;int found_hook;strbuf_reset (&path); -strbuf_git_path (&path,"hooks/%s" , name); +strbuf_repo_git_path (&path, r,"hooks/%s" , name); found_hook =access (path.buf,X_OK ) >=0 ;#ifdef STRIP_EXTENSION if (!found_hook) {
@@ -48,9 +48,9 @@ const char *find_hook(const char *name)return path.buf; } -int hook_exists (const char *name) +int hook_exists (struct repository *r,const char *name) { -return !!find_hook (name); +return !!find_hook (r, name); } static int pick_next_hook(struct child_process *cp,
@@ -121,7 +121,8 @@ static void run_hooks_opt_clear(struct run_hooks_opt *options)strvec_clear (&options->args); } -int run_hooks_opt (const char *hook_name,struct run_hooks_opt *options) +int run_hooks_opt (struct repository *r,const char *hook_name, +struct run_hooks_opt *options) {struct strbuf abs_path =STRBUF_INIT ;struct hook_cb_data cb_data = {
@@ -129,7 +130,7 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options) .hook_name = hook_name, .options = options, }; -const char *const hook_path =find_hook (hook_name); +const char *const hook_path =find_hook (r, hook_name);int ret =0 ;const struct run_process_parallel_opts opts = { .tr2_category ="hook" ,
@@ -173,14 +174,14 @@ int run_hooks_opt(const char *hook_name, struct run_hooks_opt *options)return ret; } -int run_hooks (const char *hook_name) +int run_hooks (struct repository *r,const char *hook_name) {struct run_hooks_opt opt =RUN_HOOKS_OPT_INIT ; -return run_hooks_opt (hook_name, &opt); +return run_hooks_opt (r, hook_name, &opt); } -int run_hooks_l (const char *hook_name, ...) +int run_hooks_l (struct repository *r,const char *hook_name, ...) {struct run_hooks_opt opt =RUN_HOOKS_OPT_INIT ;va_list ap;
@@ -191,5 +192,5 @@ int run_hooks_l(const char *hook_name, ...)strvec_push (&opt.args, arg);va_end (ap); -return run_hooks_opt (hook_name, &opt); +return run_hooks_opt (r, hook_name, &opt); }
hook.h +8 -5
@@ -2,6 +2,8 @@#define HOOK_H #include "strvec.h" +struct repository ; +struct run_hooks_opt {/* Environment vars to be set for each hook */
@@ -55,12 +57,12 @@ struct hook_cb_data {* or disabled. Note that this points to static storage that will be * overwritten by further calls to find_hook and run_hook_*. */ -const char *find_hook (const char *name); +const char *find_hook (struct repository *r,const char *name);/** * A boolean version of find_hook() */ -int hook_exists (const char *hookname); +int hook_exists (struct repository *r,const char *hookname);/** * Takes a `hook_name`, resolves it to a path with find_hook(), and
@@ -70,13 +72,14 @@ int hook_exists(const char *hookname);* Returns the status code of the run hook, or a negative value on * error(). */ -int run_hooks_opt (const char *hook_name,struct run_hooks_opt *options); +int run_hooks_opt (struct repository *r,const char *hook_name, +struct run_hooks_opt *options);/** * A wrapper for run_hooks_opt() which provides a dummy "struct * run_hooks_opt" initialized with "RUN_HOOKS_OPT_INIT". */ -int run_hooks (const char *hook_name); +int run_hooks (struct repository *r,const char *hook_name);/** * Like run_hooks(), a wrapper for run_hooks_opt().
@@ -87,5 +90,5 @@ int run_hooks(const char *hook_name);* hook. This function behaves like the old run_hook_le() API. */ LAST_ARG_MUST_BE_NULL -int run_hooks_l(const char *hook_name, ...); +int run_hooks_l(struct repository *r, const char *hook_name, ...);#endif
read-cache.c +3 -3
@@ -3156,9 +3156,9 @@ static int do_write_locked_index(struct index_state *istate,else ret =close_lock_file_gently (lock); -run_hooks_l ("post-index-change" , - istate->updated_workdir ?"1" :"0" , - istate->updated_skipworktree ?"1" :"0" ,NULL ); +run_hooks_l (the_repository,"post-index-change" , + istate->updated_workdir ?"1" :"0" , + istate->updated_skipworktree ?"1" :"0" ,NULL ); istate->updated_workdir =0 ; istate->updated_skipworktree =0 ;
refs.c +1 -1
@@ -2132,7 +2132,7 @@ static int run_transaction_hook(struct ref_transaction *transaction,const char *hook;int ret =0 , i; - hook =find_hook ("reference-transaction" ); + hook =find_hook (transaction->ref_store->repo,"reference-transaction" );if (!hook)return ret;
reset.c +1 -1
@@ -79,7 +79,7 @@ static int update_refs(const struct reset_head_opts *opts, reflog_head); }if (!ret && run_hook) -run_hooks_l ("post-checkout" , +run_hooks_l (the_repository,"post-checkout" ,oid_to_hex (head ? head :null_oid ()),oid_to_hex (oid),"1" ,NULL );strbuf_release (&msg);
sequencer.c +3 -3
@@ -1316,7 +1316,7 @@ static int run_rewrite_hook(const struct object_id *oldoid,struct child_process proc =CHILD_PROCESS_INIT ;int code;struct strbuf sb =STRBUF_INIT ; -const char *hook_path =find_hook ("post-rewrite" ); +const char *hook_path =find_hook (the_repository,"post-rewrite" );if (!hook_path)return 0 ;
@@ -1614,7 +1614,7 @@ static int try_to_commit(struct repository *r, } } -if (hook_exists ("prepare-commit-msg" )) { +if (hook_exists (r,"prepare-commit-msg" )) { res =run_prepare_commit_msg_hook (r, msg, hook_commit);if (res) goto out;
@@ -5149,7 +5149,7 @@ static int pick_commits(struct repository *r, hook_opt.path_to_stdin =rebase_path_rewritten_list ();strvec_push (&hook_opt.args,"rebase" ); -run_hooks_opt ("post-rewrite" , &hook_opt); +run_hooks_opt (r,"post-rewrite" , &hook_opt); }apply_autostash (rebase_path_autostash ());
transport.c +1 -1
@@ -1271,7 +1271,7 @@ static int run_pre_push_hook(struct transport *transport,struct ref *r;struct child_process proc =CHILD_PROCESS_INIT ;struct strbuf buf; -const char *hook_path =find_hook ("pre-push" ); +const char *hook_path =find_hook (the_repository,"pre-push" );if (!hook_path)return 0 ;
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 5/20 path: stop relying on `the_repository` when reporting garbage
In reply to Patrick SteinhardtWe access the_repository in report_linked_checkout_garbage() both directly and indirectly via get_git_dir(). Remove this dependency by instead passing a struct repository as parameter.
--- builtin/count-objects.c | 2 +- path.c | 6 +++--- path.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
builtin/count-objects.c +1 -1
@@ -113,7 +113,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)usage_with_options (count_objects_usage, opts);if (verbose) { report_garbage = real_report_garbage; -report_linked_checkout_garbage (); +report_linked_checkout_garbage (the_repository); } for_each_loose_file_in_objdir(get_object_directory(),
path.c +3 -3
@@ -365,15 +365,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,strbuf_addstr (buf,LOCK_SUFFIX ); } -void report_linked_checkout_garbage (void ) +void report_linked_checkout_garbage (struct repository *r) {struct strbuf sb =STRBUF_INIT ;const struct common_dir *p;int len; -if (!the_repository->different_commondir) +if (!r->different_commondir)return ; -strbuf_addf (&sb,"%s/" ,get_git_dir ()); +strbuf_addf (&sb,"%s/" , r->gitdir); len = sb.len;for (p = common_list; p->path; p++) {const char *path = p->path;
path.h +1 -1
@@ -158,7 +158,7 @@ int strbuf_git_path_submodule(struct strbuf *sb, const char *path, const char *fmt, ...) __attribute__((format (printf, 3, 4))); -void report_linked_checkout_garbage (void ); +void report_linked_checkout_garbage (struct repository *r);/* * You can define a static memoized git path like:
Signature · 1 line
2.46.0.46.g406f326d27.dirty
Re: [PATCH v2 05/20] path: stop relying on `the_repository` when reporting garbage
Quoted 24 lines · Patrick Steinhardt
We access
the_repositoryinreport_linked_checkout_garbage()both directly and indirectly viaget_git_dir(). Remove this dependency by instead passing astruct repositoryas parameter.Signed-off-by Patrick Steinhardt <[email protected]>--- builtin/count-objects.c | 2 +- path.c | 6 +++--- path.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)path.c +1
-1@@ -365,15 +365,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,strbuf_addstr (buf,LOCK_SUFFIX ); } -void report_linked_checkout_garbage (void ) +void report_linked_checkout_garbage (struct repository *r) {struct strbuf sb =STRBUF_INIT ;const struct common_dir *p;
path.c static void update_common_dir(struct strbuf *buf, int git_dir_len, · line 379
Quoted 10 lines
path.c +2
-2int len; -if (!the_repository->different_commondir) +if (!r->different_commondir)return ; -strbuf_addf (&sb,"%s/" ,get_git_dir ()); +strbuf_addf (&sb,"%s/" , r->gitdir); len = sb.len;for (p = common_list; p->path; p++) {const char *path = p->path;
Callers have two options here for accessing the gitdir: one is including environment.h and calling get_git_dir(). The other is passing in struct repository *r and accessing r->gitdir. It's not entirely clear which should be used in what scenario. Sure with the second option the user has the option of passing something in that isn't the_repository but practically speaking that's not happening here and also in the large majority of other scenarios.
I'm OK with this patch for the purposes of the series, but do you think in the future we should introduce get_git_dir(struct repository *r) and change get_git_dir() into get_env_git_dir() that simply calls get_git_dir(the_repository)?
Re: [PATCH v2 05/20] path: stop relying on `the_repository` when reporting garbage
Quoted 44 lines · Calvin Wan
Quoted 24 lines · Patrick Steinhardt
We access
the_repositoryinreport_linked_checkout_garbage()both directly and indirectly viaget_git_dir(). Remove this dependency by instead passing astruct repositoryas parameter.Signed-off-by Patrick Steinhardt <[email protected]>--- builtin/count-objects.c | 2 +- path.c | 6 +++--- path.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)path.c +1
-1@@ -365,15 +365,15 @@ static void update_common_dir(struct strbuf *buf, int git_dir_len,strbuf_addstr (buf,LOCK_SUFFIX ); } -void report_linked_checkout_garbage (void ) +void report_linked_checkout_garbage (struct repository *r) {struct strbuf sb =STRBUF_INIT ;const struct common_dir *p;path.c static void update_common_dir(struct strbuf *buf, int git_dir_len, · line 379
Quoted 10 lines
path.c +2
-2int len; -if (!the_repository->different_commondir) +if (!r->different_commondir)return ; -strbuf_addf (&sb,"%s/" ,get_git_dir ()); +strbuf_addf (&sb,"%s/" , r->gitdir); len = sb.len;for (p = common_list; p->path; p++) {const char *path = p->path;Callers have two options here for accessing the gitdir: one is including
environment.hand callingget_git_dir(). The other is passing instruct repository *rand accessingr->gitdir. It's not entirely clear which should be used in what scenario. Sure with the second option the user has the option of passing something in that isn'tthe_repositorybut practically speaking that's not happening here and also in the large majority of other scenarios.
Quoted 4 lines
I'm OK with this patch for the purposes of the series, but do you think in the future we should introduce
get_git_dir(struct repository *r)and changeget_git_dir()intoget_env_git_dir()that simply callsget_git_dir(the_repository)?
Good question. get_git_dir() is implemented like this:
const char *get_git_dir(void)
{
if (!the_repository->gitdir)
BUG("git environment hasn't been setup");
return the_repository->gitdir;
}We could of course introduce something like repo_get_git_dir() that takes an arbitrary repository as input, like this:
const char *repo_get_git_dir(struct repository *r)
{
if (!r->gitdir)
BUG("git environment hasn't been setup");
return r->gitdir;
}The only benefit that this has is that we double check whether r->gitdir has actually been set in the first place. I don't really think that check is all that useful though, because I expect that the caller either has a repository, and given that a repository always has a gitdir I'd always expect it to be populated. Or they don't have a gitdir, but in that case they cannot call repo_get_git_dir() in the first place because we'd already segfault before hitting the BUG when trying to dereference a NULL pointer.
So I'm not entirely sure of the benefit of such a function over just accessing r->gitdir directly.
Patrick
PATCH v2 6/20 path: stop relying on `the_repository` in `worktree_git_path()`
In reply to Patrick SteinhardtWhen not provided a worktree, then worktree_git_path() will fall back to returning a path relative to the main repository. In this case, we implicitly rely on the_repository to derive the path. Remove this dependency by passing a struct repository as parameter.
--- builtin/fsck.c | 2 +- builtin/worktree.c | 4 ++-- path.c | 9 +++++++-- path.h | 8 +++++--- revision.c | 2 +- worktree.c | 2 +- wt-status.c | 14 +++++++------- 7 files changed, 24 insertions(+), 17 deletions(-)
builtin/fsck.c +1 -1
@@ -1050,7 +1050,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)* and may get overwritten by other calls * while we're examining the index. */ - path =xstrdup (worktree_git_path (wt,"index" )); + path =xstrdup (worktree_git_path (the_repository, wt,"index" ));read_index_from (&istate, path,get_worktree_git_dir (wt));fsck_index (&istate, path, wt->is_current);discard_index (&istate);
builtin/worktree.c +2 -2
@@ -1146,14 +1146,14 @@ static void validate_no_submodules(const struct worktree *wt)struct strbuf path =STRBUF_INIT ;int i, found_submodules =0 ; -if (is_directory (worktree_git_path (wt,"modules" ))) { +if (is_directory (worktree_git_path (the_repository, wt,"modules" ))) {/* * There could be false positives, e.g. the "modules" * directory exists but is empty. But it's a rare case and * this simpler check is probably good enough for now. */ found_submodules =1 ; - }else if (read_index_from (&istate,worktree_git_path (wt,"index" ), + }else if (read_index_from (&istate,worktree_git_path (the_repository, wt,"index" ),get_worktree_git_dir (wt)) >0 ) {for (i =0 ; i < istate.cache_nr; i++) {struct cache_entry *ce = istate.cache[i];
path.c +7 -2
@@ -512,12 +512,17 @@ const char *mkpath(const char *fmt, ...)return cleanup_path (pathname->buf); } -const char *worktree_git_path (const struct worktree *wt,const char *fmt, ...) +const char *worktree_git_path (struct repository *r, +const struct worktree *wt,const char *fmt, ...) {struct strbuf *pathname =get_pathname ();va_list args; + +if (wt && wt->repo != r) +BUG ("worktree not connected to expected repository" ); +va_start (args, fmt); -repo_git_pathv (the_repository, wt, pathname, fmt, args); +repo_git_pathv (r, wt, pathname, fmt, args);va_end (args);return pathname->buf; }
path.h +5 -3
@@ -95,11 +95,13 @@ const char *git_path(const char *fmt, ...)/* * Similar to git_path() but can produce paths for a specified -* worktree instead of current one +* worktree instead of current one. When no worktree is given, then the path is +* computed relative to main worktree of the given repository. */ -const char *worktree_git_path (const struct worktree *wt, +const char *worktree_git_path (struct repository *r, +const struct worktree *wt,const char *fmt, ...) - __attribute__((format (printf,2 ,3 ))); + __attribute__((format (printf,3 ,4 )));/* * Return a path into the main repository's (the_repository) git directory.
revision.c +1 -1
@@ -1872,7 +1872,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)continue ;/* current index already taken care of */ if (read_index_from (&istate, -worktree_git_path (wt,"index" ), +worktree_git_path (the_repository, wt,"index" ),get_worktree_git_dir (wt)) >0 )do_add_index_objects_to_pending (revs, &istate, flags);discard_index (&istate);
worktree.c +1 -1
@@ -252,7 +252,7 @@ const char *worktree_lock_reason(struct worktree *wt)if (!wt->lock_reason_valid) {struct strbuf path =STRBUF_INIT ; -strbuf_addstr (&path,worktree_git_path (wt,"locked" )); +strbuf_addstr (&path,worktree_git_path (the_repository, wt,"locked" ));if (file_exists (path.buf)) {struct strbuf lock_reason =STRBUF_INIT ;if (strbuf_read_file (&lock_reason, path.buf,0 ) <0 )
wt-status.c +7 -7
@@ -1618,7 +1618,7 @@ static char *get_branch(const struct worktree *wt, const char *path)struct object_id oid;const char *branch_name; -if (strbuf_read_file (&sb,worktree_git_path (wt,"%s" , path),0 ) <=0 ) +if (strbuf_read_file (&sb,worktree_git_path (the_repository, wt,"%s" , path),0 ) <=0 ) goto got_nothing;while (sb.len && sb.buf[sb.len -1 ] =='\n' )
@@ -1716,18 +1716,18 @@ int wt_status_check_rebase(const struct worktree *wt, {struct stat st; -if (!stat (worktree_git_path (wt,"rebase-apply" ), &st)) { -if (!stat (worktree_git_path (wt,"rebase-apply/applying" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"rebase-apply" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"rebase-apply/applying" ), &st)) { state->am_in_progress =1 ; -if (!stat (worktree_git_path (wt,"rebase-apply/patch" ), &st) && !st.st_size) +if (!stat (worktree_git_path (the_repository, wt,"rebase-apply/patch" ), &st) && !st.st_size) state->am_empty_patch =1 ; }else { state->rebase_in_progress =1 ; state->branch =get_branch (wt,"rebase-apply/head-name" ); state->onto =get_branch (wt,"rebase-apply/onto" ); } - }else if (!stat (worktree_git_path (wt,"rebase-merge" ), &st)) { -if (!stat (worktree_git_path (wt,"rebase-merge/interactive" ), &st)) + }else if (!stat (worktree_git_path (the_repository, wt,"rebase-merge" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"rebase-merge/interactive" ), &st)) state->rebase_interactive_in_progress =1 ;else state->rebase_in_progress =1 ;
@@ -1743,7 +1743,7 @@ int wt_status_check_bisect(const struct worktree *wt, {struct stat st; -if (!stat (worktree_git_path (wt,"BISECT_LOG" ), &st)) { +if (!stat (worktree_git_path (the_repository, wt,"BISECT_LOG" ), &st)) { state->bisect_in_progress =1 ; state->bisecting_from =get_branch (wt,"BISECT_START" );return 1 ;
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 7/20 path: hide functions using `the_repository` by default
In reply to Patrick SteinhardtThe path subsystem provides a bunch of legacy functions that compute paths relative to the "gitdir" and "commondir" directories of the global the_repository variable. Use of those functions is discouraged, and it is easy to miss the implicit dependency on the_repository that calls to those functions may cause.
With USE_THE_REPOSITORY_VARIABLE, we have recently introduced a tool that allows us to get rid of such functions over time. With this macro, we can hide away functions that have such implicit dependency such that other subsystems that want to be free of the_repository will not use them by accident.
Move all path-related functions that use the_repository into a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "path.c", allowing us to remove the definition of said preprocessor macro.
--- path.c | 52 +------------------- path.h | 147 ++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 100 insertions(+), 99 deletions(-)
path.c +1 -51
@@ -2,8 +2,6 @@* Utilities for paths and pathnames */ -#define USE_THE_REPOSITORY_VARIABLE -#include "git-compat-util.h" #include "abspath.h" #include "environment.h"
@@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode)return 0 ; } -static struct strbuf *get_pathname (void ) +struct strbuf *get_pathname (void ) {static struct strbuf pathname_array[4 ] = {STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT ,STRBUF_INIT
@@ -453,44 +451,6 @@ void strbuf_repo_git_path(struct strbuf *sb,va_end (args); } -char *git_path_buf (struct strbuf *buf,const char *fmt, ...) -{ -va_list args; -strbuf_reset (buf); -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , buf, fmt, args); -va_end (args); -return buf->buf; -} - -void strbuf_git_path (struct strbuf *sb,const char *fmt, ...) -{ -va_list args; -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , sb, fmt, args); -va_end (args); -} - -const char *git_path (const char *fmt, ...) -{ -struct strbuf *pathname =get_pathname (); -va_list args; -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , pathname, fmt, args); -va_end (args); -return pathname->buf; -} - -char *git_pathdup (const char *fmt, ...) -{ -struct strbuf path =STRBUF_INIT ; -va_list args; -va_start (args, fmt); -repo_git_pathv (the_repository,NULL , &path, fmt, args); -va_end (args); -return strbuf_detach (&path,NULL ); -} -char *mkpathdup (const char *fmt, ...) {struct strbuf sb =STRBUF_INIT ;
@@ -634,16 +594,6 @@ void repo_common_pathv(const struct repository *repo,strbuf_cleanup_path (sb); } -const char *git_common_path (const char *fmt, ...) -{ -struct strbuf *pathname =get_pathname (); -va_list args; -va_start (args, fmt); -repo_common_pathv (the_repository, pathname, fmt, args); -va_end (args); -return pathname->buf; -} -void strbuf_git_common_path (struct strbuf *sb,const struct repository *repo,const char *fmt, ...)
path.h +99 -48
184 lines not on this page · raw message
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 8/20 config: introduce missing setters that take repo as parameter
In reply to Patrick SteinhardtWhile we already provide some of the config-setting interfaces with a struct repository as parameter, others only have a variant that implicitly depends on the_repository. Fill in those gaps such that we can start to deprecate the repo-less variants.
--- config.c | 93 ++++++++++++++++++++++++++++++++++++++++++++------------ config.h | 15 ++++++++- 2 files changed, 87 insertions(+), 21 deletions(-)
config.c +73 -20
@@ -3178,21 +3178,39 @@ static void maybe_remove_section(struct config_store_data *store, *end_offset = store->parsed[store->parsed_nr -1 ].end; } +int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value) +{ +return repo_config_set_multivar_in_file_gently (r, config_filename, key, value,NULL , comment,0 ); +} +int git_config_set_in_file_gently (const char *config_filename,const char *key,const char *comment,const char *value) { -return git_config_set_multivar_in_file_gently (config_filename, key, value,NULL , comment,0 ); +return repo_config_set_in_file_gently (the_repository, config_filename, + key, comment, value); +} + +void repo_config_set_in_file (struct repository *r,const char *config_filename, +const char *key,const char *value) +{ +repo_config_set_multivar_in_file (r, config_filename, key, value,NULL ,0 ); }void git_config_set_in_file (const char *config_filename,const char *key,const char *value) { -git_config_set_multivar_in_file (config_filename, key, value,NULL ,0 ); +repo_config_set_in_file (the_repository, config_filename, key, value); +} + +int repo_config_set_gently (struct repository *r,const char *key,const char *value) +{ +return repo_config_set_multivar_gently (r, key, value,NULL ,0 ); }int git_config_set_gently (const char *key,const char *value) { -return git_config_set_multivar_gently (key, value,NULL ,0 ); +return repo_config_set_gently (the_repository, key, value); } int repo_config_set_worktree_gently(struct repository *r,
@@ -3209,13 +3227,18 @@ int repo_config_set_worktree_gently(struct repository *r,return repo_config_set_multivar_gently (r, key, value,NULL ,0 ); } -void git_config_set (const char *key,const char *value) +void repo_config_set (struct repository *r,const char *key,const char *value) { -git_config_set_multivar (key, value,NULL ,0 ); +repo_config_set_multivar (r, key, value,NULL ,0 );trace2_cmd_set_config (key, value); } +void git_config_set (const char *key,const char *value) +{ +repo_config_set (the_repository, key, value); +} +char *git_config_prepare_comment_string (const char *comment) {size_t leading_blanks;
@@ -3293,11 +3316,12 @@ static void validate_comment_string(const char *comment)* - the config file is removed and the lock file rename()d to it. * */ -int git_config_set_multivar_in_file_gently (const char *config_filename, -const char *key,const char *value, -const char *value_pattern, -const char *comment, -unsigned flags) +int repo_config_set_multivar_in_file_gently (struct repository *r, +const char *config_filename, +const char *key,const char *value, +const char *value_pattern, +const char *comment, +unsigned flags) {int fd =-1 , in_fd =-1 ;int ret;
@@ -3317,7 +3341,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, store.multi_replace = (flags &CONFIG_FLAGS_MULTI_REPLACE ) !=0 ;if (!config_filename) - config_filename = filename_buf =git_pathdup ("config" ); + config_filename = filename_buf =repo_git_path (r,"config" );/* * The lock serves a purpose in addition to locking: the new
@@ -3526,7 +3550,7 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, ret =0 ;/* Invalidate the config cache */ -git_config_clear (); +repo_config_clear (r); out_free:rollback_lock_file (&lock);
@@ -3543,12 +3567,24 @@ int git_config_set_multivar_in_file_gently(const char *config_filename, goto out_free; } -void git_config_set_multivar_in_file (const char *config_filename, -const char *key,const char *value, -const char *value_pattern,unsigned flags) +int git_config_set_multivar_in_file_gently (const char *config_filename, +const char *key,const char *value, +const char *value_pattern, +const char *comment, +unsigned flags) { -if (!git_config_set_multivar_in_file_gently (config_filename, key, value, - value_pattern,NULL , flags)) +return repo_config_set_multivar_in_file_gently (the_repository, config_filename, + key, value, value_pattern, + comment, flags); +} + +void repo_config_set_multivar_in_file (struct repository *r, +const char *config_filename, +const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +if (!repo_config_set_multivar_in_file_gently (r, config_filename, key, value, + value_pattern,NULL , flags))return ;if (value)die (_ ("could not set '%s' to '%s'" ), key, value);
@@ -3556,6 +3592,14 @@ void git_config_set_multivar_in_file(const char *config_filename,die (_ ("could not unset '%s'" ), key); } +void git_config_set_multivar_in_file (const char *config_filename, +const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +repo_config_set_multivar_in_file (the_repository, config_filename, + key, value, value_pattern, flags); +} +int git_config_set_multivar_gently (const char *key,const char *value,const char *value_pattern,unsigned flags) {
@@ -3576,12 +3620,21 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key,return res; } +void repo_config_set_multivar (struct repository *r, +const char *key,const char *value, +const char *value_pattern,unsigned flags) +{ +char *file =repo_git_path (r,"config" ); +git_config_set_multivar_in_file (file, key, value, + value_pattern, flags); +free (file); +} +void git_config_set_multivar (const char *key,const char *value,const char *value_pattern,unsigned flags) { -git_config_set_multivar_in_file (git_path ("config" ), - key, value, value_pattern, - flags); +repo_config_set_multivar (the_repository, key, value, + value_pattern, flags); }static size_t section_name_match (const char *buf,const char *name)
config.h +14 -1
@@ -298,14 +298,18 @@ int git_config_pathname(char **, const char *, const char *);int git_config_expiry_date (timestamp_t *,const char *,const char *);int git_config_color (char *,const char *,const char *);int git_config_set_in_file_gently (const char *,const char *,const char *,const char *); +int repo_config_set_in_file_gently (struct repository *r,const char *config_filename, +const char *key,const char *comment,const char *value);/** * write config values to a specific config file, takes a key/value pair as * parameter. */ void git_config_set_in_file (const char *,const char *,const char *); +void repo_config_set_in_file (struct repository *,const char *,const char *,const char *);int git_config_set_gently (const char *,const char *); +int repo_config_set_gently (struct repository *r,const char *,const char *);/** * Write a config value that should apply to the current worktree. If
@@ -318,6 +322,7 @@ int repo_config_set_worktree_gently(struct repository *, const char *, const cha* write config values to `.git/config`, takes a key/value pair as parameter. */ void git_config_set (const char *,const char *); +void repo_config_set (struct repository *,const char *,const char *);int git_config_parse_key (const char *,char **,size_t *);
@@ -341,9 +346,11 @@ int git_config_parse_key(const char *, char **, size_t *);#define CONFIG_FLAGS_FIXED_VALUE (1 << 1)int git_config_set_multivar_gently (const char *,const char *,const char *,unsigned ); -void git_config_set_multivar (const char *,const char *,const char *,unsigned );int repo_config_set_multivar_gently (struct repository *,const char *,const char *,const char *,unsigned ); +void git_config_set_multivar (const char *,const char *,const char *,unsigned ); +void repo_config_set_multivar (struct repository *r,const char *,const char *,const char *,unsigned );int git_config_set_multivar_in_file_gently (const char *,const char *,const char *,const char *,const char *,unsigned ); +int repo_config_set_multivar_in_file_gently (struct repository *,const char *,const char *,const char *,const char *,const char *,unsigned );char *git_config_prepare_comment_string (const char *);
@@ -372,6 +379,12 @@ void git_config_set_multivar_in_file(const char *config_filename,const char *value, const char *value_pattern, unsigned flags); +void repo_config_set_multivar_in_file (struct repository *r, +const char *config_filename, +const char *key, +const char *value, +const char *value_pattern, +unsigned flags);/** * rename or remove sections in the config file
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 9/20 config: expose `repo_config_clear()`
In reply to Patrick SteinhardtWhile we already have repo_config_clear() as an alternative to git_config_clear() that doesn't rely on the_repository, it is not exposed to callers outside of the config subsystem. Do so.
--- config.c | 2 +- config.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
config.c +1 -1
@@ -2564,7 +2564,7 @@ static void git_config_check_init(struct repository *repo)repo_read_config (repo); } -static void repo_config_clear (struct repository *repo) +void repo_config_clear (struct repository *repo) {if (!repo->config || !repo->config->hash_initialized)return ;
config.h +1 -0
@@ -651,6 +651,7 @@ int git_config_get_string_multi(const char *key,* Resets and invalidates the config cache. */ void git_config_clear (void ); +void repo_config_clear (struct repository *repo);/** * Allocates and copies the retrieved string into the `dest` parameter for
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 10/20 config: pass repo to `git_config_get_index_threads()`
In reply to Patrick SteinhardtRefactor git_config_get_index_threads() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
config.c +2 -2
@@ -2826,7 +2826,7 @@ int git_config_get_max_percent_split_change(void)return -1 ;/* default value */ } -int git_config_get_index_threads (int *dest) +int repo_config_get_index_threads (struct repository *r,int *dest) {int is_bool, val;
@@ -2836,7 +2836,7 @@ int git_config_get_index_threads(int *dest)return 0 ; } -if (!git_config_get_bool_or_int ("index.threads" , &is_bool, &val)) { +if (!repo_config_get_bool_or_int (r,"index.threads" , &is_bool, &val)) {if (is_bool) *dest = val ?0 :1 ;else
config.h +1 -1
@@ -710,7 +710,7 @@ int git_config_get_maybe_bool(const char *key, int *dest);*/ int git_config_get_pathname (const char *key,char **dest); -int git_config_get_index_threads (int *dest); +int repo_config_get_index_threads (struct repository *r,int *dest);int git_config_get_split_index (void );int git_config_get_max_percent_split_change (void );
read-cache.c +4 -4
@@ -2267,7 +2267,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) src_offset =sizeof (*hdr); -if (git_config_get_index_threads (&nr_threads)) +if (repo_config_get_index_threads (the_repository, &nr_threads)) nr_threads =1 ;/* TODO: does creating more threads than cores help? */
@@ -2787,7 +2787,7 @@ static int record_eoie(void)* used for threading is written by default if the user * explicitly requested threaded index reads. */ -return !git_config_get_index_threads (&val) && val !=1 ; +return !repo_config_get_index_threads (the_repository, &val) && val !=1 ; }static int record_ieot (void )
@@ -2802,7 +2802,7 @@ static int record_ieot(void)* written by default if the user explicitly requested * threaded index reads. */ -return !git_config_get_index_threads (&val) && val !=1 ; +return !repo_config_get_index_threads (the_repository, &val) && val !=1 ; }enum write_extensions {
@@ -2875,7 +2875,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,hashwrite (f, &hdr,sizeof (hdr)); -if (!HAVE_THREADS ||git_config_get_index_threads (&nr_threads)) +if (!HAVE_THREADS ||repo_config_get_index_threads (the_repository, &nr_threads)) nr_threads =1 ;if (nr_threads !=1 &&record_ieot ()) {
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 11/20 config: pass repo to `git_config_get_split_index()`
In reply to Patrick SteinhardtRefactor git_config_get_split_index() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- builtin/update-index.c | 4 ++-- config.c | 4 ++-- config.h | 2 +- read-cache.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
builtin/update-index.c +2 -2
@@ -1156,7 +1156,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)end_odb_transaction ();if (split_index >0 ) { -if (git_config_get_split_index () ==0 ) +if (repo_config_get_split_index (the_repository) ==0 )warning (_ ("core.splitIndex is set to false; " "remove or change it, if you really want to " "enable split index" ));
@@ -1165,7 +1165,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)else add_split_index (the_repository->index); }else if (!split_index) { -if (git_config_get_split_index () ==1 ) +if (repo_config_get_split_index (the_repository) ==1 )warning (_ ("core.splitIndex is set to true; " "remove or change it, if you really want to " "disable split index" ));
config.c +2 -2
@@ -2801,11 +2801,11 @@ int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamreturn -1 ;/* thing exists but cannot be parsed */ } -int git_config_get_split_index (void ) +int repo_config_get_split_index (struct repository *r) {int val; -if (!git_config_get_maybe_bool ("core.splitindex" , &val)) +if (!repo_config_get_maybe_bool (r,"core.splitindex" , &val))return val;return -1 ;/* default value */
config.h +1 -1
@@ -711,7 +711,7 @@ int git_config_get_maybe_bool(const char *key, int *dest);int git_config_get_pathname (const char *key,char **dest);int repo_config_get_index_threads (struct repository *r,int *dest); -int git_config_get_split_index (void ); +int repo_config_get_split_index (struct repository *r);int git_config_get_max_percent_split_change (void );/* This dies if the configured or default date is in the future */
read-cache.c +1 -1
@@ -1945,7 +1945,7 @@ static void tweak_untracked_cache(struct index_state *istate)static void tweak_split_index (struct index_state *istate) { -switch (git_config_get_split_index ()) { +switch (repo_config_get_split_index (the_repository)) {case -1 :/* unset: do nothing */ break ;case 0 :/* false */
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 12/20 config: pass repo to `git_config_get_max_percent_split_change()`
In reply to Patrick SteinhardtRefactor git_config_get_max_percent_split_change() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
config.c +2 -2
@@ -2811,11 +2811,11 @@ int repo_config_get_split_index(struct repository *r)return -1 ;/* default value */ } -int git_config_get_max_percent_split_change (void ) +int repo_config_get_max_percent_split_change (struct repository *r) {int val =-1 ; -if (!git_config_get_int ("splitindex.maxpercentchange" , &val)) { +if (!repo_config_get_int (r,"splitindex.maxpercentchange" , &val)) {if (0 <= val && val <=100 )return val;
config.h +1 -1
@@ -712,7 +712,7 @@ int git_config_get_pathname(const char *key, char **dest);int repo_config_get_index_threads (struct repository *r,int *dest);int repo_config_get_split_index (struct repository *r); -int git_config_get_max_percent_split_change (void ); +int repo_config_get_max_percent_split_change (struct repository *r);/* This dies if the configured or default date is in the future */ int git_config_get_expiry (const char *key,const char **output);
read-cache.c +1 -1
@@ -3275,7 +3275,7 @@ static const int default_max_percent_split_change = 20;static int too_many_not_shared_entries (struct index_state *istate) {int i, not_shared =0 ; -int max_split =git_config_get_max_percent_split_change (); +int max_split =repo_config_get_max_percent_split_change (the_repository);switch (max_split) {case -1 :
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 13/20 config: pass repo to `git_config_get_expiry()`
In reply to Patrick SteinhardtRefactor git_config_get_expiry() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- builtin/gc.c | 6 +++--- config.c | 4 ++-- config.h | 2 +- read-cache.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-)
builtin/gc.c +3 -3
@@ -167,9 +167,9 @@ static void gc_config(void)git_config_get_bool ("gc.autodetach" , &detach_auto);git_config_get_bool ("gc.cruftpacks" , &cruft_packs);git_config_get_ulong ("gc.maxcruftsize" , &max_cruft_size); -git_config_get_expiry ("gc.pruneexpire" , &prune_expire); -git_config_get_expiry ("gc.worktreepruneexpire" , &prune_worktrees_expire); -git_config_get_expiry ("gc.logexpiry" , &gc_log_expire); +repo_config_get_expiry (the_repository,"gc.pruneexpire" , &prune_expire); +repo_config_get_expiry (the_repository,"gc.worktreepruneexpire" , &prune_worktrees_expire); +repo_config_get_expiry (the_repository,"gc.logexpiry" , &gc_log_expire);git_config_get_ulong ("gc.bigpackthreshold" , &big_pack_threshold);git_config_get_ulong ("pack.deltacachesize" , &max_delta_cache_size);
config.c +2 -2
@@ -2766,9 +2766,9 @@ int git_config_get_pathname(const char *key, char **dest)return repo_config_get_pathname (the_repository, key, dest); } -int git_config_get_expiry (const char *key,const char **output) +int repo_config_get_expiry (struct repository *r,const char *key,const char **output) { -int ret =git_config_get_string (key, (char **)output); +int ret =repo_config_get_string (r, key, (char **)output);if (ret)return ret;if (strcmp (*output,"now" )) {
config.h +1 -1
@@ -715,7 +715,7 @@ int repo_config_get_split_index(struct repository *r);int repo_config_get_max_percent_split_change (struct repository *r);/* This dies if the configured or default date is in the future */ -int git_config_get_expiry (const char *key,const char **output); +int repo_config_get_expiry (struct repository *r,const char *key,const char **output);/* parse either "this many days" integer, or "5.days.ago" approxidate */ int git_config_get_expiry_in_days (const char *key,timestamp_t *,timestamp_t now);
read-cache.c +2 -2
@@ -3184,8 +3184,8 @@ static unsigned long get_shared_index_expire_date(void)static int shared_index_expire_date_prepared;if (!shared_index_expire_date_prepared) { -git_config_get_expiry ("splitindex.sharedindexexpire" , - &shared_index_expire); +repo_config_get_expiry (the_repository,"splitindex.sharedindexexpire" , + &shared_index_expire); shared_index_expire_date =approxidate (shared_index_expire); shared_index_expire_date_prepared =1 ; }
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 14/20 config: pass repo to `git_config_get_expiry_in_days()`
In reply to Patrick SteinhardtRefactor git_config_get_expiry_in_days() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- config.c | 5 +++-- config.h | 3 ++- rerere.c | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-)
config.c +3 -2
@@ -2779,13 +2779,14 @@ int repo_config_get_expiry(struct repository *r, const char *key, const char **oreturn ret; } -int git_config_get_expiry_in_days (const char *key,timestamp_t *expiry,timestamp_t now) +int repo_config_get_expiry_in_days (struct repository *r,const char *key, +timestamp_t *expiry,timestamp_t now) {const char *expiry_string;intmax_t days;timestamp_t when; -if (git_config_get_string_tmp (key, &expiry_string)) +if (repo_config_get_string_tmp (r, key, &expiry_string))return 1 ;/* no such thing */ if (git_parse_signed (expiry_string, &days,maximum_signed_value_of_type (int))) {
config.h +2 -1
@@ -718,7 +718,8 @@ int repo_config_get_max_percent_split_change(struct repository *r);int repo_config_get_expiry (struct repository *r,const char *key,const char **output);/* parse either "this many days" integer, or "5.days.ago" approxidate */ -int git_config_get_expiry_in_days (const char *key,timestamp_t *,timestamp_t now); +int repo_config_get_expiry_in_days (struct repository *r,const char *key, +timestamp_t *,timestamp_t now);/** * First prints the error message specified by the caller in `err` and then
rerere.c +4 -2
@@ -1203,8 +1203,10 @@ void rerere_gc(struct repository *r, struct string_list *rr)if (setup_rerere (r, rr,0 ) <0 )return ; -git_config_get_expiry_in_days ("gc.rerereresolved" , &cutoff_resolve, now); -git_config_get_expiry_in_days ("gc.rerereunresolved" , &cutoff_noresolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereresolved" , + &cutoff_resolve, now); +repo_config_get_expiry_in_days (the_repository,"gc.rerereunresolved" , + &cutoff_noresolve, now);git_config (git_default_config,NULL ); dir =opendir (git_path ("rr-cache" ));if (!dir)
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 15/20 config: pass repo to `git_die_config()`
In reply to Patrick SteinhardtRefactor git_die_config() to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the function accordingly.
--- builtin/fast-import.c | 4 ++-- builtin/notes.c | 2 +- config.c | 12 ++++++------ config.h | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-)
builtin/fast-import.c +2 -2
@@ -3481,8 +3481,8 @@ static void git_pack_config(void)if (!git_config_get_int ("pack.indexversion" , &indexversion_value)) { pack_idx_opts.version = indexversion_value;if (pack_idx_opts.version >2 ) -git_die_config ("pack.indexversion" , -"bad pack.indexVersion=%" PRIu32, pack_idx_opts.version); +git_die_config (the_repository,"pack.indexversion" , +"bad pack.indexVersion=%" PRIu32, pack_idx_opts.version); }if (!git_config_get_ulong ("pack.packsizelimit" , &packsizelimit_value)) max_packsize = packsizelimit_value;
builtin/notes.c +1 -1
@@ -868,7 +868,7 @@ static int git_config_get_notes_strategy(const char *key,if (git_config_get_string (key, &value))return 1 ;if (parse_notes_merge_strategy (value, strategy)) -git_die_config (key,_ ("unknown notes merge strategy %s" ), value); +git_die_config (the_repository, key,_ ("unknown notes merge strategy %s" ), value);free (value);return 0 ;
config.c +6 -6
@@ -2611,7 +2611,7 @@ int repo_config_get_string(struct repository *repo,git_config_check_init (repo); ret =git_configset_get_string (repo->config, key, dest);if (ret <0 ) -git_die_config (key,NULL ); +git_die_config (repo, key,NULL );return ret; }
@@ -2622,7 +2622,7 @@ int repo_config_get_string_tmp(struct repository *repo,git_config_check_init (repo); ret =git_configset_get_string_tmp (repo->config, key, dest);if (ret <0 ) -git_die_config (key,NULL ); +git_die_config (repo, key,NULL );return ret; }
@@ -2668,7 +2668,7 @@ int repo_config_get_pathname(struct repository *repo,git_config_check_init (repo); ret =git_configset_get_pathname (repo->config, key, dest);if (ret <0 ) -git_die_config (key,NULL ); +git_die_config (repo, key,NULL );return ret; }
@@ -2774,7 +2774,7 @@ int repo_config_get_expiry(struct repository *r, const char *key, const char **oif (strcmp (*output,"now" )) {timestamp_t now =approxidate ("now" );if (approxidate (*output) >= now) -git_die_config (key,_ ("Invalid %s: '%s'" ), key, *output); +git_die_config (r, key,_ ("Invalid %s: '%s'" ), key, *output); }return ret; }
@@ -2858,7 +2858,7 @@ void git_die_config_linenr(const char *key, const char *filename, int linenr) key, filename, linenr); } -void git_die_config (const char *key,const char *err, ...) +void git_die_config (struct repository *r,const char *key,const char *err, ...) {const struct string_list *values;struct key_value_info *kv_info;
@@ -2870,7 +2870,7 @@ void git_die_config(const char *key, const char *err, ...)error_fn (err, params);va_end (params); } -if (git_config_get_value_multi (key, &values)) +if (repo_config_get_value_multi (r, key, &values))BUG ("for key '%s' we must have a value to report on" , key); kv_info = values->items[values->nr -1 ].util;git_die_config_linenr (key, kv_info->filename, kv_info->linenr);
config.h +2 -1
@@ -726,7 +726,8 @@ int repo_config_get_expiry_in_days(struct repository *r, const char *key,* dies printing the line number and the file name of the highest priority * value for the configuration variable `key`. */ -NORETURN void git_die_config(const char *key, const char *err, ...) __attribute__((format(printf, 2, 3))); +NORETURN void git_die_config(struct repository *r, const char *key, const char *err, ...) + __attribute__((format (printf,3 ,4 )));/** * Helper function which formats the die error message according to the
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 16/20 config: pass repo to functions that rename or copy sections
In reply to Patrick SteinhardtRefactor functions that rename or copy config sections to accept a struct repository such that we can get rid of the implicit dependency on the_repository. Rename the functions accordingly.
--- builtin/branch.c | 7 ++++--- builtin/config.c | 16 ++++++++-------- builtin/remote.c | 4 ++-- builtin/submodule--helper.c | 2 +- config.c | 30 ++++++++++++++++-------------- config.h | 8 ++++---- submodule.c | 2 +- 7 files changed, 36 insertions(+), 33 deletions(-)
builtin/branch.c +4 -3
@@ -210,7 +210,7 @@ static void delete_branch_config(const char *branchname) {struct strbuf buf =STRBUF_INIT ;strbuf_addf (&buf,"branch.%s" , branchname); -if (git_config_rename_section (buf.buf,NULL ) <0 ) +if (repo_config_rename_section (the_repository, buf.buf,NULL ) <0 )warning (_ ("update of config-file failed" ));strbuf_release (&buf); }
@@ -659,9 +659,10 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, intstrbuf_addf (&oldsection,"branch.%s" , interpreted_oldname);strbuf_addf (&newsection,"branch.%s" , interpreted_newname); -if (!copy &&git_config_rename_section (oldsection.buf, newsection.buf) <0 ) +if (!copy &&repo_config_rename_section (the_repository, oldsection.buf, newsection.buf) <0 )die (_ ("branch is renamed, but update of config-file failed" )); -if (copy &&strcmp (interpreted_oldname, interpreted_newname) &&git_config_copy_section (oldsection.buf, newsection.buf) <0 ) +if (copy &&strcmp (interpreted_oldname, interpreted_newname) && +repo_config_copy_section (the_repository, oldsection.buf, newsection.buf) <0 )die (_ ("branch is copied, but update of config-file failed" ));strbuf_release (&oldref);strbuf_release (&newref);
builtin/config.c +8 -8
@@ -1026,8 +1026,8 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *prlocation_options_init (&location_opts, prefix);check_write (&location_opts.source); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ], argv[1 ]); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ], argv[1 ]);if (ret <0 ) goto out;else if (!ret)
@@ -1055,8 +1055,8 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *prlocation_options_init (&location_opts, prefix);check_write (&location_opts.source); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ],NULL ); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ],NULL );if (ret <0 ) goto out;else if (!ret)
@@ -1353,8 +1353,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)else if (actions ==ACTION_RENAME_SECTION ) {check_write (&location_opts.source);check_argc (argc,2 ,2 ); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ], argv[1 ]); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ], argv[1 ]);if (ret <0 ) goto out;else if (!ret)
@@ -1365,8 +1365,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix)else if (actions ==ACTION_REMOVE_SECTION ) {check_write (&location_opts.source);check_argc (argc,1 ,1 ); - ret =git_config_rename_section_in_file (location_opts.source.file, - argv[0 ],NULL ); + ret =repo_config_rename_section_in_file (the_repository, location_opts.source.file, + argv[0 ],NULL );if (ret <0 ) goto out;else if (!ret)
builtin/remote.c +2 -2
@@ -736,7 +736,7 @@ static int mv(int argc, const char **argv, const char *prefix)strbuf_addf (&buf,"remote.%s" , rename.old_name);strbuf_addf (&buf2,"remote.%s" , rename.new_name); -if (git_config_rename_section (buf.buf, buf2.buf) <1 ) +if (repo_config_rename_section (the_repository, buf.buf, buf2.buf) <1 )return error (_ ("Could not rename config section '%s' to '%s'" ), buf.buf, buf2.buf);
@@ -944,7 +944,7 @@ static int rm(int argc, const char **argv, const char *prefix)if (!result) {strbuf_addf (&buf,"remote.%s" , remote->name); -if (git_config_rename_section (buf.buf,NULL ) <1 ) +if (repo_config_rename_section (the_repository, buf.buf,NULL ) <1 )return error (_ ("Could not remove config section '%s'" ), buf.buf);handle_push_default (remote->name,NULL );
builtin/submodule--helper.c +1 -1
@@ -1455,7 +1455,7 @@ static void deinit_submodule(const char *path, const char *prefix,* remove the whole section so we have a clean state when * the user later decides to init this submodule again */ -git_config_rename_section_in_file (NULL , sub_key,NULL ); +repo_config_rename_section_in_file (the_repository,NULL , sub_key,NULL );if (!(flags &OPT_QUIET ))printf (_ ("Submodule '%s' (%s) unregistered for path '%s'\n" ), sub->name, sub->url, displaypath);
config.c +16 -14
@@ -3697,9 +3697,11 @@ static int section_name_is_ok(const char *name)#define GIT_CONFIG_MAX_LINE_LEN (512 * 1024)/* if new_name == NULL, the section is removed instead */ -static int git_config_copy_or_rename_section_in_file (const char *config_filename, -const char *old_name, -const char *new_name,int copy) +static int repo_config_copy_or_rename_section_in_file ( +struct repository *r, +const char *config_filename, +const char *old_name, +const char *new_name,int copy) {int ret =0 , remove =0 ;char *filename_buf =NULL ;
@@ -3720,7 +3722,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename }if (!config_filename) - config_filename = filename_buf =git_pathdup ("config" ); + config_filename = filename_buf =repo_git_path (r,"config" ); out_fd =hold_lock_file_for_update (&lock, config_filename,0 );if (out_fd <0 ) {
@@ -3863,28 +3865,28 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filenamereturn ret; } -int git_config_rename_section_in_file (const char *config_filename, -const char *old_name,const char *new_name) +int repo_config_rename_section_in_file (struct repository *r,const char *config_filename, +const char *old_name,const char *new_name) { -return git_config_copy_or_rename_section_in_file (config_filename, +return repo_config_copy_or_rename_section_in_file (r, config_filename, old_name, new_name,0 ); } -int git_config_rename_section (const char *old_name,const char *new_name) +int repo_config_rename_section (struct repository *r,const char *old_name,const char *new_name) { -return git_config_rename_section_in_file (NULL , old_name, new_name); +return repo_config_rename_section_in_file (r,NULL , old_name, new_name); } -int git_config_copy_section_in_file (const char *config_filename, -const char *old_name,const char *new_name) +int repo_config_copy_section_in_file (struct repository *r,const char *config_filename, +const char *old_name,const char *new_name) { -return git_config_copy_or_rename_section_in_file (config_filename, +return repo_config_copy_or_rename_section_in_file (r, config_filename, old_name, new_name,1 ); } -int git_config_copy_section (const char *old_name,const char *new_name) +int repo_config_copy_section (struct repository *r,const char *old_name,const char *new_name) { -return git_config_copy_section_in_file (NULL , old_name, new_name); +return repo_config_copy_section_in_file (r,NULL , old_name, new_name); }/*
config.h +4 -4
@@ -392,11 +392,11 @@ void repo_config_set_multivar_in_file(struct repository *r,* If NULL is passed through `new_name` parameter, * the section will be removed from the config file. */ -int git_config_rename_section (const char *,const char *); +int repo_config_rename_section (struct repository *,const char *,const char *); -int git_config_rename_section_in_file (const char *,const char *,const char *); -int git_config_copy_section (const char *,const char *); -int git_config_copy_section_in_file (const char *,const char *,const char *); +int repo_config_rename_section_in_file (struct repository *,const char *,const char *,const char *); +int repo_config_copy_section (struct repository *,const char *,const char *); +int repo_config_copy_section_in_file (struct repository *,const char *,const char *,const char *);int git_config_system (void );int config_error_nonbool (const char *);#if defined(__GNUC__)
submodule.c +1 -1
@@ -159,7 +159,7 @@ int remove_path_from_gitmodules(const char *path) }strbuf_addstr (§,"submodule." );strbuf_addstr (§, submodule->name); -if (git_config_rename_section_in_file (GITMODULES_FILE , sect.buf,NULL ) <0 ) { +if (repo_config_rename_section_in_file (the_repository,GITMODULES_FILE , sect.buf,NULL ) <0 ) {/* Maybe the user already did that, don't error out here */ warning (_ ("Could not remove .gitmodules entry for %s" ), path);strbuf_release (§);
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 17/20 config: don't have setters depend on `the_repository`
In reply to Patrick SteinhardtSome of the setters that accept a struct repository still implicitly rely on the_repository via git_config_set_multivar_in_file(). While this function would typically use the caller-provided path, it knows to fall back to using the configuration path indicated by the_repository.
Adapt those functions to instead use the caller-provided repository.
--- config.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
config.c +8 -8
@@ -3220,8 +3220,8 @@ int repo_config_set_worktree_gently(struct repository *r,/* Only use worktree-specific config if it is already enabled. */ if (r->repository_format_worktree_config) {char *file =repo_git_path (r,"config.worktree" ); -int ret =git_config_set_multivar_in_file_gently ( - file, key, value,NULL ,NULL ,0 ); +int ret =repo_config_set_multivar_in_file_gently ( + r, file, key, value,NULL ,NULL ,0 );free (file);return ret; }
@@ -3613,10 +3613,10 @@ int repo_config_set_multivar_gently(struct repository *r, const char *key, const char *value_pattern, unsigned flags) { char *file = repo_git_path(r, "config"); -int res =git_config_set_multivar_in_file_gently (file, - key, value, - value_pattern, -NULL , flags); +int res =repo_config_set_multivar_in_file_gently (r, file, + key, value, + value_pattern, +NULL , flags);free (file);return res; }
@@ -3626,8 +3626,8 @@ void repo_config_set_multivar(struct repository *r, const char *value_pattern, unsigned flags) { char *file = repo_git_path(r, "config"); -git_config_set_multivar_in_file (file, key, value, - value_pattern, flags); +repo_config_set_multivar_in_file (r, file, key, value, + value_pattern, flags);free (file); }
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 18/20 config: don't depend on `the_repository` with branch conditions
In reply to Patrick SteinhardtWhen computing branch "includeIf" conditions we use the_repository to obtain the main ref store. We really shouldn't depend on this global repository though, but should instead use the repository that is being passed to us via struct config_include_data. Otherwise, when parsing configuration of e.g. submodules, we may end up evaluating the condition the via the wrong refdb.
Fix this.
--- config.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
config.c +5 -4
@@ -300,13 +300,14 @@ static int include_by_gitdir(const struct key_value_info *kvi,return ret; } -static int include_by_branch (const char *cond,size_t cond_len) +static int include_by_branch (struct config_include_data *data, +const char *cond,size_t cond_len) {int flags;int ret;struct strbuf pattern =STRBUF_INIT ; -const char *refname = !the_repository->gitdir ? -NULL :refs_resolve_ref_unsafe (get_main_ref_store (the_repository), +const char *refname = (!data->repo || !data->repo->gitdir) ? +NULL :refs_resolve_ref_unsafe (get_main_ref_store (data->repo),"HEAD" ,0 ,NULL , &flags);const char *shortname;
@@ -406,7 +407,7 @@ static int include_condition_is_true(const struct key_value_info *kvi,else if (skip_prefix_mem (cond, cond_len,"gitdir/i:" , &cond, &cond_len))return include_by_gitdir (kvi, opts, cond, cond_len,1 );else if (skip_prefix_mem (cond, cond_len,"onbranch:" , &cond, &cond_len)) -return include_by_branch (cond, cond_len); +return include_by_branch (inc, cond, cond_len);else if (skip_prefix_mem (cond, cond_len,"hasconfig:remote.*.url:" , &cond, &cond_len))return include_by_remote_url (inc, cond, cond_len);
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 19/20 global: prepare for hiding away repo-less config functions
In reply to Patrick SteinhardtWe're about to hide config functions that implicitly depend on the_repository behind the USE_THE_REPOSITORY_VARIABLE macro. This will uncover a bunch of dependents that transitively relied on the global variable, but didn't define the macro yet.
Adapt them such that we define the macro to prepare for this change.
--- compat/fsmonitor/fsm-ipc-darwin.c | 2 ++ compat/precompose_utf8.c | 1 + connect.c | 2 ++ credential.c | 2 ++ daemon.c | 2 ++ editor.c | 2 ++ fsmonitor.c | 2 ++ gpg-interface.c | 2 ++ graph.c | 2 ++ imap-send.c | 2 ++ mailinfo.c | 2 ++ merge-ll.c | 2 ++ parallel-checkout.c | 2 ++ protocol.c | 2 ++ refs.c | 2 ++ refs/packed-backend.c | 2 ++ refs/reftable-backend.c | 2 ++ sideband.c | 2 ++ t/helper/test-advise.c | 2 ++ t/helper/test-config.c | 2 ++ t/helper/test-userdiff.c | 2 ++ trailer.c | 2 ++ versioncmp.c | 2 ++ 23 files changed, 45 insertions(+)
compat/fsmonitor/fsm-ipc-darwin.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "gettext.h"
compat/precompose_utf8.c +1 -0
@@ -4,6 +4,7 @@*/ #define PRECOMPOSE_UNICODE_C +#define USE_THE_REPOSITORY_VARIABLE #include "git-compat-util.h" #include "config.h"
connect.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "environment.h"
credential.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "abspath.h" #include "config.h"
daemon.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "abspath.h" #include "config.h"
editor.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "abspath.h" #include "advice.h"
fsmonitor.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "dir.h"
gpg-interface.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "commit.h" #include "config.h"
graph.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "gettext.h" #include "config.h"
imap-send.c +2 -0
@@ -21,6 +21,8 @@* along with this program; if not, see <https://www.gnu.org/licenses/>. */ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "credential.h"
mailinfo.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "gettext.h"
merge-ll.c +2 -0
@@ -4,6 +4,8 @@* Copyright (c) 2007 Junio C Hamano */ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "convert.h"
parallel-checkout.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "entry.h"
protocol.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "environment.h"
refs.c +2 -0
@@ -2,6 +2,8 @@* The backend-independent part of the reference module. */ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "advice.h" #include "config.h"
refs/packed-backend.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "../git-compat-util.h" #include "../config.h" #include "../dir.h"
refs/reftable-backend.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "../git-compat-util.h" #include "../abspath.h" #include "../chdir-notify.h"
sideband.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "color.h" #include "config.h"
t/helper/test-advise.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "test-tool.h" #include "advice.h" #include "config.h"
t/helper/test-config.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "test-tool.h" #include "config.h" #include "setup.h"
t/helper/test-userdiff.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "test-tool.h" #include "setup.h" #include "userdiff.h"
trailer.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "environment.h"
versioncmp.c +2 -0
@@ -1,3 +1,5 @@ +#define USE_THE_REPOSITORY_VARIABLE +#include "git-compat-util.h" #include "config.h" #include "strbuf.h"
Signature · 1 line
2.46.0.46.g406f326d27.dirty
PATCH v2 20/20 config: hide functions using `the_repository` by default
In reply to Patrick SteinhardtThe config subsystem provides a bunch of legacy functions that read or set configuration for the_repository. The use of those functions is discouraged, and it is easy to miss the implicit dependency on the_repository that calls to those functions may cause.
Move all config-related functions that use the_repository into a block that gets only conditionally compiled depending on whether or not the macro has been defined. This also removes all dependencies on that variable in "config.c", allowing us to remove the definition of said preprocessor macro.
--- config.c | 130 ----------------------------- config.h | 249 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 171 insertions(+), 208 deletions(-)
config.c +0 -130
@@ -6,8 +6,6 @@* */ -#define USE_THE_REPOSITORY_VARIABLE -#include "git-compat-util.h" #include "abspath.h" #include "advice.h"
@@ -2695,78 +2693,6 @@ void git_protected_config(config_fn_t fn, void *data)configset_iter (&protected_config, fn, data); } -/* Functions used historically to read configuration from 'the_repository' */ -void git_config (config_fn_t fn,void *data) -{ -repo_config (the_repository, fn, data); -} - -void git_config_clear (void ) -{ -repo_config_clear (the_repository); -} - -int git_config_get (const char *key) -{ -return repo_config_get (the_repository, key); -} - -int git_config_get_value (const char *key,const char **value) -{ -return repo_config_get_value (the_repository, key, value); -} - -int git_config_get_value_multi (const char *key,const struct string_list **dest) -{ -return repo_config_get_value_multi (the_repository, key, dest); -} - -int git_config_get_string_multi (const char *key, -const struct string_list **dest) -{ -return repo_config_get_string_multi (the_repository, key, dest); -} - -int git_config_get_string (const char *key,char **dest) -{ -return repo_config_get_string (the_repository, key, dest); -} - -int git_config_get_string_tmp (const char *key,const char **dest) -{ -return repo_config_get_string_tmp (the_repository, key, dest); -} - -int git_config_get_int (const char *key,int *dest) -{ -return repo_config_get_int (the_repository, key, dest); -} - -int git_config_get_ulong (const char *key,unsigned long *dest) -{ -return repo_config_get_ulong (the_repository, key, dest); -} - -int git_config_get_bool (const char *key,int *dest) -{ -return repo_config_get_bool (the_repository, key, dest); -} - -int git_config_get_bool_or_int (const char *key,int *is_bool,int *dest) -{ -return repo_config_get_bool_or_int (the_repository, key, is_bool, dest); -} - -int git_config_get_maybe_bool (const char *key,int *dest) -{ -return repo_config_get_maybe_bool (the_repository, key, dest); -} - -int git_config_get_pathname (const char *key,char **dest) -{ -return repo_config_get_pathname (the_repository, key, dest); -} -int repo_config_get_expiry (struct repository *r,const char *key,const char **output) {int ret =repo_config_get_string (r, key, (char **)output);
@@ -3186,35 +3112,17 @@ int repo_config_set_in_file_gently(struct repository *r, const char *config_filereturn repo_config_set_multivar_in_file_gently (r, config_filename, key, value,NULL , comment,0 ); } -int git_config_set_in_file_gently (const char *config_filename, -const char *key,const char *comment,const char *value) -{ -return repo_config_set_in_file_gently (the_repository, config_filename, - key, comment, value); -} -void repo_config_set_in_file (struct repository *r,const char *config_filename,const char *key,const char *value) {repo_config_set_multivar_in_file (r, config_filename, key, value,NULL ,0 ); } -void git_config_set_in_file (const char *config_filename, -const char *key,const char *value) -{ -repo_config_set_in_file (the_repository, config_filename, key, value); -} -int repo_config_set_gently (struct repository *r,const char *key,const char *value) {return repo_config_set_multivar_gently (r, key, value,NULL ,0 ); } -int git_config_set_gently (const char *key,const char *value) -{ -return repo_config_set_gently (the_repository, key, value); -} -int repo_config_set_worktree_gently (struct repository *r,const char *key,const char *value) {
@@ -3236,11 +3144,6 @@ void repo_config_set(struct repository *r, const char *key, const char *value)trace2_cmd_set_config (key, value); } -void git_config_set (const char *key,const char *value) -{ -repo_config_set (the_repository, key, value); -} -char *git_config_prepare_comment_string (const char *comment) {size_t leading_blanks;
@@ -3569,17 +3472,6 @@ int repo_config_set_multivar_in_file_gently(struct repository *r, goto out_free; } -int git_config_set_multivar_in_file_gently (const char *config_filename, -const char *key,const char *value, -const char *value_pattern, -const char *comment, -unsigned flags) -{ -return repo_config_set_multivar_in_file_gently (the_repository, config_filename, - key, value, value_pattern, - comment, flags); -} - void repo_config_set_multivar_in_file(struct repository *r, const char *config_filename, const char *key, const char *value,
@@ -3594,21 +3486,6 @@ void repo_config_set_multivar_in_file(struct repository *r,die (_ ("could not unset '%s'" ), key); } -void git_config_set_multivar_in_file (const char *config_filename, -const char *key,const char *value, -const char *value_pattern,unsigned flags) -{ -repo_config_set_multivar_in_file (the_repository, config_filename, - key, value, value_pattern, flags); -} - -int git_config_set_multivar_gently (const char *key,const char *value, -const char *value_pattern,unsigned flags) -{ -return repo_config_set_multivar_gently (the_repository, key, value, - value_pattern, flags); -} -int repo_config_set_multivar_gently (struct repository *r,const char *key,const char *value,const char *value_pattern,unsigned flags)
@@ -3632,13 +3509,6 @@ void repo_config_set_multivar(struct repository *r,free (file); } -void git_config_set_multivar (const char *key,const char *value, -const char *value_pattern,unsigned flags) -{ -repo_config_set_multivar (the_repository, key, value, - value_pattern, flags); -} -static size_t section_name_match (const char *buf,const char *name) {size_t i =0 , j =0 ;
config.h +171 -78
413 lines not on this page · raw message
Signature · 1 line
2.46.0.46.g406f326d27.dirty
Quoted 12 lines · Patrick Steinhardt
this is the second version of my patch series that drops the dependency on
the_repositoryin both "path.c" and "config.c".Changes compared to v1:
- Various typo fixes in commit messages.
- Rename
strbuf_git_common_pathv()torepo_common_pathv().- Reorder arguments of
strbuf_edit_interactively()such that thestruct repositorygets passed as first argument.
Quoted 6 lines
- Document behaviour of
worktree_git_path()when no worktree is given.- Wrap some overly long lines.
Thanks!
Nicely done. I found that both of the two larger changes relative to the previous iteration are sensible.
Hi Patrick,
Glad to see us slowly getting rid of the global, the_repository! I had missed your original series[1] introducing the USE_THE_REPOSITORY_AVAILABLE macro, but going thru it provided all the context necessary for this series.
I see there have been a few cleanups since the first version, and I didn't spot any typos on my end. Overall, this is a good step towards reducing our dependency on the_repository by removing it from the config subsystem. Additionally, this makes libifying that subsystem much easier since removing globals usage is a prerequisite for libification. I only left a non-blocking comment on one of the patches, but besides that this series LGTM. Feel free to cc me on any related series in the future!
[1] https://lore.kernel.org/git/[email protected]/
Quoted 16 lines · Calvin Wan
Hi Patrick,
Glad to see us slowly getting rid of the global,
the_repository! I had missed your original series[1] introducing theUSE_THE_REPOSITORY_AVAILABLEmacro, but going thru it provided all the context necessary for this series.I see there have been a few cleanups since the first version, and I didn't spot any typos on my end. Overall, this is a good step towards reducing our dependency on
the_repositoryby removing it from the config subsystem. Additionally, this makes libifying that subsystem much easier since removing globals usage is a prerequisite for libification. I only left a non-blocking comment on one of the patches, but besides that this series LGTM. Feel free to cc me on any related series in the future!
Quoted 1 line
Thanks, will do!
Patrick
Quoted 14 lines · Patrick Steinhardt
Hi,
this is the second version of my patch series that drops the dependency on
the_repositoryin both "path.c" and "config.c".Changes compared to v1:
- Various typo fixes in commit messages.
- Rename
strbuf_git_common_pathv()torepo_common_pathv().- Reorder arguments of
strbuf_edit_interactively()such that thestruct repositorygets passed as first argument.
Quoted 6 lines
- Document behaviour of
worktree_git_path()when no worktree is given.- Wrap some overly long lines.
Thanks!
After reviewing the changes in this version, the series looks good to me! Thanks :)
-Justin