Commit f2105129 by Carlos Martín Nieto

refs: expose has_log() on the backend

The frontend used to look at the file directly, but that's obviously not
the right thing to do. Expose it on the backend and use that function
instead.
parent 8d5ec910
......@@ -548,12 +548,12 @@ GIT_EXTERN(int) git_reference_foreach_glob(
/**
* Check if a reflog exists for the specified reference.
*
* @param ref A git reference
*
* @param repo the repository
* @param refname the reference's name
* @return 0 when no reflog can be found, 1 when it exists;
* otherwise an error code.
*/
GIT_EXTERN(int) git_reference_has_log(git_reference *ref);
GIT_EXTERN(int) git_reference_has_log(git_repository *repo, const char *refname);
/**
* Ensure there is a reflog for a particular reference.
......
......@@ -117,6 +117,11 @@ struct git_refdb_backend {
int (*compress)(git_refdb_backend *backend);
/**
* Query whether a particular reference has a log (may be empty)
*/
int (*has_log)(git_refdb_backend *backend, const char *refname);
/**
* Make sure a particular reference will have a reflog which
* will be appended to on writes.
*/
......
......@@ -222,6 +222,13 @@ int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name)
return 0;
}
int git_refdb_has_log(git_refdb *db, const char *refname)
{
assert(db && refname);
return db->backend->has_log(db->backend, refname);
}
int git_refdb_ensure_log(git_refdb *db, const char *refname)
{
assert(db && refname);
......
......@@ -48,6 +48,7 @@ int git_refdb_delete(git_refdb *refdb, const char *ref_name);
int git_refdb_reflog_read(git_reflog **out, git_refdb *db, const char *name);
int git_refdb_reflog_write(git_reflog *reflog);
int git_refdb_has_log(git_refdb *db, const char *refname);
int git_refdb_ensure_log(git_refdb *refdb, const char *refname);
......
......@@ -1278,6 +1278,17 @@ cleanup:
return ret;
}
static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *name)
{
refdb_fs_backend *backend;
assert(_backend && name);
backend = (refdb_fs_backend *) _backend;
return has_reflog(backend->repo, name);
}
static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
{
int error = -1;
......@@ -1608,6 +1619,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.has_log = &refdb_reflog_fs__has_log;
backend->parent.ensure_log = &refdb_reflog_fs__ensure_log;
backend->parent.free = &refdb_fs_backend__free;
backend->parent.reflog_read = &refdb_reflog_fs__read;
......
......@@ -1050,22 +1050,17 @@ int git_reference__update_terminal(
return reference__update_terminal(repo, ref_name, oid, 0);
}
int git_reference_has_log(
git_reference *ref)
int git_reference_has_log(git_repository *repo, const char *refname)
{
git_buf path = GIT_BUF_INIT;
int result;
assert(ref);
int error;
git_refdb *refdb;
if (git_buf_join_n(&path, '/', 3, ref->db->repo->path_repository,
GIT_REFLOG_DIR, ref->name) < 0)
return -1;
assert(repo && refname);
result = git_path_isfile(git_buf_cstr(&path));
git_buf_free(&path);
if ((error = git_repository_refdb__weakptr(&refdb, repo)) < 0)
return error;
return result;
return git_refdb_has_log(refdb, refname);
}
int git_reference_ensure_log(git_repository *repo, const char *refname)
......
......@@ -127,13 +127,7 @@ void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
static void assert_has_reflog(bool expected_result, const char *name)
{
git_reference *ref;
cl_git_pass(git_reference_lookup(&ref, g_repo, name));
cl_assert_equal_i(expected_result, git_reference_has_log(ref));
git_reference_free(ref);
cl_assert_equal_i(expected_result, git_reference_has_log(g_repo, name));
}
void test_refs_reflog_reflog__reference_has_reflog(void)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment