git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: git@vger.kernel.org
Cc: Denton Liu <liu.denton@gmail.com>, Johannes Sixt <j6t@kdbg.org>,
	Eric Huber <echuber2@illinois.edu>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Avi Halachmi <avihpit@yahoo.com>,
	Christoph Sommer <sommer@cms-labs.org>,
	Paul Mackerras <paulus@ozlabs.org>
Subject: [PATCH 2/2] gitk: Add auto-select length preference for SHA256
Date: Thu, 20 Mar 2025 16:41:34 +0100	[thread overview]
Message-ID: <20250320154136.23262-3-tiwai@suse.de> (raw)
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


  parent reply	other threads:[~2025-03-20 15:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20 15:41 [PATCH 0/2] gitk: Support of SHA256 repos Takashi Iwai
2025-03-20 15:41 ` [PATCH 1/2] gitk: Add a basic support of SHA256 repositories into Gitk Takashi Iwai
2025-05-08  6:20   ` Johannes Sixt
2025-05-12 14:29     ` Takashi Iwai
2025-03-20 15:41 ` Takashi Iwai [this message]
2025-05-08  6:20   ` [PATCH 2/2] gitk: Add auto-select length preference for SHA256 Johannes Sixt
2025-05-12 14:36     ` Takashi Iwai
2025-05-08  6:21 ` [PATCH 0/2] gitk: Support of SHA256 repos Johannes Sixt
2025-05-12 14:45   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250320154136.23262-3-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avihpit@yahoo.com \
    --cc=echuber2@illinois.edu \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=liu.denton@gmail.com \
    --cc=paulus@ozlabs.org \
    --cc=sommer@cms-labs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).