Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2012-07-21 21:19:46 +0400
committernulltoken <emeric.fermas@gmail.com>2012-07-25 10:01:13 +0400
commitc3be5c5af089683b6c61d1d37d8c2c40ff48e9a8 (patch)
treeee2f7b8615da1c6f85a096ea09697c798a525f8b /src/reflog.c
parent40c75652d075f87f20ddfbb715667f82644bc760 (diff)
reflog: keep the reflog name in sync with the reference name
Diffstat (limited to 'src/reflog.c')
-rw-r--r--src/reflog.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/reflog.c b/src/reflog.c
index ef0aa7eca..f841b2174 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -183,6 +183,18 @@ static int retrieve_reflog_path(git_buf *path, git_reference *ref)
git_reference_owner(ref)->path_repository, GIT_REFLOG_DIR, ref->name);
}
+int create_new_reflog_file(const char *filepath)
+{
+ int fd;
+
+ if ((fd = p_open(filepath,
+ O_WRONLY | O_CREAT | O_TRUNC,
+ GIT_REFLOG_FILE_MODE)) < 0)
+ return -1;
+
+ return p_close(fd);
+}
+
int git_reflog_read(git_reflog **reflog, git_reference *ref)
{
int error;
@@ -204,6 +216,10 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref)
if (error < 0 && error != GIT_ENOTFOUND)
goto cleanup;
+ if ((error == GIT_ENOTFOUND) &&
+ ((error = create_new_reflog_file(git_buf_cstr(&log_path))) < 0))
+ goto cleanup;
+
if ((error = reflog_parse(log,
git_buf_cstr(&log_file), git_buf_len(&log_file))) < 0)
goto cleanup;
@@ -237,6 +253,12 @@ int git_reflog_write(git_reflog *reflog)
git_repository_path(reflog->owner), GIT_REFLOG_DIR, reflog->ref_name) < 0)
return -1;
+ if (!git_path_isfile(git_buf_cstr(&log_path))) {
+ giterr_set(GITERR_INVALID,
+ "Log file for reference '%s' doesn't exist.", reflog->ref_name);
+ goto cleanup;
+ }
+
if ((error = git_filebuf_open(&fbuf, git_buf_cstr(&log_path), 0)) < 0)
goto cleanup;