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

[PATCH v5] commit-graph: remove a duplicate assignment

From
Alex Henrie <alexhenrie24@gmail.com>
Date
Oct 1, 2019, 02:29 UTC
Message-ID
<20191001022936.1757141-1-alexhenrie24@gmail.com>

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

Also initialize the variable 'num_commits' just before the loop instead of at the beginning of the function for the same reason.

Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 commit-graph.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/commit-graph.c b/commit-graph.c
index 9b02d2c426..4028508e9c 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1522,8 +1522,8 @@ 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;
-	uint32_t num_commits = ctx->commits.nr;
+	struct commit_graph *g;
+	uint32_t num_commits;
 	uint32_t i;
 
 	int max_commits = 0;
@@ -1535,6 +1535,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
 	}
 
 	g = ctx->r->objects->commit_graph;
+	num_commits = ctx->commits.nr;
 	ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
 
 	while (g && (g->num_commits <= size_mult * num_commits ||
-- 
2.23.0
Next: Alex Henrie
Message 1 of 5 in “commit-graph: remove a duplicate assignment”
  1. commit-graph: remove a duplicate assignmentAlex Henrie, Oct 1, 2019
  2. diffcore-break: use a goto instead of a redundant if statementAlex Henrie, Oct 1, 2019
  3. wrapper: use a loop instead of repetitive statementsAlex Henrie, Oct 1, 2019
  4. Junio C HamanoOct 2, 2019
  5. Jeff KingOct 2, 2019

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.