summaryrefslogtreecommitdiff
path: root/src/refdb_fs.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-11-23 14:13:01 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2013-12-09 15:55:11 +0100
commit8d5ec9106afbca346a8def84ef20de0a7ba2240a (patch)
tree83dea84e33442fa8e4c58321a246b08b52c5fc0e /src/refdb_fs.c
parent6f13a30565fc3891c0df161945097b316945fca7 (diff)
downloadlibgit2-8d5ec9106afbca346a8def84ef20de0a7ba2240a.tar.gz
refs: expose a way to ensure a ref has a log
Sometimes (e.g. stash) we want to make sure that a log will be written, even if it's not in one of the standard locations. Let's make that easier.
Diffstat (limited to 'src/refdb_fs.c')
-rw-r--r--src/refdb_fs.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 9f23de248..2cdea8274 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -1233,7 +1233,7 @@ static int create_new_reflog_file(const char *filepath)
return error;
if ((fd = p_open(filepath,
- O_WRONLY | O_CREAT | O_TRUNC,
+ O_WRONLY | O_CREAT,
GIT_REFLOG_FILE_MODE)) < 0)
return -1;
@@ -1245,6 +1245,24 @@ GIT_INLINE(int) retrieve_reflog_path(git_buf *path, git_repository *repo, const
return git_buf_join_n(path, '/', 3, repo->path_repository, GIT_REFLOG_DIR, name);
}
+static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *name)
+{
+ refdb_fs_backend *backend;
+ git_repository *repo;
+ git_buf path = GIT_BUF_INIT;
+ int error;
+
+ assert(_backend && name);
+
+ backend = (refdb_fs_backend *) _backend;
+ repo = backend->repo;
+
+ if ((error = retrieve_reflog_path(&path, repo, name)) < 0)
+ return error;
+
+ return create_new_reflog_file(git_buf_cstr(&path));
+}
+
static int has_reflog(git_repository *repo, const char *name)
{
int ret = 0;
@@ -1590,6 +1608,7 @@ int git_refdb_backend_fs(
backend->parent.del = &refdb_fs_backend__delete;
backend->parent.rename = &refdb_fs_backend__rename;
backend->parent.compress = &refdb_fs_backend__compress;
+ backend->parent.ensure_log = &refdb_reflog_fs__ensure_log;
backend->parent.free = &refdb_fs_backend__free;
backend->parent.reflog_read = &refdb_reflog_fs__read;
backend->parent.reflog_write = &refdb_reflog_fs__write;