Skip to content

Commit e29cb53

Browse files
author
Junio C Hamano
committed
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>
1 parent 6304929 commit e29cb53

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

refs.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10131013
{
10141014
const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
10151015
char *tz_c;
1016-
int logfd, tz;
1016+
int logfd, tz, reccnt = 0;
10171017
struct stat st;
10181018
unsigned long date;
10191019
unsigned char logged_sha1[20];
@@ -1031,6 +1031,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10311031
lastrec = NULL;
10321032
rec = logend = logdata + st.st_size;
10331033
while (logdata < rec) {
1034+
reccnt++;
10341035
if (logdata < rec && *(rec-1) == '\n')
10351036
rec--;
10361037
lastgt = NULL;
@@ -1087,8 +1088,12 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
10871088
if (get_sha1_hex(logdata, sha1))
10881089
die("Log %s is corrupt.", logfile);
10891090
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);
10921097
return 0;
10931098
}
10941099

@@ -1116,3 +1121,4 @@ void for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)
11161121
}
11171122
fclose(logfp);
11181123
}
1124+

0 commit comments

Comments
 (0)