rbong / vim-flog

A blazingly fast, stunningly beautiful, exceptionally powerful git branch viewer for Vim/Neovim.
750 stars 22 forks source link

Add "native support" for --first-parent option #104

Closed lervag closed 1 year ago

lervag commented 1 year ago

I'm working in a relatively big project where the full Git log becomes unwieldy. I find it is often useful to include the --first-parent option, as I am often only interested in seeing the changes applied to the current branch (e.g. master).

I would love to see a similar option to the -merges and -no-merges option, e.g.:

:Flog -first-parent                                      *:Flog_-first-parent*
:Flog -no-first-parent                                *:Flog_-no-first-parent*

  When enabled, pass the "--first-parent" argument to "git log".
  Disabled by default.

… SNIP …

                                               *<Plug>(FlogToggleFirstParent)*
gP                                                                   *flog-gP*

  Toggle |:Flog-first-parent|.

By the way, it seems there are some minor errors in the helpfile tags. I may submit a PR to help fix that if you are interested.

TamaMcGlinn commented 1 year ago

does passing -raw-args= work for your use case? I.e.

:Flog -raw-args=--first-parent
lervag commented 1 year ago

Yes; the main benefit of my feature request is to easily toggle this argument. I currently use the following map inside floggraph buffers, which works as expected:

nnoremap gP :Flogsetargs -- --first-parent<cr>

Doing :Flog -- --first-parent also works, of course. But the requested feature would, if implemented as I hope, allow to toggle the option on and off.

rbong commented 1 year ago

I am always hesitant to add new options like this because binding real estate is hard to find. We have to make sure we both don't conflict too heavily with Fugitive and that it makes sense in the context of Flog with the few safe bindings we have available, so I want to make sure every option is a really good choice to add.

Thankfully in Fugitive gP is something that we'll probably never need an equivalent binding for ("Jump to file [count] in the "Unpulled" section"), so it's a good choice. But I still have a few questions.

Can you please describe:

Thank you.

lervag commented 1 year ago

I am always hesitant to add new options like this because binding real estate is hard to find.

Yes, I can relate to and respect that!

Can you please describe:

  • When you would use this option in your workflow (different cases you might find this option useful)

Yes. First, some context: I find myself working in a relatively big (not huge) repo with O(10) contributors. The Git history is messy and people are creating merge commits all over the place. There is not much rebasing and squashing, and so I've found it is hard to use the Git log through e.g. Flog to inspect the most relevant history.

I've found that git log --first-parent is very useful in this case, because it will remove the noicy branches and only show the commits from my current branch and backwards; e.g. the main commits (usually merge commits) on main/master. In many cases, this is as useful to me as seeing the actual tree that includes the source branches.

  • How often you would use it

I find I use it quite often now, perhaps once or twice a day.

I've already made my own mapping on top of Flog:

vim.keymap.set("n", "gP", "<cmd>Flogsetargs -- --first-parent<cr>", { buffer = true})

The main problem with this mapping is that I can't revert it. I have to kill the Flog buffer and open it fresh if I regret activating the argument. This is only a minor inconvenience, of course.

rbong commented 1 year ago

I can't revert it

You can do:

Flogsetargs -raw-args=

Thanks for making your case, I will probably add this.

lervag commented 1 year ago

Great, thanks! :)

By the way: Is there a way to inspect the current raw args?

rbong commented 1 year ago

Is there a way to inspect the current raw args?

You can do echo b:flog_state.opts.raw_args

rbong commented 1 year ago

Added

lervag commented 1 year ago

Great, thanks!