Skip to content

Commit a0efef1

Browse files
pks-tgitster
authored andcommitted
refs: allow passing flags when setting up a transaction
Allow passing flags when setting up a transaction such that the behaviour of the transaction itself can be altered. This functionality will be used in a subsequent patch. Adapt callers accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent facbe4f commit a0efef1

File tree

14 files changed

+33
-26
lines changed

14 files changed

+33
-26
lines changed

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ void create_branch(struct repository *r,
627627
else
628628
msg = xstrfmt("branch: Created from %s", start_name);
629629
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
630-
&err);
630+
0, &err);
631631
if (!transaction ||
632632
ref_transaction_update(transaction, ref.buf,
633633
&oid, forcing ? NULL : null_oid(),

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ static void write_remote_refs(const struct ref *local_refs)
574574
struct strbuf err = STRBUF_INIT;
575575

576576
t = ref_store_transaction_begin(get_main_ref_store(the_repository),
577-
&err);
577+
0, &err);
578578
if (!t)
579579
die("%s", err.buf);
580580

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ static int update_branch(struct branch *b)
16341634
}
16351635
}
16361636
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1637-
&err);
1637+
0, &err);
16381638
if (!transaction ||
16391639
ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
16401640
NULL, NULL, 0, msg, &err) ||
@@ -1669,7 +1669,7 @@ static void dump_tags(void)
16691669
struct ref_transaction *transaction;
16701670

16711671
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1672-
&err);
1672+
0, &err);
16731673
if (!transaction) {
16741674
failure |= error("%s", err.buf);
16751675
goto cleanup;

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ static int s_update_ref(const char *action,
669669
*/
670670
if (!transaction) {
671671
transaction = our_transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
672-
&err);
672+
0, &err);
673673
if (!transaction) {
674674
ret = STORE_REF_ERROR_OTHER;
675675
goto out;
@@ -1671,7 +1671,7 @@ static int do_fetch(struct transport *transport,
16711671

16721672
if (atomic_fetch) {
16731673
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1674-
&err);
1674+
0, &err);
16751675
if (!transaction) {
16761676
retcode = -1;
16771677
goto cleanup;

builtin/receive-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ static void execute_commands_non_atomic(struct command *commands,
18491849
continue;
18501850

18511851
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1852-
&err);
1852+
0, &err);
18531853
if (!transaction) {
18541854
rp_error("%s", err.buf);
18551855
strbuf_reset(&err);
@@ -1878,7 +1878,7 @@ static void execute_commands_atomic(struct command *commands,
18781878
const char *reported_error = "atomic push failure";
18791879

18801880
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
1881-
&err);
1881+
0, &err);
18821882
if (!transaction) {
18831883
rp_error("%s", err.buf);
18841884
strbuf_reset(&err);

builtin/replace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int replace_object_oid(const char *object_ref,
201201
}
202202

203203
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
204-
&err);
204+
0, &err);
205205
if (!transaction ||
206206
ref_transaction_update(transaction, ref.buf, repl, &prev,
207207
NULL, NULL, 0, NULL, &err) ||

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ int cmd_tag(int argc,
681681
}
682682

683683
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
684-
&err);
684+
0, &err);
685685
if (!transaction ||
686686
ref_transaction_update(transaction, ref.buf, &object, &prev,
687687
NULL, NULL,

builtin/update-ref.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ static void update_refs_stdin(void)
612612
int i, j;
613613

614614
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
615-
&err);
615+
0, &err);
616616
if (!transaction)
617617
die("%s", err.buf);
618618

@@ -680,7 +680,7 @@ static void update_refs_stdin(void)
680680
*/
681681
state = cmd->state;
682682
transaction = ref_store_transaction_begin(get_main_ref_store(the_repository),
683-
&err);
683+
0, &err);
684684
if (!transaction)
685685
die("%s", err.buf);
686686

refs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ int refs_delete_ref(struct ref_store *refs, const char *msg,
918918
struct ref_transaction *transaction;
919919
struct strbuf err = STRBUF_INIT;
920920

921-
transaction = ref_store_transaction_begin(refs, &err);
921+
transaction = ref_store_transaction_begin(refs, 0, &err);
922922
if (!transaction ||
923923
ref_transaction_delete(transaction, refname, old_oid,
924924
NULL, flags, msg, &err) ||
@@ -1116,13 +1116,15 @@ int read_ref_at(struct ref_store *refs, const char *refname,
11161116
}
11171117

11181118
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
1119+
unsigned int flags,
11191120
struct strbuf *err)
11201121
{
11211122
struct ref_transaction *tr;
11221123
assert(err);
11231124

11241125
CALLOC_ARRAY(tr, 1);
11251126
tr->ref_store = refs;
1127+
tr->flags = flags;
11261128
return tr;
11271129
}
11281130

@@ -1309,7 +1311,7 @@ int refs_update_ref(struct ref_store *refs, const char *msg,
13091311
struct strbuf err = STRBUF_INIT;
13101312
int ret = 0;
13111313

1312-
t = ref_store_transaction_begin(refs, &err);
1314+
t = ref_store_transaction_begin(refs, 0, &err);
13131315
if (!t ||
13141316
ref_transaction_update(t, refname, new_oid, old_oid, NULL, NULL,
13151317
flags, msg, &err) ||
@@ -2120,7 +2122,7 @@ int refs_update_symref(struct ref_store *refs, const char *ref,
21202122
struct strbuf err = STRBUF_INIT;
21212123
int ret = 0;
21222124

2123-
transaction = ref_store_transaction_begin(refs, &err);
2125+
transaction = ref_store_transaction_begin(refs, 0, &err);
21242126
if (!transaction ||
21252127
ref_transaction_update(transaction, ref, NULL, NULL,
21262128
target, NULL, REF_NO_DEREF,
@@ -2527,7 +2529,7 @@ int refs_delete_refs(struct ref_store *refs, const char *logmsg,
25272529
* individual updates can't fail, so we can pack all of the
25282530
* updates into a single transaction.
25292531
*/
2530-
transaction = ref_store_transaction_begin(refs, &err);
2532+
transaction = ref_store_transaction_begin(refs, 0, &err);
25312533
if (!transaction) {
25322534
ret = error("%s", err.buf);
25332535
goto out;
@@ -2833,7 +2835,7 @@ int repo_migrate_ref_storage_format(struct repository *repo,
28332835
if (ret < 0)
28342836
goto done;
28352837

2836-
transaction = ref_store_transaction_begin(new_refs, errbuf);
2838+
transaction = ref_store_transaction_begin(new_refs, 0, errbuf);
28372839
if (!transaction)
28382840
goto done;
28392841

refs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
234234
* struct strbuf err = STRBUF_INIT;
235235
* int ret = 0;
236236
*
237-
* transaction = ref_store_transaction_begin(refs, &err);
237+
* transaction = ref_store_transaction_begin(refs, 0, &err);
238238
* if (!transaction ||
239239
* ref_transaction_update(...) ||
240240
* ref_transaction_create(...) ||
@@ -584,6 +584,7 @@ enum action_on_err {
584584
* be freed by calling ref_transaction_free().
585585
*/
586586
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
587+
unsigned int flags,
587588
struct strbuf *err);
588589

589590
/*

0 commit comments

Comments
 (0)