From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id E8F5B1F54E for ; Sat, 6 Aug 2022 00:09:37 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.b="xgSAf0xh"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241017AbiHFAJf (ORCPT ); Fri, 5 Aug 2022 20:09:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230490AbiHFAJd (ORCPT ); Fri, 5 Aug 2022 20:09:33 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FB752CE32 for ; Fri, 5 Aug 2022 17:09:32 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id F0F401300D0; Fri, 5 Aug 2022 20:09:30 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=KLSHtHfuvywGYvCuMvXSJjwYF1hWVKsItVs4Cj xE+LA=; b=xgSAf0xhgooIgTZXPk735SjfTIOm6LbRDxWyYl/h9gZSR6o1qGYkR3 XpepYvwhQkfw73wWh/AR9CJdFhgdHGA/mtq0DXGTkR3oxpPhc/OslX5ASBEAgvVm o4f0+XtZbzPQOisZLXPeZDfIXPOz/aEHJYMLf4KNVHe1xUkboZQYY= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id E7D671300CF; Fri, 5 Aug 2022 20:09:30 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [34.145.39.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 202B11300CD; Fri, 5 Aug 2022 20:09:30 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: "Victoria Dye via GitGitGadget" Cc: git@vger.kernel.org, derrickstolee@github.com, shaoxuan.yuan02@gmail.com, newren@gmail.com, Victoria Dye Subject: Re: [PATCH 3/4] cache.h: replace 'index_entry_exists()' with 'index_name_pos_sparse()' References: Date: Fri, 05 Aug 2022 17:09:29 -0700 In-Reply-To: (Victoria Dye via GitGitGadget's message of "Thu, 04 Aug 2022 20:46:06 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 0AB856C6-151C-11ED-A513-CB998F0A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "Victoria Dye via GitGitGadget" writes: > 'index_entry_exists()' was original implemented in 20ec2d034c (reset: make > sparse-aware (except --mixed), 2021-11-29) to allow callers to search for an > index entry without expanding a sparse index. That particular case only > required knowing whether the requested entry existed. This patch expands the > amount of information returned by indicating both 1) whether the entry > exists, and 2) its position (or potential position) in the index. This patch probably should keep index_entry_exists() to potential new callers that may be introduced by contemporary topics in flight, by doing something like the following squashed in. We know that Shaoxuan's series does add a new callsite, which is of a lessor concern as that series may want to be rebased on top of these fixes anyway. But there may be other topics that may want to add new calls for this helper that is more trivially and obviously correct than these four patches, in which case such topics want to proceed independent of these four patches. cache.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git c/cache.h w/cache.h index ba85435fee..039a32a317 100644 --- c/cache.h +++ w/cache.h @@ -839,6 +839,17 @@ int index_name_pos(struct index_state *, const char *name, int namelen); */ int index_name_pos_sparse(struct index_state *, const char *name, int namelen); +/* + * This helper function is only kept to help possible + * contemporary topics in flight. Do not use it in new + * code; use index_name_pos_sparse() instead. + */ +static inline int index_entry_exists(struct index_state *istate, + const char *name, int namelen) +{ + return 0 <= index_name_pos_sparse(istate, name, namelen); +} + /* * Some functions return the negative complement of an insert position when a * precise match was not found but a position was found where the entry would