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

Re: [PATCH 3/3] path: remove redundant function calls

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 3, 2026, 13:42 UTC
Message-ID
<aablRKlhQZUTct56@pks.im>
In-Reply-To
<20260302142138.712273-4-jayatheerthkulkarni2005@gmail.com>
On Mon, Mar 02, 2026 at 07:51:38PM +0530, K Jayatheerth wrote:
> We fetch the exact same setting up to four times.
> We fix this by evaluating it once, storing it in a local variable,
Micronit: we typically write this as if instructing the code itself to
change. So this would rather be something like "Fix this by storing it
in a local variable.".
Show 35 quoted lines
> and referencing that variable.
> 
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
>  path.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/path.c b/path.c
> index 56be5e1726..5cd38b2a16 100644
> --- 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;

I agree with the fix itself though. Probably doesn't matter much as we simply retrieve a value from the repo settings, but this also removes some mental overhead in my mind.

Thanks!
Patrick
Previous: K JayatheerthNext: Junio C Hamano
Message 7 of 21 in “path: clean up few things”
  1. 0/3 path: clean up few thingsK Jayatheerth, Mar 2, 2026
  2. 1/3 path: remove unused headerK Jayatheerth, Mar 2, 2026
  3. 2/3 path: use the right datatypeK Jayatheerth, Mar 2, 2026
  4. Patrick SteinhardtMar 3, 2026
  5. Junio C HamanoMar 3, 2026
  6. 3/3 path: remove redundant function callsK Jayatheerth, Mar 2, 2026
  7. Patrick SteinhardtMar 3, 2026
  8. Junio C HamanoMar 3, 2026
  9. 0/3 clean up a few thingsK Jayatheerth, Mar 4, 2026
  10. 1/3 path: remove unused headerK Jayatheerth, Mar 4, 2026
  11. 2/3 path: use size_t for dir_prefix lengthK Jayatheerth, Mar 4, 2026
  12. Junio C HamanoMar 4, 2026
  13. 3/3 path: remove redundant function callsK Jayatheerth, Mar 4, 2026
  14. 0/3 clean up a few thingsK Jayatheerth, Mar 5, 2026
  15. 1/3 path: remove unused headerK Jayatheerth, Mar 5, 2026
  16. 2/3 path: use size_t for dir_prefix lengthK Jayatheerth, Mar 5, 2026
  17. 3/3 path: remove redundant function callsK Jayatheerth, Mar 5, 2026
  18. Junio C HamanoMar 5, 2026
  19. K JayatheerthMar 6, 2026
  20. K JayatheerthMar 6, 2026
  21. Junio C HamanoMar 6, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.