900
const char *message, void *cb_data)
901
{
902
struct read_ref_at_cb *cb = cb_data;
903
+ int reached_count;
904
905
cb->tz = tz;
906
cb->date = timestamp;
907
907
- if (timestamp <= cb->at_time || cb->cnt == 0) {
908
+ /*
909
+ * It is not possible for cb->cnt == 0 on the first iteration because
910
+ * that special case is handled in read_ref_at().
911
+ */
912
+ if (cb->cnt > 0)
913
+ cb->cnt--;
914
+ reached_count = cb->cnt == 0 && !is_null_oid(ooid);
915
+ if (timestamp <= cb->at_time || reached_count) {
916
set_read_ref_cutoffs(cb, timestamp, tz, message);
917
/*
918
* we have not yet updated cb->[n|o]oid so they still
919
* hold the values for the previous record.
920
*/
913
- if (!is_null_oid(&cb->ooid)) {
914
- oidcpy(cb->oid, noid);
915
- if (!oideq(&cb->ooid, noid))
916
- warning(_("log for ref %s has gap after %s"),
921
+ if (!is_null_oid(&cb->ooid) && !oideq(&cb->ooid, noid))
922
+ warning(_("log for ref %s has gap after %s"),
923
cb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));
918
- }
919
- else if (cb->date == cb->at_time)
924
+ if (reached_count)
925
+ oidcpy(cb->oid, ooid);
926
+ else if (!is_null_oid(&cb->ooid) || cb->date == cb->at_time)
927
oidcpy(cb->oid, noid);
928
else if (!oideq(noid, cb->oid))
929
warning(_("log for ref %s unexpectedly ended on %s"),
930
cb->refname, show_date(cb->date, cb->tz,
931
DATE_MODE(RFC2822)));
925
- cb->reccnt++;
926
- oidcpy(&cb->ooid, ooid);
927
- oidcpy(&cb->noid, noid);
932
cb->found_it = 1;
929
- return 1;
933
}
934
cb->reccnt++;
935
oidcpy(&cb->ooid, ooid);
936
oidcpy(&cb->noid, noid);
934
- if (cb->cnt > 0)
935
- cb->cnt--;
936
- return 0;
937
+ return cb->found_it;
938
+}
939
+
940
+static int read_ref_at_ent_newest(struct object_id *ooid, struct object_id *noid,
941
+ const char *email, timestamp_t timestamp,
942
+ int tz, const char *message, void *cb_data)
943
+{
944
+ struct read_ref_at_cb *cb = cb_data;
945
+
946
+ set_read_ref_cutoffs(cb, timestamp, tz, message);
947
+ oidcpy(cb->oid, noid);
948
+ /* We just want the first entry */
949
+ return 1;
950
}
951
952
static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,
980
cb.cutoff_cnt = cutoff_cnt;
981
cb.oid = oid;
982
983
+ if (cb.cnt == 0) {
984
+ refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent_newest, &cb);
985
+ return 0;
986
+ }
987
+
988
refs_for_each_reflog_ent_reverse(refs, refname, read_ref_at_ent, &cb);
989
990
if (!cb.reccnt) {