git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] gitk: Add auto-select length preference for SHA256

From
Takashi Iwai <tiwai@suse.de>
Date
Mar 20, 2025, 15:41 UTC
Message-ID
<20250320154136.23262-3-tiwai@suse.de>
In-Reply-To
<20250320154136.23262-1-tiwai@suse.de>

This implements the missing preference setup of the auto select length for SHA256. The variable set via the preference menu is switched depending on the hash algorithm.

The default auto-select length is set to 64 for SHA256, and saved/restored as "autosellensha256" in the config.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 gitk-git/gitk | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 1e85cfef2ee3..b364d9e7dc93 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7488,6 +7488,16 @@ proc make_idmark {id} {
     $canv raise $t
 }
 
+proc get_autosellen {} {
+    global hashalgorithm autosellen autosellensha256
+
+    if {$hashalgorithm == "SHA256"} {
+        return $autosellensha256
+    } else {
+        return $autosellen
+    }
+}
+
 proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
     global canv ctext commitinfo selectedline
     global canvy0 linespc parents children curview
@@ -7496,7 +7506,7 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
     global mergemax numcommits pending_select
     global cmitmode showneartags allcommits
     global targetrow targetid lastscrollrows
-    global autocopy autoselect autosellen jump_to_here
+    global autocopy autoselect jump_to_here
     global vinlinediff
 
     unset -nocomplain pending_select
@@ -7563,11 +7573,11 @@ proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} {
     $sha1entry delete 0 end
     $sha1entry insert 0 $id
     if {$autoselect && [haveselectionclipboard]} {
-        $sha1entry selection range 0 $autosellen
+        $sha1entry selection range 0 [get_autosellen]
     }
     if {$autocopy} {
         clipboard clear
-        clipboard append [string range $id 0 [expr $autosellen - 1]]
+        clipboard append [string range $id 0 [expr [get_autosellen] - 1]]
     }
     rhighlight_sel $id
 
@@ -9629,13 +9639,14 @@ proc mktaggo {} {
 }
 
 proc copyreference {} {
-    global rowmenuid autosellen
+    global rowmenuid
     global hashlength
 
     set format "%h (\"%s\", %ad)"
     set cmd [list git show -s --pretty=format:$format --date=short]
-    if {$autosellen < $hashlength} {
-        lappend cmd --abbrev=$autosellen
+    set alen [get_autosellen]
+    if {$alen < $hashlength} {
+        lappend cmd --abbrev=$alen
     }
     set reference [eval exec $cmd $rowmenuid]
 
@@ -11741,8 +11752,9 @@ proc create_prefs_page {w} {
 proc prefspage_general {notebook} {
     global NS maxwidth maxgraphpct showneartags showlocalchanges
     global tabstop wrapcomment wrapdefault limitdiffs
-    global autocopy autoselect autosellen extdifftool perfile_attrs
+    global autocopy autoselect extdifftool perfile_attrs
     global hideremotes want_ttk have_ttk maxrefs web_browser
+    global hashalgorithm hashlength
 
     set page [create_prefs_page $notebook.general]
 
@@ -11771,7 +11783,13 @@ proc prefspage_general {notebook} {
             -variable autoselect
         grid x $page.autoselect -sticky w
     }
-    spinbox $page.autosellen -from 1 -to 40 -width 4 -textvariable autosellen
+
+    if {$hashalgorithm == "SHA256"} {
+        set autolenvar "autosellensha256"
+    } else {
+        set autolenvar "autosellen"
+    }
+    spinbox $page.autosellen -from 1 -to $hashlength -width 4 -textvariable $autolenvar
     ${NS}::label $page.autosellenl -text [mc "Length of commit ID to copy"]
     grid x $page.autosellenl $page.autosellen -sticky w
 
@@ -11908,7 +11926,7 @@ proc doprefs {} {
     global maxwidth maxgraphpct use_ttk NS
     global oldprefs prefstop showneartags showlocalchanges
     global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
-    global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
+    global tabstop limitdiffs autoselect extdifftool perfile_attrs
     global hideremotes want_ttk have_ttk wrapcomment wrapdefault
 
     set top .gitkprefs
@@ -12606,6 +12624,7 @@ set datetimeformat "%Y-%m-%d %H:%M:%S"
 set autocopy 0
 set autoselect 1
 set autosellen 40
+set autosellensha256 64
 set perfile_attrs 0
 set want_ttk 1
 
@@ -12702,7 +12721,7 @@ config_check_tmp_exists 50
 set config_variables {
     mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
     cmitmode wrapcomment wrapdefault autocopy autoselect autosellen
-    showneartags maxrefs visiblerefs
+    autosellensha256 showneartags maxrefs visiblerefs
     hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
     bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
     markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
-- 
2.49.0
Previous: Takashi IwaiNext: Johannes Sixt
Message 5 of 9 in “gitk: Support of SHA256 repos”
  1. 0/2 gitk: Support of SHA256 reposTakashi Iwai, Mar 20, 2025
  2. 1/2 gitk: Add a basic support of SHA256 repositories into GitkTakashi Iwai, Mar 20, 2025
  3. Johannes SixtMay 8, 2025
  4. Takashi IwaiMay 12, 2025
  5. 2/2 gitk: Add auto-select length preference for SHA256Takashi Iwai, Mar 20, 2025
  6. Johannes SixtMay 8, 2025
  7. Takashi IwaiMay 12, 2025
  8. Johannes SixtMay 8, 2025
  9. Takashi IwaiMay 12, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.