From patchwork Sat Oct 12 04:37:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Abhijeetsingh Meena X-Patchwork-Id: 13833485 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5D67374F1 for ; Sat, 12 Oct 2024 04:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728707873; cv=none; b=S+D0YolwVzOjclGbyNQx2IZnkYnvj68lysi72Bqh1RJnq2Ulo+ifYWaEkFtP8n6ibUzNTz5ly2Y5NfmzpXqrIZ04xXzARa0RE2PHYgLzZJ9+rGiK0jHOtwa/JNifyAbrFKQBw5iwfrMqh2cKpBSRENtwRZGHqLlQNCAOQhrBThc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728707873; c=relaxed/simple; bh=yNCSwp9ilTB7k7dn+LXBoJNN362bwLWCTtTb6uButYk=; h=Message-Id:In-Reply-To:References:From:Date:Subject:MIME-Version: Content-Type:To:Cc; b=JysPJmsAJ11rp9G0zYFOfCEUSHNWK4Y6UQbh0PDZtOELvIbPEQPkwAKZL6E+GWdiV32oorqBaK35qqNyYT2076GwYN33rGZpbvErm9UT65qa+iyj4J+K2YN52hzBLw+inCxU6vEwUTPd1r9/a4gVS0yBXPwAmIb8WCTq/61cBPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ST0G3zoV; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ST0G3zoV" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a99c0beaaa2so193579366b.1 for ; Fri, 11 Oct 2024 21:37:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728707870; x=1729312670; darn=vger.kernel.org; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=y9P5pIMd/g5eplTsOG7n3zuU5oOZnpPUceC9tGFrrvo=; b=ST0G3zoVaQ8XtI3zXqjRZMnJv57neGOUaBvxVcXFAWdc1NysMuAyqhyEep+wOzAVWl WHo3iLan6VhIJwaJK7C330F4JDsnyo+x/w8kfNnWRzXVv5BSh2PFPIktYkgksOBBJb3Q 82XSMnITIcRyUa7JWqp1SybcfEk6yMtxadFQtCnOU/OZwT1SQdbXtNz4gNQaebco631e jpRSR+XBUdpF1k6g6BoOP3iLSY9yCzpegzt7e+ERhmHqC9WwTbRDnc1OxwkRiRg7kWi9 asXXqSwjQ6TblGQqFnjfKgZ8MOD3zYzbc9xVXZwKUSSyfSfFUnsDTDakEyHD/O8Vawrz tH9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728707870; x=1729312670; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y9P5pIMd/g5eplTsOG7n3zuU5oOZnpPUceC9tGFrrvo=; b=RJoMmdGz4SkJ6/5AwzKSJ7wOL+woCjk0hJHWY9j1TL38HfuxX/qbkmedx8VLlfMcZw gUgfkJ05jp7AsXxcbNcgoZ2hBtz5+QceQNqoQTH4KqGIuIc2dK2uW4kAL8v7gbp9rDDA qU1297iuyhSY6O1BvZqA77MpQ2P1ZSu0JMbKSMxIGaLJ9vow5q6C8RjGT1iicO1x1Hyz YeYQbp+DZ6HQEujemV4Ddt6JuTPu9CMK14N1CaXGCXaIZx6kClBgGRIQo32Jwf12z8K7 FfGFGNmLkvp6e64eABwVKXlgGo3tjy0mrpzumBWcno8JxfiMMTn+G/8sQBi69/IDnCiz +LhA== X-Gm-Message-State: AOJu0YxzShme0GX20MNq+SDZ74wSjhgrm/fPROKUc8BqpaWj7A604WPJ ZKeLO+PvbcVbCf8C9F94Yt2mTESv7xkUfZgU/9nOa9lGAZygn0WunzuBVg== X-Google-Smtp-Source: AGHT+IGxcaWMD4yo4/lH8pWmBNPo3aa+V5jaYyfuvbxdYfM2glt2TSHm9vcJKLrOLazB7NYOdNiQyQ== X-Received: by 2002:a17:907:d2e8:b0:a99:5cf0:4b83 with SMTP id a640c23a62f3a-a99b9583ed2mr403220766b.30.1728707869457; Fri, 11 Oct 2024 21:37:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99a80c02b9sm280976766b.138.2024.10.11.21.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 21:37:49 -0700 (PDT) Message-Id: <4ed930cab1b7f5e9738e73c7b9374d927a8acd94.1728707867.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 12 Oct 2024 04:37:46 +0000 Subject: [PATCH v2 1/2] blame: respect .git-blame-ignore-revs automatically Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Phillip Wood , Abhijeetsingh Meena , Abhijeetsingh Meena From: Abhijeetsingh Meena From: Abhijeetsingh Meena git-blame(1) can ignore a list of commits with `--ignore-revs-file`. This is useful for marking uninteresting commits like formatting changes, refactors and whatever else should not be “blamed”. Some projects even version control this file so that all contributors can use it; the conventional name is `.git-blame-ignore-revs`. But each user still has to opt-in to the standard ignore list, either with this option or with the config `blame.ignoreRevsFile`. Let’s teach git-blame(1) to respect this conventional file in order to streamline the process. Signed-off-by: Abhijeetsingh Meena --- builtin/blame.c | 8 ++++++++ t/t8015-blame-default-ignore-revs.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 t/t8015-blame-default-ignore-revs.sh diff --git a/builtin/blame.c b/builtin/blame.c index e407a22da3b..1eddabaf60f 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1105,6 +1105,14 @@ parse_done: add_pending_object(&revs, &head_commit->object, "HEAD"); } + /* + * By default, add .git-blame-ignore-revs to the list of files + * containing revisions to ignore if it exists. + */ + if (access(".git-blame-ignore-revs", F_OK) == 0) { + string_list_append(&ignore_revs_file_list, ".git-blame-ignore-revs"); + } + init_scoreboard(&sb); sb.revs = &revs; sb.contents_from = contents_from; diff --git a/t/t8015-blame-default-ignore-revs.sh b/t/t8015-blame-default-ignore-revs.sh new file mode 100755 index 00000000000..d4ab686f14d --- /dev/null +++ b/t/t8015-blame-default-ignore-revs.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +test_description='default revisions to ignore when blaming' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'blame: default-ignore-revs-file' ' + test_commit first-commit hello.txt hello && + + echo world >>hello.txt && + test_commit second-commit hello.txt && + + sed "1s/hello/hi/" hello.txt.tmp && + mv hello.txt.tmp hello.txt && + test_commit third-commit hello.txt && + + git rev-parse HEAD >ignored-file && + git blame --ignore-revs-file=ignored-file hello.txt >expect && + git rev-parse HEAD >.git-blame-ignore-revs && + git blame hello.txt >actual && + + test_cmp expect actual +' + +test_done From patchwork Sat Oct 12 04:37:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhijeetsingh Meena X-Patchwork-Id: 13833486 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C45E37E76D for ; Sat, 12 Oct 2024 04:37:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728707874; cv=none; b=SZTZF1NiWeoqGj54kev6AGRsvueM3h+ERaGUTalSY9VDwoDca+byn03OIoDVdUwVE5GPFuIyAhfwc/EiRQOOcRa+oovN67scy7rs1V/PQQMlgf8h9kubFfc+rFPHyvdNgZoQ6kPWddsRZeG2WXc33v7Tn4B4L+hECYq+BB21+W0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728707874; c=relaxed/simple; bh=X95jfjZy5a768s/71Dp8Ow0RXQzhy5uf88F8cSoBgWA=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=tLGe3IFWh3eQZ5MxQ6tTHDE9c1MLpYGyE0Pc95yv9Z1ljjIj0q21g/JXNticIgT8ONQyC9NozXourqK5GYTBhVBvh3QkhV34r7lxocalhTLl3TQ63sLMfokS7K3i+trU5dZ0t3uq6QknEidISUhPJFiWhmOGVC7t9TzFLTzsrQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YjGUW+0V; arc=none smtp.client-ip=209.85.218.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YjGUW+0V" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a99f1fd20c4so9256166b.0 for ; Fri, 11 Oct 2024 21:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728707870; x=1729312670; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=2RAA9EhAuPuJVUIH+x4ZgeM3kZpErL+qYNf2DDuGcP8=; b=YjGUW+0VHlI/zNkoa0IdNT7y9qhK2v1QXCbNRXJXoKt/IR239+bTR5KhSKlxIvY7Ks uRSdWKsP0mWNo1CBtENCW2jgshfW1JZyUBeUJVw18nvWQfsFI800edGsBi9jP3Jzepwc EooLb39EgaUBw7H6kUqq3nC1uitD/MdI2w5peFyHMzI0kpEl8mfcFDssyncn9lm4NlMc 0RhndBHkXphYYg3vy+HuM+6S6Z+k4iNV7KmQ4quzRVdKG9HkB5iiPARnB+a21uO4QO2q YNv24ZHWiIdYmxxtsMC+qPUe9Gcey9+l1M/gfksW4sBoYGmtvrEX/sJ9V5MSflAoyPsp mVyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728707870; x=1729312670; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2RAA9EhAuPuJVUIH+x4ZgeM3kZpErL+qYNf2DDuGcP8=; b=fyEw3tjOFG7clR8Dz97BxKz4a6UISJ0x7Q2wPIjOc+hHcVsCc5Zjm1NrhbMhWriUKb meCCpnYEfGh7KSgbup3s3PBRq8GANTbMtpPh/zZvikS+Fb9yOGwFV36d69zXYSZpRAev 9YEMJibOWOMDiGRpD+wLajszZQpM+xa0r2zvE1nua4T6in+oLzJ447EUcRhk/qBYzP0O TxmbxxGlgoqfbEdfKY8Te5MQA/bAeCxfM5QJfNGBE+6/PCIofDp8mZ/mQHXkAkIxQa4r Npmcimyga9YKMzYyqG8t8htBZEsDbS6sjKczzxhm99/xIRZvvUGRNu6QQv2NZhKIX7Vs vn1Q== X-Gm-Message-State: AOJu0YymCPt15ZVaqY+0gwdh3vcRrXZjWGyJB1y75ZRDhU0zPfabgYjF 9suubfmkxipKBoNIvOaOglGuWO/Llkkpuytdwc8zbhFuXTv8U2bR5YXZHA== X-Google-Smtp-Source: AGHT+IH1qOXrS07E6pk8ELda4ePHQT8yYhIkycgdFYwLUedRg/mvpGrlwbhFuTEOC2klEij3xHzorQ== X-Received: by 2002:a17:907:9811:b0:a99:89ea:593e with SMTP id a640c23a62f3a-a99b93aafb3mr443089866b.13.1728707870234; Fri, 11 Oct 2024 21:37:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a99dfb3539fsm66759266b.134.2024.10.11.21.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2024 21:37:49 -0700 (PDT) Message-Id: <8d2fa3af7964dacd09d454de4325b1d5eb7a5c3d.1728707867.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sat, 12 Oct 2024 04:37:47 +0000 Subject: [PATCH v2 2/2] blame: introduce --override-ignore-revs to bypass ignore revisions list Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Phillip Wood , Abhijeetsingh Meena , Abhijeetsingh Meena From: Abhijeetsingh Meena From: Abhijeetsingh Meena The git blame command can ignore a list of revisions specified either through the --ignore-revs-file option or the blame.ignoreRevsFile configuration. This feature is useful for excluding irrelevant commits, such as formatting changes or large refactors, from blame annotations. However, users may encounter cases where they need to temporarily override these configurations to inspect all commits, even those excluded by the ignore list. Currently, there is no simple way to bypass all ignore revisions settings in one go. This patch introduces the --override-ignore-revs option (or -O), which allows users to easily bypass the --ignore-revs-file option, --ignore-rev option and the blame.ignoreRevsFile configuration. When this option is used, git blame will completely disregard all configured ignore revisions lists. The motivation behind this feature is to provide users with more flexibility when dealing with large codebases that rely on .git-blame-ignore-revs files for shared configurations, while still allowing them to disable the ignore list when necessary for troubleshooting or deeper inspections. Signed-off-by: Abhijeetsingh Meena --- builtin/blame.c | 8 +++++++- t/t8016-blame-override-ignore-revs.sh | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 t/t8016-blame-override-ignore-revs.sh diff --git a/builtin/blame.c b/builtin/blame.c index 1eddabaf60f..956520edcd9 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -69,6 +69,7 @@ static int coloring_mode; static struct string_list ignore_revs_file_list = STRING_LIST_INIT_DUP; static int mark_unblamable_lines; static int mark_ignored_lines; +static int override_ignore_revs = 0; static struct date_mode blame_date_mode = { DATE_ISO8601 }; static size_t blame_date_width; @@ -901,6 +902,7 @@ int cmd_blame(int argc, OPT_BIT('w', NULL, &xdl_opts, N_("ignore whitespace differences"), XDF_IGNORE_WHITESPACE), OPT_STRING_LIST(0, "ignore-rev", &ignore_rev_list, N_("rev"), N_("ignore when blaming")), OPT_STRING_LIST(0, "ignore-revs-file", &ignore_revs_file_list, N_("file"), N_("ignore revisions from ")), + OPT_BOOL('O', "override-ignore-revs", &override_ignore_revs, N_("override all configurations that exclude revisions")), OPT_BIT(0, "color-lines", &output_option, N_("color redundant metadata from previous line differently"), OUTPUT_COLOR_LINE), OPT_BIT(0, "color-by-age", &output_option, N_("color lines by age"), OUTPUT_SHOW_AGE_WITH_COLOR), OPT_BIT(0, "minimal", &xdl_opts, N_("spend extra cycles to find better match"), XDF_NEED_MINIMAL), @@ -1119,7 +1121,11 @@ parse_done: sb.reverse = reverse; sb.repo = the_repository; sb.path = path; - build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list); + + if (!override_ignore_revs) { + build_ignorelist(&sb, &ignore_revs_file_list, &ignore_rev_list); + } + string_list_clear(&ignore_revs_file_list, 0); string_list_clear(&ignore_rev_list, 0); setup_scoreboard(&sb, &o); diff --git a/t/t8016-blame-override-ignore-revs.sh b/t/t8016-blame-override-ignore-revs.sh new file mode 100755 index 00000000000..b5899729f8e --- /dev/null +++ b/t/t8016-blame-override-ignore-revs.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +test_description='default revisions to ignore when blaming' + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +test_expect_success 'blame: override-ignore-revs' ' + test_commit first-commit hello.txt hello && + + echo world >>hello.txt && + test_commit second-commit hello.txt && + + sed "1s/hello/hi/" hello.txt.tmp && + mv hello.txt.tmp hello.txt && + test_commit third-commit hello.txt && + + git blame hello.txt >expect && + git rev-parse HEAD >.git-blame-ignore-revs && + git blame -O hello.txt >actual && + + test_cmp expect actual +' + +test_done