Skip to content

Commit 4beb7a3

Browse files
committed
Merge branch 'kn/ref-transaction-symref'
Updates to symbolic refs can now be made as a part of ref transaction. * 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 d8ab1d4 + 4865707 commit 4beb7a3

28 files changed

+385
-310
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
@@ -628,7 +628,7 @@ void create_branch(struct repository *r,
628628
if (!transaction ||
629629
ref_transaction_update(transaction, ref.buf,
630630
&oid, forcing ? NULL : null_oid(),
631-
0, msg, &err) ||
631+
NULL, NULL, 0, msg, &err) ||
632632
ref_transaction_commit(transaction, &err))
633633
die("%s", err.buf);
634634
ref_transaction_free(transaction);

builtin/branch.c

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

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

builtin/checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
10111011
describe_detached_head(_("HEAD is now at"), new_branch_info->commit);
10121012
}
10131013
} else if (new_branch_info->path) { /* Switch branches. */
1014-
if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, msg.buf) < 0)
1014+
if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", new_branch_info->path, msg.buf) < 0)
10151015
die(_("unable to update HEAD"));
10161016
if (!opts->quiet) {
10171017
if (old_branch_info->path && !strcmp(new_branch_info->path, old_branch_info->path)) {
@@ -1472,7 +1472,7 @@ static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
14721472
if (!opts->new_branch)
14731473
die(_("You are on a branch yet to be born"));
14741474
strbuf_addf(&branch_ref, "refs/heads/%s", opts->new_branch);
1475-
status = refs_create_symref(get_main_ref_store(the_repository),
1475+
status = refs_update_symref(get_main_ref_store(the_repository),
14761476
"HEAD", branch_ref.buf, "checkout -b");
14771477
strbuf_release(&branch_ref);
14781478
if (!opts->quiet)

builtin/clone.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static void update_remote_refs(const struct ref *refs,
653653
struct strbuf head_ref = STRBUF_INIT;
654654
strbuf_addstr(&head_ref, branch_top);
655655
strbuf_addstr(&head_ref, "HEAD");
656-
if (refs_create_symref(get_main_ref_store(the_repository), head_ref.buf,
656+
if (refs_update_symref(get_main_ref_store(the_repository), head_ref.buf,
657657
remote_head_points_at->peer_ref->name,
658658
msg) < 0)
659659
die(_("unable to update %s"), head_ref.buf);
@@ -667,7 +667,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
667667
const char *head;
668668
if (our && skip_prefix(our->name, "refs/heads/", &head)) {
669669
/* Local default branch link */
670-
if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL) < 0)
670+
if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", our->name, NULL) < 0)
671671
die(_("unable to update HEAD"));
672672
if (!option_bare) {
673673
refs_update_ref(get_main_ref_store(the_repository),
@@ -696,7 +696,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
696696
* Unborn head from remote; same as "our" case above except
697697
* that we have no ref to update.
698698
*/
699-
if (refs_create_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL) < 0)
699+
if (refs_update_symref(get_main_ref_store(the_repository), "HEAD", unborn, NULL) < 0)
700700
die(_("unable to update HEAD"));
701701
if (!option_bare)
702702
install_branch_config(0, head, remote_name, unborn);

builtin/fast-import.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ static int update_branch(struct branch *b)
16361636
&err);
16371637
if (!transaction ||
16381638
ref_transaction_update(transaction, b->name, &b->oid, &old_oid,
1639-
0, msg, &err) ||
1639+
NULL, NULL, 0, msg, &err) ||
16401640
ref_transaction_commit(transaction, &err)) {
16411641
ref_transaction_free(transaction);
16421642
error("%s", err.buf);
@@ -1678,7 +1678,8 @@ static void dump_tags(void)
16781678
strbuf_addf(&ref_name, "refs/tags/%s", t->name);
16791679

16801680
if (ref_transaction_update(transaction, ref_name.buf,
1681-
&t->oid, NULL, 0, msg, &err)) {
1681+
&t->oid, NULL, NULL, NULL,
1682+
0, msg, &err)) {
16821683
failure |= error("%s", err.buf);
16831684
goto cleanup;
16841685
}

builtin/fetch.c

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

673673
ret = ref_transaction_update(transaction, ref->name, &ref->new_oid,
674674
check_old ? &ref->old_oid : NULL,
675-
0, msg, &err);
675+
NULL, NULL, 0, msg, &err);
676676
if (ret) {
677677
ret = STORE_REF_ERROR_OTHER;
678678
goto out;

builtin/notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ static int merge(int argc, const char **argv, const char *prefix)
981981
die(_("a notes merge into %s is already in-progress at %s"),
982982
default_notes_ref(), wt->path);
983983
free_worktrees(worktrees);
984-
if (refs_create_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", default_notes_ref(), NULL))
984+
if (refs_update_symref(get_main_ref_store(the_repository), "NOTES_MERGE_REF", default_notes_ref(), NULL))
985985
die(_("failed to store link to current notes ref (%s)"),
986986
default_notes_ref());
987987
fprintf(stderr, _("Automatic notes merge failed. Fix conflicts in %s "

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/remote.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static int add(int argc, const char **argv, const char *prefix)
240240
strbuf_reset(&buf2);
241241
strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master);
242242

243-
if (refs_create_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add"))
243+
if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add"))
244244
return error(_("Could not setup master '%s'"), master);
245245
}
246246

@@ -845,7 +845,7 @@ static int mv(int argc, const char **argv, const char *prefix)
845845
strbuf_reset(&buf3);
846846
strbuf_addf(&buf3, "remote: renamed %s to %s",
847847
item->string, buf.buf);
848-
if (refs_create_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, buf3.buf))
848+
if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, buf3.buf))
849849
die(_("creating '%s' failed"), buf.buf);
850850
display_progress(progress, ++refs_renamed_nr);
851851
}
@@ -1423,7 +1423,7 @@ static int set_head(int argc, const char **argv, const char *prefix)
14231423
/* make sure it's valid */
14241424
if (!refs_ref_exists(get_main_ref_store(the_repository), buf2.buf))
14251425
result |= error(_("Not a valid ref: %s"), buf2.buf);
1426-
else if (refs_create_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head"))
1426+
else if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote set-head"))
14271427
result |= error(_("Could not setup %s"), buf.buf);
14281428
else if (opt_a)
14291429
printf("%s/HEAD set to %s\n", argv[0], head_name);

0 commit comments

Comments
 (0)