reflog: fix warning message.
When ref@{N} is specified on a ref that has only M entries (M < N), instead of saying the initial timestamp the reflog has, warn that there is only M entries. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 18, 2006 at 22:07 UTC
e29cb53a8b6aa1256221207b14a1c8ef72f69d9f
1 file changed
+9
-3
refs.c
+9
-3
@@ -1013,7 +1013,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1013
{
1014
const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
1015
char *tz_c;
1016
- int logfd, tz;
1016
+ int logfd, tz, reccnt = 0;
1017
struct stat st;
1018
unsigned long date;
1019
unsigned char logged_sha1[20];
@@ -1031,6 +1031,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1031
lastrec = NULL;
1032
rec = logend = logdata + st.st_size;
1033
while (logdata < rec) {
1034
+ reccnt++;
1035
if (logdata < rec && *(rec-1) == '\n')
1036
rec--;
1037
lastgt = NULL;
@@ -1087,8 +1088,12 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
1088
if (get_sha1_hex(logdata, sha1))
1089
die("Log %s is corrupt.", logfile);
1090
munmap((void*)logdata, st.st_size);
1090
- fprintf(stderr, "warning: Log %s only goes back to %s.\n",
1091
- logfile, show_rfc2822_date(date, tz));
1091
+ if (at_time)
1092
+ fprintf(stderr, "warning: Log %s only goes back to %s.\n",
1093
+ logfile, show_rfc2822_date(date, tz));
1094
+ else
1095
+ fprintf(stderr, "warning: Log %s only has %d entries.\n",
1096
+ logfile, reccnt);
1097
return 0;
1098
}
1099
@@ -1116,3 +1121,4 @@ void for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
1121
}
1122
fclose(logfp);
1123
}
1124
+