Skip to content

Visualize local branch heads in commits panel#2737

Closed
stefanhaller wants to merge 8 commits intomasterfrom
visualize-local-branch-heads
Closed

Visualize local branch heads in commits panel#2737
stefanhaller wants to merge 8 commits intomasterfrom
visualize-local-branch-heads

Conversation

@stefanhaller
Copy link
Collaborator

This implements the approach suggested in #2735, and removes the experimentalShowBranchHeads config again because it should no longer be needed.

@stefanhaller stefanhaller force-pushed the visualize-local-branch-heads branch 2 times, most recently from efd5125 to 9fdcc64 Compare June 26, 2023 06:36
@stefanhaller
Copy link
Collaborator Author

@jesseduffield I'd be interested in your thoughts on this. The branch conflicts pretty heavily with other work that I have open, so it's going to be painful to carry it around for longer.

@jesseduffield
Copy link
Owner

@stefanhaller I intend to get around to this: but have yet to find the time to properly read through the issue

@peppy
Copy link

peppy commented Jun 26, 2023

Looking at this from a visual perspective, It's definitely better than before (less noisy for my use case), but looking at the following screenshot:

2023-06-27 00 11 41@2x

I feel like I'd want to see some context as to which head/branch is at this point. As someone who basically never switches to the full git graph view, it would be nice to see it on the right pane in the header details for the commit, similar to how it's already displayed when viewing a branch directly:

2023-06-27 00 13 47@2x

@stefanhaller
Copy link
Collaborator Author

I agree, and it does do that for me. I'm using the delta pager, which seems to add this information. I was a bit surprised to see that, I didn't actually know this would be possible, as I thought the pager was purely a post-processor; but I don't see any other config setting that could be responsible for this.

Give it a try, delta is awesome anyway. 😄

@peppy
Copy link

peppy commented Jun 27, 2023

I tried using the delta pager in the past, but it results in broken displays which are very hard to read so don't see that as an option:

iTerm2 2023-06-27 at 05 23 46

iTerm2 2023-06-27 at 05 25 38

@stefanhaller
Copy link
Collaborator Author

As for delta: it can be configured pretty heavily, you might try to tone it down a bit to make it less noisy. My own preferred configuration is (this goes in ~/.gitconfig:

[delta]
	syntax-theme = none
	file-decoration-style = yellow ol
	file-style = yellow bold
	hunk-header-decoration-style = blue
	hunk-header-style = file normal
	hunk-header-decoration-style = ol ul magenta
	hunk-header-file-style = blue
	minus-style = normal "#660000"
	minus-emph-style = normal "#aa1111"
	plus-style = normal "#004400"
	plus-emph-style = normal "#117711"
	line-numbers = true

The main reason why I use delta is the word highlighting which shows which parts of a line have changed. I wouldn't want to live without this any more.

As for the branch annotation though: I'm very confused about this. When I run lazygit without delta, I don't see it, but when I type git show on the command line (which is what lazygit uses to render the display), I do. Can anybody explain this?

image image

@stefanhaller
Copy link
Collaborator Author

Hm, it looks like git bases the decision whether or not to show the branch annotation on whether output goes to a tty; I don't see a git option to influence this. So if you don't like delta, a very crude workaround is to set your pager to cat. 😄

git:
  paging:
    pager: cat

I still don't fully understand it, I wonder if it's a bug in git.

@peppy
Copy link

peppy commented Jun 27, 2023

Hm, it looks like git bases the decision whether or not to show the branch annotation on whether output goes to a tty; I don't see a git option to influence this. So if you don't like delta, a very crude workaround is to set your pager to cat. 😄

This works great. I do wonder if this should be default for lazygit.

@stefanhaller
Copy link
Collaborator Author

I read the git source code a bit, and found that it's intentional to show ref names when the output is a tty, and don't show them if not. This corresponds to the --decorate=auto option of git log. This means that another workaround is to do git config --global log.decorate short, which git show respects too.

For lazygit, the best fix is to pass --decorate to git show. I'll make a PR.

@stefanhaller stefanhaller force-pushed the visualize-local-branch-heads branch from 9fdcc64 to 64a6341 Compare June 27, 2023 19:45
@stefanhaller
Copy link
Collaborator Author

PR is here: #2748

It shows that right now, we take only the first tag if there are multiple.
Judging from how the code is written, I'm not sure this was intentional.
We now store all tags in this field if there are several.
These tests not only test the correct handling and display of the updateRef
command, but also the visualization of branch heads in the commits panel. Since
we are about to change the behavior here, extend the tests so that a master
commit is added (we don't want this to be visualized as a branch head), and then
a stack of two non-main branches. At the end of this branch we only want to
visualize the head commit of the first.
This allow us to check not only whether a given commit has the branch head
marker, but also that other commits _don't_ have it, which is important.
Don't visualize branch heads of main branches or remote branches.
It should no longer be needed now, because the (*) marker now only appears for
stacks of local branches, and in this situation it is always useful and
shouldn't confuse people who create such stacks.
@stefanhaller stefanhaller force-pushed the visualize-local-branch-heads branch from 64a6341 to 3cb954c Compare June 30, 2023 13:15
Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked closely at the code but one thing I want to explore is not involving remotes when loading the commits. If these markers are purely presentational we could instead filter out remote branch heads in the presentation package. The reason for this is that it means we don't need to ensure they're loaded by the time we're loading our commits. When I run this PR locally I see the head markers appear briefly and then disappear. I'm not sure why that is but I assume it's due to the remotes and if so, leaving it to the presentation layer should fix the issue

@jesseduffield
Copy link
Owner

jesseduffield commented Jul 10, 2023

Actually something that just occurred to me that could vastly simplify this: we now obtain commit hashes when we load local branches. We could use those when displaying the commits. That would spare much of the complexity of the current solution. That is: in the presentation package, when displaying commits, we pass in branch commit hashes and if a given commit matches the hash, we show the marker. The only extra thing is that we'd need to refresh the commits view after loading branches (trivially easy to do)

@stefanhaller
Copy link
Collaborator Author

Actually something that just occurred to me that could vastly simplify this: we now obtain commit hashes when we load local branches. We could use those when displaying the commits.

That's a great idea, I'm trying this right now, and indeed it greatly simplifies things.

One thing that I'm not sure how to do: I need to read .git/rebase-merge/head-name in order to find out whether a commit points to the head of the branch that is currently being rebased (we don't want to show the marker for this one). In the previous version of the PR I did it like this. Now I need the same thing in GetCommitListDisplayStrings (or at the call site and pass it in), but I can't figure out how to get at dotGitDir there. But I have the feeling I shouldn't be loading files at that place in the code anyway, but rather have a function somewhere that does this. Any suggestions where this would go?

@jesseduffield
Copy link
Owner

I agree that we should obtain that info ahead of time to keep the presentation code pure. I'm happy to add the merge head as a field on our Model struct and set that from RefreshHelper (perhaps as part of loading branches or loading commits, or as its own separate thing).

@stefanhaller
Copy link
Collaborator Author

Since the new approach is quite different from this one, I'm opening a new PR for it: #2775.

@stefanhaller stefanhaller mentioned this pull request Jul 13, 2023
6 tasks
@stefanhaller stefanhaller deleted the visualize-local-branch-heads branch August 1, 2023 12:46
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

Successfully merging this pull request may close these issues.

3 participants