Skip to contentSkip to conversation

commit-graph: remove a duplicate assignment

PATCH Superseded Alex Henrie 2 participants 3 messages Sep 29, 2019 – Sep 30, 2019

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 commit-graph: remove a duplicate assignment

The variable g was being set to the same value both at the beginning of the function and before the loop. The assignment before the loop was kept because it helps clarify what the loop does, and the redundant assignment at the beginning of the function was removed.

---
 commit-graph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
commit-graph.c +1 -1
index 9b02d2c426..d0e1f9e1f2 100644
@@ -1522,7 +1522,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
 
 static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
 {
-	struct commit_graph *g = ctx->r->objects->commit_graph;
+	struct commit_graph *g;
 	uint32_t num_commits = ctx->commits.nr;
 	uint32_t i;
 
Signature · 1 line
2.23.0
#1 lore raw
Quoted 4 lines · Alex Henrie

The variable g was being set to the same value both at the beginning of the function and before the loop. The assignment before the loop was kept because it helps clarify what the loop does, and the redundant assignment at the beginning of the function was removed.

Writing these mostly in the past tense is misleading to those who are used to read "git log" from this project. Give orders to the codebase to "become like so" instead. Perhaps like

Leave the variable 'g' uninitialized before it is set just before its first use in front of a loop, which is a lot more appropriate place to indicate what it is used for.

commit-graph.c static int write_commit_graph_file(struct write_commit_graph_context *ctx) · line 1526

Quoted 5 lines

static void split_graph_merge_strategy(struct write_commit_graph_context *ctx) {

commit-graph.c +1 -1
-	struct commit_graph *g = ctx->r->objects->commit_graph;
+	struct commit_graph *g;
 	uint32_t num_commits = ctx->commits.nr;

Stepping back a bit, doesn't the same justification you gave to this change apply to 'num_commits'? If you make it uninitialized before its first use and assign ctx->commits.nr to it near where 'g' is given its first value, wouldn't it make it even clearer that these two variables are almost always used together and how they are used in the loop?

#2 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Alex Henrie

The variable g was being set to the same value both at the beginning of the function and before the loop. The assignment before the loop was kept because it helps clarify what the loop does, and the redundant assignment at the beginning of the function was removed.

Quoted 7 lines

Writing these mostly in the past tense is misleading to those who are used to read "git log" from this project. Give orders to the codebase to "become like so" instead. Perhaps like

Leave the variable 'g' uninitialized before it is set just before its first use in front of a loop, which is a lot more appropriate place to indicate what it is used for.

Okay, thanks for the guidance. I'll use your text on the next version of the patch.

Quoted 6 lines

commit-graph.c static int write_commit_graph_file(struct write_commit_graph_context *ctx) · line 1526

Quoted 5 lines

static void split_graph_merge_strategy(struct write_commit_graph_context *ctx) {

commit-graph.c +1 -1
-     struct commit_graph *g = ctx->r->objects->commit_graph;
+     struct commit_graph *g;
      uint32_t num_commits = ctx->commits.nr;
Quoted 6 lines

Stepping back a bit, doesn't the same justification you gave to this change apply to 'num_commits'? If you make it uninitialized before its first use and assign ctx->commits.nr to it near where 'g' is given its first value, wouldn't it make it even clearer that these two variables are almost always used together and how they are used in the loop?

Yes, that makes sense. I'll send a revised patch that includes that change as well.

-Alex