From patchwork Sat Sep 5 19:08:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11759249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81C80618 for ; Sat, 5 Sep 2020 19:08:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64E942074B for ; Sat, 5 Sep 2020 19:08:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uVdybtNL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728483AbgIETIk (ORCPT ); Sat, 5 Sep 2020 15:08:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728400AbgIETIh (ORCPT ); Sat, 5 Sep 2020 15:08:37 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90166C061245 for ; Sat, 5 Sep 2020 12:08:36 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id t7so1566879pjd.3 for ; Sat, 05 Sep 2020 12:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uG+rdFBgQ4d6bYL826YwKc7u6DJg+MMEMJJlHeoU3VI=; b=uVdybtNL0Zy+eebTEz9AmnCD41cpFOXQCON7p2vkTWdvfgpF7N7NqqM7VOYzchyuBf uhj3dRMSgGWe/UImnux49or3f6haK+lSxDdHwbkpqIGTkFFTLBbgeyZ3IaRM+WYvjfSl lMtJ+EcDf4oxBj+8Jy8pQvkETphq+NWreJ8k/Unmys87F5y5hB2dBFT+I1LDXVLQ+SV/ OHE1BHjiyUiLY5bN5o3Jr/Y6TMV7z4XcJoBSx4gf+pJR6kdq1zs6//Ixxn2S5q7MP+2J RYoBDshJFbf28+9hj1uUDkG0leh//N82bGcah1ribb48Fzjh3V6zOxj9hLDz+XCF6HnE 91FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uG+rdFBgQ4d6bYL826YwKc7u6DJg+MMEMJJlHeoU3VI=; b=L+UuaX8N4E+qwm/FYbKS2ZQEbbUTqzoxsb8QuxEMTNE9bJ7pVlxl+5mYfr4rwDtwke FJjfvkwSfw/MOMEhLxflXUaQCRY7E36BLsUJXivpMAIq/Rc8p+7RMcL1N9pVTOnFUjrX HmvTSaTqSKpo3dWICC/kK6cy7RuaclWuL0JRnBsRWKR6m75QGZmcGnopwzu1PoTXpe0t WX4/AGQ8ah8UwpLl08ymHefJExl2hoqJnylzKOHlH7GjkEyr7T9vDEz1LM6Gfic6Q/eK DQ9cb6LD04wosTo9mWkzsZgKnc8PS6Zw6KTMrjx1uoXuNol9Fy4gpEdhnkZWQ9+LMFjO 9XNA== X-Gm-Message-State: AOAM531/0VhmslsvslG3bqZJYM13/Oz293sf/wgBUD/TT5Ap2X8cw0zH YPa2QifX6geefM9yfNJYo53A42Pl8AM= X-Google-Smtp-Source: ABdhPJyV11/Ir30gEdGk/YGRz8jWsp7CC9yAjpPOWOdwbXQAEsre1IKV7KwHxh8fIg02OJ3pw4+R3w== X-Received: by 2002:a17:90a:9708:: with SMTP id x8mr1447815pjo.213.1599332915730; Sat, 05 Sep 2020 12:08:35 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:5900:d670::1ab5]) by smtp.gmail.com with ESMTPSA id u5sm3045459pfh.215.2020.09.05.12.08.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 12:08:34 -0700 (PDT) From: Denton Liu To: Git Mailing List Subject: [PATCH 1/4] t4068: remove unnecessary >tmp Date: Sat, 5 Sep 2020 12:08:18 -0700 Message-Id: <80e9066a59524ededbb0d0191a93e6e3154c5623.1599332861.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.rc0.135.gc7877b767d In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The many `git diff` invocations have a `>tmp` redirection even though the file is not being used afterwards. Remove these unnecessary redirections. Signed-off-by: Denton Liu --- t/t4068-diff-symmetric.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/t/t4068-diff-symmetric.sh b/t/t4068-diff-symmetric.sh index 31d17a5af0..60c506c2b2 100755 --- a/t/t4068-diff-symmetric.sh +++ b/t/t4068-diff-symmetric.sh @@ -64,27 +64,27 @@ test_expect_success 'diff with two merge bases' ' ' test_expect_success 'diff with no merge bases' ' - test_must_fail git diff br2...br3 >tmp 2>err && + test_must_fail git diff br2...br3 2>err && test_i18ngrep "fatal: br2...br3: no merge base" err ' test_expect_success 'diff with too many symmetric differences' ' - test_must_fail git diff br1...master br2...br3 >tmp 2>err && + test_must_fail git diff br1...master br2...br3 2>err && test_i18ngrep "usage" err ' test_expect_success 'diff with symmetric difference and extraneous arg' ' - test_must_fail git diff master br1...master >tmp 2>err && + test_must_fail git diff master br1...master 2>err && test_i18ngrep "usage" err ' test_expect_success 'diff with two ranges' ' - test_must_fail git diff master br1..master br2..br3 >tmp 2>err && + test_must_fail git diff master br1..master br2..br3 2>err && test_i18ngrep "usage" err ' test_expect_success 'diff with ranges and extra arg' ' - test_must_fail git diff master br1..master commit-D >tmp 2>err && + test_must_fail git diff master br1..master commit-D 2>err && test_i18ngrep "usage" err ' From patchwork Sat Sep 5 19:08:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11759253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 49569112E for ; Sat, 5 Sep 2020 19:08:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 28E6F20757 for ; Sat, 5 Sep 2020 19:08:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eMU5Fjp8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728507AbgIETIr (ORCPT ); Sat, 5 Sep 2020 15:08:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728449AbgIETIj (ORCPT ); Sat, 5 Sep 2020 15:08:39 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F342C061244 for ; Sat, 5 Sep 2020 12:08:37 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id b124so6413916pfg.13 for ; Sat, 05 Sep 2020 12:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=4AVt485aTuo7yvtGO3YBhuaEV0nIIPDV4HX+ZW+Zhak=; b=eMU5Fjp8FqNu3xPQ5JkG8MUxQS4jW80XinlZGleO6gN5kOhD/0i/qNJPbAt4WC9TdS a97B3LZYrkLvCampHLDwyc7VKYs0W7Z5JyjeUfClaSM5Wn7+2/qqOXVdNuGxooBZx9yU XMDuhgYoyhQoElip7oBHkDf5nWEbq8VTostxICUHdLikxd70VS45Sa1H2MjdZ81IouOU woRYT00dTdsXyMeAZjBXZ6TPzz2iwK8LKdvvl9ANbq/rpxLKccLFvsg9ZUo5I2JQObrh Ziqw6GUkktupoCHF8En2fyYUxDBQ4n0nuN/3JrXrYi0TqIn26468mbDVo+y9R9z9uiAP Mlnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4AVt485aTuo7yvtGO3YBhuaEV0nIIPDV4HX+ZW+Zhak=; b=JIvf+40qsXQNlR8dT00W2i2BCEDui7Yd49VufxanTiFW9MryW/X+8mGaiZskoQx37p q/KV7rmCg+6YaCiQPDIkJ7we6wNgp7tKWgmxUvZAy0dCc+oKO3D35lYBw0K9s58+8g/l KpXhBs+yCh4QKN0Ht66sydyV5m94WxPlwueNeqUrJNdbHyXgsjSow0UCmEhDPCeZ3vTo d2aM9W7D8v9cqcUP0d8bM7Zqn8QdliweGH+IlyFqUE9U6oHoAlodY/ZCK1PtCgP0jve0 AvF1R+7+6pxvjudKLtznB03wVKURgei2JvBqZ8Qr0NrYvYPlgDSMYueINTIvwQqqjF6U /nMQ== X-Gm-Message-State: AOAM531QzZm5+VoegikdRhCVJxea3JlxSJOTwW+6zR49b6sS2TN/rZ1F L3JE3+8O16x+q6KWSNttkpkHeK1IcRQ= X-Google-Smtp-Source: ABdhPJwfHixVUve4iLLVuVSlMq2aTUFpYpnq9tW7npGKnqAEX0zKyPqMwVGX2pVk33UBkCvDMedLfg== X-Received: by 2002:a62:1b56:: with SMTP id b83mr12005281pfb.15.1599332916668; Sat, 05 Sep 2020 12:08:36 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:5900:d670::1ab5]) by smtp.gmail.com with ESMTPSA id u5sm3045459pfh.215.2020.09.05.12.08.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 12:08:36 -0700 (PDT) From: Denton Liu To: Git Mailing List Subject: [PATCH 2/4] git-diff.txt: backtick quote command text Date: Sat, 5 Sep 2020 12:08:19 -0700 Message-Id: <8e72bd8fea276d40729705eb8dcc63bcc9faef2c.1599332861.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.rc0.135.gc7877b767d In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The modern way to quote commands in the documentation is to use backticks instead of double-quotes as this renders the text with the code style. Convert double-quoted command text to backtick-quoted commands. While we're at it, quote one instance of `^@`. Signed-off-by: Denton Liu --- Documentation/git-diff.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 727f24d16e..8f7b4ed3ca 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -68,13 +68,13 @@ files on disk. This form is to view the results of a merge commit. The first listed must be the merge itself; the remaining two or more commits should be its parents. A convenient way to produce - the desired set of revisions is to use the {caret}@ suffix. + the desired set of revisions is to use the `^@` suffix. For instance, if `master` names a merge commit, `git diff master master^@` gives the same combined diff as `git show master`. 'git diff' [] .. [--] [...]:: - This is synonymous to the earlier form (without the "..") for + This is synonymous to the earlier form (without the `..`) for viewing the changes between two arbitrary . If on one side is omitted, it will have the same effect as using HEAD instead. @@ -83,20 +83,20 @@ files on disk. This form is to view the changes on the branch containing and up to the second , starting at a common ancestor - of both . "git diff A\...B" is equivalent to - "git diff $(git merge-base A B) B". You can omit any one + of both . `git diff A...B` is equivalent to + `git diff $(git merge-base A B) B`. You can omit any one of , which has the same effect as using HEAD instead. Just in case you are doing something exotic, it should be noted that all of the in the above description, except -in the last two forms that use ".." notations, can be any +in the last two forms that use `..` notations, can be any . For a more complete list of ways to spell , see "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. However, "diff" is about comparing two _endpoints_, not ranges, -and the range notations (".." and -"\...") do not mean a range as defined in the +and the range notations (`..` and +`...`) do not mean a range as defined in the "SPECIFYING RANGES" section in linkgit:gitrevisions[7]. 'git diff' [] :: @@ -144,9 +144,9 @@ $ git diff HEAD <3> + <1> Changes in the working tree not yet staged for the next commit. <2> Changes between the index and your last commit; what you - would be committing if you run "git commit" without "-a" option. + would be committing if you run `git commit` without `-a` option. <3> Changes in the working tree since your last commit; what you - would be committing if you run "git commit -a" + would be committing if you run `git commit -a` Comparing with arbitrary commits:: + From patchwork Sat Sep 5 19:08:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11759251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52DD3112E for ; Sat, 5 Sep 2020 19:08:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37B042074B for ; Sat, 5 Sep 2020 19:08:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K9dvZMG5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728502AbgIETIn (ORCPT ); Sat, 5 Sep 2020 15:08:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728397AbgIETIi (ORCPT ); Sat, 5 Sep 2020 15:08:38 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80AEAC061245 for ; Sat, 5 Sep 2020 12:08:38 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id 31so6013569pgy.13 for ; Sat, 05 Sep 2020 12:08:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xQI/6CNpU4SSYBeNcucHOniADlACfETmjQN7IYpwlBY=; b=K9dvZMG5JcusoezR1IVNvqHRlidxp8fVQyOHcVuY6cPL1llJd+Kvi9ddKHJ0CjnCVA FuwtLw2FqVaS7ovSqatxXAEPqfIzrjFu+Axk4WhIkyC3+f9Knbs3EmdHwjYPr+mwzJpo 5nc5MJNS6EMuEkEyX3/KIbVS2w8tWRCHk9omjrbHKfB52Qyt+SpZ128cZ+HXgy2Lj4iA 2TqMH4vRhxRhd1gC419EiD7i6opNpYN6jWo/yufoJtXC0LxNhQqoBkVQvvTpJokExq07 8zDi/RmV4IHmvvFMcL2+0xSOpgYSqeX+QTburcFAPFLj3Ps2vgt5PyX/b2EDVR0EGyh+ +ZfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xQI/6CNpU4SSYBeNcucHOniADlACfETmjQN7IYpwlBY=; b=ARKMbGN++8ec1xUnhFEndlGbc+m0VcS6+vTH7NZBH4TRk+Mpw5SJD4ozuTAsW0NV+y njrwQhYQ41YAAhzHj97ifl6L0bhad283LhkhSSDeZrlY6cNMsvXEQ9/zpdZBbeHUvmEH 4PLqiofsYnVyEs1KNfzuMnTy9H9yTspbF9oG6lK8aVdidgGRMzQ6+zWlKaKbBiHaNaKN fn7N//Dmdcki9b8Zr35SuZmU7EBB3hQGweNHWG+iNEbebQ9BbDuNV2M3dq0dAowqT9Zt UxyBPe3+1p/10g1jeDJZ+CRwOHAaOYQSziP+FuExi3YI7l/L4zown1PfZd6F9I3NeJBg mHqQ== X-Gm-Message-State: AOAM530I1WPbxK29M7uma9U6qog6G1JHPjSpukJtua9/XuV5QMZqZCJp +dK5/FUnlm66sIJroDjwQpU0lLDPrvs= X-Google-Smtp-Source: ABdhPJw+MYGrAud8wXy8OzNeaelB87nOoMJmu/fmmtC/CfJ8GJ1YraKdIMXjDVQBYGfKFxZ+HN1yNw== X-Received: by 2002:a63:7b54:: with SMTP id k20mr11443058pgn.75.1599332917743; Sat, 05 Sep 2020 12:08:37 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:5900:d670::1ab5]) by smtp.gmail.com with ESMTPSA id u5sm3045459pfh.215.2020.09.05.12.08.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 12:08:36 -0700 (PDT) From: Denton Liu To: Git Mailing List Subject: [PATCH 3/4] builtin/diff: parse --no-index using parse_options() Date: Sat, 5 Sep 2020 12:08:20 -0700 Message-Id: X-Mailer: git-send-email 2.28.0.rc0.135.gc7877b767d In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of parsing the `--no-index` option with a plain strcmp, use parse_options() to parse options. This allows us to easily add more options in a future commit. As a result of this change, `--no-index` is removed from `argv` so, as a result, we no longer need to handle it in diff_no_index(). Signed-off-by: Denton Liu --- builtin/diff.c | 33 ++++++++++++++++++++++----------- diff-no-index.c | 15 +++------------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/builtin/diff.c b/builtin/diff.c index cb98811c21..0e086ed7c4 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -373,6 +373,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix) int nongit = 0, no_index = 0; int result = 0; struct symdiff sdiff; + struct option options[] = { + OPT_SET_INT_F(0, "no-index", &no_index, + N_("compare the given paths on the filesystem"), + DIFF_NO_INDEX_EXPLICIT, + PARSE_OPT_NONEG), + OPT_END(), + }; /* * We could get N tree-ish in the rev.pending_objects list. @@ -406,21 +413,25 @@ int cmd_diff(int argc, const char **argv, const char *prefix) * Other cases are errors. */ - /* Were we asked to do --no-index explicitly? */ - for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "--")) { - i++; - break; - } - if (!strcmp(argv[i], "--no-index")) - no_index = DIFF_NO_INDEX_EXPLICIT; - if (argv[i][0] != '-') - break; - } + argc = parse_options(argc, argv, prefix, options, NULL, + PARSE_OPT_KEEP_DASHDASH | + PARSE_OPT_KEEP_ARGV0 | + PARSE_OPT_KEEP_UNKNOWN | + PARSE_OPT_NO_INTERNAL_HELP); prefix = setup_git_directory_gently(&nongit); if (!no_index) { + int i; + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--")) { + i++; + break; + } + if (argv[i][0] != '-') + break; + } + /* * Treat git diff with at least one path outside of the * repo the same as if the command would have been executed diff --git a/diff-no-index.c b/diff-no-index.c index 7814eabfe0..da82e2d090 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -243,28 +243,19 @@ int diff_no_index(struct rev_info *revs, int implicit_no_index, int argc, const char **argv) { - int i, no_index; + int i; const char *paths[2]; struct strbuf replacement = STRBUF_INIT; const char *prefix = revs->prefix; - struct option no_index_options[] = { - OPT_BOOL_F(0, "no-index", &no_index, "", - PARSE_OPT_NONEG | PARSE_OPT_HIDDEN), - OPT_END(), - }; - struct option *options; - options = parse_options_concat(no_index_options, - revs->diffopt.parseopts); - argc = parse_options(argc, argv, revs->prefix, options, + argc = parse_options(argc, argv, revs->prefix, revs->diffopt.parseopts, diff_no_index_usage, 0); if (argc != 2) { if (implicit_no_index) warning(_("Not a git repository. Use --no-index to " "compare two paths outside a working tree")); - usage_with_options(diff_no_index_usage, options); + usage_with_options(diff_no_index_usage, revs->diffopt.parseopts); } - FREE_AND_NULL(options); for (i = 0; i < 2; i++) { const char *p = argv[argc - 2 + i]; if (!strcmp(p, "-")) From patchwork Sat Sep 5 19:08:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11759255 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33F18112E for ; Sat, 5 Sep 2020 19:09:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 128E22074D for ; Sat, 5 Sep 2020 19:09:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bGtU21L7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728585AbgIETJE (ORCPT ); Sat, 5 Sep 2020 15:09:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728449AbgIETJD (ORCPT ); Sat, 5 Sep 2020 15:09:03 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04C75C061244 for ; Sat, 5 Sep 2020 12:09:03 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id h2so2661770plr.0 for ; Sat, 05 Sep 2020 12:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=plN2wm577lGn+Pqcavnl6I6FixoCaKw1gMizd1/qJ3Q=; b=bGtU21L7pgvdFH4DQzSbMyyOVp+gND9VlEpjXt3oHIEOpjgs61hf0NmWoasSmLdFpf /fJmxKZQDEKb5SANNw+fcMOBpfgbMvWqLHo2koYX98EkDy1j80iGBQs6prcoY239dMcY 6OmYgNGBnOpJpbPDPNYF58XEHGQ9vLaJ7j5l8JnXSgDEarA7A/D6KvtXceeiwSVvtK9f OL3NPNsHDqj2G+O7zX3DoKNYb1N7kM4lIugRheJg0z7XzplT+f0SA/hTNz+WUcTD3La1 1LS26NMeWAgI9nxPuf9G0XgCtmdDuFIDXwtl+1dndZvQtSpSw0QUpHDr/kdFIEVWpDn0 uf+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=plN2wm577lGn+Pqcavnl6I6FixoCaKw1gMizd1/qJ3Q=; b=pZkjnerqHGO7tXkzgHGjoDo48WkH2KK9dogaJ2SUlz1JTUKnQ0LPsfdyRxn22oRcdY 0tTk8e01hBwE0726naiF5KPI9uN4b7nA9RhbzZ7HiIe+8GHQjUs9ylq+3c9/9ClGgoWY Eix0XW8Ypjwf5yw1+b969AlGUGhDT1yk848w6lfjLKvxdR96nucXci/QFGJd12L3GI4O 74NwWsc6SFn2ndl1U2+sPQvqhytFhMhqr5J5Shll+PQFgLDM6Zu7j2ULGJ+ikDO/mX2v +NGsOh0yM6Y9cbXOqJBX3rY/VMUYyv8B3bRPFcbvRh6TVaFe2WmdXE+KZTXNMtDQAomg KAXw== X-Gm-Message-State: AOAM5300xXhnArv2++gDBQiBqOghFQ4SNUfDp5PSNuTv7ape+bqmne96 cyF3D2AQ7lBLDkM0Xnn4rM93Wo6OWzQ= X-Google-Smtp-Source: ABdhPJyORdAmeTZ6IoQbeQ4D7BGhFSspgAkI0t9nb9d4cCTihLjdfuvDU7AXCuC2LHh5sYu0qI8dfw== X-Received: by 2002:a17:902:d904:: with SMTP id c4mr13125077plz.115.1599332940651; Sat, 05 Sep 2020 12:09:00 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:5900:d670::1ab5]) by smtp.gmail.com with ESMTPSA id u5sm3045459pfh.215.2020.09.05.12.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 12:08:59 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Jonathan Nieder Subject: [PATCH 4/4] builtin/diff: learn --merge-base Date: Sat, 5 Sep 2020 12:08:21 -0700 Message-Id: <231ba3f661cc4aa7a55c44e339e187c6d70c5507.1599332861.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.rc0.135.gc7877b767d In-Reply-To: References: MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order to get the diff between a commit and its merge base, the currently preferred method is to use `git diff A...B`. However, the range-notation with diff has, time and time again, been noted as a point of confusion and thus, it should be avoided. Although we have a substitute for the double-dot notation, we don't have any replacement for the triple-dot notation. Introduce the `--merge-base` flag as a replacement for triple-dot notation. Thus, we would be able to write the above as `git diff --merge-base A B`, allowing us to gently deprecate range-notation completely. Suggested-by: Jonathan Nieder Signed-off-by: Denton Liu --- Documentation/git-diff.txt | 24 ++++++++++-- builtin/diff.c | 59 ++++++++++++++++++++++++++++ t/t4068-diff-symmetric.sh | 79 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 3 deletions(-) diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 8f7b4ed3ca..0031729794 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -12,7 +12,7 @@ SYNOPSIS 'git diff' [] [] [--] [...] 'git diff' [] --cached [] [--] [...] 'git diff' [] [...] [--] [...] -'git diff' [] ... [--] [...] +'git diff' [] --merge-base [--cached] [ []] [--] [...] 'git diff' [] 'git diff' [] --no-index [--] @@ -63,6 +63,24 @@ files on disk. This is to view the changes between two arbitrary . +'git diff' [] --merge-base [--cached] [ []] [--] [...]:: + + In this form, the "before" side will be the merge base of the + two given commits. If either commit is omitted, it will default + to HEAD. ++ +In the case where two commits are given, a diff is displayed between the +merge base and the second commit. `git diff --merge-base A B` is +equivalent to `git diff $(git merge-base A B) B`. ++ +In the case where one commit is given, a diff is displayed between the +merge base and the working tree or the index if `--cached` is given. +`git diff --merge-base A` is equivalent to `git diff $(git merge-base A +HEAD)`. ++ +In the case where no commits are given, this form behaves identically to +as if no `--merge-base` were supplied. + 'git diff' [] ... [--] [...]:: This form is to view the results of a merge commit. The first @@ -89,8 +107,8 @@ files on disk. Just in case you are doing something exotic, it should be noted that all of the in the above description, except -in the last two forms that use `..` notations, can be any -. +in the `--merge-base` case and the last two forms that use `..` +notations, can be any . For a more complete list of ways to spell , see "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. diff --git a/builtin/diff.c b/builtin/diff.c index 0e086ed7c4..0af5a6c8c9 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -19,6 +19,7 @@ #include "builtin.h" #include "submodule.h" #include "oid-array.h" +#include "commit-reach.h" #define DIFF_NO_INDEX_EXPLICIT 1 #define DIFF_NO_INDEX_IMPLICIT 2 @@ -371,6 +372,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) int blobs = 0, paths = 0; struct object_array_entry *blob[2]; int nongit = 0, no_index = 0; + int merge_base = 0; int result = 0; struct symdiff sdiff; struct option options[] = { @@ -378,6 +380,8 @@ int cmd_diff(int argc, const char **argv, const char *prefix) N_("compare the given paths on the filesystem"), DIFF_NO_INDEX_EXPLICIT, PARSE_OPT_NONEG), + OPT_BOOL(0, "merge-base", &merge_base, + N_("use the merge base between the two commits as the diff base")), OPT_END(), }; @@ -457,6 +461,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix) rev.diffopt.flags.allow_external = 1; rev.diffopt.flags.allow_textconv = 1; + if (no_index && merge_base) + die(_("--no-index and --merge-base are mutually exclusive")); + /* If this is a no-index diff, just run it and exit there. */ if (no_index) exit(diff_no_index(&rev, no_index == DIFF_NO_INDEX_IMPLICIT, @@ -513,6 +520,58 @@ int cmd_diff(int argc, const char **argv, const char *prefix) } symdiff_prepare(&rev, &sdiff); + + if (merge_base && rev.pending.nr) { + int i; + struct commit *mb_child[2] = {0}; + struct commit_list *merge_bases; + int old_nr; + + for (i = 0; i < rev.pending.nr; i++) { + struct object *obj = rev.pending.objects[i].item; + if (obj->flags) + die(_("--merge-base does not work with ranges")); + if (obj->type != OBJ_COMMIT) + die(_("--merge-base only works with commits")); + } + + /* + * This check must go after the for loop above because A...B + * ranges produce three pending commits, resulting in a + * misleading error message. + */ + if (rev.pending.nr > ARRAY_SIZE(mb_child)) + die(_("--merge-base does not work with more than two commits")); + + for (i = 0; i < rev.pending.nr; i++) + mb_child[i] = lookup_commit_reference(the_repository, &rev.pending.objects[i].item->oid); + if (rev.pending.nr < ARRAY_SIZE(mb_child)) { + struct object_id oid; + + if (rev.pending.nr != 1) + BUG("unexpected rev.pending.nr: %d", rev.pending.nr); + + if (get_oid("HEAD", &oid)) + die(_("unable to get HEAD")); + + mb_child[1] = lookup_commit_reference(the_repository, &oid); + } + + merge_bases = repo_get_merge_bases(the_repository, mb_child[0], mb_child[1]); + if (!merge_bases) + die(_("no merge base found")); + if (merge_bases->next) + die(_("multiple merge bases found")); + + old_nr = rev.pending.nr; + rev.pending.nr = 1; + object_array_pop(&rev.pending); + add_object_array(&merge_bases->item->object, oid_to_hex(&merge_bases->item->object.oid), &rev.pending); + rev.pending.nr = old_nr; + + free_commit_list(merge_bases); + } + for (i = 0; i < rev.pending.nr; i++) { struct object_array_entry *entry = &rev.pending.objects[i]; struct object *obj = entry->item; diff --git a/t/t4068-diff-symmetric.sh b/t/t4068-diff-symmetric.sh index 60c506c2b2..0e43ed7660 100755 --- a/t/t4068-diff-symmetric.sh +++ b/t/t4068-diff-symmetric.sh @@ -88,4 +88,83 @@ test_expect_success 'diff with ranges and extra arg' ' test_i18ngrep "usage" err ' +test_expect_success 'diff --merge-base with two commits' ' + git diff commit-C master >expect && + git diff --merge-base br2 master >actual && + test_cmp expect actual +' + +test_expect_success 'diff --merge-base with no commits' ' + git diff --merge-base >actual && + test_must_be_empty actual +' + +test_expect_success 'diff --merge-base with one commit' ' + git checkout master && + git diff commit-C >expect && + git diff --merge-base br2 >actual && + test_cmp expect actual +' + +test_expect_success 'diff --merge-base with one commit and unstaged changes' ' + git checkout master && + test_when_finished git reset --hard && + echo unstaged >>c && + git diff commit-C >expect && + git diff --merge-base br2 >actual && + test_cmp expect actual +' + +test_expect_success 'diff --merge-base with one commit and staged and unstaged changes' ' + git checkout master && + test_when_finished git reset --hard && + echo staged >>c && + git add c && + echo unstaged >>c && + git diff commit-C >expect && + git diff --merge-base br2 >actual && + test_cmp expect actual +' + +test_expect_success 'diff --merge-base --cached with one commit and staged and unstaged changes' ' + git checkout master && + test_when_finished git reset --hard && + echo staged >>c && + git add c && + echo unstaged >>c && + git diff --cached commit-C >expect && + git diff --cached --merge-base br2 >actual && + test_cmp expect actual +' + +test_expect_success 'diff --merge-base with --no-index' ' + test_must_fail git diff --merge-base --no-index expect actual 2>err && + test_i18ngrep "fatal: --no-index and --merge-base are mutually exclusive" err +' + +test_expect_success 'diff --merge-base with range' ' + test_must_fail git diff --merge-base br2..br3 2>err && + test_i18ngrep "fatal: --merge-base does not work with ranges" err +' + +test_expect_success 'diff --merge-base non-commit' ' + test_must_fail git diff --merge-base master^{tree} 2>err && + test_i18ngrep "fatal: --merge-base only works with commits" err +' + +test_expect_success 'diff --merge-base with three commits' ' + test_must_fail git diff --merge-base br1 br2 master 2>err && + test_i18ngrep "fatal: --merge-base does not work with more than two commits" err +' + +test_expect_success 'diff --merge-base with no merge bases' ' + test_must_fail git diff --merge-base br2 br3 2>err && + test_i18ngrep "fatal: no merge base found" err +' + +test_expect_success 'diff --merge-base with multiple merge bases' ' + test_must_fail git diff --merge-base master br1 2>err && + test_i18ngrep "fatal: multiple merge bases found" err +' + test_done