reset: drop `USE_THE_REPOSITORY_VARIABLE`

In "reset.c" we still have references to `the_repository`, even though
the only entry point into the file already receives a repository as
parameter.

Update all uses of `the_repository` to instead use the passed-in repo
and drop `USE_THE_REPOSITORY_VARIABLE`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
next
Patrick Steinhardt 2026-07-01 13:35:29 +02:00 committed by Junio C Hamano
parent ca39c3511d
commit 5ce540bed3
1 changed files with 13 additions and 14 deletions

27
reset.c
View File

@ -1,5 +1,3 @@
#define USE_THE_REPOSITORY_VARIABLE

#include "git-compat-util.h"
#include "cache-tree.h"
#include "gettext.h"
@ -13,7 +11,8 @@
#include "unpack-trees.h"
#include "hook.h"

static int update_refs(const struct reset_head_opts *opts,
static int update_refs(struct repository *repo,
const struct reset_head_opts *opts,
const struct object_id *oid,
const struct object_id *head)
{
@ -42,19 +41,19 @@ static int update_refs(const struct reset_head_opts *opts,
prefix_len = msg.len;

if (update_orig_head) {
if (!repo_get_oid(the_repository, "ORIG_HEAD", &oid_old_orig))
if (!repo_get_oid(repo, "ORIG_HEAD", &oid_old_orig))
old_orig = &oid_old_orig;
if (head) {
if (!reflog_orig_head) {
strbuf_addstr(&msg, "updating ORIG_HEAD");
reflog_orig_head = msg.buf;
}
refs_update_ref(get_main_ref_store(the_repository),
refs_update_ref(get_main_ref_store(repo),
reflog_orig_head, "ORIG_HEAD",
orig_head ? orig_head : head,
old_orig, 0, UPDATE_REFS_MSG_ON_ERR);
} else if (old_orig)
refs_delete_ref(get_main_ref_store(the_repository),
refs_delete_ref(get_main_ref_store(repo),
NULL, "ORIG_HEAD", old_orig, 0);
}

@ -64,23 +63,23 @@ static int update_refs(const struct reset_head_opts *opts,
reflog_head = msg.buf;
}
if (!switch_to_branch)
ret = refs_update_ref(get_main_ref_store(the_repository),
ret = refs_update_ref(get_main_ref_store(repo),
reflog_head, "HEAD", oid, head,
detach_head ? REF_NO_DEREF : 0,
UPDATE_REFS_MSG_ON_ERR);
else {
ret = refs_update_ref(get_main_ref_store(the_repository),
ret = refs_update_ref(get_main_ref_store(repo),
reflog_branch ? reflog_branch : reflog_head,
switch_to_branch, oid, NULL, 0,
UPDATE_REFS_MSG_ON_ERR);
if (!ret)
ret = refs_update_symref(get_main_ref_store(the_repository),
ret = refs_update_symref(get_main_ref_store(repo),
"HEAD", switch_to_branch,
reflog_head);
}
if (!ret && run_hook)
run_hooks_l(the_repository, "post-checkout",
oid_to_hex(head ? head : null_oid(the_hash_algo)),
run_hooks_l(repo, "post-checkout",
oid_to_hex(head ? head : null_oid(repo->hash_algo)),
oid_to_hex(oid), "1", NULL);
strbuf_release(&msg);
return ret;
@ -126,7 +125,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)
oid = &head_oid;

if (refs_only)
return update_refs(opts, oid, head);
return update_refs(r, opts, oid, head);

action = reset_hard ? "reset" : "checkout";
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
@ -163,7 +162,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)
goto leave_reset_head;
}

tree = repo_parse_tree_indirect(the_repository, oid);
tree = repo_parse_tree_indirect(r, oid);
if (!tree) {
ret = error(_("unable to read tree (%s)"), oid_to_hex(oid));
goto leave_reset_head;
@ -177,7 +176,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts)
}

if (oid != &head_oid || update_orig_head || switch_to_branch)
ret = update_refs(opts, oid, head);
ret = update_refs(r, opts, oid, head);

leave_reset_head:
rollback_lock_file(&lock);