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: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id B57011F5AE for ; Sun, 30 May 2021 20:54:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbhE3U4W (ORCPT ); Sun, 30 May 2021 16:56:22 -0400 Received: from cloud.peff.net ([104.130.231.41]:41458 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbhE3U4W (ORCPT ); Sun, 30 May 2021 16:56:22 -0400 Received: (qmail 18764 invoked by uid 109); 30 May 2021 20:54:43 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Sun, 30 May 2021 20:54:43 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 21782 invoked by uid 111); 30 May 2021 20:54:43 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Sun, 30 May 2021 16:54:43 -0400 Authentication-Results: peff.net; auth=none Date: Sun, 30 May 2021 16:54:42 -0400 From: Jeff King To: ZheNing Hu Cc: Git List , Junio C Hamano , Christian Couder , Hariom verma , Felipe Contreras , Phillip Wood Subject: Re: [QUESTION] how to quickly find an oid in the git repository Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Sun, May 30, 2021 at 02:53:24PM +0800, ZheNing Hu wrote: > When I tried to make cat-file --batch use ref-filter logic, > I encountered this problem: > > get_oid_with_context() does not really let me know > if an oid is in the git repository. E.g. > > get_oid_with_context(the_repository, > "0000000000000000000000000000000000000000",...) > > will return FOUND. (I really want it to tell me MISSING_OBJECT > or something else) Right, it's purely a name->oid lookup. > On the other hand, oid_object_info_extended() will parse an object > in depth, using it will seriously affect performance. So I want to know > if there is a function that can quickly find the oid? I searched in > `object-name.c`, `object-file.c`, and there seems to be no clue... You should be able to use oid_object_info_extended() here. It will try to do as little work as possible to fulfill the items requested in the object_info struct. So a blank one (or even passing NULL) will return an error if the object doesn't exist, but not otherwise. There's also has_object_file(), which is essentially a wrapper for this. -Peff