Skip to content

Commit 961c3bc

Browse files
committed
Add config option for length of commit hash displayed in commits view
- 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
1 parent 34f8f72 commit 961c3bc

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

docs/Config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ gui:
8080
showIcons: false # deprecated: use nerdFontsVersion instead
8181
nerdFontsVersion: "" # nerd fonts version to use ("2" or "3"); empty means don't show nerd font icons
8282
showFileIcons: true # for hiding file icons in the file views
83+
commitHashLength: 8 # length of commit ID/ref (hash) in commits view
8384
commandLogSize: 8
8485
splitDiff: 'auto' # one of 'auto' | 'always'
8586
skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor

pkg/config/user_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ type GuiConfig struct {
123123
NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="`
124124
// If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
125125
ShowFileIcons bool `yaml:"showFileIcons"`
126+
// Length of commit ID/ref (hash) in commits view.
127+
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=1,maximum=12"`
126128
// If true, show commit hashes alongside branch names in the branches view.
127129
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
128130
// Height of the command log view
@@ -675,6 +677,7 @@ func GetDefaultConfig() *UserConfig {
675677
ShowIcons: false,
676678
NerdFontsVersion: "",
677679
ShowFileIcons: true,
680+
CommitHashLength: 8,
678681
ShowBranchCommitHash: false,
679682
CommandLogSize: 8,
680683
SplitDiff: "auto",

pkg/gui/presentation/commits.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,17 @@ func displayCommit(
312312
bisectInfo *git_commands.BisectInfo,
313313
isYouAreHereCommit bool,
314314
) []string {
315-
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
316315
bisectString := getBisectStatusText(bisectStatus, bisectInfo)
317316

317+
hashString := ""
318+
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
319+
hashLength := common.UserConfig.Gui.CommitHashLength
320+
if hashLength > len(commit.Hash) || hashLength < 1 {
321+
hashString = hashColor.Sprint(commit.ShortHash())
322+
} else {
323+
hashString = hashColor.Sprint(commit.Hash[:hashLength])
324+
}
325+
318326
actionString := ""
319327
if commit.Action != models.ActionNone {
320328
todoString := lo.Ternary(commit.Action == models.ActionConflict, "conflict", commit.Action.String())
@@ -373,7 +381,7 @@ func displayCommit(
373381
} else if icons.IsIconEnabled() {
374382
cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit)))
375383
}
376-
cols = append(cols, hashColor.Sprint(commit.ShortHash()))
384+
cols = append(cols, hashString)
377385
cols = append(cols, bisectString)
378386
if fullDescription {
379387
cols = append(cols, style.FgBlue.Sprint(

schema/config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@
309309
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
310310
"default": true
311311
},
312+
"commitHashLength": {
313+
"type": "integer",
314+
"maximum": 12,
315+
"minimum": 1,
316+
"description": "Length of commit ID/ref (hash) in commits view.",
317+
"default": 8
318+
},
312319
"showBranchCommitHash": {
313320
"type": "boolean",
314321
"description": "If true, show commit hashes alongside branch names in the branches view."

0 commit comments

Comments
 (0)