From patchwork Thu Jan 21 22:20:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12037883 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 91E9CC433E0 for ; Thu, 21 Jan 2021 22:22:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 629EA23A5E for ; Thu, 21 Jan 2021 22:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbhAUWWO (ORCPT ); Thu, 21 Jan 2021 17:22:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726863AbhAUWVZ (ORCPT ); Thu, 21 Jan 2021 17:21:25 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65EC3C0613D6 for ; Thu, 21 Jan 2021 14:20:42 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id v184so2795256wma.1 for ; Thu, 21 Jan 2021 14:20:42 -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=zwW37Km+r4zps4r4VkD9Ul6EsBzptqoj2Ha5MI5WvLA=; b=uQGvvnA6vVMgSS+H1JK58bfbxcgP268ZXywWvNU8fLC6S8C5i//XmrTfio/kpBLvl3 MZaSdDBWUnxM5MHLMpZe4HoIuKY/H3rUT7Cjzib6u01Q/M3BYpgD98w6NRj2hjXc/tJB x/7UFo/4Cs6aLzw0rldXsxrEQdI67RcFkg6ysHabHkcwbNrMTN8Kr8KSXkDX+dnB4Lwa OAsGkQ6YpwHTnKFdge3Dn+0fQaLA+mDBxdV8cXzx+EvKj1HHzWTRX2ik1THVjP+HSoNb sERXssbGhC10mzT73g5pctG/tuAhzPQfZNcD2qwISxBS8K1T6yNUm6E0G6HX3AuRb+hX e9PQ== 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=zwW37Km+r4zps4r4VkD9Ul6EsBzptqoj2Ha5MI5WvLA=; b=JgXKjePq6GXVShTcMNeMT39wXpqRm/PfwhAr1jtn8CiRGHJ5G3lxTyoPCDrdTq35G8 RGiCPfU+AVZ+iVwtWASJElyg+G7CU2o5v6ZtWDoCquv52QDI0RNC4HwVLTk4LlKAaDgm C+ly7A0LMXRT6org35ZjFoXeeuj7Z+XLLaSonN07kx6sGIWC0hOg1dVxKSJRvjddl8vx zKwCj+SOnxC+50y1xgpuCzoC4JAhBGS11VudsmC17QLCVTVCqrssNBDUa8m8ICveF2uA DLn5Dw1gN7Y+Ri6lJwAnpiNGhXAI+WAdw4O3jeSHK/uzVv6sLi8qBlQX+rHwbM9Qw2pN Ckrg== X-Gm-Message-State: AOAM530RHZxIbl+mDmeKpwcw4Vtuq+B9pokl4FbFg7Grew/Ux+y2EYjd sywimVNvnYSK8YuQshlcfMGgUccGqvk= X-Google-Smtp-Source: ABdhPJztl3kwS2eY5S9gYS2RaOXTdJy22OA5M2jj2eJKn1CnRrD2QNc8N+1tIJ7gkC1fHSwZWSEt6A== X-Received: by 2002:a05:600c:1552:: with SMTP id f18mr1206488wmg.149.1611267641020; Thu, 21 Jan 2021 14:20:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 17sm8807208wmk.48.2021.01.21.14.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 14:20:40 -0800 (PST) Message-Id: <5839ba4f7615819ed6f9a0fcb6de1855cd2e89e1.1611267638.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 21 Jan 2021 22:20:36 +0000 Subject: [PATCH 1/3] range-diff: refactor check for commit range Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Uwe =?utf-8?q?Kleine-K=C3=B6nig?= , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin Currently, when called with exactly two arguments, we test for a literal `..` in each of the two. However, `^!` is a perfectly valid commit range, equivalent to `^..` according to the `SPECIFYING RANGES` section of gitrevisions[7]. In preparation for allowing more sophisticated ways to specify commit ranges, let's refactor the conditional into its own function. Signed-off-by: Johannes Schindelin --- builtin/range-diff.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/range-diff.c b/builtin/range-diff.c index 24c4162f744..551d3e689cb 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -11,6 +11,11 @@ N_("git range-diff [] "), NULL }; +static int is_range(const char *range) +{ + return !!strstr(range, ".."); +} + int cmd_range_diff(int argc, const char **argv, const char *prefix) { int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; @@ -46,12 +51,12 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) diffopt.use_color = 1; if (argc == 2) { - if (!strstr(argv[0], "..")) - die(_("no .. in range: '%s'"), argv[0]); + if (!is_range(argv[0])) + die(_("not a commit range: '%s'"), argv[0]); strbuf_addstr(&range1, argv[0]); - if (!strstr(argv[1], "..")) - die(_("no .. in range: '%s'"), argv[1]); + if (!is_range(argv[1])) + die(_("not a commit range: '%s'"), argv[1]); strbuf_addstr(&range2, argv[1]); } else if (argc == 3) { strbuf_addf(&range1, "%s..%s", argv[0], argv[1]); From patchwork Thu Jan 21 22:20:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12037885 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 AB8A7C433E9 for ; Thu, 21 Jan 2021 22:22:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79E4C221E5 for ; Thu, 21 Jan 2021 22:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbhAUWWH (ORCPT ); Thu, 21 Jan 2021 17:22:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726873AbhAUWVZ (ORCPT ); Thu, 21 Jan 2021 17:21:25 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21811C0613ED for ; Thu, 21 Jan 2021 14:20:43 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id q7so3234352wre.13 for ; Thu, 21 Jan 2021 14:20:43 -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=MlB78MSeD43RpQYwEtmuC1BVv0QVQez8DcE5XaZ6MFQ=; b=NYzRsHWfgIO+Mqw/tjqBNLtoZRhY8Z6TLryTVKIV1J9ept1owFwICNgX1difyWCF9c 0w34EQsnrl9fOHfc8bG/jFSlHk3CHWt/tpT3OKdVT92zgP1FxigVEG5OveoDybMDYAa7 4Kklcjf4/H97uKk8dtWQK6JFK7usHOFdkyIx6q6B6ECWhnSZdcaEpaq3R5DkduBQyFLH sjQSA8DG72uv8wPzFNwZS7eA8pYK8Piz+05JLJaTOsh+ewzEqqVSLHKFpsVayZhYZ+DR 8OOXHch4f+jOagJFUnj7LpOz5L87JSnLxL8epN/PYDpBUrPLwrjD5RrfAkF8VKSbu4gO hXQw== 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=MlB78MSeD43RpQYwEtmuC1BVv0QVQez8DcE5XaZ6MFQ=; b=eP0hKy4DTPd3xCf1qrUpfNpJZ5SYvvWU8SZGQqaMHz9pGJ97iSHYbzEZT7fEdoe4+K Qh9Eqt7apog9ArCkgu3OKAN7Dg0rP7lSrIJbIky9+39Gmyt2cCcR1MwtIuglKmZIHBNi yiyZEX1aJp9AMddyAho0WwMVUAhB7i52yVkEymtTPIuiq8H3tekDJKIiAxncDQJSINYU 3mohdTsNe56FHOm4RUtcaldnWoQe7UB8Agim2tvvM8Z2yCyXTQAE1/0rVKmnP4K53sLq XavOlDzrXxvg3ekwYvjkAGqM3bM+ut+p+cCKcoWcNtZozw2judFlcH/+4v8VaXTW1eCd 5Pew== X-Gm-Message-State: AOAM530a1/mzSTozx+w3u/mgVgyPR37V+jq+06iVehCzIz0HIziaby/o G93M12QS+MRhEUDYxuGlppVbvli0/lQ= X-Google-Smtp-Source: ABdhPJwoS8mMO8BZwTBwEGNkZiFxttTqH35x82Wm/vGQjIiZlUmcWHKY9ejC0a1TyphstJ75RCOa3A== X-Received: by 2002:adf:ab1d:: with SMTP id q29mr1381735wrc.415.1611267641781; Thu, 21 Jan 2021 14:20:41 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id v11sm9640642wrt.25.2021.01.21.14.20.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 14:20:41 -0800 (PST) Message-Id: <88c15617b4ba8ae3211b1a01861eb4165f3eda38.1611267638.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 21 Jan 2021 22:20:37 +0000 Subject: [PATCH 2/3] range-diff: handle commit ranges other than A..B Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Uwe =?utf-8?q?Kleine-K=C3=B6nig?= , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin In the `SPECIFYING RANGES` section of gitrevisions[7], two ways are described to specify commit ranges that `range-diff` does not yet accept: "^!" and "^-". Let's accept them. Signed-off-by: Johannes Schindelin --- builtin/range-diff.c | 21 ++++++++++++++++++++- t/t3206-range-diff.sh | 8 ++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/builtin/range-diff.c b/builtin/range-diff.c index 551d3e689cb..6097635c432 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -13,7 +13,26 @@ NULL static int is_range(const char *range) { - return !!strstr(range, ".."); + size_t i; + char c; + + if (strstr(range, "..")) + return 1; + + i = strlen(range); + c = i ? range[--i] : 0; + if (c == '!') + i--; /* might be ...^! or ...^@ */ + else if (isdigit(c)) { + /* handle ...^- */ + while (i > 2 && isdigit(range[--i])) + ; /* keep trimming trailing digits */ + if (i < 2 || range[i--] != '-') + return 0; + } else + return 0; + + return i > 0 && range[i] == '^'; } int cmd_range_diff(int argc, const char **argv, const char *prefix) diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh index 6eb344be031..e217cecac9e 100755 --- a/t/t3206-range-diff.sh +++ b/t/t3206-range-diff.sh @@ -150,6 +150,14 @@ test_expect_success 'simple A B C (unmodified)' ' test_cmp expect actual ' +test_expect_success 'A^! and A^- (unmodified)' ' + git range-diff --no-color topic^! unmodified^-1 >actual && + cat >expect <<-EOF && + 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/ + EOF + test_cmp expect actual +' + test_expect_success 'trivial reordering' ' git range-diff --no-color master topic reordered >actual && cat >expect <<-EOF && From patchwork Thu Jan 21 22:20:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 12037887 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 57A73C433E0 for ; Thu, 21 Jan 2021 22:22:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E2E723A5E for ; Thu, 21 Jan 2021 22:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727151AbhAUWWR (ORCPT ); Thu, 21 Jan 2021 17:22:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726981AbhAUWVZ (ORCPT ); Thu, 21 Jan 2021 17:21:25 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008E4C061786 for ; Thu, 21 Jan 2021 14:20:43 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id 6so3263153wri.3 for ; Thu, 21 Jan 2021 14:20:43 -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=a0l+HITz6SzitgtYi+GV15d+1DsaJwoOm5MRDPNWvgg=; b=hAMjwnr1Lkh6VjoQxKydmSlFVuB2O6J0x5Z9ALvPpWcgj1iLLseBEUYScnskAUKfTG sYAKKgKIjJl/1sbiRPUZfyCAgZ+8WXtrzz9mSJYsaHbb6zSqj9qS1sJA80gT84wEpwfb xiHmOCbb1WAPjleIH4bG/p3jdmPriGJBMKU9x0Zd8QKD33h/ApSkSECvbwUGiVSwWNdt HjduOdj+DrIV9pjdAhEJJEs73TKgF26k1VzYyvdKElu+USrykaXQex8di5vMV4TdPWrO ahBCeGMSbrrzVEfARjDIGrGq9vqu3b2zxy5Xd0JeX/mVoRLqv8J6PnigJmo1NRsCrSW4 wXtw== 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=a0l+HITz6SzitgtYi+GV15d+1DsaJwoOm5MRDPNWvgg=; b=YoBWwGwH7w7lMsi78l18Bk0vx32VpI/xUni2I55m922C4V51dCe4QJVKUX4iHwMP9s dzbvxXKuDeOP6XoG/86otmMQOBnI+EFh8Zzy7N+o51heX/fix1iJy0+4qfp0gXCRqCRV MD0v62Ojmj6uSodhNr7FIFQJK2EIDtCJ8WeYyB6DyssIq8K1xyXc1XMaCwQADTBbXw4W c4+Vdrsvw5gSQpynGUEPxUccWCEbeQYenxsGdI4tmOpy4RYb5TtUR+xzRlLLkjnPo4rD dcxB1Cl8Ri4dwNF64UBBuKUW7oFh6xR+/PUYlUoscPAdqLKxRMZWCa4VsRmHPxIK00YW UC8Q== X-Gm-Message-State: AOAM531MD7f/+J4SQIb45Ya8YC9ojMFZsdiP0j15xHCUzEN3qAMfs93W +zfUPNSEWUaqESPheJiplqyg4PCor1E= X-Google-Smtp-Source: ABdhPJx9g6hGMo9sjegGfrjMo1MjK3xeDQGGWp6lMwSI9ODCKtlznK/t9fVeZh1B0mb3eJ1xG0YWrQ== X-Received: by 2002:a5d:558a:: with SMTP id i10mr1463023wrv.363.1611267642586; Thu, 21 Jan 2021 14:20:42 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d2sm9970262wre.39.2021.01.21.14.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 14:20:42 -0800 (PST) Message-Id: <041456b6e73b3a88097d0cc06056eb43d35d42c6.1611267638.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 21 Jan 2021 22:20:38 +0000 Subject: [PATCH 3/3] range-diff(docs): explain how to specify commit ranges Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Uwe =?utf-8?q?Kleine-K=C3=B6nig?= , Johannes Schindelin , Johannes Schindelin Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Johannes Schindelin From: Johannes Schindelin There are three forms, depending whether the user specifies one, two or three non-option arguments. We've never actually explained how this works in the manual, so let's explain it. Signed-off-by: Johannes Schindelin --- Documentation/git-range-diff.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/git-range-diff.txt b/Documentation/git-range-diff.txt index 9701c1e5fdd..76359baf26d 100644 --- a/Documentation/git-range-diff.txt +++ b/Documentation/git-range-diff.txt @@ -28,6 +28,19 @@ Finally, the list of matching commits is shown in the order of the second commit range, with unmatched commits being inserted just after all of their ancestors have been shown. +There are three ways to specify the commit ranges: + +- ` `: Either commit range can be of the form + `..`, `^!` or `^-`. See `SPECIFYING RANGES` + in linkgit:gitrevisions[7] for more details. + +- `...`. This resembles the symmetric ranges mentioned in + the `SPECIFYING RANGES` section of linkgit:gitrevisions[7], and is + equivalent to `.. ..` where `` is the + merge base as obtained via `git merge-base `. + +- ` `: This is equivalent to `.. + ..`. OPTIONS -------