mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-24 07:03:45 +00:00
reflog: prevent git_reflog_read() from chocking when no log exists yet
This commit is contained in:
parent
bd72425d16
commit
ae8331784e
@ -23,6 +23,10 @@ GIT_BEGIN_DECL
|
|||||||
/**
|
/**
|
||||||
* Read the reflog for the given reference
|
* Read the reflog for the given reference
|
||||||
*
|
*
|
||||||
|
* If there is no reflog file for the given
|
||||||
|
* reference yet, an empty reflog object will
|
||||||
|
* be returned.
|
||||||
|
*
|
||||||
* The reflog must be freed manually by using
|
* The reflog must be freed manually by using
|
||||||
* git_reflog_free().
|
* git_reflog_free().
|
||||||
*
|
*
|
||||||
|
25
src/reflog.c
25
src/reflog.c
@ -217,22 +217,29 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
|
|||||||
|
|
||||||
*reflog = NULL;
|
*reflog = NULL;
|
||||||
|
|
||||||
|
assert(reflog && ref);
|
||||||
|
|
||||||
if (reflog_init(&log, ref) < 0)
|
if (reflog_init(&log, ref) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
error = retrieve_reflog_path(&log_path, ref);
|
if (retrieve_reflog_path(&log_path, ref) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!error)
|
error = git_futils_readbuffer(&log_file, git_buf_cstr(&log_path));
|
||||||
error = git_futils_readbuffer(&log_file, log_path.ptr);
|
if (error < 0 && error != GIT_ENOTFOUND)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!error)
|
if ((error = reflog_parse(log,
|
||||||
error = reflog_parse(log, log_file.ptr, log_file.size);
|
git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!error)
|
*reflog = log;
|
||||||
*reflog = log;
|
goto success;
|
||||||
else
|
|
||||||
git_reflog_free(log);
|
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
git_reflog_free(log);
|
||||||
|
|
||||||
|
success:
|
||||||
git_buf_free(&log_file);
|
git_buf_free(&log_file);
|
||||||
git_buf_free(&log_path);
|
git_buf_free(&log_path);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user