From patchwork Sun Jun 27 12:35:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZheNing Hu X-Patchwork-Id: 12346765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE1ACC49EAB for ; Sun, 27 Jun 2021 12:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A00A461AC0 for ; Sun, 27 Jun 2021 12:36:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230282AbhF0MiX (ORCPT ); Sun, 27 Jun 2021 08:38:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230098AbhF0MiT (ORCPT ); Sun, 27 Jun 2021 08:38:19 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74567C061766 for ; Sun, 27 Jun 2021 05:35:54 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id b3so17012824wrm.6 for ; Sun, 27 Jun 2021 05:35:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/+pHTUCgsn/eJhBt7TH6g2FT5CeygqVH9py2mRcVtgU=; b=SaA4xYzYKRjMaPP+DX4wgVzVbvX14FVZ+hQIgo9hHX1fKeNP3KapG3Z4TmoYxqovHb da/a0jDvWMg7CPXfns0iXf5Shz9f5tQf0OW0KD9kH5r+FKBssrs/Vd5qF1dJe8Zt6PDH Ym49PNFHP8ajtfpM2DhVxipvnqt6x6FhUvZEoc69EEFcRG/ok7GA51ZmrYLFvzhnMtA+ mUdmFI197ujDlZvayfONVKDmslQui3LxrCCr8mpsoJFJw6quMOPglel9NIU61YufIVjC mRyvucpnLqihdfZhHepsM8BXl+wdZkONPQl+B7JBcumpjVjaJStreav077Y1WPCBIzWZ KFHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/+pHTUCgsn/eJhBt7TH6g2FT5CeygqVH9py2mRcVtgU=; b=deIh6bCo2HuZJKza6BrDB4wB60nUrzw/UFWwq2f92zFvDjphKtRBT1tWe4F+pjmsHC PGhmzjFZ90VmL7b3IlTypKFT1x/awEEFuxNySzkBZJpAT+u09E5W7OA6ogYjYvtT/KVC yJwHkM5z9svD8OKDv+Ql56QfhriWQmtjNbYB9naVU7Aw9rszdYTJM0aKPHGtQi/FAvQl k6SibseVORjNqfcUjG5TuUPviPFsc/oFsZCVyc0xDtXa25H3fV8iCGvFBzAacJthdzs5 0cTmSQD6nlfgYXmzhOyWKoSl7d0UGEeJkMGyXuHcYs5maQDowyZ3LHIf7gpHmYzfqULi 1m6g== X-Gm-Message-State: AOAM530Ei5Pfs83sQCwM5t2W8fjRXR1SehMFw0HJOGxm0Tzocq0oVd3j RzsrBBykPlq1KEuZDgsfflASNE5L5gw= X-Google-Smtp-Source: ABdhPJysa4Rb4UvhDasUNog1pHGsPQjNMkeH7oJSAXblWdVh39H8XIj2wo64eN56np2EL/IQ4e+Y2Q== X-Received: by 2002:a5d:6d83:: with SMTP id l3mr14342555wrs.91.1624797353104; Sun, 27 Jun 2021 05:35:53 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e8sm2425416wrx.26.2021.06.27.05.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Jun 2021 05:35:52 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Sun, 27 Jun 2021 12:35:36 +0000 Subject: [PATCH v6 01/15] [GSOC] ref-filter: add obj-type check in grab contents Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Christian Couder , Hariom Verma , Bagas Sanjaya , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , ZheNing Hu , ZheNing Hu Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: ZheNing Hu From: ZheNing Hu Only tag and commit objects use `grab_sub_body_contents()` to grab object contents in the current codebase. We want to teach the function to also handle blobs and trees to get their raw data, without parsing a blob (whose contents looks like a commit or a tag) incorrectly as a commit or a tag. Skip the block of code that is specific to handling commits and tags early when the given object is of a wrong type to help later addition to handle other types of objects in this function. Mentored-by: Christian Couder Mentored-by: Hariom Verma Helped-by: Junio C Hamano Signed-off-by: ZheNing Hu --- ref-filter.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ref-filter.c b/ref-filter.c index 4db0e40ff4c..5cee6512fba 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1356,11 +1356,12 @@ static void append_lines(struct strbuf *out, const char *buf, unsigned long size } /* See grab_values */ -static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) +static void grab_sub_body_contents(struct atom_value *val, int deref, struct expand_data *data) { int i; const char *subpos = NULL, *bodypos = NULL, *sigpos = NULL; size_t sublen = 0, bodylen = 0, nonsiglen = 0, siglen = 0; + void *buf = data->content; for (i = 0; i < used_atom_cnt; i++) { struct used_atom *atom = &used_atom[i]; @@ -1371,10 +1372,13 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf) continue; if (deref) name++; - if (strcmp(name, "body") && - !starts_with(name, "subject") && - !starts_with(name, "trailers") && - !starts_with(name, "contents")) + + if ((data->type != OBJ_TAG && + data->type != OBJ_COMMIT) || + (strcmp(name, "body") && + !starts_with(name, "subject") && + !starts_with(name, "trailers") && + !starts_with(name, "contents"))) continue; if (!subpos) find_subpos(buf, @@ -1438,17 +1442,19 @@ static void fill_missing_values(struct atom_value *val) * pointed at by the ref itself; otherwise it is the object the * ref (which is a tag) refers to. */ -static void grab_values(struct atom_value *val, int deref, struct object *obj, void *buf) +static void grab_values(struct atom_value *val, int deref, struct object *obj, struct expand_data *data) { + void *buf = data->content; + switch (obj->type) { case OBJ_TAG: grab_tag_values(val, deref, obj); - grab_sub_body_contents(val, deref, buf); + grab_sub_body_contents(val, deref, data); grab_person("tagger", val, deref, buf); break; case OBJ_COMMIT: grab_commit_values(val, deref, obj); - grab_sub_body_contents(val, deref, buf); + grab_sub_body_contents(val, deref, data); grab_person("author", val, deref, buf); grab_person("committer", val, deref, buf); break; @@ -1678,7 +1684,7 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), oid_to_hex(&oi->oid), ref->refname); } - grab_values(ref->value, deref, *obj, oi->content); + grab_values(ref->value, deref, *obj, oi); } grab_common_values(ref->value, deref, oi);