Commit 110df893 by Carlos Martín Nieto

refdb: add a `message` parameter for appending to the log

This is as yet unused.
parent a6b50808
......@@ -93,11 +93,13 @@ struct git_refdb_backend {
* must provide this function.
*/
int (*write)(git_refdb_backend *backend,
const git_reference *ref, int force);
const git_reference *ref, int force,
const char *message);
int (*rename)(
git_reference **out, git_refdb_backend *backend,
const char *old_name, const char *new_name, int force);
const char *old_name, const char *new_name, int force,
const char *message);
/**
* Deletes the given reference from the refdb. A refdb implementation
......
......@@ -167,14 +167,14 @@ void git_refdb_iterator_free(git_reference_iterator *iter)
iter->free(iter);
}
int git_refdb_write(git_refdb *db, git_reference *ref, int force)
int git_refdb_write(git_refdb *db, git_reference *ref, int force, const char *message)
{
assert(db && db->backend);
GIT_REFCOUNT_INC(db);
ref->db = db;
return db->backend->write(db->backend, ref, force);
return db->backend->write(db->backend, ref, force, message);
}
int git_refdb_rename(
......@@ -182,12 +182,13 @@ int git_refdb_rename(
git_refdb *db,
const char *old_name,
const char *new_name,
int force)
int force,
const char *message)
{
int error;
assert(db && db->backend);
error = db->backend->rename(out, db->backend, old_name, new_name, force);
error = db->backend->rename(out, db->backend, old_name, new_name, force, message);
if (error < 0)
return error;
......
......@@ -33,14 +33,15 @@ int git_refdb_rename(
git_refdb *db,
const char *old_name,
const char *new_name,
int force);
int force,
const char *message);
int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob);
int git_refdb_iterator_next(git_reference **out, git_reference_iterator *iter);
int git_refdb_iterator_next_name(const char **out, git_reference_iterator *iter);
void git_refdb_iterator_free(git_reference_iterator *iter);
int git_refdb_write(git_refdb *refdb, git_reference *ref, int force);
int git_refdb_write(git_refdb *refdb, git_reference *ref, int force, const char *message);
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);
......
......@@ -910,7 +910,8 @@ fail:
static int refdb_fs_backend__write(
git_refdb_backend *_backend,
const git_reference *ref,
int force)
int force,
const char *message)
{
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
int error;
......@@ -974,7 +975,8 @@ static int refdb_fs_backend__rename(
git_refdb_backend *_backend,
const char *old_name,
const char *new_name,
int force)
int force,
const char *message)
{
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
git_reference *old, *new;
......@@ -1264,6 +1266,32 @@ static int serialize_reflog_entry(
return git_buf_oom(buf);
}
static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname)
{
git_repository *repo;
git_buf log_path = GIT_BUF_INIT;
int error;
repo = backend->repo;
if (retrieve_reflog_path(&log_path, repo, refname) < 0)
return -1;
if (!git_path_isfile(git_buf_cstr(&log_path))) {
giterr_set(GITERR_INVALID,
"Log file for reference '%s' doesn't exist.", refname);
error = -1;
goto cleanup;
}
error = git_filebuf_open(file, git_buf_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
cleanup:
git_buf_free(&log_path);
return error;
}
static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflog)
{
int error = -1;
......@@ -1271,7 +1299,6 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
git_reflog_entry *entry;
git_repository *repo;
refdb_fs_backend *backend;
git_buf log_path = GIT_BUF_INIT;
git_buf log = GIT_BUF_INIT;
git_filebuf fbuf = GIT_FILEBUF_INIT;
......@@ -1280,18 +1307,9 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
backend = (refdb_fs_backend *) _backend;
repo = backend->repo;
if (retrieve_reflog_path(&log_path, repo, reflog->ref_name) < 0)
if ((error = lock_reflog(&fbuf, backend, 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, GIT_REFLOG_FILE_MODE)) < 0)
goto cleanup;
git_vector_foreach(&reflog->entries, i, entry) {
if (serialize_reflog_entry(&log, &(entry->oid_old), &(entry->oid_cur), entry->committer, entry->msg) < 0)
goto cleanup;
......@@ -1308,7 +1326,7 @@ cleanup:
success:
git_buf_free(&log);
git_buf_free(&log_path);
return error;
}
......
......@@ -396,7 +396,7 @@ static int reference__create(
GITERR_CHECK_ALLOC(ref);
if ((error = git_refdb_write(refdb, ref, force)) < 0) {
if ((error = git_refdb_write(refdb, ref, force, log_message)) < 0) {
git_reference_free(ref);
return error;
}
......@@ -579,7 +579,7 @@ int git_reference_rename(
should_head_be_updated = (error > 0);
if ((error = git_refdb_rename(out, ref->db, ref->name, new_name, force)) < 0)
if ((error = git_refdb_rename(out, ref->db, ref->name, new_name, force, NULL)) < 0)
return error;
/* Update HEAD it was poiting to the reference being renamed. */
......
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