From patchwork Mon Dec 24 13:24:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10742287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AEEB13B5 for ; Mon, 24 Dec 2018 13:24:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78A3928AF8 for ; Mon, 24 Dec 2018 13:24:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D67728B01; Mon, 24 Dec 2018 13:24:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6837E28B05 for ; Mon, 24 Dec 2018 13:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726373AbeLXNYd (ORCPT ); Mon, 24 Dec 2018 08:24:33 -0500 Received: from a7-10.smtp-out.eu-west-1.amazonses.com ([54.240.7.10]:49728 "EHLO a7-10.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbeLXNYc (ORCPT ); Mon, 24 Dec 2018 08:24:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1545657870; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=vRydY3jQAIZmK8RisuR91RIpW8OU3Kj9+ADG4CFPsyA=; b=Ty+FdA40TzdH0HxMhYRHEvC0sM9Jne1iOYyTCGU+n7kBeQgRol3nMsKcF9I9JK5e OA2obwZMvOIvnGZY59gBBn005TSN5fZB3rp8hPlnD+H0Cc/Rekt8kO/Ac+mTMHESokW 8Jm50KCxNwe3qEAsWD3fvFBY0z7D3pafppVK+EWo= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <01020167e06368eb-576f5c6e-b54d-4169-971d-a1affed08551-000000@eu-west-1.amazonses.com> In-Reply-To: <01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com> References: <01020167e063687c-37a43a09-0a5f-4335-8c21-ec15a0a67882-000000@eu-west-1.amazonses.com> Subject: [PATCH v2 4/6] ref-filter: add deltabase option MIME-Version: 1.0 Date: Mon, 24 Dec 2018 13:24:30 +0000 X-SES-Outgoing: 2018.12.24-54.240.7.10 Feedback-ID: 1.eu-west-1.YYPRFFOog89kHDDPKvTu4MK67j4wW0z7cAgZtFqQH58=:AmazonSES Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add new formatting option: deltabase. If the object is stored as a delta on-disk, this expands to the 40-hex sha1 of the delta base object. Otherwise, expands to the null sha1 (40 zeroes). We have same option in cat-file command. Hopefully, in the end I will remove formatting code from cat-file and reuse formatting parts from ref-filter. Signed-off-by: Olga Telezhnaia --- ref-filter.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- https://github.com/git/git/pull/552 diff --git a/ref-filter.c b/ref-filter.c index 45c558bcbd521..debb8cacad067 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -246,6 +246,18 @@ static int objectsize_atom_parser(const struct ref_format *format, struct used_a return 0; } +static int deltabase_atom_parser(const struct ref_format *format, struct used_atom *atom, + const char *arg, struct strbuf *err) +{ + if (arg) + return strbuf_addf_ret(err, -1, _("%%(deltabase) does not take arguments")); + if (*atom->name == '*') + oi_deref.info.delta_base_sha1 = oi_deref.delta_base_oid.hash; + else + oi.info.delta_base_sha1 = oi.delta_base_oid.hash; + return 0; +} + static int body_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -437,6 +449,7 @@ static struct { { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser }, { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser }, { "objectname", SOURCE_OTHER, FIELD_STR, objectname_atom_parser }, + { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser }, { "tree", SOURCE_OBJ }, { "parent", SOURCE_OBJ }, { "numparent", SOURCE_OBJ, FIELD_ULONG }, @@ -892,7 +905,8 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_ } else if (!strcmp(name, "objectsize")) { v->value = oi->size; v->s = xstrfmt("%"PRIuMAX , (uintmax_t)oi->size); - } + } else if (!strcmp(name, "deltabase")) + v->s = xstrdup(oid_to_hex(&oi->delta_base_oid)); else if (deref) grab_objectname(name, &oi->oid, v, &used_atom[i]); }