mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-03 22:01:26 +00:00
refdb: delete a ref's reflog upon deletion
Removing a reflog upon ref deletion is something which only some backends might wish to do. Backends which are database-backed may wish to archive a reflog, log-based ones may not need to do anything.
This commit is contained in:
parent
a522d8c1e7
commit
01d0c02dba
@ -15,6 +15,10 @@ v0.23 + 1
|
|||||||
|
|
||||||
* `git_cert` descendent types now have a proper `parent` member
|
* `git_cert` descendent types now have a proper `parent` member
|
||||||
|
|
||||||
|
* It is the responsibility fo the refdb backend to decide what to do
|
||||||
|
with the reflog on ref deletion. The file-based backend must delete
|
||||||
|
it, a database-backed one may wish to archive it.
|
||||||
|
|
||||||
v0.23
|
v0.23
|
||||||
------
|
------
|
||||||
|
|
||||||
|
@ -103,8 +103,9 @@ struct git_refdb_backend {
|
|||||||
const git_signature *who, const char *message);
|
const git_signature *who, const char *message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the given reference from the refdb. A refdb implementation
|
* Deletes the given reference (and if necessary its reflog)
|
||||||
* must provide this function.
|
* from the refdb. A refdb implementation must provide this
|
||||||
|
* function.
|
||||||
*/
|
*/
|
||||||
int (*del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target);
|
int (*del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target);
|
||||||
|
|
||||||
|
13
src/branch.c
13
src/branch.c
@ -155,18 +155,7 @@ int git_branch_delete(git_reference *branch)
|
|||||||
git_reference_owner(branch), git_buf_cstr(&config_section), NULL) < 0)
|
git_reference_owner(branch), git_buf_cstr(&config_section), NULL) < 0)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
if (git_reference_delete(branch) < 0)
|
error = git_reference_delete(branch);
|
||||||
goto on_error;
|
|
||||||
|
|
||||||
if ((error = git_reflog_delete(git_reference_owner(branch), git_reference_name(branch))) < 0) {
|
|
||||||
if (error == GIT_ENOTFOUND) {
|
|
||||||
giterr_clear();
|
|
||||||
error = 0;
|
|
||||||
}
|
|
||||||
goto on_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = 0;
|
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
git_buf_free(&config_section);
|
git_buf_free(&config_section);
|
||||||
|
@ -63,6 +63,8 @@ typedef struct refdb_fs_backend {
|
|||||||
uint32_t direach_flags;
|
uint32_t direach_flags;
|
||||||
} refdb_fs_backend;
|
} refdb_fs_backend;
|
||||||
|
|
||||||
|
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
|
||||||
|
|
||||||
static int packref_cmp(const void *a_, const void *b_)
|
static int packref_cmp(const void *a_, const void *b_)
|
||||||
{
|
{
|
||||||
const struct packref *a = a_, *b = b_;
|
const struct packref *a = a_, *b = b_;
|
||||||
@ -1217,6 +1219,11 @@ static int refdb_fs_backend__delete(
|
|||||||
if ((error = loose_lock(&file, backend, ref_name)) < 0)
|
if ((error = loose_lock(&file, backend, ref_name)) < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
if ((error = refdb_reflog_fs__delete(_backend, ref_name)) < 0) {
|
||||||
|
git_filebuf_cleanup(&file);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
return refdb_fs_backend__delete_tail(_backend, &file, ref_name, old_id, old_target);
|
return refdb_fs_backend__delete_tail(_backend, &file, ref_name, old_id, old_target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +132,8 @@ void test_refs_branches_delete__removes_reflog(void)
|
|||||||
cl_git_pass(git_branch_delete(branch));
|
cl_git_pass(git_branch_delete(branch));
|
||||||
git_reference_free(branch);
|
git_reference_free(branch);
|
||||||
|
|
||||||
|
cl_assert_equal_i(false, git_reference_has_log(repo, "refs/heads/track-local"));
|
||||||
|
|
||||||
/* Reading a nonexistant reflog creates it, but it should be empty */
|
/* Reading a nonexistant reflog creates it, but it should be empty */
|
||||||
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local"));
|
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local"));
|
||||||
cl_assert_equal_i(0, git_reflog_entrycount(log));
|
cl_assert_equal_i(0, git_reflog_entrycount(log));
|
||||||
|
Loading…
Reference in New Issue
Block a user