git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v3] commit-graph: remove a duplicate assignment
@ 2019-09-29  0:55 Alex Henrie
  2019-09-30  1:22 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Henrie @ 2019-09-29  0:55 UTC (permalink / raw)
  To: git, dstolee; +Cc: Alex Henrie, Derrick Stolee

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.

Reviewed-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 commit-graph.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commit-graph.c b/commit-graph.c
index 9b02d2c426..d0e1f9e1f2 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -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;
 
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] commit-graph: remove a duplicate assignment
  2019-09-29  0:55 [PATCH v3] commit-graph: remove a duplicate assignment Alex Henrie
@ 2019-09-30  1:22 ` Junio C Hamano
  2019-09-30  7:34   ` Alex Henrie
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2019-09-30  1:22 UTC (permalink / raw)
  To: Alex Henrie; +Cc: git, dstolee, Derrick Stolee

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.

>  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?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] commit-graph: remove a duplicate assignment
  2019-09-30  1:22 ` Junio C Hamano
@ 2019-09-30  7:34   ` Alex Henrie
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Henrie @ 2019-09-30  7:34 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git mailing list, dstolee, Derrick Stolee

On Sun, Sep 29, 2019 at 7:22 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> 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.

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

> >  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?

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

-Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-30  7:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-29  0:55 [PATCH v3] commit-graph: remove a duplicate assignment Alex Henrie
2019-09-30  1:22 ` Junio C Hamano
2019-09-30  7:34   ` Alex Henrie

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).