mkdocs-git-authors-plugin icon indicating copy to clipboard operation
mkdocs-git-authors-plugin copied to clipboard

Ignore whitespace-only changes

Open ThiefMaster opened this issue 2 years ago • 10 comments

I just reformatted docs because people had trailing whitespace in many places. This doesn't mean I should be considered an author, so it would be nice if whitespace changes were ignored. Alternatively, a way to mention in the detailed commit message that it should be excluded from this plugin would work too

ThiefMaster avatar Feb 17 '23 13:02 ThiefMaster

Hi @ThiefMaster,

The way this plugin works is that it uses git blame --porcelain (see this method).

Adding logic that checks per line if there was only a whitespace added compared to the previous commit, and then recursively going through the commit history for that line and finding the next author, well that's going to be complex & slow, so not worth it.

Would the authorship_threshold_percent option be a good outcome here? https://timvink.github.io/mkdocs-git-authors-plugin/options.html#authorship_threshold_percent

It would be nice to have a feature where you could add some YAML frontmatter to a specific page to overwrite the authors determined by the git history. Open to PRs for that one :)

timvink avatar Feb 20 '23 08:02 timvink

I tried that but it didn't work well - especially for smaller pages the changes may be significant enough to go above the threshold while keeping is reasonable for actual changes.

Would it be possible to check for something like mkdocs-authors-exclude in the commit message (ideally not summary, space there is too) and/or add a simple option to blacklist certain commit hashes for this feature?

ThiefMaster avatar Feb 20 '23 09:02 ThiefMaster

I had a look, and yes, that is possible: https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt

The cool thing is, there are no changes needed to this plugin to use it. See this blogpost: https://michaelheap.com/git-ignore-rev/

Summary:

  • Add a file to your repo called .git-blame-ignore-revs with git hashes to ignore
  • Run git config --global blame.ignoreRevsFile .git-blame-ignore-revs (or remove --global to set the config only for one repository). If you run builds on CI, you will have to add this line also.

Let me know if that solves it. Might be nice to add to the documentation as a 'how to'

timvink avatar Feb 20 '23 13:02 timvink

Haven't tested it yet but it indeed sounds like good solution.

ThiefMaster avatar Feb 20 '23 13:02 ThiefMaster

Can you let me know if the solution worked for you?

timvink avatar Apr 06 '23 14:04 timvink

I also have some use cases where it would be nice to be able to exclude authors from the list. "Bulk" reformattings is one of them. I tried the solution .git-blame-ignore-revs, and it works to some extent. However, there are still changes that blame cannot attribute to other commits, which still impact the list of authors.

In my case, ignoring the names from a configurable list of authors would be a simple way to support what I need. Would you be open to this feature? If so, I can try to work on a PR to support it.

rcgoncalves avatar Mar 10 '24 15:03 rcgoncalves

Thanks for chipping in! I'd appreciate a PR here.

Basically we want to ignore certain authors and certain commit hashes. I think we can use the same mechanism for both. Are you open to fixing both issues?

Happy to brainstorm with you on how to do it. First thought would be to add two options ignore_authors and ignore_commits which when specified should point to a .txt file. Maybe it could be a single list, and a single option ignore_revs if it's obvious enough for users how to use it (either add hashes or emailaddresses) and the implementation is clean enough.

timvink avatar Mar 12 '24 22:03 timvink

Btw, here's a similar PR to a very similar package: https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/pull/114/files

timvink avatar Mar 12 '24 22:03 timvink

I was only thinking about an ignore_authors option, as I though that would make the ignore_commits unnecessary. But thinking a bit more about it, I guess that without the ignore_commits, we would be able to remove some undesired authors, but we would not give credit to the "original" authors of some lines. So, ideally, I need to use both features.

Considering that both features are useful, do you think that the ignore_commits should also be supported by the plugin?

Personally, for that feature I'm fine with using git config --global blame.ignoreRevsFile. Considering the complexity of the logic, I guess the only thing the plugin could do is to add --ignore-revs-file to the Git command. Does this sounds a reasonable option to you?


Regarding the ignore_authors option, I was thinking about adding the logic to the mkdocs_git_authors_plugin.git.page.Page.get_authors() method (before the logic to check author_threshold). What do you think?

rcgoncalves avatar Mar 14 '24 15:03 rcgoncalves

I opened a PR attempting to implement these features: https://github.com/timvink/mkdocs-git-authors-plugin/pull/85

rcgoncalves avatar Apr 15 '24 19:04 rcgoncalves