threads / patch / 65187

patch, 2 partsrepo: remove redundant variable shadow in stats_table_print_structure

Subject: [PATCH 0/2] repo: remove redundant variable shadow in stats_table_print_structure

## tl;dr

5 messages between Mar 10, 2026 and Mar 10, 2026. Diffs are folded; open one to read it.

replies: 4people: 4as markdown or json

Mansi Singh via GitGitGadget· Mar 10, 2026, 02:16 UTC · lore

The variable i is declared in the outer scope of stats_table_print_structure() and then re-declared inside the loop, shadowing the outer one unnecessarily. Remove the redundant inner declaration to clean up the scope.

Signed-off-by: Mansi Singh mansimaanu8627@gmail.com
Mansi (1):
  t7605: use test_path_is_file instead of test -f
Mansi Singh (1):
  repo: remove redundant variable shadow in stats_table_print_structure
 builtin/repo.c           | 1 -
 t/t7605-merge-resolve.sh | 6 +++---
 2 files changed, 3 insertions(+), 4 deletions(-)
base-commit: 7c02d39fc2ed2702223c7674f73150d9a7e61ba4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2062%2FMansiSingh17%2Frepo-fix-variable-shadow-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2062/MansiSingh17/repo-fix-variable-shadow-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2062
-- 
gitgitgadget
Mansi via GitGitGadget· Mar 10, 2026, 02:16 UTC · re: Mansi Singh via GitGitGadget · lore

[PATCH 1/2] t7605: use test_path_is_file instead of test -f

From: Mansi <mansimaanu8627@gmail.com>

Replace old-style 'test -f' path checks with the modern test_path_is_file helper in the merge_c1_to_c2_cmds block.

The helper provides clearer failure messages and is the established convention in Git's test suite.

These instances were found using:
  grep -rn "test -[efd]" t/ --include="*.sh"
Signed-off-by: Mansi <mansimaanu8627@gmail.com>
---
 t/t7605-merge-resolve.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to t/t7605-merge-resolve.sh +3 −3
diff --git a/t/t7605-merge-resolve.sh b/t/t7605-merge-resolve.sh
index 5d56c38546..44de97a480 100755
--- a/t/t7605-merge-resolve.sh
+++ b/t/t7605-merge-resolve.sh
@@ -34,9 +34,9 @@ merge_c1_to_c2_cmds='
 	test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
 	test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
 	git diff --exit-code &&
-	test -f c0.c &&
-	test -f c1.c &&
-	test -f c2.c &&
+	test_path_is_file c0.c &&
+	test_path_is_file c1.c &&
+	test_path_is_file c2.c &&
 	test 3 = $(git ls-tree -r HEAD | wc -l) &&
 	test 3 = $(git ls-files | wc -l)
 '
-- 
gitgitgadget
Mansi Singh via GitGitGadget· Mar 10, 2026, 02:16 UTC · re: Mansi Singh via GitGitGadget · lore

[PATCH 2/2] repo: remove redundant variable shadow in stats_table_print_structure

From: Mansi Singh <mansimaanu8627@gmail.com>

In stats_table_print_structure(), the variable 'entry' is declared at the top of the loop body and assigned from item->util. Inside the 'if (entry)' block, the same variable is redeclared and assigned identically, shadowing the outer declaration unnecessarily.

Remove the inner redeclaration since the outer 'entry' is already available and non-NULL at that point.

Signed-off-by: Mansi Singh <mansimaanu8627@gmail.com>
---
 builtin/repo.c | 1 -
 1 file changed, 1 deletion(-)
Show changes to builtin/repo.c +0 −1
diff --git a/builtin/repo.c b/builtin/repo.c
index 0ea045abc1..5540bd25d2 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -412,7 +412,6 @@ static void stats_table_print_structure(const struct stats_table *table)
 		const char *unit = "";
 
 		if (entry) {
-			struct stats_table_entry *entry = item->util;
 			value = entry->value;
 			if (entry->unit)
 				unit = entry->unit;
-- 
gitgitgadget
K Jayatheerth· Mar 10, 2026, 13:08 UTC · re: Mansi Singh via GitGitGadget · lore

Re: [PATCH 0/2] repo: remove redundant variable shadow in stats_table_print_structure

Show 22 quoted lines
> Remove the inner redeclaration since the outer 'entry' is already
> available and non-NULL at that point.
>
> Signed-off-by: Mansi Singh <mansimaanu8627@gmail.com>
> ---
>  builtin/repo.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/builtin/repo.c b/builtin/repo.c
> index 0ea045abc1..5540bd25d2 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -412,7 +412,6 @@ static void stats_table_print_structure(const struct stats_table *table)
>  		const char *unit = "";
>
>  		if (entry) {
> -			struct stats_table_entry *entry = item->util;
>  			value = entry->value;
>  			if (entry->unit)
>  				unit = entry->unit;
> --
> gitgitgadget
Hi Mansi,

This is a good catch but I have to say this patch is already sent by me And is also merged into the master branch [1].

You can search in the mailing list or sometimes check the "What's cooking in git.git" (recent one [2]) before making the changes. You don't need anyone's permission to work on a patch but it is also important to not step on someone's toes ;)

1 - https://github.com/git/git/commit/676c145afdd88024057296f11fdf2c224001549e 2 - https://lore.kernel.org/git/xmqqh5qozdkq.fsf@gitster.g/T/#u

coming to the double naming problem That is because one of your patch is using `format-patch` and `send-email` method of sending patches and the other one is using `gitgitgadget`.

My suggestion would be to stick with one and move forward with that for the entirety.
Regards,
- Jayatheerth
Junio C Hamano· Mar 10, 2026, 03:08 UTC · re: Mansi Singh via GitGitGadget · lore

Re: [PATCH 0/2] repo: remove redundant variable shadow in stats_table_print_structure

"Mansi Singh via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> The variable i is declared in the outer scope of
> stats_table_print_structure() and then re-declared inside the loop,
> shadowing the outer one unnecessarily. Remove the redundant inner
> declaration to clean up the scope.
>
> Signed-off-by: Mansi Singh mansimaanu8627@gmail.com

The above sounds more like a description for a single patch, not a cover letter.

Because we strongly encourage one patch doing only one thing and doing it well, a commit log message for one of the patches in a two-patch series rarely makes a good description for the whole series.

But reading it again, which variable 'i' is it talking about? [2/2] does address 'entry' that is declared in an inner scope, masking the variable with the same name declared in an outer scope.

Stepping back a bit, I do not quite see the need for these two patcches to form a single topic. They look pretty much totally independent topics. Perhaps you're better off treating them as two independent topics, each with a single patch.

Show 5 quoted lines
> Mansi (1):
>   t7605: use test_path_is_file instead of test -f
>
> Mansi Singh (1):
>   repo: remove redundant variable shadow in stats_table_print_structure
Are these two patches from two different people?

Last time in https://lore.kernel.org/git/xmqqv7fjw6yx.fsf@gitster.g/ we had three names, and we now have only two, so that can be called an improvement, but let's whittle them down to just one ;-).

Thanks.

← back to recent threads