{"thread":{"id":"66313","subject":"[PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","startedAt":"2026-09-11T23:29:50Z","lastAt":"2026-10-15T15:19:45Z","messageCount":40,"participants":["Ravi Mistry via GitGitGadget","Ravi Mistry","Junio C Hamano","Eric Sunshine","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"552614","messageId":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":null,"subject":"[PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-09-11T23:29:44Z","receivedAt":"2026-09-11T23:29:50Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\ngit-blame(1) can ignore a list of commits specified via\n--ignore-revs-file or the blame.ignoreRevsFile configuration option.\nThis is useful for skipping uninteresting revisions such as tree-wide\nformatting changes, large-scale refactors, and code modernizations that\nwould otherwise obscure genuine historical authorship.\n\nWhen revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\nblame.ignoreRevsFile config option\", 2019-10-18), it intentionally\navoided adopting a default ignore file. At the time, the capability was\nnew and unproven, so avoiding unrequested filesystem I/O or unexpected\nattribution shifts took priority over a project-wide default.\nRequiring explicit opt-in per clone was therefore the prudent design.\n\nSince then, maintaining a .git-blame-ignore-revs file in the repository\nroot has become the de facto standard across the Git ecosystem, adopted\nby major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\nsource projects (such as Chromium and LLVM). As a consequence,\ndevelopers frequently encounter a jarring mismatch: web interfaces\nseamlessly ignore formatting commits, but local git-blame(1) and\ngit-annotate(1) runs do not, unless each user manually configures\nblame.ignoreRevsFile for every local checkout.\n\nTeach git-blame(1) and git-annotate(1) to automatically check for a\nregular .git-blame-ignore-revs file at the root of the working tree when\noperating in a non-bare repository.\n\nTo ensure consistent precedence, security, and override semantics:\n- Loading the default file occurs before reading configuration and CLI\n  options, preserving user and repository config overrides.\n- Path resolution is anchored to repo_get_work_tree() and verified via\n  lstat() to ensure it is a regular file. Symbolic links, directories,\n  FIFOs, and sockets are safely skipped, preventing local information\n  disclosure and denial-of-service hangs.\n- In build_ignorelist(), ignore-rev files are parsed starting after the\n  last empty string entry. This ensures setting blame.ignoreRevsFile to\n  \"\" or passing --ignore-revs-file \"\" or --no-ignore-revs-file cleanly\n  discards the default file without attempting to open or parse it,\n  allowing users to bypass corrupted default files.\n- Duplicate parsing is prevented by tracking seen files in a strset.\n\nUpdate documentation in blame-options.adoc and config/blame.adoc, and\nadd comprehensive test coverage in t8013 for the default file lookup,\nsubdirectory invocations, CLI and config overrides, symlink rejection,\ncomments and whitespace handling, and bare repositories.\n\nBased-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\nHelped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\nHelped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n    blame: default to ignoring revisions in .git-blame-ignore-revs\n    \n    This series restarts the conversation from the stalled attempt in PR\n    https://github.com/gitgitgadget/git/pull/1809 and addresses feature\n    request https://github.com/gitgitgadget/git/issues/1494\n    \n    See the previous discussion in\n    https://lore.kernel.org/git/pull.1809.v2.git.1728707867.gitgitgadget@gmail.com/\n    \n    In addition to resolving the questions raised by reviewers during the\n    previous discussion, this updated iteration introduces important\n    security hardening, bug fixes, and test improvements:\n    \n     1. Commit message rationale: The commit message now details why\n        revision ignoring originally avoided a default file when the feature\n        was first added:\n        https://github.com/git/git/commit/ae3f36dea16e51041c56ba9ed6b38380c8421816\n        It explains why ecosystem standardization across GitHub, GitLab,\n        Gerrit, Chromium, and LLVM makes a default file desirable today,\n        addressing the previous feedback from Phillip Wood. Trailers\n        acknowledge earlier patch authorship and reviewer contributions.\n    \n     2. Security and path resolution: Path lookup is anchored to\n        repo_get_work_tree(). Using lstat ensures that symbolic links,\n        directories, FIFOs, and sockets are skipped safely.\n    \n     3. Configuration and option override semantics: The build_ignorelist()\n        function begins processing after the last empty string entry.\n        Setting blame.ignoreRevsFile to an empty string or providing an\n        empty filename option on the command line allows users to bypass a\n        corrupted default file without encountering a fatal error.\n    \n     4. Documentation updates: Documentation clarifies that configured files\n        are processed after the default file. It explains how providing an\n        empty filename disables the default file and notes that bare\n        repositories do not search for the file. Documentation checks pass\n        without warning.\n    \n     5. Test harness improvements: The test suite removes the destructive\n        repository reset in t8013 and adds test coverage for comments,\n        whitespace, zero byte files, symlink rejection, corrupted file\n        overrides, and git annotate parity. Test lint checks pass without\n        error.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2224%2Frmistry%2Fblame-default-ignore-revs-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2224/rmistry/blame-default-ignore-revs-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2224\n\n Documentation/blame-options.adoc |   6 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  42 +++++++--\n t/t8013-blame-ignore-revs.sh     | 151 +++++++++++++++++++++++++++++++\n 4 files changed, 196 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\nindex 1ae1222b6b..17f5734d61 100644\n--- a/Documentation/blame-options.adoc\n+++ b/Documentation/blame-options.adoc\n@@ -133,8 +133,10 @@ take effect.\n \tIgnore revisions listed in _<file>_, which must be in the same format as an\n \t`fsck.skipList`.  This option may be repeated, and these files will be\n \tprocessed after any files specified with the `blame.ignoreRevsFile` config\n-\toption.  An empty file name, `\"\"`, will clear the list of revs from\n-\tpreviously processed files.\n+\toption or the default `.git-blame-ignore-revs` file.  An empty file name,\n+\t`\"\"`, will clear the list of revs from previously processed files.\n+\t`--no-ignore-revs-file` will clear all previously specified ignore revs\n+\tfiles, including the default `.git-blame-ignore-revs` file.\n \n `--color-lines`::\n \tColor line annotations in the default format differently if they come from\ndiff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\nindex 4d047c1790..6f9be627e1 100644\n--- a/Documentation/config/blame.adoc\n+++ b/Documentation/config/blame.adoc\n@@ -23,9 +23,12 @@ blame.showRoot::\n blame.ignoreRevsFile::\n \tIgnore revisions listed in the file, one unabbreviated object name per\n \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n-\t`#` are ignored.  This option may be repeated multiple times.  Empty\n-\tfile names will reset the list of ignored revisions.  This option will\n-\tbe handled before the command line option `--ignore-revs-file`.\n+\t`#` are ignored.  If `.git-blame-ignore-revs` exists at the root of the\n+\tworking tree in a non-bare repository, it is used by default.  This option\n+\tmay be repeated multiple times; files specified here are processed after\n+\tthe default file.  An empty file name will reset the list of ignored\n+\trevisions from previously processed files and disable the default file.\n+\tThis option is handled before the command-line option `--ignore-revs-file`.\n \n blame.markUnblamableLines::\n \tMark lines that were changed by an ignored revision that we could not\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 48d5251c6d..0935d864ad 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -15,9 +15,11 @@\n #include \"hex.h\"\n #include \"commit.h\"\n #include \"diff.h\"\n+#include \"path.h\"\n #include \"revision.h\"\n #include \"quote.h\"\n #include \"string-list.h\"\n+#include \"strmap.h\"\n #include \"mailmap.h\"\n #include \"parse-options.h\"\n #include \"prio-queue.h\"\n@@ -768,8 +770,12 @@ static int git_blame_config(const char *var, const char *value,\n \t\tret = git_config_pathname(&str, var, value);\n \t\tif (ret)\n \t\t\treturn ret;\n-\t\tif (str)\n-\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n+\t\tif (str) {\n+\t\t\tif (!*str)\n+\t\t\t\tstring_list_clear(&ignore_revs_file_list, 0);\n+\t\t\telse\n+\t\t\t\tstring_list_append(&ignore_revs_file_list, str);\n+\t\t}\n \t\tfree(str);\n \t\treturn 0;\n \t}\n@@ -936,16 +942,24 @@ static void build_ignorelist(struct blame_scoreboard *sb,\n {\n \tstruct string_list_item *i;\n \tstruct object_id oid;\n+\tstruct strset seen_files = STRSET_INIT;\n+\tsize_t start_idx = 0, idx;\n+\n+\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tif (!*ignore_revs_file_list->items[idx].string)\n+\t\t\tstart_idx = idx + 1;\n+\t}\n \n \toidset_init(&sb->ignore_list, 0);\n-\tfor_each_string_list_item(i, ignore_revs_file_list) {\n-\t\tif (!strcmp(i->string, \"\"))\n-\t\t\toidset_clear(&sb->ignore_list);\n-\t\telse\n-\t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n+\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tconst char *path = ignore_revs_file_list->items[idx].string;\n+\n+\t\tif (strset_add(&seen_files, path))\n+\t\t\toidset_parse_file_carefully(&sb->ignore_list, path,\n \t\t\t\t\t\t    the_repository->hash_algo,\n \t\t\t\t\t\t    peel_to_commit_oid, sb);\n \t}\n+\tstrset_clear(&seen_files);\n \tfor_each_string_list_item(i, ignore_rev_list) {\n \t\tif (repo_get_oid_committish(the_repository, i->string, &oid) ||\n \t\t    peel_to_commit_oid(&oid, sb))\n@@ -1020,6 +1034,20 @@ int cmd_blame(int argc,\n \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n \n \tsetup_default_color_by_age();\n+\t{\n+\t\tconst char *work_tree = repo_get_work_tree(the_repository);\n+\n+\t\tif (work_tree) {\n+\t\t\tchar *default_file = mkpathdup(\"%s/%s\", work_tree,\n+\t\t\t\t\t\t       \".git-blame-ignore-revs\");\n+\t\t\tstruct stat st;\n+\n+\t\t\tif (!lstat(default_file, &st) && S_ISREG(st.st_mode) &&\n+\t\t\t    !access(default_file, R_OK))\n+\t\t\t\tstring_list_append(&ignore_revs_file_list, default_file);\n+\t\t\tfree(default_file);\n+\t\t}\n+\t}\n \trepo_config(the_repository, git_blame_config, &output_option);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \trevs.date_mode = blame_date_mode;\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex cace00ae8d..a43654a7ba 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -327,4 +327,155 @@ test_expect_success ignore_merge '\n \ttest_cmp expect actual\n '\n \n+# Tests for default .git-blame-ignore-revs file\n+test_expect_success 'setup default .git-blame-ignore-revs' '\n+\tgit checkout -b default-file-branch &&\n+\ttest_write_lines line1 line2 >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default base\" &&\n+\tgit tag DEF_A &&\n+\n+\ttest_write_lines line1-modified line2-modified >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default mod\" &&\n+\tgit tag DEF_B &&\n+\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs is used by default' '\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs respected by git annotate' '\n+\tgit rev-parse --short DEF_A >expect_sha &&\n+\tgit annotate def-file >actual &&\n+\ttest_grep \"^$(cat expect_sha)\" actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs works from subdirectory' '\n+\tmkdir -p sub &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n+\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\t\tgit rev-parse DEF_A >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with --no-ignore-revs-file' '\n+\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with --ignore-revs-file \"\"' '\n+\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n+\ttest_config blame.ignoreRevsFile \"\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs handles comments and whitespace' '\n+\ttest_when_finished \"git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n+\t{\n+\t\techo \"# Leading comment\" &&\n+\t\techo \"\" &&\n+\t\techo \"   $(git rev-parse DEF_B)   \" &&\n+\t\techo \"# Trailing comment\"\n+\t} >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'empty default .git-blame-ignore-revs is harmless' '\n+\ttest_when_finished \"git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n+\t: >.git-blame-ignore-revs &&\n+\tgit blame def-file\n+'\n+\n+test_expect_success SYMLINKS 'symlink .git-blame-ignore-revs is ignored' '\n+\ttest_when_finished \"rm -f target_file .git-blame-ignore-revs && git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n+\tgit rev-parse DEF_B >target_file &&\n+\tln -sf target_file .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'malformed default .git-blame-ignore-revs fails but can be bypassed' '\n+\ttest_when_finished \"git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\ttest_must_fail git blame def-file &&\n+\tgit blame --no-ignore-revs-file def-file &&\n+\tgit blame --ignore-revs-file \"\" def-file\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs deduplicated when also set in config' '\n+\ttest_config blame.ignoreRevsFile .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n+\ttest_write_lines line1-modified line2-c >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m C &&\n+\tgit tag DEF_C &&\n+\tgit rev-parse DEF_C >custom_ignore &&\n+\ttest_config blame.ignoreRevsFile custom_ignore &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs ignored in bare repo' '\n+\tgit clone --bare . bare.git &&\n+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_C >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'blame works when .git-blame-ignore-revs does not exist' '\n+\trm -f .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n\nbase-commit: fa7f9290efe2bd22dd736689597b474b93798e11\n-- \ngitgitgadget\n"},{"id":"553715","messageId":"20260930145952.1840998-1-rmistry@google.com","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"Re: [PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-09-30T14:59:52Z","receivedAt":"2026-09-30T14:59:58Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Hi all,\n\nGentle ping on this patch. Please let me know if you have any feedback or questions on this approach, or if there are other reviewers I should loop in.\n\nTIA!\n"},{"id":"554188","messageId":"xmqqse2kma4o.fsf@gitster.g","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"Re: [PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-05T15:37:27Z","receivedAt":"2026-10-05T15:37:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ravi Mistry via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  blame.ignoreRevsFile::\n>  \tIgnore revisions listed in the file, one unabbreviated object name per\n>  \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n> -\t`#` are ignored.  This option may be repeated multiple times.  Empty\n> -\tfile names will reset the list of ignored revisions.  This option will\n> -\tbe handled before the command line option `--ignore-revs-file`.\n> +\t`#` are ignored.  If `.git-blame-ignore-revs` exists at the root of the\n> +\tworking tree in a non-bare repository, it is used by default.  This option\n> +\tmay be repeated multiple times; files specified here are processed after\n> +\tthe default file.  An empty file name will reset the list of ignored\n> +\trevisions from previously processed files and disable the default file.\n> +\tThis option is handled before the command-line option `--ignore-revs-file`.\n\nThe proposed log message explains that '.git-blame-ignore-revs' is\nused as the default for blame.ignoreRevsFile even when the user does\nnot ask to do so in order to match what hosting sites do, as it\nwould be confusing if the local repository behaved differently.\nWhile wanting consistency is reasonable, the description above does\nnot quite match that goal.  If an untracked '.git-blame-ignore-revs'\nfile exists at the root of the working tree, or if a tracked one has\nlocal changes relative to HEAD, the local repository behaves\ndifferently from hosting sites that operate on the\n'HEAD:.git-blame-ignore-revs' blob.  It may make more sense to say:\n\"If the 'HEAD:.git-blame-ignore-revs' blob exists, it is added as\nthe initial element in the list of ignore-revs files.  Other files\nlisted in the configuration are also used, but an empty element\nmakes all elements that appeared before in the list forgotten.\"\nThis rule should apply whether the repository is bare or not.\n\nThe proposed log message also talks about taking only a regular file\nand ignoring everything else for \"security\" [*], but there is\nanother important thing we need to worry about security-wise.\nSomebody has to audit the parser for these files (one unabbreviated\nobject name per line, ignoring whitespace and lines starting with\n'#') and ensure that the implementation is truly secure.\n\nThis is a new threat vector introduced by this change.  Without this\npatch, blame.ignoreRevsFile comes only from the configuration, which\ncannot point to an attacker-controlled file under our threat model.\nNow, however, the parser must read upstream-controlled content at a\nknown path, and it must be prepared to cope with attempts to use it\nas an attack vector.\n\n[Footnote]\n\n * By the way, \"we do not read anything from the working tree.\n   'HEAD:.git-blame-ignore-revs' is the only thing that is added\n   to the picture\" would make it unnecessary to lstat() and ignore\n   non-regular files.\n\n"},{"id":"554224","messageId":"20261005211213.1896012-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqse2kma4o.fsf@gitster.g","subject":"Re: [PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-05T21:12:13Z","receivedAt":"2026-10-05T21:12:13Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"\"Junio C Hamano\" <gitster@pobox.com> writes:\n\n> While wanting consistency is reasonable, the description above does\n> not quite match that goal.  If an untracked '.git-blame-ignore-revs'\n> file exists at the root of the working tree, or if a tracked one has\n> local changes relative to HEAD, the local repository behaves\n> differently from hosting sites that operate on the\n> 'HEAD:.git-blame-ignore-revs' blob.  It may make more sense to say:\n> \"If the 'HEAD:.git-blame-ignore-revs' blob exists, it is added as\n> the initial element in the list of ignore-revs files.  Other files\n> listed in the configuration are also used, but an empty element\n> makes all elements that appeared before in the list forgotten.\"\n> This rule should apply whether the repository is bare or not.\n\nThank you very much for the detailed feedback, Junio! Reading the\ncommitted blob from HEAD instead of the working tree totally makes\nsense.\n\n> Somebody has to audit the parser for these files (one unabbreviated\n> object name per line, ignoring whitespace and lines starting with\n> '#') and ensure that the implementation is truly secure.\n\nI looked through the parser in oidset.c (which we can share for\nboth the HEAD blob and configured files) and peel_to_commit_oid in\nbuiltin/blame.c. Mostly looks good, IMHO, but there may be two edge\ncases we can tighten up:\n\n1. Rejecting lines with embedded NUL bytes via memchr in oidset.c\n   (where strchr and the check after parse_oid_hex_algop currently\n   stop at the first NUL byte and ignore trailing bytes on the\n   line).\n\n2. Passing OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK in\n   peel_to_commit_oid and peeling tags step by step so missing OIDs\n   or tag targets do not trigger lazy promisor fetches in partial\n   clones.\n\nDoes this plan sound good to you for v2?\n\nThanks,\nRavi\n\n"},{"id":"554398","messageId":"xmqqmrsp8kzj.fsf@gitster.g","threadId":"66313","inReplyTo":"20261005211213.1896012-1-rmistry@google.com","subject":"Re: [PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-07T17:43:28Z","receivedAt":"2026-10-07T17:43:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ravi Mistry <rmistry@google.com> writes:\n\n> \"Junio C Hamano\" <gitster@pobox.com> writes:\n>\n>> While wanting consistency is reasonable, the description above does\n>> not quite match that goal.  If an untracked '.git-blame-ignore-revs'\n>> file exists at the root of the working tree, or if a tracked one has\n>> local changes relative to HEAD, the local repository behaves\n>> differently from hosting sites that operate on the\n>> 'HEAD:.git-blame-ignore-revs' blob.  It may make more sense to say:\n>> \"If the 'HEAD:.git-blame-ignore-revs' blob exists, it is added as\n>> the initial element in the list of ignore-revs files.  Other files\n>> listed in the configuration are also used, but an empty element\n>> makes all elements that appeared before in the list forgotten.\"\n>> This rule should apply whether the repository is bare or not.\n>\n> Thank you very much for the detailed feedback, Junio! Reading the\n> committed blob from HEAD instead of the working tree totally makes\n> sense.\n>\n>> Somebody has to audit the parser for these files (one unabbreviated\n>> object name per line, ignoring whitespace and lines starting with\n>> '#') and ensure that the implementation is truly secure.\n>\n> I looked through the parser in oidset.c (which we can share for\n> both the HEAD blob and configured files) and peel_to_commit_oid in\n> builtin/blame.c. Mostly looks good, IMHO, but there may be two edge\n> cases we can tighten up:\n>\n> 1. Rejecting lines with embedded NUL bytes via memchr in oidset.c\n>    (where strchr and the check after parse_oid_hex_algop currently\n>    stop at the first NUL byte and ignore trailing bytes on the\n>    line).\n>\n> 2. Passing OBJECT_INFO_SKIP_FETCH_OBJECT and OBJECT_INFO_QUICK in\n>    peel_to_commit_oid and peeling tags step by step so missing OIDs\n>    or tag targets do not trigger lazy promisor fetches in partial\n>    clones.\n>\n> Does this plan sound good to you for v2?\n\nAre you presenting a different plan, or just adding details to what\nyou quoted from my message above?\n\nI delegated because I did not want to spend time on the auditing\npart, so if you are asking me that these two are the only things we\nneed to address, that defeats the point of me delegating it to\n\"somebody else\" X-<.  Hopefully a v2 with some tightening the OID\nparsing may entice folks (who are hopefully interested in security\nrelated work) to chime in and they would help us decide if it is\ngood enough to cover these two points and nothing else.\n\nThanks.\n\n"},{"id":"554406","messageId":"20261007180722.3413265-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqmrsp8kzj.fsf@gitster.g","subject":"Re: [PATCH] blame: default to ignoring revisions in .git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-07T18:07:22Z","receivedAt":"2026-10-07T18:07:22Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"\"Junio C Hamano\" <gitster@pobox.com> writes:\n\n> Are you presenting a different plan, or just adding details to what\n> you quoted from my message above?\n>\n> I delegated because I did not want to spend time on the auditing\n> part, so if you are asking me that these two are the only things we\n> need to address, that defeats the point of me delegating it to\n> \"somebody else\" X-<.  Hopefully a v2 with some tightening the OID\n> parsing may entice folks (who are hopefully interested in security\n> related work) to chime in and they would help us decide if it is\n> good enough to cover these two points and nothing else.\n\nAh, sorry for my confusion, I was adding details to your plan\nabove (I thought the audit was being delegated to me so wanted to\nmake sure the approach was correct). Will put up a v2 for the\nsecurity reviewers to chime in.\n\nThanks again!\nRavi\n\n"},{"id":"554539","messageId":"pull.2224.v2.git.1791493644.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"[PATCH v2 0/2] blame: ignore revs in HEAD:.git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-08T21:07:22Z","receivedAt":"2026-10-08T21:07:22Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"This series teaches git-blame(1) and git-annotate(1) to automatically use\nthe HEAD:.git-blame-ignore-revs blob by default if it exists, so local runs\nmatch hosting platforms without requiring manual blame.ignoreRevsFile\nconfiguration in every clone. This restarts the stalled attempt in PR\nhttps://github.com/gitgitgadget/git/pull/1809\n(https://lore.kernel.org/git/pull.1809.v2.git.1728707867.gitgitgadget@gmail.com/)\nand addresses https://github.com/gitgitgadget/git/issues/1494.\n\nChanges since v1:\n\n * Split the series into two commits.\n * Patch 1/2 hardens oidset_parse_file_carefully() in oidset.c and\n   peel_to_commit_oid() in builtin/blame.c before exposing them to\n   upstream-controlled content at a well-known path:\n   * Reject lines containing embedded NUL bytes via memchr() so trailing\n     bytes after a NUL cannot be silently ignored.\n   * Pass OBJECT_INFO_LOOKUP_REPLACE | OBJECT_INFO_SKIP_FETCH_OBJECT |\n     OBJECT_INFO_QUICK to odb_read_object_info_extended() and peel tags one\n     layer per iteration so missing OIDs or tag targets do not trigger lazy\n     promisor fetches or pack directory rescans in partial clones, and\n     verify that each peeled target matches the tag's declared type.\n * Patch 2/2 reads the committed HEAD:.git-blame-ignore-revs blob (in both\n   bare and non-bare repositories) instead of reading a file from the\n   working tree, matching hosting platforms even when an untracked file is\n   present or a tracked one has local modifications. The tree entry is\n   checked with S_ISREG() so non-regular entries (such as committed\n   symlinks) are skipped, parsed in memory via\n   oidset_parse_buffer_carefully(), and bypassed without reading if cleared\n   via blame.ignoreRevsFile=\"\" or --no-ignore-revs-file.\n\nRavi Mistry (2):\n  blame: harden ignore-revs parser and tag peeling\n  blame: ignore revs in HEAD:.git-blame-ignore-revs\n\n Documentation/blame-options.adoc |   8 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  65 ++++++++-\n oidset.c                         |  81 ++++++++----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 220 +++++++++++++++++++++++++++++++\n 6 files changed, 357 insertions(+), 35 deletions(-)\n\n\nbase-commit: fa7f9290efe2bd22dd736689597b474b93798e11\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2224%2Frmistry%2Fblame-default-ignore-revs-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2224/rmistry/blame-default-ignore-revs-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/2224\n\nRange-diff vs v1:\n\n -:  ---------- > 1:  2e12486c0d blame: harden ignore-revs parser and tag peeling\n 1:  22a100d00d ! 2:  35e303d65b blame: default to ignoring revisions in .git-blame-ignore-revs\n     @@ Metadata\n      Author: Ravi Mistry <rmistry@google.com>\n      \n       ## Commit message ##\n     -    blame: default to ignoring revisions in .git-blame-ignore-revs\n     +    blame: ignore revs in HEAD:.git-blame-ignore-revs\n      \n          git-blame(1) can ignore a list of commits specified via\n          --ignore-revs-file or the blame.ignoreRevsFile configuration option.\n     @@ Commit message\n          git-annotate(1) runs do not, unless each user manually configures\n          blame.ignoreRevsFile for every local checkout.\n      \n     -    Teach git-blame(1) and git-annotate(1) to automatically check for a\n     -    regular .git-blame-ignore-revs file at the root of the working tree when\n     -    operating in a non-bare repository.\n     +    Teach git-blame(1) and git-annotate(1) to automatically add the\n     +    HEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\n     +    in the list of ignore-revs files in both bare and non-bare\n     +    repositories. Reading the committed blob from HEAD rather than the\n     +    working tree ensures that local runs match hosting platforms even when\n     +    an untracked .git-blame-ignore-revs file is present or a tracked one\n     +    has uncommitted local changes.\n      \n     -    To ensure consistent precedence, security, and override semantics:\n     -    - Loading the default file occurs before reading configuration and CLI\n     -      options, preserving user and repository config overrides.\n     -    - Path resolution is anchored to repo_get_work_tree() and verified via\n     -      lstat() to ensure it is a regular file. Symbolic links, directories,\n     -      FIFOs, and sockets are safely skipped, preventing local information\n     -      disclosure and denial-of-service hangs.\n     -    - In build_ignorelist(), ignore-rev files are parsed starting after the\n     -      last empty string entry. This ensures setting blame.ignoreRevsFile to\n     -      \"\" or passing --ignore-revs-file \"\" or --no-ignore-revs-file cleanly\n     -      discards the default file without attempting to open or parse it,\n     -      allowing users to bypass corrupted default files.\n     -    - Duplicate parsing is prevented by tracking seen files in a strset.\n     +    To ensure consistent precedence and override semantics:\n     +    - The default HEAD:.git-blame-ignore-revs entry is added before reading\n     +      configuration and CLI options, preserving user and repository config\n     +      overrides.\n     +    - In git_blame_config(), blame.ignoreRevsFile entries are appended via\n     +      string_list_append() rather than inserted in sorted order via\n     +      string_list_insert() so that configuration entries preserve their\n     +      order relative to the initial default entry.\n     +    - The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n     +      get_oid_with_context(). Its mode is checked with S_ISREG() before\n     +      reading the object so that non-regular tree entries (such as a\n     +      committed symbolic link whose blob stores a target path rather than\n     +      revision IDs, a subdirectory, or a gitlink) are skipped instead of\n     +      being read and rejected as malformed object names. The blob is parsed\n     +      in memory via a new oidset_parse_buffer_carefully() helper in\n     +      oidset.c that shares line parsing with oidset_parse_file_carefully().\n     +    - In build_ignorelist(), ignore-revs entries are processed starting\n     +      after the last empty string entry. This ensures setting\n     +      blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n     +      --no-ignore-revs-file cleanly discards the default blob without\n     +      attempting to read or parse it, allowing users to bypass a malformed\n     +      default blob.\n      \n          Update documentation in blame-options.adoc and config/blame.adoc, and\n     -    add comprehensive test coverage in t8013 for the default file lookup,\n     -    subdirectory invocations, CLI and config overrides, symlink rejection,\n     -    comments and whitespace handling, and bare repositories.\n     +    add comprehensive test coverage in t8013 for the default blob lookup,\n     +    subdirectory invocations, bare repositories, uncommitted and untracked\n     +    working-tree files, CLI and config overrides, committed symlink\n     +    entries, and comments and whitespace handling.\n      \n          Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\n          Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n     @@ Commit message\n      \n       ## Documentation/blame-options.adoc ##\n      @@ Documentation/blame-options.adoc: take effect.\n     + `--ignore-revs-file <file>`::\n       \tIgnore revisions listed in _<file>_, which must be in the same format as an\n       \t`fsck.skipList`.  This option may be repeated, and these files will be\n     - \tprocessed after any files specified with the `blame.ignoreRevsFile` config\n     +-\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n      -\toption.  An empty file name, `\"\"`, will clear the list of revs from\n      -\tpreviously processed files.\n     -+\toption or the default `.git-blame-ignore-revs` file.  An empty file name,\n     -+\t`\"\"`, will clear the list of revs from previously processed files.\n     -+\t`--no-ignore-revs-file` will clear all previously specified ignore revs\n     -+\tfiles, including the default `.git-blame-ignore-revs` file.\n     ++\tprocessed after the default `HEAD:.git-blame-ignore-revs` blob (if it\n     ++\texists) and any files specified with the `blame.ignoreRevsFile` config\n     ++\toption.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will clear\n     ++\tthe list of revs from previously processed files, including the default\n     ++\t`HEAD:.git-blame-ignore-revs` blob.\n       \n       `--color-lines`::\n       \tColor line annotations in the default format differently if they come from\n     @@ Documentation/config/blame.adoc: blame.showRoot::\n      -\t`#` are ignored.  This option may be repeated multiple times.  Empty\n      -\tfile names will reset the list of ignored revisions.  This option will\n      -\tbe handled before the command line option `--ignore-revs-file`.\n     -+\t`#` are ignored.  If `.git-blame-ignore-revs` exists at the root of the\n     -+\tworking tree in a non-bare repository, it is used by default.  This option\n     -+\tmay be repeated multiple times; files specified here are processed after\n     -+\tthe default file.  An empty file name will reset the list of ignored\n     -+\trevisions from previously processed files and disable the default file.\n     -+\tThis option is handled before the command-line option `--ignore-revs-file`.\n     ++\t`#` are ignored.  If the `HEAD:.git-blame-ignore-revs` blob exists, it\n     ++\tis added as the initial element in the list of ignore-revs files.\n     ++\tOther files listed in the configuration are also used, but an empty\n     ++\telement makes all elements that appeared before in the list forgotten.\n     ++\tThis option will be handled before the command line option\n     ++\t`--ignore-revs-file`.\n       \n       blame.markUnblamableLines::\n       \tMark lines that were changed by an ignored revision that we could not\n      \n       ## builtin/blame.c ##\n     -@@\n     - #include \"hex.h\"\n     - #include \"commit.h\"\n     - #include \"diff.h\"\n     -+#include \"path.h\"\n     - #include \"revision.h\"\n     - #include \"quote.h\"\n     - #include \"string-list.h\"\n     -+#include \"strmap.h\"\n     - #include \"mailmap.h\"\n     - #include \"parse-options.h\"\n     - #include \"prio-queue.h\"\n      @@ builtin/blame.c: static int git_blame_config(const char *var, const char *value,\n     - \t\tret = git_config_pathname(&str, var, value);\n       \t\tif (ret)\n       \t\t\treturn ret;\n     --\t\tif (str)\n     + \t\tif (str)\n      -\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n     -+\t\tif (str) {\n     -+\t\t\tif (!*str)\n     -+\t\t\t\tstring_list_clear(&ignore_revs_file_list, 0);\n     -+\t\t\telse\n     -+\t\t\t\tstring_list_append(&ignore_revs_file_list, str);\n     -+\t\t}\n     ++\t\t\tstring_list_append(&ignore_revs_file_list, str);\n       \t\tfree(str);\n       \t\treturn 0;\n       \t}\n     -@@ builtin/blame.c: static void build_ignorelist(struct blame_scoreboard *sb,\n     +@@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n     + \t}\n     + }\n     + \n     ++static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n     ++\t\t\t\t\t   const char *name)\n     ++{\n     ++\tstruct object_context oc;\n     ++\tstruct object_id oid;\n     ++\tenum object_type type;\n     ++\tsize_t size;\n     ++\tchar *buf;\n     ++\n     ++\tif (get_oid_with_context(the_repository, name, GET_OID_QUIETLY,\n     ++\t\t\t\t &oid, &oc))\n     ++\t\tgoto out;\n     ++\tif (!S_ISREG(oc.mode))\n     ++\t\tgoto out;\n     ++\n     ++\tbuf = odb_read_object(the_repository->objects, &oid, &type, &size);\n     ++\tif (!buf)\n     ++\t\tgoto out;\n     ++\tif (type == OBJ_BLOB)\n     ++\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n     ++\t\t\t\t\t      the_repository->hash_algo,\n     ++\t\t\t\t\t      peel_to_commit_oid, sb);\n     ++\tfree(buf);\n     ++\n     ++out:\n     ++\tobject_context_release(&oc);\n     ++}\n     ++\n     + static void build_ignorelist(struct blame_scoreboard *sb,\n     + \t\t\t     struct string_list *ignore_revs_file_list,\n     + \t\t\t     struct string_list *ignore_rev_list)\n       {\n       \tstruct string_list_item *i;\n       \tstruct object_id oid;\n     -+\tstruct strset seen_files = STRSET_INIT;\n      +\tsize_t start_idx = 0, idx;\n      +\n      +\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n     @@ builtin/blame.c: static void build_ignorelist(struct blame_scoreboard *sb,\n      -\tfor_each_string_list_item(i, ignore_revs_file_list) {\n      -\t\tif (!strcmp(i->string, \"\"))\n      -\t\t\toidset_clear(&sb->ignore_list);\n     --\t\telse\n     --\t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n      +\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n     -+\t\tconst char *path = ignore_revs_file_list->items[idx].string;\n     -+\n     -+\t\tif (strset_add(&seen_files, path))\n     -+\t\t\toidset_parse_file_carefully(&sb->ignore_list, path,\n     ++\t\ti = &ignore_revs_file_list->items[idx];\n     ++\t\tif (i->util)\n     ++\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n     + \t\telse\n     + \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n       \t\t\t\t\t\t    the_repository->hash_algo,\n     - \t\t\t\t\t\t    peel_to_commit_oid, sb);\n     - \t}\n     -+\tstrset_clear(&seen_files);\n     - \tfor_each_string_list_item(i, ignore_rev_list) {\n     - \t\tif (repo_get_oid_committish(the_repository, i->string, &oid) ||\n     - \t\t    peel_to_commit_oid(&oid, sb))\n      @@ builtin/blame.c: int cmd_blame(int argc,\n       \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n       \n       \tsetup_default_color_by_age();\n     -+\t{\n     -+\t\tconst char *work_tree = repo_get_work_tree(the_repository);\n     -+\n     -+\t\tif (work_tree) {\n     -+\t\t\tchar *default_file = mkpathdup(\"%s/%s\", work_tree,\n     -+\t\t\t\t\t\t       \".git-blame-ignore-revs\");\n     -+\t\t\tstruct stat st;\n     -+\n     -+\t\t\tif (!lstat(default_file, &st) && S_ISREG(st.st_mode) &&\n     -+\t\t\t    !access(default_file, R_OK))\n     -+\t\t\t\tstring_list_append(&ignore_revs_file_list, default_file);\n     -+\t\t\tfree(default_file);\n     -+\t\t}\n     -+\t}\n     ++\tstring_list_append(&ignore_revs_file_list,\n     ++\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n       \trepo_config(the_repository, git_blame_config, &output_option);\n       \trepo_init_revisions(the_repository, &revs, NULL);\n       \trevs.date_mode = blame_date_mode;\n      \n     + ## oidset.c ##\n     +@@ oidset.c: void oidset_parse_file(struct oidset *set, const char *path,\n     + \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n     + }\n     + \n     ++static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n     ++\t\t\t      const struct git_hash_algo *algop,\n     ++\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n     ++{\n     ++\tconst char *p;\n     ++\tconst char *name;\n     ++\tstruct object_id oid;\n     ++\n     ++\tif (memchr(sb->buf, '\\0', sb->len))\n     ++\t\tdie(\"invalid object name: %s\", sb->buf);\n     ++\n     ++\t/*\n     ++\t * Allow trailing comments, leading whitespace\n     ++\t * (including before commits), and empty or whitespace\n     ++\t * only lines.\n     ++\t */\n     ++\tname = strchr(sb->buf, '#');\n     ++\tif (name)\n     ++\t\tstrbuf_setlen(sb, name - sb->buf);\n     ++\tstrbuf_trim(sb);\n     ++\tif (!sb->len)\n     ++\t\treturn;\n     ++\n     ++\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n     ++\t\tdie(\"invalid object name: %s\", sb->buf);\n     ++\tif (fn && fn(&oid, cbdata))\n     ++\t\treturn;\n     ++\toidset_insert(set, &oid);\n     ++}\n     ++\n     + void oidset_parse_file_carefully(struct oidset *set, const char *path,\n     + \t\t\t\t const struct git_hash_algo *algop,\n     + \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n     + {\n     + \tFILE *fp;\n     + \tstruct strbuf sb = STRBUF_INIT;\n     +-\tstruct object_id oid;\n     + \n     + \tfp = fopen(path, \"r\");\n     + \tif (!fp)\n     + \t\tdie(\"could not open object name list: %s\", path);\n     +-\twhile (!strbuf_getline(&sb, fp)) {\n     +-\t\tconst char *p;\n     +-\t\tconst char *name;\n     +-\n     +-\t\tif (memchr(sb.buf, '\\0', sb.len))\n     +-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n     +-\n     +-\t\t/*\n     +-\t\t * Allow trailing comments, leading whitespace\n     +-\t\t * (including before commits), and empty or whitespace\n     +-\t\t * only lines.\n     +-\t\t */\n     +-\t\tname = strchr(sb.buf, '#');\n     +-\t\tif (name)\n     +-\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n     +-\t\tstrbuf_trim(&sb);\n     +-\t\tif (!sb.len)\n     +-\t\t\tcontinue;\n     +-\n     +-\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n     +-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n     +-\t\tif (fn && fn(&oid, cbdata))\n     +-\t\t\tcontinue;\n     +-\t\toidset_insert(set, &oid);\n     +-\t}\n     ++\twhile (!strbuf_getline(&sb, fp))\n     ++\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n     + \tif (ferror(fp))\n     + \t\tdie_errno(\"Could not read '%s'\", path);\n     + \tfclose(fp);\n     + \tstrbuf_release(&sb);\n     + }\n     ++\n     ++void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n     ++\t\t\t\t   size_t size,\n     ++\t\t\t\t   const struct git_hash_algo *algop,\n     ++\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n     ++{\n     ++\tstruct strbuf sb = STRBUF_INIT;\n     ++\tconst char *p = buf, *end;\n     ++\n     ++\tif (!size)\n     ++\t\treturn;\n     ++\tend = buf + size;\n     ++\n     ++\twhile (p < end) {\n     ++\t\tconst char *nl = memchr(p, '\\n', end - p);\n     ++\t\tsize_t len = (nl ? nl : end) - p;\n     ++\n     ++\t\tstrbuf_reset(&sb);\n     ++\t\tif (len && p[len - 1] == '\\r')\n     ++\t\t\tlen--;\n     ++\t\tstrbuf_add(&sb, p, len);\n     ++\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n     ++\t\tp = nl ? nl + 1 : end;\n     ++\t}\n     ++\tstrbuf_release(&sb);\n     ++}\n     +\n     + ## oidset.h ##\n     +@@ oidset.h: void oidset_parse_file_carefully(struct oidset *set, const char *path,\n     + \t\t\t\t const struct git_hash_algo *algop,\n     + \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n     + \n     ++/*\n     ++ * Similar to oidset_parse_file_carefully(), but parses lines from an\n     ++ * in-memory buffer of 'size' bytes.\n     ++ */\n     ++void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n     ++\t\t\t\t   size_t size,\n     ++\t\t\t\t   const struct git_hash_algo *algop,\n     ++\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n     ++\n     + struct oidset_iter {\n     + \tconst kh_oid_set_t *set;\n     + \tkhiter_t iter;\n     +\n       ## t/t8013-blame-ignore-revs.sh ##\n     -@@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n     +@@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n       \ttest_cmp expect actual\n       '\n       \n     -+# Tests for default .git-blame-ignore-revs file\n     -+test_expect_success 'setup default .git-blame-ignore-revs' '\n     ++# Tests for default HEAD:.git-blame-ignore-revs blob\n     ++test_expect_success 'setup default HEAD:.git-blame-ignore-revs' '\n      +\tgit checkout -b default-file-branch &&\n      +\ttest_write_lines line1 line2 >def-file &&\n      +\tgit add def-file &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\tgit commit -m \"default mod\" &&\n      +\tgit tag DEF_B &&\n      +\n     -+\tgit rev-parse DEF_B >.git-blame-ignore-revs\n     ++\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n     ++\tgit add .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"add .git-blame-ignore-revs\"\n      +'\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs is used by default' '\n     ++test_expect_success 'default HEAD:.git-blame-ignore-revs is used by default' '\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_A >expect &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs respected by git annotate' '\n     ++test_expect_success 'default HEAD:.git-blame-ignore-revs respected by git annotate' '\n      +\tgit rev-parse --short DEF_A >expect_sha &&\n      +\tgit annotate def-file >actual &&\n      +\ttest_grep \"^$(cat expect_sha)\" actual\n      +'\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs works from subdirectory' '\n     ++test_expect_success 'default HEAD:.git-blame-ignore-revs works from subdirectory' '\n      +\tmkdir -p sub &&\n      +\t(\n      +\t\tcd sub &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\t)\n      +'\n      +\n     -+test_expect_success 'disable default .git-blame-ignore-revs with --no-ignore-revs-file' '\n     ++test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n     ++\ttest_when_finished \"rm -rf bare.git\" &&\n     ++\tgit clone --bare . bare.git &&\n     ++\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_A >expect &&\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are ignored' '\n     ++\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n     ++\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n     ++\tgit blame --line-porcelain def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_A >expect &&\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --no-ignore-revs-file' '\n      +\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'disable default .git-blame-ignore-revs with --ignore-revs-file \"\"' '\n     ++test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --ignore-revs-file \"\"' '\n      +\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'disable default .git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n     ++test_expect_success 'disable default HEAD:.git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n      +\ttest_config blame.ignoreRevsFile \"\" &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs handles comments and whitespace' '\n     -+\ttest_when_finished \"git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n     ++test_expect_success 'default HEAD:.git-blame-ignore-revs handles comments and whitespace' '\n     ++\trev_def_b=$(git rev-parse DEF_B) &&\n      +\t{\n      +\t\techo \"# Leading comment\" &&\n      +\t\techo \"\" &&\n     -+\t\techo \"   $(git rev-parse DEF_B)   \" &&\n     ++\t\techo \"   $rev_def_b   # inline comment\" &&\n      +\t\techo \"# Trailing comment\"\n      +\t} >.git-blame-ignore-revs &&\n     ++\tgit add .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_A >expect &&\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'empty default .git-blame-ignore-revs is harmless' '\n     -+\ttest_when_finished \"git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n     ++test_expect_success 'empty default HEAD:.git-blame-ignore-revs is harmless' '\n      +\t: >.git-blame-ignore-revs &&\n     -+\tgit blame def-file\n     ++\tgit add .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n     ++\tgit blame --line-porcelain def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_B >expect &&\n     ++\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success SYMLINKS 'symlink .git-blame-ignore-revs is ignored' '\n     -+\ttest_when_finished \"rm -f target_file .git-blame-ignore-revs && git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n     ++test_expect_success 'committed symlink .git-blame-ignore-revs in HEAD is ignored' '\n     ++\tgit rm -f .git-blame-ignore-revs &&\n      +\tgit rev-parse DEF_B >target_file &&\n     -+\tln -sf target_file .git-blame-ignore-revs &&\n     ++\ttest_ln_s_add target_file .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'malformed default .git-blame-ignore-revs fails but can be bypassed' '\n     -+\ttest_when_finished \"git rev-parse DEF_B >.git-blame-ignore-revs\" &&\n     ++test_expect_success 'malformed default HEAD:.git-blame-ignore-revs fails but can be bypassed' '\n     ++\tgit rm -f .git-blame-ignore-revs &&\n      +\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n     ++\tgit add .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n      +\ttest_must_fail git blame def-file &&\n      +\tgit blame --no-ignore-revs-file def-file &&\n     -+\tgit blame --ignore-revs-file \"\" def-file\n     -+'\n     ++\tgit blame --ignore-revs-file \"\" def-file &&\n     ++\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs deduplicated when also set in config' '\n     -+\ttest_config blame.ignoreRevsFile .git-blame-ignore-revs &&\n     -+\tgit blame --line-porcelain def-file >blame_raw &&\n     -+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     -+\tgit rev-parse DEF_A >expect &&\n     -+\ttest_cmp expect actual\n     ++\trev_def_b=$(git rev-parse DEF_B) &&\n     ++\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n     ++\tgit add .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n     ++\ttest_must_fail git blame def-file 2>err &&\n     ++\ttest_grep \"invalid object name:\" err\n      +'\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n     ++test_expect_success 'default HEAD:.git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n     ++\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n      +\ttest_write_lines line1-modified line2-c >def-file &&\n     -+\tgit add def-file &&\n     ++\tgit add .git-blame-ignore-revs def-file &&\n      +\ttest_tick &&\n      +\tgit commit -m C &&\n      +\tgit tag DEF_C &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success ignore_merge '\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'default .git-blame-ignore-revs ignored in bare repo' '\n     -+\tgit clone --bare . bare.git &&\n     -+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n     -+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n     -+\tgit rev-parse DEF_C >expect &&\n     -+\ttest_cmp expect actual\n     -+'\n     -+\n     -+test_expect_success 'blame works when .git-blame-ignore-revs does not exist' '\n     -+\trm -f .git-blame-ignore-revs &&\n     ++test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n     ++\tgit rm -f .git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n     ++\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n\n-- \ngitgitgadget\n\n"},{"id":"554540","messageId":"2e12486c0d5dd8b94393b08413a85a8d47f86edd.1791493644.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v2.git.1791493644.gitgitgadget@gmail.com","subject":"[PATCH v2 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-08T21:07:23Z","receivedAt":"2026-10-08T21:07:23Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\nCurrently, blame.ignoreRevsFile and --ignore-revs-file only read paths\nexplicitly configured by the user, which cannot point to an\nattacker-controlled file under Git's threat model. An upcoming commit\nwill teach git-blame(1) and git-annotate(1) to automatically read the\nHEAD:.git-blame-ignore-revs blob by default if it exists, exposing the\nignore-revs parser (oidset_parse_file_carefully() in oidset.c) and its\ntag-peeling callback (peel_to_commit_oid() in builtin/blame.c) to\nupstream-controlled content at a well-known path.\n\nHarden both code paths before enabling the default blob:\n\n- In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n  next newline and records the full line length in sb.len, including\n  any embedded NUL bytes. However, strchr(sb.buf, '#') and\n  parse_oid_hex_algop(sb.buf, &oid, &p, algop) treat sb.buf as a\n  NUL-terminated string. If a line contains an embedded NUL byte after\n  a valid object name (such as \"<oid>\\0garbage\" or \"<oid>\\0# comment\"),\n  *p is '\\0' and trailing bytes on the line are silently ignored.\n  Reject any line containing an embedded NUL byte via memchr() before\n  stripping comments and whitespace.\n- In peel_to_commit_oid(), odb_read_object_info() is called without\n  OBJECT_INFO_SKIP_FETCH_OBJECT or OBJECT_INFO_QUICK, and deref_tag()\n  calls parse_object() on tag targets without checking whether the\n  target object exists locally first. In a partial clone, any missing\n  commit OID or tag target listed in the ignore-revs file would trigger\n  lazy promisor fetches and pack directory rescans during git-blame(1).\n  Use odb_read_object_info_extended() with OBJECT_INFO_LOOKUP_REPLACE |\n  OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK and peel OBJ_TAG\n  objects one layer per iteration, verifying that each target object\n  exists locally and matches the tag's declared type before parsing it.\n\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n builtin/blame.c              | 20 +++++++++++++++++--\n oidset.c                     |  3 +++\n t/t8013-blame-ignore-revs.sh | 38 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 59 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 48d5251c6d..6741a7b9df 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -911,21 +911,37 @@ static int is_a_rev(const char *name)\n static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n {\n \tstruct repository *r = ((struct blame_scoreboard *)cbdata)->repo;\n+\tenum object_type expected_type = OBJ_ANY;\n \tstruct object_id oid;\n \n \toidcpy(&oid, oid_ret);\n \twhile (1) {\n+\t\tunsigned flags = OBJECT_INFO_LOOKUP_REPLACE |\n+\t\t\t\t OBJECT_INFO_SKIP_FETCH_OBJECT |\n+\t\t\t\t OBJECT_INFO_QUICK;\n+\t\tstruct object_info oi = OBJECT_INFO_INIT;\n+\t\tenum object_type kind;\n \t\tstruct object *obj;\n-\t\tint kind = odb_read_object_info(r->objects, &oid, NULL);\n+\n+\t\toi.typep = &kind;\n+\t\tif (odb_read_object_info_extended(r->objects, &oid, &oi,\n+\t\t\t\t\t\t  flags) < 0)\n+\t\t\treturn -1;\n+\t\tif (expected_type != OBJ_ANY && kind != expected_type)\n+\t\t\treturn -1;\n \t\tif (kind == OBJ_COMMIT) {\n \t\t\toidcpy(oid_ret, &oid);\n \t\t\treturn 0;\n \t\t}\n \t\tif (kind != OBJ_TAG)\n \t\t\treturn -1;\n-\t\tobj = deref_tag(r, parse_object(r, &oid), NULL, 0);\n+\t\tobj = parse_object(r, &oid);\n+\t\tif (!obj || obj->type != OBJ_TAG)\n+\t\t\treturn -1;\n+\t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\treturn -1;\n+\t\texpected_type = obj->type;\n \t\toidcpy(&oid, &obj->oid);\n \t}\n }\ndiff --git a/oidset.c b/oidset.c\nindex c8ff0b385c..90d39204d3 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -85,6 +85,9 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\tconst char *p;\n \t\tconst char *name;\n \n+\t\tif (memchr(sb.buf, '\\0', sb.len))\n+\t\t\tdie(\"invalid object name: %s\", sb.buf);\n+\n \t\t/*\n \t\t * Allow trailing comments, leading whitespace\n \t\t * (including before commits), and empty or whitespace\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex cace00ae8d..70fe509a64 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -327,4 +327,42 @@ test_expect_success ignore_merge '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'ignore-revs-file rejects lines with embedded NUL bytes' '\n+\trev_b=$(git rev-parse B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_b\" | q_to_nul >ignore_nul &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul 2>err &&\n+\ttest_grep \"invalid object name:\" err &&\n+\n+\tprintf \"%sQ# comment\\n\" \"$rev_b\" | q_to_nul >ignore_nul_comment &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul_comment 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'ignore-revs-file peels chained tags and skips missing tag targets' '\n+\ttest_write_lines BB L2-modified L3 L4 L5 L6 L7 L8 CC >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m D &&\n+\tgit tag -a -m \"tag 1\" D_TAG1 HEAD &&\n+\tgit tag -a -m \"tag 2\" D_TAG2 D_TAG1 &&\n+\tgit rev-parse D_TAG2 >ignore_tag_chain &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_tag_chain >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\ttest_config extensions.partialClone origin &&\n+\ttest_config remote.origin.promisor true &&\n+\ttest_config remote.origin.url /nonexistent &&\n+\tmissing_oid=$(test_oid deadbeef) &&\n+\tbad_tag=$(printf \"object %s\\ntype commit\\ntag bad-tag\\ntagger T <t@example.com> 0 +0000\\n\\nmsg\\n\" \"$missing_oid\" |\n+\t\tgit hash-object -t tag -w --stdin) &&\n+\ttest_write_lines \"$missing_oid\" \"$bad_tag\" >ignore_bad_tag &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_bad_tag >blame_raw 2>err &&\n+\ttest_must_be_empty err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse HEAD >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n\n"},{"id":"554541","messageId":"35e303d65bc378e733b1e9e8d6908a829352e857.1791493644.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v2.git.1791493644.gitgitgadget@gmail.com","subject":"[PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-08T21:07:24Z","receivedAt":"2026-10-08T21:07:24Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\ngit-blame(1) can ignore a list of commits specified via\n--ignore-revs-file or the blame.ignoreRevsFile configuration option.\nThis is useful for skipping uninteresting revisions such as tree-wide\nformatting changes, large-scale refactors, and code modernizations that\nwould otherwise obscure genuine historical authorship.\n\nWhen revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\nblame.ignoreRevsFile config option\", 2019-10-18), it intentionally\navoided adopting a default ignore file. At the time, the capability was\nnew and unproven, so avoiding unrequested filesystem I/O or unexpected\nattribution shifts took priority over a project-wide default.\nRequiring explicit opt-in per clone was therefore the prudent design.\n\nSince then, maintaining a .git-blame-ignore-revs file in the repository\nroot has become the de facto standard across the Git ecosystem, adopted\nby major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\nsource projects (such as Chromium and LLVM). As a consequence,\ndevelopers frequently encounter a jarring mismatch: web interfaces\nseamlessly ignore formatting commits, but local git-blame(1) and\ngit-annotate(1) runs do not, unless each user manually configures\nblame.ignoreRevsFile for every local checkout.\n\nTeach git-blame(1) and git-annotate(1) to automatically add the\nHEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\nin the list of ignore-revs files in both bare and non-bare\nrepositories. Reading the committed blob from HEAD rather than the\nworking tree ensures that local runs match hosting platforms even when\nan untracked .git-blame-ignore-revs file is present or a tracked one\nhas uncommitted local changes.\n\nTo ensure consistent precedence and override semantics:\n- The default HEAD:.git-blame-ignore-revs entry is added before reading\n  configuration and CLI options, preserving user and repository config\n  overrides.\n- In git_blame_config(), blame.ignoreRevsFile entries are appended via\n  string_list_append() rather than inserted in sorted order via\n  string_list_insert() so that configuration entries preserve their\n  order relative to the initial default entry.\n- The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n  get_oid_with_context(). Its mode is checked with S_ISREG() before\n  reading the object so that non-regular tree entries (such as a\n  committed symbolic link whose blob stores a target path rather than\n  revision IDs, a subdirectory, or a gitlink) are skipped instead of\n  being read and rejected as malformed object names. The blob is parsed\n  in memory via a new oidset_parse_buffer_carefully() helper in\n  oidset.c that shares line parsing with oidset_parse_file_carefully().\n- In build_ignorelist(), ignore-revs entries are processed starting\n  after the last empty string entry. This ensures setting\n  blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n  --no-ignore-revs-file cleanly discards the default blob without\n  attempting to read or parse it, allowing users to bypass a malformed\n  default blob.\n\nUpdate documentation in blame-options.adoc and config/blame.adoc, and\nadd comprehensive test coverage in t8013 for the default blob lookup,\nsubdirectory invocations, bare repositories, uncommitted and untracked\nworking-tree files, CLI and config overrides, committed symlink\nentries, and comments and whitespace handling.\n\nBased-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\nHelped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\nHelped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n Documentation/blame-options.adoc |   8 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  45 +++++++-\n oidset.c                         |  84 +++++++++-----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 182 +++++++++++++++++++++++++++++++\n 6 files changed, 301 insertions(+), 36 deletions(-)\n\ndiff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\nindex 1ae1222b6b..8d59dcc8f3 100644\n--- a/Documentation/blame-options.adoc\n+++ b/Documentation/blame-options.adoc\n@@ -132,9 +132,11 @@ take effect.\n `--ignore-revs-file <file>`::\n \tIgnore revisions listed in _<file>_, which must be in the same format as an\n \t`fsck.skipList`.  This option may be repeated, and these files will be\n-\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n-\toption.  An empty file name, `\"\"`, will clear the list of revs from\n-\tpreviously processed files.\n+\tprocessed after the default `HEAD:.git-blame-ignore-revs` blob (if it\n+\texists) and any files specified with the `blame.ignoreRevsFile` config\n+\toption.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will clear\n+\tthe list of revs from previously processed files, including the default\n+\t`HEAD:.git-blame-ignore-revs` blob.\n \n `--color-lines`::\n \tColor line annotations in the default format differently if they come from\ndiff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\nindex 4d047c1790..153d4ab524 100644\n--- a/Documentation/config/blame.adoc\n+++ b/Documentation/config/blame.adoc\n@@ -23,9 +23,12 @@ blame.showRoot::\n blame.ignoreRevsFile::\n \tIgnore revisions listed in the file, one unabbreviated object name per\n \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n-\t`#` are ignored.  This option may be repeated multiple times.  Empty\n-\tfile names will reset the list of ignored revisions.  This option will\n-\tbe handled before the command line option `--ignore-revs-file`.\n+\t`#` are ignored.  If the `HEAD:.git-blame-ignore-revs` blob exists, it\n+\tis added as the initial element in the list of ignore-revs files.\n+\tOther files listed in the configuration are also used, but an empty\n+\telement makes all elements that appeared before in the list forgotten.\n+\tThis option will be handled before the command line option\n+\t`--ignore-revs-file`.\n \n blame.markUnblamableLines::\n \tMark lines that were changed by an ignored revision that we could not\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 6741a7b9df..a730ee87ea 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -769,7 +769,7 @@ static int git_blame_config(const char *var, const char *value,\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tif (str)\n-\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n+\t\t\tstring_list_append(&ignore_revs_file_list, str);\n \t\tfree(str);\n \t\treturn 0;\n \t}\n@@ -946,17 +946,52 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n \t}\n }\n \n+static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *name)\n+{\n+\tstruct object_context oc;\n+\tstruct object_id oid;\n+\tenum object_type type;\n+\tsize_t size;\n+\tchar *buf;\n+\n+\tif (get_oid_with_context(the_repository, name, GET_OID_QUIETLY,\n+\t\t\t\t &oid, &oc))\n+\t\tgoto out;\n+\tif (!S_ISREG(oc.mode))\n+\t\tgoto out;\n+\n+\tbuf = odb_read_object(the_repository->objects, &oid, &type, &size);\n+\tif (!buf)\n+\t\tgoto out;\n+\tif (type == OBJ_BLOB)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      the_repository->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\tfree(buf);\n+\n+out:\n+\tobject_context_release(&oc);\n+}\n+\n static void build_ignorelist(struct blame_scoreboard *sb,\n \t\t\t     struct string_list *ignore_revs_file_list,\n \t\t\t     struct string_list *ignore_rev_list)\n {\n \tstruct string_list_item *i;\n \tstruct object_id oid;\n+\tsize_t start_idx = 0, idx;\n+\n+\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tif (!*ignore_revs_file_list->items[idx].string)\n+\t\t\tstart_idx = idx + 1;\n+\t}\n \n \toidset_init(&sb->ignore_list, 0);\n-\tfor_each_string_list_item(i, ignore_revs_file_list) {\n-\t\tif (!strcmp(i->string, \"\"))\n-\t\t\toidset_clear(&sb->ignore_list);\n+\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n+\t\ti = &ignore_revs_file_list->items[idx];\n+\t\tif (i->util)\n+\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n \t\telse\n \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n \t\t\t\t\t\t    the_repository->hash_algo,\n@@ -1036,6 +1071,8 @@ int cmd_blame(int argc,\n \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n \n \tsetup_default_color_by_age();\n+\tstring_list_append(&ignore_revs_file_list,\n+\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n \trepo_config(the_repository, git_blame_config, &output_option);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \trevs.date_mode = blame_date_mode;\ndiff --git a/oidset.c b/oidset.c\nindex 90d39204d3..8469d03b9b 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n }\n \n+static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n+\t\t\t      const struct git_hash_algo *algop,\n+\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tconst char *p;\n+\tconst char *name;\n+\tstruct object_id oid;\n+\n+\tif (memchr(sb->buf, '\\0', sb->len))\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\n+\t/*\n+\t * Allow trailing comments, leading whitespace\n+\t * (including before commits), and empty or whitespace\n+\t * only lines.\n+\t */\n+\tname = strchr(sb->buf, '#');\n+\tif (name)\n+\t\tstrbuf_setlen(sb, name - sb->buf);\n+\tstrbuf_trim(sb);\n+\tif (!sb->len)\n+\t\treturn;\n+\n+\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\tif (fn && fn(&oid, cbdata))\n+\t\treturn;\n+\toidset_insert(set, &oid);\n+}\n+\n void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n {\n \tFILE *fp;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tstruct object_id oid;\n \n \tfp = fopen(path, \"r\");\n \tif (!fp)\n \t\tdie(\"could not open object name list: %s\", path);\n-\twhile (!strbuf_getline(&sb, fp)) {\n-\t\tconst char *p;\n-\t\tconst char *name;\n-\n-\t\tif (memchr(sb.buf, '\\0', sb.len))\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\n-\t\t/*\n-\t\t * Allow trailing comments, leading whitespace\n-\t\t * (including before commits), and empty or whitespace\n-\t\t * only lines.\n-\t\t */\n-\t\tname = strchr(sb.buf, '#');\n-\t\tif (name)\n-\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n-\t\tstrbuf_trim(&sb);\n-\t\tif (!sb.len)\n-\t\t\tcontinue;\n-\n-\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\t\tif (fn && fn(&oid, cbdata))\n-\t\t\tcontinue;\n-\t\toidset_insert(set, &oid);\n-\t}\n+\twhile (!strbuf_getline(&sb, fp))\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n \tif (ferror(fp))\n \t\tdie_errno(\"Could not read '%s'\", path);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n }\n+\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tconst char *p = buf, *end;\n+\n+\tif (!size)\n+\t\treturn;\n+\tend = buf + size;\n+\n+\twhile (p < end) {\n+\t\tconst char *nl = memchr(p, '\\n', end - p);\n+\t\tsize_t len = (nl ? nl : end) - p;\n+\n+\t\tstrbuf_reset(&sb);\n+\t\tif (len && p[len - 1] == '\\r')\n+\t\t\tlen--;\n+\t\tstrbuf_add(&sb, p, len);\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n+\t\tp = nl ? nl + 1 : end;\n+\t}\n+\tstrbuf_release(&sb);\n+}\ndiff --git a/oidset.h b/oidset.h\nindex e0f1a6ff4f..667c390842 100644\n--- a/oidset.h\n+++ b/oidset.h\n@@ -98,6 +98,15 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n \n+/*\n+ * Similar to oidset_parse_file_carefully(), but parses lines from an\n+ * in-memory buffer of 'size' bytes.\n+ */\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n+\n struct oidset_iter {\n \tconst kh_oid_set_t *set;\n \tkhiter_t iter;\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex 70fe509a64..3e1b5291aa 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -365,4 +365,186 @@ test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n \ttest_cmp expect actual\n '\n \n+# Tests for default HEAD:.git-blame-ignore-revs blob\n+test_expect_success 'setup default HEAD:.git-blame-ignore-revs' '\n+\tgit checkout -b default-file-branch &&\n+\ttest_write_lines line1 line2 >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default base\" &&\n+\tgit tag DEF_A &&\n+\n+\ttest_write_lines line1-modified line2-modified >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default mod\" &&\n+\tgit tag DEF_B &&\n+\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"add .git-blame-ignore-revs\"\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs is used by default' '\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected by git annotate' '\n+\tgit rev-parse --short DEF_A >expect_sha &&\n+\tgit annotate def-file >actual &&\n+\ttest_grep \"^$(cat expect_sha)\" actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs works from subdirectory' '\n+\tmkdir -p sub &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n+\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\t\tgit rev-parse DEF_A >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\tgit clone --bare . bare.git &&\n+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are ignored' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --no-ignore-revs-file' '\n+\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --ignore-revs-file \"\"' '\n+\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n+\ttest_config blame.ignoreRevsFile \"\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs handles comments and whitespace' '\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\t{\n+\t\techo \"# Leading comment\" &&\n+\t\techo \"\" &&\n+\t\techo \"   $rev_def_b   # inline comment\" &&\n+\t\techo \"# Trailing comment\"\n+\t} >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'empty default HEAD:.git-blame-ignore-revs is harmless' '\n+\t: >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'committed symlink .git-blame-ignore-revs in HEAD is ignored' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\tgit rev-parse DEF_B >target_file &&\n+\ttest_ln_s_add target_file .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'malformed default HEAD:.git-blame-ignore-revs fails but can be bypassed' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file &&\n+\tgit blame --no-ignore-revs-file def-file &&\n+\tgit blame --ignore-revs-file \"\" def-file &&\n+\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n+\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\ttest_write_lines line1-modified line2-c >def-file &&\n+\tgit add .git-blame-ignore-revs def-file &&\n+\ttest_tick &&\n+\tgit commit -m C &&\n+\tgit tag DEF_C &&\n+\tgit rev-parse DEF_C >custom_ignore &&\n+\ttest_config blame.ignoreRevsFile custom_ignore &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"554550","messageId":"xmqqjynrwjg0.fsf@gitster.g","threadId":"66313","inReplyTo":"2e12486c0d5dd8b94393b08413a85a8d47f86edd.1791493644.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-09T05:07:27Z","receivedAt":"2026-10-09T05:07:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ravi Mistry via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> - In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n>   next newline and records the full line length in sb.len, including\n>   any embedded NUL bytes. However, strchr(sb.buf, '#') and\n>   parse_oid_hex_algop(sb.buf, &oid, &p, algop) treat sb.buf as a\n>   NUL-terminated string. If a line contains an embedded NUL byte after\n>   a valid object name (such as \"<oid>\\0garbage\" or \"<oid>\\0# comment\"),\n>   *p is '\\0' and trailing bytes on the line are silently ignored.\n>   Reject any line containing an embedded NUL byte via memchr() before\n>   stripping comments and whitespace.\n\nMaybe I am slow, but I do not immediately see why ignoring\neverything after the first NUL is a problem.  A call to\nstrbuf_trim() is ineffective at trimming whitespace that appears\nimmediately before such a NUL.  For example, while\n\n    cf9bdb1...f6092d # comment LF\n\nwould feed the leading 'cf9bdb1...f6092d' part (after stripping\nwhitespace before '#') to parse_oid_hex_algop(), this\n\n    cf9bdb1...f6092d NUL comment LF\n\nwould keep the whitespace after '92d' and cause the parsing to\nfail.  I do not see any security implications here.\n\nOn the other hand ...\n\n> - In peel_to_commit_oid(), odb_read_object_info() is called without\n>   OBJECT_INFO_SKIP_FETCH_OBJECT or OBJECT_INFO_QUICK, and deref_tag()\n>   calls parse_object() on tag targets without checking whether the\n>   target object exists locally first. In a partial clone, any missing\n>   commit OID or tag target listed in the ignore-revs file would trigger\n>   lazy promisor fetches and pack directory rescans during git-blame(1).\n>   Use odb_read_object_info_extended() with OBJECT_INFO_LOOKUP_REPLACE |\n>   OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK and peel OBJ_TAG\n>   objects one layer per iteration, verifying that each target object\n>   exists locally and matches the tag's declared type before parsing it.\n\n... this may be a very reasonable thing to do, I would think.  In a\nshallow clone, if we are not auto-deepening the shallow boundary\nduring a \"git blame\" session, we have no reason to lazy fetch\nentries in the ignore file that are older than the shallow boundary.\n\n> diff --git a/oidset.c b/oidset.c\n> index c8ff0b385c..90d39204d3 100644\n> --- a/oidset.c\n> +++ b/oidset.c\n> @@ -85,6 +85,9 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n>  \t\tconst char *p;\n>  \t\tconst char *name;\n>  \n> +\t\tif (memchr(sb.buf, '\\0', sb.len))\n> +\t\t\tdie(\"invalid object name: %s\", sb.buf);\n\nA file with such an entry is rejected and the entire operation is\naborted as suspected attack attempt, which feels like striking the\nbalance between usability and security at a wrong place.\n\nBut a line with broken object name already is rejected with \"die()\"\nwith the existing code, so it may be OK.\n\n> diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\n> index cace00ae8d..70fe509a64 100755\n> --- a/t/t8013-blame-ignore-revs.sh\n> +++ b/t/t8013-blame-ignore-revs.sh\n> @@ -327,4 +327,42 @@ test_expect_success ignore_merge '\n>  \ttest_cmp expect actual\n>  '\n>  \n> +test_expect_success 'ignore-revs-file rejects lines with embedded NUL bytes' '\n> +\trev_b=$(git rev-parse B) &&\n> +\tprintf \"%sQgarbage\\n\" \"$rev_b\" | q_to_nul >ignore_nul &&\n> +\ttest_must_fail git blame file --ignore-revs-file ignore_nul 2>err &&\n> +\ttest_grep \"invalid object name:\" err &&\n> +\n> +\tprintf \"%sQ# comment\\n\" \"$rev_b\" | q_to_nul >ignore_nul_comment &&\n> +\ttest_must_fail git blame file --ignore-revs-file ignore_nul_comment 2>err &&\n> +\ttest_grep \"invalid object name:\" err\n> +'\n> +\n> +test_expect_success 'ignore-revs-file peels chained tags and skips missing tag targets' '\n> +\ttest_write_lines BB L2-modified L3 L4 L5 L6 L7 L8 CC >file &&\n> +\tgit add file &&\n> +\ttest_tick &&\n> +\tgit commit -m D &&\n> +\tgit tag -a -m \"tag 1\" D_TAG1 HEAD &&\n> +\tgit tag -a -m \"tag 2\" D_TAG2 D_TAG1 &&\n> +\tgit rev-parse D_TAG2 >ignore_tag_chain &&\n> +\tgit blame --line-porcelain file --ignore-revs-file ignore_tag_chain >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse A >expect &&\n> +\ttest_cmp expect actual &&\n> +\n> +\ttest_config extensions.partialClone origin &&\n> +\ttest_config remote.origin.promisor true &&\n> +\ttest_config remote.origin.url /nonexistent &&\n> +\tmissing_oid=$(test_oid deadbeef) &&\n> +\tbad_tag=$(printf \"object %s\\ntype commit\\ntag bad-tag\\ntagger T <t@example.com> 0 +0000\\n\\nmsg\\n\" \"$missing_oid\" |\n> +\t\tgit hash-object -t tag -w --stdin) &&\n> +\ttest_write_lines \"$missing_oid\" \"$bad_tag\" >ignore_bad_tag &&\n> +\tgit blame --line-porcelain file --ignore-revs-file ignore_bad_tag >blame_raw 2>err &&\n> +\ttest_must_be_empty err &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse HEAD >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n>  test_done\n\n"},{"id":"554655","messageId":"xmqqbj92ochm.fsf@gitster.g","threadId":"66313","inReplyTo":"35e303d65bc378e733b1e9e8d6908a829352e857.1791493644.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-09T20:17:09Z","receivedAt":"2026-10-09T20:17:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ravi Mistry via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Ravi Mistry <rmistry@google.com>\n>\n> git-blame(1) can ignore a list of commits specified via\n> --ignore-revs-file or the blame.ignoreRevsFile configuration option.\n> This is useful for skipping uninteresting revisions such as tree-wide\n> formatting changes, large-scale refactors, and code modernizations that\n> would otherwise obscure genuine historical authorship.\n>\n> When revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\n> blame.ignoreRevsFile config option\", 2019-10-18), it intentionally\n> avoided adopting a default ignore file. At the time, the capability was\n> new and unproven, so avoiding unrequested filesystem I/O or unexpected\n> attribution shifts took priority over a project-wide default.\n> Requiring explicit opt-in per clone was therefore the prudent design.\n>\n> Since then, maintaining a .git-blame-ignore-revs file in the repository\n> root has become the de facto standard across the Git ecosystem, adopted\n> by major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\n> source projects (such as Chromium and LLVM). As a consequence,\n> developers frequently encounter a jarring mismatch: web interfaces\n> seamlessly ignore formatting commits, but local git-blame(1) and\n> git-annotate(1) runs do not, unless each user manually configures\n> blame.ignoreRevsFile for every local checkout.\n>\n> Teach git-blame(1) and git-annotate(1) to automatically add the\n> HEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\n> in the list of ignore-revs files in both bare and non-bare\n> repositories. Reading the committed blob from HEAD rather than the\n> working tree ensures that local runs match hosting platforms even when\n> an untracked .git-blame-ignore-revs file is present or a tracked one\n> has uncommitted local changes.\n>\n> To ensure consistent precedence and override semantics:\n> - The default HEAD:.git-blame-ignore-revs entry is added before reading\n>   configuration and CLI options, preserving user and repository config\n>   overrides.\n> - In git_blame_config(), blame.ignoreRevsFile entries are appended via\n>   string_list_append() rather than inserted in sorted order via\n>   string_list_insert() so that configuration entries preserve their\n>   order relative to the initial default entry.\n> - The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n>   get_oid_with_context(). Its mode is checked with S_ISREG() before\n>   reading the object so that non-regular tree entries (such as a\n>   committed symbolic link whose blob stores a target path rather than\n>   revision IDs, a subdirectory, or a gitlink) are skipped instead of\n>   being read and rejected as malformed object names. The blob is parsed\n>   in memory via a new oidset_parse_buffer_carefully() helper in\n>   oidset.c that shares line parsing with oidset_parse_file_carefully().\n> - In build_ignorelist(), ignore-revs entries are processed starting\n>   after the last empty string entry. This ensures setting\n>   blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n>   --no-ignore-revs-file cleanly discards the default blob without\n>   attempting to read or parse it, allowing users to bypass a malformed\n>   default blob.\n>\n> Update documentation in blame-options.adoc and config/blame.adoc, and\n> add comprehensive test coverage in t8013 for the default blob lookup,\n> subdirectory invocations, bare repositories, uncommitted and untracked\n> working-tree files, CLI and config overrides, committed symlink\n> entries, and comments and whitespace handling.\n>\n> Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\n> Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n> Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n\nThese Helped-by: drew my attention as none of these folks commented\non v1 of this series.  I do see they have helped the original series\n<pull.1809.v2.git.1728707867.gitgitgadget@gmail.com>, but it is not\nclear how much their inputs have survivied to this version.\n\nThey are all CC'ed so they can give their Acked-by: or Reviewed-by: \non this round if they want.\n\n\n[...]\n\n> diff --git a/builtin/blame.c b/builtin/blame.c\n> index 6741a7b9df..a730ee87ea 100644\n> --- a/builtin/blame.c\n> +++ b/builtin/blame.c\n> @@ -769,7 +769,7 @@ static int git_blame_config(const char *var, const char *value,\n>  \t\tif (ret)\n>  \t\t\treturn ret;\n>  \t\tif (str)\n> -\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n> +\t\t\tstring_list_append(&ignore_revs_file_list, str);\n>  \t\tfree(str);\n>  \t\treturn 0;\n>  \t}\n\nGood, and the log message is clear why we make this change.\n\n> @@ -946,17 +946,52 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n>  \t}\n>  }\n>  \n> +static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n> +\t\t\t\t\t   const char *name)\n> +{\n> +\tstruct object_context oc;\n> +\tstruct object_id oid;\n> +\tenum object_type type;\n> +\tsize_t size;\n> +\tchar *buf;\n> +\n> +\tif (get_oid_with_context(the_repository, name, GET_OID_QUIETLY,\n> +\t\t\t\t &oid, &oc))\n> +\t\tgoto out;\n> +\tif (!S_ISREG(oc.mode))\n> +\t\tgoto out;\n> +\n> +\tbuf = odb_read_object(the_repository->objects, &oid, &type, &size);\n> +\tif (!buf)\n> +\t\tgoto out;\n> +\tif (type == OBJ_BLOB)\n> +\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n> +\t\t\t\t\t      the_repository->hash_algo,\n> +\t\t\t\t\t      peel_to_commit_oid, sb);\n> +\tfree(buf);\n> +\n> +out:\n> +\tobject_context_release(&oc);\n> +}\n\nOK.\n\n>  static void build_ignorelist(struct blame_scoreboard *sb,\n>  \t\t\t     struct string_list *ignore_revs_file_list,\n>  \t\t\t     struct string_list *ignore_rev_list)\n>  {\n>  \tstruct string_list_item *i;\n>  \tstruct object_id oid;\n> +\tsize_t start_idx = 0, idx;\n> +\n> +\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n> +\t\tif (!*ignore_revs_file_list->items[idx].string)\n> +\t\t\tstart_idx = idx + 1;\n> +\t}\n\nOK, we make two passes, and during the first pass, we find where the\nlast \"empty\" entry that signals \"forget everything you have seen\" is.\n\n>  \toidset_init(&sb->ignore_list, 0);\n> -\tfor_each_string_list_item(i, ignore_revs_file_list) {\n> -\t\tif (!strcmp(i->string, \"\"))\n> -\t\t\toidset_clear(&sb->ignore_list);\n> +\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n\nAnd we scan starting from there.  Very clean.\n\n> +\t\ti = &ignore_revs_file_list->items[idx];\n> +\t\tif (i->util)\n> +\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n>  \t\telse\n>  \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n>  \t\t\t\t\t\t    the_repository->hash_algo,\n> @@ -1036,6 +1071,8 @@ int cmd_blame(int argc,\n>  \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n>  \n>  \tsetup_default_color_by_age();\n> +\tstring_list_append(&ignore_revs_file_list,\n> +\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n\nCute.  This takes advantage of the fact that everybody else just\nappends to the string_list without populating the .util member.\n\n> diff --git a/oidset.c b/oidset.c\n> index 90d39204d3..8469d03b9b 100644\n> --- a/oidset.c\n> +++ b/oidset.c\n> @@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n>  \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n>  }\n>  \n> +static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n> +\t\t\t      const struct git_hash_algo *algop,\n> +\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n> +{\n> +\tconst char *p;\n> +\tconst char *name;\n> +\tstruct object_id oid;\n> +\n> +\tif (memchr(sb->buf, '\\0', sb->len))\n> +\t\tdie(\"invalid object name: %s\", sb->buf);\n> +\n> +\t/*\n> +\t * Allow trailing comments, leading whitespace\n> +\t * (including before commits), and empty or whitespace\n> +\t * only lines.\n> +\t */\n> +\tname = strchr(sb->buf, '#');\n> +\tif (name)\n> +\t\tstrbuf_setlen(sb, name - sb->buf);\n> +\tstrbuf_trim(sb);\n> +\tif (!sb->len)\n> +\t\treturn;\n> +\n> +\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n> +\t\tdie(\"invalid object name: %s\", sb->buf);\n> +\tif (fn && fn(&oid, cbdata))\n> +\t\treturn;\n> +\toidset_insert(set, &oid);\n> +}\n> +\n>  void oidset_parse_file_carefully(struct oidset *set, const char *path,\n>  \t\t\t\t const struct git_hash_algo *algop,\n>  \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n>  {\n>  \tFILE *fp;\n>  \tstruct strbuf sb = STRBUF_INIT;\n> -\tstruct object_id oid;\n>  \n>  \tfp = fopen(path, \"r\");\n>  \tif (!fp)\n>  \t\tdie(\"could not open object name list: %s\", path);\n> -\twhile (!strbuf_getline(&sb, fp)) {\n> -\t\tconst char *p;\n> -\t\tconst char *name;\n> -\n> -\t\tif (memchr(sb.buf, '\\0', sb.len))\n> -\t\t\tdie(\"invalid object name: %s\", sb.buf);\n> -\n> -\t\t/*\n> -\t\t * Allow trailing comments, leading whitespace\n> -\t\t * (including before commits), and empty or whitespace\n> -\t\t * only lines.\n> -\t\t */\n> -\t\tname = strchr(sb.buf, '#');\n> -\t\tif (name)\n> -\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n> -\t\tstrbuf_trim(&sb);\n> -\t\tif (!sb.len)\n> -\t\t\tcontinue;\n> -\n> -\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n> -\t\t\tdie(\"invalid object name: %s\", sb.buf);\n> -\t\tif (fn && fn(&oid, cbdata))\n> -\t\t\tcontinue;\n> -\t\toidset_insert(set, &oid);\n> -\t}\n> +\twhile (!strbuf_getline(&sb, fp))\n> +\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n>  \tif (ferror(fp))\n>  \t\tdie_errno(\"Could not read '%s'\", path);\n>  \tfclose(fp);\n>  \tstrbuf_release(&sb);\n>  }\n\nShouldn't the above refactoring have been part of the previous step\ninstead?\n\nThanks.\n\n"},{"id":"554674","messageId":"CAPig+cTZsbYq3=9AnN+00EiWZPNhQiF2iG7gFdmEQqjFcGfM+Q@mail.gmail.com","threadId":"66313","inReplyTo":"xmqqbj92ochm.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2026-10-10T06:12:05Z","receivedAt":"2026-10-10T06:12:05Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Fri, Oct 9, 2026 at 4:17 PM Junio C Hamano <gitster@pobox.com> wrote:\n> \"Ravi Mistry via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n> > Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\n> > Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n> > Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n> > Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n>\n> These Helped-by: drew my attention as none of these folks commented\n> on v1 of this series.  I do see they have helped the original series\n> <pull.1809.v2.git.1728707867.gitgitgadget@gmail.com>, but it is not\n> clear how much their inputs have survivied to this version.\n>\n> They are all CC'ed so they can give their Acked-by: or Reviewed-by:\n> on this round if they want.\n\nFor what it's worth, having skimmed the old thread, if anything did\nsurvive from my reviews/recommendations, it would have been only\nextremely minor style fixups.\n\n"},{"id":"554699","messageId":"20261010184007.112258-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqbj92ochm.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-10T18:40:07Z","receivedAt":"2026-10-10T18:40:07Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> These Helped-by: drew my attention as none of these folks commented\n> on v1 of this series.  I do see they have helped the original series\n> <pull.1809.v2.git.1728707867.gitgitgadget@gmail.com>, but it is not\n> clear how much their inputs have survivied to this version.\n\nFrom that earlier thread, Phillip suggested explaining why commit\nae3f36dea1 originally avoided a default file, Kristoffer suggested the\nconfig override model and documenting --no-ignore-revs-file, and as\nEric noted, his comments were minor structural suggestions such as\nupdating the docs and placing the tests in t8013.\n\n> > +\twhile (!strbuf_getline(&sb, fp))\n> > +\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n> >  \tif (ferror(fp))\n> >  \t\tdie_errno(\"Could not read '%s'\", path);\n> >  \tfclose(fp);\n> >  \tstrbuf_release(&sb);\n> >  }\n>\n> Shouldn't the above refactoring have been part of the previous step\n> instead?\n\nI extracted parse_oidset_line() in patch 2/2 because that is where the\nsecond caller (oidset_parse_buffer_carefully()) was added, though\nextracting it in patch 1/2 would avoid touching that loop in both\npatches. Happy to move this into patch 1/2 if preferred.\n\nThanks!\n\n"},{"id":"554700","messageId":"20261010192515.212460-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqjynrwjg0.fsf@gitster.g","subject":"Re: [PATCH v2 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-10T19:25:15Z","receivedAt":"2026-10-10T19:25:15Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Maybe I am slow, but I do not immediately see why ignoring\n> everything after the first NUL is a problem.  A call to\n> strbuf_trim() is ineffective at trimming whitespace that appears\n> immediately before such a NUL.  For example, while\n>\n>     cf9bdb1...f6092d # comment LF\n>\n> would feed the leading 'cf9bdb1...f6092d' part (after stripping\n> whitespace before '#') to parse_oid_hex_algop(), this\n>\n>     cf9bdb1...f6092d NUL comment LF\n>\n> would keep the whitespace after '92d' and cause the parsing to\n> fail.  I do not see any security implications here.\n\n> > +\t\tif (memchr(sb.buf, '\\0', sb.len))\n> > +\t\t\tdie(\"invalid object name: %s\", sb.buf);\n>\n> A file with such an entry is rejected and the entire operation is\n> aborted as suspected attack attempt, which feels like striking the\n> balance between usability and security at a wrong place.\n>\n> But a line with broken object name already is rejected with \"die()\"\n> with the existing code, so it may be OK.\n\nAgreed, there is no security implication there. Rejecting\n\"<oid>\\0garbage\" (when there is no space before the NUL) was only for\nconsistency with how other non-comment trailing garbage on a line is\nrejected with die(). If we end up rerolling the series, I am happy to\ndrop the NUL check if you prefer.\n\nThanks!\n\n"},{"id":"554720","messageId":"xmqqtsmsdpxz.fsf@gitster.g","threadId":"66313","inReplyTo":"35e303d65bc378e733b1e9e8d6908a829352e857.1791493644.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-11T18:58:48Z","receivedAt":"2026-10-11T18:58:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ravi Mistry via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> +static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n> +\t\t\t\t\t   const char *name)\n> +{\n> +\tstruct object_context oc;\n> +\tstruct object_id oid;\n> +\tenum object_type type;\n> +\tsize_t size;\n> +\tchar *buf;\n> +\n> +\tif (get_oid_with_context(the_repository, name, GET_OID_QUIETLY,\n> +\t\t\t\t &oid, &oc))\n> +\t\tgoto out;\n> +\tif (!S_ISREG(oc.mode))\n> +\t\tgoto out;\n> +\n> +\tbuf = odb_read_object(the_repository->objects, &oid, &type, &size);\n> +\tif (!buf)\n> +\t\tgoto out;\n> +\tif (type == OBJ_BLOB)\n> +\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n> +\t\t\t\t\t      the_repository->hash_algo,\n> +\t\t\t\t\t      peel_to_commit_oid, sb);\n> +\tfree(buf);\n> +\n> +out:\n> +\tobject_context_release(&oc);\n> +}\n\nSince the scoreboard is passed around throughout the subsystem and\nhas a pointer to the repository it is working with, a new function\nlike this one does not have to add new references to the_repository.\n\nI do not think it is ultra urgent, but I suspect that many of\nexisting references in this file to the_repository happen in\nfunctions that take the scoreboard pointer, and they should be able\nto replace the_repository with sb->repo more or less mechanically.\n\n\n\n"},{"id":"554724","messageId":"pull.2224.v3.git.1791757294.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"[PATCH v3 0/2] blame: ignore revs in HEAD:.git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-11T22:21:31Z","receivedAt":"2026-10-11T22:21:31Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"This series teaches git-blame(1) and git-annotate(1) to automatically use\nthe HEAD:.git-blame-ignore-revs blob by default if it exists, so local runs\nmatch hosting platforms without requiring manual blame.ignoreRevsFile\nconfiguration in every clone. This restarts the stalled attempt in PR\nhttps://github.com/gitgitgadget/git/pull/1809\n(https://lore.kernel.org/git/pull.1809.v2.git.1728707867.gitgitgadget@gmail.com/)\nand addresses https://github.com/gitgitgadget/git/issues/1494.\n\nChanges since v2:\n\n * Patch 2/2 uses sb->repo instead of the_repository in\n   parse_default_ignore_revs_blob().\n\nChanges since v1:\n\n * Split the series into two commits.\n * Patch 1/2 hardens oidset_parse_file_carefully() in oidset.c and\n   peel_to_commit_oid() in builtin/blame.c before exposing them to\n   upstream-controlled content at a well-known path:\n   * Reject lines containing embedded NUL bytes via memchr() so trailing\n     bytes after a NUL cannot be silently ignored.\n   * Pass OBJECT_INFO_LOOKUP_REPLACE | OBJECT_INFO_SKIP_FETCH_OBJECT |\n     OBJECT_INFO_QUICK to odb_read_object_info_extended() and peel tags one\n     layer per iteration so missing OIDs or tag targets do not trigger lazy\n     promisor fetches or pack directory rescans in partial clones, and\n     verify that each peeled target matches the tag's declared type.\n * Patch 2/2 reads the committed HEAD:.git-blame-ignore-revs blob (in both\n   bare and non-bare repositories) instead of reading a file from the\n   working tree, matching hosting platforms even when an untracked file is\n   present or a tracked one has local modifications. The tree entry is\n   checked with S_ISREG() so non-regular entries (such as committed\n   symlinks) are skipped, parsed in memory via\n   oidset_parse_buffer_carefully(), and bypassed without reading if cleared\n   via blame.ignoreRevsFile=\"\" or --no-ignore-revs-file.\n\nRavi Mistry (2):\n  blame: harden ignore-revs parser and tag peeling\n  blame: ignore revs in HEAD:.git-blame-ignore-revs\n\n Documentation/blame-options.adoc |   8 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  65 ++++++++-\n oidset.c                         |  81 ++++++++----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 220 +++++++++++++++++++++++++++++++\n 6 files changed, 357 insertions(+), 35 deletions(-)\n\n\nbase-commit: fa7f9290efe2bd22dd736689597b474b93798e11\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2224%2Frmistry%2Fblame-default-ignore-revs-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2224/rmistry/blame-default-ignore-revs-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/2224\n\nRange-diff vs v2:\n\n 1:  2e12486c0d = 1:  2e12486c0d blame: harden ignore-revs parser and tag peeling\n 2:  35e303d65b ! 2:  72a87d1c34 blame: ignore revs in HEAD:.git-blame-ignore-revs\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +\tsize_t size;\n      +\tchar *buf;\n      +\n     -+\tif (get_oid_with_context(the_repository, name, GET_OID_QUIETLY,\n     ++\tif (get_oid_with_context(sb->repo, name, GET_OID_QUIETLY,\n      +\t\t\t\t &oid, &oc))\n      +\t\tgoto out;\n      +\tif (!S_ISREG(oc.mode))\n      +\t\tgoto out;\n      +\n     -+\tbuf = odb_read_object(the_repository->objects, &oid, &type, &size);\n     ++\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n      +\tif (!buf)\n      +\t\tgoto out;\n      +\tif (type == OBJ_BLOB)\n      +\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n     -+\t\t\t\t\t      the_repository->hash_algo,\n     ++\t\t\t\t\t      sb->repo->hash_algo,\n      +\t\t\t\t\t      peel_to_commit_oid, sb);\n      +\tfree(buf);\n      +\n\n-- \ngitgitgadget\n\n"},{"id":"554725","messageId":"2e12486c0d5dd8b94393b08413a85a8d47f86edd.1791757294.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v3.git.1791757294.gitgitgadget@gmail.com","subject":"[PATCH v3 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-11T22:21:32Z","receivedAt":"2026-10-11T22:21:32Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\nCurrently, blame.ignoreRevsFile and --ignore-revs-file only read paths\nexplicitly configured by the user, which cannot point to an\nattacker-controlled file under Git's threat model. An upcoming commit\nwill teach git-blame(1) and git-annotate(1) to automatically read the\nHEAD:.git-blame-ignore-revs blob by default if it exists, exposing the\nignore-revs parser (oidset_parse_file_carefully() in oidset.c) and its\ntag-peeling callback (peel_to_commit_oid() in builtin/blame.c) to\nupstream-controlled content at a well-known path.\n\nHarden both code paths before enabling the default blob:\n\n- In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n  next newline and records the full line length in sb.len, including\n  any embedded NUL bytes. However, strchr(sb.buf, '#') and\n  parse_oid_hex_algop(sb.buf, &oid, &p, algop) treat sb.buf as a\n  NUL-terminated string. If a line contains an embedded NUL byte after\n  a valid object name (such as \"<oid>\\0garbage\" or \"<oid>\\0# comment\"),\n  *p is '\\0' and trailing bytes on the line are silently ignored.\n  Reject any line containing an embedded NUL byte via memchr() before\n  stripping comments and whitespace.\n- In peel_to_commit_oid(), odb_read_object_info() is called without\n  OBJECT_INFO_SKIP_FETCH_OBJECT or OBJECT_INFO_QUICK, and deref_tag()\n  calls parse_object() on tag targets without checking whether the\n  target object exists locally first. In a partial clone, any missing\n  commit OID or tag target listed in the ignore-revs file would trigger\n  lazy promisor fetches and pack directory rescans during git-blame(1).\n  Use odb_read_object_info_extended() with OBJECT_INFO_LOOKUP_REPLACE |\n  OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK and peel OBJ_TAG\n  objects one layer per iteration, verifying that each target object\n  exists locally and matches the tag's declared type before parsing it.\n\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n builtin/blame.c              | 20 +++++++++++++++++--\n oidset.c                     |  3 +++\n t/t8013-blame-ignore-revs.sh | 38 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 59 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 48d5251c6d..6741a7b9df 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -911,21 +911,37 @@ static int is_a_rev(const char *name)\n static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n {\n \tstruct repository *r = ((struct blame_scoreboard *)cbdata)->repo;\n+\tenum object_type expected_type = OBJ_ANY;\n \tstruct object_id oid;\n \n \toidcpy(&oid, oid_ret);\n \twhile (1) {\n+\t\tunsigned flags = OBJECT_INFO_LOOKUP_REPLACE |\n+\t\t\t\t OBJECT_INFO_SKIP_FETCH_OBJECT |\n+\t\t\t\t OBJECT_INFO_QUICK;\n+\t\tstruct object_info oi = OBJECT_INFO_INIT;\n+\t\tenum object_type kind;\n \t\tstruct object *obj;\n-\t\tint kind = odb_read_object_info(r->objects, &oid, NULL);\n+\n+\t\toi.typep = &kind;\n+\t\tif (odb_read_object_info_extended(r->objects, &oid, &oi,\n+\t\t\t\t\t\t  flags) < 0)\n+\t\t\treturn -1;\n+\t\tif (expected_type != OBJ_ANY && kind != expected_type)\n+\t\t\treturn -1;\n \t\tif (kind == OBJ_COMMIT) {\n \t\t\toidcpy(oid_ret, &oid);\n \t\t\treturn 0;\n \t\t}\n \t\tif (kind != OBJ_TAG)\n \t\t\treturn -1;\n-\t\tobj = deref_tag(r, parse_object(r, &oid), NULL, 0);\n+\t\tobj = parse_object(r, &oid);\n+\t\tif (!obj || obj->type != OBJ_TAG)\n+\t\t\treturn -1;\n+\t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\treturn -1;\n+\t\texpected_type = obj->type;\n \t\toidcpy(&oid, &obj->oid);\n \t}\n }\ndiff --git a/oidset.c b/oidset.c\nindex c8ff0b385c..90d39204d3 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -85,6 +85,9 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\tconst char *p;\n \t\tconst char *name;\n \n+\t\tif (memchr(sb.buf, '\\0', sb.len))\n+\t\t\tdie(\"invalid object name: %s\", sb.buf);\n+\n \t\t/*\n \t\t * Allow trailing comments, leading whitespace\n \t\t * (including before commits), and empty or whitespace\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex cace00ae8d..70fe509a64 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -327,4 +327,42 @@ test_expect_success ignore_merge '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'ignore-revs-file rejects lines with embedded NUL bytes' '\n+\trev_b=$(git rev-parse B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_b\" | q_to_nul >ignore_nul &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul 2>err &&\n+\ttest_grep \"invalid object name:\" err &&\n+\n+\tprintf \"%sQ# comment\\n\" \"$rev_b\" | q_to_nul >ignore_nul_comment &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul_comment 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'ignore-revs-file peels chained tags and skips missing tag targets' '\n+\ttest_write_lines BB L2-modified L3 L4 L5 L6 L7 L8 CC >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m D &&\n+\tgit tag -a -m \"tag 1\" D_TAG1 HEAD &&\n+\tgit tag -a -m \"tag 2\" D_TAG2 D_TAG1 &&\n+\tgit rev-parse D_TAG2 >ignore_tag_chain &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_tag_chain >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\ttest_config extensions.partialClone origin &&\n+\ttest_config remote.origin.promisor true &&\n+\ttest_config remote.origin.url /nonexistent &&\n+\tmissing_oid=$(test_oid deadbeef) &&\n+\tbad_tag=$(printf \"object %s\\ntype commit\\ntag bad-tag\\ntagger T <t@example.com> 0 +0000\\n\\nmsg\\n\" \"$missing_oid\" |\n+\t\tgit hash-object -t tag -w --stdin) &&\n+\ttest_write_lines \"$missing_oid\" \"$bad_tag\" >ignore_bad_tag &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_bad_tag >blame_raw 2>err &&\n+\ttest_must_be_empty err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse HEAD >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n\n"},{"id":"554726","messageId":"72a87d1c34bba81cb760e47436a39cb249e42278.1791757294.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v3.git.1791757294.gitgitgadget@gmail.com","subject":"[PATCH v3 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-11T22:21:33Z","receivedAt":"2026-10-11T22:21:33Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\ngit-blame(1) can ignore a list of commits specified via\n--ignore-revs-file or the blame.ignoreRevsFile configuration option.\nThis is useful for skipping uninteresting revisions such as tree-wide\nformatting changes, large-scale refactors, and code modernizations that\nwould otherwise obscure genuine historical authorship.\n\nWhen revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\nblame.ignoreRevsFile config option\", 2019-10-18), it intentionally\navoided adopting a default ignore file. At the time, the capability was\nnew and unproven, so avoiding unrequested filesystem I/O or unexpected\nattribution shifts took priority over a project-wide default.\nRequiring explicit opt-in per clone was therefore the prudent design.\n\nSince then, maintaining a .git-blame-ignore-revs file in the repository\nroot has become the de facto standard across the Git ecosystem, adopted\nby major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\nsource projects (such as Chromium and LLVM). As a consequence,\ndevelopers frequently encounter a jarring mismatch: web interfaces\nseamlessly ignore formatting commits, but local git-blame(1) and\ngit-annotate(1) runs do not, unless each user manually configures\nblame.ignoreRevsFile for every local checkout.\n\nTeach git-blame(1) and git-annotate(1) to automatically add the\nHEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\nin the list of ignore-revs files in both bare and non-bare\nrepositories. Reading the committed blob from HEAD rather than the\nworking tree ensures that local runs match hosting platforms even when\nan untracked .git-blame-ignore-revs file is present or a tracked one\nhas uncommitted local changes.\n\nTo ensure consistent precedence and override semantics:\n- The default HEAD:.git-blame-ignore-revs entry is added before reading\n  configuration and CLI options, preserving user and repository config\n  overrides.\n- In git_blame_config(), blame.ignoreRevsFile entries are appended via\n  string_list_append() rather than inserted in sorted order via\n  string_list_insert() so that configuration entries preserve their\n  order relative to the initial default entry.\n- The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n  get_oid_with_context(). Its mode is checked with S_ISREG() before\n  reading the object so that non-regular tree entries (such as a\n  committed symbolic link whose blob stores a target path rather than\n  revision IDs, a subdirectory, or a gitlink) are skipped instead of\n  being read and rejected as malformed object names. The blob is parsed\n  in memory via a new oidset_parse_buffer_carefully() helper in\n  oidset.c that shares line parsing with oidset_parse_file_carefully().\n- In build_ignorelist(), ignore-revs entries are processed starting\n  after the last empty string entry. This ensures setting\n  blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n  --no-ignore-revs-file cleanly discards the default blob without\n  attempting to read or parse it, allowing users to bypass a malformed\n  default blob.\n\nUpdate documentation in blame-options.adoc and config/blame.adoc, and\nadd comprehensive test coverage in t8013 for the default blob lookup,\nsubdirectory invocations, bare repositories, uncommitted and untracked\nworking-tree files, CLI and config overrides, committed symlink\nentries, and comments and whitespace handling.\n\nBased-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\nHelped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\nHelped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n Documentation/blame-options.adoc |   8 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  45 +++++++-\n oidset.c                         |  84 +++++++++-----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 182 +++++++++++++++++++++++++++++++\n 6 files changed, 301 insertions(+), 36 deletions(-)\n\ndiff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\nindex 1ae1222b6b..8d59dcc8f3 100644\n--- a/Documentation/blame-options.adoc\n+++ b/Documentation/blame-options.adoc\n@@ -132,9 +132,11 @@ take effect.\n `--ignore-revs-file <file>`::\n \tIgnore revisions listed in _<file>_, which must be in the same format as an\n \t`fsck.skipList`.  This option may be repeated, and these files will be\n-\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n-\toption.  An empty file name, `\"\"`, will clear the list of revs from\n-\tpreviously processed files.\n+\tprocessed after the default `HEAD:.git-blame-ignore-revs` blob (if it\n+\texists) and any files specified with the `blame.ignoreRevsFile` config\n+\toption.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will clear\n+\tthe list of revs from previously processed files, including the default\n+\t`HEAD:.git-blame-ignore-revs` blob.\n \n `--color-lines`::\n \tColor line annotations in the default format differently if they come from\ndiff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\nindex 4d047c1790..153d4ab524 100644\n--- a/Documentation/config/blame.adoc\n+++ b/Documentation/config/blame.adoc\n@@ -23,9 +23,12 @@ blame.showRoot::\n blame.ignoreRevsFile::\n \tIgnore revisions listed in the file, one unabbreviated object name per\n \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n-\t`#` are ignored.  This option may be repeated multiple times.  Empty\n-\tfile names will reset the list of ignored revisions.  This option will\n-\tbe handled before the command line option `--ignore-revs-file`.\n+\t`#` are ignored.  If the `HEAD:.git-blame-ignore-revs` blob exists, it\n+\tis added as the initial element in the list of ignore-revs files.\n+\tOther files listed in the configuration are also used, but an empty\n+\telement makes all elements that appeared before in the list forgotten.\n+\tThis option will be handled before the command line option\n+\t`--ignore-revs-file`.\n \n blame.markUnblamableLines::\n \tMark lines that were changed by an ignored revision that we could not\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 6741a7b9df..f5b944f182 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -769,7 +769,7 @@ static int git_blame_config(const char *var, const char *value,\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tif (str)\n-\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n+\t\t\tstring_list_append(&ignore_revs_file_list, str);\n \t\tfree(str);\n \t\treturn 0;\n \t}\n@@ -946,17 +946,52 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n \t}\n }\n \n+static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *name)\n+{\n+\tstruct object_context oc;\n+\tstruct object_id oid;\n+\tenum object_type type;\n+\tsize_t size;\n+\tchar *buf;\n+\n+\tif (get_oid_with_context(sb->repo, name, GET_OID_QUIETLY,\n+\t\t\t\t &oid, &oc))\n+\t\tgoto out;\n+\tif (!S_ISREG(oc.mode))\n+\t\tgoto out;\n+\n+\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n+\tif (!buf)\n+\t\tgoto out;\n+\tif (type == OBJ_BLOB)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      sb->repo->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\tfree(buf);\n+\n+out:\n+\tobject_context_release(&oc);\n+}\n+\n static void build_ignorelist(struct blame_scoreboard *sb,\n \t\t\t     struct string_list *ignore_revs_file_list,\n \t\t\t     struct string_list *ignore_rev_list)\n {\n \tstruct string_list_item *i;\n \tstruct object_id oid;\n+\tsize_t start_idx = 0, idx;\n+\n+\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tif (!*ignore_revs_file_list->items[idx].string)\n+\t\t\tstart_idx = idx + 1;\n+\t}\n \n \toidset_init(&sb->ignore_list, 0);\n-\tfor_each_string_list_item(i, ignore_revs_file_list) {\n-\t\tif (!strcmp(i->string, \"\"))\n-\t\t\toidset_clear(&sb->ignore_list);\n+\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n+\t\ti = &ignore_revs_file_list->items[idx];\n+\t\tif (i->util)\n+\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n \t\telse\n \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n \t\t\t\t\t\t    the_repository->hash_algo,\n@@ -1036,6 +1071,8 @@ int cmd_blame(int argc,\n \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n \n \tsetup_default_color_by_age();\n+\tstring_list_append(&ignore_revs_file_list,\n+\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n \trepo_config(the_repository, git_blame_config, &output_option);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \trevs.date_mode = blame_date_mode;\ndiff --git a/oidset.c b/oidset.c\nindex 90d39204d3..8469d03b9b 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n }\n \n+static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n+\t\t\t      const struct git_hash_algo *algop,\n+\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tconst char *p;\n+\tconst char *name;\n+\tstruct object_id oid;\n+\n+\tif (memchr(sb->buf, '\\0', sb->len))\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\n+\t/*\n+\t * Allow trailing comments, leading whitespace\n+\t * (including before commits), and empty or whitespace\n+\t * only lines.\n+\t */\n+\tname = strchr(sb->buf, '#');\n+\tif (name)\n+\t\tstrbuf_setlen(sb, name - sb->buf);\n+\tstrbuf_trim(sb);\n+\tif (!sb->len)\n+\t\treturn;\n+\n+\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\tif (fn && fn(&oid, cbdata))\n+\t\treturn;\n+\toidset_insert(set, &oid);\n+}\n+\n void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n {\n \tFILE *fp;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tstruct object_id oid;\n \n \tfp = fopen(path, \"r\");\n \tif (!fp)\n \t\tdie(\"could not open object name list: %s\", path);\n-\twhile (!strbuf_getline(&sb, fp)) {\n-\t\tconst char *p;\n-\t\tconst char *name;\n-\n-\t\tif (memchr(sb.buf, '\\0', sb.len))\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\n-\t\t/*\n-\t\t * Allow trailing comments, leading whitespace\n-\t\t * (including before commits), and empty or whitespace\n-\t\t * only lines.\n-\t\t */\n-\t\tname = strchr(sb.buf, '#');\n-\t\tif (name)\n-\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n-\t\tstrbuf_trim(&sb);\n-\t\tif (!sb.len)\n-\t\t\tcontinue;\n-\n-\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\t\tif (fn && fn(&oid, cbdata))\n-\t\t\tcontinue;\n-\t\toidset_insert(set, &oid);\n-\t}\n+\twhile (!strbuf_getline(&sb, fp))\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n \tif (ferror(fp))\n \t\tdie_errno(\"Could not read '%s'\", path);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n }\n+\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tconst char *p = buf, *end;\n+\n+\tif (!size)\n+\t\treturn;\n+\tend = buf + size;\n+\n+\twhile (p < end) {\n+\t\tconst char *nl = memchr(p, '\\n', end - p);\n+\t\tsize_t len = (nl ? nl : end) - p;\n+\n+\t\tstrbuf_reset(&sb);\n+\t\tif (len && p[len - 1] == '\\r')\n+\t\t\tlen--;\n+\t\tstrbuf_add(&sb, p, len);\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n+\t\tp = nl ? nl + 1 : end;\n+\t}\n+\tstrbuf_release(&sb);\n+}\ndiff --git a/oidset.h b/oidset.h\nindex e0f1a6ff4f..667c390842 100644\n--- a/oidset.h\n+++ b/oidset.h\n@@ -98,6 +98,15 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n \n+/*\n+ * Similar to oidset_parse_file_carefully(), but parses lines from an\n+ * in-memory buffer of 'size' bytes.\n+ */\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n+\n struct oidset_iter {\n \tconst kh_oid_set_t *set;\n \tkhiter_t iter;\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex 70fe509a64..3e1b5291aa 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -365,4 +365,186 @@ test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n \ttest_cmp expect actual\n '\n \n+# Tests for default HEAD:.git-blame-ignore-revs blob\n+test_expect_success 'setup default HEAD:.git-blame-ignore-revs' '\n+\tgit checkout -b default-file-branch &&\n+\ttest_write_lines line1 line2 >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default base\" &&\n+\tgit tag DEF_A &&\n+\n+\ttest_write_lines line1-modified line2-modified >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default mod\" &&\n+\tgit tag DEF_B &&\n+\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"add .git-blame-ignore-revs\"\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs is used by default' '\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected by git annotate' '\n+\tgit rev-parse --short DEF_A >expect_sha &&\n+\tgit annotate def-file >actual &&\n+\ttest_grep \"^$(cat expect_sha)\" actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs works from subdirectory' '\n+\tmkdir -p sub &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n+\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\t\tgit rev-parse DEF_A >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\tgit clone --bare . bare.git &&\n+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are ignored' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --no-ignore-revs-file' '\n+\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --ignore-revs-file \"\"' '\n+\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n+\ttest_config blame.ignoreRevsFile \"\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs handles comments and whitespace' '\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\t{\n+\t\techo \"# Leading comment\" &&\n+\t\techo \"\" &&\n+\t\techo \"   $rev_def_b   # inline comment\" &&\n+\t\techo \"# Trailing comment\"\n+\t} >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'empty default HEAD:.git-blame-ignore-revs is harmless' '\n+\t: >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'committed symlink .git-blame-ignore-revs in HEAD is ignored' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\tgit rev-parse DEF_B >target_file &&\n+\ttest_ln_s_add target_file .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'malformed default HEAD:.git-blame-ignore-revs fails but can be bypassed' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file &&\n+\tgit blame --no-ignore-revs-file def-file &&\n+\tgit blame --ignore-revs-file \"\" def-file &&\n+\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n+\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\ttest_write_lines line1-modified line2-c >def-file &&\n+\tgit add .git-blame-ignore-revs def-file &&\n+\ttest_tick &&\n+\tgit commit -m C &&\n+\tgit tag DEF_C &&\n+\tgit rev-parse DEF_C >custom_ignore &&\n+\ttest_config blame.ignoreRevsFile custom_ignore &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"554727","messageId":"20261011222929.2957901-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqtsmsdpxz.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-11T22:29:29Z","receivedAt":"2026-10-11T22:29:29Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Since the scoreboard is passed around throughout the subsystem and\n> has a pointer to the repository it is working with, a new function\n> like this one does not have to add new references to the_repository.\n\nSince there is an ongoing effort to reduce uses of the_repository in\nthe codebase, I went ahead and switched parse_default_ignore_revs_blob()\nto use sb->repo in v3.\n\nThanks!\n\n"},{"id":"554729","messageId":"xmqq8q43eszt.fsf@gitster.g","threadId":"66313","inReplyTo":"20261011222929.2957901-1-rmistry@google.com","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-11T23:07:34Z","receivedAt":"2026-10-11T23:07:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ravi Mistry <rmistry@google.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> Since the scoreboard is passed around throughout the subsystem and\n>> has a pointer to the repository it is working with, a new function\n>> like this one does not have to add new references to the_repository.\n>\n> Since there is an ongoing effort to reduce uses of the_repository in\n> the codebase, I went ahead and switched parse_default_ignore_revs_blob()\n> to use sb->repo in v3.\n>\n> Thanks!\n\nSounds good, and v3 looks good.  Let me mark the topic ready for\n'next' unless we hear objections in a few days.\n\nThanks.\n\n"},{"id":"554747","messageId":"e3b68210-7558-4f95-bc3c-eb57b1065790@gmail.com","threadId":"66313","inReplyTo":"72a87d1c34bba81cb760e47436a39cb249e42278.1791757294.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v3 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-12T09:10:33Z","receivedAt":"2026-10-12T09:10:33Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Ravi\n\nOn 11/10/2026 23:21, Ravi Mistry via GitGitGadget wrote:\n> From: Ravi Mistry <rmistry@google.com>\n> > git-blame(1) can ignore a list of commits specified via\n> --ignore-revs-file or the blame.ignoreRevsFile configuration option.\n> This is useful for skipping uninteresting revisions such as tree-wide\n> formatting changes, large-scale refactors, and code modernizations that\n> would otherwise obscure genuine historical authorship.\n> > When revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\n> blame.ignoreRevsFile config option\", 2019-10-18), it intentionally\n> avoided adopting a default ignore file. At the time, the capability was\n> new and unproven, so avoiding unrequested filesystem I/O or unexpected\n> attribution shifts took priority over a project-wide default.\n> Requiring explicit opt-in per clone was therefore the prudent design.\n> > Since then, maintaining a .git-blame-ignore-revs file in the repository\n> root has become the de facto standard across the Git ecosystem, adopted\n> by major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\n> source projects (such as Chromium and LLVM). As a consequence,\n> developers frequently encounter a jarring mismatch: web interfaces\n> seamlessly ignore formatting commits, but local git-blame(1) and\n> git-annotate(1) runs do not, unless each user manually configures\n> blame.ignoreRevsFile for every local checkout.\n\nThis is nicely explained\n\n> Teach git-blame(1) and git-annotate(1) to automatically add the\n> HEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\n> in the list of ignore-revs files in both bare and non-bare\n> repositories. Reading the committed blob from HEAD rather than the\n> working tree ensures that local runs match hosting platforms even when\n> an untracked .git-blame-ignore-revs file is present or a tracked one\n> has uncommitted local changes.\n\nI can see we'd want to use the committed version in a bare repository, but it seems strange to me to ignore uncommitted changes in a non-bare repository. We don't do that for other special files like .gitattributes. It is rather inconvinient if the user has to explicitly pass the file inorder to test the effect of local modification to .git-brame-ignore-revs. To me it would make more sense to automatically use .git-blame-ignore-revs file from the working tree when that path is tracked by git.\n\nI did wonder if we wanted to automatically support .git-blame-ignore-revs in the root of a subtree, but I don't think there is an easy way to do that without visiting all the directories containing tracked files which makes it too expensive.\n\nOne final thought - do we want to limit the size of the blob that we're prepared to parse as we do for .gitattributes? I had a very quick look at the khash code which is used by 'struct oidset' and it seems to use 32 bit integers for the number of entries. I did not spend anytime trying to figure out what happens if you try and store 2^32 entires.\n\nThanks\n\nPhillip\n\n> To ensure consistent precedence and override semantics:\n> - The default HEAD:.git-blame-ignore-revs entry is added before reading\n>    configuration and CLI options, preserving user and repository config\n>    overrides.\n> - In git_blame_config(), blame.ignoreRevsFile entries are appended via\n>    string_list_append() rather than inserted in sorted order via\n>    string_list_insert() so that configuration entries preserve their\n>    order relative to the initial default entry.\n> - The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n>    get_oid_with_context(). Its mode is checked with S_ISREG() before\n>    reading the object so that non-regular tree entries (such as a\n>    committed symbolic link whose blob stores a target path rather than\n>    revision IDs, a subdirectory, or a gitlink) are skipped instead of\n>    being read and rejected as malformed object names. The blob is parsed\n>    in memory via a new oidset_parse_buffer_carefully() helper in\n>    oidset.c that shares line parsing with oidset_parse_file_carefully().\n> - In build_ignorelist(), ignore-revs entries are processed starting\n>    after the last empty string entry. This ensures setting\n>    blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n>    --no-ignore-revs-file cleanly discards the default blob without\n>    attempting to read or parse it, allowing users to bypass a malformed\n>    default blob.\n> > Update documentation in blame-options.adoc and config/blame.adoc, and\n> add comprehensive test coverage in t8013 for the default blob lookup,\n> subdirectory invocations, bare repositories, uncommitted and untracked\n> working-tree files, CLI and config overrides, committed symlink\n> entries, and comments and whitespace handling.\n> > Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\n> Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n> Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n> Helped-by: Eric Sunshine <sunshine@sunshineco.com>\n> Signed-off-by: Ravi Mistry <rmistry@google.com>\n> ---\n>   Documentation/blame-options.adoc |   8 +-\n>   Documentation/config/blame.adoc  |   9 +-\n>   builtin/blame.c                  |  45 +++++++-\n>   oidset.c                         |  84 +++++++++-----\n>   oidset.h                         |   9 ++\n>   t/t8013-blame-ignore-revs.sh     | 182 +++++++++++++++++++++++++++++++\n>   6 files changed, 301 insertions(+), 36 deletions(-)\n> > diff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\n> index 1ae1222b6b..8d59dcc8f3 100644\n> --- a/Documentation/blame-options.adoc\n> +++ b/Documentation/blame-options.adoc\n> @@ -132,9 +132,11 @@ take effect.\n>   `--ignore-revs-file <file>`::\n>   \tIgnore revisions listed in _<file>_, which must be in the same format as an\n>   \t`fsck.skipList`.  This option may be repeated, and these files will be\n> -\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n> -\toption.  An empty file name, `\"\"`, will clear the list of revs from\n> -\tpreviously processed files.\n> +\tprocessed after the default `HEAD:.git-blame-ignore-revs` blob (if it\n> +\texists) and any files specified with the `blame.ignoreRevsFile` config\n> +\toption.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will clear\n> +\tthe list of revs from previously processed files, including the default\n> +\t`HEAD:.git-blame-ignore-revs` blob.\n>   >   `--color-lines`::\n>   \tColor line annotations in the default format differently if they come from\n> diff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\n> index 4d047c1790..153d4ab524 100644\n> --- a/Documentation/config/blame.adoc\n> +++ b/Documentation/config/blame.adoc\n> @@ -23,9 +23,12 @@ blame.showRoot::\n>   blame.ignoreRevsFile::\n>   \tIgnore revisions listed in the file, one unabbreviated object name per\n>   \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n> -\t`#` are ignored.  This option may be repeated multiple times.  Empty\n> -\tfile names will reset the list of ignored revisions.  This option will\n> -\tbe handled before the command line option `--ignore-revs-file`.\n> +\t`#` are ignored.  If the `HEAD:.git-blame-ignore-revs` blob exists, it\n> +\tis added as the initial element in the list of ignore-revs files.\n> +\tOther files listed in the configuration are also used, but an empty\n> +\telement makes all elements that appeared before in the list forgotten.\n> +\tThis option will be handled before the command line option\n> +\t`--ignore-revs-file`.\n>   >   blame.markUnblamableLines::\n>   \tMark lines that were changed by an ignored revision that we could not\n> diff --git a/builtin/blame.c b/builtin/blame.c\n> index 6741a7b9df..f5b944f182 100644\n> --- a/builtin/blame.c\n> +++ b/builtin/blame.c\n> @@ -769,7 +769,7 @@ static int git_blame_config(const char *var, const char *value,\n>   \t\tif (ret)\n>   \t\t\treturn ret;\n>   \t\tif (str)\n> -\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n> +\t\t\tstring_list_append(&ignore_revs_file_list, str);\n>   \t\tfree(str);\n>   \t\treturn 0;\n>   \t}\n> @@ -946,17 +946,52 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n>   \t}\n>   }\n>   > +static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n> +\t\t\t\t\t   const char *name)\n> +{\n> +\tstruct object_context oc;\n> +\tstruct object_id oid;\n> +\tenum object_type type;\n> +\tsize_t size;\n> +\tchar *buf;\n> +\n> +\tif (get_oid_with_context(sb->repo, name, GET_OID_QUIETLY,\n> +\t\t\t\t &oid, &oc))\n> +\t\tgoto out;\n> +\tif (!S_ISREG(oc.mode))\n> +\t\tgoto out;\n> +\n> +\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n> +\tif (!buf)\n> +\t\tgoto out;\n> +\tif (type == OBJ_BLOB)\n> +\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n> +\t\t\t\t\t      sb->repo->hash_algo,\n> +\t\t\t\t\t      peel_to_commit_oid, sb);\n> +\tfree(buf);\n> +\n> +out:\n> +\tobject_context_release(&oc);\n> +}\n> +\n>   static void build_ignorelist(struct blame_scoreboard *sb,\n>   \t\t\t     struct string_list *ignore_revs_file_list,\n>   \t\t\t     struct string_list *ignore_rev_list)\n>   {\n>   \tstruct string_list_item *i;\n>   \tstruct object_id oid;\n> +\tsize_t start_idx = 0, idx;\n> +\n> +\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n> +\t\tif (!*ignore_revs_file_list->items[idx].string)\n> +\t\t\tstart_idx = idx + 1;\n> +\t}\n>   >   \toidset_init(&sb->ignore_list, 0);\n> -\tfor_each_string_list_item(i, ignore_revs_file_list) {\n> -\t\tif (!strcmp(i->string, \"\"))\n> -\t\t\toidset_clear(&sb->ignore_list);\n> +\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n> +\t\ti = &ignore_revs_file_list->items[idx];\n> +\t\tif (i->util)\n> +\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n>   \t\telse\n>   \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n>   \t\t\t\t\t\t    the_repository->hash_algo,\n> @@ -1036,6 +1071,8 @@ int cmd_blame(int argc,\n>   \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n>   >   \tsetup_default_color_by_age();\n> +\tstring_list_append(&ignore_revs_file_list,\n> +\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n>   \trepo_config(the_repository, git_blame_config, &output_option);\n>   \trepo_init_revisions(the_repository, &revs, NULL);\n>   \trevs.date_mode = blame_date_mode;\n> diff --git a/oidset.c b/oidset.c\n> index 90d39204d3..8469d03b9b 100644\n> --- a/oidset.c\n> +++ b/oidset.c\n> @@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n>   \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n>   }\n>   > +static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n> +\t\t\t      const struct git_hash_algo *algop,\n> +\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n> +{\n> +\tconst char *p;\n> +\tconst char *name;\n> +\tstruct object_id oid;\n> +\n> +\tif (memchr(sb->buf, '\\0', sb->len))\n> +\t\tdie(\"invalid object name: %s\", sb->buf);\n> +\n> +\t/*\n> +\t * Allow trailing comments, leading whitespace\n> +\t * (including before commits), and empty or whitespace\n> +\t * only lines.\n> +\t */\n> +\tname = strchr(sb->buf, '#');\n> +\tif (name)\n> +\t\tstrbuf_setlen(sb, name - sb->buf);\n> +\tstrbuf_trim(sb);\n> +\tif (!sb->len)\n> +\t\treturn;\n> +\n> +\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n> +\t\tdie(\"invalid object name: %s\", sb->buf);\n> +\tif (fn && fn(&oid, cbdata))\n> +\t\treturn;\n> +\toidset_insert(set, &oid);\n> +}\n> +\n>   void oidset_parse_file_carefully(struct oidset *set, const char *path,\n>   \t\t\t\t const struct git_hash_algo *algop,\n>   \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n>   {\n>   \tFILE *fp;\n>   \tstruct strbuf sb = STRBUF_INIT;\n> -\tstruct object_id oid;\n>   >   \tfp = fopen(path, \"r\");\n>   \tif (!fp)\n>   \t\tdie(\"could not open object name list: %s\", path);\n> -\twhile (!strbuf_getline(&sb, fp)) {\n> -\t\tconst char *p;\n> -\t\tconst char *name;\n> -\n> -\t\tif (memchr(sb.buf, '\\0', sb.len))\n> -\t\t\tdie(\"invalid object name: %s\", sb.buf);\n> -\n> -\t\t/*\n> -\t\t * Allow trailing comments, leading whitespace\n> -\t\t * (including before commits), and empty or whitespace\n> -\t\t * only lines.\n> -\t\t */\n> -\t\tname = strchr(sb.buf, '#');\n> -\t\tif (name)\n> -\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n> -\t\tstrbuf_trim(&sb);\n> -\t\tif (!sb.len)\n> -\t\t\tcontinue;\n> -\n> -\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n> -\t\t\tdie(\"invalid object name: %s\", sb.buf);\n> -\t\tif (fn && fn(&oid, cbdata))\n> -\t\t\tcontinue;\n> -\t\toidset_insert(set, &oid);\n> -\t}\n> +\twhile (!strbuf_getline(&sb, fp))\n> +\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n>   \tif (ferror(fp))\n>   \t\tdie_errno(\"Could not read '%s'\", path);\n>   \tfclose(fp);\n>   \tstrbuf_release(&sb);\n>   }\n> +\n> +void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n> +\t\t\t\t   size_t size,\n> +\t\t\t\t   const struct git_hash_algo *algop,\n> +\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n> +{\n> +\tstruct strbuf sb = STRBUF_INIT;\n> +\tconst char *p = buf, *end;\n> +\n> +\tif (!size)\n> +\t\treturn;\n> +\tend = buf + size;\n> +\n> +\twhile (p < end) {\n> +\t\tconst char *nl = memchr(p, '\\n', end - p);\n> +\t\tsize_t len = (nl ? nl : end) - p;\n> +\n> +\t\tstrbuf_reset(&sb);\n> +\t\tif (len && p[len - 1] == '\\r')\n> +\t\t\tlen--;\n> +\t\tstrbuf_add(&sb, p, len);\n> +\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n> +\t\tp = nl ? nl + 1 : end;\n> +\t}\n> +\tstrbuf_release(&sb);\n> +}\n> diff --git a/oidset.h b/oidset.h\n> index e0f1a6ff4f..667c390842 100644\n> --- a/oidset.h\n> +++ b/oidset.h\n> @@ -98,6 +98,15 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n>   \t\t\t\t const struct git_hash_algo *algop,\n>   \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n>   > +/*\n> + * Similar to oidset_parse_file_carefully(), but parses lines from an\n> + * in-memory buffer of 'size' bytes.\n> + */\n> +void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n> +\t\t\t\t   size_t size,\n> +\t\t\t\t   const struct git_hash_algo *algop,\n> +\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n> +\n>   struct oidset_iter {\n>   \tconst kh_oid_set_t *set;\n>   \tkhiter_t iter;\n> diff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\n> index 70fe509a64..3e1b5291aa 100755\n> --- a/t/t8013-blame-ignore-revs.sh\n> +++ b/t/t8013-blame-ignore-revs.sh\n> @@ -365,4 +365,186 @@ test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n>   \ttest_cmp expect actual\n>   '\n>   > +# Tests for default HEAD:.git-blame-ignore-revs blob\n> +test_expect_success 'setup default HEAD:.git-blame-ignore-revs' '\n> +\tgit checkout -b default-file-branch &&\n> +\ttest_write_lines line1 line2 >def-file &&\n> +\tgit add def-file &&\n> +\ttest_tick &&\n> +\tgit commit -m \"default base\" &&\n> +\tgit tag DEF_A &&\n> +\n> +\ttest_write_lines line1-modified line2-modified >def-file &&\n> +\tgit add def-file &&\n> +\ttest_tick &&\n> +\tgit commit -m \"default mod\" &&\n> +\tgit tag DEF_B &&\n> +\n> +\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n> +\tgit add .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"add .git-blame-ignore-revs\"\n> +'\n> +\n> +test_expect_success 'default HEAD:.git-blame-ignore-revs is used by default' '\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_A >expect &&\n> +\ttest_cmp expect actual &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'default HEAD:.git-blame-ignore-revs respected by git annotate' '\n> +\tgit rev-parse --short DEF_A >expect_sha &&\n> +\tgit annotate def-file >actual &&\n> +\ttest_grep \"^$(cat expect_sha)\" actual\n> +'\n> +\n> +test_expect_success 'default HEAD:.git-blame-ignore-revs works from subdirectory' '\n> +\tmkdir -p sub &&\n> +\t(\n> +\t\tcd sub &&\n> +\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n> +\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\t\tgit rev-parse DEF_A >expect &&\n> +\t\ttest_cmp expect actual\n> +\t)\n> +'\n> +\n> +test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n> +\ttest_when_finished \"rm -rf bare.git\" &&\n> +\tgit clone --bare . bare.git &&\n> +\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_A >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are ignored' '\n> +\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n> +\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_A >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --no-ignore-revs-file' '\n> +\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_B >expect &&\n> +\ttest_cmp expect actual &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --ignore-revs-file \"\"' '\n> +\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_B >expect &&\n> +\ttest_cmp expect actual &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'disable default HEAD:.git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n> +\ttest_config blame.ignoreRevsFile \"\" &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_B >expect &&\n> +\ttest_cmp expect actual &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'default HEAD:.git-blame-ignore-revs handles comments and whitespace' '\n> +\trev_def_b=$(git rev-parse DEF_B) &&\n> +\t{\n> +\t\techo \"# Leading comment\" &&\n> +\t\techo \"\" &&\n> +\t\techo \"   $rev_def_b   # inline comment\" &&\n> +\t\techo \"# Trailing comment\"\n> +\t} >.git-blame-ignore-revs &&\n> +\tgit add .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_A >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'empty default HEAD:.git-blame-ignore-revs is harmless' '\n> +\t: >.git-blame-ignore-revs &&\n> +\tgit add .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_B >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'committed symlink .git-blame-ignore-revs in HEAD is ignored' '\n> +\tgit rm -f .git-blame-ignore-revs &&\n> +\tgit rev-parse DEF_B >target_file &&\n> +\ttest_ln_s_add target_file .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_B >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'malformed default HEAD:.git-blame-ignore-revs fails but can be bypassed' '\n> +\tgit rm -f .git-blame-ignore-revs &&\n> +\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n> +\tgit add .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n> +\ttest_must_fail git blame def-file &&\n> +\tgit blame --no-ignore-revs-file def-file &&\n> +\tgit blame --ignore-revs-file \"\" def-file &&\n> +\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n> +\n> +\trev_def_b=$(git rev-parse DEF_B) &&\n> +\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n> +\tgit add .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n> +\ttest_must_fail git blame def-file 2>err &&\n> +\ttest_grep \"invalid object name:\" err\n> +'\n> +\n> +test_expect_success 'default HEAD:.git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n> +\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n> +\ttest_write_lines line1-modified line2-c >def-file &&\n> +\tgit add .git-blame-ignore-revs def-file &&\n> +\ttest_tick &&\n> +\tgit commit -m C &&\n> +\tgit tag DEF_C &&\n> +\tgit rev-parse DEF_C >custom_ignore &&\n> +\ttest_config blame.ignoreRevsFile custom_ignore &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_A >expect &&\n> +\ttest_cmp expect actual &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_A >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n> +test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n> +\tgit rm -f .git-blame-ignore-revs &&\n> +\ttest_tick &&\n> +\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n> +\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n> +\tgit blame --line-porcelain def-file >blame_raw &&\n> +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n> +\tgit rev-parse DEF_B >expect &&\n> +\ttest_cmp expect actual\n> +'\n> +\n>   test_done\n\n\n"},{"id":"554748","messageId":"5fcd107d-b620-44d1-91b7-e5f9965171cc@gmail.com","threadId":"66313","inReplyTo":"xmqq8q43eszt.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-12T09:13:28Z","receivedAt":"2026-10-12T09:13:28Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 12/10/2026 00:07, Junio C Hamano wrote:\n> Ravi Mistry <rmistry@google.com> writes:\n> >> Junio C Hamano <gitster@pobox.com> writes:\n>>\n>>> Since the scoreboard is passed around throughout the subsystem and\n>>> has a pointer to the repository it is working with, a new function\n>>> like this one does not have to add new references to the_repository.\n>>\n>> Since there is an ongoing effort to reduce uses of the_repository in\n>> the codebase, I went ahead and switched parse_default_ignore_revs_blob()\n>> to use sb->repo in v3.\n>>\n>> Thanks!\n> > Sounds good, and v3 looks good.  Let me mark the topic ready for\n> 'next' unless we hear objections in a few days.\n\nI've left a couple of comments on v3. Ignoring uncommitted changes in the file in the working tree seems a bit odd to me and we seem to be prepared to load a file of any size from an untrusted source.\n\nThanks\n\nPhillip\n\n\n"},{"id":"554773","messageId":"20261012154834.622130-1-rmistry@google.com","threadId":"66313","inReplyTo":"e3b68210-7558-4f95-bc3c-eb57b1065790@gmail.com","subject":"Re: [PATCH v3 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-12T15:48:34Z","receivedAt":"2026-10-12T15:48:34Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Hi Phillip!\n\nPhillip Wood <phillip.wood123@gmail.com> writes:\n\n> I can see we'd want to use the committed version in a bare repository,\n> but it seems strange to me to ignore uncommitted changes in a non-bare\n> repository. We don't do that for other special files like\n> .gitattributes. It is rather inconvinient if the user has to explicitly\n> pass the file inorder to test the effect of local modification to\n> .git-brame-ignore-revs. To me it would make more sense to automatically\n> use .git-blame-ignore-revs file from the working tree when that path is\n> tracked by git.\n\nIn v1, this patch originally read .git-blame-ignore-revs from the\nworking tree in non-bare repositories. I switched to reading the\nHEAD:.git-blame-ignore-revs blob in v2 based on Junio's review and\nsuggestions on v1\n(https://lore.kernel.org/git/xmqqse2kma4o.fsf@gitster.g/).\n\n> I did wonder if we wanted to automatically support\n> .git-blame-ignore-revs in the root of a subtree, but I don't think there\n> is an easy way to do that without visiting all the directories\n> containing tracked files which makes it too expensive.\n\nAgreed. By convention across the ecosystem (GitHub, GitLab, and soon\nGerrit and Gitiles), .git-blame-ignore-revs is read from the root of\nthe repository, so only looking at the root keeps it simple and avoids\nthe overhead of walking subdirectories.\n\n> One final thought - do we want to limit the size of the blob that we're\n> prepared to parse as we do for .gitattributes? I had a very quick look\n> at the khash code which is used by 'struct oidset' and it seems to use\n> 32 bit integers for the number of entries. I did not spend anytime\n> trying to figure out what happens if you try and store 2^32 entires.\n\nIn parse_oidset_line(), peel_to_commit_oid() runs before\noidset_insert() and skips any OID that is not an existing local commit\nin the repository, and duplicate OIDs hash to the same entry. So the\noidset (and khash) will not have more entries than the number of local\ncommits in the repository. That said, if you and Junio would like a\nblob size cap in parse_default_ignore_revs_blob() (similar to\nATTR_MAX_FILE_SIZE), I am happy to add one.\n\nThanks!\n\n"},{"id":"554776","messageId":"xmqqbj8yan77.fsf@gitster.g","threadId":"66313","inReplyTo":"5fcd107d-b620-44d1-91b7-e5f9965171cc@gmail.com","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-12T16:38:36Z","receivedAt":"2026-10-12T16:38:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> I've left a couple of comments on v3. Ignoring uncommitted changes in \n> the file in the working tree seems a bit odd to me and we seem to be \n> prepared to load a file of any size from an untrusted source.\n\nThe latter sounds like a sensible thing to worry about.  Thanks for\nbringing it up.\n\nI do not have strong opinions either way on the former myself (the\nbehaviour implemented is to attempt matching what the hosting sites\ndo, which obviously work from the committed copy).  It indeed feels\nmore intuitive if the checked out copy (or even the file before it\ngets added for the first time) were consulted.\n\nThanks.\n\n\n"},{"id":"554797","messageId":"pull.2224.v4.git.1791832644.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"[PATCH v4 0/2] blame: ignore revs in HEAD:.git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-12T19:17:22Z","receivedAt":"2026-10-12T19:17:22Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"This series teaches git-blame(1) and git-annotate(1) to automatically use\nthe HEAD:.git-blame-ignore-revs blob by default if it exists, so local runs\nmatch hosting platforms without requiring manual blame.ignoreRevsFile\nconfiguration in every clone. This restarts the stalled attempt in PR\nhttps://github.com/gitgitgadget/git/pull/1809\n(https://lore.kernel.org/git/pull.1809.v2.git.1728707867.gitgitgadget@gmail.com/)\nand addresses https://github.com/gitgitgadget/git/issues/1494.\n\nChanges since v3:\n\n * Patch 2/2 caps the size of the default HEAD:.git-blame-ignore-revs blob\n   at IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from\n   3c50032ff5 (\"attr: ignore overly large gitattributes files\", 2022-12-01))\n   via odb_read_object_info() before calling odb_read_object(), skipping\n   oversized blobs with a warning without loading them into memory.\n\nChanges since v2:\n\n * Patch 2/2 uses sb->repo instead of the_repository in\n   parse_default_ignore_revs_blob().\n\nChanges since v1:\n\n * Split the series into two commits.\n * Patch 1/2 hardens oidset_parse_file_carefully() in oidset.c and\n   peel_to_commit_oid() in builtin/blame.c before exposing them to\n   upstream-controlled content at a well-known path:\n   * Reject lines containing embedded NUL bytes via memchr() so trailing\n     bytes after a NUL cannot be silently ignored.\n   * Pass OBJECT_INFO_LOOKUP_REPLACE | OBJECT_INFO_SKIP_FETCH_OBJECT |\n     OBJECT_INFO_QUICK to odb_read_object_info_extended() and peel tags one\n     layer per iteration so missing OIDs or tag targets do not trigger lazy\n     promisor fetches or pack directory rescans in partial clones, and\n     verify that each peeled target matches the tag's declared type.\n * Patch 2/2 reads the committed HEAD:.git-blame-ignore-revs blob (in both\n   bare and non-bare repositories) instead of reading a file from the\n   working tree, matching hosting platforms even when an untracked file is\n   present or a tracked one has local modifications. The tree entry is\n   checked with S_ISREG() so non-regular entries (such as committed\n   symlinks) are skipped, parsed in memory via\n   oidset_parse_buffer_carefully(), and bypassed without reading if cleared\n   via blame.ignoreRevsFile=\"\" or --no-ignore-revs-file.\n\nRavi Mistry (2):\n  blame: harden ignore-revs parser and tag peeling\n  blame: ignore revs in HEAD:.git-blame-ignore-revs\n\n Documentation/blame-options.adoc |   8 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  74 +++++++++-\n oidset.c                         |  81 ++++++++---\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 235 +++++++++++++++++++++++++++++++\n 6 files changed, 381 insertions(+), 35 deletions(-)\n\n\nbase-commit: fa7f9290efe2bd22dd736689597b474b93798e11\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2224%2Frmistry%2Fblame-default-ignore-revs-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2224/rmistry/blame-default-ignore-revs-v4\nPull-Request: https://github.com/gitgitgadget/git/pull/2224\n\nRange-diff vs v3:\n\n 1:  2e12486c0d = 1:  2e12486c0d blame: harden ignore-revs parser and tag peeling\n 2:  72a87d1c34 ! 2:  76d597dfa8 blame: ignore revs in HEAD:.git-blame-ignore-revs\n     @@ Commit message\n            reading the object so that non-regular tree entries (such as a\n            committed symbolic link whose blob stores a target path rather than\n            revision IDs, a subdirectory, or a gitlink) are skipped instead of\n     -      being read and rejected as malformed object names. The blob is parsed\n     -      in memory via a new oidset_parse_buffer_carefully() helper in\n     -      oidset.c that shares line parsing with oidset_parse_file_carefully().\n     +      being read and rejected as malformed object names. Its size is checked\n     +      via odb_read_object_info() and capped at IGNORE_REVS_MAX_FILE_SIZE\n     +      (100MB, matching ATTR_MAX_FILE_SIZE from 3c50032ff5 (\"attr: ignore\n     +      overly large gitattributes files\", 2022-12-01)) so an oversized blob\n     +      is skipped with a warning without being loaded into memory. The blob\n     +      is parsed in memory via a new oidset_parse_buffer_carefully() helper\n     +      in oidset.c that shares line parsing with\n     +      oidset_parse_file_carefully().\n          - In build_ignorelist(), ignore-revs entries are processed starting\n            after the last empty string entry. This ensures setting\n            blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n     @@ Commit message\n          add comprehensive test coverage in t8013 for the default blob lookup,\n          subdirectory invocations, bare repositories, uncommitted and untracked\n          working-tree files, CLI and config overrides, committed symlink\n     -    entries, and comments and whitespace handling.\n     +    entries, overly large blobs, and comments and whitespace handling.\n      \n          Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\n          Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n       \t}\n       }\n       \n     ++#define IGNORE_REVS_MAX_FILE_SIZE (100 * 1024 * 1024)\n     ++\n      +static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n      +\t\t\t\t\t   const char *name)\n      +{\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +\tif (!S_ISREG(oc.mode))\n      +\t\tgoto out;\n      +\n     ++\tif (odb_read_object_info(sb->repo->objects, &oid, &size) != OBJ_BLOB)\n     ++\t\tgoto out;\n     ++\tif (size >= IGNORE_REVS_MAX_FILE_SIZE) {\n     ++\t\twarning(_(\"ignoring overly large ignore-revs blob '%s'\"), name);\n     ++\t\tgoto out;\n     ++\t}\n     ++\n      +\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n      +\tif (!buf)\n      +\t\tgoto out;\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +'\n      +\n      +test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n     ++\ttest_when_finished \"rm -f .git-blame-ignore-revs\" &&\n      +\tgit rm -f .git-blame-ignore-revs &&\n      +\ttest_tick &&\n      +\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\tgit rev-parse DEF_B >expect &&\n      +\ttest_cmp expect actual\n      +'\n     ++\n     ++test_expect_success EXPENSIVE 'overly large default HEAD:.git-blame-ignore-revs blob is ignored' '\n     ++\tblob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null |\n     ++\t\tgit hash-object -w --stdin) &&\n     ++\tgit update-index --add --cacheinfo 100644,$blob,.git-blame-ignore-revs &&\n     ++\ttest_tick &&\n     ++\tgit commit -m \"overly large .git-blame-ignore-revs\" &&\n     ++\ttest_when_finished \"git reset --hard HEAD~\" &&\n     ++\tgit blame --line-porcelain def-file >blame_raw 2>err &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_B >expect &&\n     ++\ttest_cmp expect actual &&\n     ++\ttest_grep \"warning: ignoring overly large ignore-revs blob '\\''HEAD:.git-blame-ignore-revs'\\''\" err\n     ++'\n      +\n       test_done\n\n-- \ngitgitgadget\n\n"},{"id":"554798","messageId":"2e12486c0d5dd8b94393b08413a85a8d47f86edd.1791832644.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v4.git.1791832644.gitgitgadget@gmail.com","subject":"[PATCH v4 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-12T19:17:23Z","receivedAt":"2026-10-12T19:17:23Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\nCurrently, blame.ignoreRevsFile and --ignore-revs-file only read paths\nexplicitly configured by the user, which cannot point to an\nattacker-controlled file under Git's threat model. An upcoming commit\nwill teach git-blame(1) and git-annotate(1) to automatically read the\nHEAD:.git-blame-ignore-revs blob by default if it exists, exposing the\nignore-revs parser (oidset_parse_file_carefully() in oidset.c) and its\ntag-peeling callback (peel_to_commit_oid() in builtin/blame.c) to\nupstream-controlled content at a well-known path.\n\nHarden both code paths before enabling the default blob:\n\n- In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n  next newline and records the full line length in sb.len, including\n  any embedded NUL bytes. However, strchr(sb.buf, '#') and\n  parse_oid_hex_algop(sb.buf, &oid, &p, algop) treat sb.buf as a\n  NUL-terminated string. If a line contains an embedded NUL byte after\n  a valid object name (such as \"<oid>\\0garbage\" or \"<oid>\\0# comment\"),\n  *p is '\\0' and trailing bytes on the line are silently ignored.\n  Reject any line containing an embedded NUL byte via memchr() before\n  stripping comments and whitespace.\n- In peel_to_commit_oid(), odb_read_object_info() is called without\n  OBJECT_INFO_SKIP_FETCH_OBJECT or OBJECT_INFO_QUICK, and deref_tag()\n  calls parse_object() on tag targets without checking whether the\n  target object exists locally first. In a partial clone, any missing\n  commit OID or tag target listed in the ignore-revs file would trigger\n  lazy promisor fetches and pack directory rescans during git-blame(1).\n  Use odb_read_object_info_extended() with OBJECT_INFO_LOOKUP_REPLACE |\n  OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK and peel OBJ_TAG\n  objects one layer per iteration, verifying that each target object\n  exists locally and matches the tag's declared type before parsing it.\n\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n builtin/blame.c              | 20 +++++++++++++++++--\n oidset.c                     |  3 +++\n t/t8013-blame-ignore-revs.sh | 38 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 59 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 48d5251c6d..6741a7b9df 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -911,21 +911,37 @@ static int is_a_rev(const char *name)\n static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n {\n \tstruct repository *r = ((struct blame_scoreboard *)cbdata)->repo;\n+\tenum object_type expected_type = OBJ_ANY;\n \tstruct object_id oid;\n \n \toidcpy(&oid, oid_ret);\n \twhile (1) {\n+\t\tunsigned flags = OBJECT_INFO_LOOKUP_REPLACE |\n+\t\t\t\t OBJECT_INFO_SKIP_FETCH_OBJECT |\n+\t\t\t\t OBJECT_INFO_QUICK;\n+\t\tstruct object_info oi = OBJECT_INFO_INIT;\n+\t\tenum object_type kind;\n \t\tstruct object *obj;\n-\t\tint kind = odb_read_object_info(r->objects, &oid, NULL);\n+\n+\t\toi.typep = &kind;\n+\t\tif (odb_read_object_info_extended(r->objects, &oid, &oi,\n+\t\t\t\t\t\t  flags) < 0)\n+\t\t\treturn -1;\n+\t\tif (expected_type != OBJ_ANY && kind != expected_type)\n+\t\t\treturn -1;\n \t\tif (kind == OBJ_COMMIT) {\n \t\t\toidcpy(oid_ret, &oid);\n \t\t\treturn 0;\n \t\t}\n \t\tif (kind != OBJ_TAG)\n \t\t\treturn -1;\n-\t\tobj = deref_tag(r, parse_object(r, &oid), NULL, 0);\n+\t\tobj = parse_object(r, &oid);\n+\t\tif (!obj || obj->type != OBJ_TAG)\n+\t\t\treturn -1;\n+\t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\treturn -1;\n+\t\texpected_type = obj->type;\n \t\toidcpy(&oid, &obj->oid);\n \t}\n }\ndiff --git a/oidset.c b/oidset.c\nindex c8ff0b385c..90d39204d3 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -85,6 +85,9 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\tconst char *p;\n \t\tconst char *name;\n \n+\t\tif (memchr(sb.buf, '\\0', sb.len))\n+\t\t\tdie(\"invalid object name: %s\", sb.buf);\n+\n \t\t/*\n \t\t * Allow trailing comments, leading whitespace\n \t\t * (including before commits), and empty or whitespace\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex cace00ae8d..70fe509a64 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -327,4 +327,42 @@ test_expect_success ignore_merge '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'ignore-revs-file rejects lines with embedded NUL bytes' '\n+\trev_b=$(git rev-parse B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_b\" | q_to_nul >ignore_nul &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul 2>err &&\n+\ttest_grep \"invalid object name:\" err &&\n+\n+\tprintf \"%sQ# comment\\n\" \"$rev_b\" | q_to_nul >ignore_nul_comment &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul_comment 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'ignore-revs-file peels chained tags and skips missing tag targets' '\n+\ttest_write_lines BB L2-modified L3 L4 L5 L6 L7 L8 CC >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m D &&\n+\tgit tag -a -m \"tag 1\" D_TAG1 HEAD &&\n+\tgit tag -a -m \"tag 2\" D_TAG2 D_TAG1 &&\n+\tgit rev-parse D_TAG2 >ignore_tag_chain &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_tag_chain >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\ttest_config extensions.partialClone origin &&\n+\ttest_config remote.origin.promisor true &&\n+\ttest_config remote.origin.url /nonexistent &&\n+\tmissing_oid=$(test_oid deadbeef) &&\n+\tbad_tag=$(printf \"object %s\\ntype commit\\ntag bad-tag\\ntagger T <t@example.com> 0 +0000\\n\\nmsg\\n\" \"$missing_oid\" |\n+\t\tgit hash-object -t tag -w --stdin) &&\n+\ttest_write_lines \"$missing_oid\" \"$bad_tag\" >ignore_bad_tag &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_bad_tag >blame_raw 2>err &&\n+\ttest_must_be_empty err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse HEAD >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n\n"},{"id":"554799","messageId":"76d597dfa803eb19e7274e0980fb02917fb8d5fd.1791832644.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v4.git.1791832644.gitgitgadget@gmail.com","subject":"[PATCH v4 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-12T19:17:24Z","receivedAt":"2026-10-12T19:17:24Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\ngit-blame(1) can ignore a list of commits specified via\n--ignore-revs-file or the blame.ignoreRevsFile configuration option.\nThis is useful for skipping uninteresting revisions such as tree-wide\nformatting changes, large-scale refactors, and code modernizations that\nwould otherwise obscure genuine historical authorship.\n\nWhen revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\nblame.ignoreRevsFile config option\", 2019-10-18), it intentionally\navoided adopting a default ignore file. At the time, the capability was\nnew and unproven, so avoiding unrequested filesystem I/O or unexpected\nattribution shifts took priority over a project-wide default.\nRequiring explicit opt-in per clone was therefore the prudent design.\n\nSince then, maintaining a .git-blame-ignore-revs file in the repository\nroot has become the de facto standard across the Git ecosystem, adopted\nby major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\nsource projects (such as Chromium and LLVM). As a consequence,\ndevelopers frequently encounter a jarring mismatch: web interfaces\nseamlessly ignore formatting commits, but local git-blame(1) and\ngit-annotate(1) runs do not, unless each user manually configures\nblame.ignoreRevsFile for every local checkout.\n\nTeach git-blame(1) and git-annotate(1) to automatically add the\nHEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\nin the list of ignore-revs files in both bare and non-bare\nrepositories. Reading the committed blob from HEAD rather than the\nworking tree ensures that local runs match hosting platforms even when\nan untracked .git-blame-ignore-revs file is present or a tracked one\nhas uncommitted local changes.\n\nTo ensure consistent precedence and override semantics:\n- The default HEAD:.git-blame-ignore-revs entry is added before reading\n  configuration and CLI options, preserving user and repository config\n  overrides.\n- In git_blame_config(), blame.ignoreRevsFile entries are appended via\n  string_list_append() rather than inserted in sorted order via\n  string_list_insert() so that configuration entries preserve their\n  order relative to the initial default entry.\n- The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n  get_oid_with_context(). Its mode is checked with S_ISREG() before\n  reading the object so that non-regular tree entries (such as a\n  committed symbolic link whose blob stores a target path rather than\n  revision IDs, a subdirectory, or a gitlink) are skipped instead of\n  being read and rejected as malformed object names. Its size is checked\n  via odb_read_object_info() and capped at IGNORE_REVS_MAX_FILE_SIZE\n  (100MB, matching ATTR_MAX_FILE_SIZE from 3c50032ff5 (\"attr: ignore\n  overly large gitattributes files\", 2022-12-01)) so an oversized blob\n  is skipped with a warning without being loaded into memory. The blob\n  is parsed in memory via a new oidset_parse_buffer_carefully() helper\n  in oidset.c that shares line parsing with\n  oidset_parse_file_carefully().\n- In build_ignorelist(), ignore-revs entries are processed starting\n  after the last empty string entry. This ensures setting\n  blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n  --no-ignore-revs-file cleanly discards the default blob without\n  attempting to read or parse it, allowing users to bypass a malformed\n  default blob.\n\nUpdate documentation in blame-options.adoc and config/blame.adoc, and\nadd comprehensive test coverage in t8013 for the default blob lookup,\nsubdirectory invocations, bare repositories, uncommitted and untracked\nworking-tree files, CLI and config overrides, committed symlink\nentries, overly large blobs, and comments and whitespace handling.\n\nBased-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\nHelped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\nHelped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n Documentation/blame-options.adoc |   8 +-\n Documentation/config/blame.adoc  |   9 +-\n builtin/blame.c                  |  54 ++++++++-\n oidset.c                         |  84 +++++++++----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 197 +++++++++++++++++++++++++++++++\n 6 files changed, 325 insertions(+), 36 deletions(-)\n\ndiff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\nindex 1ae1222b6b..8d59dcc8f3 100644\n--- a/Documentation/blame-options.adoc\n+++ b/Documentation/blame-options.adoc\n@@ -132,9 +132,11 @@ take effect.\n `--ignore-revs-file <file>`::\n \tIgnore revisions listed in _<file>_, which must be in the same format as an\n \t`fsck.skipList`.  This option may be repeated, and these files will be\n-\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n-\toption.  An empty file name, `\"\"`, will clear the list of revs from\n-\tpreviously processed files.\n+\tprocessed after the default `HEAD:.git-blame-ignore-revs` blob (if it\n+\texists) and any files specified with the `blame.ignoreRevsFile` config\n+\toption.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will clear\n+\tthe list of revs from previously processed files, including the default\n+\t`HEAD:.git-blame-ignore-revs` blob.\n \n `--color-lines`::\n \tColor line annotations in the default format differently if they come from\ndiff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\nindex 4d047c1790..153d4ab524 100644\n--- a/Documentation/config/blame.adoc\n+++ b/Documentation/config/blame.adoc\n@@ -23,9 +23,12 @@ blame.showRoot::\n blame.ignoreRevsFile::\n \tIgnore revisions listed in the file, one unabbreviated object name per\n \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n-\t`#` are ignored.  This option may be repeated multiple times.  Empty\n-\tfile names will reset the list of ignored revisions.  This option will\n-\tbe handled before the command line option `--ignore-revs-file`.\n+\t`#` are ignored.  If the `HEAD:.git-blame-ignore-revs` blob exists, it\n+\tis added as the initial element in the list of ignore-revs files.\n+\tOther files listed in the configuration are also used, but an empty\n+\telement makes all elements that appeared before in the list forgotten.\n+\tThis option will be handled before the command line option\n+\t`--ignore-revs-file`.\n \n blame.markUnblamableLines::\n \tMark lines that were changed by an ignored revision that we could not\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 6741a7b9df..13a9dcc2e7 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -769,7 +769,7 @@ static int git_blame_config(const char *var, const char *value,\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tif (str)\n-\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n+\t\t\tstring_list_append(&ignore_revs_file_list, str);\n \t\tfree(str);\n \t\treturn 0;\n \t}\n@@ -946,17 +946,61 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n \t}\n }\n \n+#define IGNORE_REVS_MAX_FILE_SIZE (100 * 1024 * 1024)\n+\n+static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *name)\n+{\n+\tstruct object_context oc;\n+\tstruct object_id oid;\n+\tenum object_type type;\n+\tsize_t size;\n+\tchar *buf;\n+\n+\tif (get_oid_with_context(sb->repo, name, GET_OID_QUIETLY,\n+\t\t\t\t &oid, &oc))\n+\t\tgoto out;\n+\tif (!S_ISREG(oc.mode))\n+\t\tgoto out;\n+\n+\tif (odb_read_object_info(sb->repo->objects, &oid, &size) != OBJ_BLOB)\n+\t\tgoto out;\n+\tif (size >= IGNORE_REVS_MAX_FILE_SIZE) {\n+\t\twarning(_(\"ignoring overly large ignore-revs blob '%s'\"), name);\n+\t\tgoto out;\n+\t}\n+\n+\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n+\tif (!buf)\n+\t\tgoto out;\n+\tif (type == OBJ_BLOB)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      sb->repo->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\tfree(buf);\n+\n+out:\n+\tobject_context_release(&oc);\n+}\n+\n static void build_ignorelist(struct blame_scoreboard *sb,\n \t\t\t     struct string_list *ignore_revs_file_list,\n \t\t\t     struct string_list *ignore_rev_list)\n {\n \tstruct string_list_item *i;\n \tstruct object_id oid;\n+\tsize_t start_idx = 0, idx;\n+\n+\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tif (!*ignore_revs_file_list->items[idx].string)\n+\t\t\tstart_idx = idx + 1;\n+\t}\n \n \toidset_init(&sb->ignore_list, 0);\n-\tfor_each_string_list_item(i, ignore_revs_file_list) {\n-\t\tif (!strcmp(i->string, \"\"))\n-\t\t\toidset_clear(&sb->ignore_list);\n+\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n+\t\ti = &ignore_revs_file_list->items[idx];\n+\t\tif (i->util)\n+\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n \t\telse\n \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n \t\t\t\t\t\t    the_repository->hash_algo,\n@@ -1036,6 +1080,8 @@ int cmd_blame(int argc,\n \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n \n \tsetup_default_color_by_age();\n+\tstring_list_append(&ignore_revs_file_list,\n+\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n \trepo_config(the_repository, git_blame_config, &output_option);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \trevs.date_mode = blame_date_mode;\ndiff --git a/oidset.c b/oidset.c\nindex 90d39204d3..8469d03b9b 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n }\n \n+static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n+\t\t\t      const struct git_hash_algo *algop,\n+\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tconst char *p;\n+\tconst char *name;\n+\tstruct object_id oid;\n+\n+\tif (memchr(sb->buf, '\\0', sb->len))\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\n+\t/*\n+\t * Allow trailing comments, leading whitespace\n+\t * (including before commits), and empty or whitespace\n+\t * only lines.\n+\t */\n+\tname = strchr(sb->buf, '#');\n+\tif (name)\n+\t\tstrbuf_setlen(sb, name - sb->buf);\n+\tstrbuf_trim(sb);\n+\tif (!sb->len)\n+\t\treturn;\n+\n+\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\tif (fn && fn(&oid, cbdata))\n+\t\treturn;\n+\toidset_insert(set, &oid);\n+}\n+\n void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n {\n \tFILE *fp;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tstruct object_id oid;\n \n \tfp = fopen(path, \"r\");\n \tif (!fp)\n \t\tdie(\"could not open object name list: %s\", path);\n-\twhile (!strbuf_getline(&sb, fp)) {\n-\t\tconst char *p;\n-\t\tconst char *name;\n-\n-\t\tif (memchr(sb.buf, '\\0', sb.len))\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\n-\t\t/*\n-\t\t * Allow trailing comments, leading whitespace\n-\t\t * (including before commits), and empty or whitespace\n-\t\t * only lines.\n-\t\t */\n-\t\tname = strchr(sb.buf, '#');\n-\t\tif (name)\n-\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n-\t\tstrbuf_trim(&sb);\n-\t\tif (!sb.len)\n-\t\t\tcontinue;\n-\n-\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\t\tif (fn && fn(&oid, cbdata))\n-\t\t\tcontinue;\n-\t\toidset_insert(set, &oid);\n-\t}\n+\twhile (!strbuf_getline(&sb, fp))\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n \tif (ferror(fp))\n \t\tdie_errno(\"Could not read '%s'\", path);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n }\n+\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tconst char *p = buf, *end;\n+\n+\tif (!size)\n+\t\treturn;\n+\tend = buf + size;\n+\n+\twhile (p < end) {\n+\t\tconst char *nl = memchr(p, '\\n', end - p);\n+\t\tsize_t len = (nl ? nl : end) - p;\n+\n+\t\tstrbuf_reset(&sb);\n+\t\tif (len && p[len - 1] == '\\r')\n+\t\t\tlen--;\n+\t\tstrbuf_add(&sb, p, len);\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n+\t\tp = nl ? nl + 1 : end;\n+\t}\n+\tstrbuf_release(&sb);\n+}\ndiff --git a/oidset.h b/oidset.h\nindex e0f1a6ff4f..667c390842 100644\n--- a/oidset.h\n+++ b/oidset.h\n@@ -98,6 +98,15 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n \n+/*\n+ * Similar to oidset_parse_file_carefully(), but parses lines from an\n+ * in-memory buffer of 'size' bytes.\n+ */\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n+\n struct oidset_iter {\n \tconst kh_oid_set_t *set;\n \tkhiter_t iter;\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex 70fe509a64..f2eae809cb 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -365,4 +365,201 @@ test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n \ttest_cmp expect actual\n '\n \n+# Tests for default HEAD:.git-blame-ignore-revs blob\n+test_expect_success 'setup default HEAD:.git-blame-ignore-revs' '\n+\tgit checkout -b default-file-branch &&\n+\ttest_write_lines line1 line2 >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default base\" &&\n+\tgit tag DEF_A &&\n+\n+\ttest_write_lines line1-modified line2-modified >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default mod\" &&\n+\tgit tag DEF_B &&\n+\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"add .git-blame-ignore-revs\"\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs is used by default' '\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected by git annotate' '\n+\tgit rev-parse --short DEF_A >expect_sha &&\n+\tgit annotate def-file >actual &&\n+\ttest_grep \"^$(cat expect_sha)\" actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs works from subdirectory' '\n+\tmkdir -p sub &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n+\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\t\tgit rev-parse DEF_A >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\tgit clone --bare . bare.git &&\n+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are ignored' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --no-ignore-revs-file' '\n+\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --ignore-revs-file \"\"' '\n+\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n+\ttest_config blame.ignoreRevsFile \"\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs handles comments and whitespace' '\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\t{\n+\t\techo \"# Leading comment\" &&\n+\t\techo \"\" &&\n+\t\techo \"   $rev_def_b   # inline comment\" &&\n+\t\techo \"# Trailing comment\"\n+\t} >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'empty default HEAD:.git-blame-ignore-revs is harmless' '\n+\t: >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'committed symlink .git-blame-ignore-revs in HEAD is ignored' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\tgit rev-parse DEF_B >target_file &&\n+\ttest_ln_s_add target_file .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'malformed default HEAD:.git-blame-ignore-revs fails but can be bypassed' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file &&\n+\tgit blame --no-ignore-revs-file def-file &&\n+\tgit blame --ignore-revs-file \"\" def-file &&\n+\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n+\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\ttest_write_lines line1-modified line2-c >def-file &&\n+\tgit add .git-blame-ignore-revs def-file &&\n+\ttest_tick &&\n+\tgit commit -m C &&\n+\tgit tag DEF_C &&\n+\tgit rev-parse DEF_C >custom_ignore &&\n+\ttest_config blame.ignoreRevsFile custom_ignore &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n+\ttest_when_finished \"rm -f .git-blame-ignore-revs\" &&\n+\tgit rm -f .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success EXPENSIVE 'overly large default HEAD:.git-blame-ignore-revs blob is ignored' '\n+\tblob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null |\n+\t\tgit hash-object -w --stdin) &&\n+\tgit update-index --add --cacheinfo 100644,$blob,.git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"overly large .git-blame-ignore-revs\" &&\n+\ttest_when_finished \"git reset --hard HEAD~\" &&\n+\tgit blame --line-porcelain def-file >blame_raw 2>err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"warning: ignoring overly large ignore-revs blob '\\''HEAD:.git-blame-ignore-revs'\\''\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"554801","messageId":"20261012192157.1835972-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqbj8yan77.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-12T19:21:57Z","receivedAt":"2026-10-12T19:21:57Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Phillip Wood <phillip.wood123@gmail.com> writes:\n>\n> > I've left a couple of comments on v3. Ignoring uncommitted changes in\n> > the file in the working tree seems a bit odd to me and we seem to be\n> > prepared to load a file of any size from an untrusted source.\n>\n> The latter sounds like a sensible thing to worry about.  Thanks for\n> bringing it up.\n>\n> I do not have strong opinions either way on the former myself (the\n> behaviour implemented is to attempt matching what the hosting sites\n> do, which obviously work from the committed copy).  It indeed feels\n> more intuitive if the checked out copy (or even the file before it\n> gets added for the first time) were consulted.\n\nI have sent v4, which caps the size of the default\nHEAD:.git-blame-ignore-revs blob at 100MB (matching ATTR_MAX_FILE_SIZE\nfrom 3c50032ff5 (\"attr: ignore overly large gitattributes files\",\n2022-12-01)) so an oversized blob is skipped with a warning without\nbeing loaded into memory.\n\nFor v4, I left the behavior as reading from HEAD:.git-blame-ignore-revs\nto match hosting sites for now. Maybe consulting the working tree could\nbe explored in the future in a separate series if desired, or please let\nme know if you or Phillip would prefer to change it in this series.\n\nThanks!\n\n"},{"id":"554812","messageId":"xmqqwlrm4o6z.fsf@gitster.g","threadId":"66313","inReplyTo":"20261012192157.1835972-1-rmistry@google.com","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-12T21:13:40Z","receivedAt":"2026-10-12T21:13:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ravi Mistry <rmistry@google.com> writes:\n\n> For v4, I left the behavior as reading from HEAD:.git-blame-ignore-revs\n> to match hosting sites for now. Maybe consulting the working tree could\n> be explored in the future in a separate series if desired, or please let\n> me know if you or Phillip would prefer to change it in this series.\n\nIt needs to be justified in some way other than \"match what the\nforges do (which is to use the one from HEAD)\", but other than that,\nI think it would be more ergonomic to pick up the copy from the\nworking tree (with local modifications) in non-bare case.\n\nThanks.\n\n"},{"id":"554865","messageId":"pull.2224.v5.git.1791902175.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"[PATCH v5 0/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-13T14:36:13Z","receivedAt":"2026-10-13T14:36:13Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"This series teaches git-blame(1) and git-annotate(1) to automatically use\n.git-blame-ignore-revs at the root of the working tree (or\nHEAD:.git-blame-ignore-revs in bare repositories) by default if it exists,\nwithout requiring manual blame.ignoreRevsFile configuration in every clone.\nThis restarts the stalled attempt in PR\nhttps://github.com/gitgitgadget/git/pull/1809\n(https://lore.kernel.org/git/pull.1809.v2.git.1728707867.gitgitgadget@gmail.com/)\nand addresses https://github.com/gitgitgadget/git/issues/1494.\n\nChanges since v4:\n\n * In non-bare repositories, Patch 2/2 now reads .git-blame-ignore-revs from\n   the root of the working tree (using open_nofollow(), S_ISREG(), and\n   IGNORE_REVS_MAX_FILE_SIZE) instead of HEAD:.git-blame-ignore-revs, while\n   continuing to use HEAD:.git-blame-ignore-revs in bare repositories\n   (matching the .mailmap model in read_mailmap()). This makes it ergonomic\n   to test uncommitted or untracked changes to .git-blame-ignore-revs\n   locally before committing.\n * Updated the commit messages and documentation to justify the default\n   lookup and working-tree behavior on ergonomic grounds.\n\nChanges since v3:\n\n * Patch 2/2 caps the size of the default HEAD:.git-blame-ignore-revs blob\n   at IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from\n   3c50032ff5 (\"attr: ignore overly large gitattributes files\", 2022-12-01))\n   via odb_read_object_info() before calling odb_read_object(), skipping\n   oversized blobs with a warning without loading them into memory.\n\nChanges since v2:\n\n * Patch 2/2 uses sb->repo instead of the_repository in\n   parse_default_ignore_revs_blob().\n\nChanges since v1:\n\n * Split the series into two commits.\n * Patch 1/2 hardens oidset_parse_file_carefully() in oidset.c and\n   peel_to_commit_oid() in builtin/blame.c before exposing them to\n   upstream-controlled content at a well-known path:\n   * Reject lines containing embedded NUL bytes via memchr() so trailing\n     bytes after a NUL cannot be silently ignored.\n   * Pass OBJECT_INFO_LOOKUP_REPLACE | OBJECT_INFO_SKIP_FETCH_OBJECT |\n     OBJECT_INFO_QUICK to odb_read_object_info_extended() and peel tags one\n     layer per iteration so missing OIDs or tag targets do not trigger lazy\n     promisor fetches or pack directory rescans in partial clones, and\n     verify that each peeled target matches the tag's declared type.\n * Patch 2/2 reads the committed HEAD:.git-blame-ignore-revs blob (in both\n   bare and non-bare repositories) instead of reading a file from the\n   working tree, matching hosting platforms even when an untracked file is\n   present or a tracked one has local modifications. The tree entry is\n   checked with S_ISREG() so non-regular entries (such as committed\n   symlinks) are skipped, parsed in memory via\n   oidset_parse_buffer_carefully(), and bypassed without reading if cleared\n   via blame.ignoreRevsFile=\"\" or --no-ignore-revs-file.\n\nRavi Mistry (2):\n  blame: harden ignore-revs parser and tag peeling\n  blame: ignore revs in .git-blame-ignore-revs by default\n\n Documentation/blame-options.adoc |   9 +-\n Documentation/config/blame.adoc  |  10 +-\n builtin/blame.c                  | 115 ++++++++++++-\n oidset.c                         |  81 ++++++---\n oidset.h                         |   9 +\n t/t8013-blame-ignore-revs.sh     | 271 +++++++++++++++++++++++++++++++\n 6 files changed, 460 insertions(+), 35 deletions(-)\n\n\nbase-commit: fa7f9290efe2bd22dd736689597b474b93798e11\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2224%2Frmistry%2Fblame-default-ignore-revs-v5\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2224/rmistry/blame-default-ignore-revs-v5\nPull-Request: https://github.com/gitgitgadget/git/pull/2224\n\nRange-diff vs v4:\n\n 1:  2e12486c0d ! 1:  e9b2c1dae2 blame: harden ignore-revs parser and tag peeling\n     @@ Commit message\n          Currently, blame.ignoreRevsFile and --ignore-revs-file only read paths\n          explicitly configured by the user, which cannot point to an\n          attacker-controlled file under Git's threat model. An upcoming commit\n     -    will teach git-blame(1) and git-annotate(1) to automatically read the\n     -    HEAD:.git-blame-ignore-revs blob by default if it exists, exposing the\n     +    will teach git-blame(1) and git-annotate(1) to automatically read\n     +    .git-blame-ignore-revs by default if it exists, exposing the\n          ignore-revs parser (oidset_parse_file_carefully() in oidset.c) and its\n          tag-peeling callback (peel_to_commit_oid() in builtin/blame.c) to\n          upstream-controlled content at a well-known path.\n      \n     -    Harden both code paths before enabling the default blob:\n     +    Harden both code paths before enabling the default ignore-revs file:\n      \n          - In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n            next newline and records the full line length in sb.len, including\n 2:  76d597dfa8 ! 2:  605eb049a1 blame: ignore revs in HEAD:.git-blame-ignore-revs\n     @@ Metadata\n      Author: Ravi Mistry <rmistry@google.com>\n      \n       ## Commit message ##\n     -    blame: ignore revs in HEAD:.git-blame-ignore-revs\n     +    blame: ignore revs in .git-blame-ignore-revs by default\n      \n          git-blame(1) can ignore a list of commits specified via\n          --ignore-revs-file or the blame.ignoreRevsFile configuration option.\n     @@ Commit message\n          attribution shifts took priority over a project-wide default.\n          Requiring explicit opt-in per clone was therefore the prudent design.\n      \n     -    Since then, maintaining a .git-blame-ignore-revs file in the repository\n     -    root has become the de facto standard across the Git ecosystem, adopted\n     -    by major hosting platforms (GitHub, GitLab, Gerrit) and prominent open\n     -    source projects (such as Chromium and LLVM). As a consequence,\n     -    developers frequently encounter a jarring mismatch: web interfaces\n     -    seamlessly ignore formatting commits, but local git-blame(1) and\n     -    git-annotate(1) runs do not, unless each user manually configures\n     -    blame.ignoreRevsFile for every local checkout.\n     +    Since then, maintaining a .git-blame-ignore-revs file at the top level\n     +    of the repository has become the standard convention across the Git\n     +    ecosystem, adopted by many open source projects (such as Chromium and\n     +    LLVM) as well as hosting platforms (GitHub, GitLab, Gerrit). However,\n     +    git-blame(1) and git-annotate(1) still ignore this file unless each\n     +    user remembers to manually configure blame.ignoreRevsFile in every\n     +    local clone.\n      \n     -    Teach git-blame(1) and git-annotate(1) to automatically add the\n     -    HEAD:.git-blame-ignore-revs blob, if it exists, as the initial element\n     -    in the list of ignore-revs files in both bare and non-bare\n     -    repositories. Reading the committed blob from HEAD rather than the\n     -    working tree ensures that local runs match hosting platforms even when\n     -    an untracked .git-blame-ignore-revs file is present or a tracked one\n     -    has uncommitted local changes.\n     +    Teach git-blame(1) and git-annotate(1) to automatically add\n     +    .git-blame-ignore-revs, if it exists, as the initial element in the\n     +    list of ignore-revs files. Similar to how read_mailmap() handles\n     +    .mailmap, consult .git-blame-ignore-revs at the root of the working\n     +    tree when a working tree is available and fall back to the\n     +    HEAD:.git-blame-ignore-revs blob in bare repositories. Reading from the\n     +    working tree in non-bare repositories makes it ergonomic to prepare a\n     +    new .git-blame-ignore-revs file or add revisions to an existing one and\n     +    immediately test the effect with git-blame(1) before committing, while\n     +    falling back to HEAD:.git-blame-ignore-revs allows bare repositories to\n     +    respect the committed ignore list as well.\n      \n     -    To ensure consistent precedence and override semantics:\n     -    - The default HEAD:.git-blame-ignore-revs entry is added before reading\n     +    To ensure consistent precedence, override semantics, and safety when\n     +    reading upstream-controlled content:\n     +    - The default .git-blame-ignore-revs entry is added before reading\n            configuration and CLI options, preserving user and repository config\n            overrides.\n          - In git_blame_config(), blame.ignoreRevsFile entries are appended via\n            string_list_append() rather than inserted in sorted order via\n            string_list_insert() so that configuration entries preserve their\n            order relative to the initial default entry.\n     -    - The HEAD:.git-blame-ignore-revs tree entry is resolved quietly via\n     -      get_oid_with_context(). Its mode is checked with S_ISREG() before\n     -      reading the object so that non-regular tree entries (such as a\n     -      committed symbolic link whose blob stores a target path rather than\n     -      revision IDs, a subdirectory, or a gitlink) are skipped instead of\n     -      being read and rejected as malformed object names. Its size is checked\n     -      via odb_read_object_info() and capped at IGNORE_REVS_MAX_FILE_SIZE\n     -      (100MB, matching ATTR_MAX_FILE_SIZE from 3c50032ff5 (\"attr: ignore\n     -      overly large gitattributes files\", 2022-12-01)) so an oversized blob\n     -      is skipped with a warning without being loaded into memory. The blob\n     -      is parsed in memory via a new oidset_parse_buffer_carefully() helper\n     -      in oidset.c that shares line parsing with\n     -      oidset_parse_file_carefully().\n     +    - When a working tree is present, the working-tree\n     +      .git-blame-ignore-revs path is checked with lstat() and S_ISREG(),\n     +      opened with open_nofollow(), and verified with fstat() and S_ISREG()\n     +      so symbolic links and non-regular files are silently skipped. In bare\n     +      repositories, HEAD:.git-blame-ignore-revs is resolved quietly via\n     +      get_oid_with_context() and its tree entry mode is checked with\n     +      S_ISREG() before checking the object.\n     +    - In both modes, the file or blob size is capped at\n     +      IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from\n     +      3c50032ff5 (\"attr: ignore overly large gitattributes files\",\n     +      2022-12-01)) before reading its contents, skipping an oversized file\n     +      or blob with a warning without loading it into memory. The contents\n     +      are parsed via a new oidset_parse_buffer_carefully() helper in\n     +      oidset.c that shares line parsing with oidset_parse_file_carefully().\n          - In build_ignorelist(), ignore-revs entries are processed starting\n            after the last empty string entry. This ensures setting\n            blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n     -      --no-ignore-revs-file cleanly discards the default blob without\n     +      --no-ignore-revs-file cleanly discards the default entry without\n            attempting to read or parse it, allowing users to bypass a malformed\n     -      default blob.\n     +      default ignore-revs file.\n      \n          Update documentation in blame-options.adoc and config/blame.adoc, and\n     -    add comprehensive test coverage in t8013 for the default blob lookup,\n     -    subdirectory invocations, bare repositories, uncommitted and untracked\n     -    working-tree files, CLI and config overrides, committed symlink\n     -    entries, overly large blobs, and comments and whitespace handling.\n     +    add test coverage in t8013 for the default working-tree lookup,\n     +    uncommitted and untracked .git-blame-ignore-revs files, subdirectory\n     +    invocations, bare repositories, CLI and config overrides, symbolic\n     +    links, overly large files and blobs, and comments and whitespace\n     +    handling.\n      \n          Based-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\n          Helped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\n     @@ Documentation/blame-options.adoc: take effect.\n      -\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n      -\toption.  An empty file name, `\"\"`, will clear the list of revs from\n      -\tpreviously processed files.\n     -+\tprocessed after the default `HEAD:.git-blame-ignore-revs` blob (if it\n     -+\texists) and any files specified with the `blame.ignoreRevsFile` config\n     -+\toption.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will clear\n     -+\tthe list of revs from previously processed files, including the default\n     -+\t`HEAD:.git-blame-ignore-revs` blob.\n     ++\tprocessed after the default `.git-blame-ignore-revs` file at the root of\n     ++\tthe working tree (or `HEAD:.git-blame-ignore-revs` in a bare repository),\n     ++\tif it exists, and any files specified with the `blame.ignoreRevsFile`\n     ++\tconfig option.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will\n     ++\tclear the list of revs from previously processed files, including the\n     ++\tdefault ignore-revs file.\n       \n       `--color-lines`::\n       \tColor line annotations in the default format differently if they come from\n     @@ Documentation/config/blame.adoc: blame.showRoot::\n      -\t`#` are ignored.  This option may be repeated multiple times.  Empty\n      -\tfile names will reset the list of ignored revisions.  This option will\n      -\tbe handled before the command line option `--ignore-revs-file`.\n     -+\t`#` are ignored.  If the `HEAD:.git-blame-ignore-revs` blob exists, it\n     ++\t`#` are ignored.  If `.git-blame-ignore-revs` exists at the root of the\n     ++\tworking tree (or `HEAD:.git-blame-ignore-revs` in a bare repository), it\n      +\tis added as the initial element in the list of ignore-revs files.\n      +\tOther files listed in the configuration are also used, but an empty\n      +\telement makes all elements that appeared before in the list forgotten.\n     @@ Documentation/config/blame.adoc: blame.showRoot::\n       \tMark lines that were changed by an ignored revision that we could not\n      \n       ## builtin/blame.c ##\n     +@@\n     + #include \"object-name.h\"\n     + #include \"odb.h\"\n     + #include \"pager.h\"\n     ++#include \"path.h\"\n     + #include \"blame.h\"\n     + #include \"refs.h\"\n     + #include \"setup.h\"\n      @@ builtin/blame.c: static int git_blame_config(const char *var, const char *value,\n       \t\tif (ret)\n       \t\t\treturn ret;\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +out:\n      +\tobject_context_release(&oc);\n      +}\n     ++\n     ++static void parse_default_ignore_revs_file(struct blame_scoreboard *sb,\n     ++\t\t\t\t\t   const char *name)\n     ++{\n     ++\tchar *path = repo_worktree_path(sb->repo, \"%s\", name);\n     ++\tstruct stat st;\n     ++\tint fd = -1;\n     ++\tsize_t size;\n     ++\tchar *buf = NULL;\n     ++\n     ++\tif (lstat(path, &st) || !S_ISREG(st.st_mode))\n     ++\t\tgoto out;\n     ++\tfd = open_nofollow(path, O_RDONLY);\n     ++\tif (fd < 0 || fstat(fd, &st) || !S_ISREG(st.st_mode))\n     ++\t\tgoto out;\n     ++\tif (st.st_size >= IGNORE_REVS_MAX_FILE_SIZE) {\n     ++\t\twarning(_(\"ignoring overly large ignore-revs file '%s'\"), name);\n     ++\t\tgoto out;\n     ++\t}\n     ++\tsize = xsize_t(st.st_size);\n     ++\tbuf = xmalloc(size);\n     ++\tif (read_in_full(fd, buf, size) == (ssize_t)size)\n     ++\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n     ++\t\t\t\t\t      sb->repo->hash_algo,\n     ++\t\t\t\t\t      peel_to_commit_oid, sb);\n     ++\n     ++out:\n     ++\tif (fd >= 0)\n     ++\t\tclose(fd);\n     ++\tfree(buf);\n     ++\tfree(path);\n     ++}\n     ++\n     ++static void parse_default_ignore_revs(struct blame_scoreboard *sb)\n     ++{\n     ++\tif (repo_get_work_tree(sb->repo))\n     ++\t\tparse_default_ignore_revs_file(sb, \".git-blame-ignore-revs\");\n     ++\telse\n     ++\t\tparse_default_ignore_revs_blob(sb, \"HEAD:.git-blame-ignore-revs\");\n     ++}\n      +\n       static void build_ignorelist(struct blame_scoreboard *sb,\n       \t\t\t     struct string_list *ignore_revs_file_list,\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n      +\t\ti = &ignore_revs_file_list->items[idx];\n      +\t\tif (i->util)\n     -+\t\t\tparse_default_ignore_revs_blob(sb, i->string);\n     ++\t\t\tparse_default_ignore_revs(sb);\n       \t\telse\n       \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n       \t\t\t\t\t\t    the_repository->hash_algo,\n     @@ builtin/blame.c: int cmd_blame(int argc,\n       \n       \tsetup_default_color_by_age();\n      +\tstring_list_append(&ignore_revs_file_list,\n     -+\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n     ++\t\t\t   \".git-blame-ignore-revs\")->util = &sb;\n       \trepo_config(the_repository, git_blame_config, &output_option);\n       \trepo_init_revisions(the_repository, &revs, NULL);\n       \trevs.date_mode = blame_date_mode;\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n       \ttest_cmp expect actual\n       '\n       \n     -+# Tests for default HEAD:.git-blame-ignore-revs blob\n     -+test_expect_success 'setup default HEAD:.git-blame-ignore-revs' '\n     ++# Tests for default .git-blame-ignore-revs\n     ++test_expect_success 'setup default .git-blame-ignore-revs' '\n      +\tgit checkout -b default-file-branch &&\n      +\ttest_write_lines line1 line2 >def-file &&\n      +\tgit add def-file &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\tgit tag DEF_B &&\n      +\n      +\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n     ++\tgit blame --line-porcelain def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_A >expect &&\n     ++\ttest_cmp expect actual &&\n     ++\n      +\tgit add .git-blame-ignore-revs &&\n      +\ttest_tick &&\n      +\tgit commit -m \"add .git-blame-ignore-revs\"\n      +'\n      +\n     -+test_expect_success 'default HEAD:.git-blame-ignore-revs is used by default' '\n     ++test_expect_success 'default .git-blame-ignore-revs is used by default' '\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_A >expect &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'default HEAD:.git-blame-ignore-revs respected by git annotate' '\n     ++test_expect_success 'default .git-blame-ignore-revs respected by git annotate' '\n      +\tgit rev-parse --short DEF_A >expect_sha &&\n      +\tgit annotate def-file >actual &&\n      +\ttest_grep \"^$(cat expect_sha)\" actual\n      +'\n      +\n     -+test_expect_success 'default HEAD:.git-blame-ignore-revs works from subdirectory' '\n     ++test_expect_success 'default .git-blame-ignore-revs works from subdirectory' '\n     ++\ttest_when_finished \"rm -rf sub\" &&\n      +\tmkdir -p sub &&\n     ++\techo \"invalid-oid-value\" >sub/.git-blame-ignore-revs &&\n      +\t(\n      +\t\tcd sub &&\n      +\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_A >expect &&\n     ++\ttest_cmp expect actual &&\n     ++\n     ++\tgit -C .git blame --line-porcelain HEAD -- def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are ignored' '\n     ++test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are respected' '\n      +\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n     -+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n     ++\t: >.git-blame-ignore-revs &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     -+\tgit rev-parse DEF_A >expect &&\n     -+\ttest_cmp expect actual\n     ++\tgit rev-parse DEF_B >expect &&\n     ++\ttest_cmp expect actual &&\n     ++\n     ++\trm .git-blame-ignore-revs &&\n     ++\tgit blame --line-porcelain def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\ttest_cmp expect actual &&\n     ++\n     ++\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n     ++\ttest_must_fail git blame def-file\n      +'\n      +\n     -+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --no-ignore-revs-file' '\n     ++test_expect_success 'disable default .git-blame-ignore-revs with --no-ignore-revs-file' '\n      +\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with --ignore-revs-file \"\"' '\n     ++test_expect_success 'disable default .git-blame-ignore-revs with --ignore-revs-file \"\"' '\n      +\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'disable default HEAD:.git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n     ++test_expect_success 'disable default .git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n      +\ttest_config blame.ignoreRevsFile \"\" &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'default HEAD:.git-blame-ignore-revs handles comments and whitespace' '\n     ++test_expect_success 'default .git-blame-ignore-revs handles comments and whitespace' '\n      +\trev_def_b=$(git rev-parse DEF_B) &&\n      +\t{\n      +\t\techo \"# Leading comment\" &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'empty default HEAD:.git-blame-ignore-revs is harmless' '\n     ++test_expect_success 'empty default .git-blame-ignore-revs is harmless' '\n      +\t: >.git-blame-ignore-revs &&\n      +\tgit add .git-blame-ignore-revs &&\n      +\ttest_tick &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'committed symlink .git-blame-ignore-revs in HEAD is ignored' '\n     -+\tgit rm -f .git-blame-ignore-revs &&\n     ++test_expect_success SYMLINKS 'symlink .git-blame-ignore-revs in working tree is ignored' '\n     ++\ttest_when_finished \"git checkout -- .git-blame-ignore-revs && rm -f target_file\" &&\n      +\tgit rev-parse DEF_B >target_file &&\n     -+\ttest_ln_s_add target_file .git-blame-ignore-revs &&\n     ++\trm -f .git-blame-ignore-revs &&\n     ++\tln -s target_file .git-blame-ignore-revs &&\n     ++\tgit blame --line-porcelain def-file >blame_raw &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_B >expect &&\n     ++\ttest_cmp expect actual\n     ++'\n     ++\n     ++test_expect_success 'committed symlink .git-blame-ignore-revs in bare repo HEAD is ignored' '\n     ++\ttest_when_finished \"git reset --hard HEAD~ && rm -rf bare-symlink.git\" &&\n     ++\tblob=$(printf \"%s\" \"target_file\" | git hash-object -w --stdin) &&\n     ++\tgit update-index --replace --cacheinfo 120000,$blob,.git-blame-ignore-revs &&\n      +\ttest_tick &&\n      +\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n     -+\tgit blame --line-porcelain def-file >blame_raw &&\n     ++\tgit clone --bare . bare-symlink.git &&\n     ++\tgit -C bare-symlink.git blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'malformed default HEAD:.git-blame-ignore-revs fails but can be bypassed' '\n     ++test_expect_success 'malformed default .git-blame-ignore-revs fails but can be bypassed' '\n      +\tgit rm -f .git-blame-ignore-revs &&\n      +\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n      +\tgit add .git-blame-ignore-revs &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_grep \"invalid object name:\" err\n      +'\n      +\n     -+test_expect_success 'default HEAD:.git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n     ++test_expect_success 'default .git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n      +\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n      +\ttest_write_lines line1-modified line2-c >def-file &&\n      +\tgit add .git-blame-ignore-revs def-file &&\n     @@ t/t8013-blame-ignore-revs.sh: test_expect_success 'ignore-revs-file peels chaine\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success 'blame works when HEAD:.git-blame-ignore-revs does not exist and ignores untracked file' '\n     -+\ttest_when_finished \"rm -f .git-blame-ignore-revs\" &&\n     ++test_expect_success 'blame works when .git-blame-ignore-revs does not exist' '\n      +\tgit rm -f .git-blame-ignore-revs &&\n      +\ttest_tick &&\n      +\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n     -+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n      +\tgit blame --line-porcelain def-file >blame_raw &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n      +\tgit rev-parse DEF_B >expect &&\n      +\ttest_cmp expect actual\n      +'\n      +\n     -+test_expect_success EXPENSIVE 'overly large default HEAD:.git-blame-ignore-revs blob is ignored' '\n     -+\tblob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null |\n     -+\t\tgit hash-object -w --stdin) &&\n     ++test_expect_success EXPENSIVE 'overly large default .git-blame-ignore-revs is ignored' '\n     ++\ttest_when_finished \"rm -f .git-blame-ignore-revs\" &&\n     ++\tdd if=/dev/zero of=.git-blame-ignore-revs bs=1048576 count=101 2>/dev/null &&\n     ++\tgit blame --line-porcelain def-file >blame_raw 2>err &&\n     ++\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     ++\tgit rev-parse DEF_B >expect &&\n     ++\ttest_cmp expect actual &&\n     ++\ttest_grep \"warning: ignoring overly large ignore-revs file '\\''.git-blame-ignore-revs'\\''\" err &&\n     ++\n     ++\tblob=$(git hash-object -w .git-blame-ignore-revs) &&\n     ++\trm -f .git-blame-ignore-revs &&\n      +\tgit update-index --add --cacheinfo 100644,$blob,.git-blame-ignore-revs &&\n      +\ttest_tick &&\n      +\tgit commit -m \"overly large .git-blame-ignore-revs\" &&\n      +\ttest_when_finished \"git reset --hard HEAD~\" &&\n     -+\tgit blame --line-porcelain def-file >blame_raw 2>err &&\n     ++\tgit -C .git blame --line-porcelain HEAD -- def-file >blame_raw 2>err &&\n      +\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n     -+\tgit rev-parse DEF_B >expect &&\n      +\ttest_cmp expect actual &&\n      +\ttest_grep \"warning: ignoring overly large ignore-revs blob '\\''HEAD:.git-blame-ignore-revs'\\''\" err\n      +'\n\n-- \ngitgitgadget\n\n"},{"id":"554866","messageId":"e9b2c1dae2cd11783a66f0afdce53dfad78b43d8.1791902175.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v5.git.1791902175.gitgitgadget@gmail.com","subject":"[PATCH v5 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-13T14:36:14Z","receivedAt":"2026-10-13T14:36:14Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\nCurrently, blame.ignoreRevsFile and --ignore-revs-file only read paths\nexplicitly configured by the user, which cannot point to an\nattacker-controlled file under Git's threat model. An upcoming commit\nwill teach git-blame(1) and git-annotate(1) to automatically read\n.git-blame-ignore-revs by default if it exists, exposing the\nignore-revs parser (oidset_parse_file_carefully() in oidset.c) and its\ntag-peeling callback (peel_to_commit_oid() in builtin/blame.c) to\nupstream-controlled content at a well-known path.\n\nHarden both code paths before enabling the default ignore-revs file:\n\n- In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n  next newline and records the full line length in sb.len, including\n  any embedded NUL bytes. However, strchr(sb.buf, '#') and\n  parse_oid_hex_algop(sb.buf, &oid, &p, algop) treat sb.buf as a\n  NUL-terminated string. If a line contains an embedded NUL byte after\n  a valid object name (such as \"<oid>\\0garbage\" or \"<oid>\\0# comment\"),\n  *p is '\\0' and trailing bytes on the line are silently ignored.\n  Reject any line containing an embedded NUL byte via memchr() before\n  stripping comments and whitespace.\n- In peel_to_commit_oid(), odb_read_object_info() is called without\n  OBJECT_INFO_SKIP_FETCH_OBJECT or OBJECT_INFO_QUICK, and deref_tag()\n  calls parse_object() on tag targets without checking whether the\n  target object exists locally first. In a partial clone, any missing\n  commit OID or tag target listed in the ignore-revs file would trigger\n  lazy promisor fetches and pack directory rescans during git-blame(1).\n  Use odb_read_object_info_extended() with OBJECT_INFO_LOOKUP_REPLACE |\n  OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK and peel OBJ_TAG\n  objects one layer per iteration, verifying that each target object\n  exists locally and matches the tag's declared type before parsing it.\n\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n builtin/blame.c              | 20 +++++++++++++++++--\n oidset.c                     |  3 +++\n t/t8013-blame-ignore-revs.sh | 38 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 59 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 48d5251c6d..6741a7b9df 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -911,21 +911,37 @@ static int is_a_rev(const char *name)\n static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n {\n \tstruct repository *r = ((struct blame_scoreboard *)cbdata)->repo;\n+\tenum object_type expected_type = OBJ_ANY;\n \tstruct object_id oid;\n \n \toidcpy(&oid, oid_ret);\n \twhile (1) {\n+\t\tunsigned flags = OBJECT_INFO_LOOKUP_REPLACE |\n+\t\t\t\t OBJECT_INFO_SKIP_FETCH_OBJECT |\n+\t\t\t\t OBJECT_INFO_QUICK;\n+\t\tstruct object_info oi = OBJECT_INFO_INIT;\n+\t\tenum object_type kind;\n \t\tstruct object *obj;\n-\t\tint kind = odb_read_object_info(r->objects, &oid, NULL);\n+\n+\t\toi.typep = &kind;\n+\t\tif (odb_read_object_info_extended(r->objects, &oid, &oi,\n+\t\t\t\t\t\t  flags) < 0)\n+\t\t\treturn -1;\n+\t\tif (expected_type != OBJ_ANY && kind != expected_type)\n+\t\t\treturn -1;\n \t\tif (kind == OBJ_COMMIT) {\n \t\t\toidcpy(oid_ret, &oid);\n \t\t\treturn 0;\n \t\t}\n \t\tif (kind != OBJ_TAG)\n \t\t\treturn -1;\n-\t\tobj = deref_tag(r, parse_object(r, &oid), NULL, 0);\n+\t\tobj = parse_object(r, &oid);\n+\t\tif (!obj || obj->type != OBJ_TAG)\n+\t\t\treturn -1;\n+\t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\treturn -1;\n+\t\texpected_type = obj->type;\n \t\toidcpy(&oid, &obj->oid);\n \t}\n }\ndiff --git a/oidset.c b/oidset.c\nindex c8ff0b385c..90d39204d3 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -85,6 +85,9 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\tconst char *p;\n \t\tconst char *name;\n \n+\t\tif (memchr(sb.buf, '\\0', sb.len))\n+\t\t\tdie(\"invalid object name: %s\", sb.buf);\n+\n \t\t/*\n \t\t * Allow trailing comments, leading whitespace\n \t\t * (including before commits), and empty or whitespace\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex cace00ae8d..70fe509a64 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -327,4 +327,42 @@ test_expect_success ignore_merge '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'ignore-revs-file rejects lines with embedded NUL bytes' '\n+\trev_b=$(git rev-parse B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_b\" | q_to_nul >ignore_nul &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul 2>err &&\n+\ttest_grep \"invalid object name:\" err &&\n+\n+\tprintf \"%sQ# comment\\n\" \"$rev_b\" | q_to_nul >ignore_nul_comment &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul_comment 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'ignore-revs-file peels chained tags and skips missing tag targets' '\n+\ttest_write_lines BB L2-modified L3 L4 L5 L6 L7 L8 CC >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m D &&\n+\tgit tag -a -m \"tag 1\" D_TAG1 HEAD &&\n+\tgit tag -a -m \"tag 2\" D_TAG2 D_TAG1 &&\n+\tgit rev-parse D_TAG2 >ignore_tag_chain &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_tag_chain >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\ttest_config extensions.partialClone origin &&\n+\ttest_config remote.origin.promisor true &&\n+\ttest_config remote.origin.url /nonexistent &&\n+\tmissing_oid=$(test_oid deadbeef) &&\n+\tbad_tag=$(printf \"object %s\\ntype commit\\ntag bad-tag\\ntagger T <t@example.com> 0 +0000\\n\\nmsg\\n\" \"$missing_oid\" |\n+\t\tgit hash-object -t tag -w --stdin) &&\n+\ttest_write_lines \"$missing_oid\" \"$bad_tag\" >ignore_bad_tag &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_bad_tag >blame_raw 2>err &&\n+\ttest_must_be_empty err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse HEAD >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n\n"},{"id":"554867","messageId":"605eb049a18cdd92e30f049d597ab7dfe217ce92.1791902175.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v5.git.1791902175.gitgitgadget@gmail.com","subject":"[PATCH v5 2/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-13T14:36:15Z","receivedAt":"2026-10-13T14:36:15Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\ngit-blame(1) can ignore a list of commits specified via\n--ignore-revs-file or the blame.ignoreRevsFile configuration option.\nThis is useful for skipping uninteresting revisions such as tree-wide\nformatting changes, large-scale refactors, and code modernizations that\nwould otherwise obscure genuine historical authorship.\n\nWhen revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\nblame.ignoreRevsFile config option\", 2019-10-18), it intentionally\navoided adopting a default ignore file. At the time, the capability was\nnew and unproven, so avoiding unrequested filesystem I/O or unexpected\nattribution shifts took priority over a project-wide default.\nRequiring explicit opt-in per clone was therefore the prudent design.\n\nSince then, maintaining a .git-blame-ignore-revs file at the top level\nof the repository has become the standard convention across the Git\necosystem, adopted by many open source projects (such as Chromium and\nLLVM) as well as hosting platforms (GitHub, GitLab, Gerrit). However,\ngit-blame(1) and git-annotate(1) still ignore this file unless each\nuser remembers to manually configure blame.ignoreRevsFile in every\nlocal clone.\n\nTeach git-blame(1) and git-annotate(1) to automatically add\n.git-blame-ignore-revs, if it exists, as the initial element in the\nlist of ignore-revs files. Similar to how read_mailmap() handles\n.mailmap, consult .git-blame-ignore-revs at the root of the working\ntree when a working tree is available and fall back to the\nHEAD:.git-blame-ignore-revs blob in bare repositories. Reading from the\nworking tree in non-bare repositories makes it ergonomic to prepare a\nnew .git-blame-ignore-revs file or add revisions to an existing one and\nimmediately test the effect with git-blame(1) before committing, while\nfalling back to HEAD:.git-blame-ignore-revs allows bare repositories to\nrespect the committed ignore list as well.\n\nTo ensure consistent precedence, override semantics, and safety when\nreading upstream-controlled content:\n- The default .git-blame-ignore-revs entry is added before reading\n  configuration and CLI options, preserving user and repository config\n  overrides.\n- In git_blame_config(), blame.ignoreRevsFile entries are appended via\n  string_list_append() rather than inserted in sorted order via\n  string_list_insert() so that configuration entries preserve their\n  order relative to the initial default entry.\n- When a working tree is present, the working-tree\n  .git-blame-ignore-revs path is checked with lstat() and S_ISREG(),\n  opened with open_nofollow(), and verified with fstat() and S_ISREG()\n  so symbolic links and non-regular files are silently skipped. In bare\n  repositories, HEAD:.git-blame-ignore-revs is resolved quietly via\n  get_oid_with_context() and its tree entry mode is checked with\n  S_ISREG() before checking the object.\n- In both modes, the file or blob size is capped at\n  IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from\n  3c50032ff5 (\"attr: ignore overly large gitattributes files\",\n  2022-12-01)) before reading its contents, skipping an oversized file\n  or blob with a warning without loading it into memory. The contents\n  are parsed via a new oidset_parse_buffer_carefully() helper in\n  oidset.c that shares line parsing with oidset_parse_file_carefully().\n- In build_ignorelist(), ignore-revs entries are processed starting\n  after the last empty string entry. This ensures setting\n  blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n  --no-ignore-revs-file cleanly discards the default entry without\n  attempting to read or parse it, allowing users to bypass a malformed\n  default ignore-revs file.\n\nUpdate documentation in blame-options.adoc and config/blame.adoc, and\nadd test coverage in t8013 for the default working-tree lookup,\nuncommitted and untracked .git-blame-ignore-revs files, subdirectory\ninvocations, bare repositories, CLI and config overrides, symbolic\nlinks, overly large files and blobs, and comments and whitespace\nhandling.\n\nBased-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\nHelped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\nHelped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n Documentation/blame-options.adoc |   9 +-\n Documentation/config/blame.adoc  |  10 +-\n builtin/blame.c                  |  95 ++++++++++++-\n oidset.c                         |  84 +++++++----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 233 +++++++++++++++++++++++++++++++\n 6 files changed, 404 insertions(+), 36 deletions(-)\n\ndiff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\nindex 1ae1222b6b..f985788112 100644\n--- a/Documentation/blame-options.adoc\n+++ b/Documentation/blame-options.adoc\n@@ -132,9 +132,12 @@ take effect.\n `--ignore-revs-file <file>`::\n \tIgnore revisions listed in _<file>_, which must be in the same format as an\n \t`fsck.skipList`.  This option may be repeated, and these files will be\n-\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n-\toption.  An empty file name, `\"\"`, will clear the list of revs from\n-\tpreviously processed files.\n+\tprocessed after the default `.git-blame-ignore-revs` file at the root of\n+\tthe working tree (or `HEAD:.git-blame-ignore-revs` in a bare repository),\n+\tif it exists, and any files specified with the `blame.ignoreRevsFile`\n+\tconfig option.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will\n+\tclear the list of revs from previously processed files, including the\n+\tdefault ignore-revs file.\n \n `--color-lines`::\n \tColor line annotations in the default format differently if they come from\ndiff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\nindex 4d047c1790..a46aea8d98 100644\n--- a/Documentation/config/blame.adoc\n+++ b/Documentation/config/blame.adoc\n@@ -23,9 +23,13 @@ blame.showRoot::\n blame.ignoreRevsFile::\n \tIgnore revisions listed in the file, one unabbreviated object name per\n \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n-\t`#` are ignored.  This option may be repeated multiple times.  Empty\n-\tfile names will reset the list of ignored revisions.  This option will\n-\tbe handled before the command line option `--ignore-revs-file`.\n+\t`#` are ignored.  If `.git-blame-ignore-revs` exists at the root of the\n+\tworking tree (or `HEAD:.git-blame-ignore-revs` in a bare repository), it\n+\tis added as the initial element in the list of ignore-revs files.\n+\tOther files listed in the configuration are also used, but an empty\n+\telement makes all elements that appeared before in the list forgotten.\n+\tThis option will be handled before the command line option\n+\t`--ignore-revs-file`.\n \n blame.markUnblamableLines::\n \tMark lines that were changed by an ignored revision that we could not\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 6741a7b9df..1a1bcc51f5 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -29,6 +29,7 @@\n #include \"object-name.h\"\n #include \"odb.h\"\n #include \"pager.h\"\n+#include \"path.h\"\n #include \"blame.h\"\n #include \"refs.h\"\n #include \"setup.h\"\n@@ -769,7 +770,7 @@ static int git_blame_config(const char *var, const char *value,\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tif (str)\n-\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n+\t\t\tstring_list_append(&ignore_revs_file_list, str);\n \t\tfree(str);\n \t\treturn 0;\n \t}\n@@ -946,17 +947,101 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n \t}\n }\n \n+#define IGNORE_REVS_MAX_FILE_SIZE (100 * 1024 * 1024)\n+\n+static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *name)\n+{\n+\tstruct object_context oc;\n+\tstruct object_id oid;\n+\tenum object_type type;\n+\tsize_t size;\n+\tchar *buf;\n+\n+\tif (get_oid_with_context(sb->repo, name, GET_OID_QUIETLY,\n+\t\t\t\t &oid, &oc))\n+\t\tgoto out;\n+\tif (!S_ISREG(oc.mode))\n+\t\tgoto out;\n+\n+\tif (odb_read_object_info(sb->repo->objects, &oid, &size) != OBJ_BLOB)\n+\t\tgoto out;\n+\tif (size >= IGNORE_REVS_MAX_FILE_SIZE) {\n+\t\twarning(_(\"ignoring overly large ignore-revs blob '%s'\"), name);\n+\t\tgoto out;\n+\t}\n+\n+\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n+\tif (!buf)\n+\t\tgoto out;\n+\tif (type == OBJ_BLOB)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      sb->repo->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\tfree(buf);\n+\n+out:\n+\tobject_context_release(&oc);\n+}\n+\n+static void parse_default_ignore_revs_file(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *name)\n+{\n+\tchar *path = repo_worktree_path(sb->repo, \"%s\", name);\n+\tstruct stat st;\n+\tint fd = -1;\n+\tsize_t size;\n+\tchar *buf = NULL;\n+\n+\tif (lstat(path, &st) || !S_ISREG(st.st_mode))\n+\t\tgoto out;\n+\tfd = open_nofollow(path, O_RDONLY);\n+\tif (fd < 0 || fstat(fd, &st) || !S_ISREG(st.st_mode))\n+\t\tgoto out;\n+\tif (st.st_size >= IGNORE_REVS_MAX_FILE_SIZE) {\n+\t\twarning(_(\"ignoring overly large ignore-revs file '%s'\"), name);\n+\t\tgoto out;\n+\t}\n+\tsize = xsize_t(st.st_size);\n+\tbuf = xmalloc(size);\n+\tif (read_in_full(fd, buf, size) == (ssize_t)size)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      sb->repo->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\n+out:\n+\tif (fd >= 0)\n+\t\tclose(fd);\n+\tfree(buf);\n+\tfree(path);\n+}\n+\n+static void parse_default_ignore_revs(struct blame_scoreboard *sb)\n+{\n+\tif (repo_get_work_tree(sb->repo))\n+\t\tparse_default_ignore_revs_file(sb, \".git-blame-ignore-revs\");\n+\telse\n+\t\tparse_default_ignore_revs_blob(sb, \"HEAD:.git-blame-ignore-revs\");\n+}\n+\n static void build_ignorelist(struct blame_scoreboard *sb,\n \t\t\t     struct string_list *ignore_revs_file_list,\n \t\t\t     struct string_list *ignore_rev_list)\n {\n \tstruct string_list_item *i;\n \tstruct object_id oid;\n+\tsize_t start_idx = 0, idx;\n+\n+\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tif (!*ignore_revs_file_list->items[idx].string)\n+\t\t\tstart_idx = idx + 1;\n+\t}\n \n \toidset_init(&sb->ignore_list, 0);\n-\tfor_each_string_list_item(i, ignore_revs_file_list) {\n-\t\tif (!strcmp(i->string, \"\"))\n-\t\t\toidset_clear(&sb->ignore_list);\n+\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n+\t\ti = &ignore_revs_file_list->items[idx];\n+\t\tif (i->util)\n+\t\t\tparse_default_ignore_revs(sb);\n \t\telse\n \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n \t\t\t\t\t\t    the_repository->hash_algo,\n@@ -1036,6 +1121,8 @@ int cmd_blame(int argc,\n \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n \n \tsetup_default_color_by_age();\n+\tstring_list_append(&ignore_revs_file_list,\n+\t\t\t   \".git-blame-ignore-revs\")->util = &sb;\n \trepo_config(the_repository, git_blame_config, &output_option);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \trevs.date_mode = blame_date_mode;\ndiff --git a/oidset.c b/oidset.c\nindex 90d39204d3..8469d03b9b 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n }\n \n+static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n+\t\t\t      const struct git_hash_algo *algop,\n+\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tconst char *p;\n+\tconst char *name;\n+\tstruct object_id oid;\n+\n+\tif (memchr(sb->buf, '\\0', sb->len))\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\n+\t/*\n+\t * Allow trailing comments, leading whitespace\n+\t * (including before commits), and empty or whitespace\n+\t * only lines.\n+\t */\n+\tname = strchr(sb->buf, '#');\n+\tif (name)\n+\t\tstrbuf_setlen(sb, name - sb->buf);\n+\tstrbuf_trim(sb);\n+\tif (!sb->len)\n+\t\treturn;\n+\n+\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\tif (fn && fn(&oid, cbdata))\n+\t\treturn;\n+\toidset_insert(set, &oid);\n+}\n+\n void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n {\n \tFILE *fp;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tstruct object_id oid;\n \n \tfp = fopen(path, \"r\");\n \tif (!fp)\n \t\tdie(\"could not open object name list: %s\", path);\n-\twhile (!strbuf_getline(&sb, fp)) {\n-\t\tconst char *p;\n-\t\tconst char *name;\n-\n-\t\tif (memchr(sb.buf, '\\0', sb.len))\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\n-\t\t/*\n-\t\t * Allow trailing comments, leading whitespace\n-\t\t * (including before commits), and empty or whitespace\n-\t\t * only lines.\n-\t\t */\n-\t\tname = strchr(sb.buf, '#');\n-\t\tif (name)\n-\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n-\t\tstrbuf_trim(&sb);\n-\t\tif (!sb.len)\n-\t\t\tcontinue;\n-\n-\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\t\tif (fn && fn(&oid, cbdata))\n-\t\t\tcontinue;\n-\t\toidset_insert(set, &oid);\n-\t}\n+\twhile (!strbuf_getline(&sb, fp))\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n \tif (ferror(fp))\n \t\tdie_errno(\"Could not read '%s'\", path);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n }\n+\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tconst char *p = buf, *end;\n+\n+\tif (!size)\n+\t\treturn;\n+\tend = buf + size;\n+\n+\twhile (p < end) {\n+\t\tconst char *nl = memchr(p, '\\n', end - p);\n+\t\tsize_t len = (nl ? nl : end) - p;\n+\n+\t\tstrbuf_reset(&sb);\n+\t\tif (len && p[len - 1] == '\\r')\n+\t\t\tlen--;\n+\t\tstrbuf_add(&sb, p, len);\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n+\t\tp = nl ? nl + 1 : end;\n+\t}\n+\tstrbuf_release(&sb);\n+}\ndiff --git a/oidset.h b/oidset.h\nindex e0f1a6ff4f..667c390842 100644\n--- a/oidset.h\n+++ b/oidset.h\n@@ -98,6 +98,15 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n \n+/*\n+ * Similar to oidset_parse_file_carefully(), but parses lines from an\n+ * in-memory buffer of 'size' bytes.\n+ */\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n+\n struct oidset_iter {\n \tconst kh_oid_set_t *set;\n \tkhiter_t iter;\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex 70fe509a64..92d8296c7b 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -365,4 +365,237 @@ test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n \ttest_cmp expect actual\n '\n \n+# Tests for default .git-blame-ignore-revs\n+test_expect_success 'setup default .git-blame-ignore-revs' '\n+\tgit checkout -b default-file-branch &&\n+\ttest_write_lines line1 line2 >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default base\" &&\n+\tgit tag DEF_A &&\n+\n+\ttest_write_lines line1-modified line2-modified >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default mod\" &&\n+\tgit tag DEF_B &&\n+\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"add .git-blame-ignore-revs\"\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs is used by default' '\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs respected by git annotate' '\n+\tgit rev-parse --short DEF_A >expect_sha &&\n+\tgit annotate def-file >actual &&\n+\ttest_grep \"^$(cat expect_sha)\" actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs works from subdirectory' '\n+\ttest_when_finished \"rm -rf sub\" &&\n+\tmkdir -p sub &&\n+\techo \"invalid-oid-value\" >sub/.git-blame-ignore-revs &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n+\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\t\tgit rev-parse DEF_A >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\tgit clone --bare . bare.git &&\n+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit -C .git blame --line-porcelain HEAD -- def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are respected' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n+\t: >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\n+\trm .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual &&\n+\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\ttest_must_fail git blame def-file\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with --no-ignore-revs-file' '\n+\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with --ignore-revs-file \"\"' '\n+\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n+\ttest_config blame.ignoreRevsFile \"\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs handles comments and whitespace' '\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\t{\n+\t\techo \"# Leading comment\" &&\n+\t\techo \"\" &&\n+\t\techo \"   $rev_def_b   # inline comment\" &&\n+\t\techo \"# Trailing comment\"\n+\t} >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'empty default .git-blame-ignore-revs is harmless' '\n+\t: >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success SYMLINKS 'symlink .git-blame-ignore-revs in working tree is ignored' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs && rm -f target_file\" &&\n+\tgit rev-parse DEF_B >target_file &&\n+\trm -f .git-blame-ignore-revs &&\n+\tln -s target_file .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'committed symlink .git-blame-ignore-revs in bare repo HEAD is ignored' '\n+\ttest_when_finished \"git reset --hard HEAD~ && rm -rf bare-symlink.git\" &&\n+\tblob=$(printf \"%s\" \"target_file\" | git hash-object -w --stdin) &&\n+\tgit update-index --replace --cacheinfo 120000,$blob,.git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n+\tgit clone --bare . bare-symlink.git &&\n+\tgit -C bare-symlink.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'malformed default .git-blame-ignore-revs fails but can be bypassed' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file &&\n+\tgit blame --no-ignore-revs-file def-file &&\n+\tgit blame --ignore-revs-file \"\" def-file &&\n+\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n+\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\ttest_write_lines line1-modified line2-c >def-file &&\n+\tgit add .git-blame-ignore-revs def-file &&\n+\ttest_tick &&\n+\tgit commit -m C &&\n+\tgit tag DEF_C &&\n+\tgit rev-parse DEF_C >custom_ignore &&\n+\ttest_config blame.ignoreRevsFile custom_ignore &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'blame works when .git-blame-ignore-revs does not exist' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success EXPENSIVE 'overly large default .git-blame-ignore-revs is ignored' '\n+\ttest_when_finished \"rm -f .git-blame-ignore-revs\" &&\n+\tdd if=/dev/zero of=.git-blame-ignore-revs bs=1048576 count=101 2>/dev/null &&\n+\tgit blame --line-porcelain def-file >blame_raw 2>err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"warning: ignoring overly large ignore-revs file '\\''.git-blame-ignore-revs'\\''\" err &&\n+\n+\tblob=$(git hash-object -w .git-blame-ignore-revs) &&\n+\trm -f .git-blame-ignore-revs &&\n+\tgit update-index --add --cacheinfo 100644,$blob,.git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"overly large .git-blame-ignore-revs\" &&\n+\ttest_when_finished \"git reset --hard HEAD~\" &&\n+\tgit -C .git blame --line-porcelain HEAD -- def-file >blame_raw 2>err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"warning: ignoring overly large ignore-revs blob '\\''HEAD:.git-blame-ignore-revs'\\''\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"554869","messageId":"20261013144852.1155285-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqqwlrm4o6z.fsf@gitster.g","subject":"Re: [PATCH v2 2/2] blame: ignore revs in HEAD:.git-blame-ignore-revs","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-13T14:48:52Z","receivedAt":"2026-10-13T14:48:52Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Ravi Mistry <rmistry@google.com> writes:\n> > For v4, I left the behavior as reading from HEAD:.git-blame-ignore-revs\n> > to match hosting sites for now. Maybe consulting the working tree could\n> > be explored in the future in a separate series if desired, or please let\n> > me know if you or Phillip would prefer to change it in this series.\n>\n> It needs to be justified in some way other than \"match what the\n> forges do (which is to use the one from HEAD)\", but other than that,\n> I think it would be more ergonomic to pick up the copy from the\n> working tree (with local modifications) in non-bare case.\n\nMakes sense, I did not have a justification for sticking with HEAD other\nthan matching hosting sites.\n\nI have sent v5, which reads .git-blame-ignore-revs from the root of the\nworking tree in non-bare repositories (and HEAD:.git-blame-ignore-revs\nin bare repositories) and updates the commit message to justify the\nbehavior on ergonomic grounds.\n\nThanks!\n\n"},{"id":"554887","messageId":"xmqq4iepzex9.fsf@gitster.g","threadId":"66313","inReplyTo":"pull.2224.v5.git.1791902175.gitgitgadget@gmail.com","subject":"Re: [PATCH v5 0/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T17:30:26Z","receivedAt":"2026-10-13T17:30:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ravi Mistry via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>      +    tree when a working tree is available and fall back to the\n>      +    HEAD:.git-blame-ignore-revs blob in bare repositories. Reading from the\n>      +    working tree in non-bare repositories makes it ergonomic to prepare a\n>      +    new .git-blame-ignore-revs file or add revisions to an existing one and\n>      +    immediately test the effect with git-blame(1) before committing, while\n>      +    falling back to HEAD:.git-blame-ignore-revs allows bare repositories to\n>      +    respect the committed ignore list as well.\n\nVery well written justification.\n\n>      ++\tprocessed after the default `.git-blame-ignore-revs` file at the root of\n>      ++\tthe working tree (or `HEAD:.git-blame-ignore-revs` in a bare repository),\n>      ++\tif it exists, and any files specified with the `blame.ignoreRevsFile`\n\nGood.  A bit more comment on this later.\n\n>      ++\tconfig option.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will\n\nThat's \"a configuration variable\".\n\n>      ++static void parse_default_ignore_revs(struct blame_scoreboard *sb)\n>      ++{\n>      ++\tif (repo_get_work_tree(sb->repo))\n>      ++\t\tparse_default_ignore_revs_file(sb, \".git-blame-ignore-revs\");\n>      ++\telse\n>      ++\t\tparse_default_ignore_revs_blob(sb, \"HEAD:.git-blame-ignore-revs\");\n>      ++}\n\nHere, HEAD:.git-blame-ignore-revs is used only in bare repositories\nso that those working in a working tree of the project and on a\nrevision with a committed ignore-revs file can remove it from the\nworking tree, verify the behaviour of \"git blame\" to test before\ncommitting the removal, if they no longer want to use the committed\nignore-revs list.  Which is great.  We do not want to say \"we have a\nworking tree, we do not have the file there, fall back to HEAD\".\n\n>      @@ builtin/blame.c: int cmd_blame(int argc,\n>        \n>        \tsetup_default_color_by_age();\n>       +\tstring_list_append(&ignore_revs_file_list,\n>      -+\t\t\t   \"HEAD:.git-blame-ignore-revs\")->util = &sb;\n>      ++\t\t\t   \".git-blame-ignore-revs\")->util = &sb;\n\nHmph, build_ignorelist() ignores the string and only pays attention\nto the fact that the string_list_item having a non-null .util member,\nso this diff, and the fact that a specific string is on the list, is\na bit misleading in two ways (i.e., the string itself does not\nmatter, and the value of .util member does not metter, either).\n\nIn other words, a cute hack like this\n\n\t\tstring_list_append(&ignore_revs_file_list,\n                \t\t   \"<builtin default>\")->util =\n                                   \"see build_ignorelist()\";\n\nmay still give us the same behaviour, which is *horrible*.\n\nIt probably deserves a comment to help future readers, e.g.\n\n\t\t/*\n\t\t * An entry with non-NULL .util member adds the\n\t\t *  .git-blame-ignore-revs at the project root;\n                 * see build_ignorelist()\n\t\t */\n                string_list_append(&ignore_revs_file_list,\n                                   \".git-blame-ignore-revs\")->util = &sb;\n\nor something?  It is especially misleading to pass &sb here because\nit is not used as a scoreboard at all anywhere.\n\nThanks.\n\n"},{"id":"554905","messageId":"pull.2224.v6.git.1791922928.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.git.1789169384240.gitgitgadget@gmail.com","subject":"[PATCH v6 0/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-13T20:22:06Z","receivedAt":"2026-10-13T20:22:06Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"This series teaches git-blame(1) and git-annotate(1) to automatically use\n.git-blame-ignore-revs at the root of the working tree (or\nHEAD:.git-blame-ignore-revs in bare repositories) by default if it exists,\nwithout requiring manual blame.ignoreRevsFile configuration in every clone.\nThis restarts the stalled attempt in PR\nhttps://github.com/gitgitgadget/git/pull/1809\n(https://lore.kernel.org/git/pull.1809.v2.git.1728707867.gitgitgadget@gmail.com/)\nand addresses https://github.com/gitgitgadget/git/issues/1494.\n\nChanges since v5:\n\n * Passed i->string from build_ignorelist() into parse_default_ignore_revs()\n   so the item string is used for both the working-tree path and \"HEAD:\" in\n   bare repositories, and changed cmd_blame() to set ->util = (void *)1 with\n   an explanatory comment instead of passing the scoreboard.\n * Doc update: Changed \"config option\" / \"configuration option\" to\n   \"configuration variable\" in Documentation/blame-options.adoc and the\n   commit message.\n\nChanges since v4:\n\n * In non-bare repositories, Patch 2/2 now reads .git-blame-ignore-revs from\n   the root of the working tree (using open_nofollow(), S_ISREG(), and\n   IGNORE_REVS_MAX_FILE_SIZE) instead of HEAD:.git-blame-ignore-revs, while\n   continuing to use HEAD:.git-blame-ignore-revs in bare repositories\n   (matching the .mailmap model in read_mailmap()). This makes it ergonomic\n   to test uncommitted or untracked changes to .git-blame-ignore-revs\n   locally before committing.\n * Updated the commit messages and documentation to justify the default\n   lookup and working-tree behavior on ergonomic grounds.\n\nChanges since v3:\n\n * Patch 2/2 caps the size of the default HEAD:.git-blame-ignore-revs blob\n   at IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from\n   3c50032ff5 (\"attr: ignore overly large gitattributes files\", 2022-12-01))\n   via odb_read_object_info() before calling odb_read_object(), skipping\n   oversized blobs with a warning without loading them into memory.\n\nChanges since v2:\n\n * Patch 2/2 uses sb->repo instead of the_repository in\n   parse_default_ignore_revs_blob().\n\nChanges since v1:\n\n * Split the series into two commits.\n * Patch 1/2 hardens oidset_parse_file_carefully() in oidset.c and\n   peel_to_commit_oid() in builtin/blame.c before exposing them to\n   upstream-controlled content at a well-known path:\n   * Reject lines containing embedded NUL bytes via memchr() so trailing\n     bytes after a NUL cannot be silently ignored.\n   * Pass OBJECT_INFO_LOOKUP_REPLACE | OBJECT_INFO_SKIP_FETCH_OBJECT |\n     OBJECT_INFO_QUICK to odb_read_object_info_extended() and peel tags one\n     layer per iteration so missing OIDs or tag targets do not trigger lazy\n     promisor fetches or pack directory rescans in partial clones, and\n     verify that each peeled target matches the tag's declared type.\n * Patch 2/2 reads the committed HEAD:.git-blame-ignore-revs blob (in both\n   bare and non-bare repositories) instead of reading a file from the\n   working tree, matching hosting platforms even when an untracked file is\n   present or a tracked one has local modifications. The tree entry is\n   checked with S_ISREG() so non-regular entries (such as committed\n   symlinks) are skipped, parsed in memory via\n   oidset_parse_buffer_carefully(), and bypassed without reading if cleared\n   via blame.ignoreRevsFile=\"\" or --no-ignore-revs-file.\n\nRavi Mistry (2):\n  blame: harden ignore-revs parser and tag peeling\n  blame: ignore revs in .git-blame-ignore-revs by default\n\n Documentation/blame-options.adoc |   9 +-\n Documentation/config/blame.adoc  |  10 +-\n builtin/blame.c                  | 122 +++++++++++++-\n oidset.c                         |  81 ++++++---\n oidset.h                         |   9 +\n t/t8013-blame-ignore-revs.sh     | 271 +++++++++++++++++++++++++++++++\n 6 files changed, 467 insertions(+), 35 deletions(-)\n\n\nbase-commit: fa7f9290efe2bd22dd736689597b474b93798e11\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2224%2Frmistry%2Fblame-default-ignore-revs-v6\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2224/rmistry/blame-default-ignore-revs-v6\nPull-Request: https://github.com/gitgitgadget/git/pull/2224\n\nRange-diff vs v5:\n\n 1:  e9b2c1dae2 = 1:  e9b2c1dae2 blame: harden ignore-revs parser and tag peeling\n 2:  605eb049a1 ! 2:  6039d4bc2d blame: ignore revs in .git-blame-ignore-revs by default\n     @@ Commit message\n          blame: ignore revs in .git-blame-ignore-revs by default\n      \n          git-blame(1) can ignore a list of commits specified via\n     -    --ignore-revs-file or the blame.ignoreRevsFile configuration option.\n     +    --ignore-revs-file or the blame.ignoreRevsFile configuration variable.\n          This is useful for skipping uninteresting revisions such as tree-wide\n          formatting changes, large-scale refactors, and code modernizations that\n          would otherwise obscure genuine historical authorship.\n     @@ Commit message\n          .git-blame-ignore-revs, if it exists, as the initial element in the\n          list of ignore-revs files. Similar to how read_mailmap() handles\n          .mailmap, consult .git-blame-ignore-revs at the root of the working\n     -    tree when a working tree is available and fall back to the\n     -    HEAD:.git-blame-ignore-revs blob in bare repositories. Reading from the\n     -    working tree in non-bare repositories makes it ergonomic to prepare a\n     -    new .git-blame-ignore-revs file or add revisions to an existing one and\n     -    immediately test the effect with git-blame(1) before committing, while\n     -    falling back to HEAD:.git-blame-ignore-revs allows bare repositories to\n     +    tree when a working tree is available, and otherwise consult the\n     +    HEAD:.git-blame-ignore-revs blob in bare repositories. Reading only\n     +    from the working tree in non-bare repositories makes it ergonomic to\n     +    prepare a new .git-blame-ignore-revs file, edit an existing one, or\n     +    remove a committed one and immediately test the effect with\n     +    git-blame(1) before committing, while consulting\n     +    HEAD:.git-blame-ignore-revs in bare repositories allows them to\n          respect the committed ignore list as well.\n      \n          To ensure consistent precedence, override semantics, and safety when\n     @@ Documentation/blame-options.adoc: take effect.\n      +\tprocessed after the default `.git-blame-ignore-revs` file at the root of\n      +\tthe working tree (or `HEAD:.git-blame-ignore-revs` in a bare repository),\n      +\tif it exists, and any files specified with the `blame.ignoreRevsFile`\n     -+\tconfig option.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will\n     -+\tclear the list of revs from previously processed files, including the\n     -+\tdefault ignore-revs file.\n     ++\tconfiguration variable.  An empty file name, `\"\"`, or\n     ++\t`--no-ignore-revs-file` will clear the list of revs from previously\n     ++\tprocessed files, including the default ignore-revs file.\n       \n       `--color-lines`::\n       \tColor line annotations in the default format differently if they come from\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +#define IGNORE_REVS_MAX_FILE_SIZE (100 * 1024 * 1024)\n      +\n      +static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n     -+\t\t\t\t\t   const char *name)\n     ++\t\t\t\t\t   const char *path)\n      +{\n     ++\tchar *name = xstrfmt(\"HEAD:%s\", path);\n      +\tstruct object_context oc;\n      +\tstruct object_id oid;\n      +\tenum object_type type;\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +\n      +out:\n      +\tobject_context_release(&oc);\n     ++\tfree(name);\n      +}\n      +\n      +static void parse_default_ignore_revs_file(struct blame_scoreboard *sb,\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +\tfree(path);\n      +}\n      +\n     -+static void parse_default_ignore_revs(struct blame_scoreboard *sb)\n     ++static void parse_default_ignore_revs(struct blame_scoreboard *sb,\n     ++\t\t\t\t      const char *name)\n      +{\n      +\tif (repo_get_work_tree(sb->repo))\n     -+\t\tparse_default_ignore_revs_file(sb, \".git-blame-ignore-revs\");\n     ++\t\tparse_default_ignore_revs_file(sb, name);\n      +\telse\n     -+\t\tparse_default_ignore_revs_blob(sb, \"HEAD:.git-blame-ignore-revs\");\n     ++\t\tparse_default_ignore_revs_blob(sb, name);\n      +}\n      +\n       static void build_ignorelist(struct blame_scoreboard *sb,\n     @@ builtin/blame.c: static int peel_to_commit_oid(struct object_id *oid_ret, void *\n      +\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n      +\t\ti = &ignore_revs_file_list->items[idx];\n      +\t\tif (i->util)\n     -+\t\t\tparse_default_ignore_revs(sb);\n     ++\t\t\tparse_default_ignore_revs(sb, i->string);\n       \t\telse\n       \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n       \t\t\t\t\t\t    the_repository->hash_algo,\n     @@ builtin/blame.c: int cmd_blame(int argc,\n       \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n       \n       \tsetup_default_color_by_age();\n     ++\t/*\n     ++\t * An entry with a non-NULL .util member names the default\n     ++\t * ignore-revs file at the project root; see build_ignorelist().\n     ++\t */\n      +\tstring_list_append(&ignore_revs_file_list,\n     -+\t\t\t   \".git-blame-ignore-revs\")->util = &sb;\n     ++\t\t\t   \".git-blame-ignore-revs\")->util = (void *)1;\n       \trepo_config(the_repository, git_blame_config, &output_option);\n       \trepo_init_revisions(the_repository, &revs, NULL);\n       \trevs.date_mode = blame_date_mode;\n\n-- \ngitgitgadget\n\n"},{"id":"554906","messageId":"e9b2c1dae2cd11783a66f0afdce53dfad78b43d8.1791922928.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v6.git.1791922928.gitgitgadget@gmail.com","subject":"[PATCH v6 1/2] blame: harden ignore-revs parser and tag peeling","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-13T20:22:07Z","receivedAt":"2026-10-13T20:22:07Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\nCurrently, blame.ignoreRevsFile and --ignore-revs-file only read paths\nexplicitly configured by the user, which cannot point to an\nattacker-controlled file under Git's threat model. An upcoming commit\nwill teach git-blame(1) and git-annotate(1) to automatically read\n.git-blame-ignore-revs by default if it exists, exposing the\nignore-revs parser (oidset_parse_file_carefully() in oidset.c) and its\ntag-peeling callback (peel_to_commit_oid() in builtin/blame.c) to\nupstream-controlled content at a well-known path.\n\nHarden both code paths before enabling the default ignore-revs file:\n\n- In oidset_parse_file_carefully(), strbuf_getline() reads up to the\n  next newline and records the full line length in sb.len, including\n  any embedded NUL bytes. However, strchr(sb.buf, '#') and\n  parse_oid_hex_algop(sb.buf, &oid, &p, algop) treat sb.buf as a\n  NUL-terminated string. If a line contains an embedded NUL byte after\n  a valid object name (such as \"<oid>\\0garbage\" or \"<oid>\\0# comment\"),\n  *p is '\\0' and trailing bytes on the line are silently ignored.\n  Reject any line containing an embedded NUL byte via memchr() before\n  stripping comments and whitespace.\n- In peel_to_commit_oid(), odb_read_object_info() is called without\n  OBJECT_INFO_SKIP_FETCH_OBJECT or OBJECT_INFO_QUICK, and deref_tag()\n  calls parse_object() on tag targets without checking whether the\n  target object exists locally first. In a partial clone, any missing\n  commit OID or tag target listed in the ignore-revs file would trigger\n  lazy promisor fetches and pack directory rescans during git-blame(1).\n  Use odb_read_object_info_extended() with OBJECT_INFO_LOOKUP_REPLACE |\n  OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_QUICK and peel OBJ_TAG\n  objects one layer per iteration, verifying that each target object\n  exists locally and matches the tag's declared type before parsing it.\n\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n builtin/blame.c              | 20 +++++++++++++++++--\n oidset.c                     |  3 +++\n t/t8013-blame-ignore-revs.sh | 38 ++++++++++++++++++++++++++++++++++++\n 3 files changed, 59 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 48d5251c6d..6741a7b9df 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -911,21 +911,37 @@ static int is_a_rev(const char *name)\n static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n {\n \tstruct repository *r = ((struct blame_scoreboard *)cbdata)->repo;\n+\tenum object_type expected_type = OBJ_ANY;\n \tstruct object_id oid;\n \n \toidcpy(&oid, oid_ret);\n \twhile (1) {\n+\t\tunsigned flags = OBJECT_INFO_LOOKUP_REPLACE |\n+\t\t\t\t OBJECT_INFO_SKIP_FETCH_OBJECT |\n+\t\t\t\t OBJECT_INFO_QUICK;\n+\t\tstruct object_info oi = OBJECT_INFO_INIT;\n+\t\tenum object_type kind;\n \t\tstruct object *obj;\n-\t\tint kind = odb_read_object_info(r->objects, &oid, NULL);\n+\n+\t\toi.typep = &kind;\n+\t\tif (odb_read_object_info_extended(r->objects, &oid, &oi,\n+\t\t\t\t\t\t  flags) < 0)\n+\t\t\treturn -1;\n+\t\tif (expected_type != OBJ_ANY && kind != expected_type)\n+\t\t\treturn -1;\n \t\tif (kind == OBJ_COMMIT) {\n \t\t\toidcpy(oid_ret, &oid);\n \t\t\treturn 0;\n \t\t}\n \t\tif (kind != OBJ_TAG)\n \t\t\treturn -1;\n-\t\tobj = deref_tag(r, parse_object(r, &oid), NULL, 0);\n+\t\tobj = parse_object(r, &oid);\n+\t\tif (!obj || obj->type != OBJ_TAG)\n+\t\t\treturn -1;\n+\t\tobj = ((struct tag *)obj)->tagged;\n \t\tif (!obj)\n \t\t\treturn -1;\n+\t\texpected_type = obj->type;\n \t\toidcpy(&oid, &obj->oid);\n \t}\n }\ndiff --git a/oidset.c b/oidset.c\nindex c8ff0b385c..90d39204d3 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -85,6 +85,9 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\tconst char *p;\n \t\tconst char *name;\n \n+\t\tif (memchr(sb.buf, '\\0', sb.len))\n+\t\t\tdie(\"invalid object name: %s\", sb.buf);\n+\n \t\t/*\n \t\t * Allow trailing comments, leading whitespace\n \t\t * (including before commits), and empty or whitespace\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex cace00ae8d..70fe509a64 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -327,4 +327,42 @@ test_expect_success ignore_merge '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'ignore-revs-file rejects lines with embedded NUL bytes' '\n+\trev_b=$(git rev-parse B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_b\" | q_to_nul >ignore_nul &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul 2>err &&\n+\ttest_grep \"invalid object name:\" err &&\n+\n+\tprintf \"%sQ# comment\\n\" \"$rev_b\" | q_to_nul >ignore_nul_comment &&\n+\ttest_must_fail git blame file --ignore-revs-file ignore_nul_comment 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'ignore-revs-file peels chained tags and skips missing tag targets' '\n+\ttest_write_lines BB L2-modified L3 L4 L5 L6 L7 L8 CC >file &&\n+\tgit add file &&\n+\ttest_tick &&\n+\tgit commit -m D &&\n+\tgit tag -a -m \"tag 1\" D_TAG1 HEAD &&\n+\tgit tag -a -m \"tag 2\" D_TAG2 D_TAG1 &&\n+\tgit rev-parse D_TAG2 >ignore_tag_chain &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_tag_chain >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\ttest_config extensions.partialClone origin &&\n+\ttest_config remote.origin.promisor true &&\n+\ttest_config remote.origin.url /nonexistent &&\n+\tmissing_oid=$(test_oid deadbeef) &&\n+\tbad_tag=$(printf \"object %s\\ntype commit\\ntag bad-tag\\ntagger T <t@example.com> 0 +0000\\n\\nmsg\\n\" \"$missing_oid\" |\n+\t\tgit hash-object -t tag -w --stdin) &&\n+\ttest_write_lines \"$missing_oid\" \"$bad_tag\" >ignore_bad_tag &&\n+\tgit blame --line-porcelain file --ignore-revs-file ignore_bad_tag >blame_raw 2>err &&\n+\ttest_must_be_empty err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse HEAD >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n\n"},{"id":"554907","messageId":"6039d4bc2d8b22254406b9dec79c7fdb1a4c499c.1791922928.git.gitgitgadget@gmail.com","threadId":"66313","inReplyTo":"pull.2224.v6.git.1791922928.gitgitgadget@gmail.com","subject":"[PATCH v6 2/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Ravi Mistry via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-10-13T20:22:08Z","receivedAt":"2026-10-13T20:22:08Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"From: Ravi Mistry <rmistry@google.com>\n\ngit-blame(1) can ignore a list of commits specified via\n--ignore-revs-file or the blame.ignoreRevsFile configuration variable.\nThis is useful for skipping uninteresting revisions such as tree-wide\nformatting changes, large-scale refactors, and code modernizations that\nwould otherwise obscure genuine historical authorship.\n\nWhen revision-ignoring was introduced in commit ae3f36dea1 (\"blame: add\nblame.ignoreRevsFile config option\", 2019-10-18), it intentionally\navoided adopting a default ignore file. At the time, the capability was\nnew and unproven, so avoiding unrequested filesystem I/O or unexpected\nattribution shifts took priority over a project-wide default.\nRequiring explicit opt-in per clone was therefore the prudent design.\n\nSince then, maintaining a .git-blame-ignore-revs file at the top level\nof the repository has become the standard convention across the Git\necosystem, adopted by many open source projects (such as Chromium and\nLLVM) as well as hosting platforms (GitHub, GitLab, Gerrit). However,\ngit-blame(1) and git-annotate(1) still ignore this file unless each\nuser remembers to manually configure blame.ignoreRevsFile in every\nlocal clone.\n\nTeach git-blame(1) and git-annotate(1) to automatically add\n.git-blame-ignore-revs, if it exists, as the initial element in the\nlist of ignore-revs files. Similar to how read_mailmap() handles\n.mailmap, consult .git-blame-ignore-revs at the root of the working\ntree when a working tree is available, and otherwise consult the\nHEAD:.git-blame-ignore-revs blob in bare repositories. Reading only\nfrom the working tree in non-bare repositories makes it ergonomic to\nprepare a new .git-blame-ignore-revs file, edit an existing one, or\nremove a committed one and immediately test the effect with\ngit-blame(1) before committing, while consulting\nHEAD:.git-blame-ignore-revs in bare repositories allows them to\nrespect the committed ignore list as well.\n\nTo ensure consistent precedence, override semantics, and safety when\nreading upstream-controlled content:\n- The default .git-blame-ignore-revs entry is added before reading\n  configuration and CLI options, preserving user and repository config\n  overrides.\n- In git_blame_config(), blame.ignoreRevsFile entries are appended via\n  string_list_append() rather than inserted in sorted order via\n  string_list_insert() so that configuration entries preserve their\n  order relative to the initial default entry.\n- When a working tree is present, the working-tree\n  .git-blame-ignore-revs path is checked with lstat() and S_ISREG(),\n  opened with open_nofollow(), and verified with fstat() and S_ISREG()\n  so symbolic links and non-regular files are silently skipped. In bare\n  repositories, HEAD:.git-blame-ignore-revs is resolved quietly via\n  get_oid_with_context() and its tree entry mode is checked with\n  S_ISREG() before checking the object.\n- In both modes, the file or blob size is capped at\n  IGNORE_REVS_MAX_FILE_SIZE (100MB, matching ATTR_MAX_FILE_SIZE from\n  3c50032ff5 (\"attr: ignore overly large gitattributes files\",\n  2022-12-01)) before reading its contents, skipping an oversized file\n  or blob with a warning without loading it into memory. The contents\n  are parsed via a new oidset_parse_buffer_carefully() helper in\n  oidset.c that shares line parsing with oidset_parse_file_carefully().\n- In build_ignorelist(), ignore-revs entries are processed starting\n  after the last empty string entry. This ensures setting\n  blame.ignoreRevsFile to \"\" or passing --ignore-revs-file \"\" or\n  --no-ignore-revs-file cleanly discards the default entry without\n  attempting to read or parse it, allowing users to bypass a malformed\n  default ignore-revs file.\n\nUpdate documentation in blame-options.adoc and config/blame.adoc, and\nadd test coverage in t8013 for the default working-tree lookup,\nuncommitted and untracked .git-blame-ignore-revs files, subdirectory\ninvocations, bare repositories, CLI and config overrides, symbolic\nlinks, overly large files and blobs, and comments and whitespace\nhandling.\n\nBased-on-patch-by: Abhijeetsingh Meena <abhijeet040403@gmail.com>\nHelped-by: Kristoffer Haugsbakk <code@khaugsbakk.name>\nHelped-by: Phillip Wood <phillip.wood@dunelm.org.uk>\nHelped-by: Eric Sunshine <sunshine@sunshineco.com>\nSigned-off-by: Ravi Mistry <rmistry@google.com>\n---\n Documentation/blame-options.adoc |   9 +-\n Documentation/config/blame.adoc  |  10 +-\n builtin/blame.c                  | 102 +++++++++++++-\n oidset.c                         |  84 +++++++----\n oidset.h                         |   9 ++\n t/t8013-blame-ignore-revs.sh     | 233 +++++++++++++++++++++++++++++++\n 6 files changed, 411 insertions(+), 36 deletions(-)\n\ndiff --git a/Documentation/blame-options.adoc b/Documentation/blame-options.adoc\nindex 1ae1222b6b..7e910373bd 100644\n--- a/Documentation/blame-options.adoc\n+++ b/Documentation/blame-options.adoc\n@@ -132,9 +132,12 @@ take effect.\n `--ignore-revs-file <file>`::\n \tIgnore revisions listed in _<file>_, which must be in the same format as an\n \t`fsck.skipList`.  This option may be repeated, and these files will be\n-\tprocessed after any files specified with the `blame.ignoreRevsFile` config\n-\toption.  An empty file name, `\"\"`, will clear the list of revs from\n-\tpreviously processed files.\n+\tprocessed after the default `.git-blame-ignore-revs` file at the root of\n+\tthe working tree (or `HEAD:.git-blame-ignore-revs` in a bare repository),\n+\tif it exists, and any files specified with the `blame.ignoreRevsFile`\n+\tconfiguration variable.  An empty file name, `\"\"`, or\n+\t`--no-ignore-revs-file` will clear the list of revs from previously\n+\tprocessed files, including the default ignore-revs file.\n \n `--color-lines`::\n \tColor line annotations in the default format differently if they come from\ndiff --git a/Documentation/config/blame.adoc b/Documentation/config/blame.adoc\nindex 4d047c1790..a46aea8d98 100644\n--- a/Documentation/config/blame.adoc\n+++ b/Documentation/config/blame.adoc\n@@ -23,9 +23,13 @@ blame.showRoot::\n blame.ignoreRevsFile::\n \tIgnore revisions listed in the file, one unabbreviated object name per\n \tline, in linkgit:git-blame[1].  Whitespace and comments beginning with\n-\t`#` are ignored.  This option may be repeated multiple times.  Empty\n-\tfile names will reset the list of ignored revisions.  This option will\n-\tbe handled before the command line option `--ignore-revs-file`.\n+\t`#` are ignored.  If `.git-blame-ignore-revs` exists at the root of the\n+\tworking tree (or `HEAD:.git-blame-ignore-revs` in a bare repository), it\n+\tis added as the initial element in the list of ignore-revs files.\n+\tOther files listed in the configuration are also used, but an empty\n+\telement makes all elements that appeared before in the list forgotten.\n+\tThis option will be handled before the command line option\n+\t`--ignore-revs-file`.\n \n blame.markUnblamableLines::\n \tMark lines that were changed by an ignored revision that we could not\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 6741a7b9df..1e753a0b60 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -29,6 +29,7 @@\n #include \"object-name.h\"\n #include \"odb.h\"\n #include \"pager.h\"\n+#include \"path.h\"\n #include \"blame.h\"\n #include \"refs.h\"\n #include \"setup.h\"\n@@ -769,7 +770,7 @@ static int git_blame_config(const char *var, const char *value,\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tif (str)\n-\t\t\tstring_list_insert(&ignore_revs_file_list, str);\n+\t\t\tstring_list_append(&ignore_revs_file_list, str);\n \t\tfree(str);\n \t\treturn 0;\n \t}\n@@ -946,17 +947,104 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)\n \t}\n }\n \n+#define IGNORE_REVS_MAX_FILE_SIZE (100 * 1024 * 1024)\n+\n+static void parse_default_ignore_revs_blob(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *path)\n+{\n+\tchar *name = xstrfmt(\"HEAD:%s\", path);\n+\tstruct object_context oc;\n+\tstruct object_id oid;\n+\tenum object_type type;\n+\tsize_t size;\n+\tchar *buf;\n+\n+\tif (get_oid_with_context(sb->repo, name, GET_OID_QUIETLY,\n+\t\t\t\t &oid, &oc))\n+\t\tgoto out;\n+\tif (!S_ISREG(oc.mode))\n+\t\tgoto out;\n+\n+\tif (odb_read_object_info(sb->repo->objects, &oid, &size) != OBJ_BLOB)\n+\t\tgoto out;\n+\tif (size >= IGNORE_REVS_MAX_FILE_SIZE) {\n+\t\twarning(_(\"ignoring overly large ignore-revs blob '%s'\"), name);\n+\t\tgoto out;\n+\t}\n+\n+\tbuf = odb_read_object(sb->repo->objects, &oid, &type, &size);\n+\tif (!buf)\n+\t\tgoto out;\n+\tif (type == OBJ_BLOB)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      sb->repo->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\tfree(buf);\n+\n+out:\n+\tobject_context_release(&oc);\n+\tfree(name);\n+}\n+\n+static void parse_default_ignore_revs_file(struct blame_scoreboard *sb,\n+\t\t\t\t\t   const char *name)\n+{\n+\tchar *path = repo_worktree_path(sb->repo, \"%s\", name);\n+\tstruct stat st;\n+\tint fd = -1;\n+\tsize_t size;\n+\tchar *buf = NULL;\n+\n+\tif (lstat(path, &st) || !S_ISREG(st.st_mode))\n+\t\tgoto out;\n+\tfd = open_nofollow(path, O_RDONLY);\n+\tif (fd < 0 || fstat(fd, &st) || !S_ISREG(st.st_mode))\n+\t\tgoto out;\n+\tif (st.st_size >= IGNORE_REVS_MAX_FILE_SIZE) {\n+\t\twarning(_(\"ignoring overly large ignore-revs file '%s'\"), name);\n+\t\tgoto out;\n+\t}\n+\tsize = xsize_t(st.st_size);\n+\tbuf = xmalloc(size);\n+\tif (read_in_full(fd, buf, size) == (ssize_t)size)\n+\t\toidset_parse_buffer_carefully(&sb->ignore_list, buf, size,\n+\t\t\t\t\t      sb->repo->hash_algo,\n+\t\t\t\t\t      peel_to_commit_oid, sb);\n+\n+out:\n+\tif (fd >= 0)\n+\t\tclose(fd);\n+\tfree(buf);\n+\tfree(path);\n+}\n+\n+static void parse_default_ignore_revs(struct blame_scoreboard *sb,\n+\t\t\t\t      const char *name)\n+{\n+\tif (repo_get_work_tree(sb->repo))\n+\t\tparse_default_ignore_revs_file(sb, name);\n+\telse\n+\t\tparse_default_ignore_revs_blob(sb, name);\n+}\n+\n static void build_ignorelist(struct blame_scoreboard *sb,\n \t\t\t     struct string_list *ignore_revs_file_list,\n \t\t\t     struct string_list *ignore_rev_list)\n {\n \tstruct string_list_item *i;\n \tstruct object_id oid;\n+\tsize_t start_idx = 0, idx;\n+\n+\tfor (idx = 0; idx < ignore_revs_file_list->nr; idx++) {\n+\t\tif (!*ignore_revs_file_list->items[idx].string)\n+\t\t\tstart_idx = idx + 1;\n+\t}\n \n \toidset_init(&sb->ignore_list, 0);\n-\tfor_each_string_list_item(i, ignore_revs_file_list) {\n-\t\tif (!strcmp(i->string, \"\"))\n-\t\t\toidset_clear(&sb->ignore_list);\n+\tfor (idx = start_idx; idx < ignore_revs_file_list->nr; idx++) {\n+\t\ti = &ignore_revs_file_list->items[idx];\n+\t\tif (i->util)\n+\t\t\tparse_default_ignore_revs(sb, i->string);\n \t\telse\n \t\t\toidset_parse_file_carefully(&sb->ignore_list, i->string,\n \t\t\t\t\t\t    the_repository->hash_algo,\n@@ -1036,6 +1124,12 @@ int cmd_blame(int argc,\n \tconst char *const *opt_usage = cmd_is_annotate ? annotate_opt_usage : blame_opt_usage;\n \n \tsetup_default_color_by_age();\n+\t/*\n+\t * An entry with a non-NULL .util member names the default\n+\t * ignore-revs file at the project root; see build_ignorelist().\n+\t */\n+\tstring_list_append(&ignore_revs_file_list,\n+\t\t\t   \".git-blame-ignore-revs\")->util = (void *)1;\n \trepo_config(the_repository, git_blame_config, &output_option);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \trevs.date_mode = blame_date_mode;\ndiff --git a/oidset.c b/oidset.c\nindex 90d39204d3..8469d03b9b 100644\n--- a/oidset.c\n+++ b/oidset.c\n@@ -70,44 +70,76 @@ void oidset_parse_file(struct oidset *set, const char *path,\n \toidset_parse_file_carefully(set, path, algop, NULL, NULL);\n }\n \n+static void parse_oidset_line(struct oidset *set, struct strbuf *sb,\n+\t\t\t      const struct git_hash_algo *algop,\n+\t\t\t      oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tconst char *p;\n+\tconst char *name;\n+\tstruct object_id oid;\n+\n+\tif (memchr(sb->buf, '\\0', sb->len))\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\n+\t/*\n+\t * Allow trailing comments, leading whitespace\n+\t * (including before commits), and empty or whitespace\n+\t * only lines.\n+\t */\n+\tname = strchr(sb->buf, '#');\n+\tif (name)\n+\t\tstrbuf_setlen(sb, name - sb->buf);\n+\tstrbuf_trim(sb);\n+\tif (!sb->len)\n+\t\treturn;\n+\n+\tif (parse_oid_hex_algop(sb->buf, &oid, &p, algop) || *p != '\\0')\n+\t\tdie(\"invalid object name: %s\", sb->buf);\n+\tif (fn && fn(&oid, cbdata))\n+\t\treturn;\n+\toidset_insert(set, &oid);\n+}\n+\n void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata)\n {\n \tFILE *fp;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tstruct object_id oid;\n \n \tfp = fopen(path, \"r\");\n \tif (!fp)\n \t\tdie(\"could not open object name list: %s\", path);\n-\twhile (!strbuf_getline(&sb, fp)) {\n-\t\tconst char *p;\n-\t\tconst char *name;\n-\n-\t\tif (memchr(sb.buf, '\\0', sb.len))\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\n-\t\t/*\n-\t\t * Allow trailing comments, leading whitespace\n-\t\t * (including before commits), and empty or whitespace\n-\t\t * only lines.\n-\t\t */\n-\t\tname = strchr(sb.buf, '#');\n-\t\tif (name)\n-\t\t\tstrbuf_setlen(&sb, name - sb.buf);\n-\t\tstrbuf_trim(&sb);\n-\t\tif (!sb.len)\n-\t\t\tcontinue;\n-\n-\t\tif (parse_oid_hex_algop(sb.buf, &oid, &p, algop) || *p != '\\0')\n-\t\t\tdie(\"invalid object name: %s\", sb.buf);\n-\t\tif (fn && fn(&oid, cbdata))\n-\t\t\tcontinue;\n-\t\toidset_insert(set, &oid);\n-\t}\n+\twhile (!strbuf_getline(&sb, fp))\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n \tif (ferror(fp))\n \t\tdie_errno(\"Could not read '%s'\", path);\n \tfclose(fp);\n \tstrbuf_release(&sb);\n }\n+\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tconst char *p = buf, *end;\n+\n+\tif (!size)\n+\t\treturn;\n+\tend = buf + size;\n+\n+\twhile (p < end) {\n+\t\tconst char *nl = memchr(p, '\\n', end - p);\n+\t\tsize_t len = (nl ? nl : end) - p;\n+\n+\t\tstrbuf_reset(&sb);\n+\t\tif (len && p[len - 1] == '\\r')\n+\t\t\tlen--;\n+\t\tstrbuf_add(&sb, p, len);\n+\t\tparse_oidset_line(set, &sb, algop, fn, cbdata);\n+\t\tp = nl ? nl + 1 : end;\n+\t}\n+\tstrbuf_release(&sb);\n+}\ndiff --git a/oidset.h b/oidset.h\nindex e0f1a6ff4f..667c390842 100644\n--- a/oidset.h\n+++ b/oidset.h\n@@ -98,6 +98,15 @@ void oidset_parse_file_carefully(struct oidset *set, const char *path,\n \t\t\t\t const struct git_hash_algo *algop,\n \t\t\t\t oidset_parse_tweak_fn fn, void *cbdata);\n \n+/*\n+ * Similar to oidset_parse_file_carefully(), but parses lines from an\n+ * in-memory buffer of 'size' bytes.\n+ */\n+void oidset_parse_buffer_carefully(struct oidset *set, const char *buf,\n+\t\t\t\t   size_t size,\n+\t\t\t\t   const struct git_hash_algo *algop,\n+\t\t\t\t   oidset_parse_tweak_fn fn, void *cbdata);\n+\n struct oidset_iter {\n \tconst kh_oid_set_t *set;\n \tkhiter_t iter;\ndiff --git a/t/t8013-blame-ignore-revs.sh b/t/t8013-blame-ignore-revs.sh\nindex 70fe509a64..92d8296c7b 100755\n--- a/t/t8013-blame-ignore-revs.sh\n+++ b/t/t8013-blame-ignore-revs.sh\n@@ -365,4 +365,237 @@ test_expect_success 'ignore-revs-file peels chained tags and skips missing tag t\n \ttest_cmp expect actual\n '\n \n+# Tests for default .git-blame-ignore-revs\n+test_expect_success 'setup default .git-blame-ignore-revs' '\n+\tgit checkout -b default-file-branch &&\n+\ttest_write_lines line1 line2 >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default base\" &&\n+\tgit tag DEF_A &&\n+\n+\ttest_write_lines line1-modified line2-modified >def-file &&\n+\tgit add def-file &&\n+\ttest_tick &&\n+\tgit commit -m \"default mod\" &&\n+\tgit tag DEF_B &&\n+\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"add .git-blame-ignore-revs\"\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs is used by default' '\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs respected by git annotate' '\n+\tgit rev-parse --short DEF_A >expect_sha &&\n+\tgit annotate def-file >actual &&\n+\ttest_grep \"^$(cat expect_sha)\" actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs works from subdirectory' '\n+\ttest_when_finished \"rm -rf sub\" &&\n+\tmkdir -p sub &&\n+\techo \"invalid-oid-value\" >sub/.git-blame-ignore-revs &&\n+\t(\n+\t\tcd sub &&\n+\t\tgit blame --line-porcelain ../def-file >blame_raw &&\n+\t\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\t\tgit rev-parse DEF_A >expect &&\n+\t\ttest_cmp expect actual\n+\t)\n+'\n+\n+test_expect_success 'default HEAD:.git-blame-ignore-revs respected in bare repo' '\n+\ttest_when_finished \"rm -rf bare.git\" &&\n+\tgit clone --bare . bare.git &&\n+\tgit -C bare.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit -C .git blame --line-porcelain HEAD -- def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'uncommitted .git-blame-ignore-revs changes in working tree are respected' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs\" &&\n+\t: >.git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\n+\trm .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual &&\n+\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\ttest_must_fail git blame def-file\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with --no-ignore-revs-file' '\n+\tgit blame --line-porcelain --no-ignore-revs-file def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with --ignore-revs-file \"\"' '\n+\tgit blame --line-porcelain --ignore-revs-file \"\" def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'disable default .git-blame-ignore-revs with blame.ignoreRevsFile=\"\"' '\n+\ttest_config blame.ignoreRevsFile \"\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs handles comments and whitespace' '\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\t{\n+\t\techo \"# Leading comment\" &&\n+\t\techo \"\" &&\n+\t\techo \"   $rev_def_b   # inline comment\" &&\n+\t\techo \"# Trailing comment\"\n+\t} >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"comments and whitespace in .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'empty default .git-blame-ignore-revs is harmless' '\n+\t: >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"empty .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success SYMLINKS 'symlink .git-blame-ignore-revs in working tree is ignored' '\n+\ttest_when_finished \"git checkout -- .git-blame-ignore-revs && rm -f target_file\" &&\n+\tgit rev-parse DEF_B >target_file &&\n+\trm -f .git-blame-ignore-revs &&\n+\tln -s target_file .git-blame-ignore-revs &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'committed symlink .git-blame-ignore-revs in bare repo HEAD is ignored' '\n+\ttest_when_finished \"git reset --hard HEAD~ && rm -rf bare-symlink.git\" &&\n+\tblob=$(printf \"%s\" \"target_file\" | git hash-object -w --stdin) &&\n+\tgit update-index --replace --cacheinfo 120000,$blob,.git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"symlink .git-blame-ignore-revs\" &&\n+\tgit clone --bare . bare-symlink.git &&\n+\tgit -C bare-symlink.git blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'malformed default .git-blame-ignore-revs fails but can be bypassed' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\techo \"invalid-oid-value\" >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"malformed .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file &&\n+\tgit blame --no-ignore-revs-file def-file &&\n+\tgit blame --ignore-revs-file \"\" def-file &&\n+\tgit -c blame.ignoreRevsFile=\"\" blame def-file &&\n+\n+\trev_def_b=$(git rev-parse DEF_B) &&\n+\tprintf \"%sQgarbage\\n\" \"$rev_def_b\" | q_to_nul >.git-blame-ignore-revs &&\n+\tgit add .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"NUL in .git-blame-ignore-revs\" &&\n+\ttest_must_fail git blame def-file 2>err &&\n+\ttest_grep \"invalid object name:\" err\n+'\n+\n+test_expect_success 'default .git-blame-ignore-revs combined with config blame.ignoreRevsFile' '\n+\tgit rev-parse DEF_B >.git-blame-ignore-revs &&\n+\ttest_write_lines line1-modified line2-c >def-file &&\n+\tgit add .git-blame-ignore-revs def-file &&\n+\ttest_tick &&\n+\tgit commit -m C &&\n+\tgit tag DEF_C &&\n+\tgit rev-parse DEF_C >custom_ignore &&\n+\ttest_config blame.ignoreRevsFile custom_ignore &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 2/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_A >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'blame works when .git-blame-ignore-revs does not exist' '\n+\tgit rm -f .git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"remove .git-blame-ignore-revs\" &&\n+\tgit blame --line-porcelain def-file >blame_raw &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success EXPENSIVE 'overly large default .git-blame-ignore-revs is ignored' '\n+\ttest_when_finished \"rm -f .git-blame-ignore-revs\" &&\n+\tdd if=/dev/zero of=.git-blame-ignore-revs bs=1048576 count=101 2>/dev/null &&\n+\tgit blame --line-porcelain def-file >blame_raw 2>err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\tgit rev-parse DEF_B >expect &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"warning: ignoring overly large ignore-revs file '\\''.git-blame-ignore-revs'\\''\" err &&\n+\n+\tblob=$(git hash-object -w .git-blame-ignore-revs) &&\n+\trm -f .git-blame-ignore-revs &&\n+\tgit update-index --add --cacheinfo 100644,$blob,.git-blame-ignore-revs &&\n+\ttest_tick &&\n+\tgit commit -m \"overly large .git-blame-ignore-revs\" &&\n+\ttest_when_finished \"git reset --hard HEAD~\" &&\n+\tgit -C .git blame --line-porcelain HEAD -- def-file >blame_raw 2>err &&\n+\tsed -ne \"/^[0-9a-f][0-9a-f]* [0-9][0-9]* 1/s/ .*//p\" blame_raw >actual &&\n+\ttest_cmp expect actual &&\n+\ttest_grep \"warning: ignoring overly large ignore-revs blob '\\''HEAD:.git-blame-ignore-revs'\\''\" err\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"554908","messageId":"20261013202448.2116038-1-rmistry@google.com","threadId":"66313","inReplyTo":"xmqq4iepzex9.fsf@gitster.g","subject":"Re: [PATCH v5 0/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Ravi Mistry","fromEmail":"rmistry@google.com","sentAt":"2026-10-13T20:24:48Z","receivedAt":"2026-10-13T20:24:48Z","isPatch":true,"sender":{"key":"rmistry@google.com","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> >      ++\tconfig option.  An empty file name, `\"\"`, or `--no-ignore-revs-file` will\n>\n> That's \"a configuration variable\".\n\nFixed in Documentation/blame-options.adoc and in the commit log\nmessage.\n\n> Hmph, build_ignorelist() ignores the string and only pays attention\n> to the fact that the string_list_item having a non-null .util member,\n> so this diff, and the fact that a specific string is on the list, is\n> a bit misleading in two ways (i.e., the string itself does not\n> matter, and the value of .util member does not metter, either).\n...\n> It probably deserves a comment to help future readers, e.g.\n>\n> \t\t/*\n> \t\t * An entry with non-NULL .util member adds the\n> \t\t *  .git-blame-ignore-revs at the project root;\n>                  * see build_ignorelist()\n> \t\t */\n>                 string_list_append(&ignore_revs_file_list,\n>                                    \".git-blame-ignore-revs\")->util = &sb;\n>\n> or something?  It is especially misleading to pass &sb here because\n> it is not used as a scoreboard at all anywhere.\n\nIn v6, build_ignorelist() passes i->string to\nparse_default_ignore_revs() so the string is actually used (both for\nthe working-tree path and for \"HEAD:<path>\" in bare repositories), and\ncmd_blame() sets ->util = (void *)1 with an explanatory comment (rather\nthan passing the scoreboard).\n\nThanks!\n\n"},{"id":"554913","messageId":"xmqqse29uyh3.fsf@gitster.g","threadId":"66313","inReplyTo":"20261013202448.2116038-1-rmistry@google.com","subject":"Re: [PATCH v5 0/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-13T20:39:20Z","receivedAt":"2026-10-13T20:39:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ravi Mistry <rmistry@google.com> writes:\n\n> In v6, build_ignorelist() passes i->string to\n> parse_default_ignore_revs() so the string is actually used (both for\n> the working-tree path and for \"HEAD:<path>\" in bare repositories), and\n> cmd_blame() sets ->util = (void *)1 with an explanatory comment (rather\n> than passing the scoreboard).\n\nVery cleanly done.  I very much like this new design that still\nhonors what the item->string says, instead of \"ah, .util is not\nNULL, so let's do the hardcoded default thing\".\n\nUnless I hear objections in a few days, let's mark the topic ready\nfor 'next'.\n\nWill replace.  Thanks.\n\n"},{"id":"555154","messageId":"d9c282e4-f960-49a9-a9a5-edd833e3d6ae@gmail.com","threadId":"66313","inReplyTo":"xmqqse29uyh3.fsf@gitster.g","subject":"Re: [PATCH v5 0/2] blame: ignore revs in .git-blame-ignore-revs by default","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-10-15T15:19:45Z","receivedAt":"2026-10-15T15:19:45Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 13/10/2026 21:39, Junio C Hamano wrote:\n> Ravi Mistry <rmistry@google.com> writes:\n> >> In v6, build_ignorelist() passes i->string to\n>> parse_default_ignore_revs() so the string is actually used (both for\n>> the working-tree path and for \"HEAD:<path>\" in bare repositories), and\n>> cmd_blame() sets ->util = (void *)1 with an explanatory comment (rather\n>> than passing the scoreboard).\n> > Very cleanly done.  I very much like this new design that still\n> honors what the item->string says, instead of \"ah, .util is not\n> NULL, so let's do the hardcoded default thing\".\n> > Unless I hear objections in a few days, let's mark the topic ready\n> for 'next'.\nI'm not sure we need the lstat() call before open_nofollow() in the second patch of V6 but everything else looked good - I'd be happy to see that version merged.\n\nThanks\n\nPhillip\n\n"}]}