From patchwork Thu Feb 4 20:07:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12068585 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 B601AC433DB for ; Thu, 4 Feb 2021 20:15:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6586464F76 for ; Thu, 4 Feb 2021 20:15:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239397AbhBDUPC (ORCPT ); Thu, 4 Feb 2021 15:15:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240000AbhBDUIi (ORCPT ); Thu, 4 Feb 2021 15:08:38 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B8BC061788 for ; Thu, 4 Feb 2021 12:07:58 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id y187so4092914wmd.3 for ; Thu, 04 Feb 2021 12:07:58 -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=VORLwtUUvBY30GqFiNijFLxV5rRrjyLP+YPskiY9VhE=; b=otNsuvERHj+V7SCxAiKic3d4/nR9uFdATW5Nwr1ZeM9Pgic9TITL3sO29DJ3VrxiyG RgQGzuflUOnkCOI3ugbcSBDGNdEXpFwRkzfxVrPvJ6CmCIHAJqEK/P1NVgcsto8fh+Am Bocp2CFcSlCPZd8+UyD4cgsKjU13R0P72pkYSFSWmJsH8o/KncucjHVT/qyf5NbhuJo0 JAJt3oQNveGSBmOfK+FTwutuIH9G/WASEN3UvYr670aIK13pNRgjBB3NLmrf6U0xHu7v 5j3e/wlFvgbWAkQOlsIjPXdMP0nvO16cb/XJySnAKObXc73qHGH+9sxJhrW4Wk3y8kKb L9/g== 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=VORLwtUUvBY30GqFiNijFLxV5rRrjyLP+YPskiY9VhE=; b=ffsYu5V1mkRJmTlPb1yChhmcK2dEusYPzgFREvOSpqJkaBI4bopm0YYvUCMQvesqCZ z28qM0N0RVng4miAubQJGHr2s3QgLkSaB0C0ygaU+D44ggiepZJ0CdVDL39i2d63bGu5 eXJoDWMatHdCcJvTrw8KWl8t+GnDgo407MoA8zmDAhE1J/okJ1eA/1v5derjWDy8vxDf Zm39GTJfMLa2EpZY48J/4Hl7mSv9e9IpcNEm5k022z4C0HuaM59QWi6G9wYq985lzpuB 4D1duOEftUAkHAMCrwrSsQP9K8QItX2YgVtZIdeq8+znIz6jYqYlKvGgjwiLLZvbN2ZJ V0nw== X-Gm-Message-State: AOAM533H/oSs9ZLYa29JMxj8mvRxoHP1zlsOsyavYZEIHFIZKlo7RHSY WLvACQbtHxWhnRcS4gsZ6+qkwyXV3/0= X-Google-Smtp-Source: ABdhPJxIFrG3wG7ikB6lJ09Mqdo9MWI5HevbkuFm+CL+/6Fqumx523J2sHWmMqaEZmbivsWIMo7f9A== X-Received: by 2002:a1c:2403:: with SMTP id k3mr727751wmk.130.1612469277092; Thu, 04 Feb 2021 12:07:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z15sm8975459wrt.8.2021.02.04.12.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:07:56 -0800 (PST) Message-Id: <5f2f06b79e208b68f3c753538f2b081729765b82.1612469275.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 04 Feb 2021 20:07:49 +0000 Subject: [PATCH 1/6] range-diff: avoid leaking memory in two error code paths Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 0c6ac4f954d1..963cdecb4cbb 100644 --- a/range-diff.c +++ b/range-diff.c @@ -97,6 +97,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); @@ -112,6 +113,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 Thu Feb 4 20:07:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12068587 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 CC1CEC433E0 for ; Thu, 4 Feb 2021 20:15:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E84D64F78 for ; Thu, 4 Feb 2021 20:15:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239482AbhBDUPS (ORCPT ); Thu, 4 Feb 2021 15:15:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240009AbhBDUIj (ORCPT ); Thu, 4 Feb 2021 15:08:39 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E1BC06178A for ; Thu, 4 Feb 2021 12:07:59 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id g10so5078319wrx.1 for ; Thu, 04 Feb 2021 12:07:59 -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=UzjscSMb79x/GFMISrlroGOOsjly/OZvJv1LPuYxIuA=; b=H3K/jHpZa2TX4kv2Qf7a01kWNqgyjWYEBVVGAzwrshI3vRU1+STBKT0nSZHWmGZJ1c j6pnL6E1wR3sG7jFCl+02BjIXUz2i6t+NNYlj9Sz+gwym/G6fIqcZzTwT0PSa2kH7J0G QsiLPZM/STs24hg4ERm+NZ/t9xZduO6kuLxhM3d8mtoAjN8vPOA0Z0cMT8UxumRlpfnM RX5HFerl1yeuYATf7MWUd5KeJcWLa/FWonZfEod4XXT9bosX0Q5MUYO1cXEuodm1a9o9 Rr2IfzPMCu5wlC4NzsZkoPOL5f9MY+d0rPz2hloA/QfPOfNIc6zr9u8FD9uUjjSygxq9 h2lg== 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=UzjscSMb79x/GFMISrlroGOOsjly/OZvJv1LPuYxIuA=; b=i+di2iPpiekD6U1njfW4UNI2OKYaIDtQhGebP2E/Ujy2+dATlDy+MvSMNcffaI+e1l BNUxpg1NI8bfvBIu8d13U4u7SZ8gsUCj4ywvFoSWuL61WC5QK+r04VCKMdrOGvYCQrly kOEhNKpSrdiYmnjX479InE97YCRI7f0cDiE/oVtw1VKr3fgjkw+J1Z/sgotserb2dcZo EqwJdOYWFMAkD0SBS+o52DdETOdMr+6bnCyngmY9SnfPqUdLYvRmmQu9NWNduyu70P9E jMw6hkFAocS+F5IxcwD94uvpdPDdl4sgIYKLEwQwVIRaqTG/4aYqqfTXA+o+GZUzffJs PHdA== X-Gm-Message-State: AOAM531EcQ6/Pa3iQAsmsGfPiaVohK1o+acICKv+z6a9uW/qnkFYBH+W 9A2CAj5771Z1QA6zVZ6rTXx/VQxsXl8= X-Google-Smtp-Source: ABdhPJzP+sB5DUvkefyQUGL/9v6F/qsBK9Ntq4LySYgdvq4s+gWiQJp0f0qQqUhksVnh4vwiqLNvLQ== X-Received: by 2002:a5d:4386:: with SMTP id i6mr1037353wrq.411.1612469277981; Thu, 04 Feb 2021 12:07:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 67sm7235459wmz.46.2021.02.04.12.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:07:57 -0800 (PST) Message-Id: <0d25dd2a9c2d15479d098b10a85cf14144329a57.1612469275.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 04 Feb 2021 20:07:50 +0000 Subject: [PATCH 2/6] range-diff: libify the read_patches() function again Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 963cdecb4cbb..6707b728a07f 100644 --- a/range-diff.c +++ b/range-diff.c @@ -135,9 +135,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 Thu Feb 4 20:07:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12068583 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 9B27AC433DB for ; Thu, 4 Feb 2021 20:15:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D99664F76 for ; Thu, 4 Feb 2021 20:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239318AbhBDUO7 (ORCPT ); Thu, 4 Feb 2021 15:14:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240012AbhBDUIk (ORCPT ); Thu, 4 Feb 2021 15:08:40 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 425BEC06178B for ; Thu, 4 Feb 2021 12:08:00 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id a1so5050575wrq.6 for ; Thu, 04 Feb 2021 12:08:00 -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=ChGRXI1L+NFDyLh0BtuB3FtiEzfJAQX5KmaKrBGGQ1Q=; b=p1VaMxgZuXEiLjiIbLLL1vyHuU2CZRvv9XEHVlcgTL0gYAvlRtiDdJShvreUJmAq28 ww0loexdnTS3tZzCbSo219AmWvQn3ip9XxPtMHFOLAs1nlhFE4U7y52+A1TWeorlGDfX cj6HWTgz5EisY52qlDy5lx41bDBlKeCZN4eV91iqOon0b1gG+B9UGjtO1jd+LlT8ZYwL uKDXaUVbCrAPjgcCPsK/B17PY8j095OyvP50zRa9/3ehZp3VTHBZrUB2qeeUF68Pb2PN qshnTkzgVwqiZWNw7d9H0ky/O0Zpkg9g/SGjNilNGDp2yzNzQ380etzlGW9uN3I0PJ+m HTPA== 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=ChGRXI1L+NFDyLh0BtuB3FtiEzfJAQX5KmaKrBGGQ1Q=; b=MnHZRx1RfeA18EMWHhQAF9s0OimAKYPbxH0xDq0RZXrU3oY+YnvX6tzeYWNZAA7CgX HSfhqIiEswdziT3uwIOHQqlG1vpy47nvSWCTC5XQyHtudBGO1ObOrHLxkjvr/DvYfD7t kO7xgAGR6W+jh2P7v4d3RQzQilZPgYyNXZ6xgKauqc5thd4SFIczE27zhrqY9O4erE1t fRj/w1mifb1P9es/pwB75eBZbvCz/1R6pnmhCQXcMyGpZfbUK8XWiHQ43B1BREHWIm1Y wCVyTUka4GMbBXAbn4o2m21BbGOlDA8iACLANFvwX9UXItcDIXv7TCM3Y457Xpimu+mZ AD9Q== X-Gm-Message-State: AOAM530Ll+eMEAMNLkeizW3vMxgD/tBu2ngo+SZtxuBN6wANMpBmZo43 CXNinGHHRriYbOjukCYKEBOozv5CoIw= X-Google-Smtp-Source: ABdhPJx0DRG5teri0d/WwOyluJQuc76CeNYs7iglGQElZ2+k4IDFioVaNliL/SeqHsyhwM7Nsodzjw== X-Received: by 2002:a5d:453b:: with SMTP id j27mr1166484wra.92.1612469278806; Thu, 04 Feb 2021 12:07:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o83sm1396537wme.37.2021.02.04.12.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:07:58 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 04 Feb 2021 20:07:51 +0000 Subject: [PATCH 3/6] range-diff: simplify code spawning `git log` Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 6707b728a07f..3919d56e3716 100644 --- a/range-diff.c +++ b/range-diff.c @@ -80,6 +80,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; @@ -101,7 +103,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; @@ -117,7 +118,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; } @@ -227,9 +227,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 Thu Feb 4 20:07:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12068603 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 4F7AFC4332B for ; Thu, 4 Feb 2021 20:22:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2458E64E0A for ; Thu, 4 Feb 2021 20:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240054AbhBDUWd (ORCPT ); Thu, 4 Feb 2021 15:22:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238272AbhBDUWZ (ORCPT ); Thu, 4 Feb 2021 15:22:25 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10CB1C06178C for ; Thu, 4 Feb 2021 12:08:01 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id a1so5050623wrq.6 for ; Thu, 04 Feb 2021 12:08:00 -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=8IABtOIYvh1NujCAFSg88lTFCJ2xSmLtsPeG0cgY2EM=; b=F9ByMQNgJuWavxsDJbTVIMv0CUxhRY3VhG4RSFOEn+NXxN+bGZbYOtdKUUP2rt/4Sf yDIWmc4P/qUGHqw4OMC27KMx7su+v1OwBgush6WMr9HPhDIjNIzPM9qxGdQVp6tH5dlQ /b1MeIEEKUSKqu+1HdqQJdKfclokthgiqpxToYdkNsoNRaDWksBfWog7L/1034v1wHkf tFLY1AdHbpPcrazYU2VAJIukM3dja6oA6tJhlFRV6V6uPVE+t8ogqMMU9MEIOxxhASc3 04JlxzJbgmoRrthzQd6n+p8mc1ged9TXk6Y594L5JYCtmbqNVdOcLcFbh/TIRmtkhblo 5ZSw== 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=8IABtOIYvh1NujCAFSg88lTFCJ2xSmLtsPeG0cgY2EM=; b=OEWyoduwY7mNFKocIZsNOUMRak/v9iWHsoSaZQEwyJ2YtWbDc7O9mnviE8X9wDJEA2 RsXNtwrHya+fTbd05C48nm9c5AIxFj6PsmQtybKy1Txii8qBLZyowIZORKL5hMeHjcQb dWoWq6/4KLO2R1Wo3m+ZkdOCYs7xu9flB2AKJhCuGdQXA8RUWukSmmZIk3t9C50UxXeg cnC2sKUt/xgDyvCAsUmUO2ZxdY0/LU6npJ+cmEYXOYJZ3EgH+wYC0ilDVx7RcBIFm9Jm p2oHslAsvQ4m37ZWOL+LB6E5Q9r3wSd+7uvuQq2y5YZJbl6TNtvqDFMMexagbxkpyAhV dVRA== X-Gm-Message-State: AOAM533PrCAu2SoilWiAGCbWIzTifwvzeQMOfQBFtOddnFc7N3G7UDUy h+OLPKXl9ZDK1IrrvPfAaVISY188ww4= X-Google-Smtp-Source: ABdhPJzBlWyQMRfH43M0igdjF2Fj49qiSU7lAZ3FjEY4kthHIc6sPp8MlZN4QhX4HARg+eU7+3mN3w== X-Received: by 2002:adf:f8c8:: with SMTP id f8mr1169277wrq.132.1612469279653; Thu, 04 Feb 2021 12:07:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r25sm10073763wrr.64.2021.02.04.12.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:07:59 -0800 (PST) Message-Id: In-Reply-To: References: Date: Thu, 04 Feb 2021 20:07:52 +0000 Subject: [PATCH 4/6] range-diff: combine all options in a single data structure Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 | 11 ++++++++--- 5 files changed, 40 insertions(+), 20 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 3919d56e3716..58528c43a3e8 100644 --- a/range-diff.c +++ b/range-diff.c @@ -525,33 +525,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, " "); @@ -559,7 +558,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 c17dbc2e75a8..8fb2ff05865d 100644 --- a/range-diff.h +++ b/range-diff.h @@ -6,15 +6,20 @@ #define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60 +struct range_diff_options { + int creation_factor; + unsigned dual_color:1; + const struct diff_options *diffopt; + const struct strvec *other_arg; +}; + /* * 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. */ 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 Thu Feb 4 20:07:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12068607 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 9C674C433E0 for ; Thu, 4 Feb 2021 20:24:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50B7A64E0A for ; Thu, 4 Feb 2021 20:24:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239425AbhBDUXS (ORCPT ); Thu, 4 Feb 2021 15:23:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240073AbhBDUWu (ORCPT ); Thu, 4 Feb 2021 15:22:50 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15477C061793 for ; Thu, 4 Feb 2021 12:08:02 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id j11so4200031wmi.3 for ; Thu, 04 Feb 2021 12:08:02 -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=rIxCTtB9/Md2rqt/hbOd/IIVWbiw5yX9sz1mfi7cMYs=; b=An+e8smDgvUBXd9F/Ya+5pm5Sz91KwC5qasynsgDuSLoV16v8LNzCp4Xz+vKcIXHQw 3xDYcbX1aV1XUk+UV9lg8wGnQQJ4b6MzTe1hYgfAzVDtTfXo6to31c7Hhz+yALPrtMnH 0GeLAYFjdJOsbwo+Dv6QHuoV/i6uFsQIv8+hEZyxdKZedSW19sW5N5IkmTJgTZuOjWU9 gHIdhwpKP6RWTU07bczUzz/8EKmdsKPw12XtHgTzIYzvMUV8IdRyn2GT4zaiGYztfDzV qAhBg0XsHjHdcRIw3oBDF68w1uPoL2D5pzCUjwlZTHLM3ja2pLJVA22JW736bsiiFg7B 7zuw== 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=rIxCTtB9/Md2rqt/hbOd/IIVWbiw5yX9sz1mfi7cMYs=; b=im4I5XQ3V7Tb956g+m6w1MK9MPzyqQ3xI3AiQhtxqFMkRj2+X1jd49IrRThcju8uC+ A3JxSaQ/a7yBPzv6sZLo/4Vit5YJb6idyz31VoIBNsjhxzTUArTTQ/vI+ZvTurhwY54p nDZRrecyYHFNwulspJ6BokRHlGtOXU52jfDUN5d+Oz1QPJ6KK/uMxowk0Dx1v62Qyy5Q y+9xogwjNRqs32jKXeuFGHeM9IflOfg6Q8V9SvacqGEtZ8JPXQeUQ/VcyvpZFnurMkMD ah5W6WBOefhMlmsFWd99R3jhldI+6oUwuyXfLa2tNTkSZJM2AIdO8xcG6YrrqomUq6fl IEeg== X-Gm-Message-State: AOAM530DLZl7+YD9My0eZuDyAgzOM8B0KDNDRKFelT5FruLNyNmuX3AB r+iPjlP5QK0KDpgbZ3oH/Lld9npwj6s= X-Google-Smtp-Source: ABdhPJwH5slN+o4wW/I82yp8LHokfEJv8co3Kv0xtDRA3iRLpOYakvtkgprJ7AUf0h4bqXGttx8Oww== X-Received: by 2002:a7b:c355:: with SMTP id l21mr730246wmj.61.1612469280524; Thu, 04 Feb 2021 12:08:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c9sm10326113wrw.76.2021.02.04.12.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:08:00 -0800 (PST) Message-Id: <9fa945db5f135d3b829aef70da490184f898e276.1612469275.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 04 Feb 2021 20:07:53 +0000 Subject: [PATCH 5/6] range-diff: move the diffopt initialization down one layer Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 58528c43a3e8..5455cbb9521b 100644 --- a/range-diff.c +++ b/range-diff.c @@ -464,12 +464,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 @@ -490,7 +513,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; @@ -498,7 +521,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; } @@ -506,22 +529,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, @@ -538,31 +557,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 Thu Feb 4 20:07:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12068605 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 27342C433DB for ; Thu, 4 Feb 2021 20:23:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B340164E0A for ; Thu, 4 Feb 2021 20:23:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240067AbhBDUWk (ORCPT ); Thu, 4 Feb 2021 15:22:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240058AbhBDUWh (ORCPT ); Thu, 4 Feb 2021 15:22:37 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C63C061794 for ; Thu, 4 Feb 2021 12:08:03 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id 7so5106548wrz.0 for ; Thu, 04 Feb 2021 12:08:03 -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=YtdXnObg3kniJj+YeqqTbm2VP7wZXt7FTIB0shXGuYI=; b=gMf+EpwtIAAyNSDDCTEgwqf/BBkqOMD8fY1cG5A4zQajO/HNgwliVNAipybtJNmuHQ dZXPsjd5CGse3mNf5ycA/1aiVPl5FduvHspYS5aZLHLinTiIER+55U1RWcTSk5CwO4Fx naQCW/vcoq3av34SVP8EKRlE1vVt6jBcyfcreUmO0WuMi0qCbd3TanezG71BHUNXjcvh CVwfXXEXmMrX3N0Dcz9VHHq2zxsTuxCQb7pdCGzvDzcN9ZobtJaxcB97/6i7Qcaw/b0G Gjh4DYO671OffDI5HxrXayu/SgKVsmOstFysOwNIjLWYYnmG8r2T2JfH4FJ9rqI9eXT8 kdTg== 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=YtdXnObg3kniJj+YeqqTbm2VP7wZXt7FTIB0shXGuYI=; b=mraMXqk5zFwxusTL3MIo3kYIJh5Fi4W3WTvZDAbDc0qDWdelvDeYDwCIfkZpDyX7rj G+WmcJIE7wvyv7vtIKa8GfyTBHUBf0LiyHms9WK333CWJwE9p0fVmi6E6i4WkkIdIw6r 9mxU+VVag8EVBpHDXfKTVENsS7SCOlHsXd6A8GSGl0mkyj1nsfGvmsZGkBe6jvaPJW4x 3na0kKZhAoLPrvUeq0srx17kXhcsYrOnMnDPlpFaJ1Y39QjcBsqI8eMQFj21ipdM0o5h f0LcUPvMfIckERlG6S8uf6v9D2Adxt1hauRPqW/JaX7iuyKP2sF7ORXA4e0ddw+RhWbD Zt2g== X-Gm-Message-State: AOAM531PuwJL5SJH46UqaZx6hPgsS5n9ThpQfPE6k1VNJ+gBUewu3XL5 8myMrK+GgPOhgV7blOvpVDjrZ44ClRE= X-Google-Smtp-Source: ABdhPJzzMQrG2uYEl1iLdWDqM5CrHDM0PBUx+mqiN0cRzWvIHVPvIygcl4HpOI6G8BVpmgu4PlrtXg== X-Received: by 2002:a5d:68c4:: with SMTP id p4mr1203531wrw.62.1612469281591; Thu, 04 Feb 2021 12:08:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o124sm7360162wmb.5.2021.02.04.12.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Feb 2021 12:08:01 -0800 (PST) Message-Id: <1c599abdbb6fd304dd340ecbf903082306cf9138.1612469275.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 04 Feb 2021 20:07:54 +0000 Subject: [PATCH 6/6] range-diff: offer --left-only/--right-only options Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: 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 14bffb272a06..e3bd93515819 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 @@ -69,6 +70,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 5455cbb9521b..6f52dce0f6b6 100644 --- a/range-diff.c +++ b/range-diff.c @@ -513,7 +513,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; @@ -521,7 +522,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; } @@ -551,7 +553,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 8fb2ff05865d..66aacd47d149 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; const struct strvec *other_arg; }; diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index e217cecac9ed..41cc1077a18f 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -725,4 +725,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