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,18 +155,22 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char * ...@@ -153,18 +155,22 @@ 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);
refloglen = git_reflog_entrycount(reflog); if (!regcomp(&regex, "checkout: moving from (.*) to .*", REG_EXTENDED)) {
for (i=0; i < refloglen; i++) { regmatch_t regexmatches[2];
const char *msg;
entry = git_reflog_entry_byindex(reflog, i); refloglen = git_reflog_entrycount(reflog);
for (i=refloglen-1; i >= 0; i--) {
msg = git_reflog_entry_msg(entry); const char *msg;
if (!git__prefixcmp(msg, "checkout: moving")) { entry = git_reflog_entry_byindex(reflog, i);
n--;
if (!n) { msg = git_reflog_entry_msg(entry);
char *branchname = strrchr(msg, ' ') + 1; if (!regexec(&regex, msg, 2, regexmatches, 0)) {
retcode = revparse_lookup_object(out, repo, branchname); n--;
break; if (!n) {
git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so);
retcode = revparse_lookup_object(out, repo, git_buf_cstr(&buf));
break;
}
} }
} }
} }
......
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