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

Jump to commit via sha #1818

Merged
merged 40 commits into from
Aug 27, 2023
Merged

Jump to commit via sha #1818

merged 40 commits into from
Aug 27, 2023

Conversation

AmmarAbouZor
Copy link
Contributor

@AmmarAbouZor AmmarAbouZor commented Aug 20, 2023

This Pull Request fixes/closes #1799

This PR stills work in progress

It changes the following:

  • Adds new function the commits-log to jump to commit via its sha
  • Default Keybinding is currently Ctrl-j
  • The input pupop has live validation
  • After closing the input box it'll jump to the commit with the matching SHA

The following point need clarification:

  • The live validation retrieve the repo with each keystroke to check if the sha is valid via the method git2::revparse_single(). I've tested it with big repos and didn't see any performance hit with it. But we still can make simple live validation (only hash chars, no spaces, length at most 40) If the current implementation's performance isn't good enough.
  • The default keybinding
  • Validation error text
  • Title and placeholder texts

I'll add a demo for the current progress

I followed the checklist:

  • I added unittests
  • I ran make check without errors
  • I tested the overall application
  • I added an appropriate item to the changelog

Struct is created with a default keybindings.
Popup in integrated in the initialisation macros
- implement default components methods on the popup
- Create internal event for jump to commit
- Popup is reactive and has the standard key bindings
- Validation is still not implemented
- Past from clipboard is still not implemented
- Basic Validation is implemented
- Jump to comment with full sha is implemented without error handling
- Handle move to commit errors
- Validation error message improvements
- Method renamed
@AmmarAbouZor
Copy link
Contributor Author

Here is a small demo for the current progress

jump_sha.mp4

@joyously
Copy link

Does it jump to it even if that SHA is not in the visible list?

@AmmarAbouZor
Copy link
Contributor Author

AmmarAbouZor commented Aug 20, 2023

@joyously Yes it jumps to any commit in the repository since it uses the well-tested method select_commit() in revlog

- Add redraw flag after it jumps to commit
- Remove unused code
@extrawurst
Copy link
Owner

Does it jump to it even if that SHA is not in the visible list?

yes it will only be able to go to commits in the current branch. otherwise it will show an error right now. #81 will introduce looking at all branches and fix this

@extrawurst
Copy link
Owner

@AmmarAbouZor this looks great.

To not add yet another command to the log view I would like this to be an option in the new search popup LogSearchPopupComponent. Logically it also makes sense to be in there. once this in place I will merge this.

@AmmarAbouZor
Copy link
Contributor Author

@extrawurst I think it would be better in the search popup too.
I'd add a new option there Commit SHA Or Commit Hash and move the implementation there.
Could you please have a look at #1816 before. This would save me one merge conflict 😉

@extrawurst
Copy link
Owner

#1816 is merged

@AmmarAbouZor
Copy link
Contributor Author

@extrawurst Jump to SHA is embedded in LogSearchPopupComponent.

  • I added a new mode there with the name 'commit hash'
  • No other option can be active along with the commit hash mode
  • The validation still happens but it's not visible to the users. No execution can happened if the commit hash mode is active and no valid SHA exists
jump_sha.mp4

@AmmarAbouZor AmmarAbouZor marked this pull request as draft August 23, 2023 19:10
@extrawurst
Copy link
Owner

Ok I'll get back to the previous implementation

but do not add a new popup. Reuse this one please. Make it use a mode neun or something to store what mode it is in at the moment

@AmmarAbouZor
Copy link
Contributor Author

@extrawurst I've built the different modes behavior in LogSearchPopupComponent.

  • With the default key f the popup will open in the normal search mode.
  • With the default key Ctrl-j the popup will open in the jump to commit mode.
  • Jump to commit mode is just the input box with a validation shown on the border only

I think it would be better to define how the validation visualization should look before it's implemented.

  • Currently only the border will turn red if it's invalid
  • Should the text in the input field be red in the case of invalid too?
  • The current colors pallet doesn't have a color for valid input. It has only the danger-fg which is used for the invalid case.
jump_sha.mp4

@joyously
Copy link

For accessibility, it's important that information is not conveyed only with color. (7% of men are red/green color blind)
In the demo, it looked like less than 3 characters was considered invalid, but it matched at 4. Perhaps a better UI would show the matching hashes, which the user could pick from, although that might be a bit much for a terminal... (but the whole point is that the hash is not visible)

@AmmarAbouZor
Copy link
Contributor Author

For accessibility, it's important that information is not conveyed only with color. (7% of men are red/green color blind)
In the demo,

We can show a validation message in the right bottom corner like in the commit popup. (first iteration of this PR used that)

Considering that the users won't type the hashes themselves in the most cases but they will paste from the clipboard, I don't think that implementing an auto-completion here would add more value.
I can though complete the SHA in the textbox once the users have typed enough characters to determine one single commit, but this can confuse the users in case they are typing a commit that doesn't exist in the repository

asyncgit/src/sync/commits_info.rs Show resolved Hide resolved
src/app.rs Outdated Show resolved Hide resolved
src/keys/key_list.rs Outdated Show resolved Hide resolved
src/queue.rs Outdated Show resolved Hide resolved
src/queue.rs Outdated Show resolved Hide resolved
src/strings.rs Outdated Show resolved Hide resolved
src/tabs/revlog.rs Outdated Show resolved Hide resolved
src/components/log_search_popup.rs Outdated Show resolved Hide resolved
@extrawurst
Copy link
Owner

extrawurst commented Aug 26, 2023

back to the previous implementation

that was not the idea. the command for jump-to-commit-sha should be only available in the search-popup to prevent littering the revlog command list more. it contextually also makes sense to be a sub behaviour of find/search.

also please add the new command in the cmd-bar so its clear that this feature is available

We can show a validation message in the right bottom corner like in the commit popup

lets do that

complete the SHA in the textbox once the users have typed enough characters

no magic please. for the unlikely case that people want to search for incomplete/fractional SHAs we can add that to the regular substring search

- Jump to commit is now a sub-command in log_search_popup
- Remove redundant JumpToCommit Internal Event and use
  SelectCommitInRevlog instead
- Rename jump_to_commit_hash to search_commit_sha
- Remove Jump to commit title and use search instead
- Change find_commit_sha group
- Mode switch is done internally
- Switch to jump commit is always enabled
- Esc in jump commit mode return to search mode
src/strings.rs Outdated Show resolved Hide resolved
@AmmarAbouZor
Copy link
Contributor Author

  • Commit sha command is shown in LogSearchPopup with the default keybinding Ctrl-j
  • Validation message is shown on the right bottom corner when the sha is invalid only
  • Esc in Commit SHA will go back the search popup
jump_sha.mp4

@AmmarAbouZor AmmarAbouZor marked this pull request as ready for review August 27, 2023 07:34
@extrawurst
Copy link
Owner

Thanks for sticking with this. Good work! ❤️

@extrawurst extrawurst merged commit c68fa3e into extrawurst:master Aug 27, 2023
19 checks passed
@AmmarAbouZor AmmarAbouZor deleted the jump-to-commit-via-sha branch August 27, 2023 08:36
IndianBoy42 pushed a commit to IndianBoy42/gitui that referenced this pull request Jun 4, 2024
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.

open specific commit sha view
3 participants