Skip to content

Commit fbd1a69

Browse files
pks-tgitster
authored andcommitted
refs: allow to skip creation of reflog entries
The ref backends do not have any way to disable the creation of reflog entries. This will be required for upcoming ref format migration logic so that we do not create any entries that didn't exist in the original ref database. Provide a new `REF_SKIP_CREATE_REFLOG` flag that allows the caller to disable reflog entry creation. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6e1683a commit fbd1a69

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

refs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,12 @@ int ref_transaction_update(struct ref_transaction *transaction,
11941194
{
11951195
assert(err);
11961196

1197+
if ((flags & REF_FORCE_CREATE_REFLOG) &&
1198+
(flags & REF_SKIP_CREATE_REFLOG)) {
1199+
strbuf_addstr(err, _("refusing to force and skip creation of reflog"));
1200+
return -1;
1201+
}
1202+
11971203
if (!(flags & REF_SKIP_REFNAME_VERIFICATION) &&
11981204
((new_oid && !is_null_oid(new_oid)) ?
11991205
check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :

refs.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,13 +659,19 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
659659
*/
660660
#define REF_SKIP_REFNAME_VERIFICATION (1 << 11)
661661

662+
/*
663+
* Skip creation of a reflog entry, even if it would have otherwise been
664+
* created.
665+
*/
666+
#define REF_SKIP_CREATE_REFLOG (1 << 12)
667+
662668
/*
663669
* Bitmask of all of the flags that are allowed to be passed in to
664670
* ref_transaction_update() and friends:
665671
*/
666672
#define REF_TRANSACTION_UPDATE_ALLOWED_FLAGS \
667673
(REF_NO_DEREF | REF_FORCE_CREATE_REFLOG | REF_SKIP_OID_VERIFICATION | \
668-
REF_SKIP_REFNAME_VERIFICATION)
674+
REF_SKIP_REFNAME_VERIFICATION | REF_SKIP_CREATE_REFLOG)
669675

670676
/*
671677
* Add a reference update to transaction. `new_oid` is the value that

refs/files-backend.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,9 @@ static int files_log_ref_write(struct files_ref_store *refs,
17501750
{
17511751
int logfd, result;
17521752

1753+
if (flags & REF_SKIP_CREATE_REFLOG)
1754+
return 0;
1755+
17531756
if (log_all_ref_updates == LOG_REFS_UNSET)
17541757
log_all_ref_updates = is_bare_repository() ? LOG_REFS_NONE : LOG_REFS_NORMAL;
17551758

@@ -2251,6 +2254,7 @@ static int split_head_update(struct ref_update *update,
22512254
struct ref_update *new_update;
22522255

22532256
if ((update->flags & REF_LOG_ONLY) ||
2257+
(update->flags & REF_SKIP_CREATE_REFLOG) ||
22542258
(update->flags & REF_IS_PRUNING) ||
22552259
(update->flags & REF_UPDATE_VIA_HEAD))
22562260
return 0;

refs/reftable-backend.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,8 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
11031103

11041104
if (ret)
11051105
goto done;
1106-
} else if (u->flags & REF_HAVE_NEW &&
1106+
} else if (!(u->flags & REF_SKIP_CREATE_REFLOG) &&
1107+
(u->flags & REF_HAVE_NEW) &&
11071108
(u->flags & REF_FORCE_CREATE_REFLOG ||
11081109
should_write_log(&arg->refs->base, u->refname))) {
11091110
struct reftable_log_record *log;

t/helper/test-ref-store.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static struct flag_definition transaction_flags[] = {
126126
FLAG_DEF(REF_FORCE_CREATE_REFLOG),
127127
FLAG_DEF(REF_SKIP_OID_VERIFICATION),
128128
FLAG_DEF(REF_SKIP_REFNAME_VERIFICATION),
129+
FLAG_DEF(REF_SKIP_CREATE_REFLOG),
129130
{ NULL, 0 }
130131
};
131132

0 commit comments

Comments
 (0)