aboutsummaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/refs.c b/refs.c
index 0f41b2fd4a..91da5325d7 100644
--- a/refs.c
+++ b/refs.c
@@ -1318,19 +1318,27 @@ int ref_transaction_update(struct ref_transaction *transaction,
return 0;
}
-int ref_transaction_update_reflog(struct ref_transaction *transaction,
- const char *refname,
- const struct object_id *new_oid,
- const struct object_id *old_oid,
- const char *committer_info, unsigned int flags,
- const char *msg, unsigned int index,
- struct strbuf *err)
+/*
+ * Similar to`ref_transaction_update`, but this function is only for adding
+ * a reflog update. Supports providing custom committer information. The index
+ * field can be utiltized to order updates as desired. When not used, the
+ * updates default to being ordered by refname.
+ */
+static int ref_transaction_update_reflog(struct ref_transaction *transaction,
+ const char *refname,
+ const struct object_id *new_oid,
+ const struct object_id *old_oid,
+ const char *committer_info,
+ unsigned int flags,
+ const char *msg,
+ uint64_t index,
+ struct strbuf *err)
{
struct ref_update *update;
assert(err);
- flags |= REF_LOG_ONLY | REF_NO_DEREF;
+ flags |= REF_LOG_ONLY | REF_FORCE_CREATE_REFLOG | REF_NO_DEREF;
if (!transaction_refname_valid(refname, new_oid, flags, err))
return -1;
@@ -1345,6 +1353,13 @@ int ref_transaction_update_reflog(struct ref_transaction *transaction,
update->flags &= ~REF_HAVE_OLD;
update->index = index;
+ /*
+ * Reference backends may need to know the max index to optimize
+ * their writes. So we store the max_index on the transaction level.
+ */
+ if (index > transaction->max_index)
+ transaction->max_index = index;
+
return 0;
}
@@ -2798,7 +2813,7 @@ done:
}
struct reflog_migration_data {
- unsigned int index;
+ uint64_t index;
const char *refname;
struct ref_store *old_refs;
struct ref_transaction *transaction;
@@ -3028,9 +3043,11 @@ int repo_migrate_ref_storage_format(struct repository *repo,
if (ret < 0)
goto done;
- ret = refs_for_each_reflog(old_refs, migrate_one_reflog, &data);
- if (ret < 0)
- goto done;
+ if (!(flags & REPO_MIGRATE_REF_STORAGE_FORMAT_SKIP_REFLOG)) {
+ ret = refs_for_each_reflog(old_refs, migrate_one_reflog, &data);
+ if (ret < 0)
+ goto done;
+ }
ret = ref_transaction_commit(transaction, errbuf);
if (ret < 0)