]> git.ipfire.org Git - thirdparty/git.git/commitdiff
path: remove redundant function calls
authorK Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Wed, 4 Mar 2026 13:05:02 +0000 (18:35 +0530)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Mar 2026 17:06:30 +0000 (09:06 -0800)
repo_settings_get_shared_repository() is invoked multiple times in
calc_shared_perm(). While the function internally caches the value,
repeated calls still add unnecessary noise.

Store the result in a local variable and reuse it instead. This makes
it explicit that the value is expected to remain constant and avoids
repeated calls in the same scope.

Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
path.c

diff --git a/path.c b/path.c
index 56be5e17265313dd0ba2bf8d948bd4a71cae80db..5cd38b2a163722a411e7f77bbf249f731c4edffa 100644 (file)
--- a/path.c
+++ b/path.c
@@ -741,18 +741,18 @@ int calc_shared_perm(struct repository *repo,
                     int mode)
 {
        int tweak;
-
-       if (repo_settings_get_shared_repository(repo) < 0)
-               tweak = -repo_settings_get_shared_repository(repo);
+       int shared_repo = repo_settings_get_shared_repository(repo);
+       if (shared_repo < 0)
+               tweak = -shared_repo;
        else
-               tweak = repo_settings_get_shared_repository(repo);
+               tweak = shared_repo;
 
        if (!(mode & S_IWUSR))
                tweak &= ~0222;
        if (mode & S_IXUSR)
                /* Copy read bits to execute bits */
                tweak |= (tweak & 0444) >> 2;
-       if (repo_settings_get_shared_repository(repo) < 0)
+       if (shared_repo < 0)
                mode = (mode & ~0777) | tweak;
        else
                mode |= tweak;