Skip to content

Commit 95c2a71

Browse files
Denton-Lgitster
authored andcommitted
refs: factor out set_read_ref_cutoffs()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71ca53e commit 95c2a71

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

refs.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -882,25 +882,30 @@ struct read_ref_at_cb {
882882
int *cutoff_cnt;
883883
};
884884

885+
static void set_read_ref_cutoffs(struct read_ref_at_cb *cb,
886+
timestamp_t timestamp, int tz, const char *message)
887+
{
888+
if (cb->msg)
889+
*cb->msg = xstrdup(message);
890+
if (cb->cutoff_time)
891+
*cb->cutoff_time = timestamp;
892+
if (cb->cutoff_tz)
893+
*cb->cutoff_tz = tz;
894+
if (cb->cutoff_cnt)
895+
*cb->cutoff_cnt = cb->reccnt;
896+
}
897+
885898
static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,
886899
const char *email, timestamp_t timestamp, int tz,
887900
const char *message, void *cb_data)
888901
{
889902
struct read_ref_at_cb *cb = cb_data;
890903

891-
cb->reccnt++;
892904
cb->tz = tz;
893905
cb->date = timestamp;
894906

895907
if (timestamp <= cb->at_time || cb->cnt == 0) {
896-
if (cb->msg)
897-
*cb->msg = xstrdup(message);
898-
if (cb->cutoff_time)
899-
*cb->cutoff_time = timestamp;
900-
if (cb->cutoff_tz)
901-
*cb->cutoff_tz = tz;
902-
if (cb->cutoff_cnt)
903-
*cb->cutoff_cnt = cb->reccnt - 1;
908+
set_read_ref_cutoffs(cb, timestamp, tz, message);
904909
/*
905910
* we have not yet updated cb->[n|o]oid so they still
906911
* 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,
917922
warning(_("log for ref %s unexpectedly ended on %s"),
918923
cb->refname, show_date(cb->date, cb->tz,
919924
DATE_MODE(RFC2822)));
925+
cb->reccnt++;
920926
oidcpy(&cb->ooid, ooid);
921927
oidcpy(&cb->noid, noid);
922928
cb->found_it = 1;
923929
return 1;
924930
}
931+
cb->reccnt++;
925932
oidcpy(&cb->ooid, ooid);
926933
oidcpy(&cb->noid, noid);
927934
if (cb->cnt > 0)
@@ -935,14 +942,7 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
935942
{
936943
struct read_ref_at_cb *cb = cb_data;
937944

938-
if (cb->msg)
939-
*cb->msg = xstrdup(message);
940-
if (cb->cutoff_time)
941-
*cb->cutoff_time = timestamp;
942-
if (cb->cutoff_tz)
943-
*cb->cutoff_tz = tz;
944-
if (cb->cutoff_cnt)
945-
*cb->cutoff_cnt = cb->reccnt;
945+
set_read_ref_cutoffs(cb, timestamp, tz, message);
946946
oidcpy(cb->oid, ooid);
947947
if (is_null_oid(cb->oid))
948948
oidcpy(cb->oid, noid);

0 commit comments

Comments
 (0)