summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Straub <bstraub@github.com>2012-05-10 15:07:04 -0700
committerBen Straub <bstraub@github.com>2012-05-11 11:35:50 -0700
commit94952ded3aed856d8fd41ca9a65fcbe59a301efa (patch)
tree34b9277188386542a695de660d4587f368d7bf3f
parent7e79d389a400952a24a5619a8bee88b7b40bee72 (diff)
downloadlibgit2-94952ded3aed856d8fd41ca9a65fcbe59a301efa.tar.gz
Rev-parse: proper error checking.
-rw-r--r--src/revparse.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/revparse.c b/src/revparse.c
index 0fea5ce8d..7cb96b806 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -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);
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 (regex_error != 0) {
- giterr_set_regex(&regex, regex_error);
- } else {
- regmatch_t regexmatches[2];
-
- refloglen = git_reflog_entrycount(reflog);
- for (i=refloglen-1; i >= 0; i--) {
- const char *msg;
- entry = git_reflog_entry_byindex(reflog, i);
-
- msg = git_reflog_entry_msg(entry);
- if (!regexec(&regex, msg, 2, regexmatches, 0)) {
- n--;
- 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;
+ if (!git_reference_lookup(&ref, repo, "HEAD")) {
+ if (!git_reflog_read(&reflog, ref)) {
+ regex_error = regcomp(&regex, "checkout: moving from (.*) to .*", REG_EXTENDED);
+ if (regex_error != 0) {
+ giterr_set_regex(&regex, regex_error);
+ } else {
+ regmatch_t regexmatches[2];
+
+ refloglen = git_reflog_entrycount(reflog);
+ for (i=refloglen-1; i >= 0; i--) {
+ const char *msg;
+ entry = git_reflog_entry_byindex(reflog, i);
+
+ msg = git_reflog_entry_msg(entry);
+ if (!regexec(&regex, msg, 2, regexmatches, 0)) {
+ n--;
+ 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;
+ }
+ }
}
+ regfree(&regex);
}
}
- regfree(&regex);
+ git_reference_free(ref);
}
} else {
git_buf datebuf = GIT_BUF_INIT;