1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-22 15:22:51 +03:00

6368 Commits

Author SHA1 Message Date
Stefan Haller
02aeb6101c Remove unused struct 2024-06-23 14:47:50 +02:00
Stefan Haller
2ccd9980e3
Fix wrong highlight in staging panel when entering file with only staged changes (#3667)
Reproduction recipe:
1. stage all changes in a file by pressing space on it in the files panel
2. enter the staged changes panel by pressing enter
3. unstage one of the changes

This makes the unstaged changes panel visible, but keeps the focus in
the staged changes panel. However, the highlight in the unstaged changes
view becomes visible, as if it were focused.

Fixes #3664
2024-06-23 14:46:36 +02:00
Stefan Haller
db0a1586d9 Highlight inactive selection in bold
An inactive selection is one where the view is part of the context stack, but
not the active view. For example, the files view when you enter the staging
panel, or any view when you open a panel.
2024-06-23 14:43:13 +02:00
Stefan Haller
4e441127f3 Clear highlight in HandleFocusLost
Remove the old mechanism of clearing the highlight in Layout.

This fixes a problem with a wrong highlight showing up in the staging panel when
entering a file with only staged changes.

Reproduction recipe:
1. stage all changes in a file by pressing space on it in the files panel
2. enter the staged changes panel by pressing enter
3. unstage one of the changes
This makes the unstaged changes panel visible, but keeps the focus in the staged
changes panel. However, the highlight in the unstaged changes view becomes
visible, as if it were focused.

To explain why this happens, you need to know how the selection highlighting of
a view is turned on or off. It is turned on when it gains the focus, i.e. when
ActivateFocus is called on it, which in turn happens when PushContext is called.
It is turned off in Layout when gocui sees that the current view is no longer
the same as last time, in which case it calls onViewFocusLost on the previous
current view.

This mechanism only works reliably when there is at most one PushContext call
per event handler. If there is more than one, then the first one gets its
highlight turned on, then the second one, but since gocui has never seen the
first one as the active view in Layout, it doesn't get the highlight turned off
again even though it should.

And this happens in the above scenario. When pressing enter on a file with only
staged changes, we first push the staging context (in
FilesController.EnterFile), and then later we push the stagingSecondary context
when we realize we only have staged changes. This leaves the highlight of the
staging context on.
2024-06-23 13:21:49 +02:00
Stefan Haller
cf40a5b077
Improve render performance (#3686)
- **PR Description**

Fix a performance regression that I introduced with v0.41: when entering
or leaving staging mode for a file, or when switching from a file that
has only unstaged changes to one that has both staged and unstaged
changes, there was a noticeable lag of about 500ms on my machine. With
the improvements in this PR we get this back down to about 20ms.
2024-06-23 13:13:58 +02:00
Stefan Haller
26132cf5bd Use utils.StringWidth to optimize rendering performance
runewidth.StringWidth is an expensive call, even if the input string is pure
ASCII. Improve this by providing a wrapper that short-circuits the call to len
if the input is ASCII.

Benchmark results show that for non-ASCII strings it makes no noticable
difference, but for ASCII strings it provides a more than 200x speedup.

BenchmarkStringWidthAsciiOriginal-10            718135       1637 ns/op
BenchmarkStringWidthAsciiOptimized-10        159197538          7.545 ns/op
BenchmarkStringWidthNonAsciiOriginal-10         486290       2391 ns/op
BenchmarkStringWidthNonAsciiOptimized-10        502286       2383 ns/op
2024-06-23 13:10:48 +02:00
Stefan Haller
a67eda39a5 Rerender fewer views when their width changes
In d5b4f7bb3e and 58a83b0862 we introduced a combined mechanism for rerendering
views when either their width changes (needed for the branches view which
truncates long branch names), or the screen mode (needed for those views that
display more information in half or full screen mode, e.g. the commits view).

This was a bad idea, because it unnecessarily rerenders too many views when just
their width changes, which causes a noticable lag. This is a problem, for
example, when selecting a file in the files panel that has only unstaged
changes, and then going to one that has both staged and unstaged changes; this
splits the main view, causing the side panels to become a bit narrower, and
rerendering all those views took almost 500ms on my machine. Another similar
example is entering or leaving staging mode.

Fix this by being more specific about which views need rerendering under what
conditions; this improves the time it takes to rerender in the above scenarios
from 450-500s down to about 20ms.

This reintroduces the code that was removed in 58a83b0862, but in a slightly
different way.
2024-06-23 13:10:48 +02:00
Stefan Haller
8e1464f720 Don't redraw remote branches view when its width changes
The rendering of remote branches is in no way dependent on the width of the view
(or the screen mode). Unlike in the local branches view, we don't truncate long
branch names here (because there's no more information after them).

This is an error introduced in d5b4f7bb3e.
2024-06-23 13:08:01 +02:00
Stefan Haller
a62a5089d6
Show current value in menus (#3628)
- **PR Description**

Some of our menus let you pick a value for some option (e.g. the sort
order menus for branches and commits). It's nice to see which one is the
current value when opening such a menu, so this PR implements that.

For menus that also have key bindings, the radio button goes between the
key and the label.

As an alternative, I considered selecting the current value when the
menu is opened; however, we currently have no menus where we select a
different entry than the first one, and it might be confusing for people
who are used to opening a menu and then pressing down-arrow a certain
number of times to get to a particular value.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-23 12:56:08 +02:00
Stefan Haller
4967e5136e Show radio buttons in the show log graph and commit sort order menus 2024-06-23 12:53:15 +02:00
Stefan Haller
68c966567c Show radio buttons in the sort order menu for branches 2024-06-23 12:53:15 +02:00
Stefan Haller
20a4aeab6e Support showing checkboxes or radio buttons in menus
For checkboxes it probably doesn't really make sense to use them yet, because
we'd have to find a way how you can toggle them without closing the dialog; but
we already provide rendering for them to lay the ground.

But radio buttons can be used already, because for those it is ok to close the
dialog when choosing a different option (as long as there is only one grounp of
radio buttons in the panel, that is).
2024-06-23 12:53:15 +02:00
Stefan Haller
a5620ebe3a
Always show the "Discard unchanged changes" menu item (#3683)
Always show the "Discard unchanged changes" menu item in the Discard
menu, just strike it through if not applicable. This will hopefully help
with confusion about the meaning of "all" in the "Discard all changes"
entry; some people misunderstand this to mean all changes in the working
copy. Seeing the "Discard unstaged changes" item next to it hopefully
makes it clearer that "all" is meant in contrast to that.
2024-06-23 12:46:59 +02:00
Stefan Haller
1b245ef5f6 Always show the "Discard unchanged changes" menu item
Strike it through if not applicable. This will hopefully help with confusion
about the meaning of "all" in the "Discard all changes" entry; some people
misunderstand this to mean all changes in the working copy. Seeing the "Discard
unstaged changes" item next to it hopefully makes it clearer that "all" is meant
in contrast to that.
2024-06-23 12:43:34 +02:00
Stefan Haller
a08c86c182
Fix custom patch operations for added files (#3684)
- **PR Description**

Several custom patch commands on parts of an added file would fail with the
confusing error message "error: new file XXX depends on old contents".
These were dropping the custom patch from the original commit, moving the
patch to a new commit, moving it to a later commit, or moving it to the index.

We fix this by converting the patch header from an added file to a diff against
an empty file. We do this not just for the purpose of applying the patch, but
also for rendering it and copying it to the clip board. I'm not sure it matters
much in these cases, but it does feel more correct for a filtered patch to be
presented this way.

Fixes #3679.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-23 12:43:09 +02:00
Stefan Haller
4cd15a36e3 Fix custom patch operations on added files
Several custom patch commands on parts of an added file would fail with the
confusing error message "error: new file XXX depends on old contents". These
were dropping the custom patch from the original commit, moving the patch to a
new commit, moving it to a later commit, or moving it to the index.

We fix this by converting the patch header from an added file to a diff against
an empty file. We do this not just for the purpose of applying the patch, but
also for rendering it and copying it to the clip board. I'm not sure it matters
much in these cases, but it does feel more correct for a filtered patch to be
presented this way.
2024-06-23 12:40:31 +02:00
Stefan Haller
13a35408e6 Introduce options struct for RenderPatchForFile
We're going to add another argument in the next commit, and that's getting a bit
much, especially when most of the arguments are bool and you only see true and
false at the call sites without knowing what they mean.
2024-06-23 12:40:31 +02:00
Stefan Haller
1a76a7da09 Add test for moving a patch from an added file to an earlier commit
This currently works (albeit with a bit of manual work, as the user needs to
resolve conflicts), and we add this test just to make sure that we don't break
it with the following change.
2024-06-23 12:40:31 +02:00
Stefan Haller
8a16f24ecb Add test for moving a patch from a deleted file to a new commit
This currently works, we add it as a regression test to make sure we don't break
it. It is an interesting test because it turns the deletion of the file in the
moved-from commit into a modification.
2024-06-23 12:40:31 +02:00
Stefan Haller
e2b4d9cff3 Remove unneccesary test actions
Pressing enter in the patch building view does nothing.
2024-06-23 12:40:31 +02:00
Stefan Haller
b2c457366a
Fix PTY layout problems (#3658)
- **PR Description**

This fixes two layout problems with pagers that draw a horizontal line
across the entire width of the view (e.g. delta):
- sometimes the width of that line was one character too long or too
short in the staged changes view
- when changing from a file or directory that has only staged or only
unstaged changes to one that has both, the length of the horizontal line
was totally off and only redraw correctly at the next refresh
2024-06-23 12:39:41 +02:00
Stefan Haller
8b8343b8a9 Run PTY tasks after layout so that they get the correct view size
This is important when using a pager that draws a horizontal line across the
entire width of the view; when changing from a file or directory that has only
unstaged (or only staged) changes to one that has both, the main view is split
in half, but the PTY task would be run on the view in its old state, so the
horizonal line would be too long and wrap around.
2024-06-23 12:36:40 +02:00
Stefan Haller
f98da780de Fix possible off-by-one error wrt PTY size
All PTYs were created with the size of the main view, on the assumption that
main and secondary always have the same size. That's not true though; in
horizontal split mode, the width of the two views can differ by one because of
rounding, and when using a pager that draws a horizontal line across the width
of the view, this is visible and looks very ugly.
2024-06-23 12:36:40 +02:00
Stefan Haller
c401f34530
Add prompt to the remote branch checkout menu (#3652)
- **PR Description**

As a followup to [this
discussion](https://github.com/jesseduffield/lazygit/pull/3388#issuecomment-2002308045),
this PR adds a way to add a prompt text to menus. It is shown above the
menu items, separated by a blank line. We use it to add a prompt to the
remote branch checkout menu.
2024-06-23 12:35:50 +02:00
Stefan Haller
ddd6323aa5 Add prompt to the remote branch checkout menu 2024-06-23 12:33:16 +02:00
Stefan Haller
7e92dbfd3d Add menu prompt
This makes it possible to add a prompt to a menu. It will be shown above the
menu items, separated from them by a blank line.
2024-06-23 12:33:16 +02:00
Stefan Haller
dbc21af3b1 Extract function wrapMessageToWidth
This steals even more code from `gocui.lineWrap`.

We'll make use of this in the next commit.
2024-06-23 12:33:15 +02:00
Stefan Haller
6f8244e3fe
Fix duplicate keybinding suggestions in status bar after switching repos (#3660)
- **PR Description**

When switching to a repo that was open before, all keybinding
suggestions in the status bar would show twice.

Fixes #3612.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [x] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-23 12:31:42 +02:00
Stefan Haller
cf27fd827b Clear keybinding functions in resetHelpersAndControllers
When switching to a repo that was open before, the context tree is reused, so
before adding keybinding functions to those contexts again, we need to clear the
old ones.
2024-06-23 12:28:42 +02:00
Stefan Haller
a7c97400c6 Add a test demonstrating the bug
After switching to another repo and then back to the original one, all
keybinding suggestions in the status bar are shown twice.
2024-06-23 12:28:42 +02:00
Stefan Haller
5e9fe2be80
Fix truncation of branch names containing non-ASCII characters (#3685)
Fix truncating long branch names containing non-ASCII characters.
2024-06-23 12:28:05 +02:00
Stefan Haller
d406ec06af Fix truncation of long branch names containing non-ASCII characters 2024-06-23 12:25:28 +02:00
Stefan Haller
7ec784e2a0 Add test demonstrating wrong truncation of branch names containing non-ASCII characters 2024-06-23 12:25:28 +02:00
Stefan Haller
93af0016f7 Use actual ellipsis character instead of ... to truncate strings
Space is scarce in lazygit's UI, and using ... wastes a lot of it.
2024-06-23 12:25:28 +02:00
Stefan Haller
a171ec4294
Reduce memory consumption when loading large number of commits (#3687)
(Github decided to auto-close #2533, and I don't see any way to reopen
it, so opening a new one here. Please see there for discussion and
review.)

When pressing `>` in the commits panel to trigger loading all the
remaining commits past the initial 300, memory consumption is a pretty
big problem for larger repositories.

The two main causes seem to be
1. the cell memory from rendering the entire list of commits into the
gocui view
2. the pipe sets when git.log.showGraph is on

This PR addresses only the first of these problems, by not rendering the
entire view, but only the visible portion of it. Since we already
re-render the visible portion of the view on every layout call, this was
relatively easy to do.

Below are some measurements for our repository at work (261.985
commits):

|               | master | this PR |
| ------------- | ------ | ------- |
| without Graph | 855 MB | 360 MB  |
| with Graph    | 3.1 GB | 770 MB  |

And for the linux kernel repo (1.170.387 commits):

|               | master                                    | this PR |
| ------------- | ----------------------------------------- | ------- |
| without Graph | 5.8 GB                                    | 1.2G    |
| with Graph    | Killed by the OS after it reached 86.9 GB | 39.9 GB |

The measurements were taken after scrolling all the way down in the list
of commits. They have to be taken with a grain of salt, as memory
consumption fluctuates quite a bit in ways that I find hard to make
sense of.

As you can see, there's more work to do to reduce the memory usage for
the graph, but for our repo at work this PR makes it usable already,
which it wasn't really before.
2024-06-23 12:09:16 +02:00
Stefan Haller
deee5fa957 Render the view when scrolling with the wheel 2024-06-23 11:54:21 +02:00
Stefan Haller
44160ef844 Only render visible portion of the screen for commits view 2024-06-23 11:54:21 +02:00
Stefan Haller
dd2bffc278 Simplify ListContextTrait.FocusLine
When refreshViewportOnChange is true, we would refresh the viewport once at the
end of FocusLine, and then we would check at the end of AfterLayout if the
origin has changed, and refresh again if so. That's unnecessarily complicated,
let's just unconditionally refresh at the end of AfterLayout only.
2024-06-23 11:54:21 +02:00
Stefan Haller
9eb9b369ff Bump gocui 2024-06-23 11:54:01 +02:00
Stefan Haller
fafa4280f5 Log memory usage every 10s 2024-06-23 11:48:40 +02:00
Stefan Haller
5a5cd849d1
Search the model instead of the view in the commits panel (#3642)
- **PR Description**

This makes it possible to search the model data instead of the view when
pressing `/`, and uses this for the commits view.

This is mainly a preparation for #2533 which requires it, but it is also
useful on its own, because it makes it possible to search for full
commit hashes. It will highlight the abbreviated hash in that case.

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [ ] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [ ] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-23 11:48:00 +02:00
Stefan Haller
6a6316cfb6 Use model searching in commits (and sub-commits) view 2024-06-23 11:43:12 +02:00
Stefan Haller
779e6f95a3 Assert that the search status view is visible
Just to be really sure that it not only contains the expected status text, but
also actually shows it.
2024-06-23 11:43:12 +02:00
Stefan Haller
44ad36bb39 Add type assertions for all searchable contexts
We want to add an additional method to ISearchableContext later in this branch,
and this will make sure that we don't forget to implement it in any concrete
context.
2024-06-23 11:43:12 +02:00
Stefan Haller
08a8b067a5 Cleanup: remove outdated comment
We do show the graph in the left/right view, as of b7673577a2.
2024-06-23 11:43:12 +02:00
Stefan Haller
15b25b5afb Fix searching in the divergence (left/right) view
Searching in the "Divergence from upstream" view would select the wrong lines.
The OnSearchSelect function gets passed a view index, and uses it to select a
model line. In most views these are the same, but not in the divergence view
(because of the Remote/Local section headers).
2024-06-23 11:43:12 +02:00
Stefan Haller
27ad75de16 Cleanup: reduce some code duplication
ListContextTrait.OnSearchSelect was introduced in 138be04e65, but it was never
called. I can only guess that a planned refactoring wasn't finished here.
2024-06-23 11:43:12 +02:00
Stefan Haller
3af545daf7
Add user config gui.commitAuthorFormat (#3625)
- **PR Description**
Adds configuration option defining whether to show full author names or
their shortened form in the commit graph.

Closes [#3624](https://github.com/jesseduffield/lazygit/issues/3624).

- **Please check if the PR fulfills these requirements**

* [x] Cheatsheets are up-to-date (run `go generate ./...`)
* [x] Code has been formatted (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting))
* [ ] Tests have been added/updated (see
[here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md)
for the integration test guide)
* [ ] Text is internationalised (see
[here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation))
* [x] Docs have been updated if necessary
* [x] You've read through your own file changes for silly mistakes etc
2024-06-15 16:17:48 +02:00
anikiforov
57f9493770 Add user config gui.commitAuthorFormat 2024-06-15 10:39:50 +04:00
Stefan Haller
629b7ba1b8
Fix reporting of unexpected selections in integration tests (#3662)
Expected and actual selection were swapped in the error message.
2024-06-14 13:36:45 +02:00