summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 422b4a0)
raw | patch | inline | side by side (parent: 422b4a0)
author | Junio C Hamano <junkio@cox.net> | |
Fri, 6 Oct 2006 06:16:15 +0000 (23:16 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 6 Oct 2006 06:17:11 +0000 (23:17 -0700) |
Often I find myself wanting to say 'tip of "next" before I
merged the last three topics'. Now I can say that with:
git log next@{3}..next
Since small integers alone are invalid input strings to
approxidate, there is no fear of confusion.
Signed-off-by: Junio C Hamano <junkio@cox.net>
merged the last three topics'. Now I can say that with:
git log next@{3}..next
Since small integers alone are invalid input strings to
approxidate, there is no fear of confusion.
Signed-off-by: Junio C Hamano <junkio@cox.net>
refs.c | patch | blob | history | |
refs.h | patch | blob | history | |
sha1_name.c | patch | blob | history |
index 305c1a92cca8e546a91b578df227212acc96279c..d7f4aa5d87b0fc33abb25864fa92b8001b415f53 100644 (file)
--- a/refs.c
+++ b/refs.c
return 0;
}
-int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1)
+int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1)
{
const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec;
char *tz_c;
if (!lastgt)
die("Log %s is corrupt.", logfile);
date = strtoul(lastgt + 1, &tz_c, 10);
- if (date <= at_time) {
+ if (date <= at_time || cnt == 0) {
if (lastrec) {
if (get_sha1_hex(lastrec, logged_sha1))
die("Log %s is corrupt.", logfile);
return 0;
}
lastrec = rec;
+ if (cnt > 0)
+ cnt--;
}
rec = logdata;
index 0d4d79e03f50223ef95e9297b29a581fadeaa1a1..a57d43726a0fee5686e2c0d505f250c6b4adc150 100644 (file)
--- a/refs.h
+++ b/refs.h
extern int write_ref_sha1(struct ref_lock *lock, const unsigned char *sha1, const char *msg);
/** Reads log for the value of ref during at_time. **/
-extern int read_ref_at(const char *ref, unsigned long at_time, unsigned char *sha1);
+extern int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char *sha1);
/** Returns 0 if target has the right format for a ref. **/
extern int check_ref_format(const char *target);
diff --git a/sha1_name.c b/sha1_name.c
index ed711f2079752fd7ecc24b1a48b7d6fcc256659f..e5170336ff27606596fa8de887b576a0b9ab3cb8 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
static const char *warning = "warning: refname '%.*s' is ambiguous.\n";
const char **p, *ref;
char *real_ref = NULL;
- int refs_found = 0, am;
- unsigned long at_time = (unsigned long)-1;
+ int refs_found = 0;
+ int at, reflog_len;
unsigned char *this_result;
unsigned char sha1_from_ref[20];
if (len == 40 && !get_sha1_hex(str, sha1))
return 0;
- /* At a given period of time? "@{2 hours ago}" */
- for (am = 1; am < len - 1; am++) {
- if (str[am] == '@' && str[am+1] == '{' && str[len-1] == '}') {
- int date_len = len - am - 3;
- char *date_spec = xmalloc(date_len + 1);
- strlcpy(date_spec, str + am + 2, date_len + 1);
- at_time = approxidate(date_spec);
- free(date_spec);
- len = am;
- break;
+ /* basic@{time or number} format to query ref-log */
+ reflog_len = 0;
+ if (str[len-1] == '}') {
+ for (at = 1; at < len - 1; at++) {
+ if (str[at] == '@' && str[at+1] == '{') {
+ reflog_len = (len-1) - (at+2);
+ len = at;
+ break;
+ }
}
}
if (warn_ambiguous_refs && refs_found > 1)
fprintf(stderr, warning, len, str);
- if (at_time != (unsigned long)-1) {
- read_ref_at(
- real_ref,
- at_time,
- sha1);
+ if (reflog_len) {
+ /* Is it asking for N-th entry, or approxidate? */
+ int nth, i;
+ unsigned long at_time;
+ for (i = nth = 0; 0 <= nth && i < reflog_len; i++) {
+ char ch = str[at+2+i];
+ if ('0' <= ch && ch <= '9')
+ nth = nth * 10 + ch - '0';
+ else
+ nth = -1;
+ }
+ if (0 <= nth)
+ at_time = 0;
+ else
+ at_time = approxidate(str + at + 2);
+ read_ref_at(real_ref, at_time, nth, sha1);
}
free(real_ref);