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.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,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 6AE251F8C8 for ; Fri, 17 Sep 2021 02:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242851AbhIQCd5 (ORCPT ); Thu, 16 Sep 2021 22:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242805AbhIQCdu (ORCPT ); Thu, 16 Sep 2021 22:33:50 -0400 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C79AAC061574 for ; Thu, 16 Sep 2021 19:32:28 -0700 (PDT) Received: by mail-io1-xd2a.google.com with SMTP id a22so10365660iok.12 for ; Thu, 16 Sep 2021 19:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=cEf70Fu0Guxs/eGU0I76MyJuJsGAKhkkXdmU/vvjJ58=; b=LgrBMdqFW9J21vQP1TSeXhoiZm2XsDaF22/pVvWMq6MWbrfiAr3rKExaAsZohwhkUg uHE1scBWGLJvYGfXxt0raGd9ukDt8z+UKLZUtx6Di47jI1sFyYntQkFXEBx5Q8jVQxMa 80oaoeyHcVXT4AJ9XaP84wthfpItipIpjgtK1W2wG37ADsVbo5feqVWcEh6pToILc8nW 0RlXUEt2+i8X09jEfA75Oij29meqfLTSoolndTJxPWOUFXYFgPJvVU9M0hLOumRK/jwz +47uNSzTv6oymJH6tY6eh4KbogS+zZ9gd5pRjo6PqUE2rKPs4I06X9svlk+uhbaVg+rY Cs5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=cEf70Fu0Guxs/eGU0I76MyJuJsGAKhkkXdmU/vvjJ58=; b=w6d4cg32j9tVlXJT1NzXSuAyNreHJLXlBpggmGSgT9JScwmvBgTiTgphtDd4ezrpwi YOQkEUedrW+jXy3GnY4ND27SK/Cb/W+2NjXrye36UpkgClA+v9HQ+4wVB0Gdbc4E6Fos c2dqvgaz/ZI2Jkp9xd+73bps3nDuL+7KYHEPZx219HULU7dhQGUH2d7o/7LrTfyS3M+y HStklfSZqD2yFDvRckVEz5KzWqkX5p80wSpDcQ3nqxFzLHaOROfS6Fqe1WFyv5oqwX+v 1mA2uOsmBtH0vJgWndHTcjZ8OYRUAqw/y8E2hIAt8v6NU5MKNG5R0KBdJZvA4deIVYYO vlWg== X-Gm-Message-State: AOAM532oXNVdZwgBJ4HyOc42k1wq5xZqzDl9zNIexDuBNDr3DWEaeIeS OzobAhFEoXf3SFgMBCJvXHwbFkckqoVjMtGu X-Google-Smtp-Source: ABdhPJxKhbWoX+Xcywk2+gRqd0BN6w/fIaHXPVam8dluKAk/T0it698/9pu1n7XsWOsSYSSC6oV0Gg== X-Received: by 2002:a6b:5819:: with SMTP id m25mr6696904iob.105.1631845947925; Thu, 16 Sep 2021 19:32:27 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i14sm2758360iol.27.2021.09.16.19.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 19:32:27 -0700 (PDT) Date: Thu, 16 Sep 2021 22:32:22 -0400 From: Taylor Blau To: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Cc: git@vger.kernel.org, Junio C Hamano , Jeff King , Jonathan Tan , Andrei Rybak Subject: Re: [PATCH v6 14/22] object-file.c: stop dying in parse_loose_header() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Tue, Sep 07, 2021 at 12:58:09PM +0200, Ævar Arnfjörð Bjarmason wrote: > It thus makes sense to further libify the interface so that it stops > calling die() when it encounters OBJ_BAD, and instead rely on its > callers to check the populated "oi->typep". Hmm. I thought we got rid of this behavior in a previous commit? Perhaps I'm thinking of something else, but I would certainly appreciate a clarification :). > @@ -1369,15 +1367,6 @@ int parse_loose_header(const char *hdr, > type = type_from_string_gently(type_buf, type_len, 1); > if (oi->type_name) > strbuf_add(oi->type_name, type_buf, type_len); > - /* > - * Set type to 0 if its an unknown object and > - * we're obtaining the type using '--allow-unknown-type' > - * option. > - */ > - if ((flags & OBJECT_INFO_ALLOW_UNKNOWN_TYPE) && (type < 0)) > - type = 0; > - else if (type < 0) > - die(_("invalid object type")); Good, this part moved to loose_object_info() as you said it would. > @@ -1463,18 +1460,20 @@ static int loose_object_info(struct repository *r, > status = error(_("unable to unpack %s header"), > oid_to_hex(oid)); > } > - > - if (status < 0) { > - /* Do nothing */ > - } else if (hdrbuf.len) { > - if ((status = parse_loose_header(hdrbuf.buf, oi, flags)) < 0) > - status = error(_("unable to parse %s header with --allow-unknown-type"), > - oid_to_hex(oid)); > - } else if ((status = parse_loose_header(hdr, oi, flags)) < 0) { > - status = error(_("unable to parse %s header"), oid_to_hex(oid)); > + if (!status) { > + if (!parse_loose_header(hdrbuf.len ? hdrbuf.buf : hdr, oi)) > + /* > + * oi->{sizep,typep} are meaningless unless > + * parse_loose_header() returns >= 0. > + */ This double negative is a little confusing. Clearer to say: "oi->{size,type}p is meaningless if parse_loose_header() returns < 0"? But I was also a little confused to see that the expression we are checking here is just that parse_loose_header() returned zero. What about other positive values? I think we should either update the comment to say "unless it returns zero" or the conditional expression to check for >= 0. > diff --git a/object-store.h b/object-store.h > index 4064710ae29..584bf5556af 100644 > --- a/object-store.h > +++ b/object-store.h > @@ -500,8 +500,17 @@ int for_each_packed_object(each_packed_object_fn, void *, > int unpack_loose_header(git_zstream *stream, unsigned char *map, > unsigned long mapsize, void *buffer, > unsigned long bufsiz, struct strbuf *hdrbuf); > -int parse_loose_header(const char *hdr, struct object_info *oi, > - unsigned int flags); > + > +/** > + * parse_loose_header() parses the starting " \0" of an > + * object. If it doesn't follow that format -1 is returned. To check > + * the validity of the populate the "typep" in the "struct > + * object_info". It will be OBJ_BAD if the object type is unknown. The > + * parsed can be retrieved via "oi->sizep", and from there > + * passed to unpack_loose_rest(). > + */ > +int parse_loose_header(const char *hdr, struct object_info *oi); OK, I guess this must be what I was confused about earlier (that I thought we didn't support reading typep if returning OBJ_BAD). But it seems odd to me that we would get rid of it elsewhere, yet continue using this pattern here. Or am I mistaken that the two are different? Thanks, Taylor