All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: "Martin Ågren" <martin.agren@gmail.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v2 1/2] refs: factor out set_read_ref_cutoffs()
Date: Wed,  6 Jan 2021 01:01:53 -0800	[thread overview]
Message-ID: <8f14ec39970b6cbf9b6615485316063306706e6a.1609923643.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1609923643.git.liu.denton@gmail.com>

This block of code is duplicated twice. In a future commit, it will be
duplicated for a third time. Factor out the common functionality into
set_read_ref_cutoffs().

In the case of read_ref_at_ent(), we are incrementing `cb->reccnt` at the
beginning of the function. Move these to right before the return so that
the `cb->reccnt - 1` is changed to `cb->reccnt` and it can be cleanly
factored out into set_read_ref_cutoffs(). The duplication of the
increment statements will be removed in a future patch.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 refs.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/refs.c b/refs.c
index 13dc2c3291..bfdd04aefd 100644
--- a/refs.c
+++ b/refs.c
@@ -882,25 +882,30 @@ struct read_ref_at_cb {
 	int *cutoff_cnt;
 };
 
+static void set_read_ref_cutoffs(struct read_ref_at_cb *cb,
+		timestamp_t timestamp, int tz, const char *message)
+{
+	if (cb->msg)
+		*cb->msg = xstrdup(message);
+	if (cb->cutoff_time)
+		*cb->cutoff_time = timestamp;
+	if (cb->cutoff_tz)
+		*cb->cutoff_tz = tz;
+	if (cb->cutoff_cnt)
+		*cb->cutoff_cnt = cb->reccnt;
+}
+
 static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 		const char *email, timestamp_t timestamp, int tz,
 		const char *message, void *cb_data)
 {
 	struct read_ref_at_cb *cb = cb_data;
 
-	cb->reccnt++;
 	cb->tz = tz;
 	cb->date = timestamp;
 
 	if (timestamp <= cb->at_time || cb->cnt == 0) {
-		if (cb->msg)
-			*cb->msg = xstrdup(message);
-		if (cb->cutoff_time)
-			*cb->cutoff_time = timestamp;
-		if (cb->cutoff_tz)
-			*cb->cutoff_tz = tz;
-		if (cb->cutoff_cnt)
-			*cb->cutoff_cnt = cb->reccnt - 1;
+		set_read_ref_cutoffs(cb, timestamp, tz, message);
 		/*
 		 * we have not yet updated cb->[n|o]oid so they still
 		 * hold the values for the previous record.
@@ -917,11 +922,13 @@ static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
 			warning(_("log for ref %s unexpectedly ended on %s"),
 				cb->refname, show_date(cb->date, cb->tz,
 						       DATE_MODE(RFC2822)));
+		cb->reccnt++;
 		oidcpy(&cb->ooid, ooid);
 		oidcpy(&cb->noid, noid);
 		cb->found_it = 1;
 		return 1;
 	}
+	cb->reccnt++;
 	oidcpy(&cb->ooid, ooid);
 	oidcpy(&cb->noid, noid);
 	if (cb->cnt > 0)
@@ -935,14 +942,7 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
 {
 	struct read_ref_at_cb *cb = cb_data;
 
-	if (cb->msg)
-		*cb->msg = xstrdup(message);
-	if (cb->cutoff_time)
-		*cb->cutoff_time = timestamp;
-	if (cb->cutoff_tz)
-		*cb->cutoff_tz = tz;
-	if (cb->cutoff_cnt)
-		*cb->cutoff_cnt = cb->reccnt;
+	set_read_ref_cutoffs(cb, timestamp, tz, message);
 	oidcpy(cb->oid, ooid);
 	if (is_null_oid(cb->oid))
 		oidcpy(cb->oid, noid);
-- 
2.30.0


  reply	other threads:[~2021-01-06  9:03 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02  1:36 [PATCH] refs: allow @{n} to work with n-sized reflog Denton Liu
2021-01-02 22:30 ` Martin Ågren
2021-01-03  1:24 ` Denton Liu
2021-01-05  8:52 ` SZEDER Gábor
2021-01-06  5:55 ` Junio C Hamano
2021-01-06  8:25   ` Denton Liu
2021-01-06 21:02     ` Junio C Hamano
2021-01-06  9:01 ` [PATCH v2 0/2] " Denton Liu
2021-01-06  9:01   ` Denton Liu [this message]
2021-01-06  9:01   ` [PATCH v2 2/2] " Denton Liu
2021-01-06  9:59     ` SZEDER Gábor
2021-01-07 10:36   ` [PATCH v3 0/2] " Denton Liu
2021-01-07 10:36     ` [PATCH v3 1/2] refs: factor out set_read_ref_cutoffs() Denton Liu
2021-01-07 10:36     ` [PATCH v3 2/2] refs: allow @{n} to work with n-sized reflog Denton Liu
2021-01-10 20:31       ` Simon Ruderich
2021-01-12  6:14         ` [PATCH v3] fixup! " Denton Liu
2021-01-12  6:18           ` Denton Liu
2021-01-12  6:27             ` Junio C Hamano
2021-01-10 14:44     ` [PATCH v3 0/2] " SZEDER Gábor
2021-01-10 20:24       ` Junio C Hamano
2021-01-07 10:43   ` [PATCH v3 3/2] fixup! " Denton Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8f14ec39970b6cbf9b6615485316063306706e6a.1609923643.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.agren@gmail.com \
    --cc=szeder.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.