Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Allow custom format string for status buffer log lines #2287

Open
zivarah opened this issue Mar 29, 2024 · 1 comment
Open

Comments

@zivarah
Copy link

zivarah commented Mar 29, 2024

It looks like the format string used to display lines in the status buffer is hardcoded:

function! s:QueryLog(refspec, limit, dir) abort
  let [log, exec_error] = s:LinesError(['log', '-n', '' . a:limit, '--pretty=format:%h%x09%s'] + a:refspec + ['--'], a:dir)

Has there been any consideration for allowing this to by customized? Taking a simple example of wanting to display the commit author:

function! s:QueryLog(refspec, limit, dir) abort
  let [log, exec_error] = s:LinesError(['log', '-n', '' . a:limit, '--pretty=format:%h%x09%<(15,trunc)%cn %s'] + a:refspec + ['--'], a:dir)

image

Another use case I could see would be floating a specific trailer (for a bug ID or some other oft-used trailer).

Technically, it certainly appears to be pretty trivial: just allow defining some new g:fugitive_log_format value, default it to "%s", and then plop that value into this string (keeping the hard-coded %h%x09 so that the user can't mess that up).

The main question seems to be how to handle different desired formats in different repositories (which I know you were hesitant to commit to a specific path for in #2260 (comment)).

My initial thought was that it could be fairly easily handled via some sort of pretty.<name> git config:

  • set pretty.fugitive = %s globally
  • set pretty.fugitive = %<(15,trunc)%cn %s in a specific repo
  • set g:fugitive_log_format to fugitive
  • Use ... ['--pretty=%h%x09' . g:fugitive_log_format] ...

However, git doesn't seem to have any special syntax to allow plopping a pretty alias name into a format string recursively like that.

This would work if we allowed the user to override the whole string:

  • set pretty.fugitive = format:%h%x09%s globally
  • set pretty.fugitive = format:%h%x09%<(15,trunc)%cn %s in a specific repo
  • set g:fugitive_log_format to fugitive
  • Use ... ['--pretty=' . g:fugitive_log_format] ...

But now of course we've given the user a terrible footgun to break the parsing.

So unfortunately I'm not sure how to solve this without either:

  • Caveat that the format can't cleanly be different between repositories, or
  • Giving the user a footgun
  • Committing to a repo-specific fugitive path

At the risk of opening a can of worms: Have you considered allowing fugitive config via git config (something that I know other clients like TortoiseGit have done) for those values that really warrant per-repo differences?

[fugitive]
    statusLogFormat = "%<(15,trunc)%cn %s"

That feels fairly elegant to me, though also obvious enough that I assume there's probably some reasons you've been hesitant to go that route?

@zivarah
Copy link
Author

zivarah commented Apr 2, 2024

@tpope would you be open to a pull request that addresses this via a "fugitive" section in git-config as proposed at the end of the initial issue post? I'm happy to put one together if that's a path you're willing to take.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant