From patchwork Thu Dec 21 17:07:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13502403 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 4852F59924 for ; Thu, 21 Dec 2023 17:07:23 +0000 (UTC) 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="e49c36UQ" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a2370535060so395167566b.1 for ; Thu, 21 Dec 2023 09:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703178441; x=1703783241; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U8iZ2o6NQNax5wnjEz+RFn73JzmHNezbmKccuAsG8B4=; b=e49c36UQIJ+FhF+58WTlQYL4+qFlqfqXwkizLK32WFneJsP2jdNCp27x168vK6xXio +D0W1nHtWEqEmbB8ahcJxV2x6HPZHvgLN2Ip5Ee050CBgwjtMWR4AO8xY7NU9dHsLmgo ww9qypoAXoSFAeU4iDE5hxhqeuLrf1R8RehrGYEkDdC3W/uLuV6L/lADUF0BCAXc9JOa 4hewvQih1NkmJqZQM1FlED5wfM7boaOEVDV226KwEtREc0570QWK04fmLJDVTlskmFGB dH6YLALZolMYcVcs45nS0TiPG8agi8m5R2AMUPRx3+Yhv85dLkgzp/4nGODdhODlTgbg HAZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703178441; x=1703783241; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U8iZ2o6NQNax5wnjEz+RFn73JzmHNezbmKccuAsG8B4=; b=P/Wr4ivnQcV/qVpyPkoDMC+d1a4nZl0ZJb/s3Hug7xezNc6fOB1/arbjGccYbMxjDB qlkNzb/VFi+Tsf89BkcNsjDV/2cDKtc1i9EcdPp+p7ApeFjPHCfaEmEXPZxU5LFX4s0D CBgk+bCWICDSsjvAfYgkc0R5XBqkO349fm07O4MvCow00J6mk0+IXD/gHGQRQvZrtUTv GP91WidCjZf1+og3g9z4NKZqqu37tg6hC+XPeI7MamI8U/p/7YWqkeFbocz6yQs9tAPr xttSkml9Fq/ltH2fBM9rrrRun+E375O3HNH3ShV3Gx5+32cozrFKTiogUkiiah1pH/5f jdbg== X-Gm-Message-State: AOJu0YzIn05s8inyxfGJd2aSzsusxX1LkNsnr7eeYASyAzW9ZizV4d82 JGp3JFIc+c2o9wlBAv1nYE1Z/jIlsl3xLw== X-Google-Smtp-Source: AGHT+IGIs3j9oojDaa6XqrbsM3hDLYKeTgjlQQmkuwxKwdD6jtoY3cnKGQX/16V0is3g/RZbqoK5bg== X-Received: by 2002:a17:906:2249:b0:a1e:7ddb:29c3 with SMTP id 9-20020a170906224900b00a1e7ddb29c3mr1060867ejr.63.1703178440596; Thu, 21 Dec 2023 09:07:20 -0800 (PST) Received: from localhost.localdomain (h-213.61.124.196.host.de.colt.net. [213.61.124.196]) by smtp.gmail.com with ESMTPSA id en6-20020a17090728c600b00a23577b265csm1163789ejc.173.2023.12.21.09.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:07:20 -0800 (PST) From: Karthik Nayak To: git@vger.kernel.org Cc: gitster@pobox.com, ps@pks.im, christian.couder@gmail.com, Karthik Nayak Subject: [PATCH 1/2] refs: introduce the `refs_single_ref` function Date: Thu, 21 Dec 2023 18:07:14 +0100 Message-Id: <20231221170715.110565-2-karthik.188@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231221170715.110565-1-karthik.188@gmail.com> References: <20231221170715.110565-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We currently provide the functionality to iterate over refs and call a specific callback. This functionality currently supports iterating over the entire "refs/*" space or directly the "HEAD" ref. This leaves operational refs "ORIG_HEAD", "REBASE_HEAD" and so forth behind. In the following commit, we introduce a mechanism to process all the operational refs outside the "refs/*" space. To do this, we require a function similar `refs_head_ref`, which can process a single specified reference. This commit introduces `refs_single_ref` to fill in that gap. Signed-off-by: Karthik Nayak --- refs.c | 12 +++++++++--- refs.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/refs.c b/refs.c index 59fea0d44b..cebc5458d3 100644 --- a/refs.c +++ b/refs.c @@ -1549,18 +1549,24 @@ const char *find_descendant_ref(const char *dirname, return NULL; } -int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +int refs_single_ref(struct ref_store *refs, const char *refname, + 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, refname, RESOLVE_REF_READING, &oid, &flag)) - return fn("HEAD", &oid, flag, cb_data); + return fn(refname, &oid, flag, cb_data); return 0; } +int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +{ + return refs_single_ref(refs, "HEAD", fn, cb_data); +} + int head_ref(each_ref_fn fn, void *cb_data) { return refs_head_ref(get_main_ref_store(the_repository), fn, cb_data); diff --git a/refs.h b/refs.h index 4816e46846..e147f13a85 100644 --- a/refs.h +++ b/refs.h @@ -324,6 +324,8 @@ typedef int each_repo_ref_fn(struct repository *r, * modifies the reference also returns a nonzero value to immediately * stop the iteration. Returned references are sorted. */ +int refs_single_ref(struct ref_store *refs, const char *refname, + each_ref_fn fn, void *cb_data); int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); int refs_for_each_ref(struct ref_store *refs, From patchwork Thu Dec 21 17:07:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karthik Nayak X-Patchwork-Id: 13502404 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 2C6CF627E5 for ; Thu, 21 Dec 2023 17:07:23 +0000 (UTC) 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="MNJyCmwX" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-552d39ac3ccso3919321a12.0 for ; Thu, 21 Dec 2023 09:07:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703178442; x=1703783242; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IIAxp/FD+dMxzIK605pn8H9YJfXne+MzPui1TAupPw8=; b=MNJyCmwXtTLEetCswmzofHfjkrSGeqtYXrHdHfbWRAzp0DMKXk//CZvY1Ew3ylvSaf EOFIHd7kCRtwQeCSkbj7xTscws7eagaXqdoBrpId0OkR6iAIdGEBSBalwu4VwxweiHtE GPqvHwgl2rxrr5e9jcnlSXKeNOE7Ym3pX3rTqCE3/z9pq9ofQpRMrKxCVJE/O33fFG3A NvYKQOwMfxIPA5ml6BgJ/Hdfvki5bO+zsEb36IMF/I+cd9oIAE+vkJ9LrOyR1CfBuP+7 Sl0lXwNvl8H02lbnDuVLzPSFbZkYWD6T4nmfL4UtjYtsBWdmcbREXvQwaq0hbFTbwfLP V1wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703178442; x=1703783242; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IIAxp/FD+dMxzIK605pn8H9YJfXne+MzPui1TAupPw8=; b=Q9+UO4Pf3Ec6pU3/rKc6Zz6Kx0jN5xe8X4V9W8adWFlH23GyvwXQ60IFBHvGGXhZXw F4O2Wgk0ennMZ9T6uUatjUlK0bd/84VxdZntAApVXKNFhDevY8zyENFDKpafX4qvmBut sKPawhC40gUYVZVw0iyQg/ozvkCZqCAtarVTQBpoAJGUECto03+0Q2RiYm7wT3COdh6y 8RC7FbOH9lpAHiL3GZA++H/xe/scZqlYnwKvHKnX1SHRVDqYrBaoY/1ehBJi+hDd8Y0r /htVCn2hxS/bSzgGQMGG2vjct0PcC0MPR96JErG4/kwIzB+mY8Z3KYXyIXAb3K3NSd8L yAOw== X-Gm-Message-State: AOJu0YwAx9K8X770i/OAz8/93ieGPlcZ+10gMQgq794IFszoKQXl2yTJ F5uBfQ8JWwzW+eBbfu12Av0fUMNnZPralA== X-Google-Smtp-Source: AGHT+IGwFyex/iGVy09WSMM/13kou2yXE1tf6KrumFo/0s2MFiaH4IlWE/nAVQ9JpAmN0IYO4byBoA== X-Received: by 2002:a17:906:739c:b0:a1d:2f59:81a4 with SMTP id f28-20020a170906739c00b00a1d2f5981a4mr1088084ejl.62.1703178442095; Thu, 21 Dec 2023 09:07:22 -0800 (PST) Received: from localhost.localdomain (h-213.61.124.196.host.de.colt.net. [213.61.124.196]) by smtp.gmail.com with ESMTPSA id en6-20020a17090728c600b00a23577b265csm1163789ejc.173.2023.12.21.09.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 09:07:21 -0800 (PST) From: Karthik Nayak To: git@vger.kernel.org Cc: gitster@pobox.com, ps@pks.im, christian.couder@gmail.com, Karthik Nayak Subject: [PATCH 2/2] ref-filter: support filtering of operational refs Date: Thu, 21 Dec 2023 18:07:15 +0100 Message-Id: <20231221170715.110565-3-karthik.188@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231221170715.110565-1-karthik.188@gmail.com> References: <20231221170715.110565-1-karthik.188@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 With the upcoming introduction of the reftable backend, it becomes ever so important to provide the necessary tooling for printing all refs associated with a repository. While regular refs stored within the "refs/" namespace are currently supported by multiple commands like git-for-each-ref(1), git-show-ref(1). Neither support printing all the operational refs within the repository. This is crucial because with the reftable backend, all these refs will also move to reftable. It would be necessary to identify all the refs that are stored within the reftable since there is no easy way to do so otherwise. This is because the reftable itself is a binary format and all access will be via git. Unlike the filesystem backend, which allows access directly via the filesystem. This commit adds the necessary code to iterate over operational refs present in a repository and provides a new filter flag 'FILTER_REFS_OPERATIONAL' to iterate over operational refs. This flag can now be used to extend existing git commands to print operational refs. Signed-off-by: Karthik Nayak --- ref-filter.c | 12 ++++++++++++ ref-filter.h | 4 +++- refs.c | 14 ++++++++++++++ refs.h | 3 +++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ref-filter.c b/ref-filter.c index fdaabb5bb4..307a512c27 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2756,6 +2756,10 @@ static int filter_ref_kind(struct ref_filter *filter, const char *refname) filter->kind == FILTER_REFS_REMOTES || filter->kind == FILTER_REFS_TAGS) return filter->kind; + + if (filter->kind & FILTER_REFS_OPERATIONAL) + return filter->kind; + return ref_kind_from_refname(refname); } @@ -3032,6 +3036,14 @@ static int do_filter_refs(struct ref_filter *filter, unsigned int type, each_ref if (!filter->kind) die("filter_refs: invalid type"); else { + size_t i; + if (filter->kind & FILTER_REFS_OPERATIONAL) { + for (i = 0; i < operational_refs_max; i++) { + refs_single_ref(get_main_ref_store(the_repository), + operational_refs[i], fn, cb_data); + } + } + /* * For common cases where we need only branches or remotes or tags, * we only iterate through those refs. If a mix of refs is needed, diff --git a/ref-filter.h b/ref-filter.h index 0ce5af58ab..eec1d29514 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -23,7 +23,9 @@ #define FILTER_REFS_ALL (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \ FILTER_REFS_REMOTES | FILTER_REFS_OTHERS) #define FILTER_REFS_DETACHED_HEAD 0x0020 -#define FILTER_REFS_KIND_MASK (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD) +#define FILTER_REFS_OPERATIONAL 0x0040 +#define FILTER_REFS_KIND_MASK (FILTER_REFS_ALL | FILTER_REFS_DETACHED_HEAD | \ + FILTER_REFS_OPERATIONAL) struct atom_value; struct ref_sorting; diff --git a/refs.c b/refs.c index cebc5458d3..70f6854301 100644 --- a/refs.c +++ b/refs.c @@ -82,6 +82,20 @@ static unsigned char refname_disposition[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 4, 4 }; +const char *operational_refs[] = { + "HEAD", + "ORIG_HEAD", + "REBASE_HEAD", + "REVERT_HEAD", + "CHERRY_PICK_HEAD", + "BISECT_HEAD", + "BISECT_EXPECTED_REV", + "NOTES_MERGE_PARTIAL", + "NOTES_MERGE_REF", +}; + +const int operational_refs_max = ARRAY_SIZE(operational_refs) - 1; + struct ref_namespace_info ref_namespace[] = { [NAMESPACE_HEAD] = { .ref = "HEAD", diff --git a/refs.h b/refs.h index e147f13a85..b01938a91a 100644 --- a/refs.h +++ b/refs.h @@ -15,6 +15,9 @@ int default_ref_storage_format(void); int ref_storage_format_by_name(const char *name); const char *ref_storage_format_to_name(int ref_storage_format); +extern const char *operational_refs[]; +extern const int operational_refs_max; + /* * Resolve a reference, recursively following symbolic refererences. *