tpope / vim-fugitive

fugitive.vim: A Git wrapper so awesome, it should be illegal
https://www.vim.org/scripts/script.php?script_id=2975
20.09k stars 1.01k forks source link

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

Open zivarah opened 8 months ago

zivarah commented 8 months ago

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 https://github.com/tpope/vim-fugitive/issues/2260#issuecomment-1913318380).

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

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:

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:

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 commented 7 months ago

@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.