summaryrefslogtreecommitdiff
path: root/src/reflog.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-07-21 12:32:02 +0200
committernulltoken <emeric.fermas@gmail.com>2012-07-25 07:53:31 +0200
commitae8331784eb968169e03099a5803a236a6a5aed4 (patch)
tree57dcf4b96429d973934543bc29b9eb568ec9572e /src/reflog.c
parentbd72425d16fce9771af7727029f7d8ea8c2e98d2 (diff)
downloadlibgit2-ae8331784eb968169e03099a5803a236a6a5aed4.tar.gz
reflog: prevent git_reflog_read() from chocking when no log exists yet
Diffstat (limited to 'src/reflog.c')
-rw-r--r--src/reflog.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/reflog.c b/src/reflog.c
index dbac28aff..9007bd379 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -217,22 +217,29 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
*reflog = NULL;
+ assert(reflog && ref);
+
if (reflog_init(&log, ref) < 0)
return -1;
- error = retrieve_reflog_path(&log_path, ref);
+ if (retrieve_reflog_path(&log_path, ref) < 0)
+ goto cleanup;
+
+ error = git_futils_readbuffer(&log_file, git_buf_cstr(&log_path));
+ if (error < 0 && error != GIT_ENOTFOUND)
+ goto cleanup;
- if (!error)
- error = git_futils_readbuffer(&log_file, log_path.ptr);
+ if ((error = reflog_parse(log,
+ git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
+ goto cleanup;
- if (!error)
- error = reflog_parse(log, log_file.ptr, log_file.size);
+ *reflog = log;
+ goto success;
- if (!error)
- *reflog = log;
- else
- git_reflog_free(log);
+cleanup:
+ git_reflog_free(log);
+success:
git_buf_free(&log_file);
git_buf_free(&log_path);