From patchwork Sun Sep 20 11:22: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: 11787441 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 828D26CB for ; Sun, 20 Sep 2020 11:22:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5BCEE20EDD for ; Sun, 20 Sep 2020 11:22:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BuKCOyq6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726293AbgITLWi (ORCPT ); Sun, 20 Sep 2020 07:22:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbgITLWi (ORCPT ); Sun, 20 Sep 2020 07:22:38 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EA12C0613CE for ; Sun, 20 Sep 2020 04:22:38 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id k13so6022862pfg.1 for ; Sun, 20 Sep 2020 04:22:38 -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=v5A/OJANxMU/wXJK9DY23VPVNuseHxMDJ8xntHmc1qk=; b=BuKCOyq619cIXxYkrq2Wm7kpQuT5Unrj/4yEQD0LF0qJp/mmbW0fqb7N7DZuX4eWua trvATJXnPEHXKicaayS9vRT/7BDQoNRS9lCS70Gao3jz/NSMVkJCDu/NgSoMaw3VhVuS UzVzjK7qUF/oph2Oa2jx6buSB1L+81/ZKKSLT8SV5LITq2809O4ujuCpVQDTnep0TLuU lWyNwOHlgqmhnTUyc0xk2lFxMoxCe0Y8XgW1yo1RE+0qr+ilSl7JokJ1FT4V88vIAbcU H1k7u0EiOMtY/SZ0slg5BiNwXtUAKPK2YJGUi7sske5IBZDSB2hINFslqmX90iJFvS7q eo4A== 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=v5A/OJANxMU/wXJK9DY23VPVNuseHxMDJ8xntHmc1qk=; b=rJcTnJZu87Qa9kM4Z5aoS8Z3romnN91GgyFbDCkTBYtK/aLOUQQx7fOIX9S3vOst+0 5JFMlxBwY2IF5csH93gZGmGOTa+6zERzzDJx/GCgIgMl7y9wsYJHil9QzlDr+NoHxJkS k4jDFrXKxB2kSQgHBhCy8RQCEpH1/mFWMxZofSCE61vCx/TBAWPwYfNYuTQCR3hsN+Cl cutfR0iYYMndUb0brdNdOU1mpl/0RUqrk2uZi2wgUNRaL689Gb4/FEqlBmOIc+9QHv31 jv4yKroaHm03GjJWNFIEEWKW5gHqV5ucN7TbVCrIHWeF/YoZi2Cw4Ia0g86h7rXWib9e C6fQ== X-Gm-Message-State: AOAM5314x+iW31IMGnCNMzDkQVjT8wNtujIRz0C9S0PqSn6EDckZHWVc dgX8rDKyLo3X8YWGJmZRfjY7dVtsMbg= X-Google-Smtp-Source: ABdhPJwjJIyApX9ffpdxFlI8yDVGt+qUG/tyAlNHA4KT/mKhr+L2ssv/jWT8SP02VpTBEYuOf2Bnrw== X-Received: by 2002:aa7:9986:0:b029:142:2501:39db with SMTP id k6-20020aa799860000b0290142250139dbmr23011475pfh.42.1600600956926; Sun, 20 Sep 2020 04:22:36 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:36 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 01/10] t4068: remove unnecessary >tmp Date: Sun, 20 Sep 2020 04:22:18 -0700 Message-Id: <80e9066a59524ededbb0d0191a93e6e3154c5623.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 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 Sun Sep 20 11:22: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: 11787443 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 DD94D139F for ; Sun, 20 Sep 2020 11:22:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B96E620EDD for ; Sun, 20 Sep 2020 11:22:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hX3sKBs5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726326AbgITLWj (ORCPT ); Sun, 20 Sep 2020 07:22:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbgITLWi (ORCPT ); Sun, 20 Sep 2020 07:22:38 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A603EC061755 for ; Sun, 20 Sep 2020 04:22:38 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id q4so5698996pjh.5 for ; Sun, 20 Sep 2020 04:22:38 -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=IyBVAH6DELM7zI4yYqDifCKWGj58OkgJ6OU86uSCDcs=; b=hX3sKBs51CVOUPyAEOxQ6pTegvdh5+N6suCDJtInovlqbsWI5LZ/iODvZsVG5KLvbi wf47KOEr0X5qKSi0LpGkGJF9yYDNUDCOY/Z7e/JshqAyYwTSrGqFgzZlq16mDorN8L52 MvtgotfZhA+Tens14D4TxH6rEcOhhPER9dEnnNFU2FQrFxgzwFG5sN+mkDNCacpPUBAO 9M9ZiFpg7WXnsVfVpoG7ji2eBy/aFDzStPcglB/XgK8PvyQF3hCwLrwfilGnFrzlLh+v YQNAqprZzJXciH+rrXG39XCLqosNZvAWK4cS1faurzN1QQubtrGeKGja2bR3bYtriKt2 aPHQ== 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=IyBVAH6DELM7zI4yYqDifCKWGj58OkgJ6OU86uSCDcs=; b=uj09KaCLxTbwn+yrv/vdNGBdNWiafoskLJgtxFUaMROENnS4x1Errrj7KgSCdEw5d/ v8/xHMFd0Pi5PTIZoSkk+qF3/wtpWpBNRS8/zjP2PghzwvKC84kNlKpzw9RPPDrx5VmQ eT7gTg6y3Dfz677xEbyOJj3LLNW1p7uR5Qb+a2pnfkrUk/Z+UguZBIwGsZ9B5IJh+LkY ogHcFFQsQFpuKbUOVxbKSGQEOb+QM9gAvra0h10bizqdvuZ9B+Yat/22tdjyvfD4ShvJ ySljimlvIk1v1HM7MlB4/zrsjJ/7BpqhnJJSZQ8ZQmk8HaX7vGFOO52OFlg27jH6Y4YT XHFQ== X-Gm-Message-State: AOAM533jX/lvxuMgGSjY+CIe66edsK3dHjm+SrLcMNci4w8qj4dLNTOz +OdEgj/8XJ/ktlDZAXMrwec9COTrWG8= X-Google-Smtp-Source: ABdhPJyPMxVz2yt1id1HoTDYMRd4nzifo3S/3bMBlCTjYhSq0oDStvc3hj0+N2tbVplwd5AWw1mudg== X-Received: by 2002:a17:90a:d914:: with SMTP id c20mr21188337pjv.34.1600600958054; Sun, 20 Sep 2020 04:22:38 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:37 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 02/10] git-diff-index.txt: make --cached description a proper sentence Date: Sun, 20 Sep 2020 04:22:19 -0700 Message-Id: <21b20281e6a1fa265d4853fa04cc71ba7e843267.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Denton Liu --- Documentation/git-diff-index.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-diff-index.txt b/Documentation/git-diff-index.txt index f4bd8155c0..25fe165f00 100644 --- a/Documentation/git-diff-index.txt +++ b/Documentation/git-diff-index.txt @@ -27,7 +27,7 @@ include::diff-options.txt[] The id of a tree object to diff against. --cached:: - do not consider the on-disk file at all + Do not consider the on-disk file at all. -m:: By default, files recorded in the index but not checked From patchwork Sun Sep 20 11:22: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: 11787451 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 88168174A for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F4EB216C4 for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JZihDyNd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbgITLWr (ORCPT ); Sun, 20 Sep 2020 07:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726267AbgITLWk (ORCPT ); Sun, 20 Sep 2020 07:22:40 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B49A6C0613CE for ; Sun, 20 Sep 2020 04:22:39 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id b124so6515164pfg.13 for ; Sun, 20 Sep 2020 04:22:39 -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=BBM6Z4UFUqbzxzSnSnByRwvr2Y6v7sMzlGe/goEffBw=; b=JZihDyNdKA3iWZu3gGX9wOERV45ZUZiGvyNkLxwqM9V5LeoEEpgJCAITiSuorNCsUn yQJoy3Dulxfjtv3GWZHv+V9SQ9Me2gjM8bqYKEkg8VqdzeQVyu4cfVV8bA7EjkgSGuCr ZaXF82FOgshholxI/RR/BTA1G/OSL9cPW0fWvNtXiCoEQ4CgHSbmVjB6q0A97TJRhaCk LdUiTsVU5jczph60zeFdVY5gYp/s721CZPgPL0dbhPc2z7O62YhVKI6W1yYaFjqa3co8 tZQ3xlP+LcVKTGUVQtmIw6xB75VkGWK3vrAKuWl7d57ocxCYWpgi0JVWKguoCtEHZjmP 6cew== 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=BBM6Z4UFUqbzxzSnSnByRwvr2Y6v7sMzlGe/goEffBw=; b=aDT2cVVEvvyfVRNL/dFxilRUF65cr3I87bnep6xEcRoIARYm1NveYXlZwfKb4PzejW qnPjXJRBOoYeqh7d+j2/Qe6LAZoZVanyWmmH0D3UFxXUTEzyLbnJT6p/1ySey+OxH0VH T96n+czJ+/ABcwy+w4Qrz+6AG7rLIdnucNJ4eDFVtaYoWdZLUNTRooMAtsjFbED83ew+ Q1C8t0+qqF8jSn5ekg7u2UvyiI/I8+gPuy0JhTyalKSDvMTDovhp3Vzi3vf57AVb9ilg KH5NPWVp0VxLu/LfmVktizkLka8SD0RonokduIpReae9V6gqBhQ3dFc16WgFPLqQKpfJ LvVA== X-Gm-Message-State: AOAM533mrd6reGhlMuW2Ai+VM7iFOdCnJ5lBErSy+8+f2N/7z5sH3vH8 lUWXvhvYPAORqctSCuYF80K4blZrBK4= X-Google-Smtp-Source: ABdhPJwT5F4+249tFYgGIODZwGTZbcjPZbR23+r4vmiDYl1Z31ndBJ+gB6e+GclNw687VTh83M9CWg== X-Received: by 2002:aa7:8ec7:0:b029:13e:d13d:a080 with SMTP id b7-20020aa78ec70000b029013ed13da080mr38329133pfr.23.1600600959018; Sun, 20 Sep 2020 04:22:39 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:38 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 03/10] git-diff.txt: backtick quote command text Date: Sun, 20 Sep 2020 04:22:20 -0700 Message-Id: X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 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 Sun Sep 20 11:22: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: 11787455 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 747446CA for ; Sun, 20 Sep 2020 11:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5A78020EDD for ; Sun, 20 Sep 2020 11:22:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gbG11VtX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726381AbgITLWq (ORCPT ); Sun, 20 Sep 2020 07:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726327AbgITLWk (ORCPT ); Sun, 20 Sep 2020 07:22:40 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95760C0613CF for ; Sun, 20 Sep 2020 04:22:40 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id u3so5465198pjr.3 for ; Sun, 20 Sep 2020 04:22:40 -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=gfpWlT4sg5lq1KMppHolcjV1QEI4dUWXY/Lsv3SmB6o=; b=gbG11VtXMGK+8oo149uMVi/g70OLzzinb0RrO/+V7HaZIuaOjsiTlmJrnoGhHXf5xe 3ClvQKvYfh05DxQ520kmY6L6psvJzOGRct+VHR0zazwSr21G6EMaOe+b/T+K7B0WQddF sWhfuPG3BkKPgo19CvnqlNasUYbdAw7sC86U3ThzuuKECeIU7o4ClGHgkgAX5F4TqXh5 D0M3Bzn+PUcl08NihzMwRCk1dpjzbQ8GJiQKFak/QrihmfQ5xabw1niItpyGkHL84/xN 441bYY4Grya63bwslqrW7jN62xzYFDE7qQKJJjDLbEdPEQA90I3SxMbhaMfxA49ap5YI 1h6w== 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=gfpWlT4sg5lq1KMppHolcjV1QEI4dUWXY/Lsv3SmB6o=; b=mocV0r/sRBUiWUET8OnNyVcWRlNnGysBBOkTW5M3hrPptjpwFOCKeppxNVJIxoKFXX dUbgd3HBFpG0jiTg+h4XNK0KJi6q2VklFZEtlXh+EW5KD3yq4HKbGEJ/ldyduqRWC0GF Js3DAmFxFDQARnit4QolxnVTNXSyEvipJNGOb1En/TytHkkYzNAh6nBBBpdvI28ASAEc sPZDVbmw27EgueaG8xudCmXerbb4vqw7gh8EsqDXy+v6f/+jzXPZoXjyYPFANrK/o9ET I/s7bnM5+siYuG0w5ijhcllghFrz2LcD37iSXrniG6fZJaQeO/tF7yeQv/DQRcwhwGUT 4/Kw== X-Gm-Message-State: AOAM530FzzIJXrrfR+zgt79hMx/lMafRffImR0sJxxxSijyipUNqdxUd 4xfPqn5YX/T6dL158P2AMZ8rqXMDMEA= X-Google-Smtp-Source: ABdhPJyTIZDPx7z4E/ucAqgvg98SAYpKovAGmLDXHnsvA+Baa8VX/INqP618x9XE1K9lSLMi5bToCw== X-Received: by 2002:a17:90b:e01:: with SMTP id ge1mr19758264pjb.187.1600600960004; Sun, 20 Sep 2020 04:22:40 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:39 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 04/10] contrib/completion: extract common diff/difftool options Date: Sun, 20 Sep 2020 04:22:21 -0700 Message-Id: <1ac84595419d8d1ecd8129395c3261ebca643bc2.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org difftool parses its own options and then passes the remaining options onto diff. As a result, they share common command-line options. Instead of duplicating the list, use a shared $__git_diff_difftool_options list. The completion for diff is missing --relative and the completion for difftool is missing --no-index. Add both of these to the common list. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 9147fba3d5..f68c8e0646 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1691,6 +1691,10 @@ __git_diff_common_options="--stat --numstat --shortstat --summary --textconv --no-textconv " +__git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex + --base --ours --theirs --no-index --relative + $__git_diff_common_options" + _git_diff () { __git_has_doubledash && return @@ -1713,10 +1717,7 @@ _git_diff () return ;; --*) - __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex - --base --ours --theirs --no-index - $__git_diff_common_options - " + __gitcomp "$__git_diff_difftool_options" return ;; esac @@ -1738,11 +1739,7 @@ _git_difftool () return ;; --*) - __gitcomp_builtin difftool "$__git_diff_common_options - --base --cached --ours --theirs - --pickaxe-all --pickaxe-regex - --relative --staged - " + __gitcomp_builtin difftool "$__git_diff_difftool_options" return ;; esac From patchwork Sun Sep 20 11:22:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11787449 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 612F16CA for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 463ED20EDD for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BLn4cunf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726389AbgITLWr (ORCPT ); Sun, 20 Sep 2020 07:22:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726332AbgITLWm (ORCPT ); Sun, 20 Sep 2020 07:22:42 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3BCFC0613D0 for ; Sun, 20 Sep 2020 04:22:41 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id bw23so2862924pjb.2 for ; Sun, 20 Sep 2020 04:22:41 -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=56LkUKwzEcs/uoY40e6JBavUJJKJqxA7uBuZ2S+9glA=; b=BLn4cunftEG1mmQ29hsfkno/9KjXc0XWxjO69apzGZCHPzD2TDf9Fg5k/UlQl7rO46 fOoVCourEWD7/++sfqE5nRi+4hBmfKo2lvVAdSV/dfZQRMyf4HMvnMZUWNUKa5u2PIuH tRTxu81CTrZEYh2FAcFRkZ8ei7sKmN1MaEMO2Gtzr2NZZNDW/hQMJwYjgRVRezWkjKHl GZh3iv28My3gdyCA97zk/hYlVcgMFfCYJmlHCFBNXNRRuKlFy2T6VXi2/2JWqA9VFeNP GC/0yOd8WfppNccKwP+lGvXtTLILNMjb/NZB6RTqxbYn/N+NxMJxbEbzVUlUWUQNHApV r1yQ== 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=56LkUKwzEcs/uoY40e6JBavUJJKJqxA7uBuZ2S+9glA=; b=P6UcbkKGznuWtMrmcRA/EZlUli9YB81uPYHgCjjj6J8WO/t9C2eqBU6Oi5/YaDUe0/ y1LJWFj/ZMB0Fbiavy83virmS+hUZqGNBSqEgCSOihXA0rXe4/S+N9iPni7Sf0GYvnle RwA2Sgq80nOEbfbUVMARl71FWMJ7+k2pG/00SAgpkozkEk56GplZFSRVbBBk8mQe5XFl yTq/DNO+KYBifB5ELwu5k2I5nM2mKzXU7W2W/DbRotPtyJgYta7bxxk9ldBzYYQQ7og+ Qtv20A3Y03TpACNFBoMFPoja6tZv8WJhEA7+x5PSXOlQRGOjv62T+AHIIpgdUZHJTgN4 pt4g== X-Gm-Message-State: AOAM531DDsnOnCqxrTItkbnMlhRZaVMTuyxZxtznoYfUDwC0IbsB4b0y yqfrAwGwdmD44+lfg1iyS/IwPioJ1GY= X-Google-Smtp-Source: ABdhPJz6j5NZBn4Tut7pIMnRjPoNLQxgcfn3sYQvHsryJEPeVhlenDzQNzlMSGj3+xX1lOmOZK7aBw== X-Received: by 2002:a17:902:9f84:b029:d1:cc21:9a49 with SMTP id g4-20020a1709029f84b02900d1cc219a49mr28859453plq.9.1600600961022; Sun, 20 Sep 2020 04:22:41 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:40 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 05/10] diff-lib: accept option flags in run_diff_index() Date: Sun, 20 Sep 2020 04:22:22 -0700 Message-Id: <99d8b51585b0b6831f3feaefb83de8390689b683.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will teach run_diff_index() to accept more options via flag bits. For now, change `cached` into a flag in the `option` bitfield. The behaviour should remain exactly the same. Signed-off-by: Denton Liu --- builtin/diff-index.c | 8 ++++---- builtin/diff.c | 8 ++++---- diff-lib.c | 3 ++- diff.h | 4 +++- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/builtin/diff-index.c b/builtin/diff-index.c index 93ec642423..c3878f7ad6 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -15,7 +15,7 @@ COMMON_DIFF_OPTIONS_HELP; int cmd_diff_index(int argc, const char **argv, const char *prefix) { struct rev_info rev; - int cached = 0; + unsigned int option = 0; int i; int result; @@ -32,7 +32,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; if (!strcmp(arg, "--cached")) - cached = 1; + option |= DIFF_INDEX_CACHED; else usage(diff_cache_usage); } @@ -46,7 +46,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) if (rev.pending.nr != 1 || rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) usage(diff_cache_usage); - if (!cached) { + if (!(option & DIFF_INDEX_CACHED)) { setup_work_tree(); if (read_cache_preload(&rev.diffopt.pathspec) < 0) { perror("read_cache_preload"); @@ -56,7 +56,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) perror("read_cache"); return -1; } - result = run_diff_index(&rev, cached); + result = run_diff_index(&rev, option); UNLEAK(rev); return diff_result_code(&rev.diffopt, result); } diff --git a/builtin/diff.c b/builtin/diff.c index cb98811c21..e45e19e37e 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -134,11 +134,11 @@ static int builtin_diff_blobs(struct rev_info *revs, static int builtin_diff_index(struct rev_info *revs, int argc, const char **argv) { - int cached = 0; + unsigned int option = 0; while (1 < argc) { const char *arg = argv[1]; if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged")) - cached = 1; + option |= DIFF_INDEX_CACHED; else usage(builtin_diff_usage); argv++; argc--; @@ -151,7 +151,7 @@ static int builtin_diff_index(struct rev_info *revs, revs->max_count != -1 || revs->min_age != -1 || revs->max_age != -1) usage(builtin_diff_usage); - if (!cached) { + if (!(option & DIFF_INDEX_CACHED)) { setup_work_tree(); if (read_cache_preload(&revs->diffopt.pathspec) < 0) { perror("read_cache_preload"); @@ -161,7 +161,7 @@ static int builtin_diff_index(struct rev_info *revs, perror("read_cache"); return -1; } - return run_diff_index(revs, cached); + return run_diff_index(revs, option); } static int builtin_diff_tree(struct rev_info *revs, diff --git a/diff-lib.c b/diff-lib.c index 50521e2093..d5b2c8af56 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -518,9 +518,10 @@ static int diff_cache(struct rev_info *revs, return unpack_trees(1, &t, &opts); } -int run_diff_index(struct rev_info *revs, int cached) +int run_diff_index(struct rev_info *revs, unsigned int option) { struct object_array_entry *ent; + int cached = !!(option & DIFF_INDEX_CACHED); if (revs->pending.nr != 1) BUG("run_diff_index must be passed exactly one tree"); diff --git a/diff.h b/diff.h index e0c0af6286..aea0d5b96b 100644 --- a/diff.h +++ b/diff.h @@ -585,7 +585,9 @@ const char *diff_aligned_abbrev(const struct object_id *sha1, int); /* report racily-clean paths as modified */ #define DIFF_RACY_IS_MODIFIED 02 int run_diff_files(struct rev_info *revs, unsigned int option); -int run_diff_index(struct rev_info *revs, int cached); + +#define DIFF_INDEX_CACHED 01 +int run_diff_index(struct rev_info *revs, unsigned int option); int do_diff_cache(const struct object_id *, struct diff_options *); int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int); From patchwork Sun Sep 20 11:22:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11787447 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 38A8B6CB for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B53420EDD for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uILxKJDL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726384AbgITLWq (ORCPT ); Sun, 20 Sep 2020 07:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbgITLWm (ORCPT ); Sun, 20 Sep 2020 07:22:42 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B96C0613D1 for ; Sun, 20 Sep 2020 04:22:42 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id u3so5465225pjr.3 for ; Sun, 20 Sep 2020 04:22:42 -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=HHx/hH4zc/dFFPU7CSqaDXlSFiLE7zmrnQkbrFu3PEM=; b=uILxKJDLc9e5xUcLLDIi3kRQYguCbY4owRDKOHAUMsVu9be8VAvPxxJKXMQzO9q5LR v68lFPdq43H6/fVoQzswIKfiJ7Hk8x6z6XfDl+uEtjXLyPPyelvzVVdZ5Xkykk8uOdWt RtUEDkGD/xG+xeA2TOtByujQI1kpfTesgXzHe0Fyrpza77v+KoYkwyc3kgu7f0R/mIvm N1f1OUt2BUkEy/DzZ2TnLSHZlFuYsIcuVqGVJuElcJHrLAAeMoRsw4vDGdJh/wJM0VLh 26s2BuzqFWS8ixYc84cxVhQ4mCA5KDz2vpv7vX++4Bwro3K8VNkH+y3rnVMhfBLXNnP3 lwFg== 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=HHx/hH4zc/dFFPU7CSqaDXlSFiLE7zmrnQkbrFu3PEM=; b=qG1O3XODUs00N4KVivlALsnZ21YqzMe30y+eAIiUpYbK9ZpzI6QOmsbxZBcwMT+gcX T08D2tdbX9e32TKRl+uCv4nU8Fne5bDNM/ucjXNX4DuFstx8Sz6VO/lp4T0MKgiIT0Ei 7HnYVurBSTMy65S4xwMkZIO8u6o3OHR8UybqMcMFy+QSQ+Z1xrSD75AeD0imBCNpZHMb M17O8OiDZAPfXUYueJcjxgp14AWOV+kWW5RrNXZ1pGa/wKTQDKAegnJwbIouIWqVIjyr T9FyOeMtSyfvJokwDzYC2Me/pKmgeRgQMFLGo4OBWG7LbJKZyXFRthhaBsCq7KmmnIN4 p3kQ== X-Gm-Message-State: AOAM532MAkDFH/uqyoak0LjpUkb71HXeW5dWYS9MYB4+hw+hB5fn985J qD5uTACt8G5ePmGyYXaSkzgSVvhOkvs= X-Google-Smtp-Source: ABdhPJy5F2S28oF71j0p482RSlIUEXEWCOcgBYolbB+1O6vJp/PXb3GQ2KAkiqU00DP1PqB1lgmC4w== X-Received: by 2002:a17:90b:4ac2:: with SMTP id mh2mr19137875pjb.210.1600600962129; Sun, 20 Sep 2020 04:22:42 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:41 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 06/10] diff-lib: define diff_get_merge_base() Date: Sun, 20 Sep 2020 04:22:23 -0700 Message-Id: <3287e649f15fe8ca2dca924a29f36132bbce96f8.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a future commit, we will be using this function to implement --merge-base functionality in various diff commands. Signed-off-by: Denton Liu --- diff-lib.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ diff.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index d5b2c8af56..fa64e64bbe 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -13,6 +13,7 @@ #include "submodule.h" #include "dir.h" #include "fsmonitor.h" +#include "commit-reach.h" /* * diff-files @@ -518,6 +519,50 @@ static int diff_cache(struct rev_info *revs, return unpack_trees(1, &t, &opts); } +void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb) +{ + int i; + struct commit *mb_child[2] = {0}; + struct commit_list *merge_bases; + + for (i = 0; i < revs->pending.nr; i++) { + struct object *obj = revs->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 (revs->pending.nr < 1 || revs->pending.nr > 2) + BUG("unexpected revs->pending.nr: %d", revs->pending.nr); + + for (i = 0; i < revs->pending.nr; i++) + mb_child[i] = lookup_commit_reference(the_repository, &revs->pending.objects[i].item->oid); + if (revs->pending.nr == 1) { + struct object_id oid; + + 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")); + + oidcpy(mb, &merge_bases->item->object.oid); + + free_commit_list(merge_bases); +} + int run_diff_index(struct rev_info *revs, unsigned int option) { struct object_array_entry *ent; diff --git a/diff.h b/diff.h index aea0d5b96b..fedfeab7a2 100644 --- a/diff.h +++ b/diff.h @@ -580,6 +580,8 @@ void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc); */ const char *diff_aligned_abbrev(const struct object_id *sha1, int); +void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb); + /* do not report anything on removed paths */ #define DIFF_SILENT_ON_REMOVED 01 /* report racily-clean paths as modified */ From patchwork Sun Sep 20 11:22:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11787453 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 AA77B139F for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90BB921BE5 for ; Sun, 20 Sep 2020 11:22:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EFqdL812" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726412AbgITLWs (ORCPT ); Sun, 20 Sep 2020 07:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726343AbgITLWq (ORCPT ); Sun, 20 Sep 2020 07:22:46 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D936BC0613D2 for ; Sun, 20 Sep 2020 04:22:43 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id d19so5439254pld.0 for ; Sun, 20 Sep 2020 04:22:43 -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=r5/Lz8XIOvfy4nO8p73fNkjlfMEhksE3Txea4yEMOls=; b=EFqdL8127I++8VB3GG3VPo3ZAMxp0R3O+xLo8VeT40+uN5HXvOQZcVRzlCcSvLUi7G Qr+DFaN+t4YXkBsjeGjEtPAWeX23BjKjwRDzknrNabMs6Xrf0efG9mW5K1CCLrkvPSB/ EbFJVWQT/dXvFtB8Ho4WY+Ljpxaub4ePZGNoI51ioYd+HybN66Bb08DS4asIfIrnCotY knnL0FhDrmo5ipJ9gm6m1pYMteCnw7HGcqWWMcm1K4sXuC4pvAKEGaOVki/AgUYM0EtG D8/QQX9b4cDWGLZ30ilGiW9vm6dGU6CbSiFCU4YmLW6rl2iA16bKHrtdEi0GccoTcST2 WHIw== 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=r5/Lz8XIOvfy4nO8p73fNkjlfMEhksE3Txea4yEMOls=; b=FNyuEereLXEA11mqt4Q9l7Px9XBzVmAI0cGxX3xP75NWWLuLR0leXIGdkZAtpEIcMI skOz4XrX8aXK7+5CegexZW7NYxxGT8PucMaoQFmhlbPMTGPZ6rY4WGO2GUvUN2TzWvFF iXzD/cdU/AqlL4STW9cPmt4HZda0mt8DHca91sWxrWibRZe5IVSJvI6ckMX4ZUKMp+Hj 2FcbXl8Z8cXoOSBq3noAhgHYM6quYuxqf1aJ7jRAi2BGSGGW1VeJva/mHPrllrLIATQK J0GWPVx6R8/DiSKI/QQgpKnjnhfKmpX5R7IC3hikTyEvhievTDxPEr1rk1QwpkJuS2y9 JlsA== X-Gm-Message-State: AOAM533hkGR3aM2hVPqPaPom9Dqo3uPZHRC8//u6W6xM8LCHMM6Dgzlj 99J72ZMOgQflUZXyWt8/7KhlpP5Rv6A= X-Google-Smtp-Source: ABdhPJynhtEXbHNyxq6LOMCuWQFR1qEnGr0K/TVb+AXdwEO7E/P/w1Z/z4a4CO+HmftD8n4RekCkZg== X-Received: by 2002:a17:90b:1988:: with SMTP id mv8mr21142773pjb.23.1600600963225; Sun, 20 Sep 2020 04:22:43 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:42 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 07/10] t4068: add --merge-base tests Date: Sun, 20 Sep 2020 04:22:24 -0700 Message-Id: <27930d44769503103533c8c38212d7eaa2856a8e.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the future, we will be adding more --merge-base tests to this test script. To prepare for that, rename the script accordingly and update its description. Also, add two basic --merge-base tests that don't require any functionality to be implemented yet. Signed-off-by: Denton Liu --- ...ymmetric.sh => t4068-diff-symmetric-merge-base.sh} | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) rename t/{t4068-diff-symmetric.sh => t4068-diff-symmetric-merge-base.sh} (86%) diff --git a/t/t4068-diff-symmetric.sh b/t/t4068-diff-symmetric-merge-base.sh similarity index 86% rename from t/t4068-diff-symmetric.sh rename to t/t4068-diff-symmetric-merge-base.sh index 60c506c2b2..bd4cf254d9 100755 --- a/t/t4068-diff-symmetric.sh +++ b/t/t4068-diff-symmetric-merge-base.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='behavior of diff with symmetric-diff setups' +test_description='behavior of diff with symmetric-diff setups and --merge-base' . ./test-lib.sh @@ -88,4 +88,13 @@ test_expect_success 'diff with ranges and extra arg' ' test_i18ngrep "usage" err ' +test_expect_success 'diff --merge-base with no commits' ' + test_must_fail git diff --merge-base +' + +test_expect_success 'diff --merge-base with three commits' ' + test_must_fail git diff --merge-base br1 br2 master 2>err && + test_i18ngrep "usage" err +' + test_done From patchwork Sun Sep 20 11:22:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11787457 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 99B396CB for ; Sun, 20 Sep 2020 11:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B29420EDD for ; Sun, 20 Sep 2020 11:22:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OXcd/xW8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726415AbgITLWt (ORCPT ); Sun, 20 Sep 2020 07:22:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726338AbgITLWq (ORCPT ); Sun, 20 Sep 2020 07:22:46 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 463CEC0613D3 for ; Sun, 20 Sep 2020 04:22:45 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id mm21so5697332pjb.4 for ; Sun, 20 Sep 2020 04:22:45 -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=I2qSGXT9rPfIcl/5fhUk+xVgkaraVpv7E8dIYLbpOqk=; b=OXcd/xW8gFQVNdpLbNBYj+YiUWAjxw/w7kxJsxJawW8YAbeELKIFDJd1nnKtzsbjkU 7KeHsRVjxrMNjjOZU9Lanx3XUW+x96hYhmhydBzC5HIsOGzW/IQFLXQLy3l2/k7GqRsm uSWeHHwtly+nZ2PehfjgrzeXBBAJ2t6ytd1FYerssbjuc0a9K6/Gkraa+NwWUw1GVqQ8 qUCk4x83kdiTEuElJF/bn/UCTalWP1MXJLKb9uDnXNr5PyZPXFRqrj/FPqaGKdnbrx9P N3hakJA8duIM26G4FRJOZ1OLPPfWGG+PUvL4S11Xg3vV7AzTpMqzHuTzTbLvMY6Z4qWS iJFw== 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=I2qSGXT9rPfIcl/5fhUk+xVgkaraVpv7E8dIYLbpOqk=; b=nWEJYYsz/1P91e+G721+5AoCjK6ni1Ect4kb4CEpWUyldkXle/uZt3MgQOKo1pOVbf eJ9pZx+JKMzW99/pYNmHfi23xthRWNQaSqwMurmogpQ4BiSeebcDruV2xT7LNAKGPHZ1 eJJzJq0rSbEJ/uCoJMjrWHJGbZXe7NSkl57CqxhOendBN5yKWZp+r/zZFrdAGhwAMO/p 2uWVWYAmJ59gdfVWkyRQgIyqZJORKKt4FlAWuiwUncr8oW2MIaOKN3PX9lgcSvEs/c+A 75IgeRJ+o/XmGSTgiKSuyNGKsobgxsQQqgPc1goixQ1AQl9mCEDyAquykV15XBOEElLg I62w== X-Gm-Message-State: AOAM530GhjeJX5Bvd+YaxNVgeJBo8i2wbo3X09/UZfdFwjgHmcJDoBC8 TNfUOw/AthphT43pX9HDtSyXrI55xAs= X-Google-Smtp-Source: ABdhPJztIgB11hQW3O/1NAkown6GyFIP0ifO9hrn+cZJX7hUVwwGkIU3WAbNoAUsqUCd80G5kk5IfA== X-Received: by 2002:a17:90a:65c5:: with SMTP id i5mr18388219pjs.112.1600600964423; Sun, 20 Sep 2020 04:22:44 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:43 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 08/10] builtin/diff-index: learn --merge-base Date: Sun, 20 Sep 2020 04:22:25 -0700 Message-Id: X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There is currently no easy way to take the diff between the working tree or index and the merge base between an arbitrary commit and HEAD. Even diff's `...` notation doesn't allow this because it only works between commits. However, the ability to do this would be desirable to a user who would like to see all the changes they've made on a branch plus uncommitted changes without taking into account changes made in the upstream branch. Teach diff-index and diff (with one commit) the --merge-base option which allows a user to use the merge base of a commit and HEAD as the "before" side. Signed-off-by: Denton Liu --- Documentation/git-diff-index.txt | 7 +++- Documentation/git-diff.txt | 12 ++++-- builtin/diff-index.c | 2 + builtin/diff.c | 2 + diff-lib.c | 15 ++++++- diff.h | 1 + t/t4068-diff-symmetric-merge-base.sh | 59 ++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 6 deletions(-) diff --git a/Documentation/git-diff-index.txt b/Documentation/git-diff-index.txt index 25fe165f00..27acb31cbf 100644 --- a/Documentation/git-diff-index.txt +++ b/Documentation/git-diff-index.txt @@ -9,7 +9,7 @@ git-diff-index - Compare a tree to the working tree or index SYNOPSIS -------- [verse] -'git diff-index' [-m] [--cached] [] [...] +'git diff-index' [-m] [--cached] [--merge-base] [] [...] DESCRIPTION ----------- @@ -29,6 +29,11 @@ include::diff-options.txt[] --cached:: Do not consider the on-disk file at all. +--merge-base:: + Instead of comparing directly, use the merge base + between and HEAD instead. must be a + commit. + -m:: By default, files recorded in the index but not checked out are reported as deleted. This flag makes diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 8f7b4ed3ca..762ee6d074 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git diff' [] [] [--] [...] -'git diff' [] --cached [] [--] [...] +'git diff' [] --cached [--merge-base] [] [--] [...] 'git diff' [] [...] [--] [...] 'git diff' [] ... [--] [...] 'git diff' [] @@ -40,7 +40,7 @@ files on disk. or when running the command outside a working tree controlled by Git. This form implies `--exit-code`. -'git diff' [] --cached [] [--] [...]:: +'git diff' [] --cached [--merge-base] [] [--] [...]:: This form is to view the changes you staged for the next commit relative to the named . Typically you @@ -49,6 +49,10 @@ files on disk. If HEAD does not exist (e.g. unborn branches) and is not given, it shows all staged changes. --staged is a synonym of --cached. ++ +If --merge-base is given, instead of using , use the merge base +of and HEAD. `git diff --merge-base A` is equivalent to +`git diff $(git merge-base A HEAD)`. 'git diff' [] [--] [...]:: @@ -89,8 +93,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 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]. diff --git a/builtin/diff-index.c b/builtin/diff-index.c index c3878f7ad6..7f5281c461 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -33,6 +33,8 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) if (!strcmp(arg, "--cached")) option |= DIFF_INDEX_CACHED; + else if (!strcmp(arg, "--merge-base")) + option |= DIFF_INDEX_MERGE_BASE; else usage(diff_cache_usage); } diff --git a/builtin/diff.c b/builtin/diff.c index e45e19e37e..1baea18ae0 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -139,6 +139,8 @@ static int builtin_diff_index(struct rev_info *revs, const char *arg = argv[1]; if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged")) option |= DIFF_INDEX_CACHED; + else if (!strcmp(arg, "--merge-base")) + option |= DIFF_INDEX_MERGE_BASE; else usage(builtin_diff_usage); argv++; argc--; diff --git a/diff-lib.c b/diff-lib.c index fa64e64bbe..79defdc6b8 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -567,13 +567,26 @@ int run_diff_index(struct rev_info *revs, unsigned int option) { struct object_array_entry *ent; int cached = !!(option & DIFF_INDEX_CACHED); + int merge_base = !!(option & DIFF_INDEX_MERGE_BASE); + struct object_id oid; + const char *name; + char merge_base_hex[GIT_MAX_HEXSZ + 1]; if (revs->pending.nr != 1) BUG("run_diff_index must be passed exactly one tree"); trace_performance_enter(); ent = revs->pending.objects; - if (diff_cache(revs, &ent->item->oid, ent->name, cached)) + + if (merge_base) { + diff_get_merge_base(revs, &oid); + name = oid_to_hex_r(merge_base_hex, &oid); + } else { + oidcpy(&oid, &ent->item->oid); + name = ent->name; + } + + if (diff_cache(revs, &oid, name, cached)) exit(128); diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/"); diff --git a/diff.h b/diff.h index fedfeab7a2..6c2efa16fd 100644 --- a/diff.h +++ b/diff.h @@ -589,6 +589,7 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb); int run_diff_files(struct rev_info *revs, unsigned int option); #define DIFF_INDEX_CACHED 01 +#define DIFF_INDEX_MERGE_BASE 02 int run_diff_index(struct rev_info *revs, unsigned int option); int do_diff_cache(const struct object_id *, struct diff_options *); diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh index bd4cf254d9..49432379cb 100755 --- a/t/t4068-diff-symmetric-merge-base.sh +++ b/t/t4068-diff-symmetric-merge-base.sh @@ -97,4 +97,63 @@ test_expect_success 'diff --merge-base with three commits' ' test_i18ngrep "usage" err ' +for cmd in diff-index diff +do + test_expect_success "$cmd --merge-base with one commit" ' + git checkout master && + git $cmd commit-C >expect && + git $cmd --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base with one commit and unstaged changes" ' + git checkout master && + test_when_finished git reset --hard && + echo unstaged >>c && + git $cmd commit-C >expect && + git $cmd --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --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 $cmd commit-C >expect && + git $cmd --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --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 $cmd --cached commit-C >expect && + git $cmd --cached --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base with non-commit" ' + git checkout master && + test_must_fail git $cmd --merge-base master^{tree} 2>err && + test_i18ngrep "fatal: --merge-base only works with commits" err + ' + + test_expect_success "$cmd --merge-base with no merge bases and one commit" ' + git checkout master && + test_must_fail git $cmd --merge-base br3 2>err && + test_i18ngrep "fatal: no merge base found" err + ' + + test_expect_success "$cmd --merge-base with multiple merge bases and one commit" ' + git checkout master && + test_must_fail git $cmd --merge-base br1 2>err && + test_i18ngrep "fatal: multiple merge bases found" err + ' +done + test_done From patchwork Sun Sep 20 11:22:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11787459 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 9EC766CB for ; Sun, 20 Sep 2020 11:22:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 74BF521D43 for ; Sun, 20 Sep 2020 11:22:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BDI9b406" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbgITLWx (ORCPT ); Sun, 20 Sep 2020 07:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726311AbgITLWq (ORCPT ); Sun, 20 Sep 2020 07:22:46 -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 5EBEFC061755 for ; Sun, 20 Sep 2020 04:22:46 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id s14so5766504pju.1 for ; Sun, 20 Sep 2020 04:22:46 -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=5ZYmuow/rpB+xylB4OIHhJ8ndIQZ0NEnmaGcdJruz4g=; b=BDI9b406Oqi9vGoAAjQNSPLhiYPsjRGzgFN8/QDdP9WvZKOf1LyuYEwcAHQMjnhguy BKYi4sjy1l2u/FUNPf87h68Mk77T/sG1ZDQTXsSVsr/SJ7t5wqGW7CuOrbsPrdLxdGHH 1jzQIgLE/E6zqRuNp9/pTlTth2hiXpzf/rVm6VIX7U1rvWMzeQMGCZHzAj5agvHo1zSg Rn1tXdxQfooQIgQLflf7KK52Cii9qvVyC731Xh+P55OSXRBLxKdgnu9abXKGqPQf0Q2r 1Z4U9XYSAE5P+8HL3urvMPFCPVLUkx3yXofIMdKElQRVcn52CCKBLlru5lA698sQLM31 QqmA== 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=5ZYmuow/rpB+xylB4OIHhJ8ndIQZ0NEnmaGcdJruz4g=; b=BPzUvNiBd8C0tC0IGgaVzAZrsdGUlNteiFNCwiMEGWtJDYlg4cwSSfxSQHOOsbZB7s 77KJ/HqtOPLtxZyWx6Vk+V7UvQudIIJuJ+L9H2Yg545YtZunIgZXr5x5yzxJCEkC0Ckb WAcf4DMTuwrwm2fZZHGTlGjd1+/IWccsVd/Z2e4hzmcDiYSxJYGq/sOMoWHoVHqieTmr BuDI+V5P+oBey4bbRhl0tS5Xtqx+0+jJp014WyhqcSP+Xv4TAvxgc2HIrqhyMtpYQRFN FBrtDb5tJ8HcibJ8XiI23g3rZHoCrdyFqW9AEh3rfLD7VIVaYArKUlL6soWO2dEIMZ+7 LDGg== X-Gm-Message-State: AOAM532RbyfsA5Amf/SWKofGS46UM320/Sd4ER10jzxcMEL+XG74Dm9O S6jvtXYYxrOwXjliF0xykWi7bvYzr1c= X-Google-Smtp-Source: ABdhPJxiWsSz48/mxr3NDWToeHJYDvE8R/pmY05of7W/WNRrKZqeNvPHytfW35Hpw9kWH2JO+a3zbg== X-Received: by 2002:a17:90a:481:: with SMTP id g1mr20207084pjg.157.1600600965596; Sun, 20 Sep 2020 04:22:45 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:44 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 09/10] builtin/diff-tree: learn --merge-base Date: Sun, 20 Sep 2020 04:22:26 -0700 Message-Id: <4880d21119c8b67ab53db8ce82196855f6e8680f.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The previous commit introduced ---merge-base a way to take the diff between the working tree or index and the merge base between an arbitrary commit and HEAD. It makes sense to extend this option to support the case where two commits are given too and behave in a manner identical to `git diff A...B`. Introduce the --merge-base flag as an alternative to triple-dot notation. Thus, we would be able to write the above as `git diff --merge-base A B`. Signed-off-by: Denton Liu --- Documentation/git-diff-tree.txt | 7 ++++- Documentation/git-diff.txt | 8 ++++-- builtin/diff-tree.c | 18 +++++++++++++ builtin/diff.c | 39 +++++++++++++++++++--------- t/t4068-diff-symmetric-merge-base.sh | 34 ++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 15 deletions(-) diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt index 5c8a2a5e97..2fc24c542f 100644 --- a/Documentation/git-diff-tree.txt +++ b/Documentation/git-diff-tree.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git diff-tree' [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty] - [-t] [-r] [-c | --cc] [--combined-all-paths] [--root] + [-t] [-r] [-c | --cc] [--combined-all-paths] [--root] [--merge-base] [] [] [...] DESCRIPTION @@ -43,6 +43,11 @@ include::diff-options.txt[] When `--root` is specified the initial commit will be shown as a big creation event. This is equivalent to a diff against the NULL tree. +--merge-base:: + Instead of comparing the s directly, use the merge + base between the two s as the "before" side. There + must be two s given and they must both be commits. + --stdin:: When `--stdin` is specified, the command does not take arguments from the command line. Instead, it diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 762ee6d074..7f4c8a8ce7 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -11,7 +11,7 @@ SYNOPSIS [verse] 'git diff' [] [] [--] [...] 'git diff' [] --cached [--merge-base] [] [--] [...] -'git diff' [] [...] [--] [...] +'git diff' [] [--merge-base] [...] [--] [...] 'git diff' [] ... [--] [...] 'git diff' [] 'git diff' [] --no-index [--] @@ -62,10 +62,14 @@ of and HEAD. `git diff --merge-base A` is equivalent to branch name to compare with the tip of a different branch. -'git diff' [] [--] [...]:: +'git diff' [] [--merge-base] [--] [...]:: This is to view the changes between two arbitrary . ++ +If --merge-base is given, use the merge base of the two commits for the +"before" side. `git diff --merge-base A B` is equivalent to +`git diff $(git merge-base A B) B`. 'git diff' [] ... [--] [...]:: diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 802363d0a2..823d6678e5 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -111,6 +111,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) struct setup_revision_opt s_r_opt; struct userformat_want w; int read_stdin = 0; + int merge_base = 0; if (argc == 2 && !strcmp(argv[1], "-h")) usage(diff_tree_usage); @@ -143,9 +144,26 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) read_stdin = 1; continue; } + if (!strcmp(arg, "--merge-base")) { + merge_base = 1; + continue; + } usage(diff_tree_usage); } + if (read_stdin && merge_base) + die(_("--stdin and --merge-base are mutually exclusive")); + + if (merge_base) { + struct object_id oid; + + if (opt->pending.nr != 2) + die(_("--merge-base only works with two commits")); + + diff_get_merge_base(opt, &oid); + opt->pending.objects[0].item = lookup_object(the_repository, &oid); + } + /* * NOTE! We expect "a..b" to expand to "^a b" but it is * perfectly valid for revision range parser to yield "b ^a", diff --git a/builtin/diff.c b/builtin/diff.c index 1baea18ae0..b50fc68c2a 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -26,7 +26,7 @@ static const char builtin_diff_usage[] = "git diff [] [] [--] [...]\n" " or: git diff [] --cached [] [--] [...]\n" -" or: git diff [] [...] [--] [...]\n" +" or: git diff [] [--merge-base] [...] [--] [...]\n" " or: git diff [] ...] [--] [...]\n" " or: git diff [] ]\n" " or: git diff [] --no-index [--] ]\n" @@ -172,19 +172,34 @@ static int builtin_diff_tree(struct rev_info *revs, struct object_array_entry *ent1) { const struct object_id *(oid[2]); - int swap = 0; + struct object_id mb_oid; + int merge_base = 0; - if (argc > 1) - usage(builtin_diff_usage); + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--merge-base")) + merge_base = 1; + else + usage(builtin_diff_usage); + argv++; argc--; + } - /* - * We saw two trees, ent0 and ent1. If ent1 is uninteresting, - * swap them. - */ - if (ent1->item->flags & UNINTERESTING) - swap = 1; - oid[swap] = &ent0->item->oid; - oid[1 - swap] = &ent1->item->oid; + if (merge_base) { + diff_get_merge_base(revs, &mb_oid); + oid[0] = &mb_oid; + oid[1] = &revs->pending.objects[1].item->oid; + } else { + int swap = 0; + + /* + * We saw two trees, ent0 and ent1. If ent1 is uninteresting, + * swap them. + */ + if (ent1->item->flags & UNINTERESTING) + swap = 1; + oid[swap] = &ent0->item->oid; + oid[1 - swap] = &ent1->item->oid; + } diff_tree_oid(oid[0], oid[1], "", &revs->diffopt); log_tree_diff_flush(revs); return 0; diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh index 49432379cb..03487cc945 100755 --- a/t/t4068-diff-symmetric-merge-base.sh +++ b/t/t4068-diff-symmetric-merge-base.sh @@ -156,4 +156,38 @@ do ' done +for cmd in diff-tree diff +do + test_expect_success "$cmd --merge-base with two commits" ' + git $cmd commit-C master >expect && + git $cmd --merge-base br2 master >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base commit and non-commit" ' + test_must_fail git $cmd --merge-base br2 master^{tree} 2>err && + test_i18ngrep "fatal: --merge-base only works with commits" err + ' + + test_expect_success "$cmd --merge-base with no merge bases and two commits" ' + test_must_fail git $cmd --merge-base br2 br3 2>err && + test_i18ngrep "fatal: no merge base found" err + ' + + test_expect_success "$cmd --merge-base with multiple merge bases and two commits" ' + test_must_fail git $cmd --merge-base master br1 2>err && + test_i18ngrep "fatal: multiple merge bases found" err + ' +done + +test_expect_success 'diff-tree --merge-base with one commit' ' + test_must_fail git diff-tree --merge-base master 2>err && + test_i18ngrep "fatal: --merge-base only works with two commits" 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_done From patchwork Sun Sep 20 11:22:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11787461 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 829856CB for ; Sun, 20 Sep 2020 11:22:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67CD721BE5 for ; Sun, 20 Sep 2020 11:22:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s/jX6ddx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726452AbgITLW4 (ORCPT ); Sun, 20 Sep 2020 07:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726390AbgITLWr (ORCPT ); Sun, 20 Sep 2020 07:22:47 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56ADCC061755 for ; Sun, 20 Sep 2020 04:22:47 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id x123so6521866pfc.7 for ; Sun, 20 Sep 2020 04:22:47 -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=6NWmJWmix5MbfEOPcIXCAA1zWSU0Fqu0LzA2WS4PetQ=; b=s/jX6ddxJaTTaN1N/HjU/zfKuNj+lkjoNcYpBXDMjI+E1dWV2MpqHILlqIdJslPFXU bSc2TQsW56KGgg3BHcvxvGes+u8xBh9pgat1Ut7NZEUSlCIm1I+58uC+b3zI21Juq2xn 1YUvYj4etS/4EwU1qHuoMicQpgMbt6SDkN5U7lTEsf7uWafpIy8WQ45YbOSo9c5hWWFi 7of8MFcfWQQcvkuMc8V7N7qxTLfTW4TsuOwItbffGGbkwjuqY69ZlLU5EeL2zrNscavi bSLkKDTHN+o1pYs5bhtn+d3BBKyLOt36fRSaYE6NoAGjmDIc7nNR4ND9kBZDmJWRczdA EoYQ== 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=6NWmJWmix5MbfEOPcIXCAA1zWSU0Fqu0LzA2WS4PetQ=; b=ZUNPty2eh7YhklP8FuRvRfjUp9vYe0FHI9kUS/+5vw5ZsjoS0extv7FVIjWyKNRWhf GQo9bx0NldCgUwu1/SytNW0Ox0oV/RM2zIA3eGfGj+kg3L6kBCc13bpuIxw4mqHTeend UWVMLuQhJotxyDXo4cLMBtisWAcwMEM6FTa7YW3D2D2pEipycK4MmtjanItmNRhOwMuS 1qNW8bc/NqV3Ew6Vz0YcHS0g4lQ+QfdWGKsy1q7tV8jLoD9y7inEY3q1DOn4pIGPFQEy cBH3vH3lOfGpZGf8496mgN1e970QjqlfQO9xZar+fbG6gmr0e5NqDOoa6BfnrGeXF3ld OXQg== X-Gm-Message-State: AOAM532rbl9y5F51fD/c8XKPOKYDtLfdcyRoBG6Q0MtZeBFy5GvRXAjM s7PUoCg5AjxHRVJb6x0W5hJK+qcMy00= X-Google-Smtp-Source: ABdhPJwTvO6jT2kX90yjVUxZ11xJLHLoOAUFhDHTIDiAp9ubpio/02/zjaZAD6ZU+5cBZm4qj/oeTQ== X-Received: by 2002:a63:d04b:: with SMTP id s11mr32937353pgi.241.1600600966656; Sun, 20 Sep 2020 04:22:46 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id y79sm9550737pfb.45.2020.09.20.04.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 04:22:45 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano , Jeff King Subject: [PATCH v4 10/10] contrib/completion: complete `git diff --merge-base` Date: Sun, 20 Sep 2020 04:22:27 -0700 Message-Id: <32e3e52b5f4dbbb3050fe9fcff1a3c1f1d2df123.1600600823.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.760.g8d73e04208 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index f68c8e0646..679d1ec8a8 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1692,7 +1692,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary " __git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex - --base --ours --theirs --no-index --relative + --base --ours --theirs --no-index --relative --merge-base $__git_diff_common_options" _git_diff ()