From: Phillip Wood Date: Thu, 24 Nov 2022 10:31:46 GMT Subject: Re: [bug] git log --invert-grep --grep=[sufficiently complicated regex] prints nothing Message-ID: <909b0770-2ac2-1a87-498b-0537a94e94ac@dunelm.org.uk> In-Reply-To: <71fcf215-101e-4398-bffa-4ed7e286d9c8@app.fastmail.com> Hi Zack On 23/11/2022 20:17, Zack Weinberg wrote: > I’m attempting to have my blog, which is a static site generated from > a bunch of Markdown files stored in git, automatically pull the > the most recent modification date for each page out of the git history. > The idea is to use ‘git log --follow --pretty=tformat:'%ct' ‘ on > each file and then use the oldest reported timestamp as the creation > date and the newest reported timestamp as the last modification date. > > But there’s a catch: there are commits I want to ignore in this > calculation, such as mechanical changes applied to the entire site. > And this brings me to the bug: --invert-grep doesn’t work correctly > when the --grep regex is sufficiently complicated. > > Here's the complete set of commits that modified an example file: > > $ git log --follow --pretty=tformat:'%ct %s' \ > src/posts/uncat/unearthed-arcana-music-division.md > 1668545053 Begin restoring the site structure. > 1668545051 Reorganize directory tree prior to setting up Metalsmith > 1668545032 Mechanically convert Pandoc to standard YAML metadata delimiters. > 1610735533 Mechanically convert to properly delimited YAML metadata. > 1417101173 Correct slug for Uncategorized. > 1417050416 The Great Dead and Moved Link Cleanup of 2014. > 1416938128 Use category_meta plugin to fix category slugs. > 1416763607 Initial import of content and Pelican skeleton. > > And here's an application of --grep that prints only the commits I _don't_ want: > > $ git log --follow -E --pretty=tformat:'%ct %s' \ > --grep='^(Mechanically convert|Begin restoring the site structure|Reorganize directory tree)' \ > src/posts/uncat/unearthed-arcana-music-division.md > 1668545053 Begin restoring the site structure. > 1668545051 Reorganize directory tree prior to setting up Metalsmith > 1668545032 Mechanically convert Pandoc to standard YAML metadata delimiters. > 1610735533 Mechanically convert to properly delimited YAML metadata. > > Theoretically, adding --invert-grep to that should make it print the > commits I do want, but instead it prints nothing at all: I think the problem is that you are excluding the commit that renames the file and that stops --follow from following the rename. See below for a simple reproduction using git's test suite. I'm afraid I'm not familiar with the --follow code so I've no idea how to fix this. Best Wishes Phillip ---- >8 ---- #!/bin/sh test_description='Demonstrate `git log --follow --grep` failure' . ./test-lib.sh test_expect_failure '--grep breaks --follow' ' test_commit first file-a "$(seq 1 100)" && git rm file-a && test_commit second file-b "$(seq 2 101)" && test_commit third file-b "$(seq 3 102)" && git log --follow --grep "^first" file-b >actual && git log first >expect && test_cmp expect actual ' test_expect_success '--grep breaks --follow' ' git log --follow -E --grep "^(first|second)" file-b >actual && git log second >expect && test_cmp expect actual ' test_done