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

Re: [PATCH v3] commit-graph: remove a duplicate assignment

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 30, 2019, 01:22 UTC
Message-ID
<xmqqimpainmj.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190929005558.733699-1-alexhenrie24@gmail.com>
Alex Henrie <alexhenrie24@gmail.com> writes:
> 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.
Show 5 quoted lines
>  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;

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?

Previous: Alex HenrieNext: Alex Henrie
Message 2 of 3 in “commit-graph: remove a duplicate assignment”
  1. commit-graph: remove a duplicate assignmentAlex Henrie, Sep 29, 2019
  2. Junio C HamanoSep 30, 2019
  3. Alex HenrieSep 30, 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.