From patchwork Thu Jun 6 17:26:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 13688838 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB8902E64C for ; Thu, 6 Jun 2024 17:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694809; cv=none; b=VK8aVFy97ST5ek+uEGJBg+vBuQs28c4KD9xq0DbRngA5ip1yL23JPSoW/jqcROX5jxrs4oJVL4FBx41VfWQWLLhSIkDrrDKP9DgkhUei6A1AcETrGb10IJv2ginCHtH4D+MneZGiGrRAtUxCNvAGyz9D/Is6EXXom7cxCS5rPX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694809; c=relaxed/simple; bh=Gef4D70OasNRbzT7ZZiVtIBBgEe+A6GoSGoo9n7TTiM=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=u8y21J/3pfGeLoU9f21CrqnpJ6gs0w90b5sa/IZRShrVWwSLap1vpJciJe20DlQDJcHIXRV2FnnIeh0K7qHEP4JUVovTUVgBbcNgAhQL31PA8QKFwv0etqdHt2h5ntc3+LDigHjVYs41wTkh8Pl7JFsrTpkCLm1zk1cy6SEhatQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KR6M0SMB; arc=none smtp.client-ip=209.85.167.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KR6M0SMB" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-52b8e0e98adso1852223e87.0 for ; Thu, 06 Jun 2024 10:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717694804; x=1718299604; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=FlrXk1sTMcRyGVjx6emJlpfVoTURHvWmr3aq/X+myZg=; b=KR6M0SMB18kRlPnluFPkeqyScOpOWxPM5q9cr0W1CVJO6drUdahwQ8GNzk5UUE3ukM AcmHBy5fL3+YuFrIbZv9FDyP6BQAp7aqwwknjR3CiofyObWJS6OIOMjY3Zc+gQ006lyd X6sZLmJ7dyYaZkrjb2jBPTRAdWeI3XWuyx6TTzagMQ9rU7bzRkjZmH88G/LFf+spePLU xqOe94Maj7hLQS/4xetqM3JA42w4miGtRvJs4QxkneCUMEMlcxYlSOS0fW4TTN1YkCMn pbRB6ueBo1JAU3oJHj2k0R0q2BxV0Z/1e/r6JRRxISZFSsHH9vy+oTk3MwpCs0bJBj1p A8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717694804; x=1718299604; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FlrXk1sTMcRyGVjx6emJlpfVoTURHvWmr3aq/X+myZg=; b=d9koUy9OorvyRDngTtgSqFVbVhYOXUOMDFd+GsJY37BN4wr6mN+YX8swTDs2fFXjM6 sU1OZ4UIuOICHnXFwE1eNpAjkBju9usjzf3yNQnRL2FOlu5uTXvSF4JRQA0dfZ/URoZS eU4/TgxjPmqeNoIr2J14pzUo/NYG/o22TBvLiUQ+IzOSosA7Apth0CFeOWCOGCrPiom8 AGrQSZdW9D/nn1+svehnrhexQAPpkYFiV9kB5MbtAg2OVfXBoiwWEcACrmYuvqreV87B 8b73ZOT6KEqMzBrnhdhlmTSE8da8XUFSgPcrR62t0cDtP+6gPBCncAxQZ5opLTXTAAxY dlQQ== X-Gm-Message-State: AOJu0YydPI2CNKoVxB34MvsHR8OkJpqC+pvqxeUOCDkX2YxoRfFqvhzs I6iOACJxeaxyNOwMwui/95rFxFWNxi96cb9yugNUoQ+l1wu7UAI3SafW4A== X-Google-Smtp-Source: AGHT+IEqRRztEnXBqtSOPTPVRVOvXBs7L+NQ5TfRH2au9dprreBDmCeg2Uiq129Is1rbuF4cwRlL5A== X-Received: by 2002:a19:6457:0:b0:52b:8255:71cf with SMTP id 2adb3069b0e04-52bb9fcc59emr176325e87.47.1717694804191; Thu, 06 Jun 2024 10:26:44 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4215c364bcdsm28046275e9.19.2024.06.06.10.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 10:26:43 -0700 (PDT) Message-Id: <011c10f488610b0a795a843bff66723477783761.1717694801.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 06 Jun 2024 17:26:37 +0000 Subject: [PATCH 1/4] refs: add referent parameter to refs_resolve_ref_unsafe Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "Phillip Wood [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, "Jeff King [ ]" , "Patrick Steinhardt [ ]" , " =?utf-8?q?Jean-No=C3=ABl?= Avila [ ]" , John Cai , John Cai From: John Cai From: John Cai refs_resolve_ref_unsafe retrieves the referent, the unresolved value of a reference. Add a parameter to allow refs_resolve_ref_unsafe to pass up the value of referent to the caller so it can save this value in ref iterators for more efficient access. Signed-off-by: John Cai --- add-interactive.c | 6 +++--- blame.c | 4 ++-- builtin/bisect.c | 2 +- builtin/blame.c | 2 +- builtin/branch.c | 2 +- builtin/fsck.c | 2 +- builtin/log.c | 1 + builtin/rebase.c | 6 +++--- builtin/receive-pack.c | 2 +- builtin/remote.c | 2 +- builtin/stash.c | 2 +- builtin/submodule--helper.c | 4 ++-- builtin/symbolic-ref.c | 2 +- config.c | 2 +- http-backend.c | 1 + log-tree.c | 2 +- ls-refs.c | 3 ++- refs.c | 20 ++++++++++++-------- refs.h | 1 + refs/files-backend.c | 16 ++++++++-------- refs/reftable-backend.c | 6 +++--- remote.c | 6 +++--- revision.c | 2 +- sequencer.c | 9 +++++---- t/helper/test-ref-store.c | 2 +- transport-helper.c | 1 + transport.c | 2 +- upload-pack.c | 2 +- worktree.c | 4 +++- 29 files changed, 64 insertions(+), 52 deletions(-) diff --git a/add-interactive.c b/add-interactive.c index b5d6cd689a1..041d30cf2b3 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -533,7 +533,7 @@ static int get_modified_files(struct repository *r, { struct object_id head_oid; int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", RESOLVE_REF_READING, + "HEAD", NULL, RESOLVE_REF_READING, &head_oid, NULL); struct collection_status s = { 0 }; int i; @@ -763,7 +763,7 @@ static int run_revert(struct add_i_state *s, const struct pathspec *ps, struct object_id oid; int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", RESOLVE_REF_READING, + "HEAD", NULL, RESOLVE_REF_READING, &oid, NULL); struct lock_file index_lock; @@ -994,7 +994,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps, struct object_id oid; int is_initial = !refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", RESOLVE_REF_READING, + "HEAD", NULL, RESOLVE_REF_READING, &oid, NULL); if (get_modified_files(s->r, INDEX_ONLY, files, ps, NULL, NULL) < 0) diff --git a/blame.c b/blame.c index 33586b97772..9e5d0cd788f 100644 --- a/blame.c +++ b/blame.c @@ -2700,7 +2700,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs, return NULL; /* Do we have HEAD? */ - if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, &head_oid, NULL)) + if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, RESOLVE_REF_READING, &head_oid, NULL)) return NULL; head_commit = lookup_commit_reference_gently(revs->repo, &head_oid, 1); @@ -2803,7 +2803,7 @@ void setup_scoreboard(struct blame_scoreboard *sb, if (sb->final) { parent_oid = &sb->final->object.oid; } else { - if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, &head_oid, NULL)) + if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, RESOLVE_REF_READING, &head_oid, NULL)) die("no such ref: HEAD"); parent_oid = &head_oid; } diff --git a/builtin/bisect.c b/builtin/bisect.c index a58432b9d90..76ce5f0e0df 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -783,7 +783,7 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, int argc, * Verify HEAD */ head = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, &head_oid, &flags); + "HEAD", NULL, 0, &head_oid, &flags); if (!head) if (repo_get_oid(the_repository, "HEAD", &head_oid)) return error(_("bad HEAD - I need a HEAD")); diff --git a/builtin/blame.c b/builtin/blame.c index fadba1a5304..1504a2ed99d 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1092,7 +1092,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) struct commit *head_commit; struct object_id head_oid; - if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, + if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, RESOLVE_REF_READING, &head_oid, NULL) || !(head_commit = lookup_commit_reference_gently(revs.repo, &head_oid, 1))) diff --git a/builtin/branch.c b/builtin/branch.c index 48cac74f97f..dd871d44f2d 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -503,7 +503,7 @@ static void print_current_branch_name(void) { int flags; const char *refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, NULL, &flags); + "HEAD", NULL, 0, NULL, &flags); const char *shortname; if (!refname) die(_("could not resolve HEAD")); diff --git a/builtin/fsck.c b/builtin/fsck.c index d13a226c2ed..2c0ac6653ca 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -716,7 +716,7 @@ static int fsck_head_link(const char *head_ref_name, fprintf_ln(stderr, _("Checking %s link"), head_ref_name); *head_points_at = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - head_ref_name, 0, head_oid, + head_ref_name, NULL, 0, head_oid, NULL); if (!*head_points_at) { errors_found |= ERROR_REFS; diff --git a/builtin/log.c b/builtin/log.c index c8ce0c0d88a..337f367e974 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -2228,6 +2228,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) const char *ref, *v; ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", + NULL, RESOLVE_REF_READING, NULL, NULL); if (ref && skip_prefix(ref, "refs/heads/", &v)) diff --git a/builtin/rebase.c b/builtin/rebase.c index 0466d9414af..fd14b1e4505 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1641,7 +1641,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } else if (argc == 0) { /* Do not need to switch branches, we are already on it. */ options.head_name = - xstrdup_or_null(refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, NULL, + xstrdup_or_null(refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, 0, NULL, &flags)); if (!options.head_name) die(_("No such ref: %s"), "HEAD"); @@ -1736,7 +1736,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (!(options.flags & REBASE_NO_QUIET)) ; /* be quiet */ else if (!strcmp(branch_name, "HEAD") && - refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, NULL, &flag)) + refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, 0, NULL, &flag)) puts(_("HEAD is up to date.")); else printf(_("Current branch %s is up to date.\n"), @@ -1746,7 +1746,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } else if (!(options.flags & REBASE_NO_QUIET)) ; /* be quiet */ else if (!strcmp(branch_name, "HEAD") && - refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", 0, NULL, &flag)) + refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, 0, NULL, &flag)) puts(_("HEAD is up to date, rebase forced.")); else printf(_("Current branch %s is up to date, rebase " diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index be8969a84a8..d9e2c4bbe39 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1695,7 +1695,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list) strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name); dst_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - buf.buf, 0, NULL, &flag); + buf.buf, NULL, 0, NULL, &flag); check_aliased_update_internal(cmd, list, dst_name, flag); strbuf_release(&buf); } diff --git a/builtin/remote.c b/builtin/remote.c index 447ef1d3c92..039d1d6c55a 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -599,7 +599,7 @@ static int read_remote_branches(const char *refname, if (starts_with(refname, buf.buf)) { item = string_list_append(rename->remote_branches, refname); symref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - refname, RESOLVE_REF_READING, + refname, NULL, RESOLVE_REF_READING, NULL, &flag); if (symref && (flag & REF_ISSYMREF)) { item->util = xstrdup(symref); diff --git a/builtin/stash.c b/builtin/stash.c index 7859bc0866a..b733492cead 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1386,7 +1386,7 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b } branch_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, NULL, &flags); + "HEAD", NULL, 0, NULL, &flags); if (flags & REF_ISSYMREF) skip_prefix(branch_ref, "refs/heads/", &branch_name); head_short_sha1 = repo_find_unique_abbrev(the_repository, diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 897f19868e8..e3e1f08a58c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -44,7 +44,7 @@ static int repo_get_default_remote(struct repository *repo, char **default_remot char *dest = NULL; struct strbuf sb = STRBUF_INIT; struct ref_store *store = get_main_ref_store(repo); - const char *refname = refs_resolve_ref_unsafe(store, "HEAD", 0, NULL, + const char *refname = refs_resolve_ref_unsafe(store, "HEAD", NULL, 0, NULL, NULL); if (!refname) @@ -2459,7 +2459,7 @@ static int remote_submodule_branch(const char *path, const char **branch) if (!strcmp(*branch, ".")) { const char *refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, NULL, + "HEAD", NULL, 0, NULL, NULL); if (!refname) diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index 81abdd170fe..96fa311b075 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -19,7 +19,7 @@ static int check_symref(const char *HEAD, int quiet, int shorten, int recurse, i resolve_flags = (recurse ? 0 : RESOLVE_REF_NO_RECURSE); refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - HEAD, resolve_flags, NULL, &flag); + HEAD, NULL, resolve_flags, NULL, &flag); if (!refname) die("No such ref: %s", HEAD); diff --git a/config.c b/config.c index 14461312b33..3cc1dab0fb9 100644 --- a/config.c +++ b/config.c @@ -304,7 +304,7 @@ static int include_by_branch(const char *cond, size_t cond_len) struct strbuf pattern = STRBUF_INIT; const char *refname = !the_repository->gitdir ? NULL : refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, NULL, &flags); + "HEAD", NULL, 0, NULL, &flags); const char *shortname; if (!refname || !(flags & REF_ISSYMREF) || diff --git a/http-backend.c b/http-backend.c index 5b65287ac90..20c3ff8fa95 100644 --- a/http-backend.c +++ b/http-backend.c @@ -574,6 +574,7 @@ static int show_head_ref(const char *refname, const struct object_id *oid, if (flag & REF_ISSYMREF) { const char *target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname, + NULL, RESOLVE_REF_READING, NULL, NULL); diff --git a/log-tree.c b/log-tree.c index 41416de4e3f..da06c6e982f 100644 --- a/log-tree.c +++ b/log-tree.c @@ -280,7 +280,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d /* Now resolve and find the matching current branch */ branch_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", 0, NULL, &rru_flags); + "HEAD", NULL, 0, NULL, &rru_flags); if (!branch_name || !(rru_flags & REF_ISSYMREF)) return NULL; diff --git a/ls-refs.c b/ls-refs.c index 398afe4ce39..3d047bbc64f 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -97,6 +97,7 @@ static int send_ref(const char *refname, const struct object_id *oid, struct object_id unused; const char *symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname, + NULL, 0, &unused, &flag); @@ -128,7 +129,7 @@ static void send_possibly_unborn_head(struct ls_refs_data *data) int oid_is_null; strbuf_addf(&namespaced, "%sHEAD", get_git_namespace()); - if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), namespaced.buf, 0, &oid, &flag)) + if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), namespaced.buf, NULL, 0, &oid, &flag)) return; /* bad ref */ oid_is_null = is_null_oid(&oid); if (!oid_is_null || diff --git a/refs.c b/refs.c index 31032588e0e..2c592a9ae29 100644 --- a/refs.c +++ b/refs.c @@ -378,7 +378,7 @@ char *refs_resolve_refdup(struct ref_store *refs, { const char *result; - result = refs_resolve_ref_unsafe(refs, refname, resolve_flags, + result = refs_resolve_ref_unsafe(refs, refname, NULL, resolve_flags, oid, flags); return xstrdup_or_null(result); } @@ -394,7 +394,7 @@ struct for_each_ref_filter { int refs_read_ref_full(struct ref_store *refs, const char *refname, int resolve_flags, struct object_id *oid, int *flags) { - if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, + if (refs_resolve_ref_unsafe(refs, refname, NULL, resolve_flags, oid, flags)) return 0; return -1; @@ -407,7 +407,7 @@ int refs_read_ref(struct ref_store *refs, const char *refname, struct object_id int refs_ref_exists(struct ref_store *refs, const char *refname) { - return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING, + return !!refs_resolve_ref_unsafe(refs, refname, NULL, RESOLVE_REF_READING, NULL, NULL); } @@ -442,7 +442,7 @@ static int warn_if_dangling_symref(const char *refname, if (!(flags & REF_ISSYMREF)) return 0; - resolves_to = refs_resolve_ref_unsafe(d->refs, refname, 0, NULL, NULL); + resolves_to = refs_resolve_ref_unsafe(d->refs, refname, NULL, 0, NULL, NULL); if (!resolves_to || (d->refname ? strcmp(resolves_to, d->refname) @@ -716,7 +716,7 @@ int expand_ref(struct repository *repo, const char *str, int len, this_result = refs_found ? &oid_from_ref : oid; strbuf_reset(&fullref); strbuf_addf(&fullref, *p, len, str); - r = refs_resolve_ref_unsafe(refs, fullref.buf, + r = refs_resolve_ref_unsafe(refs, fullref.buf, NULL, RESOLVE_REF_READING, this_result, &flag); if (r) { @@ -750,7 +750,7 @@ int repo_dwim_log(struct repository *r, const char *str, int len, strbuf_reset(&path); strbuf_addf(&path, *p, len, str); - ref = refs_resolve_ref_unsafe(refs, path.buf, + ref = refs_resolve_ref_unsafe(refs, path.buf, NULL, RESOLVE_REF_READING, oid ? &hash : NULL, NULL); if (!ref) @@ -1522,7 +1522,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) struct object_id oid; int flag; - if (refs_resolve_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING, + if (refs_resolve_ref_unsafe(refs, "HEAD", NULL, RESOLVE_REF_READING, &oid, &flag)) return fn("HEAD", &oid, flag, cb_data); @@ -1761,6 +1761,7 @@ int refs_read_symbolic_ref(struct ref_store *ref_store, const char *refname, const char *refs_resolve_ref_unsafe(struct ref_store *refs, const char *refname, + const char *referent, int resolve_flags, struct object_id *oid, int *flags) @@ -1822,6 +1823,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs, } *flags |= read_flags; + if (referent && (read_flags & REF_ISSYMREF) && + sb_refname.len > 0) + referent = sb_refname.buf; if (!(read_flags & REF_ISSYMREF)) { if (*flags & REF_BAD_NAME) { @@ -1865,7 +1869,7 @@ int repo_resolve_gitlink_ref(struct repository *r, if (!refs) return -1; - if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) || + if (!refs_resolve_ref_unsafe(refs, refname, NULL, 0, oid, &flags) || is_null_oid(oid)) return -1; return 0; diff --git a/refs.h b/refs.h index fe7f0db35e6..ea4a3217658 100644 --- a/refs.h +++ b/refs.h @@ -68,6 +68,7 @@ const char *ref_storage_format_to_name(unsigned int ref_storage_format); const char *refs_resolve_ref_unsafe(struct ref_store *refs, const char *refname, + const char *referent, int resolve_flags, struct object_id *oid, int *flags); diff --git a/refs/files-backend.c b/refs/files-backend.c index 324c59b096c..bf2ffe062ea 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -244,7 +244,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs, struct object_id oid; int flag; - if (!refs_resolve_ref_unsafe(&refs->base, refname, RESOLVE_REF_READING, + if (!refs_resolve_ref_unsafe(&refs->base, refname, NULL, RESOLVE_REF_READING, &oid, &flag)) { oidclr(&oid); flag |= REF_ISBROKEN; @@ -1118,7 +1118,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs, goto error_return; } - if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0, + if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, NULL, 0, &lock->old_oid, NULL)) oidclr(&lock->old_oid); goto out; @@ -1455,7 +1455,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, goto out; } - if (!refs_resolve_ref_unsafe(&refs->base, oldrefname, + if (!refs_resolve_ref_unsafe(&refs->base, oldrefname, NULL, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, &orig_oid, &flag)) { ret = error("refname %s not found", oldrefname); @@ -1501,7 +1501,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store, * the safety anyway; we want to delete the reference whatever * its current value. */ - if (!copy && refs_resolve_ref_unsafe(&refs->base, newrefname, + if (!copy && refs_resolve_ref_unsafe(&refs->base, newrefname, NULL, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, NULL, NULL) && refs_delete_ref(&refs->base, NULL, newrefname, @@ -1875,7 +1875,7 @@ static int commit_ref_update(struct files_ref_store *refs, int head_flag; const char *head_ref; - head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD", + head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD", NULL, RESOLVE_REF_READING, NULL, &head_flag); if (head_ref && (head_flag & REF_ISSYMREF) && @@ -2464,7 +2464,7 @@ static int lock_ref_for_update(struct files_ref_store *refs, * to record and possibly check old_oid: */ if (!refs_resolve_ref_unsafe(&refs->base, - referent.buf, 0, + referent.buf, NULL, 0, &lock->old_oid, NULL)) { if (update->flags & REF_HAVE_OLD) { strbuf_addf(err, "cannot lock ref '%s': " @@ -2823,7 +2823,7 @@ static int parse_and_write_reflog(struct files_ref_store *refs, * We want to get the resolved OID for the target, to ensure * that the correct value is added to the reflog. */ - if (!refs_resolve_ref_unsafe(&refs->base, update->new_target, + if (!refs_resolve_ref_unsafe(&refs->base, update->new_target, NULL, RESOLVE_REF_READING, &update->new_oid, NULL)) { /* @@ -3229,7 +3229,7 @@ static int files_reflog_expire(struct ref_store *ref_store, int type; const char *ref; - ref = refs_resolve_ref_unsafe(&refs->base, refname, + ref = refs_resolve_ref_unsafe(&refs->base, refname, NULL, RESOLVE_REF_NO_RECURSE, NULL, &type); update = !!(ref && !(type & REF_ISSYMREF)); diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 438b5c478b4..9e03582e7da 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -438,7 +438,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator) oidread(&iter->oid, iter->ref.value.val2.value); break; case REFTABLE_REF_SYMREF: - if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname, + if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname, NULL, RESOLVE_REF_READING, &iter->oid, &flags)) oidclr(&iter->oid); break; @@ -926,7 +926,7 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store, * so it is safe to call `refs_resolve_ref_unsafe()` * here without causing races. */ - const char *resolved = refs_resolve_ref_unsafe(&refs->base, u->refname, 0, + const char *resolved = refs_resolve_ref_unsafe(&refs->base, u->refname, NULL, 0, ¤t_oid, NULL); if (u->flags & REF_NO_DEREF) { @@ -1148,7 +1148,7 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data int create_reflog = 1; if (u->new_target) { - if (!refs_resolve_ref_unsafe(&arg->refs->base, u->new_target, + if (!refs_resolve_ref_unsafe(&arg->refs->base, u->new_target, NULL, RESOLVE_REF_READING, &u->new_oid, NULL)) { /* * TODO: currently we skip creating reflogs for dangling diff --git a/remote.c b/remote.c index 5898da2bb5c..c9718ee0ca1 100644 --- a/remote.c +++ b/remote.c @@ -520,7 +520,7 @@ static void read_config(struct repository *repo, int early) repo->remote_state->current_branch = NULL; if (startup_info->have_repository && !early) { const char *head_ref = refs_resolve_ref_unsafe( - get_main_ref_store(repo), "HEAD", 0, NULL, &flag); + get_main_ref_store(repo), "HEAD", NULL, 0, NULL, &flag); if (head_ref && (flag & REF_ISSYMREF) && skip_prefix(head_ref, "refs/heads/", &head_ref)) { repo->remote_state->current_branch = make_branch( @@ -1201,7 +1201,7 @@ static char *guess_ref(const char *name, struct ref *peer) struct strbuf buf = STRBUF_INIT; const char *r = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - peer->name, + peer->name, NULL, RESOLVE_REF_READING, NULL, NULL); if (!r) @@ -1321,7 +1321,7 @@ static int match_explicit(struct ref *src, struct ref *dst, int flag; dst_value = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - matched_src->name, + matched_src->name, NULL, RESOLVE_REF_READING, NULL, &flag); if (!dst_value || diff --git a/revision.c b/revision.c index 7ddf0f151a3..6aca4f42303 100644 --- a/revision.c +++ b/revision.c @@ -2920,7 +2920,7 @@ static void NORETURN diagnose_missing_default(const char *def) const char *refname; refname = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - def, 0, NULL, &flags); + def, NULL, 0, NULL, &flags); if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN)) die(_("your current branch appears to be broken")); diff --git a/sequencer.c b/sequencer.c index aa2a2398357..cf7a2a9a112 100644 --- a/sequencer.c +++ b/sequencer.c @@ -839,10 +839,10 @@ static int is_index_unchanged(struct repository *r) struct index_state *istate = r->index; const char *head_name; - if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", RESOLVE_REF_READING, &head_oid, NULL)) { + if (!refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", NULL, RESOLVE_REF_READING, &head_oid, NULL)) { /* Check to see if this is an unborn branch */ head_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - "HEAD", + "HEAD", NULL, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, &head_oid, NULL); if (!head_name || @@ -1480,7 +1480,7 @@ void print_commit_summary(struct repository *r, diff_setup_done(&rev.diffopt); refs = get_main_ref_store(r); - head = refs_resolve_ref_unsafe(refs, "HEAD", 0, NULL, NULL); + head = refs_resolve_ref_unsafe(refs, "HEAD", NULL, 0, NULL, NULL); if (!head) die(_("unable to resolve HEAD after creating commit")); if (!strcmp(head, "HEAD")) @@ -4715,7 +4715,7 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname, if (!refs_ref_exists(get_main_ref_store(r), refname)) return 0; - if (!refs_resolve_ref_unsafe(get_main_ref_store(r), refname, + if (!refs_resolve_ref_unsafe(get_main_ref_store(r), refname, NULL, RESOLVE_REF_READING, &stash_oid, &flag)) return -1; if (flag & REF_ISSYMREF) @@ -6213,6 +6213,7 @@ static int add_decorations_to_list(const struct commit *commit, const struct name_decoration *decoration = get_name_decoration(&commit->object); const char *head_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), "HEAD", + NULL, RESOLVE_REF_READING, NULL, NULL); diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index c9efd74c2b5..ef1d6acbfae 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -184,7 +184,7 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv) int flags; const char *ref; - ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags, + ref = refs_resolve_ref_unsafe(refs, refname, NULL, resolve_flags, &oid, &flags); printf("%s %s 0x%x\n", oid_to_hex(&oid), ref ? ref : "(null)", flags); return ref ? 0 : 1; diff --git a/transport-helper.c b/transport-helper.c index 780fcaf5292..27d85748b60 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -1110,6 +1110,7 @@ static int push_refs_with_export(struct transport *transport, /* Follow symbolic refs (mainly for HEAD). */ name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), ref->peer_ref->name, + NULL, RESOLVE_REF_READING, &oid, &flag); diff --git a/transport.c b/transport.c index 0ad04b77fd2..8818ba75e7a 100644 --- a/transport.c +++ b/transport.c @@ -101,7 +101,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs, localname = ref->peer_ref->name; remotename = ref->name; tmp = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - localname, RESOLVE_REF_READING, + localname, NULL, RESOLVE_REF_READING, NULL, &flag); if (tmp && flag & REF_ISSYMREF && starts_with(tmp, "refs/heads/")) diff --git a/upload-pack.c b/upload-pack.c index bbfb04c8bd8..4fddc081237 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1291,7 +1291,7 @@ static int find_symref(const char *refname, if ((flag & REF_ISSYMREF) == 0) return 0; symref_target = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), - refname, 0, NULL, &flag); + refname, NULL, 0, NULL, &flag); if (!symref_target || (flag & REF_ISSYMREF) == 0) die("'%s' is a symref but it is not?", refname); item = string_list_append(cb_data, strip_namespace(refname)); diff --git a/worktree.c b/worktree.c index 12eadacc618..ed89bab481d 100644 --- a/worktree.c +++ b/worktree.c @@ -42,6 +42,7 @@ static void add_head_info(struct worktree *wt) target = refs_resolve_ref_unsafe(get_worktree_ref_store(wt), "HEAD", + NULL, 0, &wt->head_oid, &flags); if (!target) @@ -448,7 +449,7 @@ int is_shared_symref(const struct worktree *wt, const char *symref, } refs = get_worktree_ref_store(wt); - symref_target = refs_resolve_ref_unsafe(refs, symref, 0, + symref_target = refs_resolve_ref_unsafe(refs, symref, NULL, 0, NULL, &flags); if ((flags & REF_ISSYMREF) && symref_target && !strcmp(symref_target, target)) @@ -549,6 +550,7 @@ int other_head_refs(each_ref_fn fn, void *cb_data) strbuf_worktree_ref(wt, &refname, "HEAD"); if (refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname.buf, + NULL, RESOLVE_REF_READING, &oid, &flag)) ret = fn(refname.buf, &oid, flag, cb_data); From patchwork Thu Jun 6 17:26:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 13688837 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14BB7198E87 for ; Thu, 6 Jun 2024 17:26:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694808; cv=none; b=OIFonos32VCdX467zLuxLMIv38czfZub1iXOR/o0XQWXtoiMZiiCc8wqY55GH+z1L8nU36ezRPydnOGPh7mSU6bzSe7fTxADHRjzcmA7H7RqanwgjIgvWAHlDmDXWS/aN/jSwhtZAytB2ingEf1nQRAO3AdPy/4bznBWpCwJANQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694808; c=relaxed/simple; bh=AOoGtFAeUiz7d3NyHI62uCutnIWQjWcOaN9tF+FjFF0=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=i/4TFvLjf2SdNZfkOzIw9FdisLYDwdeZqdvWAjghrYUafumPuTF+mi3DSK+lw+j+EurjTa3AtgiTkM+sgCu7egKdfhtiCUiUIDjlievEYqCW9Ysm/1vK/AI6joA/VuV+x4P3HVz05c0byJPecxK0yn4a3FFprUWPdCJqM2xHU8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=msvm1BsU; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="msvm1BsU" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4215b0c4b7dso12931595e9.0 for ; Thu, 06 Jun 2024 10:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717694805; x=1718299605; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Oi3ZC775ldC9fn9/+wwWTLI/lCYWwfYs7bCATeo1f6c=; b=msvm1BsUQWx3hk3jAmrOyRbxPNcdnqW6vsHbvbKeIvN0OIRqpVxCp0DxfjEcVMLgaY dQznsPF2GVdofP/i1eYN9t4rHr/+wIwnKI+MxGpAIY0h9yZIuIvOaDnw6GfEJ+BXzlJr +Bl6p3SWj83foTZ/Hjzf4F+hTc6MAkyU2PSSBaragF4vOo9HPMuD6KcicZ/ejCRXUYIb QIZz0TOQ8yxsisEM94dP3UETXJGcZXWmNAP4LFAy/fSVP6poGgp7czkYHUh3jMaYWKJn +ETlGdtC8sr3Ogg2D7lKJ2ab1wPwmGJPsdHY3ShDAW0bTaTYD9E+hK+fUnXsWWc03Ci3 amAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717694805; x=1718299605; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oi3ZC775ldC9fn9/+wwWTLI/lCYWwfYs7bCATeo1f6c=; b=Ssqv0KSYHY4HFKqKt8By5Xa+JsyMjSkfGIg4bjy+grZx162ay+SSyhBesec1WQqHSb hGj02kQSY35G/OjcZHmQgcaBBfSruKZw1VE10CSQOzAH/5QM6SMEc8yossRk3UftTUDI P9uBETAc8jLJMhR7W+t1mKPhWokfOQ3h2RLuhR38J5qe7DhzHBiNA5IR24cA8ALEnGb/ AYsWZC3L0APAk0nC9/jaoULfyaJD1kBltO9y2XZYmhIdWvXTlYxuSucLpPeG67N/76MU 2i1TVLhMK3Vy9ZdvQrLMuLmTkogdADnPaK95O+JGr/mvxFOT8Q44ZDKIlEReIqlAafw9 XuIg== X-Gm-Message-State: AOJu0YwYHFBq9KoLWjtVtyZBHVuLXhlIZeZ7ZT4XgLGkgP6+xO3raEaN xP+MPwWg7B0hNlESSSNUt8vwiTz+mkblexyXpKrAZR//lHg9WnqP7gRYbA== X-Google-Smtp-Source: AGHT+IEvHWyWz0FCkXyHKszFiO5oHMXO0uSZOx2vLChv5Xn5p1/yxvAwkPEkyUslBvDgElbJP4KWVA== X-Received: by 2002:a05:600c:3aca:b0:41b:f788:8ca6 with SMTP id 5b1f17b1804b1-421649ea031mr2994755e9.8.1717694805074; Thu, 06 Jun 2024 10:26:45 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4215c2a7799sm28716805e9.27.2024.06.06.10.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 10:26:44 -0700 (PDT) Message-Id: <7202ada0542b6f014647785945094a13c9d885c7.1717694802.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 06 Jun 2024 17:26:38 +0000 Subject: [PATCH 2/4] refs: keep track of unresolved reference value in iterators Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "Phillip Wood [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, "Jeff King [ ]" , "Patrick Steinhardt [ ]" , " =?utf-8?q?Jean-No=C3=ABl?= Avila [ ]" , John Cai , John Cai From: John Cai From: John Cai Since ref iterators do not hold onto the direct value of a reference without resolving it, the only way to get ahold of a direct value of a symbolic ref is to make a separate call to refs_read_symbolic_ref. To make accessing the direct value of a symbolic ref more efficient, let's save the direct value of the ref in the iterators for both the files backend and the reftable backend. Signed-off-by: John Cai --- refs/files-backend.c | 8 ++++++-- refs/iterator.c | 3 +++ refs/ref-cache.c | 6 ++++++ refs/ref-cache.h | 2 ++ refs/refs-internal.h | 1 + refs/reftable-backend.c | 2 +- 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index bf2ffe062ea..a963d796a29 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -243,8 +243,9 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs, { struct object_id oid; int flag; + const char* referent = NULL; - if (!refs_resolve_ref_unsafe(&refs->base, refname, NULL, RESOLVE_REF_READING, + if (!refs_resolve_ref_unsafe(&refs->base, refname, referent, RESOLVE_REF_READING, &oid, &flag)) { oidclr(&oid); flag |= REF_ISBROKEN; @@ -266,7 +267,7 @@ static void loose_fill_ref_dir_regular_file(struct files_ref_store *refs, oidclr(&oid); flag |= REF_BAD_NAME | REF_ISBROKEN; } - add_entry_to_dir(dir, create_ref_entry(refname, &oid, flag)); + add_entry_to_dir(dir, create_ref_entry(refname, referent, &oid, flag)); } /* @@ -854,6 +855,9 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator) iter->base.refname = iter->iter0->refname; iter->base.oid = iter->iter0->oid; iter->base.flags = iter->iter0->flags; + if (iter->iter0->flags & REF_ISSYMREF) + iter->base.referent = iter->iter0->referent; + return ITER_OK; } diff --git a/refs/iterator.c b/refs/iterator.c index d355ebf0d59..26acb6bd640 100644 --- a/refs/iterator.c +++ b/refs/iterator.c @@ -7,6 +7,7 @@ #include "refs.h" #include "refs/refs-internal.h" #include "iterator.h" +#include "strbuf.h" int ref_iterator_advance(struct ref_iterator *ref_iterator) { @@ -29,6 +30,7 @@ void base_ref_iterator_init(struct ref_iterator *iter, { iter->vtable = vtable; iter->refname = NULL; + iter->referent = NULL; iter->oid = NULL; iter->flags = 0; } @@ -199,6 +201,7 @@ static int merge_ref_iterator_advance(struct ref_iterator *ref_iterator) } if (selection & ITER_YIELD_CURRENT) { + iter->base.referent = (*iter->current)->referent; iter->base.refname = (*iter->current)->refname; iter->base.oid = (*iter->current)->oid; iter->base.flags = (*iter->current)->flags; diff --git a/refs/ref-cache.c b/refs/ref-cache.c index b6c53fc8ed2..e8ce5822cc1 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -5,6 +5,7 @@ #include "refs-internal.h" #include "ref-cache.h" #include "../iterator.h" +#include "../strbuf.h" void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry) { @@ -34,12 +35,16 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry) } struct ref_entry *create_ref_entry(const char *refname, + const char *referent, const struct object_id *oid, int flag) { struct ref_entry *ref; FLEX_ALLOC_STR(ref, name, refname); oidcpy(&ref->u.value.oid, oid); + if (referent) + ref->u.value.referent = xstrdup(referent); + ref->flag = flag; return ref; } @@ -429,6 +434,7 @@ static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator) level->index = -1; } else { iter->base.refname = entry->name; + iter->base.referent = entry->u.value.referent; iter->base.oid = &entry->u.value.oid; iter->base.flags = entry->flag; return ITER_OK; diff --git a/refs/ref-cache.h b/refs/ref-cache.h index 95c76e27c83..12ddee4fddc 100644 --- a/refs/ref-cache.h +++ b/refs/ref-cache.h @@ -42,6 +42,7 @@ struct ref_value { * referred to by the last reference in the symlink chain. */ struct object_id oid; + const char *referent; }; /* @@ -173,6 +174,7 @@ struct ref_entry *create_dir_entry(struct ref_cache *cache, const char *dirname, size_t len); struct ref_entry *create_ref_entry(const char *refname, + const char *referent, const struct object_id *oid, int flag); /* diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 33749fbd839..07754514355 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -299,6 +299,7 @@ enum do_for_each_ref_flags { struct ref_iterator { struct ref_iterator_vtable *vtable; const char *refname; + const char *referent; const struct object_id *oid; unsigned int flags; }; diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index 9e03582e7da..6328c0f77dc 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -438,7 +438,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator) oidread(&iter->oid, iter->ref.value.val2.value); break; case REFTABLE_REF_SYMREF: - if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname, NULL, + if (!refs_resolve_ref_unsafe(&iter->refs->base, iter->ref.refname, iter->base.referent, RESOLVE_REF_READING, &iter->oid, &flags)) oidclr(&iter->oid); break; From patchwork Thu Jun 6 17:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 13688840 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B9061990D8 for ; Thu, 6 Jun 2024 17:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694811; cv=none; b=NYHaAreggPhxkOvYifuXoj8vIpO41/P/4LfrMOkHI3OwzyV8qPjSbpp3cJBlpu2bwp3cdvx3IJxY8Xx8kRc0T+IrRKFTGlJBESXxkLCKfhkl7alwkiXjg0xM1Yy7ym7jP7O94/lCxaXBSlqdyx5xWqSJ1Bn9g1I5yYHnn5lobk8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694811; c=relaxed/simple; bh=gWICj18GJZHP90oGkAlBGS30WjQG9XO4drdS5SM2T/Q=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=uIoJ7rJVul6dzCR0svqbumK4NFfEtOXvoh0fS6bZnpSJW5RVrZqLOS1piYBUJ3vFeKll+Al8+0Jwvhrq9W9JRQFKyV3LQmmOD5BT07jerIRCUiaUnwwfmZchC8aMlfDNH9vCSxkOEfMa6Ol62C/S1gY4HfDQsFUf9UY/xUuWbVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M7+L2XlL; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="M7+L2XlL" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-35ef1e928c9so1424155f8f.3 for ; Thu, 06 Jun 2024 10:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717694806; x=1718299606; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=dQfu2+R/G8ECR9N1y6tnYv5Q8C+HeK9ufoX1/EDxIXA=; b=M7+L2XlLdQTaMnpzda8C+9/K/vsRrI74CbuSAoZrwoX+45J+ra5ykoEPjxMd9HBgw5 yZkPyFIJ93hwYe8zj+GyeImn76cCSywBbf4LPljSv/yhYl4F1rXT6+QjQDC7L3f14IhB w0bel5hnjMg2FlFqjcce4skSg5ix+QE5pT1T3yaOvmnokh8fCGGYJLXnCHOATwPzMenN bZDkGnLeLl3GECX5OzzvaIKTB/395WSmnra5v64xhAX638vYWg6arr7k5OMjOLYvgHmY s0N05xjF+wXTpugXsWOUwGxCX+b1xDFh67pX/Mwv3Yv8JUaRSIkzAXmmNs1uzD8Td70f bmcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717694806; x=1718299606; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dQfu2+R/G8ECR9N1y6tnYv5Q8C+HeK9ufoX1/EDxIXA=; b=uOGoTxotdxeAF+YTJQLQw23FGzwnndZBvu5I7IBsFPluc6q0bwyfwGd6lrbn4o03Kb 2CprxGHsLtKyH1Oj2Tlga+RXMnu5d+pGekm4KxDsKfpY1i6pjKb8uyPMd6ciiuSJr2yq Wd3IpAaU3k+rBA7L1xYJHo4oz8gG2p8YoJK/tEeKhI9+ZJ4IP/dWmIm8CEzKJ8cQOIfi Lo4oQn7YIl9XIsRuOjNatGl/pUJsiW6tevMK6dN6xCNeesfkoc+7CjCCaYFtUa4pre0P S0SwlTbK+JGIYdnLsiogY28bNwKDmKK3UDAGUKrtKQBVQWCrR4Kr2S4j8xGPPet52n7i r/pw== X-Gm-Message-State: AOJu0YwWRN6BZzun4Vh+QOPa/g4xHa/6TgaCZVwIdiHDnYD/TFFkU6oc 1s5asf2kbwue/qVeEpmUeerLxQkttEP7cAvU1B1kfA8eHqb+0mTDAxgNIA== X-Google-Smtp-Source: AGHT+IE8jPWBjDoa+Yv42A/PqE5MStESq4muGcbfQ9MJ4zz5lz15D/XFhWVtllgE4BDjZE1A9CRcBQ== X-Received: by 2002:a5d:4b83:0:b0:354:d098:8d67 with SMTP id ffacd0b85a97d-35efee0ed89mr261210f8f.57.1717694806188; Thu, 06 Jun 2024 10:26:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35ef5fc6c56sm2077907f8f.109.2024.06.06.10.26.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 10:26:45 -0700 (PDT) Message-Id: <33914f84a649fed5bc985d60e1947d1e414e65aa.1717694802.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 06 Jun 2024 17:26:39 +0000 Subject: [PATCH 3/4] refs: add referent to each_ref_fn Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "Phillip Wood [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, "Jeff King [ ]" , "Patrick Steinhardt [ ]" , " =?utf-8?q?Jean-No=C3=ABl?= Avila [ ]" , John Cai , John Cai From: John Cai From: John Cai Add a parameter to each_ref_fn so that callers to the ref APIs that use this function as a callback can have acess to the unresolved value of a symbolic ref. Signed-off-by: John Cai --- bisect.c | 3 ++- builtin/bisect.c | 4 +++- builtin/checkout.c | 2 +- builtin/describe.c | 2 +- builtin/fetch.c | 3 ++- builtin/fsck.c | 4 ++-- builtin/gc.c | 1 + builtin/name-rev.c | 2 +- builtin/pack-objects.c | 5 +++-- builtin/receive-pack.c | 2 +- builtin/remote.c | 4 +++- builtin/repack.c | 1 + builtin/replace.c | 1 + builtin/rev-parse.c | 4 ++-- builtin/show-branch.c | 8 ++++---- builtin/show-ref.c | 3 ++- builtin/submodule--helper.c | 1 + builtin/worktree.c | 1 + commit-graph.c | 1 + delta-islands.c | 2 +- fetch-pack.c | 2 ++ help.c | 2 +- http-backend.c | 4 ++-- log-tree.c | 2 +- ls-refs.c | 4 ++-- midx-write.c | 2 +- negotiator/default.c | 2 +- negotiator/skipping.c | 2 +- notes.c | 2 +- object-name.c | 2 +- reachable.c | 2 +- ref-filter.c | 4 ++-- reflog.c | 1 + refs.c | 12 ++++++------ refs.h | 2 +- refs/files-backend.c | 2 +- refs/iterator.c | 2 +- remote.c | 4 ++-- replace-object.c | 1 + revision.c | 2 +- server-info.c | 2 +- shallow.c | 2 ++ submodule.c | 2 ++ t/helper/test-ref-store.c | 2 +- upload-pack.c | 8 ++++---- walker.c | 1 + worktree.c | 2 +- 47 files changed, 76 insertions(+), 53 deletions(-) diff --git a/bisect.c b/bisect.c index 4ea703bec11..e22b3acf082 100644 --- a/bisect.c +++ b/bisect.c @@ -446,7 +446,7 @@ void find_bisection(struct commit_list **commit_list, int *reaches, clear_commit_weight(&commit_weight); } -static int register_ref(const char *refname, const struct object_id *oid, +static int register_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data UNUSED) { struct strbuf good_prefix = STRBUF_INIT; @@ -1168,6 +1168,7 @@ int estimate_bisect_steps(int all) } static int mark_for_removal(const char *refname, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flag UNUSED, void *cb_data) { diff --git a/builtin/bisect.c b/builtin/bisect.c index 76ce5f0e0df..142e56d6020 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -355,6 +355,7 @@ static int check_and_set_terms(struct bisect_terms *terms, const char *cmd) } static int inc_nr(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flag UNUSED, void *cb_data) { @@ -544,7 +545,7 @@ static int bisect_append_log_quoted(const char **argv) return res; } -static int add_bisect_ref(const char *refname, const struct object_id *oid, +static int add_bisect_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb) { struct add_bisect_ref_data *data = cb; @@ -1161,6 +1162,7 @@ static int bisect_visualize(struct bisect_terms *terms, int argc, } static int get_first_good(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { diff --git a/builtin/checkout.c b/builtin/checkout.c index f90a4ca4b7a..ccd27c277d9 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -1045,7 +1045,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, report_tracking(new_branch_info); } -static int add_pending_uninteresting_ref(const char *refname, +static int add_pending_uninteresting_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) { diff --git a/builtin/describe.c b/builtin/describe.c index e5287eddf2d..d95a9109eed 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -145,7 +145,7 @@ static void add_to_known_names(const char *path, } } -static int get_name(const char *path, const struct object_id *oid, +static int get_name(const char *path, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { int is_tag = 0; diff --git a/builtin/fetch.c b/builtin/fetch.c index a319954f9fd..b3e275ca5c8 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -286,7 +286,7 @@ static struct refname_hash_entry *refname_hash_add(struct hashmap *map, return ent; } -static int add_one_refname(const char *refname, +static int add_one_refname(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cbdata) { @@ -1459,6 +1459,7 @@ static void set_option(struct transport *transport, const char *name, const char static int add_oid(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) { diff --git a/builtin/fsck.c b/builtin/fsck.c index 2c0ac6653ca..650dd0d839d 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -521,7 +521,7 @@ static int fsck_handle_reflog(const char *logname, void *cb_data) return 0; } -static int fsck_handle_ref(const char *refname, const struct object_id *oid, +static int fsck_handle_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { struct object *obj; @@ -576,7 +576,7 @@ static void get_default_heads(void) strbuf_worktree_ref(wt, &ref, "HEAD"); fsck_head_link(ref.buf, &head_points_at, &head_oid); if (head_points_at && !is_null_oid(&head_oid)) - fsck_handle_ref(ref.buf, &head_oid, 0, NULL); + fsck_handle_ref(ref.buf, NULL, &head_oid, 0, NULL); strbuf_release(&ref); if (include_reflogs) diff --git a/builtin/gc.c b/builtin/gc.c index 72bac2554fc..65be7c31b33 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -836,6 +836,7 @@ struct cg_auto_data { }; static int dfs_on_ref(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 70e9ec4e477..52016f1cf7d 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -337,7 +337,7 @@ static int cmp_by_tag_and_age(const void *a_, const void *b_) return a->taggerdate != b->taggerdate; } -static int name_ref(const char *path, const struct object_id *oid, +static int name_ref(const char *path, const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) { struct object *o = parse_object(the_repository, oid); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 638f5c57f0d..a593fbfb3a3 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -771,7 +771,7 @@ static enum write_one_status write_one(struct hashfile *f, return WRITE_ONE_WRITTEN; } -static int mark_tagged(const char *path UNUSED, const struct object_id *oid, +static int mark_tagged(const char *path UNUSED, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { struct object_id peeled; @@ -3127,7 +3127,7 @@ static void add_tag_chain(const struct object_id *oid) } } -static int add_ref_tag(const char *tag UNUSED, const struct object_id *oid, +static int add_ref_tag(const char *tag UNUSED, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { struct object_id peeled; @@ -4074,6 +4074,7 @@ static void record_recent_commit(struct commit *commit, void *data UNUSED) } static int mark_bitmap_preferred_tip(const char *refname, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *data UNUSED) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d9e2c4bbe39..d3307730f39 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -300,7 +300,7 @@ static void show_ref(const char *path, const struct object_id *oid) } } -static int show_ref_cb(const char *path_full, const struct object_id *oid, +static int show_ref_cb(const char *path_full, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *data) { struct oidset *seen = data; diff --git a/builtin/remote.c b/builtin/remote.c index 039d1d6c55a..fdc5954c6e0 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -543,6 +543,7 @@ struct branches_for_remote { }; static int add_branch_for_removal(const char *refname, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flags UNUSED, void *cb_data) { @@ -585,7 +586,7 @@ struct rename_info { uint32_t symrefs_nr; }; -static int read_remote_branches(const char *refname, +static int read_remote_branches(const char *refname, const char *referent UNUSED, const struct object_id *oid UNUSED, int flags UNUSED, void *cb_data) { @@ -971,6 +972,7 @@ static void free_remote_ref_states(struct ref_states *states) } static int append_ref_to_tracked_list(const char *refname, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flags, void *cb_data) { diff --git a/builtin/repack.c b/builtin/repack.c index 58ad82dd97b..2c1218debcd 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -667,6 +667,7 @@ struct midx_snapshot_ref_data { }; static int midx_snapshot_ref_one(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *_data) { diff --git a/builtin/replace.c b/builtin/replace.c index ce9f6974d26..ab004979fbb 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -49,6 +49,7 @@ struct show_data { }; static int show_reference(const char *refname, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 1e2919fd81c..cc1a88cd933 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -211,7 +211,7 @@ static int show_default(void) return 0; } -static int show_reference(const char *refname, const struct object_id *oid, +static int show_reference(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { if (ref_excluded(&ref_excludes, refname)) @@ -220,7 +220,7 @@ static int show_reference(const char *refname, const struct object_id *oid, return 0; } -static int anti_reference(const char *refname, const struct object_id *oid, +static int anti_reference(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { show_rev(REVERSED, oid, refname); diff --git a/builtin/show-branch.c b/builtin/show-branch.c index d72f4cb98de..3427c1572e5 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -410,7 +410,7 @@ static int append_ref(const char *refname, const struct object_id *oid, return 0; } -static int append_head_ref(const char *refname, const struct object_id *oid, +static int append_head_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { struct object_id tmp; @@ -425,7 +425,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid, return append_ref(refname + ofs, oid, 0); } -static int append_remote_ref(const char *refname, const struct object_id *oid, +static int append_remote_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { struct object_id tmp; @@ -451,7 +451,7 @@ static int append_tag_ref(const char *refname, const struct object_id *oid, static const char *match_ref_pattern = NULL; static int match_ref_slash = 0; -static int append_matching_ref(const char *refname, const struct object_id *oid, +static int append_matching_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { /* we want to allow pattern hold/ to show all @@ -468,7 +468,7 @@ static int append_matching_ref(const char *refname, const struct object_id *oid, if (wildmatch(match_ref_pattern, tail, 0)) return 0; if (starts_with(refname, "refs/heads/")) - return append_head_ref(refname, oid, flag, cb_data); + return append_head_ref(refname, NULL, oid, flag, cb_data); if (starts_with(refname, "refs/tags/")) return append_tag_ref(refname, oid, flag, cb_data); return append_ref(refname, oid, 0); diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 3114bdc391a..3b9be14b61c 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -63,7 +63,7 @@ struct show_ref_data { int show_head; }; -static int show_ref(const char *refname, const struct object_id *oid, +static int show_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cbdata) { struct show_ref_data *data = cbdata; @@ -97,6 +97,7 @@ static int show_ref(const char *refname, const struct object_id *oid, } static int add_existing(const char *refname, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flag UNUSED, void *cbdata) { diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index e3e1f08a58c..d7c29383ccb 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -611,6 +611,7 @@ static void print_status(unsigned int flags, char state, const char *path, } static int handle_submodule_head_ref(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) diff --git a/builtin/worktree.c b/builtin/worktree.c index 893e973871e..14f9a525d6a 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -626,6 +626,7 @@ static void print_preparing_worktree_line(int detach, * Returns 0 on failure and non-zero on success. */ static int first_valid_ref(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flags UNUSED, void *cb_data UNUSED) diff --git a/commit-graph.c b/commit-graph.c index e5dd3553dfe..b6906633b1b 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1815,6 +1815,7 @@ struct refs_cb_data { }; static int add_ref_to_set(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) { diff --git a/delta-islands.c b/delta-islands.c index 4ac3c10551a..8bafa4b807c 100644 --- a/delta-islands.c +++ b/delta-islands.c @@ -388,7 +388,7 @@ static void add_ref_to_island(kh_str_t *remote_islands, const char *island_name, rl->hash += sha_core; } -static int find_island_for_ref(const char *refname, const struct object_id *oid, +static int find_island_for_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb) { struct island_load_data *ild = cb; diff --git a/fetch-pack.c b/fetch-pack.c index 7d2aef21add..ae9615fad65 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -181,6 +181,7 @@ static int rev_list_insert_ref(struct fetch_negotiator *negotiator, } static int rev_list_insert_ref_oid(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) @@ -608,6 +609,7 @@ static int mark_complete(const struct object_id *oid) } static int mark_complete_oid(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) diff --git a/help.c b/help.c index 1d057aa6073..385a98f81fa 100644 --- a/help.c +++ b/help.c @@ -789,7 +789,7 @@ struct similar_ref_cb { struct string_list *similar_refs; }; -static int append_similar_ref(const char *refname, +static int append_similar_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid UNUSED, int flags UNUSED, void *cb_data) { diff --git a/http-backend.c b/http-backend.c index 20c3ff8fa95..d9ed6405ed4 100644 --- a/http-backend.c +++ b/http-backend.c @@ -510,7 +510,7 @@ static void run_service(const char **argv, int buffer_input) exit(1); } -static int show_text_ref(const char *name, const struct object_id *oid, +static int show_text_ref(const char *name, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { const char *name_nons = strip_namespace(name); @@ -566,7 +566,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg UNUSED) strbuf_release(&buf); } -static int show_head_ref(const char *refname, const struct object_id *oid, +static int show_head_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { struct strbuf *buf = cb_data; diff --git a/log-tree.c b/log-tree.c index da06c6e982f..06176e34a2c 100644 --- a/log-tree.c +++ b/log-tree.c @@ -143,7 +143,7 @@ static int ref_filter_match(const char *refname, return 1; } -static int add_ref_decoration(const char *refname, const struct object_id *oid, +static int add_ref_decoration(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) { diff --git a/ls-refs.c b/ls-refs.c index 3d047bbc64f..f0d9f8864d7 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -75,7 +75,7 @@ struct ls_refs_data { unsigned unborn : 1; }; -static int send_ref(const char *refname, const struct object_id *oid, +static int send_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { struct ls_refs_data *data = cb_data; @@ -134,7 +134,7 @@ static void send_possibly_unborn_head(struct ls_refs_data *data) oid_is_null = is_null_oid(&oid); if (!oid_is_null || (data->unborn && data->symrefs && (flag & REF_ISSYMREF))) - send_ref(namespaced.buf, oid_is_null ? NULL : &oid, flag, data); + send_ref(namespaced.buf, NULL, oid_is_null ? NULL : &oid, flag, data); strbuf_release(&namespaced); } diff --git a/midx-write.c b/midx-write.c index 4998707eb8b..bac416d5e87 100644 --- a/midx-write.c +++ b/midx-write.c @@ -651,7 +651,7 @@ static void prepare_midx_packing_data(struct packing_data *pdata, trace2_region_leave("midx", "prepare_midx_packing_data", the_repository); } -static int add_ref_to_pending(const char *refname, +static int add_ref_to_pending(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { diff --git a/negotiator/default.c b/negotiator/default.c index 518b3c43b28..052c37f4ae2 100644 --- a/negotiator/default.c +++ b/negotiator/default.c @@ -36,7 +36,7 @@ static void rev_list_push(struct negotiation_state *ns, } } -static int clear_marks(const char *refname, const struct object_id *oid, +static int clear_marks(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { diff --git a/negotiator/skipping.c b/negotiator/skipping.c index b7e008c2fda..0ad76b033ab 100644 --- a/negotiator/skipping.c +++ b/negotiator/skipping.c @@ -73,7 +73,7 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int return entry; } -static int clear_marks(const char *refname, const struct object_id *oid, +static int clear_marks(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) { diff --git a/notes.c b/notes.c index 53ca25c8147..77ac78ac08e 100644 --- a/notes.c +++ b/notes.c @@ -928,7 +928,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid, return ret; } -static int string_list_add_one_ref(const char *refname, +static int string_list_add_one_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid UNUSED, int flag UNUSED, void *cb) { diff --git a/object-name.c b/object-name.c index 523af6f64f3..68b4105d614 100644 --- a/object-name.c +++ b/object-name.c @@ -1363,7 +1363,7 @@ struct handle_one_ref_cb { struct commit_list **list; }; -static int handle_one_ref(const char *path, const struct object_id *oid, +static int handle_one_ref(const char *path, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { diff --git a/reachable.c b/reachable.c index 1224b300086..1f09353bae3 100644 --- a/reachable.c +++ b/reachable.c @@ -77,7 +77,7 @@ static void add_rebase_files(struct rev_info *revs) free_worktrees(worktrees); } -static int add_one_ref(const char *path, const struct object_id *oid, +static int add_one_ref(const char *path, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { struct rev_info *revs = (struct rev_info *)cb_data; diff --git a/ref-filter.c b/ref-filter.c index f7fb0c7e0ec..0b4b6bb8d71 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2863,7 +2863,7 @@ struct ref_filter_cbdata { * A call-back given to for_each_ref(). Filter refs and keep them for * later object processing. */ -static int filter_one(const char *refname, const struct object_id *oid, int flag, void *cb_data) +static int filter_one(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { struct ref_filter_cbdata *ref_cbdata = cb_data; struct ref_array_item *ref; @@ -2898,7 +2898,7 @@ struct ref_filter_and_format_cbdata { } internal; }; -static int filter_and_format_one(const char *refname, const struct object_id *oid, int flag, void *cb_data) +static int filter_and_format_one(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) { struct ref_filter_and_format_cbdata *ref_cbdata = cb_data; struct ref_array_item *ref; diff --git a/reflog.c b/reflog.c index 3c80950186b..744e5f2d982 100644 --- a/reflog.c +++ b/reflog.c @@ -298,6 +298,7 @@ int should_expire_reflog_ent_verbose(struct object_id *ooid, } static int push_tip_to_list(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags, void *cb_data) { diff --git a/refs.c b/refs.c index 2c592a9ae29..f75d6537bc7 100644 --- a/refs.c +++ b/refs.c @@ -411,7 +411,7 @@ int refs_ref_exists(struct ref_store *refs, const char *refname) NULL, NULL); } -static int for_each_filter_refs(const char *refname, +static int for_each_filter_refs(const char *refname, const char *referent, const struct object_id *oid, int flags, void *data) { @@ -421,7 +421,7 @@ static int for_each_filter_refs(const char *refname, return 0; if (filter->prefix) skip_prefix(refname, filter->prefix, &refname); - return filter->fn(refname, oid, flags, filter->cb_data); + return filter->fn(refname, referent, oid, flags, filter->cb_data); } struct warn_if_dangling_data { @@ -432,7 +432,7 @@ struct warn_if_dangling_data { const char *msg_fmt; }; -static int warn_if_dangling_symref(const char *refname, +static int warn_if_dangling_symref(const char *refname, const char *referent UNUSED, const struct object_id *oid UNUSED, int flags, void *cb_data) { @@ -503,7 +503,7 @@ int refs_head_ref_namespaced(struct ref_store *refs, each_ref_fn fn, void *cb_da strbuf_addf(&buf, "%sHEAD", get_git_namespace()); if (!refs_read_ref_full(refs, buf.buf, RESOLVE_REF_READING, &oid, &flag)) - ret = fn(buf.buf, &oid, flag, cb_data); + ret = fn(buf.buf, NULL, &oid, flag, cb_data); strbuf_release(&buf); return ret; @@ -1524,7 +1524,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) if (refs_resolve_ref_unsafe(refs, "HEAD", NULL, RESOLVE_REF_READING, &oid, &flag)) - return fn("HEAD", &oid, flag, cb_data); + return fn("HEAD", NULL, &oid, flag, cb_data); return 0; } @@ -2360,7 +2360,7 @@ struct do_for_each_reflog_help { void *cb_data; }; -static int do_for_each_reflog_helper(const char *refname, +static int do_for_each_reflog_helper(const char *refname, const char *referent, const struct object_id *oid UNUSED, int flags, void *cb_data) diff --git a/refs.h b/refs.h index ea4a3217658..979494ce1f8 100644 --- a/refs.h +++ b/refs.h @@ -294,7 +294,7 @@ struct ref_transaction; * arguments is only guaranteed to be valid for the duration of a * single callback invocation. */ -typedef int each_ref_fn(const char *refname, +typedef int each_ref_fn(const char *refname, const char *referent, const struct object_id *oid, int flags, void *cb_data); /* diff --git a/refs/files-backend.c b/refs/files-backend.c index a963d796a29..f4c892422bc 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -3002,7 +3002,7 @@ static int files_transaction_abort(struct ref_store *ref_store, return 0; } -static int ref_present(const char *refname, +static int ref_present(const char *refname, const char *referent UNUSED, const struct object_id *oid UNUSED, int flags UNUSED, void *cb_data) diff --git a/refs/iterator.c b/refs/iterator.c index 26acb6bd640..21beeb91e9e 100644 --- a/refs/iterator.c +++ b/refs/iterator.c @@ -451,7 +451,7 @@ int do_for_each_ref_iterator(struct ref_iterator *iter, current_ref_iter = iter; while ((ok = ref_iterator_advance(iter)) == ITER_OK) { - retval = fn(iter->refname, iter->oid, iter->flags, cb_data); + retval = fn(iter->refname, iter->referent, iter->oid, iter->flags, cb_data); if (retval) { /* * If ref_iterator_abort() returns ITER_ERROR, diff --git a/remote.c b/remote.c index c9718ee0ca1..071c542ab31 100644 --- a/remote.c +++ b/remote.c @@ -2342,7 +2342,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb, return 1; } -static int one_local_ref(const char *refname, const struct object_id *oid, +static int one_local_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { @@ -2427,7 +2427,7 @@ struct stale_heads_info { struct refspec *rs; }; -static int get_stale_heads_cb(const char *refname, const struct object_id *oid, +static int get_stale_heads_cb(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags, void *cb_data) { struct stale_heads_info *info = cb_data; diff --git a/replace-object.c b/replace-object.c index 73f5acbcd9f..8ef561f1455 100644 --- a/replace-object.c +++ b/replace-object.c @@ -9,6 +9,7 @@ #include "commit.h" static int register_replace_ref(const char *refname, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) diff --git a/revision.c b/revision.c index 6aca4f42303..e37346fb52a 100644 --- a/revision.c +++ b/revision.c @@ -1627,7 +1627,7 @@ struct all_refs_cb { struct worktree *wt; }; -static int handle_one_ref(const char *path, const struct object_id *oid, +static int handle_one_ref(const char *path, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { diff --git a/server-info.c b/server-info.c index 6feaa457c5c..3a0d6ad39ab 100644 --- a/server-info.c +++ b/server-info.c @@ -151,7 +151,7 @@ static int update_info_file(char *path, return ret; } -static int add_info_ref(const char *path, const struct object_id *oid, +static int add_info_ref(const char *path, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { diff --git a/shallow.c b/shallow.c index a0b181ba8a1..a4d2c3e221b 100644 --- a/shallow.c +++ b/shallow.c @@ -610,6 +610,7 @@ static void paint_down(struct paint_info *info, const struct object_id *oid, } static int mark_uninteresting(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data UNUSED) @@ -725,6 +726,7 @@ struct commit_array { }; static int add_ref(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *cb_data) diff --git a/submodule.c b/submodule.c index 759cf1e1cda..bdba5a1ba11 100644 --- a/submodule.c +++ b/submodule.c @@ -951,6 +951,7 @@ static void free_submodules_data(struct string_list *submodules) } static int has_remote(const char *refname UNUSED, + const char *referent UNUSED, const struct object_id *oid UNUSED, int flags UNUSED, void *cb_data UNUSED) { @@ -1271,6 +1272,7 @@ int push_unpushed_submodules(struct repository *r, } static int append_oid_to_array(const char *ref UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flags UNUSED, void *data) { diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index ef1d6acbfae..78cb873e6a0 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -153,7 +153,7 @@ static int cmd_rename_ref(struct ref_store *refs, const char **argv) return refs_rename_ref(refs, oldref, newref, logmsg); } -static int each_ref(const char *refname, const struct object_id *oid, +static int each_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flags, void *cb_data UNUSED) { printf("%s %s 0x%x\n", oid_to_hex(oid), refname, flags); diff --git a/upload-pack.c b/upload-pack.c index 4fddc081237..e79e77570b7 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -855,7 +855,7 @@ static void send_unshallow(struct upload_pack_data *data) } } -static int check_ref(const char *refname_full, const struct object_id *oid, +static int check_ref(const char *refname_full, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data); static void deepen(struct upload_pack_data *data, int depth) { @@ -1206,7 +1206,7 @@ static int mark_our_ref(const char *refname, const char *refname_full, return 0; } -static int check_ref(const char *refname_full, const struct object_id *oid, +static int check_ref(const char *refname_full, const char *referent UNUSED,const struct object_id *oid, int flag UNUSED, void *cb_data) { const char *refname = strip_namespace(refname_full); @@ -1274,14 +1274,14 @@ static void write_v0_ref(struct upload_pack_data *data, return; } -static int send_ref(const char *refname, const struct object_id *oid, +static int send_ref(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data) { write_v0_ref(cb_data, refname, strip_namespace(refname), oid); return 0; } -static int find_symref(const char *refname, +static int find_symref(const char *refname, const char *referent UNUSED, const struct object_id *oid UNUSED, int flag, void *cb_data) { diff --git a/walker.c b/walker.c index 946d86b04ee..918693221a9 100644 --- a/walker.c +++ b/walker.c @@ -219,6 +219,7 @@ static int interpret_target(struct walker *walker, char *target, struct object_i } static int mark_complete(const char *path UNUSED, + const char *referent UNUSED, const struct object_id *oid, int flag UNUSED, void *cb_data UNUSED) diff --git a/worktree.c b/worktree.c index ed89bab481d..9ab7e305d39 100644 --- a/worktree.c +++ b/worktree.c @@ -553,7 +553,7 @@ int other_head_refs(each_ref_fn fn, void *cb_data) NULL, RESOLVE_REF_READING, &oid, &flag)) - ret = fn(refname.buf, &oid, flag, cb_data); + ret = fn(refname.buf, NULL, &oid, flag, cb_data); if (ret) break; } From patchwork Thu Jun 6 17:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cai X-Patchwork-Id: 13688839 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECB351991A0 for ; Thu, 6 Jun 2024 17:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694810; cv=none; b=A0stC7G1AnAVc/RPD7gv88AxFToUH1+NP6Oo/VWLLSStgctQqYYOKvrxO2wzuNBq99zb54GaE0mCqK4NpzV30izBF3bNgH0IYFgOKGLKqQmuI9pFpjM61RmkHnbnnMIVChpmE0I08EUMOe/TYw6ce8qfKoZJginpdw2jAKG9lag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717694810; c=relaxed/simple; bh=WKy6Ew8aBr4WYV+3wQI7PpDs4Kf00n8qoPms4AY6HjA=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=EbNKJfVgUrX9ShWllWnWC/QsNVXXN6W56UWhxz0fMRV/UrGFyh6C/FBQOrE9iP9NLHPsThnHVVIEdXRp7LxHd4VctVZbFFdSANErjw8lSb/44aJKX0jvegiBENfWkBRDnB5G8P5b5EY6ZVP/KuAP/3yMfRYYvIUWr6Jde4A1SHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zah/rfSf; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zah/rfSf" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4215ac379fdso11864725e9.3 for ; Thu, 06 Jun 2024 10:26:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717694807; x=1718299607; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Mf+zKG7gppPa+fZpWzVYCKKzyRfTOzP8PioMoGHRVf4=; b=Zah/rfSfl76J7N1X2ycuh+6keO3iGRmyjm0otOybOgjbz++WZnY51WwJLkZk90+SKv PaG9lhtrd9unQInUcGBVytiNun8K/mS+Dgavj8/12FzftnqTHeM+7fpHANbIVySI1dAC MUOe7pmyGZxpN6c8+ZDjADeYYc7DQ0DW02w/K9tB6l+B6NfXoy3Hf693UHEoSOUd3jQb jXb0tXn7XpUO4Nv6qOUVYEMmuJor2LMxSvy9vBOl3narysexbx5jyxoD5Ks/kJUIhTTd U4KyesDbcR7u08wPjGMnNgBc64zDVMzndGG/tfhw/Dn32rrf7XTVlQ0B1zFhp2/P/dBi LllA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717694807; x=1718299607; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mf+zKG7gppPa+fZpWzVYCKKzyRfTOzP8PioMoGHRVf4=; b=mHfEIQ/PJG3xisU2R8oP+J8+yCCyDnICVGWWzuRWsXukxzi2NCyXbpEoMdRO8s4eh4 7liiIljwWVh/rAB5GiwwUe7AwgYG4I2c+Y7lU4gyBZXy9o/KZEMjojTQoBcm5Bcmfwwp A0HGv/iy8d477CIqIm6w2cUk7bduiCzQN/OZxmRyqsfeyznTL0fJ4375Sq/jUs6OQJQn sojDFwKP3nFgx1rnAa0jzbiRUP4R76sG7qqHSplm0O4nXZ2bWwElsDucA+KDb9r8dLoJ OCobmS2oq7LUCSH09CAgiKBIhonYbn1ImKoNd60wzDD/V4i8csyTgJcAyj+Y1s9aDZai BtNg== X-Gm-Message-State: AOJu0Yyd28nUVVWIbsKgP8MY8KVEAAozSeWt5vt0k91gmnZymzKA05vy l6a0SwI7J1Xjvj89l8aU8RieC1SvxADpkZeEx7O+4kXDiJ8F1DAF85037Q== X-Google-Smtp-Source: AGHT+IFSFg5OOoLxfzX1rBMCoR3NT2pDIyUgBoIj6Wx1KtFQikZ5PfkxBJBrejb2k1qtaYbFX3BUhw== X-Received: by 2002:a05:600c:4c11:b0:421:2a2d:2bfc with SMTP id 5b1f17b1804b1-421649fe32bmr3416485e9.12.1717694806879; Thu, 06 Jun 2024 10:26:46 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35efa97b15dsm1065065f8f.81.2024.06.06.10.26.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 10:26:46 -0700 (PDT) Message-Id: <6d5b1b62e6c59ecc0f49d11e08732c6dc4d573fa.1717694802.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 06 Jun 2024 17:26:40 +0000 Subject: [PATCH 4/4] ref-filter: populate symref from iterator Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: "Phillip Wood [ ]" , Kristoffer Haugsbakk <[code@khaugsbakk.name]>, "Jeff King [ ]" , "Patrick Steinhardt [ ]" , " =?utf-8?q?Jean-No=C3=ABl?= Avila [ ]" , John Cai , John Cai From: John Cai From: John Cai With a previous commit, the reference the symbolic ref points is saved in the ref iterator records. Instead of making a separate call to resolve_refdup() each time, we can just populate the ref_array_item with the value from the iterator. Signed-off-by: John Cai --- ref-filter.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 0b4b6bb8d71..c7c2117f9cd 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2781,7 +2781,7 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname) return ref_kind_from_refname(refname); } -static struct ref_array_item *apply_ref_filter(const char *refname, const struct object_id *oid, +static struct ref_array_item *apply_ref_filter(const char *refname, const char *referent, const struct object_id *oid, int flag, struct ref_filter *filter) { struct ref_array_item *ref; @@ -2850,6 +2850,7 @@ static struct ref_array_item *apply_ref_filter(const char *refname, const struct ref->commit = commit; ref->flag = flag; ref->kind = kind; + ref->symref = referent; return ref; } @@ -2863,12 +2864,12 @@ struct ref_filter_cbdata { * A call-back given to for_each_ref(). Filter refs and keep them for * later object processing. */ -static int filter_one(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) +static int filter_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data) { struct ref_filter_cbdata *ref_cbdata = cb_data; struct ref_array_item *ref; - ref = apply_ref_filter(refname, oid, flag, ref_cbdata->filter); + ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter); if (ref) ref_array_append(ref_cbdata->array, ref); @@ -2898,13 +2899,13 @@ struct ref_filter_and_format_cbdata { } internal; }; -static int filter_and_format_one(const char *refname, const char *referent UNUSED, const struct object_id *oid, int flag, void *cb_data) +static int filter_and_format_one(const char *refname, const char *referent, const struct object_id *oid, int flag, void *cb_data) { struct ref_filter_and_format_cbdata *ref_cbdata = cb_data; struct ref_array_item *ref; struct strbuf output = STRBUF_INIT, err = STRBUF_INIT; - ref = apply_ref_filter(refname, oid, flag, ref_cbdata->filter); + ref = apply_ref_filter(refname, referent, oid, flag, ref_cbdata->filter); if (!ref) return 0;