Skip to content

Commit 939d49e

Browse files
committed
Merge branch 'kn/ref-transaction-symref' into kn/update-ref-symref
* kn/ref-transaction-symref: refs: remove `create_symref` and associated dead code refs: rename `refs_create_symref()` to `refs_update_symref()` refs: use transaction in `refs_create_symref()` refs: add support for transactional symref updates refs: move `original_update_refname` to 'refs.c' refs: support symrefs in 'reference-transaction' hook files-backend: extract out `create_symref_lock()` refs: accept symref values in `ref_transaction_update()`
2 parents 786a3e4 + 4865707 commit 939d49e

22 files changed

+374
-280
lines changed

Documentation/githooks.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ reference-transaction
486486
This hook is invoked by any Git command that performs reference
487487
updates. It executes whenever a reference transaction is prepared,
488488
committed or aborted and may thus get called multiple times. The hook
489-
does not cover symbolic references (but that may change in the future).
489+
also supports symbolic reference updates.
490490

491491
The hook takes exactly one argument, which is the current state the
492492
given reference transaction is in:
@@ -503,16 +503,20 @@ given reference transaction is in:
503503
For each reference update that was added to the transaction, the hook
504504
receives on standard input a line of the format:
505505

506-
<old-oid> SP <new-oid> SP <ref-name> LF
506+
<old-value> SP <new-value> SP <ref-name> LF
507507

508-
where `<old-oid>` is the old object name passed into the reference
509-
transaction, `<new-oid>` is the new object name to be stored in the
508+
where `<old-value>` is the old object name passed into the reference
509+
transaction, `<new-value>` is the new object name to be stored in the
510510
ref and `<ref-name>` is the full name of the ref. When force updating
511511
the reference regardless of its current value or when the reference is
512-
to be created anew, `<old-oid>` is the all-zeroes object name. To
512+
to be created anew, `<old-value>` is the all-zeroes object name. To
513513
distinguish these cases, you can inspect the current value of
514514
`<ref-name>` via `git rev-parse`.
515515

516+
For symbolic reference updates the `<old_value>` and `<new-value>`
517+
fields could denote references instead of objects. A reference will be
518+
denoted with a 'ref:' prefix, like `ref:<ref-target>`.
519+
516520
The exit status of the hook is ignored for any state except for the
517521
"prepared" state. In the "prepared" state, a non-zero exit status will
518522
cause the transaction to be aborted. The hook will not be called with

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
if (!transaction ||
628628
ref_transaction_update(transaction, ref.buf,
629629
&oid, forcing ? NULL : null_oid(),
630-
0, msg, &err) ||
630+
NULL, NULL, 0, msg, &err) ||
631631
ref_transaction_commit(transaction, &err))
632632
die("%s", err.buf);
633633
ref_transaction_free(transaction);

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int replace_each_worktree_head_symref(struct worktree **worktrees,
555555
continue;
556556

557557
refs = get_worktree_ref_store(worktrees[i]);
558-
if (refs_create_symref(refs, "HEAD", newref, logmsg))
558+
if (refs_update_symref(refs, "HEAD", newref, logmsg))
559559
ret = error(_("HEAD of working tree %s is not updated"),
560560
worktrees[i]->path);
561561
}

builtin/fast-import.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ static int update_branch(struct branch *b)
16341634
transaction = ref_transaction_begin(&err);
16351635
if (!transaction ||
16361636
ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
1637-
0, msg, &err) ||
1637+
NULL, NULL, 0, msg, &err) ||
16381638
ref_transaction_commit(transaction, &err)) {
16391639
ref_transaction_free(transaction);
16401640
error("%s", err.buf);
@@ -1675,7 +1675,8 @@ static void dump_tags(void)
16751675
strbuf_addf(&ref_name, "refs/tags/%s", t->name);
16761676

16771677
if (ref_transaction_update(transaction, ref_name.buf,
1678-
&t->oid, NULL, 0, msg, &err)) {
1678+
&t->oid, NULL, NULL, NULL,
1679+
0, msg, &err)) {
16791680
failure |= error("%s", err.buf);
16801681
goto cleanup;
16811682
}

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static int s_update_ref(const char *action,
668668

669669
ret = ref_transaction_update(transaction, ref->name, &ref->new_oid,
670670
check_old ? &ref->old_oid : NULL,
671-
0, msg, &err);
671+
NULL, NULL, 0, msg, &err);
672672
if (ret) {
673673
ret = STORE_REF_ERROR_OTHER;
674674
goto out;

builtin/receive-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15951595
if (ref_transaction_update(transaction,
15961596
namespaced_name,
15971597
new_oid, old_oid,
1598+
NULL, NULL,
15981599
0, "push",
15991600
&err)) {
16001601
rp_error("%s", err.buf);

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
transaction = ref_transaction_begin(&err);
202202
if (!transaction ||
203203
ref_transaction_update(transaction, ref.buf, repl, &prev,
204-
0, NULL, &err) ||
204+
NULL, NULL, 0, NULL, &err) ||
205205
ref_transaction_commit(transaction, &err))
206206
res = error("%s", err.buf);
207207

builtin/tag.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
660660
transaction = ref_transaction_begin(&err);
661661
if (!transaction ||
662662
ref_transaction_update(transaction, ref.buf, &object, &prev,
663+
NULL, NULL,
663664
create_reflog ? REF_FORCE_CREATE_REFLOG : 0,
664665
reflog_msg.buf, &err) ||
665666
ref_transaction_commit(transaction, &err)) {

builtin/update-ref.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ static void parse_cmd_update(struct ref_transaction *transaction,
204204

205205
if (ref_transaction_update(transaction, refname,
206206
&new_oid, have_old ? &old_oid : NULL,
207+
NULL, NULL,
207208
update_flags | create_reflog_flag,
208209
msg, &err))
209210
die("%s", err.buf);

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ static int add_worktree(const char *path, const char *refname,
517517
ret = refs_update_ref(wt_refs, NULL, "HEAD", &commit->object.oid,
518518
NULL, 0, UPDATE_REFS_MSG_ON_ERR);
519519
else
520-
ret = refs_create_symref(wt_refs, "HEAD", symref.buf, NULL);
520+
ret = refs_update_symref(wt_refs, "HEAD", symref.buf, NULL);
521521
if (ret)
522522
goto done;
523523

0 commit comments

Comments
 (0)