@@ -882,51 +882,71 @@ struct read_ref_at_cb {
882
882
int * cutoff_cnt ;
883
883
};
884
884
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
+
885
898
static int read_ref_at_ent (struct object_id * ooid , struct object_id * noid ,
886
899
const char * email , timestamp_t timestamp , int tz ,
887
900
const char * message , void * cb_data )
888
901
{
889
902
struct read_ref_at_cb * cb = cb_data ;
903
+ int reached_count ;
890
904
891
- cb -> reccnt ++ ;
892
905
cb -> tz = tz ;
893
906
cb -> date = timestamp ;
894
907
895
- 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
+ /*
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 ) ;
904
917
/*
905
918
* we have not yet updated cb->[n|o]oid so they still
906
919
* hold the values for the previous record.
907
920
*/
908
- if (!is_null_oid (& cb -> ooid )) {
909
- oidcpy (cb -> oid , noid );
910
- if (!oideq (& cb -> ooid , noid ))
911
- 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" ),
912
923
cb -> refname , show_date (cb -> date , cb -> tz , DATE_MODE (RFC2822 )));
913
- }
914
- 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 )
915
927
oidcpy (cb -> oid , noid );
916
928
else if (!oideq (noid , cb -> oid ))
917
929
warning (_ ("log for ref %s unexpectedly ended on %s" ),
918
930
cb -> refname , show_date (cb -> date , cb -> tz ,
919
931
DATE_MODE (RFC2822 )));
920
- oidcpy (& cb -> ooid , ooid );
921
- oidcpy (& cb -> noid , noid );
922
932
cb -> found_it = 1 ;
923
- return 1 ;
924
933
}
934
+ cb -> reccnt ++ ;
925
935
oidcpy (& cb -> ooid , ooid );
926
936
oidcpy (& cb -> noid , noid );
927
- if (cb -> cnt > 0 )
928
- cb -> cnt -- ;
929
- 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 ;
930
950
}
931
951
932
952
static int read_ref_at_ent_oldest (struct object_id * ooid , struct object_id * noid ,
@@ -935,14 +955,7 @@ static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid
935
955
{
936
956
struct read_ref_at_cb * cb = cb_data ;
937
957
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 ;
958
+ set_read_ref_cutoffs (cb , timestamp , tz , message );
946
959
oidcpy (cb -> oid , ooid );
947
960
if (is_null_oid (cb -> oid ))
948
961
oidcpy (cb -> oid , noid );
@@ -967,6 +980,11 @@ int read_ref_at(struct ref_store *refs, const char *refname,
967
980
cb .cutoff_cnt = cutoff_cnt ;
968
981
cb .oid = oid ;
969
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
+
970
988
refs_for_each_reflog_ent_reverse (refs , refname , read_ref_at_ent , & cb );
971
989
972
990
if (!cb .reccnt ) {
0 commit comments