refs: allow log-only updates
The refs infrastructure learns about log-only ref updates, which only update the reflog. Later, we will use this to separate symbolic reference resolution from ref updating. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
David Turner committed
Feb 24, 2016 at 17:58 UTC
d99aa884dff33d48d5aab8c9cf989a25c779fd70
2 files changed
+17
-6
refs/files-backend.c
+10
-6
@@ -2683,7 +2683,7 @@ static int commit_ref_update(struct ref_lock *lock,
2683
}
2684
}
2685
}
2686
- if (commit_ref(lock)) {
2686
+ if (!(flags & REF_LOG_ONLY) && commit_ref(lock)) {
2687
strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
2688
unlock_ref(lock);
2689
return -1;
@@ -3101,7 +3101,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3101
goto cleanup;
3102
}
3103
if ((update->flags & REF_HAVE_NEW) &&
3104
- !(update->flags & REF_DELETING)) {
3104
+ !(update->flags & REF_DELETING) &&
3105
+ !(update->flags & REF_LOG_ONLY)) {
3106
int overwriting_symref = ((update->type & REF_ISSYMREF) &&
3107
(update->flags & REF_NODEREF));
3108
@@ -3133,8 +3134,9 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3134
}
3135
if (!(update->flags & REF_NEEDS_COMMIT)) {
3136
/*
3136
- * We didn't have to write anything to the lockfile.
3137
- * Close it to free up the file descriptor:
3137
+ * We didn't call write_ref_to_lockfile(), so
3138
+ * the lockfile is still open. Close it to
3139
+ * free up the file descriptor:
3140
*/
3141
if (close_ref(update->lock)) {
3142
strbuf_addf(err, "couldn't close '%s.lock'",
@@ -3149,7 +3151,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3151
for (i = 0; i < transaction->nr; i++) {
3152
struct ref_update *update = transaction->updates[i];
3153
3152
- if (update->flags & REF_NEEDS_COMMIT) {
3154
+ if (update->flags & REF_NEEDS_COMMIT ||
3155
+ update->flags & REF_LOG_ONLY) {
3156
if (commit_ref_update(update->lock,
3157
update->new_sha1, update->msg,
3158
update->flags, err)) {
@@ -3168,7 +3171,8 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3171
for (i = 0; i < transaction->nr; i++) {
3172
struct ref_update *update = transaction->updates[i];
3173
3171
- if (update->flags & REF_DELETING) {
3174
+ if (update->flags & REF_DELETING &&
3175
+ !(update->flags & REF_LOG_ONLY)) {
3176
if (delete_ref_loose(update->lock, update->type, err)) {
3177
ret = TRANSACTION_GENERIC_ERROR;
3178
goto cleanup;
refs/refs-internal.h
+7
@@ -42,6 +42,13 @@
42
* value to ref_update::flags
43
*/
44
45
+/*
46
+ * Used as a flag in ref_update::flags when we want to log a ref
47
+ * update but not actually perform it. This is used when a symbolic
48
+ * ref update is split up.
49
+ */
50
+#define REF_LOG_ONLY 0x80
51
+
52
/*
53
* Return true iff refname is minimally safe. "Safe" here means that
54
* deleting a loose reference by this name will not do any damage, for