Skip to contentSkip to conversation

ref-log: allow ref@{count} syntax.

PATCH In review Junio C Hamano 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ref-log: allow ref@{count} syntax.

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.

---

* The implementation is rather hacky but I think this is mildly useful. Likes, dislikes?

 refs.c      |    6 ++++--
 refs.h      |    2 +-
 sha1_name.c |   44 +++++++++++++++++++++++++++-----------------
 3 files changed, 32 insertions(+), 20 deletions(-)
refs.c +4 -2
index 305c1a9..d7f4aa5 100644
@@ -795,7 +795,7 @@ int write_ref_sha1(struct ref_lock *lock
 	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;
@@ -828,7 +828,7 @@ int read_ref_at(const char *ref, unsigne
 		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);
@@ -859,6 +859,8 @@ int read_ref_at(const char *ref, unsigne
 			return 0;
 		}
 		lastrec = rec;
+		if (cnt > 0)
+			cnt--;
 	}
 
 	rec = logdata;
refs.h +1 -1
index 0d4d79e..a57d437 100644
@@ -39,7 +39,7 @@ extern void unlock_ref(struct ref_lock *
 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);
sha1_name.c +27 -17

62 lines not on this page · raw message

Signature · 1 line
1.4.2.3.gae59
#1 lore raw
Quoted 5 lines · Junio C Hamano

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
Quoted 8 lines

Since small integers alone are invalid input strings to approxidate, there is no fear of confusion.

---

* The implementation is rather hacky but I think this is mildly useful. Likes, dislikes?

Ack'd.

Its a useful feature. Something I've been wanting myself for some time. I usually just guess with '@{5.minutes.ago}' or some nonsense until I find the right time. But since I know it was X operations ago, '@{X}' will be very handy. Thanks!

Signature · 1 line
Shawn.