From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826517 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 8513A1823 for ; Fri, 22 Feb 2019 16:06:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7322532A2A for ; Fri, 22 Feb 2019 16:06:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67F7132A72; Fri, 22 Feb 2019 16:06:14 +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 0EAC432A2A for ; Fri, 22 Feb 2019 16:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727251AbfBVQGM (ORCPT ); Fri, 22 Feb 2019 11:06:12 -0500 Received: from a7-10.smtp-out.eu-west-1.amazonses.com ([54.240.7.10]:33620 "EHLO a7-10.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727212AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=xoV5L6cupe0t4D+I0/sIpdLnYI17oFDktSbYjdAI3pY=; b=lLlJROcid12C+xr2lNhlir6UVoV2hNMNkBxGYSyV2sF+YkZdHmAtUj0Jc6uHLFs+ FY5mjEEbN80jmM4XZjoJg6/NPloYzFrJPZECEuTNH+AQCVBdLZrOQF2YXWxAAcz/R+I F+TDtUcgoQmuAaAt1iZ84cKeG7p5M28x3A/rBrVk= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> In-Reply-To: References: Subject: [PATCH RFC 01/20] cat-file: reuse struct ref_format MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-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 Start using ref_format struct instead of simple char*. Need that for further reusing of formatting logic from ref-filter. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 0f092382e175c..e5de596611800 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -15,8 +15,10 @@ #include "sha1-array.h" #include "packfile.h" #include "object-store.h" +#include "ref-filter.h" struct batch_options { + struct ref_format format; int enabled; int follow_symlinks; int print_contents; @@ -24,7 +26,6 @@ struct batch_options { int all_objects; int unordered; int cmdmode; /* may be 'w' or 'c' for --filters or --textconv */ - const char *format; }; static const char *force_path; @@ -365,7 +366,7 @@ static void batch_object_write(const char *obj_name, } strbuf_reset(scratch); - strbuf_expand(scratch, opt->format, expand_format, data); + strbuf_expand(scratch, opt->format.format, expand_format, data); strbuf_addch(scratch, '\n'); batch_write(opt, scratch->buf, scratch->len); @@ -491,9 +492,6 @@ static int batch_objects(struct batch_options *opt) int save_warning; int retval = 0; - if (!opt->format) - opt->format = "%(objectname) %(objecttype) %(objectsize)"; - /* * Expand once with our special mark_query flag, which will prime the * object_info to be handed to oid_object_info_extended for each @@ -501,7 +499,7 @@ static int batch_objects(struct batch_options *opt) */ memset(&data, 0, sizeof(data)); data.mark_query = 1; - strbuf_expand(&output, opt->format, expand_format, &data); + strbuf_expand(&output, opt->format.format, expand_format, &data); data.mark_query = 0; strbuf_release(&output); if (opt->cmdmode) @@ -617,7 +615,7 @@ static int batch_option_callback(const struct option *opt, bo->enabled = 1; bo->print_contents = !strcmp(opt->long_name, "batch"); - bo->format = arg; + bo->format.format = arg; return 0; } @@ -626,7 +624,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) { int opt = 0; const char *exp_type = NULL, *obj_name = NULL; - struct batch_options batch = {0}; + struct batch_options batch = { REF_FORMAT_INIT }; int unknown_type = 0; const struct option options[] = { @@ -707,6 +705,9 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) if (batch.buffer_output < 0) batch.buffer_output = batch.all_objects; + if (!batch.format.format) + batch.format.format = "%(objectname) %(objecttype) %(objectsize)"; + if (batch.enabled) return batch_objects(&batch); From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826521 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 CC39E1390 for ; Fri, 22 Feb 2019 16:06:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA2CD32A6B for ; Fri, 22 Feb 2019 16:06:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF0AC32A75; Fri, 22 Feb 2019 16:06:17 +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 4EAAA32A72 for ; Fri, 22 Feb 2019 16:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727043AbfBVQGP (ORCPT ); Fri, 22 Feb 2019 11:06:15 -0500 Received: from a7-19.smtp-out.eu-west-1.amazonses.com ([54.240.7.19]:54602 "EHLO a7-19.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727121AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=lOf5DfQhFVtnFBrBmYKYPOM4s6GiVMFus78kCsuQK5U=; b=hTgkr3f1eNa43cC0hK3No6zQjk7Y+o6EViOuonA/uSEx8pCysUryya3+CpKlgenf F/iEdjdRATSUNa92eo7teym4toih3mrviMnOy2q/mz2XI3wLEVT60Ii8/rmLwCyutze XeRauu3z6KBwoqUgeQ4ws8uGzG7PaHNKsL7M5SPs= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a3c-5b22158a-2d4f-4611-9239-8388af61fd8f-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 02/20] ref-filter: rename field in ref_array_item stuct MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.19 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 Rename objectname field to oid in struct ref_array_item. We usually use objectname word for string representation of object id, so oid explains the content better. Signed-off-by: Olga Telezhnaia --- builtin/ls-remote.c | 2 +- ref-filter.c | 8 ++++---- ref-filter.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 1d7f1f5ce2783..ce79aede726c7 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -143,7 +143,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) const struct ref_array_item *ref = ref_array.items[i]; if (show_symref_target && ref->symref) printf("ref: %s\t%s\n", ref->symref, ref->refname); - printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname); + printf("%s\t%s\n", oid_to_hex(&ref->oid), ref->refname); status = 0; /* we found something */ } diff --git a/ref-filter.c b/ref-filter.c index 422a9c9ae3fd2..736e1f9cc38fc 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1615,7 +1615,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) v->s = xstrdup(buf + 1); } continue; - } else if (!deref && grab_objectname(name, &ref->objectname, v, atom)) { + } else if (!deref && grab_objectname(name, &ref->oid, v, atom)) { continue; } else if (!strcmp(name, "HEAD")) { if (atom->u.head && !strcmp(ref->refname, atom->u.head)) @@ -1661,7 +1661,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) struct atom_value *v = &ref->value[i]; if (v->s == NULL && used_atom[i].source == SOURCE_NONE) return strbuf_addf_ret(err, -1, _("missing object %s for %s"), - oid_to_hex(&ref->objectname), ref->refname); + oid_to_hex(&ref->oid), ref->refname); } if (need_tagged) @@ -1671,7 +1671,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) return 0; - oi.oid = ref->objectname; + oi.oid = ref->oid; if (get_object(ref, 0, &obj, &oi, err)) return -1; @@ -1898,7 +1898,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname, struct ref_array_item *ref; FLEX_ALLOC_STR(ref, refname, refname); - oidcpy(&ref->objectname, oid); + oidcpy(&ref->oid, oid); return ref; } diff --git a/ref-filter.h b/ref-filter.h index 85c8ebc3b904e..4d7d36e9f522d 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -34,7 +34,7 @@ struct ref_sorting { }; struct ref_array_item { - struct object_id objectname; + struct object_id oid; int flag; unsigned int kind; const char *symref; From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826501 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 DDBBE1390 for ; Fri, 22 Feb 2019 16:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC11532A60 for ; Fri, 22 Feb 2019 16:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C063532A6D; Fri, 22 Feb 2019 16:05:58 +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 747D232A18 for ; Fri, 22 Feb 2019 16:05:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727335AbfBVQF5 (ORCPT ); Fri, 22 Feb 2019 11:05:57 -0500 Received: from a7-10.smtp-out.eu-west-1.amazonses.com ([54.240.7.10]:33622 "EHLO a7-10.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727237AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=LoJPuEhVjrFPq+fTOsbdYu/HuviLyxmgK3aWfg3JjyY=; b=M22t/QejshRNNsjMcG4ymDZEcI3nAgLPmxuOPigtzZbIs8KTBbkzUo8gtb2QFqac 8dBrl5Sih7ma9kEBS3s4Zn/y5FD2lYsA2jDNTS+wIbzAU4qhm/YXLwFgI8vggqbA+Fb tX7MGpQSfEYdxrjd3SQ55utKM/Cum5aE6GpI/Y7M= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a49-6f817c1d-5b1c-47ac-98c3-18a124a733eb-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 03/20] ref-filter: add rest formatting option MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-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 rest option that allows to add string into ref_array_item and then put it into specific place of the output. We are using it now in cat-file command: user could put anything in the input after objectname, and it will appear in the output in place of %(rest). Signed-off-by: Olga Telezhnaia --- ref-filter.c | 4 ++++ ref-filter.h | 1 + 2 files changed, 5 insertions(+) -- https://github.com/git/git/pull/568 diff --git a/ref-filter.c b/ref-filter.c index 736e1f9cc38fc..46bf89b3330de 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -485,6 +485,7 @@ static struct { { "if", SOURCE_NONE, FIELD_STR, if_atom_parser }, { "then", SOURCE_NONE }, { "else", SOURCE_NONE }, + { "rest", SOURCE_NONE }, }; #define REF_FORMATTING_STATE_INIT { 0, NULL } @@ -1623,6 +1624,9 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) else v->s = xstrdup(" "); continue; + } else if (starts_with(name, "rest")) { + v->s = xstrdup(ref->request_rest ? ref->request_rest : ""); + continue; } else if (starts_with(name, "align")) { v->handler = align_atom_handler; v->s = xstrdup(""); diff --git a/ref-filter.h b/ref-filter.h index 4d7d36e9f522d..aaeda9f324f5c 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -40,6 +40,7 @@ struct ref_array_item { const char *symref; struct commit *commit; struct atom_value *value; + const char *request_rest; char refname[FLEX_ARRAY]; }; From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826511 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 2F1301390 for ; Fri, 22 Feb 2019 16:06:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BB6A32A6C for ; Fri, 22 Feb 2019 16:06:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 101DC32A4B; Fri, 22 Feb 2019 16:06:05 +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 C0AFA32A35 for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 Received: from a7-11.smtp-out.eu-west-1.amazonses.com ([54.240.7.11]:49300 "EHLO a7-11.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725887AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=ZOXZDhdUH5f0Zd8BS/jGO+2h1aE+cbLM7cVOqwIulXI=; b=XQjqSxv2ROPf9upEqk0ZvNOYhxMk7X0ftXjnQpx1WDdpLyNg7pQ1PrUE4OHRZrg6 K+gy5kukoY36l5/WVPVfJDYoPUXPI+5Hi7uovYI/ItcXKuMSztPSfUwZ7N81OlFV82r 6n92diT7FsA87EeMRSx57Cuo9vUXs6FYrcSOARDQ= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a4f-cdb13ec8-58ea-47aa-a64a-517db120961e-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 04/20] for-each-ref: tests for new atom %(rest) added MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.11 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 tests for new formatting atom %(rest). We need this atom for cat-file command. Signed-off-by: Olga Telezhnaia --- t/t6300-for-each-ref.sh | 6 ++++++ 1 file changed, 6 insertions(+) -- https://github.com/git/git/pull/568 diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 0ffd63071392e..fb361369a037c 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -322,6 +322,12 @@ test_expect_success 'exercise strftime with odd fields' ' test_cmp expected actual ' +test_expect_success 'Check format %(rest) gives empty output ' ' + echo >expected && + git for-each-ref --format="%(rest)" refs/heads >actual && + test_cmp expected actual +' + cat >expected <<\EOF refs/heads/master refs/remotes/origin/master From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826519 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 9112D1390 for ; Fri, 22 Feb 2019 16:06:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E8FF32A65 for ; Fri, 22 Feb 2019 16:06:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D08932A72; Fri, 22 Feb 2019 16:06:16 +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 235D332A6B for ; Fri, 22 Feb 2019 16:06:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727255AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 Received: from a7-20.smtp-out.eu-west-1.amazonses.com ([54.240.7.20]:41306 "EHLO a7-20.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727153AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=6Mz7l0mJFzYR4sM7BCe1lncpcwA+WsRh+NjzZThJTWc=; b=uz9TIxr5JCxrHY2plZUqk4uxKafzqxyV24hwEk6SnOy0Ld9K4m6TnAFhDgrRtTZk eYG3LjAFihODhF55EUevPeYoRMowQloMWgdmusHJM/O08g41f+yflxPx1mvmis3OksN Qpwoou7Q7PAAwVB2B1q0UNIkVORT6UYpFK7k+XJQ= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a4b-b346412b-752e-4068-8a25-62cac2a1f555-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 05/20] cat-file: remove split_on_whitespace MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.20 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 Get rid of split_on_whitespace field in struct expand_data. expand_data may be global further as we use it in ref-filter also, so we need to remove cat-file specific fields from it. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index e5de596611800..60f3839b06f8c 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -203,13 +203,6 @@ struct expand_data { */ int mark_query; - /* - * Whether to split the input on whitespace before feeding it to - * get_sha1; this is decided during the mark_query phase based on - * whether we have a %(rest) token in our format. - */ - int split_on_whitespace; - /* * After a mark_query run, this object_info is set up to be * passed to oid_object_info_extended. It will point to the data @@ -255,9 +248,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, else strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size); } else if (is_atom("rest", atom, len)) { - if (data->mark_query) - data->split_on_whitespace = 1; - else if (data->rest) + if (data->rest) strbuf_addstr(sb, data->rest); } else if (is_atom("deltabase", atom, len)) { if (data->mark_query) @@ -491,6 +482,7 @@ static int batch_objects(struct batch_options *opt) struct expand_data data; int save_warning; int retval = 0; + int is_rest = strstr(opt->format.format, "%(rest)") != NULL || opt->cmdmode; /* * Expand once with our special mark_query flag, which will prime the @@ -502,8 +494,6 @@ static int batch_objects(struct batch_options *opt) strbuf_expand(&output, opt->format.format, expand_format, &data); data.mark_query = 0; strbuf_release(&output); - if (opt->cmdmode) - data.split_on_whitespace = 1; if (opt->all_objects) { struct object_info empty = OBJECT_INFO_INIT; @@ -564,7 +554,7 @@ static int batch_objects(struct batch_options *opt) warn_on_object_refname_ambiguity = 0; while (strbuf_getline(&input, stdin) != EOF) { - if (data.split_on_whitespace) { + if (is_rest) { /* * Split at first whitespace, tying off the beginning * of the string and saving the remainder (or NULL) in From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826499 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 6975F1805 for ; Fri, 22 Feb 2019 16:05:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53BE632A18 for ; Fri, 22 Feb 2019 16:05:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4787F32A7C; Fri, 22 Feb 2019 16:05:58 +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 DF1C532A5A for ; Fri, 22 Feb 2019 16:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727327AbfBVQF5 (ORCPT ); Fri, 22 Feb 2019 11:05:57 -0500 Received: from a7-11.smtp-out.eu-west-1.amazonses.com ([54.240.7.11]:49302 "EHLO a7-11.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727240AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=EtweXjq7Vqyhyvt6aHhpjTCb0ei1HQDZT//IFtbAKeI=; b=HrLd1CpWVOp+541W2cL8WfY2uxMxJ20jARne7QSxXq1UUcmXpJZSG0kgqeFgS4PB s8lRJ8ntLZiAkvZWFKZ3doAq75I3WeH4QLayCSmt6RJ18eUyxcB/znUIVhVjwB1Njte hu7qDuyQc1I2JNqaQ5lPtsicF3tiwHzswYbT6Uw8= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a4f-f02a6509-a3ba-41b0-b768-3d8ba116f526-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 06/20] cat-file: remove mark_query from expand_data MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.11 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 Get rid of mark_query field in struct expand_data. expand_data may be global further as we use it in ref-filter also, so we need to remove cat-file specific fields from it. All globals that I add through this patch will be deleted in the end, so treat it just as the middle step. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 60f3839b06f8c..9bcb02fad1f0d 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -29,6 +29,8 @@ struct batch_options { }; static const char *force_path; +/* Will be deleted at the end of this patch */ +static int mark_query; static int filter_object(const char *path, unsigned mode, const struct object_id *oid, @@ -197,12 +199,6 @@ struct expand_data { const char *rest; struct object_id delta_base_oid; - /* - * If mark_query is true, we do not expand anything, but rather - * just mark the object_info with items we wish to query. - */ - int mark_query; - /* * After a mark_query run, this object_info is set up to be * passed to oid_object_info_extended. It will point to the data @@ -230,20 +226,20 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, struct expand_data *data = vdata; if (is_atom("objectname", atom, len)) { - if (!data->mark_query) + if (!mark_query) strbuf_addstr(sb, oid_to_hex(&data->oid)); } else if (is_atom("objecttype", atom, len)) { - if (data->mark_query) + if (mark_query) data->info.typep = &data->type; else strbuf_addstr(sb, type_name(data->type)); } else if (is_atom("objectsize", atom, len)) { - if (data->mark_query) + if (mark_query) data->info.sizep = &data->size; else strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size); } else if (is_atom("objectsize:disk", atom, len)) { - if (data->mark_query) + if (mark_query) data->info.disk_sizep = &data->disk_size; else strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size); @@ -251,7 +247,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, if (data->rest) strbuf_addstr(sb, data->rest); } else if (is_atom("deltabase", atom, len)) { - if (data->mark_query) + if (mark_query) data->info.delta_base_sha1 = data->delta_base_oid.hash; else strbuf_addstr(sb, @@ -490,9 +486,9 @@ static int batch_objects(struct batch_options *opt) * object. */ memset(&data, 0, sizeof(data)); - data.mark_query = 1; + mark_query = 1; strbuf_expand(&output, opt->format.format, expand_format, &data); - data.mark_query = 0; + mark_query = 0; strbuf_release(&output); if (opt->all_objects) { From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826515 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 368F21390 for ; Fri, 22 Feb 2019 16:06:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 240B732A34 for ; Fri, 22 Feb 2019 16:06:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 181B232A5A; Fri, 22 Feb 2019 16:06:14 +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 AEE8732A59 for ; Fri, 22 Feb 2019 16:06:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726680AbfBVQGM (ORCPT ); Fri, 22 Feb 2019 11:06:12 -0500 Received: from a7-17.smtp-out.eu-west-1.amazonses.com ([54.240.7.17]:35512 "EHLO a7-17.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727224AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=89QMed43/Ml1C85s+0LQkxF2zqNx5ArbMGlaF6s1Uoo=; b=NSJ+MzB3SOnMvpbGjmwRYvTiA2p4bbxx2cx3fz2vMfU07RrAn+rCqj/tuAGnuYl4 mwpZVH+PkEVyotRZ+GNw7NTAtg612dDUmhpRi1K1fD6H1Girl1M640jSQFFI3Q6LTsv hY/LbQk4OEaUu8zISloSpnOEv/ycNnGwSQm1aCaE= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a52-284c872e-17ab-4bfb-befd-2720b48fcbbe-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 07/20] cat-file: remove skip_object_info MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.17 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 Get rid of skip_object_info field in struct expand_data. expand_data may be global further as we use it in ref-filter also, so we need to remove cat-file specific fields from it. All globals that I add through this patch will be deleted in the end, so treat it just as the middle step. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 9bcb02fad1f0d..f6470380f55b3 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -29,8 +29,9 @@ struct batch_options { }; static const char *force_path; -/* Will be deleted at the end of this patch */ +/* Next 2 vars will be deleted at the end of this patch */ static int mark_query; +static int skip_object_info; static int filter_object(const char *path, unsigned mode, const struct object_id *oid, @@ -205,13 +206,6 @@ struct expand_data { * elements above, so you can retrieve the response from there. */ struct object_info info; - - /* - * This flag will be true if the requested batch format and options - * don't require us to call oid_object_info, which can then be - * optimized out. - */ - unsigned skip_object_info : 1; }; static int is_atom(const char *atom, const char *s, int slen) @@ -343,7 +337,7 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt, struct expand_data *data) { - if (!data->skip_object_info && + if (!skip_object_info && oid_object_info_extended(the_repository, &data->oid, &data->info, OBJECT_INFO_LOOKUP_REPLACE) < 0) { printf("%s missing\n", @@ -494,7 +488,7 @@ static int batch_objects(struct batch_options *opt) if (opt->all_objects) { struct object_info empty = OBJECT_INFO_INIT; if (!memcmp(&data.info, &empty, sizeof(empty))) - data.skip_object_info = 1; + skip_object_info = 1; } /* From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826491 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 08FE11823 for ; Fri, 22 Feb 2019 16:05:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB6CF32A5F for ; Fri, 22 Feb 2019 16:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E015C32A74; Fri, 22 Feb 2019 16:05:52 +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 0D06432A76 for ; Fri, 22 Feb 2019 16:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbfBVQFu (ORCPT ); Fri, 22 Feb 2019 11:05:50 -0500 Received: from a7-18.smtp-out.eu-west-1.amazonses.com ([54.240.7.18]:44896 "EHLO a7-18.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbfBVQFs (ORCPT ); Fri, 22 Feb 2019 11:05:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=3fYIMeYyY85cRkCc9W47QCD7qpgLl13vZMOdPBD3upE=; b=dC+x5S+Av3gCHEKQNqcjv+S33hfXB50+kIcFLufNRj8pdZsyjUhbxb633jcBglVK jR2xyk01h0lZ2u+2uQb/VwNE0DYselLf8o7b1FCtZO5UVg3LOHo7Itjd4Xa0oFfemX9 1BGLIAahHEXJX5dBYexWEznOIeVNaubVJsGOrVS4= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a54-e28b7a40-d51c-4dd4-85a3-0eea83d4f0cb-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 08/20] cat-file: remove rest from expand_data MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.18 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 Get rid of rest field in struct expand_data. expand_data may be global further as we use it in ref-filter also, so we need to remove cat-file specific fields from it. All globals that I add through this patch will be deleted in the end, so treat it just as the middle step. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index f6470380f55b3..e52646c0e6b5b 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -29,9 +29,10 @@ struct batch_options { }; static const char *force_path; -/* Next 2 vars will be deleted at the end of this patch */ +/* Next 3 vars will be deleted at the end of this patch */ static int mark_query; static int skip_object_info; +static const char *rest; static int filter_object(const char *path, unsigned mode, const struct object_id *oid, @@ -197,7 +198,6 @@ struct expand_data { enum object_type type; unsigned long size; off_t disk_size; - const char *rest; struct object_id delta_base_oid; /* @@ -238,8 +238,8 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len, else strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size); } else if (is_atom("rest", atom, len)) { - if (data->rest) - strbuf_addstr(sb, data->rest); + if (rest) + strbuf_addstr(sb, rest); } else if (is_atom("deltabase", atom, len)) { if (mark_query) data->info.delta_base_sha1 = data->delta_base_oid.hash; @@ -287,25 +287,25 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d char *contents; unsigned long size; - if (!data->rest) + if (!rest) die("missing path for '%s'", oid_to_hex(oid)); if (opt->cmdmode == 'w') { - if (filter_object(data->rest, 0100644, oid, + if (filter_object(rest, 0100644, oid, &contents, &size)) die("could not convert '%s' %s", - oid_to_hex(oid), data->rest); + oid_to_hex(oid), rest); } else if (opt->cmdmode == 'c') { enum object_type type; if (!textconv_object(the_repository, - data->rest, 0100644, oid, + rest, 0100644, oid, 1, &contents, &size)) contents = read_object_file(oid, &type, &size); if (!contents) die("could not convert '%s' %s", - oid_to_hex(oid), data->rest); + oid_to_hex(oid), rest); } else BUG("invalid cmdmode: %c", opt->cmdmode); batch_write(opt, contents, size); @@ -555,7 +555,7 @@ static int batch_objects(struct batch_options *opt) while (*p && strchr(" \t", *p)) *p++ = '\0'; } - data.rest = p; + rest = p; } batch_one_object(input.buf, &output, opt, &data); From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826505 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 B29591805 for ; Fri, 22 Feb 2019 16:06:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F6F232A66 for ; Fri, 22 Feb 2019 16:06:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9431032A6D; Fri, 22 Feb 2019 16:06:02 +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 4037A32A66 for ; Fri, 22 Feb 2019 16:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726945AbfBVQGB (ORCPT ); Fri, 22 Feb 2019 11:06:01 -0500 Received: from a7-18.smtp-out.eu-west-1.amazonses.com ([54.240.7.18]:44900 "EHLO a7-18.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727239AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=pMcW7SFS23BWx6axMWftypabC6i7tWu2UIxEbCjF9O4=; b=AWox4o5unD5SFHcDAS47R80VX3RE/yiTf31xHYYiAVMYAXWFOQPXhYsa2Zc46XcZ OBfjb2qfgw4Bu6bzadkGGN4XwutW23VOH76xXAKntCGRrPgKhTDYaKiQfw4l7XM/Qy/ Z277nIPQMzGyO9hOUg2eQoe8lP2fb8OUT+IP0GYM= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a58-dc12f07d-00e6-42be-812b-3072d33910d3-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 09/20] ref-filter: make expand_data global MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.18 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 Put struct expand_data into global scope to reuse it in cat-file. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 15 --------------- ref-filter.c | 11 +---------- ref-filter.h | 12 ++++++++++++ 3 files changed, 13 insertions(+), 25 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index e52646c0e6b5b..edf45f078b919 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -193,21 +193,6 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, return 0; } -struct expand_data { - struct object_id oid; - enum object_type type; - unsigned long size; - off_t disk_size; - struct object_id delta_base_oid; - - /* - * After a mark_query run, this object_info is set up to be - * passed to oid_object_info_extended. It will point to the data - * elements above, so you can retrieve the response from there. - */ - struct object_info info; -}; - static int is_atom(const char *atom, const char *s, int slen) { int alen = strlen(atom); diff --git a/ref-filter.c b/ref-filter.c index 46bf89b3330de..65b94ea21e54f 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -64,16 +64,7 @@ struct refname_atom { int lstrip, rstrip; }; -static struct expand_data { - struct object_id oid; - enum object_type type; - unsigned long size; - off_t disk_size; - struct object_id delta_base_oid; - void *content; - - struct object_info info; -} oi, oi_deref; +static struct expand_data oi, oi_deref; /* * An atom is a valid field atom listed below, possibly prefixed with diff --git a/ref-filter.h b/ref-filter.h index aaeda9f324f5c..fc61457d4d660 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -5,6 +5,7 @@ #include "refs.h" #include "commit.h" #include "parse-options.h" +#include "object-store.h" /* Quoting styles */ #define QUOTE_NONE 0 @@ -73,6 +74,17 @@ struct ref_filter { verbose; }; +struct expand_data { + struct object_id oid; + enum object_type type; + unsigned long size; + off_t disk_size; + struct object_id delta_base_oid; + void *content; + + struct object_info info; +}; + struct ref_format { /* * Set these to define the format; make sure you call From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826507 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 771441390 for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64AFE32A5A for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5907A32A73; Fri, 22 Feb 2019 16:06:04 +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 06AFD32A76 for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfBVQGC (ORCPT ); Fri, 22 Feb 2019 11:06:02 -0500 Received: from a7-12.smtp-out.eu-west-1.amazonses.com ([54.240.7.12]:35956 "EHLO a7-12.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727209AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=wLBlMjFTK0KLhr6l5xcKZJalFahfGw5BHhzD1SNAWW8=; b=kd98fYtT16DxdVJAO9iUcAGJBE8hQpntZraJMzXZK5KggxjuKLGeVBb8NHr+DztD E4gwIVv2jhl5bpLKWL+HkpSYjlNORMfewRAB6FNYK4l6j1Zn6P0mTxabdBpv/K/AflQ KbN3wCxoFMs3QyRyzjScjxWC8bZylGR0iTp+MZFw= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a5c-cbf0d726-b7dd-4da8-9cdb-5cc78dc449e9-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 10/20] cat-file: inline stream_blob MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.12 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 Inline function stream_blob, it simplifies further migrating process. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index edf45f078b919..cd9a4447c8da9 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -56,13 +56,6 @@ static int filter_object(const char *path, unsigned mode, return 0; } -static int stream_blob(const struct object_id *oid) -{ - if (stream_blob_to_fd(1, oid, NULL, 0)) - die("unable to stream %s to stdout", oid_to_hex(oid)); - return 0; -} - static int cat_one_file(int opt, const char *exp_type, const char *obj_name, int unknown_type) { @@ -145,8 +138,11 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, return cmd_ls_tree(2, ls_args, NULL); } - if (type == OBJ_BLOB) - return stream_blob(&oid); + if (type == OBJ_BLOB) { + if (stream_blob_to_fd(1, &oid, NULL, 0)) + die("unable to stream %s to stdout", oid_to_hex(&oid)); + return 0; + } buf = read_object_file(&oid, &type, &size); if (!buf) die("Cannot read object %s", obj_name); @@ -168,8 +164,11 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, } else oidcpy(&blob_oid, &oid); - if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) - return stream_blob(&blob_oid); + if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB) { + if (stream_blob_to_fd(1, &blob_oid, NULL, 0)) + die("unable to stream %s to stdout", oid_to_hex(&blob_oid)); + return 0; + } /* * we attempted to dereference a tag to a blob * and failed; there may be new dereference @@ -295,9 +294,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d BUG("invalid cmdmode: %c", opt->cmdmode); batch_write(opt, contents, size); free(contents); - } else { - stream_blob(oid); - } + } else if (stream_blob_to_fd(1, oid, NULL, 0)) + die("unable to stream %s to stdout", oid_to_hex(oid)); } else { enum object_type type; From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826509 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 C1CFC1823 for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD28E32A6D for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0AFB32A73; Fri, 22 Feb 2019 16:06:04 +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 28C0E32A7A for ; Fri, 22 Feb 2019 16:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727325AbfBVQGC (ORCPT ); Fri, 22 Feb 2019 11:06:02 -0500 Received: from a7-17.smtp-out.eu-west-1.amazonses.com ([54.240.7.17]:35510 "EHLO a7-17.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726970AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=YRWWylAc8B99LB3bksVdp5y3LQjYyIMVDE69r4rkBog=; b=SJAvTXcLxOgAYTiXIMBHZb6ZNqE1xi+1WqSd5OLZUGJeb5FMT9DqVDb08vu7kvTA QkkgTpTD6BAq+3QSdFV27S69Z2hZHuDPDTUXwpsEZXG4AI9epaOkDBJfTxY8ce5sUMe v0hf3mNTNK2tkdFjsCBXlltMScyFbDWBMfc84SUs= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a5f-d96e159b-149d-40f9-9789-d0859dc7e2e9-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 11/20] cat-file: move filter_object to diff.c MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.17 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 Move function filter_object to diff.c, like it is done with function textconv_object. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 23 ----------------------- diff.c | 23 +++++++++++++++++++++++ diff.h | 4 ++++ 3 files changed, 27 insertions(+), 23 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index cd9a4447c8da9..41f333b73d851 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -3,7 +3,6 @@ * * Copyright (C) Linus Torvalds, 2005 */ -#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "builtin.h" @@ -34,28 +33,6 @@ static int mark_query; static int skip_object_info; static const char *rest; -static int filter_object(const char *path, unsigned mode, - const struct object_id *oid, - char **buf, unsigned long *size) -{ - enum object_type type; - - *buf = read_object_file(oid, &type, size); - if (!*buf) - return error(_("cannot read object %s '%s'"), - oid_to_hex(oid), path); - if ((type == OBJ_BLOB) && S_ISREG(mode)) { - struct strbuf strbuf = STRBUF_INIT; - if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) { - free(*buf); - *size = strbuf.len; - *buf = strbuf_detach(&strbuf, NULL); - } - } - - return 0; -} - static int cat_one_file(int opt, const char *exp_type, const char *obj_name, int unknown_type) { diff --git a/diff.c b/diff.c index 5306c48652db5..fe7160c86755d 100644 --- a/diff.c +++ b/diff.c @@ -1,6 +1,7 @@ /* * Copyright (C) 2005 Junio C Hamano */ +#define USE_THE_INDEX_COMPATIBILITY_MACROS #include "cache.h" #include "config.h" #include "tempfile.h" @@ -6524,6 +6525,28 @@ int textconv_object(struct repository *r, return 1; } +int filter_object(const char *path, unsigned mode, + const struct object_id *oid, + char **buf, unsigned long *size) +{ + enum object_type type; + + *buf = read_object_file(oid, &type, size); + if (!*buf) + return error(_("cannot read object %s '%s'"), + oid_to_hex(oid), path); + if ((type == OBJ_BLOB) && S_ISREG(mode)) { + struct strbuf strbuf = STRBUF_INIT; + if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) { + free(*buf); + *size = strbuf.len; + *buf = strbuf_detach(&strbuf, NULL); + } + } + + return 0; +} + void setup_diff_pager(struct diff_options *opt) { /* diff --git a/diff.h b/diff.h index b512d0477ac3a..c3709e611870a 100644 --- a/diff.h +++ b/diff.h @@ -476,6 +476,10 @@ int textconv_object(struct repository *repo, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size); +int filter_object(const char *path, unsigned mode, + const struct object_id *oid, + char **buf, unsigned long *size); + int parse_rename_score(const char **cp_p); long parse_algorithm_value(const char *value); From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826523 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 5D9661805 for ; Fri, 22 Feb 2019 16:06:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4590532A30 for ; Fri, 22 Feb 2019 16:06:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A0E132A76; Fri, 22 Feb 2019 16:06:19 +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 D1CD432A30 for ; Fri, 22 Feb 2019 16:06:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727224AbfBVQGQ (ORCPT ); Fri, 22 Feb 2019 11:06:16 -0500 Received: from a7-17.smtp-out.eu-west-1.amazonses.com ([54.240.7.17]:35514 "EHLO a7-17.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727039AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=Os6L/s3RhrXJdYF+q+g8N/I/qRtik+YGNfclqaZs9iE=; b=FURziE/2qyJ7TqaCilYQTjaNJTdSzWsLZ5ZnTE+57tW5Z9zjhondmwff0J7jSk8A JVieY2QBCERSdd+dQBnNNEgRXbFX6bDLx/xQ+EDRxSf+EmpS1CXK0jlU+l1yYJUa9wQ hFPJTBPkhy96T9XemwA5KCHFeYwrS62THSN9pR2w= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a63-de2f8b31-3571-4bf8-9663-c8c576c2d5ff-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 12/20] cat-file: remove batch_write function MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.17 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 Correct me if I am wrong, but it was not really good idea to implement batch_write in cmd_cat_file. Maybe it's a good task for newbies to add flag (whether we accept batch write or not) to write_or_die? Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 41f333b73d851..a4e56762f9e56 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -226,15 +226,6 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data) return end - start + 1; } -static void batch_write(struct batch_options *opt, const void *data, int len) -{ - if (opt->buffer_output) { - if (fwrite(data, 1, len, stdout) != len) - die_errno("unable to write to stdout"); - } else - write_or_die(1, data, len); -} - static void print_object_or_die(struct batch_options *opt, struct expand_data *data) { const struct object_id *oid = &data->oid; @@ -269,7 +260,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d oid_to_hex(oid), rest); } else BUG("invalid cmdmode: %c", opt->cmdmode); - batch_write(opt, contents, size); + write_or_die(1, contents, size); free(contents); } else if (stream_blob_to_fd(1, oid, NULL, 0)) die("unable to stream %s to stdout", oid_to_hex(oid)); @@ -287,7 +278,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d if (data->info.sizep && size != data->size) die("object %s changed size!?", oid_to_hex(oid)); - batch_write(opt, contents, size); + write_or_die(1, contents, size); free(contents); } } @@ -309,11 +300,11 @@ static void batch_object_write(const char *obj_name, strbuf_reset(scratch); strbuf_expand(scratch, opt->format.format, expand_format, data); strbuf_addch(scratch, '\n'); - batch_write(opt, scratch->buf, scratch->len); + write_or_die(1, scratch->buf, scratch->len); if (opt->print_contents) { print_object_or_die(opt, data); - batch_write(opt, "\n", 1); + write_or_die(1, "\n", 1); } } From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826503 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 1F4211805 for ; Fri, 22 Feb 2019 16:06:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AF7632A5F for ; Fri, 22 Feb 2019 16:06:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3C3032A4B; Fri, 22 Feb 2019 16:06:00 +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 CEA6F32A5F for ; Fri, 22 Feb 2019 16:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727324AbfBVQF4 (ORCPT ); Fri, 22 Feb 2019 11:05:56 -0500 Received: from a7-11.smtp-out.eu-west-1.amazonses.com ([54.240.7.11]:49312 "EHLO a7-11.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727249AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=2+kM/udfUYvphRhw5F6t7IYqjBoZ5loOdHYwugsK63c=; b=HL4mQEUZVkeXNtRGaY1aiiWkNZeSVZ/swl3Ithk/rNe+h0O/ZB2ioeYa/5YILt6p AiWcFS+ID8ihraQ6c5wZM/yWqzIfaKbLMP+1wsxQ0DbJBqpjRiezJLslYDS3TgKhDwk R1uDkyKd1lRejsdr85uVSbjMSL8eu+Rd43nesPNY= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a66-0b8bf78d-6879-41da-b5e6-de6e7edbe71a-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 13/20] cat-file: rewrite print_object_or_die MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.11 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 In the next commit I will move function print_object_or_die to ref-filter, and I decided to rewrite it a little so that it becomes much more flatten and a little bit shorter. I also changed input parameters, it allows me to move it to ref-filter, ref-filter knows nothing about batch_options. The logic of the function remains the same. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 72 +++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index a4e56762f9e56..2066ff1e697e4 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -226,50 +226,17 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data) return end - start + 1; } -static void print_object_or_die(struct batch_options *opt, struct expand_data *data) +static void print_object_or_die(struct expand_data *data, int cmdmode, + int buffered, const char *rest) { const struct object_id *oid = &data->oid; + unsigned long size; + char *contents; assert(data->info.typep); - if (data->type == OBJ_BLOB) { - if (opt->buffer_output) - fflush(stdout); - if (opt->cmdmode) { - char *contents; - unsigned long size; - - if (!rest) - die("missing path for '%s'", oid_to_hex(oid)); - - if (opt->cmdmode == 'w') { - if (filter_object(rest, 0100644, oid, - &contents, &size)) - die("could not convert '%s' %s", - oid_to_hex(oid), rest); - } else if (opt->cmdmode == 'c') { - enum object_type type; - if (!textconv_object(the_repository, - rest, 0100644, oid, - 1, &contents, &size)) - contents = read_object_file(oid, - &type, - &size); - if (!contents) - die("could not convert '%s' %s", - oid_to_hex(oid), rest); - } else - BUG("invalid cmdmode: %c", opt->cmdmode); - write_or_die(1, contents, size); - free(contents); - } else if (stream_blob_to_fd(1, oid, NULL, 0)) - die("unable to stream %s to stdout", oid_to_hex(oid)); - } - else { + if (data->type != OBJ_BLOB) { enum object_type type; - unsigned long size; - void *contents; - contents = read_object_file(oid, &type, &size); if (!contents) die("object %s disappeared", oid_to_hex(oid)); @@ -280,7 +247,34 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d write_or_die(1, contents, size); free(contents); + return; + } + + if (buffered) + fflush(stdout); + if (!cmdmode) { + if (stream_blob_to_fd(1, oid, NULL, 0)) + die("unable to stream %s to stdout", oid_to_hex(oid)); + return; } + + if (!rest) + die("missing path for '%s'", oid_to_hex(oid)); + + if (cmdmode == 'w') { + if (filter_object(rest, 0100644, oid, &contents, &size)) + die("could not convert '%s' %s", oid_to_hex(oid), rest); + } else if (cmdmode == 'c') { + enum object_type type; + if (!textconv_object(the_repository, rest, 0100644, oid, 1, + &contents, &size)) + contents = read_object_file(oid, &type, &size); + if (!contents) + die("could not convert '%s' %s", oid_to_hex(oid), rest); + } else + BUG("invalid cmdmode: %c", cmdmode); + write_or_die(1, contents, size); + free(contents); } static void batch_object_write(const char *obj_name, @@ -303,7 +297,7 @@ static void batch_object_write(const char *obj_name, write_or_die(1, scratch->buf, scratch->len); if (opt->print_contents) { - print_object_or_die(opt, data); + print_object_or_die(data, opt->cmdmode, opt->buffer_output, rest); write_or_die(1, "\n", 1); } } From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826485 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 CEF121390 for ; Fri, 22 Feb 2019 16:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B10EC32A6E for ; Fri, 22 Feb 2019 16:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A56B332A66; Fri, 22 Feb 2019 16:05:49 +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 16E4432A24 for ; Fri, 22 Feb 2019 16:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727276AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 Received: from a7-12.smtp-out.eu-west-1.amazonses.com ([54.240.7.12]:35960 "EHLO a7-12.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727228AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=KIwMEX8isseoq2YJTm0KpxNxDPKxdNGF0UHcKIjFw7Q=; b=ZbqcHQaUWcwfAkTuVdkQWXL9GodYVhyRSvQ/MPhHQci98s8QmKOxSoBejI4Cpgt8 fN5l8LvOmdDcJORv6CbnuhKxGa/Aum6ITyjzLwQkmRX0SCYVvQ4crO9/tFZ/63FDbe3 o+gtlRW1YGAq55MKLhjdMzHFjy2cycgIZKngxWmU= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a66-7e179c2f-b7d4-4d4d-935f-ff1431f86a77-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 14/20] cat-file: move print_object_or_die to ref-filter MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.12 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 Move printing function to ref-filter, it is logical because we move all formatting/printing logic to ref-filter. It could be much better if we embed this logic into current flows in ref-filter, but it looks like the task for another patch. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 51 --------------------------------------------- ref-filter.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ ref-filter.h | 3 +++ 3 files changed, 55 insertions(+), 51 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 2066ff1e697e4..6c0cbf71f0f0c 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -226,57 +226,6 @@ static size_t expand_format(struct strbuf *sb, const char *start, void *data) return end - start + 1; } -static void print_object_or_die(struct expand_data *data, int cmdmode, - int buffered, const char *rest) -{ - const struct object_id *oid = &data->oid; - unsigned long size; - char *contents; - - assert(data->info.typep); - - if (data->type != OBJ_BLOB) { - enum object_type type; - contents = read_object_file(oid, &type, &size); - if (!contents) - die("object %s disappeared", oid_to_hex(oid)); - if (type != data->type) - die("object %s changed type!?", oid_to_hex(oid)); - if (data->info.sizep && size != data->size) - die("object %s changed size!?", oid_to_hex(oid)); - - write_or_die(1, contents, size); - free(contents); - return; - } - - if (buffered) - fflush(stdout); - if (!cmdmode) { - if (stream_blob_to_fd(1, oid, NULL, 0)) - die("unable to stream %s to stdout", oid_to_hex(oid)); - return; - } - - if (!rest) - die("missing path for '%s'", oid_to_hex(oid)); - - if (cmdmode == 'w') { - if (filter_object(rest, 0100644, oid, &contents, &size)) - die("could not convert '%s' %s", oid_to_hex(oid), rest); - } else if (cmdmode == 'c') { - enum object_type type; - if (!textconv_object(the_repository, rest, 0100644, oid, 1, - &contents, &size)) - contents = read_object_file(oid, &type, &size); - if (!contents) - die("could not convert '%s' %s", oid_to_hex(oid), rest); - } else - BUG("invalid cmdmode: %c", cmdmode); - write_or_die(1, contents, size); - free(contents); -} - static void batch_object_write(const char *obj_name, struct strbuf *scratch, struct batch_options *opt, diff --git a/ref-filter.c b/ref-filter.c index 65b94ea21e54f..68d9741a56468 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -20,6 +20,7 @@ #include "commit-slab.h" #include "commit-graph.h" #include "commit-reach.h" +#include "streaming.h" static struct ref_msg { const char *gone; @@ -2366,3 +2367,54 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) return 0; } + +void print_object_or_die(struct expand_data *data, int cmdmode, + int buffered, const char *rest) +{ + const struct object_id *oid = &data->oid; + unsigned long size; + char *contents; + + assert(data->info.typep); + + if (data->type != OBJ_BLOB) { + enum object_type type; + contents = read_object_file(oid, &type, &size); + if (!contents) + die("object %s disappeared", oid_to_hex(oid)); + if (type != data->type) + die("object %s changed type!?", oid_to_hex(oid)); + if (data->info.sizep && size != data->size) + die("object %s changed size!?", oid_to_hex(oid)); + + write_or_die(1, contents, size); + free(contents); + return; + } + + if (buffered) + fflush(stdout); + if (!cmdmode) { + if (stream_blob_to_fd(1, oid, NULL, 0)) + die("unable to stream %s to stdout", oid_to_hex(oid)); + return; + } + + if (!rest) + die("missing path for '%s'", oid_to_hex(oid)); + + if (cmdmode == 'w') { + if (filter_object(rest, 0100644, oid, &contents, &size)) + die("could not convert '%s' %s", oid_to_hex(oid), rest); + } else if (cmdmode == 'c') { + enum object_type type; + if (!textconv_object(the_repository, rest, 0100644, oid, 1, + &contents, &size)) + contents = read_object_file(oid, &type, &size); + if (!contents) + die("could not convert '%s' %s", oid_to_hex(oid), rest); + } else + BUG("invalid cmdmode: %c", cmdmode); + write_or_die(1, contents, size); + free(contents); +} diff --git a/ref-filter.h b/ref-filter.h index fc61457d4d660..3422f39e64b5b 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -157,4 +157,7 @@ struct ref_array_item *ref_array_push(struct ref_array *array, const char *refname, const struct object_id *oid); +void print_object_or_die(struct expand_data *data, int cmdmode, + int buffered, const char *rest); + #endif /* REF_FILTER_H */ From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826513 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 9C1591390 for ; Fri, 22 Feb 2019 16:06:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A16B32A6C for ; Fri, 22 Feb 2019 16:06:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EADC32A7B; Fri, 22 Feb 2019 16:06:07 +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 31F4632A6C for ; Fri, 22 Feb 2019 16:06:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbfBVQGG (ORCPT ); Fri, 22 Feb 2019 11:06:06 -0500 Received: from a7-17.smtp-out.eu-west-1.amazonses.com ([54.240.7.17]:35508 "EHLO a7-17.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727156AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=HHIaEKc3cOW1xLxquc2x2Tl+9OeDk+HErwTQLdy9mz4=; b=K3PfZKHtbR8Fj0s9TRgb42dAEUzk9fqWXTBEWobAlME+0rIPcNSu6S8FgTEyQwMy TNoqagPMQ79sh9i6722Stv1QlolDi/BHDP4FOKlXHZFBBnZejLdHnqGtp3q+w/pMtJZ 8dN2w4iHhE+PQHXfFtrvmWlvNLDA1yg4NfMAzfLA= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a6a-10a18ba5-b1f4-4514-b76d-9b213d6c51e8-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 15/20] ref-filter: add raw formatting option MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.17 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 %(raw), it means that we want to print all the file without any changes. It will help further to migrate all cat-file formatting logic from cat-file to ref-filter. For now, we just treat it as the empty string. Signed-off-by: Olga Telezhnaia --- ref-filter.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) -- https://github.com/git/git/pull/568 diff --git a/ref-filter.c b/ref-filter.c index 68d9741a56468..bb963a4110fb2 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -208,6 +208,15 @@ static int remote_ref_atom_parser(const struct ref_format *format, struct used_a return 0; } +static int raw_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, _("%%(raw) does not take arguments")); + oi.info.typep = &oi.type; + return 0; +} + static int objecttype_atom_parser(const struct ref_format *format, struct used_atom *atom, const char *arg, struct strbuf *err) { @@ -478,6 +487,7 @@ static struct { { "then", SOURCE_NONE }, { "else", SOURCE_NONE }, { "rest", SOURCE_NONE }, + { "raw", SOURCE_NONE, FIELD_STR, raw_atom_parser }, }; #define REF_FORMATTING_STATE_INIT { 0, NULL } @@ -1619,6 +1629,9 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err) } else if (starts_with(name, "rest")) { v->s = xstrdup(ref->request_rest ? ref->request_rest : ""); continue; + } else if (!strcmp(name, "raw")) { + v->s = xstrdup(""); + continue; } else if (starts_with(name, "align")) { v->handler = align_atom_handler; v->s = xstrdup(""); From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826495 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 3ED8C1390 for ; Fri, 22 Feb 2019 16:05:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D22332A24 for ; Fri, 22 Feb 2019 16:05:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B83332A5C; Fri, 22 Feb 2019 16:05:55 +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 B9BFA32A73 for ; Fri, 22 Feb 2019 16:05:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727274AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 Received: from a7-11.smtp-out.eu-west-1.amazonses.com ([54.240.7.11]:49306 "EHLO a7-11.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=rLV96qobmExuILgdvgGJ4839LLTtmtzcsQ2H1XhCeGs=; b=L0uMBt+VtZiwvDME1Ud05A9Ze5vZ3iVrz3UPe3N32BwkFNVojdYth9/Td7B7MBD6 fLK46humNEXSh1OwLf8LrReRwd4R4FwNUaMeImODzBLIxcAMZR8FqURmkkI//QPl6TY HG7+0Ddy5wuv7EiynAwGtKTBEcXTWkA/nJGY/gQg= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a6b-667faefc-a0bc-4243-b846-b78076936a74-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 16/20] for-each-ref: tests for new atom %(raw) added MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.11 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 tests for new formatting atom %(raw). We need this atom for cat-file command. Signed-off-by: Olga Telezhnaia --- t/t6300-for-each-ref.sh | 6 ++++++ 1 file changed, 6 insertions(+) -- https://github.com/git/git/pull/568 diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index fb361369a037c..6a5626d537f35 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -328,6 +328,12 @@ test_expect_success 'Check format %(rest) gives empty output ' ' test_cmp expected actual ' +test_expect_success 'Check format %(raw) gives empty output ' ' + echo >expected && + git for-each-ref --format="%(raw)" refs/heads >actual && + test_cmp expected actual +' + cat >expected <<\EOF refs/heads/master refs/remotes/origin/master From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826493 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 81EBD1390 for ; Fri, 22 Feb 2019 16:05:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B19932A72 for ; Fri, 22 Feb 2019 16:05:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FA3D32A73; Fri, 22 Feb 2019 16:05:54 +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 93BED32A24 for ; Fri, 22 Feb 2019 16:05:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727285AbfBVQFt (ORCPT ); Fri, 22 Feb 2019 11:05:49 -0500 Received: from a7-18.smtp-out.eu-west-1.amazonses.com ([54.240.7.18]:44892 "EHLO a7-18.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727208AbfBVQFs (ORCPT ); Fri, 22 Feb 2019 11:05:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=F6iVVCro+xUkL54cvQwGTe37xwISJ+94frnoqk+q+nw=; b=DhCYc/dhi0LpCOWwVi0fttUlSbowflI/9pLyFLULs8g9v7/UirJCJl6zBM0EoM6x IBGcfRGZkxrVcid1nqc+9U2nNuvp5gRWS2gyUyJ5oar8L2icYt65EzxuumeN7nR5Pjp xNG300C2yWdVaeZjS0ibMii/BeJegp1f2S1EBN58= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a72-d28a8c0c-7594-4330-8c1c-e497622a8fd9-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 17/20] cat-file: reuse ref-filter formatting logic MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.18 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 Start using general ref-filter formatting logic in cat-file. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 111 ++++++++------------------------------------- ref-filter.c | 39 +++++++++++----- ref-filter.h | 4 +- 3 files changed, 49 insertions(+), 105 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 6c0cbf71f0f0c..6fa100d1bea72 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -28,9 +28,7 @@ struct batch_options { }; static const char *force_path; -/* Next 3 vars will be deleted at the end of this patch */ -static int mark_query; -static int skip_object_info; +/* global rest will be deleted at the end of this patch */ static const char *rest; static int cat_one_file(int opt, const char *exp_type, const char *obj_name, @@ -169,84 +167,29 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, return 0; } -static int is_atom(const char *atom, const char *s, int slen) -{ - int alen = strlen(atom); - return alen == slen && !memcmp(atom, s, alen); -} - -static void expand_atom(struct strbuf *sb, const char *atom, int len, - void *vdata) -{ - struct expand_data *data = vdata; - - if (is_atom("objectname", atom, len)) { - if (!mark_query) - strbuf_addstr(sb, oid_to_hex(&data->oid)); - } else if (is_atom("objecttype", atom, len)) { - if (mark_query) - data->info.typep = &data->type; - else - strbuf_addstr(sb, type_name(data->type)); - } else if (is_atom("objectsize", atom, len)) { - if (mark_query) - data->info.sizep = &data->size; - else - strbuf_addf(sb, "%"PRIuMAX , (uintmax_t)data->size); - } else if (is_atom("objectsize:disk", atom, len)) { - if (mark_query) - data->info.disk_sizep = &data->disk_size; - else - strbuf_addf(sb, "%"PRIuMAX, (uintmax_t)data->disk_size); - } else if (is_atom("rest", atom, len)) { - if (rest) - strbuf_addstr(sb, rest); - } else if (is_atom("deltabase", atom, len)) { - if (mark_query) - data->info.delta_base_sha1 = data->delta_base_oid.hash; - else - strbuf_addstr(sb, - oid_to_hex(&data->delta_base_oid)); - } else - die("unknown format element: %.*s", len, atom); -} - -static size_t expand_format(struct strbuf *sb, const char *start, void *data) -{ - const char *end; - - if (*start != '(') - return 0; - end = strchr(start + 1, ')'); - if (!end) - die("format element '%s' does not end in ')'", start); - - expand_atom(sb, start + 1, end - start - 1, data); - - return end - start + 1; -} - static void batch_object_write(const char *obj_name, struct strbuf *scratch, struct batch_options *opt, struct expand_data *data) { - if (!skip_object_info && - oid_object_info_extended(the_repository, &data->oid, &data->info, - OBJECT_INFO_LOOKUP_REPLACE) < 0) { - printf("%s missing\n", - obj_name ? obj_name : oid_to_hex(&data->oid)); + struct strbuf err = STRBUF_INIT; + struct ref_array_item item = { data->oid }; + item.request_rest = rest; + item.check_obj = 1; + strbuf_reset(scratch); + + if (format_ref_array_item(&item, &opt->format, scratch, &err)) { + printf("%s missing\n", obj_name ? obj_name : oid_to_hex(&item.oid)); fflush(stdout); return; } - strbuf_reset(scratch); - strbuf_expand(scratch, opt->format.format, expand_format, data); strbuf_addch(scratch, '\n'); write_or_die(1, scratch->buf, scratch->len); + strbuf_release(&err); if (opt->print_contents) { - print_object_or_die(data, opt->cmdmode, opt->buffer_output, rest); + print_raw_object_or_die(&item, opt->cmdmode, opt->buffer_output); write_or_die(1, "\n", 1); } } @@ -367,30 +310,7 @@ static int batch_objects(struct batch_options *opt) int save_warning; int retval = 0; int is_rest = strstr(opt->format.format, "%(rest)") != NULL || opt->cmdmode; - - /* - * Expand once with our special mark_query flag, which will prime the - * object_info to be handed to oid_object_info_extended for each - * object. - */ memset(&data, 0, sizeof(data)); - mark_query = 1; - strbuf_expand(&output, opt->format.format, expand_format, &data); - mark_query = 0; - strbuf_release(&output); - - if (opt->all_objects) { - struct object_info empty = OBJECT_INFO_INIT; - if (!memcmp(&data.info, &empty, sizeof(empty))) - skip_object_info = 1; - } - - /* - * If we are printing out the object, then always fill in the type, - * since we will want to decide whether or not to stream. - */ - if (opt->print_contents) - data.info.typep = &data.type; if (opt->all_objects) { struct object_cb_data cb; @@ -581,6 +501,15 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) if (!batch.format.format) batch.format.format = "%(objectname) %(objecttype) %(objectsize)"; + if (batch.print_contents) { + const char *contents = "%(raw)"; + char *format = (char *)calloc(strlen(batch.format.format) + strlen(contents) + 1, 1); + memcpy(format, batch.format.format, strlen(batch.format.format)); + memcpy(format + strlen(format), contents, strlen(contents)); + batch.format.format = format; + } + if (verify_ref_format(&batch.format)) + usage_with_options(cat_file_usage, options); if (batch.enabled) return batch_objects(&batch); diff --git a/ref-filter.c b/ref-filter.c index bb963a4110fb2..45d163246e3f3 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2231,6 +2231,7 @@ int format_ref_array_item(struct ref_array_item *info, { const char *cp, *sp, *ep; struct ref_formatting_state state = REF_FORMATTING_STATE_INIT; + struct object_info empty = OBJECT_INFO_INIT; state.quote_style = format->quote_style; push_stack_element(&state.stack); @@ -2253,6 +2254,11 @@ int format_ref_array_item(struct ref_array_item *info, sp = cp + strlen(cp); append_literal(cp, sp, &state); } + if (info->check_obj && + oid_object_info_extended(the_repository, &info->oid, &empty, + OBJECT_INFO_LOOKUP_REPLACE)) + return strbuf_addf_ret(error_buf, -1, _("%s missing\n"), + oid_to_hex(&info->oid)); if (format->need_color_reset_at_eol) { struct atom_value resetv; resetv.s = GIT_COLOR_RESET; @@ -2381,23 +2387,32 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) return 0; } -void print_object_or_die(struct expand_data *data, int cmdmode, - int buffered, const char *rest) +/* + * TODO: add support of %(*raw). Need to switch between oi and oi_deref for that. + * TODO: split logic and printing (as it is done in format_ref_array_item and + * show_ref_array_item). + * TODO: rewrite print_object_or_die so that it will reuse result of general + * oid_object_info_extended call. + * TODO: embed this function into general ref_filter flow, make it static. + * That will allow other ref-filter users to print raw file + * (now only cat_file can use it). + */ +void print_raw_object_or_die(struct ref_array_item *item, int cmdmode, int buffered) { - const struct object_id *oid = &data->oid; + const struct object_id *oid = &oi.oid; unsigned long size; char *contents; - assert(data->info.typep); + assert(oi.info.typep); - if (data->type != OBJ_BLOB) { + if (oi.type != OBJ_BLOB) { enum object_type type; contents = read_object_file(oid, &type, &size); if (!contents) die("object %s disappeared", oid_to_hex(oid)); - if (type != data->type) + if (type != oi.type) die("object %s changed type!?", oid_to_hex(oid)); - if (data->info.sizep && size != data->size) + if (oi.info.sizep && size != oi.size) die("object %s changed size!?", oid_to_hex(oid)); write_or_die(1, contents, size); @@ -2413,19 +2428,19 @@ void print_object_or_die(struct expand_data *data, int cmdmode, return; } - if (!rest) + if (!item->request_rest) die("missing path for '%s'", oid_to_hex(oid)); if (cmdmode == 'w') { - if (filter_object(rest, 0100644, oid, &contents, &size)) - die("could not convert '%s' %s", oid_to_hex(oid), rest); + if (filter_object(item->request_rest, 0100644, oid, &contents, &size)) + die("could not convert '%s' %s", oid_to_hex(oid), item->request_rest); } else if (cmdmode == 'c') { enum object_type type; - if (!textconv_object(the_repository, rest, 0100644, oid, 1, + if (!textconv_object(the_repository, item->request_rest, 0100644, oid, 1, &contents, &size)) contents = read_object_file(oid, &type, &size); if (!contents) - die("could not convert '%s' %s", oid_to_hex(oid), rest); + die("could not convert '%s' %s", oid_to_hex(oid), item->request_rest); } else BUG("invalid cmdmode: %c", cmdmode); write_or_die(1, contents, size); diff --git a/ref-filter.h b/ref-filter.h index 3422f39e64b5b..e8cd97a49632c 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -42,6 +42,7 @@ struct ref_array_item { struct commit *commit; struct atom_value *value; const char *request_rest; + int check_obj; char refname[FLEX_ARRAY]; }; @@ -157,7 +158,6 @@ struct ref_array_item *ref_array_push(struct ref_array *array, const char *refname, const struct object_id *oid); -void print_object_or_die(struct expand_data *data, int cmdmode, - int buffered, const char *rest); +void print_raw_object_or_die(struct ref_array_item *item, int cmdmode, int buffered); #endif /* REF_FILTER_H */ From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826487 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 2747D1390 for ; Fri, 22 Feb 2019 16:05:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0939E32A6C for ; Fri, 22 Feb 2019 16:05:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F22B532A73; Fri, 22 Feb 2019 16:05:50 +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 6D07832A72 for ; Fri, 22 Feb 2019 16:05:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727294AbfBVQFt (ORCPT ); Fri, 22 Feb 2019 11:05:49 -0500 Received: from a7-20.smtp-out.eu-west-1.amazonses.com ([54.240.7.20]:41308 "EHLO a7-20.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727145AbfBVQFs (ORCPT ); Fri, 22 Feb 2019 11:05:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=nI4xNrV9odkN5qeCI6Lq6X6D7q9HrKyjucidS8bLDqI=; b=P+C5TNInw+8aMUv5hlX5k9WXZ9Rx8A5E2RLM7/BeB3yOjq4NBfvcXybwk8GMrrro JAPz1RMepQQow/YXl4JhwwJNXyPF/vvrdFNRT4rol12Ub460WrALe4k3AgVfMuenUon ioL4TGj/u+lUwqTPkvkEHXDBXHPGi/+ikXRpHhrw= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a72-81347643-bf78-47fe-8cee-d22ce2a18db0-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 18/20] cat-file: get rid of expand_data MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.20 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 Clean up cat-file after moving all formatting logic to ref-filter. We do not need to use struct expand_data anymore. Signed-off-by: Olga Telezhnaia --- builtin/cat-file.c | 43 +++++++++++++++++++++++-------------------- ref-filter.c | 11 ++++++++++- ref-filter.h | 12 ------------ 3 files changed, 33 insertions(+), 33 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 6fa100d1bea72..ee7557e1e0975 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -28,8 +28,6 @@ struct batch_options { }; static const char *force_path; -/* global rest will be deleted at the end of this patch */ -static const char *rest; static int cat_one_file(int opt, const char *exp_type, const char *obj_name, int unknown_type) @@ -170,16 +168,19 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, static void batch_object_write(const char *obj_name, struct strbuf *scratch, struct batch_options *opt, - struct expand_data *data) + struct ref_array_item *item) { struct strbuf err = STRBUF_INIT; - struct ref_array_item item = { data->oid }; - item.request_rest = rest; - item.check_obj = 1; + /* + * TODO: get rid of memory leak. The best way is to reuse ref_array + * in batch_objects and then call ref_array_clear. + */ + item->value = 0; + item->check_obj = 1; strbuf_reset(scratch); - if (format_ref_array_item(&item, &opt->format, scratch, &err)) { - printf("%s missing\n", obj_name ? obj_name : oid_to_hex(&item.oid)); + if (format_ref_array_item(item, &opt->format, scratch, &err)) { + printf("%s missing\n", obj_name ? obj_name : oid_to_hex(&item->oid)); fflush(stdout); return; } @@ -189,7 +190,7 @@ static void batch_object_write(const char *obj_name, strbuf_release(&err); if (opt->print_contents) { - print_raw_object_or_die(&item, opt->cmdmode, opt->buffer_output); + print_raw_object_or_die(item, opt->cmdmode, opt->buffer_output); write_or_die(1, "\n", 1); } } @@ -197,14 +198,14 @@ static void batch_object_write(const char *obj_name, static void batch_one_object(const char *obj_name, struct strbuf *scratch, struct batch_options *opt, - struct expand_data *data) + struct ref_array_item *item) { struct object_context ctx; int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0; enum get_oid_result result; result = get_oid_with_context(the_repository, obj_name, - flags, &data->oid, &ctx); + flags, &item->oid, &ctx); if (result != FOUND) { switch (result) { case MISSING_OBJECT: @@ -242,12 +243,12 @@ static void batch_one_object(const char *obj_name, return; } - batch_object_write(obj_name, scratch, opt, data); + batch_object_write(obj_name, scratch, opt, item); } struct object_cb_data { struct batch_options *opt; - struct expand_data *expand; + struct ref_array_item *item; struct oidset *seen; struct strbuf *scratch; }; @@ -255,8 +256,8 @@ struct object_cb_data { static int batch_object_cb(const struct object_id *oid, void *vdata) { struct object_cb_data *data = vdata; - oidcpy(&data->expand->oid, oid); - batch_object_write(NULL, data->scratch, data->opt, data->expand); + oidcpy(&data->item->oid, oid); + batch_object_write(NULL, data->scratch, data->opt, data->item); return 0; } @@ -306,20 +307,20 @@ static int batch_objects(struct batch_options *opt) { struct strbuf input = STRBUF_INIT; struct strbuf output = STRBUF_INIT; - struct expand_data data; int save_warning; int retval = 0; int is_rest = strstr(opt->format.format, "%(rest)") != NULL || opt->cmdmode; - memset(&data, 0, sizeof(data)); if (opt->all_objects) { struct object_cb_data cb; + struct ref_array_item item; + memset(&item, 0, sizeof(item)); if (repository_format_partial_clone) warning("This repository has extensions.partialClone set. Some objects may not be loaded."); cb.opt = opt; - cb.expand = &data; + cb.item = &item; cb.scratch = &output; if (opt->unordered) { @@ -358,6 +359,8 @@ static int batch_objects(struct batch_options *opt) warn_on_object_refname_ambiguity = 0; while (strbuf_getline(&input, stdin) != EOF) { + struct ref_array_item item; + memset(&item, 0, sizeof(item)); if (is_rest) { /* * Split at first whitespace, tying off the beginning @@ -369,10 +372,10 @@ static int batch_objects(struct batch_options *opt) while (*p && strchr(" \t", *p)) *p++ = '\0'; } - rest = p; + item.request_rest = p; } - batch_one_object(input.buf, &output, opt, &data); + batch_one_object(input.buf, &output, opt, &item); } strbuf_release(&input); diff --git a/ref-filter.c b/ref-filter.c index 45d163246e3f3..3f9bd2fc6a76a 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -65,7 +65,16 @@ struct refname_atom { int lstrip, rstrip; }; -static struct expand_data oi, oi_deref; +static struct expand_data { + struct object_id oid; + enum object_type type; + unsigned long size; + off_t disk_size; + struct object_id delta_base_oid; + void *content; + + struct object_info info; +} oi, oi_deref; /* * An atom is a valid field atom listed below, possibly prefixed with diff --git a/ref-filter.h b/ref-filter.h index e8cd97a49632c..237eed9818949 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -5,7 +5,6 @@ #include "refs.h" #include "commit.h" #include "parse-options.h" -#include "object-store.h" /* Quoting styles */ #define QUOTE_NONE 0 @@ -75,17 +74,6 @@ struct ref_filter { verbose; }; -struct expand_data { - struct object_id oid; - enum object_type type; - unsigned long size; - off_t disk_size; - struct object_id delta_base_oid; - void *content; - - struct object_info info; -}; - struct ref_format { /* * Set these to define the format; make sure you call From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826489 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 BF68C1805 for ; Fri, 22 Feb 2019 16:05:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE6D632A18 for ; Fri, 22 Feb 2019 16:05:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC9FB32A73; Fri, 22 Feb 2019 16:05:52 +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 3CE8532A74 for ; Fri, 22 Feb 2019 16:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727300AbfBVQFt (ORCPT ); Fri, 22 Feb 2019 11:05:49 -0500 Received: from a7-10.smtp-out.eu-west-1.amazonses.com ([54.240.7.10]:33624 "EHLO a7-10.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727202AbfBVQFs (ORCPT ); Fri, 22 Feb 2019 11:05:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=Pd46mE7DV6EWDoOV2OATzjz/ZmJqBK24XE2K0SVy/GI=; b=qqKTzKmo2eraUMfUAq6mGVpY3pNrBBSaF7Tb7miaVnGMBU9etBYeEbtfXFrWcS9I 8/93eE4A15743LaFNn7q+7kTfo+F7sV80ioh+ezEwFqi9gBlYDcJfUyPtDbsYkfGs3k hoVDb4a8iaBwY7UXNTHCft1G/3zegY0wHj1wt9h0= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a75-65264938-9d50-4cf0-a55a-c5b7892c15b0-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 19/20] cat-file: tests for new atoms added MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-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 some tests for new formatting atoms from ref-filter. Some of new atoms are supported automatically, some of them are expanded into empty string (because they are useless for some types of objects). Signed-off-by: Olga Telezhnaia --- t/t1006-cat-file.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) -- https://github.com/git/git/pull/568 diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 43c4be1e5ef55..3c848f2773bbb 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -20,6 +20,19 @@ maybe_remove_timestamp () { fi } +test_atom () { + name=$1 + sha1=$2 + atoms=$3 + expected=$4 + + test_expect_success "$name" ' + echo "$expected" >expect && + echo $sha1 | git cat-file --batch-check="$atoms" >actual && + test_cmp expect actual + ' +} + run_tests () { type=$1 sha1=$2 @@ -119,6 +132,13 @@ $content" maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual && test_cmp expect actual ' + + for atom in refname parent body trailers upstream push symref flag + do + test_atom "Check %($atom) gives empty output" "$sha1" "%($atom)" "" + done + + test_atom "Check %(HEAD) gives only one space as output" "$sha1" '%(HEAD)' ' ' } hello_content="Hello World" @@ -140,6 +160,12 @@ test_expect_success '--batch-check without %(rest) considers whole line' ' test_cmp expect actual ' +shortname=`echo $hello_sha1 | sed 's/^.\{0\}\(.\{7\}\).*/\1/'` +test_atom 'Check format option %(objectname:short) works' "$hello_sha1" '%(objectname:short)' "$shortname" + +test_atom 'Check format option %(align) is not broken' \ + "$hello_sha1" "%(align:8)%(objecttype)%(end)%(objectname)" "blob $hello_sha1" + test_oid_init tree_sha1=$(git write-tree) @@ -159,6 +185,17 @@ $commit_message" run_tests 'commit' $commit_sha1 $commit_size "$commit_content" "$commit_content" 1 +test_atom "Check format option %(if) is not broken" "$commit_sha1" \ + "%(if)%(author)%(then)%(objectname)%(end)" "$commit_sha1" +test_atom "Check %(tree) works for commit" "$commit_sha1" "%(tree)" "$tree_sha1" +test_atom "Check %(numparent) works for commit" "$commit_sha1" "%(numparent)" "0" +test_atom "Check %(authorname) works for commit" "$commit_sha1" "%(authorname)" "$GIT_AUTHOR_NAME" +test_atom "Check %(authoremail) works for commit" "$commit_sha1" "%(authoremail)" "<$GIT_AUTHOR_EMAIL>" +test_atom "Check %(committername) works for commit" "$commit_sha1" "%(committername)" "$GIT_COMMITTER_NAME" +test_atom "Check %(committeremail) works for commit" "$commit_sha1" "%(committeremail)" "<$GIT_COMMITTER_EMAIL>" +test_atom "Check %(subject) works for commit" "$commit_sha1" "%(subject)" "$commit_message" +test_atom "Check %(contents) works for commit" "$commit_sha1" "%(contents)" "$commit_message" + tag_header_without_timestamp="object $hello_sha1 type blob tag hellotag @@ -173,6 +210,17 @@ tag_size=$(strlen "$tag_content") run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" 1 +test_atom "Check %(object) works for tag" "$tag_sha1" "%(object)" "$hello_sha1" +test_atom "Check %(type) works for tag" "$tag_sha1" "%(type)" "blob" +test_atom "Check %(tag) works for tag" "$tag_sha1" "%(tag)" "hellotag" +test_atom "Check %(taggername) works for tag" "$tag_sha1" "%(taggername)" "$GIT_COMMITTER_NAME" +test_atom "Check %(taggeremail) works for tag" "$tag_sha1" "%(taggeremail)" "<$GIT_COMMITTER_EMAIL>" +test_atom "Check %(subject) works for tag" "$tag_sha1" "%(subject)" "$tag_description" +test_atom "Check %(contents) works for tag" "$tag_sha1" "%(contents)" "$tag_description" + +test_atom "Check %(color) gives no additional output" "$sha1" \ + "%(objectname) %(color:green) %(objecttype)" "$sha1 $type" + test_expect_success \ "Reach a blob from a tag pointing to it" \ "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\"" From patchwork Fri Feb 22 16:05:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Telezhnaya X-Patchwork-Id: 10826497 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 1E10C1805 for ; Fri, 22 Feb 2019 16:05:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B5A432A5C for ; Fri, 22 Feb 2019 16:05:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0977932A75; Fri, 22 Feb 2019 16:05:56 +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 9B9F932A73 for ; Fri, 22 Feb 2019 16:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727320AbfBVQFy (ORCPT ); Fri, 22 Feb 2019 11:05:54 -0500 Received: from a7-18.smtp-out.eu-west-1.amazonses.com ([54.240.7.18]:44894 "EHLO a7-18.smtp-out.eu-west-1.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727217AbfBVQFr (ORCPT ); Fri, 22 Feb 2019 11:05:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1550851545; h=From:To:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Date:Feedback-ID; bh=y9fKBjvpbTdm6yLSk1QFTCzSHLPx5dKTrSJo+g+nZZ8=; b=fUZoIaEBos7iucMbWgqruoBzTZWHg+48efzUU5NJqzu+WwAwoT+u95WdHqJK13h2 sCAdecObg5taEIia/00CFKHKZiIMGh+76xHPBxe8cOr4Dk3tDULm3oe0LfUMvBGw7Ai FmCink+FlfVhBxGz7Php6Lue1L9vB8soZOBP/4jo= From: Olga Telezhnaya To: git@vger.kernel.org Message-ID: <0102016915f49a88-27e5f4a8-225c-4d1b-8baf-9027c654169a-000000@eu-west-1.amazonses.com> In-Reply-To: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> References: <0102016915f499b8-5813fc52-230b-469e-b939-a1244e83a2b9-000000@eu-west-1.amazonses.com> Subject: [PATCH RFC 20/20] cat-file: update docs MIME-Version: 1.0 Date: Fri, 22 Feb 2019 16:05:45 +0000 X-SES-Outgoing: 2019.02.22-54.240.7.18 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 Update the docs for cat-file command. Some new formatting atoms added because of reusing ref-filter code. Actually, %(rest) is supported for all ref-filter commands, but it has the meaning only for cat-file, that's why I decided to leave it here. Signed-off-by: Olga Telezhnaia --- Documentation/git-cat-file.txt | 38 ++-------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) -- https://github.com/git/git/pull/568 diff --git a/Documentation/git-cat-file.txt b/Documentation/git-cat-file.txt index 8eca671b8278c..b32fcde802ca1 100644 --- a/Documentation/git-cat-file.txt +++ b/Documentation/git-cat-file.txt @@ -195,28 +195,8 @@ the whole line is considered as an object, as if it were fed to linkgit:git-rev-parse[1]. You can specify the information shown for each object by using a custom -``. The `` is copied literally to stdout for each -object, with placeholders of the form `%(atom)` expanded, followed by a -newline. The available atoms are: - -`objectname`:: - The 40-hex object name of the object. - -`objecttype`:: - The type of the object (the same as `cat-file -t` reports). - -`objectsize`:: - The size, in bytes, of the object (the same as `cat-file -s` - reports). - -`objectsize:disk`:: - The size, in bytes, that the object takes up on disk. See the - note about on-disk sizes in the `CAVEATS` section below. - -`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). See `CAVEATS` below. +``. The format is the same as that of linkgit:git-for-each-ref[1], +with one additional option: `rest`:: If this atom is used in the output string, input lines are split @@ -300,20 +280,6 @@ notdir SP LF is printed when, during symlink resolution, a file is used as a directory name. -CAVEATS -------- - -Note that the sizes of objects on disk are reported accurately, but care -should be taken in drawing conclusions about which refs or objects are -responsible for disk usage. The size of a packed non-delta object may be -much larger than the size of objects which delta against it, but the -choice of which object is the base and which is the delta is arbitrary -and is subject to change during a repack. - -Note also that multiple copies of an object may be present in the object -database; in this case, it is undefined which copy's size or delta base -will be reported. - GIT --- Part of the linkgit:git[1] suite