Skip to content

Commit

Permalink
Add config option for length of commit hash displayed in commits view
Browse files Browse the repository at this point in the history
- Added the user config option to to pkg/config/user_config.go and
schema/config.json and documented in docs/Config.md
- Changed the code that displays the hash in
pkg/gui/presentation/commits.go
  • Loading branch information
oliviaBahr committed Apr 19, 2024
1 parent 34f8f72 commit 961c3bc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/Config.md
Expand Up @@ -80,6 +80,7 @@ gui:
showIcons: false # deprecated: use nerdFontsVersion instead
nerdFontsVersion: "" # nerd fonts version to use ("2" or "3"); empty means don't show nerd font icons
showFileIcons: true # for hiding file icons in the file views
commitHashLength: 8 # length of commit ID/ref (hash) in commits view
commandLogSize: 8
splitDiff: 'auto' # one of 'auto' | 'always'
skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/user_config.go
Expand Up @@ -123,6 +123,8 @@ type GuiConfig struct {
NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="`
// If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
ShowFileIcons bool `yaml:"showFileIcons"`
// Length of commit ID/ref (hash) in commits view.
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=1,maximum=12"`
// If true, show commit hashes alongside branch names in the branches view.
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
// Height of the command log view
Expand Down Expand Up @@ -675,6 +677,7 @@ func GetDefaultConfig() *UserConfig {
ShowIcons: false,
NerdFontsVersion: "",
ShowFileIcons: true,
CommitHashLength: 8,
ShowBranchCommitHash: false,
CommandLogSize: 8,
SplitDiff: "auto",
Expand Down
12 changes: 10 additions & 2 deletions pkg/gui/presentation/commits.go
Expand Up @@ -312,9 +312,17 @@ func displayCommit(
bisectInfo *git_commands.BisectInfo,
isYouAreHereCommit bool,
) []string {
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
bisectString := getBisectStatusText(bisectStatus, bisectInfo)

hashString := ""

Check failure on line 317 in pkg/gui/presentation/commits.go

View workflow job for this annotation

GitHub Actions / lint

assigned to hashString, but reassigned without using the value (wastedassign)

Check failure on line 317 in pkg/gui/presentation/commits.go

View workflow job for this annotation

GitHub Actions / lint

assigned to hashString, but reassigned without using the value (wastedassign)
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
hashLength := common.UserConfig.Gui.CommitHashLength
if hashLength > len(commit.Hash) || hashLength < 1 {
hashString = hashColor.Sprint(commit.ShortHash())
} else {
hashString = hashColor.Sprint(commit.Hash[:hashLength])
}

actionString := ""
if commit.Action != models.ActionNone {
todoString := lo.Ternary(commit.Action == models.ActionConflict, "conflict", commit.Action.String())
Expand Down Expand Up @@ -373,7 +381,7 @@ func displayCommit(
} else if icons.IsIconEnabled() {
cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit)))
}
cols = append(cols, hashColor.Sprint(commit.ShortHash()))
cols = append(cols, hashString)
cols = append(cols, bisectString)
if fullDescription {
cols = append(cols, style.FgBlue.Sprint(
Expand Down
7 changes: 7 additions & 0 deletions schema/config.json
Expand Up @@ -309,6 +309,13 @@
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
"default": true
},
"commitHashLength": {
"type": "integer",
"maximum": 12,
"minimum": 1,
"description": "Length of commit ID/ref (hash) in commits view.",
"default": 8
},
"showBranchCommitHash": {
"type": "boolean",
"description": "If true, show commit hashes alongside branch names in the branches view."
Expand Down

0 comments on commit 961c3bc

Please sign in to comment.