summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2009-01-20 06:18:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-01-20 06:18:29 (GMT)
commit101d15e09712a0183db99d228d975c62970654cf (patch)
tree794021ad7ade07c4835ec9c356930c637da26df7 /sha1_name.c
parent39765e5941d36f74cec4764d315da0ba5743547c (diff)
downloadgit-101d15e09712a0183db99d228d975c62970654cf.zip
git-101d15e09712a0183db99d228d975c62970654cf.tar.gz
git-101d15e09712a0183db99d228d975c62970654cf.tar.bz2
Introduce for_each_recent_reflog_ent().
This can be used to scan only the last few kilobytes of a reflog, as a cheap optimization when the data you are looking for is likely to be found near the end of it. The caller is expected to fall back to the full scan if that is not the case. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 4c0370b..38c9f1b 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -775,7 +775,13 @@ int interpret_nth_last_branch(const char *name, struct strbuf *buf)
strbuf_init(&cb.buf[i], 20);
cb.cnt = 0;
retval = 0;
- for_each_reflog_ent("HEAD", grab_nth_branch_switch, &cb);
+ for_each_recent_reflog_ent("HEAD", grab_nth_branch_switch, 40960, &cb);
+ if (cb.cnt < nth) {
+ cb.cnt = 0;
+ for (i = 0; i < nth; i++)
+ strbuf_release(&cb.buf[i]);
+ for_each_reflog_ent("HEAD", grab_nth_branch_switch, &cb);
+ }
if (cb.cnt < nth)
goto release_return;
i = cb.cnt % nth;