Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2319535pxb; Fri, 25 Mar 2022 15:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNf0pXe9iExYL6ycErbmE0D+UnCarfoSlIFvblDfY6fO5z0zkKs5gZlZa2mWiQFwYQjyhe X-Received: by 2002:aa7:9253:0:b0:4fa:6974:3260 with SMTP id 19-20020aa79253000000b004fa69743260mr11940222pfp.8.1648247061084; Fri, 25 Mar 2022 15:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648247061; cv=none; d=google.com; s=arc-20160816; b=O4BvqrDH3DI7EnQHto2zlBvsRVfGbj/AK4sfR62wlDCxSUIirEZ+Dj6vDBqJXiMG+o eFPzRyc1j1oCFrmEGf34meNBDXUdAyBFrz/mxy/tog6NXLBQm6g8XXa32iX7LGybkYGk HXJQhdYq0/FBPeKN4+gdzvj5uiQYmMb6jR/NFGywERjOxmwQHxGoJBhgnTOZ78b2kN/w 8B2yHheaOEatYFW967HrmxS/Ie1P38g0R5DtZv03NzZAoyRcYmZyTRYhH7lNGs69RZ7X QkPPXVMHTGl5HQKZ1emGaag22+rtNXq09nDx9cdRiSD65M8pztDHaz5V/0enbafBy7IJ twBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=hsYCabDYG9BsnSr6aIERiuj385zksjChMI7/4113Z3I=; b=npQpHXcphwnO2A85M5JuvxQoiHubw+idsg0odSyUcYx+mB7LjTTge/xiuY55KFy6Kk f22xu4o/EYbB9QENquPFxe8WioE4m/wRaJMsZyAuTOVmErJN4Nbh8qRr9FBAeD3ZQZp7 LsjARpKqc1V/dFArSVJipo8D8www/apXaK8O0uoAhuxOgClQIA+WgCNZj9MLIKosTIXp pMTfZR3nd655TTi9qUvJy+IkvmIZerOJA1GCCENl95EbNrNJ/BpVR3YgKPXm0uZzZDoK 3uA4dLBdfuYZYhdXVEJnfLwnNKFaG/yDwmFeHTMKG37PylOzZk3a+bfaczsJ/8de4vvN MwhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=VrC4nDK2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id mh14-20020a17090b4ace00b001bd14e0306fsi4159366pjb.71.2022.03.25.15.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 15:24:21 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@lwn.net header.s=20201203 header.b=VrC4nDK2; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E5F9130C39; Fri, 25 Mar 2022 14:58:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233655AbiCYWAT (ORCPT + 99 others); Fri, 25 Mar 2022 18:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233635AbiCYWAS (ORCPT ); Fri, 25 Mar 2022 18:00:18 -0400 Received: from ms.lwn.net (ms.lwn.net [45.79.88.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9404C118F5A; Fri, 25 Mar 2022 14:58:43 -0700 (PDT) Received: from localhost (unknown [IPv6:2601:281:8300:35::5f6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ms.lwn.net (Postfix) with ESMTPSA id 454BB2C3; Fri, 25 Mar 2022 21:58:43 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 ms.lwn.net 454BB2C3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lwn.net; s=20201203; t=1648245523; bh=hsYCabDYG9BsnSr6aIERiuj385zksjChMI7/4113Z3I=; h=From:To:Cc:Subject:Date:From; b=VrC4nDK2COPGZVaDKnzQ0RIroS8+LdFo30Izn8Ow21Zvvjs6AqQjlDJVidAdf4GsO SVp8q2DV2vdvwXDMXrYcOnCR+7JQcqksOye/BVL/VSsQ4ExGakHB5wDu7TI59QEntr 8Y0SN1IqWmveU5eCyRyg6JuBCyt0Ky9DQigJT0p1yfgjemOTeEdkMshz5qptfIODsq Ba6yF7SNSH6EF5vft5y7yrnb5nDZDxAZ0keNFYmMyCfbsdVdSLRTKjfPxC+88NwKyG Ljfm/tbMjb6OVuKq82e3Vm8m0gqjM95BaDh6rH+nDwdd5/4Ys1Ecka/FtELk6jcKQ8 jnqG8bh59RWMQ== From: Jonathan Corbet To: linux-doc@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCH] docs: Add a document on how to fix a messy diffstat Date: Fri, 25 Mar 2022 15:58:42 -0600 Message-ID: <87wnghd78t.fsf@meer.lwn.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A branch with merges in will sometimes create a diffstat containing a lot of unrelated work at "git request-pull" time. Create a document based on Linus's advice (found in the links below) and add it to the maintainer manual in the hope of saving some wear on Linus's keyboard going forward. Link: https://lore.kernel.org/lkml/CAHk-=wg3wXH2JNxkQi+eLZkpuxqV+wPiHhw_Jf7ViH33Sw7PHA@mail.gmail.com/ Link: https://lore.kernel.org/lkml/CAHk-=wgXbSa8yq8Dht8at+gxb_idnJ7X5qWZQWRBN4_CUPr=eQ@mail.gmail.com/ Signed-off-by: Jonathan Corbet --- [If this passes muster I'll likely toss a version onto LWN as well] Documentation/maintainer/index.rst | 1 + Documentation/maintainer/messy-diffstat.rst | 96 +++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 Documentation/maintainer/messy-diffstat.rst diff --git a/Documentation/maintainer/index.rst b/Documentation/maintainer/index.rst index f0a60435b124..3e03283c144e 100644 --- a/Documentation/maintainer/index.rst +++ b/Documentation/maintainer/index.rst @@ -12,6 +12,7 @@ additions to this manual. configure-git rebasing-and-merging pull-requests + messy-diffstat maintainer-entry-profile modifying-patches diff --git a/Documentation/maintainer/messy-diffstat.rst b/Documentation/maintainer/messy-diffstat.rst new file mode 100644 index 000000000000..970eac087f67 --- /dev/null +++ b/Documentation/maintainer/messy-diffstat.rst @@ -0,0 +1,96 @@ +.. SPDX-License-Identifier: GPL-2.0 + +===================================== +Handling messy pull-request diffstats +===================================== + +Subsystem maintainers routinely use ``git request-pull`` as part of the +process of sending work upstream. Normally, the result includes a nice +diffstat listing showing which files will be touched and how much of each +will be changed. Occasionally, though, a repository with a relatively +complicated development history will yield a massive diffstat containing a +great deal of unrelated work. The result looks ugly and obscures what the +pull request is actually doing. This document describes what is happening +and how to fix things up; it is derived from The Wisdom of Linus Torvalds, +found in Linus1_ and Linus2_. + +.. _Linus1: https://lore.kernel.org/lkml/CAHk-=wg3wXH2JNxkQi+eLZkpuxqV+wPiHhw_Jf7ViH33Sw7PHA@mail.gmail.com/ +.. _Linus2: https://lore.kernel.org/lkml/CAHk-=wgXbSa8yq8Dht8at+gxb_idnJ7X5qWZQWRBN4_CUPr=eQ@mail.gmail.com/ + +A Git development history proceeds as a series of commits. In a simplified +manner, mainline kernel development looks like this:: + + ... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN + +If one wants to see what has changed between two points, a command like +will do the job:: + + $ git diff --stat --summary vN-rc2..vN-rc3 + +Here, there are two clear points in the history; Git will essentially +"subtract" the beginning point from the end point and display the resulting +differences. The requested operation is unambiguous and easy enough to +understand. + +When a subsystem maintainer creates a branch and commits changes to it, the +result in the simplest case is a history that looks like:: + + ... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN + | + +-- c1 --- c2 --- ... --- cN + +If that maintainer now uses ``git diff`` to see what has changed between +the mainline branch (let's call it "linus") and cN, there are still two +clear endpoints, and the result is as expected. So a pull request +generated with ``git request-pull`` will also be as expected. But now +consider a slightly more complex development history:: + + ... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN + | | + | +-- c1 --- c2 --- ... --- cN + | / + +-- x1 --- x2 --- x3 + +Our maintainer has created one branch at vN-rc1 and another at vN-rc2; the +two were then subsequently merged into c2. Now a pull request generated +for cN may end up being messy indeed, and developers often end up wondering +why. + +What is happening here is that there are no longer two clear end points for +the ``git diff`` operation to use. The development culminating in cN +started in two different places; to generate the diffstat, ``git diff`` +ends up having pick one of them and hoping for the best. If the diffstat +starts at vN-rc1, it may end up including all of the changes between there +and the second origin end point (vN-rc2), which is certainly not what our +maintainer had in mind. With all of that extra junk in the diffstat, it +may be impossible to tell what actually happened in the changes leading up +to cN. + +Maintainers often try to resolve this problem by, for example, rebasing the +branch or performing another merge with the linus branch, then recreating +the pull request. This approach tends not to lead to joy at the receiving +end of that pull request; rebasing and/or merging just before pushing +upstream is a well-known way to get a grumpy response. + +So what is to be done? The best response when confronted with this +situation is to indeed to a merge, but to do it privately, as if it were +the source of shame. Create a new, throwaway branch and do the merge +there:: + + ... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN + | | | + | +-- c1 --- c2 --- ... --- cN | + | / | | + +-- x1 --- x2 --- x3 +------------+-- TEMP + +The merge operation resolves all of the complications resulting from the +multiple beginning points, yielding a coherent result that contains only +the differences from the mainline branch. Now it will be possible to +generate a diffstat with the desired information:: + + $ git diff -C --stat --summary linus..TEMP + +Save the output from this command, then simply delete the TEMP branch; +definitely do not expose it to the outside world. Take the saved diffstat +output and edit it into the messy pull request, yielding a result that +shows what is really going on. That request can then be sent upstream. -- 2.35.1