From patchwork Fri Feb 5 14:46:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12071063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98435C43333 for ; Fri, 5 Feb 2021 22:08:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A34164FA8 for ; Fri, 5 Feb 2021 22:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbhBEWH3 (ORCPT ); Fri, 5 Feb 2021 17:07:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232808AbhBEOyU (ORCPT ); Fri, 5 Feb 2021 09:54:20 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78C28C0611BC for ; Fri, 5 Feb 2021 08:32:08 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id 190so6516942wmz.0 for ; Fri, 05 Feb 2021 08:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=NXW0/IyLnefqrhgwRAQLEbWDjQP16jqzthXYIuY4v24=; b=V5/cLbeY2UT+Dvi3m7C/NU2EqXOx7iuzQsPucpBNiCmAujlb6gRguL+wd+FEjMzwhS pC/bJ6JywyTVV4Ky1esQjwhONi2wOGgIt95pkzAElCQzRgjBYXUDMn4MpdPsfNZZoJt5 1i05lfAAQ9HNLi81ZvJbEhkWXNe/bj3yc17laoS6j+VhFICjDh6xHRN+s5beNcuXiRcv XWLi2+DUssVZ4oN57PnOJrDNoHoApBu3Wlp7tPB9sg2jLnvYT/Gb6HCvFAbc+YmswXpf 3PsKDtAsaeoRzSyInv1uDWkT50eWF6c5/uiw2J5RdOVQKfuXgtpuZnfObSj08gdczi2q Ydxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=NXW0/IyLnefqrhgwRAQLEbWDjQP16jqzthXYIuY4v24=; b=KV3tbLbJwhmFCR5FCymXvXFbFSGnCz6wKluEvFsjeAhNJE/haHkm9rBUiS8pm7qCxG xWUGVMz+8szOft5sqzfdIbQi+dR9CoPSXJpVtlwMACcaR2SrvNN7I9Xcpd1DYdUMu21W kTOS29NfnC3p6ol3TMNgshjwQKvvJt+l2hlSA1yYVofYxoSK1W663FGqeu2Mcsd9pG5I Md/uOwifvtOjgghYBV4G+LKWVqJxJeKn8hlzq0f6MGwVL9vkjRHFELLeNMaj/DuOok2k k9zRf18Gzz1A1XErMji+Kgmc0ujJT++ZXjkQ2JDllrYRC7wFm8HtWUkoBRQ0E6DkKs+X +2vQ== X-Gm-Message-State: AOAM531tK/XBQfUbgdJPLr2Opebi7TW1iE9ZULqxIVLfJNxs/+61gPFv N1QlZq/x7+58+htX3w/pvp1u8N6g+lQ= X-Google-Smtp-Source: ABdhPJwpBQxCY67GnsxvF9JPCaM9EODDCImFQs4pguUIn0REhEMukVM5IYeIC7L2cC9HFLiRP4Dqow== X-Received: by 2002:a7b:c24b:: with SMTP id b11mr3932227wmj.96.1612536375504; Fri, 05 Feb 2021 06:46:15 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u142sm9367046wmu.3.2021.02.05.06.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:46:15 -0800 (PST) Message-Id: <15f4f6abdaa206ca9b89f4f2444b88a77ef1060c.1612536373.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 05 Feb 2021 14:46:08 +0000 Subject: [PATCH v2 1/6] range-diff: avoid leaking memory in two error code paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Eric Sunshine , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In the code paths in question, we already release a lot of memory, but the `current_filename` variable was missed. Fix that. Signed-off-by: Johannes Schindelin --- range-diff.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/range-diff.c b/range-diff.c index 7a38dc871543..9972808fe4cf 100644 --- a/range-diff.c +++ b/range-diff.c @@ -98,6 +98,7 @@ static int read_patches(const char *range, struct string_list *list, if (get_oid(p, &util->oid)) { error(_("could not parse commit '%s'"), p); free(util); + free(current_filename); string_list_clear(list, 1); strbuf_release(&buf); strbuf_release(&contents); @@ -113,6 +114,7 @@ static int read_patches(const char *range, struct string_list *list, error(_("could not parse first line of `log` output: " "did not start with 'commit ': '%s'"), line); + free(current_filename); string_list_clear(list, 1); strbuf_release(&buf); strbuf_release(&contents); From patchwork Fri Feb 5 14:46:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12071029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADE6DC433DB for ; Fri, 5 Feb 2021 22:01:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76E7D64EEF for ; Fri, 5 Feb 2021 22:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230333AbhBEWAR (ORCPT ); Fri, 5 Feb 2021 17:00:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232974AbhBEO5z (ORCPT ); Fri, 5 Feb 2021 09:57:55 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67967C061797 for ; Fri, 5 Feb 2021 08:26:26 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id j21so3654730wmj.0 for ; Fri, 05 Feb 2021 08:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=gCmwl93zPkh0oihFNdClf2ImDoCqUwjAd7IhSneAF3s=; b=GKEthkGXMn7xJeHLLTlD11Yc7ofnSYRle4S4wCjmrZtUK8S7qHrO7zFOQL8GG2Ug1W qjjBhiOFpOBDIAuhmf4xyNCDqpw6Kdv41kUyJ35LTLGZNIjHQuQmMqMs8Q8eTQIvSrSt iXHNBklRA+BTJuffQsx6BPCotDAv1P0VFkrmvqjDovBs8cbT20mjoXEkWp6mw7fagc8q VyYPF+D6UDRDf5tRo8P8XZLaAFaiMtTWDtpcjMmjz5oTq30LhPRNJBZAjDXwag3PSnEU t1qCfPaXWN0xTF5urOsAxeZCR4WrpfoysC3keUBsNXM+731gter+e2axKkCWpLV2/fSn ovZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=gCmwl93zPkh0oihFNdClf2ImDoCqUwjAd7IhSneAF3s=; b=Dj9FOBvAaCViSzzKDFnD3iAdRheW9ovGTZcLWzly0BCVNwJqvX+fYwj61JYI6MRc0G /IIwIcMFIe9woot6VNOoKgsHFuyp0zMZ8Sr7EZR4uNVupTtfM26fqRaSn1rt59UWAXcr O7ajgyPMewLxWwNck0f9u76SlN2K6fFZfFHDBAcDGMWzSmAT1aQ3VoFQJQwcXGRYVGIo KMzWvkdgAYBxKVr8x5ahJMShIEel9gV7bNmCfqDzIblAnNnQ4MK7AWdjK2HLQcHSohfp bar97B+JrhKp2cCtImjlaS7AfEcZjfX1+dUOB3VIzqht06KUrmiv6ynoopialhJBwlIx M9ew== X-Gm-Message-State: AOAM530o0ZX6GL/xgr+4eF/iQLV/BU/3Szf0/iOvI3ouzNbu0qgYJnJZ w2FdkTuX//YXP2rPnD82jdc6FyHpLRU= X-Google-Smtp-Source: ABdhPJzbwzkxXVuGINW8bDmPgxD29AiUmstSrQEGThyy//BKg782U7AYQXazLNr/TUGQoUEJpb52eQ== X-Received: by 2002:a1c:9648:: with SMTP id y69mr3845349wmd.40.1612536376528; Fri, 05 Feb 2021 06:46:16 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t8sm8994805wmq.36.2021.02.05.06.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:46:15 -0800 (PST) Message-Id: <99e466ef32d77f45de5c3aae5f44bea017b622cf.1612536373.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 05 Feb 2021 14:46:09 +0000 Subject: [PATCH v2 2/6] range-diff: libify the read_patches() function again Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Eric Sunshine , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In library functions, we do want to avoid the (simple, but rather final) `die()` calls, instead returning with a value indicating an error. Let's do exactly that in the code introduced in b66885a30cb8 (range-diff: add section header instead of diff header, 2019-07-11) that wants to error out if a diff header could not be parsed. Signed-off-by: Johannes Schindelin --- range-diff.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/range-diff.c b/range-diff.c index 9972808fe4cf..8844359d416f 100644 --- a/range-diff.c +++ b/range-diff.c @@ -136,9 +136,16 @@ static int read_patches(const char *range, struct string_list *list, orig_len = len; len = parse_git_diff_header(&root, &linenr, 0, line, len, size, &patch); - if (len < 0) - die(_("could not parse git header '%.*s'"), - orig_len, line); + if (len < 0) { + error(_("could not parse git header '%.*s'"), + orig_len, line); + free(util); + free(current_filename); + string_list_clear(list, 1); + strbuf_release(&buf); + strbuf_release(&contents); + return -1; + } strbuf_addstr(&buf, " ## "); if (patch.is_new > 0) strbuf_addf(&buf, "%s (new)", patch.new_name); From patchwork Fri Feb 5 14:46:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12070867 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A4BAC433DB for ; Fri, 5 Feb 2021 20:40:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C50EE64EE8 for ; Fri, 5 Feb 2021 20:40:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbhBES5g (ORCPT ); Fri, 5 Feb 2021 13:57:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232908AbhBEPDP (ORCPT ); Fri, 5 Feb 2021 10:03:15 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C23C06174A for ; Fri, 5 Feb 2021 08:41:16 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id s11so9515949edd.5 for ; Fri, 05 Feb 2021 08:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=l65d8udfkzCvo108kV8k2aW7CWwXTuaSE/34F4Un0S4=; b=MJFIx2jHRLBiqum/RzaL/MPl+32IAgYY3d8yvDbGvh5ufj/XZHB/5Z1oayFBhcwvIP rJ2Y536pHfXhvqKH050oD5cjHlbyau1yLVLyPkTbIv58zol7vpfKVD3LBVrP6uzAV6ME 1jLPCAsKZHFWid447aZe1RDjzbRlbLm9e6d7r3mQJ1YrTef0pVltMHBhGmgf9FlGUMta wqAEI8vU7tizu4c6hqGDt8nQMyK2YeaXMhVXYijJq7QAIyhVX/q8oWrUXVM4SR4iqKZV /ppJn/I2UmTBjRfulwPHzXte976HgzzA0n3zaodv8OyqNXSn/hT20TItpX2YgPdXNQb3 k+7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=l65d8udfkzCvo108kV8k2aW7CWwXTuaSE/34F4Un0S4=; b=PueKKi8HBJKdgVNB9EVrEa9mZT/2TqOeoV4YXRM/PNoSkN+K1OkozwggSD3EyIJf1C VxJOkuqly1OvMSw2+Kc3mwkyM+yqsiBXdrt/ky3oLVkhMqbSLX8HvE25z1zqPtNuo9bJ AyCa+uwrg3yK/191DNnhx+lw3OCqKCfoSoLkkXrHQ8VV2XO5sx+pfE57NzOqfmQuGSuI xkGFaVVLRPxepTq23fULzpsLjCj+4rZvMxd519p2vCcE5LyYfyMbmOhDu75p5F0SCcvA E+NO0Ux+PcXeEoj/R0OxrWzr/41Te0VGSmu/QgJsD/vT4I1t3VrT0ijSotavf8MSSkEO DeAw== X-Gm-Message-State: AOAM533jPVWEp1Q1vPkQf3HR3Seq5hJpX/qZmqVpGB/DbkmSZIfWIGHT lCRG/2vUYSdoCFZt2f0lyF4O2ihQcVU= X-Google-Smtp-Source: ABdhPJwwJ/rJdwIAiqgh6Ur2UVwfnVVRASGi1th9fEeRWZKLdJh+38Ej7XPzMjYQP4DiRMTDxwX3qQ== X-Received: by 2002:adf:9523:: with SMTP id 32mr5571719wrs.361.1612536377431; Fri, 05 Feb 2021 06:46:17 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r13sm9852514wmh.9.2021.02.05.06.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:46:16 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 05 Feb 2021 14:46:10 +0000 Subject: [PATCH v2 3/6] range-diff: simplify code spawning `git log` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Eric Sunshine , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Previously, we waited for the child process to be finished in every failing code path as well as at the end of the function `show_range_diff()`. However, we do not need to wait that long. Directly after reading the output of the child process, we can wrap up the child process. This also has the advantage that we don't do a bunch of unnecessary work in case `finish_command()` returns with an error anyway. Signed-off-by: Johannes Schindelin --- range-diff.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/range-diff.c b/range-diff.c index 8844359d416f..d0d941a25add 100644 --- a/range-diff.c +++ b/range-diff.c @@ -81,6 +81,8 @@ static int read_patches(const char *range, struct string_list *list, finish_command(&cp); return -1; } + if (finish_command(&cp)) + return -1; line = contents.buf; size = contents.len; @@ -102,7 +104,6 @@ static int read_patches(const char *range, struct string_list *list, string_list_clear(list, 1); strbuf_release(&buf); strbuf_release(&contents); - finish_command(&cp); return -1; } util->matching = -1; @@ -118,7 +119,6 @@ static int read_patches(const char *range, struct string_list *list, string_list_clear(list, 1); strbuf_release(&buf); strbuf_release(&contents); - finish_command(&cp); return -1; } @@ -228,9 +228,6 @@ static int read_patches(const char *range, struct string_list *list, strbuf_release(&buf); free(current_filename); - if (finish_command(&cp)) - return -1; - return 0; } From patchwork Fri Feb 5 14:46:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12071135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30FBBC433E0 for ; Fri, 5 Feb 2021 22:29:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B70A64FEE for ; Fri, 5 Feb 2021 22:29:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232800AbhBEW3C (ORCPT ); Fri, 5 Feb 2021 17:29:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbhBEOWu (ORCPT ); Fri, 5 Feb 2021 09:22:50 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8208C061A29 for ; Fri, 5 Feb 2021 07:50:07 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id f16so6384254wmq.5 for ; Fri, 05 Feb 2021 07:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=SetI9u2aCQMvY5R8rvY72StXJrn3+wWQEZIDz7SL8gM=; b=UkRMHIiFukj9ufYe4OLPvn8Whz+589ErDCC2HhSQtvRa5KRm1NNBboKfa+vFaDF6qn 7bsifyevqiLTj7JSiTlEyOUK9i7MsZ8yzbfHf6zvPb0yreeermF4hkuyAjUAzAO9U2Z1 3J1Zr2cqE9bXTMVQuoXSSWoFn50tRIrfGi0MsRTYhSfsebXVEtfFgUTIwzzJwCuwG8Fs HOfVxknWwNKPBGIjnNuQLh7p4QJSv+ZGsrcWEiDdlPDU1cIJ9SKXaiCPW3j7GMKwV/59 60Fk/Dcs+Gpg31FLIQS2iFE8Fbdy2KxgosEUC/QUSKnC++KQHNTdxLcozFb7j+0peF6E om8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=SetI9u2aCQMvY5R8rvY72StXJrn3+wWQEZIDz7SL8gM=; b=qYh/0zi7RFVzxGjSa99j/gos2etzcA61w8L4DMIgPGlnKBOrlPnHTt2IrLPT+Jfkmm cnZ7D76m47bwOYzVKN+7m1vHwgJYkhb1T3M3UpsTF5CeqKyljKkU52UJlVE6yE5NTI1r wcD+stIZp83XqwFVVlsrL/GhVDFtSNkuEGy2bfd8U9pdMrBGXBYCuINCn6EtrmZU5M+N OizrmsQa+a5P+yfTFH46YNWY/H+ekiVUxo99KqRMvYpapJWZ7P7Xswwc9DodVe6ENTw/ 1y7qjTAOij4CaSQP4ejnoOMJt2ExxFJ8GArh/liC46Tw6mMopqQWSfI9jgb2uuff0SFA 373w== X-Gm-Message-State: AOAM532rMnKon5DuCqRoIqk2OsZKpxfpUgSLKPHiFlyue0JoSD61LJm2 iqZL/LF6TZpe3iMel382vIuk+/XU8kI= X-Google-Smtp-Source: ABdhPJw6j53QwE7nY5JqIALdRoDImijE/3ahm+bIPQ6IHs7e59cXdJPQdH5R+ocRv+XY2JofsaGmKg== X-Received: by 2002:a1c:7f93:: with SMTP id a141mr3921945wmd.105.1612536378394; Fri, 05 Feb 2021 06:46:18 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f7sm11613060wre.78.2021.02.05.06.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:46:17 -0800 (PST) Message-Id: <7367eadfe2430fbcd60e7b7abf7cb432488b9c39.1612536373.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 05 Feb 2021 14:46:11 +0000 Subject: [PATCH v2 4/6] range-diff: combine all options in a single data structure Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Eric Sunshine , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin This will make it easier to implement the `--left-only` and `--right-only` options. Signed-off-by: Johannes Schindelin --- builtin/log.c | 10 ++++++++-- builtin/range-diff.c | 13 +++++++++---- log-tree.c | 8 ++++++-- range-diff.c | 18 +++++++++--------- range-diff.h | 16 ++++++++++------ 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 91466c059c79..a06e5385689b 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1231,14 +1231,20 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file, */ struct diff_options opts; struct strvec other_arg = STRVEC_INIT; + struct range_diff_options range_diff_opts = { + .creation_factor = rev->creation_factor, + .dual_color = 1, + .diffopt = &opts, + .other_arg = &other_arg + }; + diff_setup(&opts); opts.file = rev->diffopt.file; opts.use_color = rev->diffopt.use_color; diff_setup_done(&opts); fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title); get_notes_args(&other_arg, rev); - show_range_diff(rev->rdiff1, rev->rdiff2, - rev->creation_factor, 1, &opts, &other_arg); + show_range_diff(rev->rdiff1, rev->rdiff2, &range_diff_opts); strvec_clear(&other_arg); } } diff --git a/builtin/range-diff.c b/builtin/range-diff.c index 5b1f6326322f..80fcdc6ad42d 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -14,12 +14,17 @@ NULL int cmd_range_diff(int argc, const char **argv, const char *prefix) { - int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; struct diff_options diffopt = { NULL }; struct strvec other_arg = STRVEC_INIT; + struct range_diff_options range_diff_opts = { + .creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT, + .diffopt = &diffopt, + .other_arg = &other_arg + }; int simple_color = -1; struct option range_diff_options[] = { - OPT_INTEGER(0, "creation-factor", &creation_factor, + OPT_INTEGER(0, "creation-factor", + &range_diff_opts.creation_factor, N_("Percentage by which creation is weighted")), OPT_BOOL(0, "no-dual-color", &simple_color, N_("use simple diff colors")), @@ -82,8 +87,8 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) } FREE_AND_NULL(options); - res = show_range_diff(range1.buf, range2.buf, creation_factor, - simple_color < 1, &diffopt, &other_arg); + range_diff_opts.dual_color = simple_color < 1; + res = show_range_diff(range1.buf, range2.buf, &range_diff_opts); strvec_clear(&other_arg); strbuf_release(&range1); diff --git a/log-tree.c b/log-tree.c index fd0dde97ec32..eeacba15dc94 100644 --- a/log-tree.c +++ b/log-tree.c @@ -808,6 +808,11 @@ void show_log(struct rev_info *opt) if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) { struct diff_queue_struct dq; struct diff_options opts; + struct range_diff_options range_diff_opts = { + .creation_factor = opt->creation_factor, + .dual_color = 1, + .diffopt = &opts + }; memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff)); DIFF_QUEUE_CLEAR(&diff_queued_diff); @@ -822,8 +827,7 @@ void show_log(struct rev_info *opt) opts.file = opt->diffopt.file; opts.use_color = opt->diffopt.use_color; diff_setup_done(&opts); - show_range_diff(opt->rdiff1, opt->rdiff2, - opt->creation_factor, 1, &opts, NULL); + show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts); memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff)); } diff --git a/range-diff.c b/range-diff.c index d0d941a25add..25d4c244799c 100644 --- a/range-diff.c +++ b/range-diff.c @@ -526,33 +526,32 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data) } int show_range_diff(const char *range1, const char *range2, - int creation_factor, int dual_color, - const struct diff_options *diffopt, - const struct strvec *other_arg) + struct range_diff_options *range_diff_opts) { int res = 0; struct string_list branch1 = STRING_LIST_INIT_DUP; struct string_list branch2 = STRING_LIST_INIT_DUP; - if (read_patches(range1, &branch1, other_arg)) + if (read_patches(range1, &branch1, range_diff_opts->other_arg)) res = error(_("could not parse log for '%s'"), range1); - if (!res && read_patches(range2, &branch2, other_arg)) + if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg)) res = error(_("could not parse log for '%s'"), range2); if (!res) { struct diff_options opts; struct strbuf indent = STRBUF_INIT; - if (diffopt) - memcpy(&opts, diffopt, sizeof(opts)); + if (range_diff_opts->diffopt) + memcpy(&opts, range_diff_opts->diffopt, sizeof(opts)); else diff_setup(&opts); if (!opts.output_format) opts.output_format = DIFF_FORMAT_PATCH; opts.flags.suppress_diff_headers = 1; - opts.flags.dual_color_diffed_diffs = dual_color; + opts.flags.dual_color_diffed_diffs = + range_diff_opts->dual_color; opts.flags.suppress_hunk_header_line_count = 1; opts.output_prefix = output_prefix_cb; strbuf_addstr(&indent, " "); @@ -560,7 +559,8 @@ int show_range_diff(const char *range1, const char *range2, diff_setup_done(&opts); find_exact_matches(&branch1, &branch2); - get_correspondences(&branch1, &branch2, creation_factor); + get_correspondences(&branch1, &branch2, + range_diff_opts->creation_factor); output(&branch1, &branch2, &opts); strbuf_release(&indent); diff --git a/range-diff.h b/range-diff.h index 4abd70c40fed..a595f4e8db2d 100644 --- a/range-diff.h +++ b/range-diff.h @@ -6,15 +6,19 @@ #define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60 +struct range_diff_options { + int creation_factor; + unsigned dual_color:1; + const struct diff_options *diffopt; /* may be NULL */ + const struct strvec *other_arg; /* may be NULL */ +}; + /* - * Compare series of commits in RANGE1 and RANGE2, and emit to the - * standard output. NULL can be passed to DIFFOPT to use the built-in - * default. + * Compare series of commits in `range1` and `range2`, and emit to the + * standard output. */ int show_range_diff(const char *range1, const char *range2, - int creation_factor, int dual_color, - const struct diff_options *diffopt, - const struct strvec *other_arg); + struct range_diff_options *opts); /* * Determine whether the given argument is usable as a range argument of `git From patchwork Fri Feb 5 14:46:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12071021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5789EC433E6 for ; Fri, 5 Feb 2021 21:52:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1D29864FB2 for ; Fri, 5 Feb 2021 21:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbhBEVnT (ORCPT ); Fri, 5 Feb 2021 16:43:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbhBEO76 (ORCPT ); Fri, 5 Feb 2021 09:59:58 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10114C061756 for ; Fri, 5 Feb 2021 08:38:12 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id hs11so12949275ejc.1 for ; Fri, 05 Feb 2021 08:38:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=WT8+PdZXgx+ouFFnMyR0znv7pFSnh4A0ykDacXA77Pw=; b=bhW19WnaBp0tEGDEdvYR7tlTz0qE99EZWxuOvGSVqGLe4eZCHUAik0MspsgdWAYxuU LJwD2VD423KuHE1efV4F5moj5ERgFKl7zFSz3xfVVg94szCXiXY65+DJuV7SFB/Z3KqA aH3+E6LjHvbInEV+TS+daJU7WxpycXhGAz1+/w4gcIZmoAwAQMLkBh9RJ0DIMHNxMhft ImElv8rXY2V6Qe0oLzhvKJQ0bUJfeYrBq5JVq83FULAx3CW5cKAqx5Ni3Y/bqJK0waze THKOPST782+HV0cNuNeXMu3lE/tA15qUV3YB664yeDnzHyoMbebjmqR0ZxiDI/Ya+Ps4 JDEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=WT8+PdZXgx+ouFFnMyR0znv7pFSnh4A0ykDacXA77Pw=; b=acXML+//7GKc760NDZdUIwQYLFKMQSvefF10LEvF7LGuVeat9OTMlQtNjpaSMJDgFb zUrL+fGygWDh0+p3nnFcsXrUctvedqEos60JUZK7Xm8O/vuA81mxaVern6aAP6wTVmM0 yxha/ow2hm+xYP6iI1nAKmzwJV53eZuJVjv7Hk3OJjmL6MjaK/mPJp2DYpyqsZ5MfKVp 5rnFKf2hK39LEEC9mKwpVfuROHsAe4mWVloxhr6OlBfc16p+wpLhHU8/Vt3/CxiN78t1 XYX+oKjqMx3L+E6nJPKCqKnqkf5HOF4AMjzPsia5kVQtjr296A3DWODEnmP5N8Ik2UGK Kcdw== X-Gm-Message-State: AOAM530ktyqVuYTSPKLHEBhL3a5718QgwjvCUc7CTt1ZcKI1WT54IRLx fiGYBm5B7In6pI8kasWGWYbUFv2Yx+4= X-Google-Smtp-Source: ABdhPJze0toOP5WDvxSMb79bFDeQFu/UV8eyMlpDO9Nc4R8yFqBQbt2SAuvgBtDB60lNAE2heVB48w== X-Received: by 2002:adf:fb49:: with SMTP id c9mr5556074wrs.72.1612536379527; Fri, 05 Feb 2021 06:46:19 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k4sm13357620wrm.53.2021.02.05.06.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:46:19 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 05 Feb 2021 14:46:12 +0000 Subject: [PATCH v2 5/6] range-diff: move the diffopt initialization down one layer Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Eric Sunshine , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin It is actually only the `output()` function that uses those diffopts. By moving the diffopt initialization down into that function, it is encapsulated better. Incidentally, it will also make it easier to implement the `--left-only` and `--right-only` options in `git range-diff` because the `output()` function is now receiving all range-diff options as a parameter, not just the diffopts. Signed-off-by: Johannes Schindelin --- range-diff.c | 64 +++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/range-diff.c b/range-diff.c index 25d4c244799c..001b6e174079 100644 --- a/range-diff.c +++ b/range-diff.c @@ -465,12 +465,35 @@ static void patch_diff(const char *a, const char *b, diff_flush(diffopt); } +static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data) +{ + return data; +} + static void output(struct string_list *a, struct string_list *b, - struct diff_options *diffopt) + struct range_diff_options *range_diff_opts) { struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT; int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr)); int i = 0, j = 0; + struct diff_options opts; + struct strbuf indent = STRBUF_INIT; + + if (range_diff_opts->diffopt) + memcpy(&opts, range_diff_opts->diffopt, sizeof(opts)); + else + diff_setup(&opts); + + if (!opts.output_format) + opts.output_format = DIFF_FORMAT_PATCH; + opts.flags.suppress_diff_headers = 1; + opts.flags.dual_color_diffed_diffs = + range_diff_opts->dual_color; + opts.flags.suppress_hunk_header_line_count = 1; + opts.output_prefix = output_prefix_cb; + strbuf_addstr(&indent, " "); + opts.output_prefix_data = &indent; + diff_setup_done(&opts); /* * We assume the user is really more interested in the second argument @@ -491,7 +514,7 @@ static void output(struct string_list *a, struct string_list *b, /* Show unmatched LHS commit whose predecessors were shown. */ if (i < a->nr && a_util->matching < 0) { - output_pair_header(diffopt, patch_no_width, + output_pair_header(&opts, patch_no_width, &buf, &dashes, a_util, NULL); i++; continue; @@ -499,7 +522,7 @@ static void output(struct string_list *a, struct string_list *b, /* Show unmatched RHS commits. */ while (j < b->nr && b_util->matching < 0) { - output_pair_header(diffopt, patch_no_width, + output_pair_header(&opts, patch_no_width, &buf, &dashes, NULL, b_util); b_util = ++j < b->nr ? b->items[j].util : NULL; } @@ -507,22 +530,18 @@ static void output(struct string_list *a, struct string_list *b, /* Show matching LHS/RHS pair. */ if (j < b->nr) { a_util = a->items[b_util->matching].util; - output_pair_header(diffopt, patch_no_width, + output_pair_header(&opts, patch_no_width, &buf, &dashes, a_util, b_util); - if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT)) + if (!(opts.output_format & DIFF_FORMAT_NO_OUTPUT)) patch_diff(a->items[b_util->matching].string, - b->items[j].string, diffopt); + b->items[j].string, &opts); a_util->shown = 1; j++; } } strbuf_release(&buf); strbuf_release(&dashes); -} - -static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data) -{ - return data; + strbuf_release(&indent); } int show_range_diff(const char *range1, const char *range2, @@ -539,31 +558,10 @@ int show_range_diff(const char *range1, const char *range2, res = error(_("could not parse log for '%s'"), range2); if (!res) { - struct diff_options opts; - struct strbuf indent = STRBUF_INIT; - - if (range_diff_opts->diffopt) - memcpy(&opts, range_diff_opts->diffopt, sizeof(opts)); - else - diff_setup(&opts); - - if (!opts.output_format) - opts.output_format = DIFF_FORMAT_PATCH; - opts.flags.suppress_diff_headers = 1; - opts.flags.dual_color_diffed_diffs = - range_diff_opts->dual_color; - opts.flags.suppress_hunk_header_line_count = 1; - opts.output_prefix = output_prefix_cb; - strbuf_addstr(&indent, " "); - opts.output_prefix_data = &indent; - diff_setup_done(&opts); - find_exact_matches(&branch1, &branch2); get_correspondences(&branch1, &branch2, range_diff_opts->creation_factor); - output(&branch1, &branch2, &opts); - - strbuf_release(&indent); + output(&branch1, &branch2, range_diff_opts); } string_list_clear(&branch1, 1); From patchwork Fri Feb 5 14:46:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12071059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62AD6C433DB for ; Fri, 5 Feb 2021 22:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1415F64F92 for ; Fri, 5 Feb 2021 22:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232877AbhBEWGk (ORCPT ); Fri, 5 Feb 2021 17:06:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232276AbhBEOwL (ORCPT ); Fri, 5 Feb 2021 09:52:11 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05662C061756 for ; Fri, 5 Feb 2021 08:30:13 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id o10so8174067wmc.1 for ; Fri, 05 Feb 2021 08:30:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=aczPL2BQyMGa79vTsYLw8a43rUc2QrO9qCyxLCNL8jE=; b=Z6VFfw0U/sHVvaxlhvoqUsEE/s1QnA5ESDHsHPaovhOBly/lLr2363F0gIYPz++XVH U5SsfZDVslWp9XL994XojLJDleqxJkhdTrg0lhBocp07REw1t8uSr36syQkfgkAGouy6 k5xSI8GbroaQHJkB/X+tmFC6hfM+v3v54fDWP6jzSwczlHxHW5QVovCHuFyl+XLRCdBq n1AQAGB+xLntkITtS/pnr01qCGbg2TwgnaMawLYJ+S1fhDMSPUBiyLTvi90lXnTHB2ej +kdeBK4nhiSSDu/dFeWk4o9dp+YypAJTKPIPplMHB2uoZ/U1Ij+ohGlgBO+5apRP6Eib vBQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=aczPL2BQyMGa79vTsYLw8a43rUc2QrO9qCyxLCNL8jE=; b=Pu7+0uhgg0JTfLRBVRKyizQa6+HQ5DsyZJq8kdxeUgsIRRtd10dhCM3RYaTnCjTDsL bPeaDjeVTGnQdz29dWYNKkyMpS/T02EGlSbraGZfsLCe1MkS3a+nIhnBkWvnAkF3y0kw KuTTdt9iepei5YPaQG5JhDYbpglP5/MpfkN9L8oWIzaBFM/r9Qt439ZAnaBMEtjySqBd b+XgiIqKu2NCQMU6/G0oZvEIhFLBRJDyCZjetJKko3LGwEwB/lA2Zl+uppWsUU5ddeL2 A3+hIzEmRSIoikzXEHOl5Fy4xCQh0HPJJHvffkU29tMYoU5GJ3cZqXvcm3fT+wJ4svK4 raHA== X-Gm-Message-State: AOAM531uJUHNy8ZvJV4IZIzrlFSzI/F0YZLYijE235vmS6zqad/T6f13 SCiNShG7p/sdvF0LB2Sop1fm1QVDaPo= X-Google-Smtp-Source: ABdhPJxmcDjv/xsGtt0DrDOvjvCIdu10RvhVa3wEbDXwmTSjwHuT5J903SKRM+BmJ77VvkCxUDap1g== X-Received: by 2002:a05:600c:2246:: with SMTP id a6mr4009838wmm.170.1612536380382; Fri, 05 Feb 2021 06:46:20 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w12sm709123wmi.4.2021.02.05.06.46.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:46:19 -0800 (PST) Message-Id: <8357d3c94f175b2354465dab3c9a6e331ab082ee.1612536373.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 05 Feb 2021 14:46:13 +0000 Subject: [PATCH v2 6/6] range-diff: offer --left-only/--right-only options Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Taylor Blau , Eric Sunshine , Jeff King , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin When comparing commit ranges, one is frequently interested only in one side, such as asking the question "Has this patch that I submitted to the Git mailing list been applied?": one would only care about the part of the output that corresponds to the commits in a local branch. To make that possible, imitate the `git rev-list` options `--left-only` and `--right-only`. This addresses https://github.com/gitgitgadget/git/issues/206 Signed-off-by: Johannes Schindelin --- Documentation/git-range-diff.txt | 9 +++++++++ builtin/range-diff.c | 8 +++++++- range-diff.c | 11 ++++++++--- range-diff.h | 1 + t/t3206-range-diff.sh | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Documentation/git-range-diff.txt b/Documentation/git-range-diff.txt index a968d5237dae..fe350d7f4056 100644 --- a/Documentation/git-range-diff.txt +++ b/Documentation/git-range-diff.txt @@ -10,6 +10,7 @@ SYNOPSIS [verse] 'git range-diff' [--color=[]] [--no-color] [] [--no-dual-color] [--creation-factor=] + [--left-only | --right-only] ( | ... | ) DESCRIPTION @@ -68,6 +69,14 @@ to revert to color all lines according to the outer diff markers See the ``Algorithm`` section below for an explanation why this is needed. +--left-only:: + Suppress commits that are missing from the first specified range + (or the "left range" when using the `...` format). + +--right-only:: + Suppress commits that are missing from the second specified range + (or the "right range" when using the `...` format). + --[no-]notes[=]:: This flag is passed to the `git log` program (see linkgit:git-log[1]) that generates the patches. diff --git a/builtin/range-diff.c b/builtin/range-diff.c index 80fcdc6ad42d..78bc9fa77062 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -21,7 +21,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) .diffopt = &diffopt, .other_arg = &other_arg }; - int simple_color = -1; + int simple_color = -1, left_only = 0, right_only = 0; struct option range_diff_options[] = { OPT_INTEGER(0, "creation-factor", &range_diff_opts.creation_factor, @@ -31,6 +31,10 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) OPT_PASSTHRU_ARGV(0, "notes", &other_arg, N_("notes"), N_("passed to 'git log'"), PARSE_OPT_OPTARG), + OPT_BOOL(0, "left-only", &left_only, + N_("only emit output related to the first range")), + OPT_BOOL(0, "right-only", &right_only, + N_("only emit output related to the second range")), OPT_END() }; struct option *options; @@ -88,6 +92,8 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) FREE_AND_NULL(options); range_diff_opts.dual_color = simple_color < 1; + range_diff_opts.left_only = left_only; + range_diff_opts.right_only = right_only; res = show_range_diff(range1.buf, range2.buf, &range_diff_opts); strvec_clear(&other_arg); diff --git a/range-diff.c b/range-diff.c index 001b6e174079..ed19b4729845 100644 --- a/range-diff.c +++ b/range-diff.c @@ -514,7 +514,8 @@ static void output(struct string_list *a, struct string_list *b, /* Show unmatched LHS commit whose predecessors were shown. */ if (i < a->nr && a_util->matching < 0) { - output_pair_header(&opts, patch_no_width, + if (!range_diff_opts->right_only) + output_pair_header(&opts, patch_no_width, &buf, &dashes, a_util, NULL); i++; continue; @@ -522,7 +523,8 @@ static void output(struct string_list *a, struct string_list *b, /* Show unmatched RHS commits. */ while (j < b->nr && b_util->matching < 0) { - output_pair_header(&opts, patch_no_width, + if (!range_diff_opts->left_only) + output_pair_header(&opts, patch_no_width, &buf, &dashes, NULL, b_util); b_util = ++j < b->nr ? b->items[j].util : NULL; } @@ -552,7 +554,10 @@ int show_range_diff(const char *range1, const char *range2, struct string_list branch1 = STRING_LIST_INIT_DUP; struct string_list branch2 = STRING_LIST_INIT_DUP; - if (read_patches(range1, &branch1, range_diff_opts->other_arg)) + if (range_diff_opts->left_only && range_diff_opts->right_only) + res = error(_("--left-only and --right-only are mutually exclusive")); + + if (!res && read_patches(range1, &branch1, range_diff_opts->other_arg)) res = error(_("could not parse log for '%s'"), range1); if (!res && read_patches(range2, &branch2, range_diff_opts->other_arg)) res = error(_("could not parse log for '%s'"), range2); diff --git a/range-diff.h b/range-diff.h index a595f4e8db2d..04ffe217be67 100644 --- a/range-diff.h +++ b/range-diff.h @@ -9,6 +9,7 @@ struct range_diff_options { int creation_factor; unsigned dual_color:1; + unsigned left_only:1, right_only:1; const struct diff_options *diffopt; /* may be NULL */ const struct strvec *other_arg; /* may be NULL */ }; diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index 2b518378d4a0..04aa9aed6bde 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -730,4 +730,19 @@ test_expect_success 'format-patch --range-diff with multiple notes' ' test_cmp expect actual ' +test_expect_success '--left-only/--right-only' ' + git switch --orphan left-right && + test_commit first && + test_commit unmatched && + test_commit common && + git switch -C left-right first && + git cherry-pick common && + + git range-diff -s --left-only ...common >actual && + head_oid=$(git rev-parse --short HEAD) && + common_oid=$(git rev-parse --short common) && + echo "1: $head_oid = 2: $common_oid common" >expect && + test_cmp expect actual +' + test_done