Commit 94952ded by Ben Straub

Rev-parse: proper error checking.

parent 7e79d389
...@@ -169,32 +169,34 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char * ...@@ -169,32 +169,34 @@ static int walk_ref_history(git_object **out, git_repository *repo, const char *
giterr_set(GITERR_INVALID, "Invalid reflogspec %s", reflogspec); giterr_set(GITERR_INVALID, "Invalid reflogspec %s", reflogspec);
return GIT_ERROR; return GIT_ERROR;
} }
git_reference_lookup(&ref, repo, "HEAD");
git_reflog_read(&reflog, ref);
git_reference_free(ref);
regex_error = regcomp(&regex, "checkout: moving from (.*) to .*", REG_EXTENDED); if (!git_reference_lookup(&ref, repo, "HEAD")) {
if (regex_error != 0) { if (!git_reflog_read(&reflog, ref)) {
giterr_set_regex(&regex, regex_error); regex_error = regcomp(&regex, "checkout: moving from (.*) to .*", REG_EXTENDED);
} else { if (regex_error != 0) {
regmatch_t regexmatches[2]; giterr_set_regex(&regex, regex_error);
} else {
refloglen = git_reflog_entrycount(reflog); regmatch_t regexmatches[2];
for (i=refloglen-1; i >= 0; i--) {
const char *msg; refloglen = git_reflog_entrycount(reflog);
entry = git_reflog_entry_byindex(reflog, i); for (i=refloglen-1; i >= 0; i--) {
const char *msg;
msg = git_reflog_entry_msg(entry); entry = git_reflog_entry_byindex(reflog, i);
if (!regexec(&regex, msg, 2, regexmatches, 0)) {
n--; msg = git_reflog_entry_msg(entry);
if (!n) { if (!regexec(&regex, msg, 2, regexmatches, 0)) {
git_buf_put(&buf, msg+regexmatches[1].rm_so, regexmatches[1].rm_eo - regexmatches[1].rm_so); n--;
retcode = revparse_lookup_object(out, repo, git_buf_cstr(&buf)); if (!n) {
break; 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;
}
}
} }
regfree(&regex);
} }
} }
regfree(&regex); git_reference_free(ref);
} }
} else { } else {
git_buf datebuf = GIT_BUF_INIT; git_buf datebuf = GIT_BUF_INIT;
......
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