summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2013-11-17 23:26:49 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2013-12-09 15:55:11 +0100
commit6f13a30565fc3891c0df161945097b316945fca7 (patch)
tree81ef80d298be7a4b669ca9ff3176e616532783de /src
parent13c9e44af9424e1fc478693f0d64fbf7082c9665 (diff)
downloadlibgit2-6f13a30565fc3891c0df161945097b316945fca7.tar.gz
reflog: write to the reflog following git's rules
git-core only writes to the reflogs of HEAD, refs/heads/ and, refs/notes/ or if there is already a reflog in place. Adjust our code to follow these semantics.
Diffstat (limited to 'src')
-rw-r--r--src/refdb_fs.c36
-rw-r--r--src/refs.h1
2 files changed, 34 insertions, 3 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 2f7b43401..9f23de248 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -911,6 +911,22 @@ fail:
}
static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_signature *author, const char *message);
+static int has_reflog(git_repository *repo, const char *name);
+
+/* We only write if it's under heads/, remotes/ or notes/ or if it already has a log */
+static bool should_write_reflog(git_repository *repo, const char *name)
+{
+ if (has_reflog(repo, name))
+ return 1;
+
+ if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR) ||
+ !git__strcmp(name, GIT_HEAD_FILE) ||
+ !git__prefixcmp(name, GIT_REFS_REMOTES_DIR) ||
+ !git__prefixcmp(name, GIT_REFS_NOTES_DIR))
+ return 1;
+
+ return 0;
+}
static int refdb_fs_backend__write(
git_refdb_backend *_backend,
@@ -933,7 +949,8 @@ static int refdb_fs_backend__write(
if ((error = loose_lock(&file, backend, ref)) < 0)
return error;
- if ((error = reflog_append(backend, ref, who, message)) < 0) {
+ if (should_write_reflog(backend->repo, ref->name) &&
+ (error = reflog_append(backend, ref, who, message)) < 0) {
git_filebuf_cleanup(&file);
return error;
}
@@ -1228,6 +1245,21 @@ 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 has_reflog(git_repository *repo, const char *name)
+{
+ int ret = 0;
+ git_buf path = GIT_BUF_INIT;
+
+ if (retrieve_reflog_path(&path, repo, name) < 0)
+ goto cleanup;
+
+ ret = git_path_isfile(git_buf_cstr(&path));
+
+cleanup:
+ git_buf_free(&path);
+ return ret;
+}
+
static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
{
int error = -1;
@@ -1338,7 +1370,6 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
int error = -1;
unsigned int i;
git_reflog_entry *entry;
- git_repository *repo;
refdb_fs_backend *backend;
git_buf log = GIT_BUF_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
@@ -1346,7 +1377,6 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
assert(_backend && reflog);
backend = (refdb_fs_backend *) _backend;
- repo = backend->repo;
if ((error = lock_reflog(&fbuf, backend, reflog->ref_name)) < 0)
return -1;
diff --git a/src/refs.h b/src/refs.h
index 80c7703fc..4d5b6dacb 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -19,6 +19,7 @@
#define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/"
#define GIT_REFS_TAGS_DIR GIT_REFS_DIR "tags/"
#define GIT_REFS_REMOTES_DIR GIT_REFS_DIR "remotes/"
+#define GIT_REFS_NOTES_DIR GIT_REFS_DIR "notes/"
#define GIT_REFS_DIR_MODE 0777
#define GIT_REFS_FILE_MODE 0666