summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2007-01-19 01:19:05 -0800
committerJunio C Hamano <junkio@cox.net>2007-01-19 17:57:53 -0800
commit16d7cc90dd6e68a170362ae6f0fbfbc504fd246b (patch)
tree6675317cbe5a1d8017d1c7856fd3ac430debd247 /refs.c
parente86eb6668ee0c574ba0b6c2c94564d4159a6fcc7 (diff)
downloadgit-16d7cc90dd6e68a170362ae6f0fbfbc504fd246b.tar.gz
Extend read_ref_at() to be usable from places other than sha1_name.
You can pass an extra argument to the function to receive the reflog message information. Also when the log does not go back beyond the point the user asked, the cut-off time and count are given back to the caller for emitting the error messages as appropriately. We could later add configuration for get_sha1_basic() to make it an error instead of it being just a warning. Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/refs.c b/refs.c
index 6310cf46e0..60375a786f 100644
--- a/refs.c
+++ b/refs.c
@@ -1017,7 +1017,21 @@ int write_ref_sha1(struct ref_lock *lock,
return 0;
}
-int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1)
+static char *ref_msg(const char *line, const char *endp)
+{
+ const char *ep;
+ char *msg;
+
+ line += 82;
+ for (ep = line; ep < endp && *ep != '\n'; ep++)
+ ;
+ msg = xmalloc(ep - line + 1);
+ memcpy(msg, line, ep - line);
+ msg[ep - line] = 0;
+ return msg;
+}
+
+int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt)
{
const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
char *tz_c;
@@ -1054,6 +1068,14 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
die("Log %s is corrupt.", logfile);
date = strtoul(lastgt + 1, &tz_c, 10);
if (date <= at_time || cnt == 0) {
+ if (msg)
+ *msg = ref_msg(rec, logend);
+ if (cutoff_time)
+ *cutoff_time = date;
+ if (cutoff_tz)
+ *cutoff_tz = tz;
+ if (cutoff_cnt)
+ *cutoff_cnt = reccnt;
if (lastrec) {
if (get_sha1_hex(lastrec, logged_sha1))
die("Log %s is corrupt.", logfile);
@@ -1097,14 +1119,17 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *
tz = strtoul(tz_c, NULL, 10);
if (get_sha1_hex(logdata, sha1))
die("Log %s is corrupt.", logfile);
+ if (msg)
+ *msg = ref_msg(logdata, logend);
munmap(log_mapped, st.st_size);
- if (at_time)
- fprintf(stderr, "warning: Log %s only goes back to %s.\n",
- logfile, show_rfc2822_date(date, tz));
- else
- fprintf(stderr, "warning: Log %s only has %d entries.\n",
- logfile, reccnt);
- return 0;
+
+ if (cutoff_time)
+ *cutoff_time = date;
+ if (cutoff_tz)
+ *cutoff_tz = tz;
+ if (cutoff_cnt)
+ *cutoff_cnt = reccnt;
+ return 1;
}
int for_each_reflog_ent(const char *ref, each_reflog_ent_fn fn, void *cb_data)