From patchwork Tue Apr 18 23:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 85114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3204724vqo; Tue, 18 Apr 2023 16:57:50 -0700 (PDT) X-Google-Smtp-Source: AKy350YlkF3Z7oSGTgbfYWYjfInTyad+0FC9Aup3otlXwv+7GKRcnkmNrKfdWoF0HpI/WbfwYuOT X-Received: by 2002:a05:6a20:7d90:b0:ef:c506:99d2 with SMTP id v16-20020a056a207d9000b000efc50699d2mr1465804pzj.5.1681862269993; Tue, 18 Apr 2023 16:57:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681862269; cv=none; d=google.com; s=arc-20160816; b=Zt7e1vStSyiLFjFVx4d4cd4cUJUlvWFBdETHYpqWZ47A0pEvHB63S7td5O6DXTONor d8aL1Sw3HneQ3qzbjxDpKaOwR70Wsl7Sx5yYNZs68cJ6vbLyDBiIEDHptdQCdQx0vyDF bF0dvK2dKoVwW9PYxQ1jzSdERuiiFtofOy5dKYccGCbFJXlnm5PCYwy9pGALDdPDbZrz /9uLjBciX0QR3zZz8aKAQViKU+fu9ZQdHV8433xK+VHl7xuoFWz02dubpZ0kCm7uAb3J rhtD3VPWWuFbpU0Yg0p2Ff8fElfE4aj2eyHWwy9TFxsTAHK/YjNnRIliRWOjyK3ixYg/ oSlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PhglwvWlSgthDlHIkB+MKZrf0HFSOExgD2fCy5cvMKk=; b=0uEQwjPszrawANFAzC6SEeMMUrQ70QErPJvfavfnfxVjpQndtewe3yP54aVerKL1bX Z4JRoTKtoNb9JPHo/UX9IrVNrPSu6roJ0uQ5O3z0zdXS+uAn44OYPsLf5HTeeFzNC+GD OxgiTB/cGDTpsSUm0P6NJfo95HoeSpU2m54doIEDAMQj1swdsKrxHOIargGLNFJfV1BO 9bViGmJcpsaf6m3qWEdVh8EP0KnoK/LIkjMOX10f/M2msYwMQ5K+rICylGW+UGmUvSgs 6Yyl4ObGeRXVjBP5xgHCpBl8dclwbiTzI8tX8KiC1l1Db8UBQCJmX7xGzsT1FkkFzMA6 t+oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kHUv3Wsq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j19-20020a634a53000000b0050bf617d84fsi16028213pgl.249.2023.04.18.16.57.32; Tue, 18 Apr 2023 16:57:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kHUv3Wsq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbjDRXbw (ORCPT + 99 others); Tue, 18 Apr 2023 19:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbjDRXbu (ORCPT ); Tue, 18 Apr 2023 19:31:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EED8776B6; Tue, 18 Apr 2023 16:31:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8A58C62F93; Tue, 18 Apr 2023 23:31:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1734BC433EF; Tue, 18 Apr 2023 23:31:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681860696; bh=dXrs6HEsN21LvkE2B3upLi4G+i29wmCt/lPdjsvXpGI=; h=From:To:Cc:Subject:Date:From; b=kHUv3WsqPqzTUjKZj5daYdXJVOeGYPfR+HG/1Ev5CEQ8LdaBAskFK4XARG+8WHt/l GRshbswOxIG769iM5hqnzpq+Me6XxQeuva7mJ4pTq26GfkqPkePob7eqP4FjCFoGKj YVreXt3MhxRSydf5g8/5BTs4qeLw+dStiJ4bxqgBZehB3XlYIduJUmcsj0fLs2YxKs 8zM7imnjJv5k5PVMlIrKpk2CRnIf3UhYDigJQ1XRnUJXxBvLly+IlibqKRWYDZDLEA P4yKAZZu33mYQriE3r4DblTGy29Q6smgowNEh7YCYmBkJBZ91sSGahWyPJPFjW+p2g cko7jlNtKcWhg== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor Cc: Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Masahiro Yamada , Stephen Boyd , Jean Delvare , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH] .gitattributes: set diff driver for Rust source code files Date: Wed, 19 Apr 2023 01:30:48 +0200 Message-Id: <20230418233048.335281-1-ojeda@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763560411769473051?= X-GMAIL-MSGID: =?utf-8?q?1763560411769473051?= Git supports a builtin Rust diff driver [1] since v2.23.0 (2019). It improves the choice of hunk headers in some cases, such as diffs within methods, since those are indented in Rust within an `impl` block, and therefore the default diff driver would pick the outer `impl` block instead (rather than the method where the changed code is). For instance, with the default diff driver: @@ -455,6 +455,8 @@ impl fmt::Write for RawFormatter { // Amount that we can copy. `saturating_sub` ensures we get 0 if `pos` goes past `end`. let len_to_copy = core::cmp::min(pos_new, self.end).saturating_sub(self.pos); + test_diff_driver(); + if len_to_copy > 0 { // SAFETY: If `len_to_copy` is non-zero, then we know `pos` has not gone past `end` // yet, so it is valid for write per the type invariants. With the Rust diff driver: @@ -455,6 +455,8 @@ fn write_str(&mut self, s: &str) -> fmt::Result { // Amount that we can copy. `saturating_sub` ensures we get 0 if `pos` goes past `end`. let len_to_copy = core::cmp::min(pos_new, self.end).saturating_sub(self.pos); + test_diff_driver(); + if len_to_copy > 0 { // SAFETY: If `len_to_copy` is non-zero, then we know `pos` has not gone past `end` // yet, so it is valid for write per the type invariants. Thus set the `rust` diff driver for `*.rs` source files. Link: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header [1] Signed-off-by: Miguel Ojeda Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Gary Guo Reviewed-by: Benno Lossin --- .gitattributes | 1 + 1 file changed, 1 insertion(+) base-commit: 09a9639e56c01c7a00d6c0ca63f4c7c41abe075d diff --git a/.gitattributes b/.gitattributes index c9ba5bfc4036..2325c529e185 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ *.[ch] diff=cpp *.dts diff=dts *.dts[io] diff=dts +*.rs diff=rust