From patchwork Thu Sep 17 07:44:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781807 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 780CF92C for ; Thu, 17 Sep 2020 07:44:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B21C208DB for ; Thu, 17 Sep 2020 07:44:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bLtHKb2N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726192AbgIQHos (ORCPT ); Thu, 17 Sep 2020 03:44:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726216AbgIQHof (ORCPT ); Thu, 17 Sep 2020 03:44:35 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5DE0C061756 for ; Thu, 17 Sep 2020 00:44:34 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id j34so867229pgi.7 for ; Thu, 17 Sep 2020 00:44:34 -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=y6rcRpyp6oEtNjMcJ5TzPBWNEijRXeIaMMkmND3iSGo=; b=bLtHKb2Niu0a7aw7gfJ+enRFJrNw/MBTJK0Rc4hHFsP4S3bApd6sRuleBPL2kxxVmL mw9D3gCB2T01HNf0e97iMQz0VW+68oyowwV/p4GBAGZLngYnwVf5+Eb/KVB1EvxQC8bq m1vB5zXZUKtCZfBS+Ef139labiqWrJWwoZ6VWrHlPLqI5UggjUqgN/4WC0BOy/Cdv7Pc a7WlqzHGtWgmegFWTPANR8zhcuckVUXhjx3sl2+lVg4Wa2wry7n3Hwi5Hq4iouZ2+9rj 6cG2uq6odLy/OHG7A6SsLJKBERzJ40JcscJrgxq3kav3oE+5DRFrqNPxKzIBOQgkSPJl v/Sw== 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=y6rcRpyp6oEtNjMcJ5TzPBWNEijRXeIaMMkmND3iSGo=; b=hKdeWj4NUClFs9KZJalNMNLID4Q0yc1M340Uj/f6iAYUDta6QaCRp9UPpPMjQx8LXL cHOK3npgv/RS3s6HRDnYpyQ2GB6whpL/vhTjURu7L6li6zSqsDUvqJqNPMJeCSS451zO qgckCaw96l+BI6mbfuQ8QwC/cxWDiVvmm2N5TuKdt49NI34EhBJo+9rXNiwrwzx2mK6f S2VNXE5IwpOBn/39jBDVhBY665Yhc8pCZt7STi5UdCcR+JL8NZU0RvS52dCdLV6qIXMQ /mmqCN9scQvKBHd7xHQA3o/VGW066+gc+D+qvdEZ9e1JYAcoHe+4xSFeZHDUoQAzFrPt G+0A== X-Gm-Message-State: AOAM5311W7lzpB7VculRgpHmcM61tXXn0srnb9jqAgK21AnbSPzfhY5u 9k3ymqd2Jz7yLAOzCbR6jlV8c7kn+htiHQ== X-Google-Smtp-Source: ABdhPJxiL6/R3fa7HJ/Uo1wmNBiDqTtXMQTymPp35F3QIJ0VBF25oI0AIvGeSXJsc1/OA2JHRbnO1g== X-Received: by 2002:a63:1455:: with SMTP id 21mr22623373pgu.52.1600328674105; Thu, 17 Sep 2020 00:44:34 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:33 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 01/10] t4068: remove unnecessary >tmp Date: Thu, 17 Sep 2020 00:44:05 -0700 Message-Id: <80e9066a59524ededbb0d0191a93e6e3154c5623.1600328335.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 Thu Sep 17 07:44:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781809 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 8A577139A for ; Thu, 17 Sep 2020 07:45:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 636EB21734 for ; Thu, 17 Sep 2020 07:45:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m7rOVS5a" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726171AbgIQHoy (ORCPT ); Thu, 17 Sep 2020 03:44:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgIQHoh (ORCPT ); Thu, 17 Sep 2020 03:44:37 -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 C79F1C06174A for ; Thu, 17 Sep 2020 00:44:35 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id o20so671287pfp.11 for ; Thu, 17 Sep 2020 00:44:35 -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=/mwx6ZHN/3I6oH1IScrvUQS1SzymAXYB1bi5yg/wxYw=; b=m7rOVS5ajWn/6DfIZFVa3QFJ9MifA//RL5zwwUTtL0ao60FkXf93StpSj7eShbzLOk udlVSglRSNjSmgGZ+SbOPf3wqJ0Pz5wjRDLgX+p6VBT0SS2Ipnn1wy9SBbTw5EShDbUm 64vS9YOAM0l4EbPibu9eGS5x0juPGuv8m/Ytr7aUDYyjMBMKBx+o8k/XvVEmlPTt3mLH A0tYz5Kjc5MR8ew+c30vdvV1JJMatmy2OWA6o0ntl49Hs+ZvNFZohNvDkDTYlIkLX7zN Bu3S7DtcWXoyksjDyenWNaNBtr6tKslSNOJhn7xmdhruZ+FO+WCnhvSXc1ao82B0CBWg eUDg== 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=/mwx6ZHN/3I6oH1IScrvUQS1SzymAXYB1bi5yg/wxYw=; b=ir7nPfB/w3eZX5aCq2kHmN+auIhYJFfNjpQtuJQyIvPsKBPhGIjs9Vdti9lqcEpe3n MM3v03Z9gjCsXf8dURYNTVKZoSg7t4k0AsbLlTeqJPS6hmz/M4oUAkVSb0OzimHEgUxs tsa0ZekklsPdTCWjvQ91jQFLpjLx2FPG9g7PNQPuM6y2QFrPrk0PyB6Et4DSJHzW6ODX Z6asI+FaMlw6LvVLvb+qxfynAi6qgFQnw+wSu0fVo6UEpO7UlstzypevsH92WThkp1Vq PD17kQNGL4nUUXe88v77O8jQzm6nv7ZhYPKWMl4/PXWuk7T6KQZd9q64esUNi4E97oGv ODvg== X-Gm-Message-State: AOAM532H8szXKiWkD+PODbXtUws8ELSSMN8kGqpsP3s0XNYlMI1U7nWy WU5JJo4UGZkO3SOvaLGIyD6oZgqbljqXeA== X-Google-Smtp-Source: ABdhPJyMJUBOqykPov5xnAOdkhsWHwUfaBD1U2fQFfsN2QSHm87bGa33oP697k66noEzpR7c6khgAA== X-Received: by 2002:a05:6a00:1513:b029:142:2501:34de with SMTP id q19-20020a056a001513b0290142250134demr10118233pfu.55.1600328675148; Thu, 17 Sep 2020 00:44:35 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:34 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 02/10] git-diff-index.txt: make --cached description a proper sentence Date: Thu, 17 Sep 2020 00:44:06 -0700 Message-Id: <21b20281e6a1fa265d4853fa04cc71ba7e843267.1600328335.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 Thu Sep 17 07:44:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781823 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 C619414B7 for ; Thu, 17 Sep 2020 07:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA60521734 for ; Thu, 17 Sep 2020 07:45:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i46mmEYQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbgIQHpu (ORCPT ); Thu, 17 Sep 2020 03:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726269AbgIQHoh (ORCPT ); Thu, 17 Sep 2020 03:44:37 -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 27067C061756 for ; Thu, 17 Sep 2020 00:44:37 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id b124so665467pfg.13 for ; Thu, 17 Sep 2020 00:44:37 -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=rupAiabRDgtPF1NJ4d/pjYnNSXyE4EjbhLrxZBEG168=; b=i46mmEYQzgro8bFmTGqznt+zX71qdpYcrGUYorU8BNyyvEdmkKSp3AhdHJIHB26C16 0imQlKz+lWCmVooP6+5XLMAaZJHAzXhqxDjXHhkMz4EZZbSe8Sa4wJpQmZl0MLhfwOXB kLVihL7SWpHZz6B+iJ+FDzH6sFQMZL5jxfp1SI+irZ5GprfRY4JbDT3rmNEYLoDuCMCL f26KobFGaslnNhn/cGLag9bsvm92Yx7Fi0TIXcimYj5eaLhOhoEU5s72ViA91gijjFmU jOuClHs0Z1vk24RJ7usDHiMiS6ub4lhzr+zLV7xWSZnEtu6vI/hmDWUdR+ZBLIRzuqlf CSZA== 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=rupAiabRDgtPF1NJ4d/pjYnNSXyE4EjbhLrxZBEG168=; b=ZqWwnOimw4WFOabIph0V4hKH70jEXcqvHYLeSLa9CqZk2/WFTmN4J2quivZIJajTGC ze6kersz6tnplbAkIU1XMrMUbkPwbFT7haHkgzx8Y4oxGhjQXg3l3XxIK0IKdT2NFLOh HhpDzxqM/CqaCaBZhDVGSp4seaTtptTwipUGRMpq3kwf/yInDJeV4gGSiZfe0qctBrRe UN60GgjobhvTmbKmDSHlL06kjUNZ5MKQGL8O08QUonmjhFZtXyts86NWIHBhl9lB6f1h Arxqg94OxLDTYrC8WvxolZzeQao3PA4W8n/G6JUwWaKnepe+MRmB+uNGwtbQLG3SqtWo YhGA== X-Gm-Message-State: AOAM531zAhRp9NR7oM8os93hIhdRH/V9O0TIAxdGRocqPK+oB3OI54Hi XGA4TVZuQYn3sITGyeBi7LloA8SJHqDFMQ== X-Google-Smtp-Source: ABdhPJyMT67qDgaxS9SCAsGgXytELK7JTAFwnqGNQGJ544yxJ+y5qAMrpz4WnDH3asYebTpdpOeWdw== X-Received: by 2002:a62:380d:0:b029:142:2501:35eb with SMTP id f13-20020a62380d0000b0290142250135ebmr10099370pfa.75.1600328676315; Thu, 17 Sep 2020 00:44:36 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:35 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 03/10] git-diff.txt: backtick quote command text Date: Thu, 17 Sep 2020 00:44:07 -0700 Message-Id: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 Thu Sep 17 07:44:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781819 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 2914C139A for ; Thu, 17 Sep 2020 07:45:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C09D20658 for ; Thu, 17 Sep 2020 07:45:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tg6P5APr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbgIQHph (ORCPT ); Thu, 17 Sep 2020 03:45:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726290AbgIQHol (ORCPT ); Thu, 17 Sep 2020 03:44:41 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF863C061788 for ; Thu, 17 Sep 2020 00:44:37 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id y1so868556pgk.8 for ; Thu, 17 Sep 2020 00:44:37 -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=ZYqdZNkC2obKcgZewbiD+Abk/bCuuK7TokBtxHeU/lo=; b=Tg6P5APrUZ47Bi1VCtEg2nwoWlBAJJ7f6hEU01fxpY1ps1N6lhJ/VpNEAmRI32ko4w H3FHRdf04i2t+6sXdEd5XbeEEUN82aM55fzXEfabdFzcXWQ5aX/NzhD+FR7gRnsi05fi jvvoEdi8uUy1o/V2Dqt/Z3lNGf/9aLvjJcNeJjKwa2nJ0C37dHbHuZIFUtQB/UO1M4bY BKxgLvwOoKuLNuEueR28UZ4hEfGh0IrbIV0CVBrX/6RSY2NZCT/IU573zCldH5V+mouO H5eO0Nz9w1MONI3BjWOVnI1JBvdmEmAb8PfeJn9w4NcWgC2wFeG/M0nysT70eJ1i4zA8 Yh3w== 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=ZYqdZNkC2obKcgZewbiD+Abk/bCuuK7TokBtxHeU/lo=; b=MS/oxFY+W7PgvXvp+4uzEQbOP30aq20r8GpCuk6ikobHHhfoG4VzJvDY+P1CPKcrcd waMrB5amQo2ejQH6o5vhdYS857B17rQrIytH0uBfkiUNoClhw9R9TCzq/17hAthhMdkc Oohryh6CHJznOHGGJLKuKO9qth0xjNvn6PpY8SuWhZW60xuWub+RmzJDQYHsOoF2f+YM WeRaCmu5sohCZSn42EVkFZdq9RubY2KQZ/i5dUOVFFFK2KP2HnBMZhA1SdIsnsnRHZTf 4kZxdmgqAeXmq/mGq5PSQLNA+Xwq8SN8XigoZZtldY+arUMTDtMFnBdkuJZrD2wriRlH CrGw== X-Gm-Message-State: AOAM533EPxsy2Y6U3wHc/m/bvp7mxk29EniLvjgOEb8SW4WR+EXv3+Bn 7foyPLRBorCcGjIe8RvUxLgRV1s9CzEmpQ== X-Google-Smtp-Source: ABdhPJzyCVF78GtclGgxMC5Tn+MoueNa0khajxRTC+BxzJXorFJoAYGdHU6j3zncrGrev8f/KZ9iNQ== X-Received: by 2002:a63:f342:: with SMTP id t2mr21807745pgj.313.1600328677262; Thu, 17 Sep 2020 00:44:37 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:36 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 04/10] contrib/completion: extract common diff/difftool options Date: Thu, 17 Sep 2020 00:44:08 -0700 Message-Id: <1ac84595419d8d1ecd8129395c3261ebca643bc2.1600328335.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 Thu Sep 17 07:44:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781817 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 A7E85112E for ; Thu, 17 Sep 2020 07:45:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DABB2072E for ; Thu, 17 Sep 2020 07:45:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YdoMxMVa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726312AbgIQHp2 (ORCPT ); Thu, 17 Sep 2020 03:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726291AbgIQHol (ORCPT ); Thu, 17 Sep 2020 03:44:41 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA14C06178A for ; Thu, 17 Sep 2020 00:44:38 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id l71so879159pge.4 for ; Thu, 17 Sep 2020 00:44: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=lEIs0fiNoKXMQOFVICJuD8pB9r3fR2cLnKNpmAitwzc=; b=YdoMxMVaK6LNOk+OChrgV9M8W6BpCkeHEfs9J2RhxmFDnXh/QzDJJwdZ7Wr1tJi/Az ljBNQdf1lsq0Zqah0hCWzVjLGEs2useozFckA3KrTA5Bp1OubGiwVMeRK8kxZnQy37mF EPTsbMWqAKdrZ9hGOdasHgiv+rETE4rM5gBNQS/HY9BaUN+1eKh3zcaVTmETrXUeUCo5 RxMXDfdgbxcdoTUN0tLIMwnmn6CmhBos2FIT8bM67lUC03xVMGgN+BwQq7aSSUo3FngR B2CXW+eA4eo7qcFN4h+psD9Xi+vlcSkxj16HI/ppJyjlf3m8m9tn3hugbnMxm4NxsOnB 7lpA== 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=lEIs0fiNoKXMQOFVICJuD8pB9r3fR2cLnKNpmAitwzc=; b=ZraaxuE8zrL9JvkvTDshvG+ieUvEJM8Fz4+1H00k/6dOqJ0nyEevrvB9ENNdtKJCc2 vOsM5R/Yi/l9mPUnIQzzuZeCgCfGtvTmVT9ytogD9kO8+k6/gM4GKy59NOZSIWvvRXyu sXv7zu8tsRqWp92IP3o0zLVd2XH799CAwEqDrKvnxtcVz5cxTzgf1qr+8oOkBkoyz6L/ 4sRv61ydJa91Tguy2TXJbGDItSN9Vx6CdYSZRgJa+/FXNHnYPygpF+JoNLXHohgBpikp i52cRahXhNYFQG48a58h7FLGZssAAkETHM921uOUMKoHP40DPsChXqbyhnZw6p3rXpd0 z2cw== X-Gm-Message-State: AOAM532sYCQIoQfVzcA/nATN/3VGMSLEQy1m00j6igdweargCV97Qhzh RbqrOySXVL2byUYdk0tXQTTP6J9+wqkKsQ== X-Google-Smtp-Source: ABdhPJw7K3KJR9jBIZh7CxJhSoAhIxrb+Ot4CStfHn3Sq+k+eRisGWGGqmgb66UOcNZG6NEAxmPRaA== X-Received: by 2002:a63:85c2:: with SMTP id u185mr20891790pgd.157.1600328678199; Thu, 17 Sep 2020 00:44:38 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:37 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 05/10] diff-lib: accept option flags in run_diff_index() Date: Thu, 17 Sep 2020 00:44:09 -0700 Message-Id: <496908ac10152edb9cbcfdb75c43b1d00e163e3c.1600328335.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 | 6 +++--- diff.h | 3 ++- 4 files changed, 13 insertions(+), 12 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..0a0e69113c 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -518,7 +518,7 @@ 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; @@ -527,10 +527,10 @@ int run_diff_index(struct rev_info *revs, int cached) trace_performance_enter(); ent = revs->pending.objects; - if (diff_cache(revs, &ent->item->oid, ent->name, cached)) + if (diff_cache(revs, &ent->item->oid, ent->name, !!(option & DIFF_INDEX_CACHED))) exit(128); - diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/"); + diff_set_mnemonic_prefix(&revs->diffopt, "c/", (option & DIFF_INDEX_CACHED) ? "i/" : "w/"); diffcore_fix_diff_index(); diffcore_std(&revs->diffopt); diff_flush(&revs->diffopt); diff --git a/diff.h b/diff.h index e0c0af6286..0cc874f2d5 100644 --- a/diff.h +++ b/diff.h @@ -585,7 +585,8 @@ 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 Thu Sep 17 07:44:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781821 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 8F973112E for ; Thu, 17 Sep 2020 07:45:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CDBF2072E for ; Thu, 17 Sep 2020 07:45:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ESCOZUdm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726306AbgIQHps (ORCPT ); Thu, 17 Sep 2020 03:45:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbgIQHol (ORCPT ); Thu, 17 Sep 2020 03:44:41 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84E80C06178B for ; Thu, 17 Sep 2020 00:44:40 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id u13so885765pgh.1 for ; Thu, 17 Sep 2020 00:44: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=ohlI/n/JKJljO3yX0hgsgo5XZdcGjFSecrCS1nY3RJY=; b=ESCOZUdmtBjzXy2puSs+wykZa4NTuv3XYAdzk6Fli5fEXoAENuiqbOuh49dBKxQfzH 4TuIv4x4g0P1VYwJyOaZ6gTGQh6v2LfxiZIJO4YB50vvuyNgkY3TyF9QLcMWUV9EGRIz 9XSqhQOuOuYTbWH3FnH8CMb6mE9Y3WAkGW17vHzxfyu7U7KxqBD2owfmcamrBoOlvL1w AkytFltFQPQPB/fIj7d2p13M6KHeLJSu+H+omkAALqsvOwU7pfnE4ovz0czpIH3yBwxq luzabcG+Bj5gKF+mRgzpHZ4cnjFBhx5KhPYosVRA+q5AQLtyEcWeHEORAwPgMfyfDiGc QNcA== 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=ohlI/n/JKJljO3yX0hgsgo5XZdcGjFSecrCS1nY3RJY=; b=EF4XDDkCnm/4WvAL8NClBCvrwkMfQ6WU3Ah3lTunqBhEOJRvTOLh4JKAwhAX6pk/rt xW4Yt34mAfg8yJC09cytQaS5mK77tp4tArP5jBdb784wre7oQ2w9UZdaa0AlbPs+1sMc k9XSJy14UD5x9ghtpSTxMxH3ggT4xqLuwP10nRphRvyMkRivGlEYBunW87v1Hbi3ULUD Xd0UkkScQIJuFcEpZ4acA4VWp/m3zpZ5iMsoJEOV3P1YNXWfs4R2LBlGGUD9ADK7q26p 8uT1nvhzZ1fFbPqiPqIdCezVQzqYifxy9r5rujTCQhcsTBCOtsi8d1FjNJdulnLhOv7m GTbg== X-Gm-Message-State: AOAM531ZA2FbDZxjkZg9mCoN33L44UR5YaLy2fKIhJiUmtT/FB8jn9NA jiYuYUyuZkpRZcGw44SJkrX4yGdSKpbplg== X-Google-Smtp-Source: ABdhPJxSnf10xkVSr46ovAQe2U6lBSpIFVRhIo2tJNLPUcmGsJguPg5Pt8L9eTn+URNa6irg5bb1Aw== X-Received: by 2002:a63:1402:: with SMTP id u2mr20096391pgl.400.1600328679189; Thu, 17 Sep 2020 00:44:39 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:38 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 06/10] diff-lib: define diff_get_merge_base() Date: Thu, 17 Sep 2020 00:44:10 -0700 Message-Id: <6aac57ca022963fb41d93905e41dff36dccd5969.1600328335.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ diff.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index 0a0e69113c..e01c3f0612 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,53 @@ 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 > ARRAY_SIZE(mb_child)) + die(_("--merge-base does not work with more than two commits")); + + 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 < ARRAY_SIZE(mb_child)) { + struct object_id oid; + + if (revs->pending.nr != 1) + BUG("unexpected revs->pending.nr: %d", revs->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")); + + 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 0cc874f2d5..ae2bb7001a 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 Thu Sep 17 07:44:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781825 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 845ED139A for ; Thu, 17 Sep 2020 07:45:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69A3621D7F for ; Thu, 17 Sep 2020 07:45:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jO7dG8ce" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726318AbgIQHpn (ORCPT ); Thu, 17 Sep 2020 03:45:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726260AbgIQHol (ORCPT ); Thu, 17 Sep 2020 03:44:41 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3158C06178C for ; Thu, 17 Sep 2020 00:44:40 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id d9so693835pfd.3 for ; Thu, 17 Sep 2020 00:44: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=DwgGylpO7ks+X6wOeUVcLzhd8gOOrgR17ZYrOeA7Dtw=; b=jO7dG8ceY32uRTa4w6IeYKQWIEBsSIylXXg6v2GKx5DVfSHX1szVUhaI2GkjCmr/UE v4c6c/VeP5OgPXVaUdYhUI0I9Pm/XvMBEjHwXxefsmkqgb5RMBMJ2nncSIZDAE80E5JM RT8RhIuoOuZBoUDxGecQCCOnFPV/uIFHl1wruXSZSO/md71v27yJtjdMwp2rq+4fdjoy p70/ELJ5hs0mhXytYq/bL3jxgaJenHUtDWWl4zmDCLOxPy+za48BbnwsTlzpMwg0Ef4j 0e1i343AV4q5BAKbK2mDtDHS0JnPoejDeeJVbDvJIuph/b5ya4rzb0tG1JZV5GgRlUEt LG7Q== 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=DwgGylpO7ks+X6wOeUVcLzhd8gOOrgR17ZYrOeA7Dtw=; b=o7SXdEmPoVSAUnmUFSzEwAKdgIhbR2YvHi5M0tgbHaXUW3A/YcUnm8WlmTDz+ZKcBY GwbWD/E5GbkOirJof9lZwT1+1Z+Hnp6ddi8mv1A8TffZmZSnB0CCg9snlPQJrO6/SWCO hxsNbEJSa+/KKxbKoR7qDGzBaLeD2Y8sFqjD0EsdoJ0yva14Emc+iFoKrBk2zR8pyjoI L9CXkXsNKlvAliTElKkQIIzhrNcXKjGL65Bq4jYZ5rC4QVDHPs14eigT3Fnp15rezPO9 griYD82Z3ZXkP8Jztqhae54zR2Ex+K5k/ZktpvKGLTAZmD4UuRt2jOppwLC7p9thVL6b 2tqw== X-Gm-Message-State: AOAM532v2UtV51UjMMNvPV4VU7jIf3thJChx2YYVg0BD1iwVJXVGRRAD iLTjGlzOIozxyftmrfGURzoD2lBTxsKGKg== X-Google-Smtp-Source: ABdhPJymHzSpyMYxiG23Gp5q5PuV1i8kWVyPRp25FKAUrsi4CTDXR3daqAvlsRWsl/rPAyu+3T6C6g== X-Received: by 2002:a63:4746:: with SMTP id w6mr21851157pgk.412.1600328680134; Thu, 17 Sep 2020 00:44:40 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:39 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 07/10] t4068: add --merge-base tests Date: Thu, 17 Sep 2020 00:44:11 -0700 Message-Id: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 Thu Sep 17 07:44:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781815 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 DB80D112E for ; Thu, 17 Sep 2020 07:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB33D21973 for ; Thu, 17 Sep 2020 07:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k5wFCdSF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726309AbgIQHpV (ORCPT ); Thu, 17 Sep 2020 03:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbgIQHom (ORCPT ); Thu, 17 Sep 2020 03:44:42 -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 DCBC6C06174A for ; Thu, 17 Sep 2020 00:44:41 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id o16so832766pjr.2 for ; Thu, 17 Sep 2020 00:44: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=krFpSjajdaRLjRa3Y+FZ/sgqQXxCVYzWwUUGXCx6WwU=; b=k5wFCdSFy/i6iTrpK2pvSTw8GziYPuy9Rhl8kAVC9ueuBELYbTo5ndZhlLrICoM8U/ L2DS6F6rp5UHPqD+vI+kW+xfPH6T+C68f+sZXSIrQjKgtV+uBfZamJ8asEancexDX9zg 9YMORPx9p80XgAGcydrgqUt+wel+AdtBgOA8TubFsxz1wfKNXb9lAKVlNGbG2LmkHq8D RXgcBL4grNxKVGbhlhyaLN36cmymRi7RJD/32yLB9AGGJmNaZ7CCPPPIw8kgVzcW0M7U k0A0FoR/8rWge5gNYcZ4JNKUsbOjDCSbZLIBCLOP5T/YrFOPuRE8QcuWoFo0jq8J+918 8hGA== 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=krFpSjajdaRLjRa3Y+FZ/sgqQXxCVYzWwUUGXCx6WwU=; b=s/n9y2kLzj0ihtjI7YFyUnhZbdSsBuT3DL8aI6WxgqB9ngnyALaannSetCH5INPCjG 8A01p3Wj85ajGxGTR8fcyT1Yk7W1N7y8bq+OXFTmz192buqTNXqxg3GJd826NrtB763/ zkzaF28xah70PsUFrfxK1BE6cmfbOOOxpi8m1LY2vfrXX8bjuxDJZ8BhpVJ58izyOm/p 0O+8YgrdvejDAL4wB17oEO/a4fGu4YIxg0Oz2UCR6m8OjEZ5RfguXzAfPbfnO8dRnsL9 YECWAx1gTWjAMfefITc2GCIarWyvafPR20RlbIgowYF8kORxe0UW8Li8lmYFhpZ+oiRK eiIA== X-Gm-Message-State: AOAM530mI4kDR8rC30FkLQq5ry2rH45Oqq+9UuTJw3LvcTGCN9q013R8 VwGNer1CtiOOtmWAWcT/WFvOZe7oed2ePQ== X-Google-Smtp-Source: ABdhPJyLMHcyKpSFH8F8pWLuqdxw6IIXkk66741P8akMvXIXgMijUNTrkrSXxRr0dYzfj9PZYFzGCw== X-Received: by 2002:a17:90a:a005:: with SMTP id q5mr6851089pjp.152.1600328681019; Thu, 17 Sep 2020 00:44:41 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:40 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 08/10] builtin/diff-index: learn --merge-base Date: Thu, 17 Sep 2020 00:44:12 -0700 Message-Id: <1e4f805e570b8caad26c43b4c8293413e9128d5f.1600328335.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 | 13 +++++- diff.h | 1 + t/t4068-diff-symmetric-merge-base.sh | 59 ++++++++++++++++++++++++++++ 7 files changed, 90 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 e01c3f0612..68bf86f289 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -569,13 +569,24 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb) int run_diff_index(struct rev_info *revs, unsigned int option) { struct object_array_entry *ent; + struct object_id oid; + const char *name; 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, !!(option & DIFF_INDEX_CACHED))) + + if (option & DIFF_INDEX_MERGE_BASE) { + diff_get_merge_base(revs, &oid); + name = xstrdup(oid_to_hex(&oid)); + } else { + oidcpy(&oid, &ent->item->oid); + name = ent->name; + } + + if (diff_cache(revs, &oid, name, !!(option & DIFF_INDEX_CACHED))) exit(128); diff_set_mnemonic_prefix(&revs->diffopt, "c/", (option & DIFF_INDEX_CACHED) ? "i/" : "w/"); diff --git a/diff.h b/diff.h index ae2bb7001a..0485786b68 100644 --- a/diff.h +++ b/diff.h @@ -588,6 +588,7 @@ void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb); #define DIFF_RACY_IS_MODIFIED 02 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 Thu Sep 17 07:44:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781813 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 32CA1139A for ; Thu, 17 Sep 2020 07:45:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 17BAD208DB for ; Thu, 17 Sep 2020 07:45:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ye02AtPz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726310AbgIQHpO (ORCPT ); Thu, 17 Sep 2020 03:45:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbgIQHon (ORCPT ); Thu, 17 Sep 2020 03:44:43 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11EB0C061756 for ; Thu, 17 Sep 2020 00:44:43 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id w7so689205pfi.4 for ; Thu, 17 Sep 2020 00:44: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=m6WDQb6DLaMu3ZAs0jPlojRIsxKhYKMU+2bn31DnqMw=; b=Ye02AtPzOCLy8SkymuqMTU1DSB98TeclG0bKyKsQrGcRr9I/etisHFw8gCrC83gCiK RbeoVarxQBKg4w+02KVNMRVbkdH3k01DhmX6gYbFExRMO1wwjMh5SKBakxF/1BGWJ5u6 7pubH/pbEhKyANv47cFD6kzn+Weem5Zzc4dYor0Oh8r+6lDlz9i1c+Jnm7CaY6AzayPf V9V/y1T1IYmb7NvaX5k34Pvu3ts3f0OcAalPZHvzJYXIAnKprqs5RfwIelHmADpi6hMm Co1tPRfqkfVzDze+Knt64+DN85RiB6xKrNv0lSgANr4NiagWtbaROG9Z1pQxFYd57TAL FyhQ== 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=m6WDQb6DLaMu3ZAs0jPlojRIsxKhYKMU+2bn31DnqMw=; b=V58VK8prutELJErp3I4uCRZlTbD52Xaya153rXY8VhV8wnqqBHobx+4+Kpu0Jf5b55 UiNrPPvLYOGNs68mmuovZoT7j7qyNOdx1CS3t8yZ+YqRIqMWU7/RVHuhBmZtNf8Pcqhh fO7WZE2sruvYWGsx+4JQGw2Uoz7OnnZGnpvB/HYrC181ZodSAf+hv1OjlZsskkgWh58D oefZfyuxXzkV0y9GzLL1tAkNnViKe9Z+0iktaAKXF7ttbqhpaSUaXs+A6W1UmqeXogq7 c2S0nMYxFFI7/iQL63XP75XkYOShPbFLXTLeWiCCPL9nU4gQHot3F929xVJ3FBpgo1VG GH/A== X-Gm-Message-State: AOAM533m0fx6FlHuQZ2EJcCJV/AHZ+OD3En3YqwbNYE5VuGQKNYMigqu 1lOx6h51tND/6iEGpDfryIJAZkGQGsuEDA== X-Google-Smtp-Source: ABdhPJxQzEXxTqAlBFQKmpwia8dLBguaD/yixYCMxhvzzHYMeSX4k8WZ1jqrzOWY0Tfc6fDttip4rQ== X-Received: by 2002:a63:8ac8:: with SMTP id y191mr21388637pgd.159.1600328682244; Thu, 17 Sep 2020 00:44:42 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:41 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 09/10] builtin/diff-tree: learn --merge-base Date: Thu, 17 Sep 2020 00:44:13 -0700 Message-Id: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 In-Reply-To: References: MIME-Version: 1.0 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. Signed-off-by: Denton Liu Signed-off-by: Denton Liu --- Documentation/git-diff-tree.txt | 7 ++++- Documentation/git-diff.txt | 9 ++++--- builtin/diff-tree.c | 18 +++++++++++++ builtin/diff.c | 40 +++++++++++++++++++--------- t/t4068-diff-symmetric-merge-base.sh | 34 +++++++++++++++++++++++ 5 files changed, 91 insertions(+), 17 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..d3b526e00a 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -11,8 +11,7 @@ SYNOPSIS [verse] 'git diff' [] [] [--] [...] 'git diff' [] --cached [--merge-base] [] [--] [...] -'git diff' [] [...] [--] [...] -'git diff' [] ... [--] [...] +'git diff' [] [--merge-base] [...] [--] [...] 'git diff' [] 'git diff' [] --no-index [--] @@ -62,10 +61,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..ad78bc89b3 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -26,8 +26,7 @@ static const char builtin_diff_usage[] = "git diff [] [] [--] [...]\n" " or: git diff [] --cached [] [--] [...]\n" -" or: git diff [] [...] [--] [...]\n" -" or: git diff [] ...] [--] [...]\n" +" or: git diff [] [--merge-base] [...] [--] [...]\n" " or: git diff [] ]\n" " or: git diff [] --no-index [--] ]\n" COMMON_DIFF_OPTIONS_HELP; @@ -172,19 +171,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 Thu Sep 17 07:44:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11781811 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 99C5E112E for ; Thu, 17 Sep 2020 07:45:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7194521734 for ; Thu, 17 Sep 2020 07:45:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cIJviHhK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726187AbgIQHpF (ORCPT ); Thu, 17 Sep 2020 03:45:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726303AbgIQHoo (ORCPT ); Thu, 17 Sep 2020 03:44:44 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 498DEC061797 for ; Thu, 17 Sep 2020 00:44:44 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id gf14so797501pjb.5 for ; Thu, 17 Sep 2020 00:44:44 -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=SMDke5q4egupJlixzIzak9Wm2pEV4d5A/nAe6GhDB6g=; b=cIJviHhKl0ix23nB92m4WzehNntDjnTacsSwMpQAKmpM6qrn43rr+a0KsX9VUpqhEO 2YS6sWd44dSjj5GFNVpjf5I7nuyjvwJO3Y1id3et6nRNsWHnHMNwnUn6e4LT8MjRmijy xsniUkoD7VuV5uxHOPaBfnDu0YGXBsQjLPyhdGUKRLDrt+l/AcIrHP+JOUfeuJmroiBr JZxV8WybCes8lcW79dIvtI24txd4iqk/3En6Fpln6I/fHaiBOlFOj9rVcGsU6Ycw7CMf kbdaxHNNz5HWdsyHpvPzRbfILu1PT3R5uqq0MwD/WXLzH9pINlNKCz07JooLMH/+lXAF jWcA== 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=SMDke5q4egupJlixzIzak9Wm2pEV4d5A/nAe6GhDB6g=; b=Y/R/ZSKuFmaGyO+N9rTkURS3ecS9KNOZ96iTMiAwgjElk9tVa1vMDpVIIskOU9b7Uf xyDtpWgOl1sUmDupa+jKeu+LPZuHhWkyZeShHSwwtPrnbYYL0UJEuCtKm68MP0scMU6n Z6qwD0cNwj1LFzgnP8t7FQaiWk8TSh1P+WuBAe2UzZ6CKhiPmjDGfu4pPBHXZ4VGy30q lofPYNq4aZ/dL8cP5q88ZrYDr4bt2on9QWMPQoYhgzgzm4PpQ6QvNuIpxcLxBgASzrf0 E7jHjRsZhJkFJtmA4x/iQZ7GQ0DzOwT9jx6axmqNozekHeXj7P7UgmLUgmiFppzm2gEV rtcA== X-Gm-Message-State: AOAM531Ul8jj1EpxMGvZfU7/hH4mWPUndAeYZoviVzAsjTJYX9BGOZio nPspvRntnlnoz3c0tlzMkpWFutH7I2fpTQ== X-Google-Smtp-Source: ABdhPJyqV4iha1cG0C91sEVinZdcUZitQ5OAskUBvsjWb4LAQ4iVbHYoYam6GgrpGVGIB8TZ0kj4sA== X-Received: by 2002:a17:90a:ed88:: with SMTP id k8mr7130475pjy.232.1600328683386; Thu, 17 Sep 2020 00:44:43 -0700 (PDT) Received: from archbookpro.hsd1.ca.comcast.net ([2601:647:4201:c540::414c]) by smtp.gmail.com with ESMTPSA id j9sm4931711pfc.175.2020.09.17.00.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 00:44:42 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Junio C Hamano Subject: [PATCH v3 10/10] contrib/completion: complete `git diff --merge-base` Date: Thu, 17 Sep 2020 00:44:14 -0700 Message-Id: <42a8c9b665c63d5e8135546538db69a366cd70da.1600328336.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7 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 ()