git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Zack Weinberg <zack@owlfolio.org>, git@vger.kernel.org
Subject: Re: [bug] git log --invert-grep --grep=[sufficiently complicated regex] prints nothing
Date: Thu, 24 Nov 2022 10:31:46 +0000	[thread overview]
Message-ID: <909b0770-2ac2-1a87-498b-0537a94e94ac@dunelm.org.uk> (raw)
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' <file>‘ 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

  reply	other threads:[~2022-11-24 10:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 20:17 [bug] git log --invert-grep --grep=[sufficiently complicated regex] prints nothing Zack Weinberg
2022-11-24 10:31 ` Phillip Wood [this message]
2022-11-24 13:36   ` Zack Weinberg
2022-11-24 15:53     ` Ævar Arnfjörð Bjarmason
2022-11-24 16:35       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=909b0770-2ac2-1a87-498b-0537a94e94ac@dunelm.org.uk \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=zack@owlfolio.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).