aboutsummaryrefslogtreecommitdiffstats
path: root/refs/packed-backend.c
diff options
context:
space:
mode:
Diffstat (limited to 'refs/packed-backend.c')
-rw-r--r--refs/packed-backend.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index d500ebfaa5..6e85b0bf0b 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -143,7 +143,7 @@ struct packed_ref_store {
* "packed-refs" file. Note that this (and thus the enclosing
* `packed_ref_store`) must not be freed.
*/
- struct tempfile tempfile;
+ struct tempfile *tempfile;
};
/*
@@ -997,8 +997,9 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
return -1;
}
- if (close_lock_file(&refs->lock)) {
+ if (close_lock_file_gently(&refs->lock)) {
strbuf_addf(err, "unable to close %s: %s", refs->path, strerror(errno));
+ rollback_lock_file(&refs->lock);
return -1;
}
@@ -1091,7 +1092,8 @@ static int write_with_updates(struct packed_ref_store *refs,
packed_refs_path = get_locked_file_path(&refs->lock);
strbuf_addf(&sb, "%s.new", packed_refs_path);
free(packed_refs_path);
- if (create_tempfile(&refs->tempfile, sb.buf) < 0) {
+ refs->tempfile = create_tempfile(sb.buf);
+ if (!refs->tempfile) {
strbuf_addf(err, "unable to create file %s: %s",
sb.buf, strerror(errno));
strbuf_release(&sb);
@@ -1099,7 +1101,7 @@ static int write_with_updates(struct packed_ref_store *refs,
}
strbuf_release(&sb);
- out = fdopen_tempfile(&refs->tempfile, "w");
+ out = fdopen_tempfile(refs->tempfile, "w");
if (!out) {
strbuf_addf(err, "unable to fdopen packed-refs tempfile: %s",
strerror(errno));
@@ -1236,11 +1238,12 @@ static int write_with_updates(struct packed_ref_store *refs,
goto error;
}
- if (close_tempfile(&refs->tempfile)) {
+ if (close_tempfile_gently(refs->tempfile)) {
strbuf_addf(err, "error closing file %s: %s",
- get_tempfile_path(&refs->tempfile),
+ get_tempfile_path(refs->tempfile),
strerror(errno));
strbuf_release(&sb);
+ delete_tempfile(&refs->tempfile);
return -1;
}
@@ -1248,7 +1251,7 @@ static int write_with_updates(struct packed_ref_store *refs,
write_error:
strbuf_addf(err, "error writing to %s: %s",
- get_tempfile_path(&refs->tempfile), strerror(errno));
+ get_tempfile_path(refs->tempfile), strerror(errno));
error:
if (iter)
@@ -1273,7 +1276,7 @@ static void packed_transaction_cleanup(struct packed_ref_store *refs,
if (data) {
string_list_clear(&data->updates, 0);
- if (is_tempfile_active(&refs->tempfile))
+ if (is_tempfile_active(refs->tempfile))
delete_tempfile(&refs->tempfile);
if (data->own_lock && is_lock_file_locked(&refs->lock)) {
@@ -1469,6 +1472,13 @@ static int packed_rename_ref(struct ref_store *ref_store,
die("BUG: packed reference store does not support renaming references");
}
+static int packed_copy_ref(struct ref_store *ref_store,
+ const char *oldrefname, const char *newrefname,
+ const char *logmsg)
+{
+ die("BUG: packed reference store does not support copying references");
+}
+
static struct ref_iterator *packed_reflog_iterator_begin(struct ref_store *ref_store)
{
return empty_ref_iterator_begin();
@@ -1533,6 +1543,7 @@ struct ref_storage_be refs_be_packed = {
packed_create_symref,
packed_delete_refs,
packed_rename_ref,
+ packed_copy_ref,
packed_ref_iterator_begin,
packed_read_raw_ref,