Commit 2b35c45f by Ben Straub

Rev-parse: now @{-N} syntax searches in the right direction!

parent 46c2ead0
...@@ -130,7 +130,7 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char * ...@@ -130,7 +130,7 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
git_reference *ref; git_reference *ref;
git_reflog *reflog = NULL; git_reflog *reflog = NULL;
int n, retcode = GIT_ERROR; int n, retcode = GIT_ERROR;
size_t i, refloglen; int i, refloglen;
const git_reflog_entry *entry; const git_reflog_entry *entry;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
size_t refspeclen = strlen(refspec); size_t refspeclen = strlen(refspec);
...@@ -144,6 +144,8 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char * ...@@ -144,6 +144,8 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
/* "@{-N}" form means walk back N checkouts. That means the HEAD log. */ /* "@{-N}" form means walk back N checkouts. That means the HEAD log. */
if (refspeclen == 0 && !git__prefixcmp(reflogspec, "@{-")) { if (refspeclen == 0 && !git__prefixcmp(reflogspec, "@{-")) {
regex_t regex;
if (git__strtol32(&n, reflogspec+3, NULL, 0) < 0 || if (git__strtol32(&n, reflogspec+3, NULL, 0) < 0 ||
n < 1) { n < 1) {
giterr_set(GITERR_INVALID, "Invalid reflogspec %s", reflogspec); giterr_set(GITERR_INVALID, "Invalid reflogspec %s", reflogspec);
...@@ -153,21 +155,25 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char * ...@@ -153,21 +155,25 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
git_reflog_read(&reflog, ref); git_reflog_read(&reflog, ref);
git_reference_free(ref); git_reference_free(ref);
if (!regcomp(&regex, "checkout: moving from (.*) to .*", REG_EXTENDED)) {
regmatch_t regexmatches[2];
refloglen = git_reflog_entrycount(reflog); refloglen = git_reflog_entrycount(reflog);
for (i=0; i < refloglen; i++) { for (i=refloglen-1; i >= 0; i--) {
const char *msg; const char *msg;
entry = git_reflog_entry_byindex(reflog, i); entry = git_reflog_entry_byindex(reflog, i);
msg = git_reflog_entry_msg(entry); msg = git_reflog_entry_msg(entry);
if (!git__prefixcmp(msg, "checkout: moving")) { if (!regexec(&regex, msg, 2, regexmatches, 0)) {
n--; n--;
if (!n) { if (!n) {
char *branchname = strrchr(msg, ' ') + 1; git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);
retcode = revparse_lookup_object(out, repo, branchname); retcode = revparse_lookup_object(out, repo, git_buf_cstr(&buf));
break; break;
} }
} }
} }
}
} else { } else {
git_buf datebuf = GIT_BUF_INIT; git_buf datebuf = GIT_BUF_INIT;
git_buf_put(&datebuf, reflogspec+2, reflogspeclen-3); git_buf_put(&datebuf, reflogspec+2, reflogspeclen-3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment