Commit Graph

806 Commits

Author SHA1 Message Date
Johannes Sixt
bd3fd7e77c Merge branch 'js/persist-ref-window-geometry'
* js/persist-ref-window-geometry:
  gitk: persist position and size of the Tags and Heads window
  Revert "gitk: Only restore window size from ~/.gitk, not position"
2025-11-26 16:02:23 +01:00
Johannes Sixt
d445a78873 gitk: show unescaped file names on 'rename' and 'copy' lines
When a file is selected in the file list, the diff window scrolls to the
corresponding section. The administrative data needed for this purpose
is extracted from the 'rename from', 'rename to', and 'copy to' lines.
Escaped file names are unescaped for this purpose. However, the lines
shown in the diff window are left in the escaped form. This is not very
pleasing. Replace the escaped form by the unescaped form.

Add a section to treat the 'copy from' case.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-11-06 10:59:02 +01:00
Johannes Sixt
77e7aab693 gitk: fix a 'continue' statement outside a loop to 'return'
When 5de460a2cf (gitk: Refactor per-line part of getblobdiffline and
its support) moved the body of a loop into a separate function, several
'continue' statements were changed to 'return'. But one instance was
missed. Fix it now.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-11-06 10:59:02 +01:00
Johannes Sixt
bf5a55ac5e gitk: persist position and size of the Tags and Heads window
The Tags and Heads window always opens at a default position and size,
requiring users to reposition it each time. Remember its geometry
between sessions in the config file as `geometry(showrefs)`.

Note that the existing configuration is sourced in proc savestuff
right before new settings are written. This makes the old settings
available as local variables(!) and does not overwrite the current
settings. Since we need access to the global geometry(showrefs), it
is necessary to unset the local variable.

Helped-by: Michael Rappazzo <rappazzo@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-10-17 18:38:11 +02:00
Johannes Sixt
8b5636a57f Revert "gitk: Only restore window size from ~/.gitk, not position"
This reverts commit b9bee11526 (gitk: Only restore window size from
~/.gitk, not position, 2008-03-10).

The earlier commit e9937d2a03 (Make gitk work reasonably well on
Cygwin, 2007-02-01) reworked the window layout considerably. Much of
this became irrelevant around 2011 after Cygwin gained an X11 server
and switched to a supportable port of the Unix/X11 Tcl/Tk (it is now
on the current 8.6 code base).

Part of the necessary change was to restore the window size across
sessions, but the position was also restored. This raised complaints
on the mailing list[*], because Gitk was opened on the wrong monitor.
b9bee11526 was the compromise, because it was only the size that
mattered for the Cygwin layout engine to work.

I personally, find it annoying when Gitk pops up on a random location
on the screen, in particular, since many other applications restore
the window positions across sessions, so why not Gitk as well? (I do
not operate multi-monitor setups, so I cannot test the case.)

[*] https://lore.kernel.org/git/47AAA254.2020008@thorn.ws/

Helped-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-10-17 18:37:52 +02:00
Johannes Sixt
c435c515da Merge branch 'ml/themes'
* ml/themes:
  gitk: set minimum size on configuration dialog
  gitk: separate code blocks for configuration dialog
  gitk: make configuration dialog resizing useful
  gitk: add theme selection to color configuration page
  gitk: add proc run_themeloader
  gitk: eliminate unused ui color variables
  gitk: eliminate Interface color option from gui
  gitk: use text labels for next/prev search buttons
  gitk: use text labels for commit ID buttons
  gitk: do not invoke tk_setPalette
  gitk: use config variables to define and load a theme
  gitk: make sha1but a ttk::button
  gitk: use themed spinboxes

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-10-05 13:09:49 +02:00
Mark Levedahl
6565ca8220 gitk: set minimum size on configuration dialog
gitk sets no size limit on its configuration dialog, allowing the user
to collapse the window so almost nothing is visible. The geometry
manager sets an initial size so all the widgets are visible, though
ignores the potentially very long text in the entry widgets in doing so.
Let's use this initial size as the minimum. The size information is
computed in Tk's idle processing queue, so a wait is required.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-10-04 10:37:18 -04:00
Mark Levedahl
8e65d38064 gitk: separate code blocks for configuration dialog
gitk's configuration dialog uses a large number of widgets, and this
code is hard to read as there is no easily recognizable grouping or
breaks. Help this by adding space between items that occupy a single row
in the dialog.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-10-04 10:37:18 -04:00
Mark Levedahl
b9f6b8237d gitk: make configuration dialog resizing useful
gitk's configuration dialog can be resized, but this does not expand the
space allocated to any widgets. Some items may have long lines of text
that would be visible if the widgets expanded, but this does not happen.

The top-level container uses a two column grid and allocates any space
change equally to both columns.  However, the configuration pages are
contained in one cell so half the additional space is wasted if
expanding. Also, the individual configuration pages do not mark any
column or widgets to expand, so any additional space given is just used
as padding.

Collapse the top-level page to have one column, placing the "OK" and
"Cancel" buttons in a non-resizing frame in column 1 (this keeps the
buttons in constant geometry as the dialog is expanded). This makes all
additional space go to the configuration page.

Mark column 3 of the individual pages to get all additional space, and
mark the text widgets in that column so they will expand to use the
space. While we're at it, eliminate or simplify use of frames to contain
column 2 content, and harmonize the indents of that content.

prefspage_general adds a special "spacer" label in row 2, column 1, that
causes all of the subsequent rows with no column 1 content to indent,
and this carries over to the next notebook tab (prefspage_color) through
some undocumented feature. The fonts page has a different indent, again
for unknown reason. The documented approach would be to use -padx
explicitly on all the rows to set the indents.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-10-04 10:31:40 -04:00
Johannes Sixt
ead1687a3e Merge branch 'es/ignore-osascript-failure'
* es/ignore-osascript-failure:
  gitk: fix MacOS 10.14 "Mojave" crash on launch
2025-10-04 15:36:42 +02:00
Johannes Sixt
d7cedce063 Merge branch 'mr/sort-refs-by-type'
* mr/sort-refs-by-type:
  gitk: fix error when remote tracking branch is deleted
2025-10-04 15:36:12 +02:00
Mark Levedahl
c0932eda80 gitk: add theme selection to color configuration page
gitk allows configuring a particular theme in its configuration file
(default on linux: ~/.config/git/gitk), but offers no ability to modify
this from gitk's configuration editor. Let's add this to the color
configuration page.

Present the offered themes in a list, and allow choosing / modifying a
theme definition file ($themeloader). Update the list of themes if the
theme file is modified, and update the theme if specifically requested
(by default, just change the value for use after gitk is restarted).

Any theme definition file can change the global options database,
affecting potentially any theme. So, the ultimate configuration should
have either
- no theme definition file (themeloader = {}), and a native Tk, theme,
or
- themeloader naming a valid file, and $theme naming a theme defined by
  that file.

But, there is no trivial way to enforce the above. Shrug.

Helped-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-10-01 13:54:31 -04:00
Mark Levedahl
830c4578cd gitk: add proc run_themeloader
gitk currently accepts a single themeloader file via the config file,
and will source this with errors reported to the console. This is fine
for simple configuration, but will not support interactive theme
exploration from the gui. In particular, a themeloader file must be
sourced only once as the themes defined cannot be re-defined. Also,
errors must be handled rather than just aborting while printing to the
console.  So, add a proc to handle the above, supporting expansion of
the gui config pages.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:54:09 -04:00
Mark Levedahl
83a2de9ca6 gitk: eliminate unused ui color variables
gitk has a number of variables used in setting up colors for the classic
(non-themed) widget set. These variables are unused with ttk, so let's
eliminate them. But, leave the variables in the config file for now -
those can be eliminated after this change is merged.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:53:59 -04:00
Mark Levedahl
1eadf0f3e0 gitk: eliminate Interface color option from gui
gitk offers to change the ui color on the colors prefs page, but the
variable set has no effect because gitk is using themes. Let's eliminate
the "Interface" color selection option from that page.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:53:55 -04:00
Mark Levedahl
9950eff841 gitk: use text labels for next/prev search buttons
gitk allows searching for commits with various criteria, and provides
up/down search buttons to facilitate this search. These buttons are
labelled with bitmaps, and those bitmaps are not always recolored
correctly for the ui scheme as the theme colors are not known. Let's
just use text labels on these, allowing the styles to handle any
coloring needed. Use utf codepoints for the arrows, presuming that these
code points are available in the selected font.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:53:46 -04:00
Mark Levedahl
61c0cfe08c gitk: use text labels for commit ID buttons
gitk maintains a stack of commit ids visited, and allows navigating
these using a pair of buttons shown with arrows using bitmaps. An attempt
is made to recolor these bitmaps to handle different color schemes, but
this is unreliable across multiple themes as the required colors are not
universally known. Let's just use text labels for these buttons,
allowing the themes to recolor the text along with everything else. Use
utf code points for the text, presuming that these arrow glyphs are
available in the selected font.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:53:40 -04:00
Mark Levedahl
7754656a4c gitk: do not invoke tk_setPalette
gitk uses themed widgets with a user selected theme, but also invokes
tk_setPalette to configure colors for the non-themed widgets including
the menubar. However, themes in general are expected to configure
those colors already. The builtin themes (default, alt, clam, classic on
unix/X11) all have compatible colors, and need no such reconfiguration,
and (most, if not all) available themes set the options database for this
purpose as well. Furthermore, gitk in the past avoided invoking
tk_setPalette on Windows to avoid some issues.

So, let's stop calling tk_setPalette everywhere, and just rely upon the
selected theme (possibly user installed) to have set all needed colors.

Note: if a user installs more than one theme using $themeloader, the last
one installed will have defined the colors to be used. Those colors will
probably be incorrect for any other set, including Tk's builtin set.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:53:29 -04:00
Mark Levedahl
8ccb2d4a76 gitk: use config variables to define and load a theme
gitk uses themed tk, but has no capability to alter the theme defined
by Tk. While there are documented ways to install other themes, and
to make one the default, these methods are obscure at best. Instead,
let's offer two config variables:

- theme  this is the name of the theme to use, and must be available.
- themeloader - this is the full pathname of a tcl script that
  will load one or more themes into the Tk namespace.

By default, theme is set to the theme active when Tk is started, and
themeloader = {}.  These variables must be defined to something else to
have any user visible effect.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-29 20:53:21 -04:00
Mark Levedahl
fe2005e723 gitk: make sha1but a ttk::button
gitk's 'Commit ID' button uses a classic widget, not a themed one,
leading to inconsistent style. Commit 51a7e8b654 (d93f1713b0 ("gitk: Use
themed tk widgets", 2009-04-17) that added themed widgets did not touch
this particular widget, but does not say why. Regardless, let's use a
themed button to be consistent with the rest of the interface.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-25 15:55:57 -04:00
Mark Levedahl
811b8a34b9 gitk: use themed spinboxes
gitk uses classic (non-themed) spinboxes rather than the ttk variants.
Commit d93f1713b0 ("gitk: Use themed tk widgets", 2009-04-17) that added
ttk makes no mention of why ttk:spinboxes were omitted, but this leads
to an inconsistent interface. Let's use the ttk version.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-09-25 12:04:02 -04:00
Eric Sunshine
9611ef554d gitk: fix MacOS 10.14 "Mojave" crash on launch
On MacOS, a "wish" application started from the terminal opens in the
background, thus doesn't match user expectation that a newly-launched
application ought to be placed in the foreground. To address this
shortcoming, both gitk and git-gui use Apple Events to send a message to
"System Events" instructing it to foreground the "wish" application by
PID.

Unfortunately, MacOS 10.14 tightens restrictions on Apple Events,
requiring explicit granting of permission to control applications in
this fashion, and apparently such granting for "Automation" is not
allowed at all[1]. As a consequence gitk crashes outright at launch time
with a "Not authorized to send Apple events to System Events" error,
thus is entirely unusable on "Mojave".

In contrast, git-gui does not crash since it deliberately[2] catches and
ignores Apple Events errors. This does mean that git-gui will not
automatically become the foreground application on "Mojave", which is a
minor inconvenience but far better than crashing outright as gitk does.

Update gitk to catch and ignore Apple Events errors, mirroring git-gui's
behavior, to avoid this crash.

(Finding and implementing an alternate approach to foregrounding the
"wish" application on "Mojave" may be desirable but is outside the scope
of this crash fix.)

[1]: https://lore.kernel.org/git/D295145E-7596-4409-9681-D8ADBB9EBB0C@me.com/
[2]: https://lore.kernel.org/git/CABNJ2G+h3zh+=wLA0KHjUn8TsfhqUK1Kn-1_=6hnXVRJUPhuuA@mail.gmail.com/

Reported-by: Evgeny Cherpak <cherpake@me.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-09-22 18:03:04 +02:00
Michael Rappazzo
88189dd7cb gitk: fix error when remote tracking branch is deleted
When a remote tracking branch is deleted (e.g., via 'git push --delete
origin branch'), the headids array entry for that branch is removed, but
upstreamofref may still reference it. This causes gitk to show an error
and prevents the Tags and Heads view from opening.

Fix by checking that headids($upstreamofref($n)) exists before accessing
it in the refill_reflist function.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-09-14 20:18:30 +02:00
Michael Rappazzo
ac8fec7d8d gitk: add README with usage, build, and contribution details
Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-28 19:51:31 +02:00
Johannes Sixt
3fbbbe27ea Merge branch 'tk87-touchpad-scroll' of github.com:ZhongRuoyu/gitk
* 'tk87-touchpad-scroll' of github.com:ZhongRuoyu/gitk:
  gitk: fix trackpad scrolling for Tcl/Tk 8.7+

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-27 20:52:35 +02:00
Ruoyu Zhong
432669914b gitk: fix trackpad scrolling for Tcl/Tk 8.7+
TIP 684 [1] introduced TouchpadScroll events in Tcl/Tk 8.7, separating
trackpad gestures from traditional MouseWheel events. This broke
trackpad scrolling in gitk where trackpads generate TouchpadScroll
events instead of MouseWheel events.

Fix that by adding TouchpadScroll event bindings for all scrollable
widgets following the TIP 684 specification. Implement a new
precisescrollval proc to handle the smaller delta values from
TouchpadScroll events, using appropriate scaling factors that seem
sensible on my MacBook.

Fixes https://github.com/j6t/gitk/issues/31.

[1]: https://core.tcl-lang.org/tips/doc/main/tip/684.md

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2025-08-27 11:42:30 +08:00
Johannes Sixt
be1829c0fd Merge branch 'aqua-ctxbut' of github.com:ZhongRuoyu/gitk
* 'aqua-ctxbut' of github.com:ZhongRuoyu/gitk:
  gitk: use <Button-3> for ctx menus on macOS with Tcl 8.7+

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-26 19:22:08 +02:00
Ruoyu Zhong
7c06c19e66 gitk: use <Button-3> for ctx menus on macOS with Tcl 8.7+
Commit d277e89f87 added special handling
on macOS (OS X) that makes button 2 the right mouse button. As per TIP
474 [1], Tcl 8.7 has swapped buttons 2 and 3 such that button 3 is made
the right mouse button as in other platforms. Therefore, the logic
should be updated to use button 3 on macOS with Tcl 8.7+.

[1]: https://core.tcl-lang.org/tips/doc/main/tip/474.md

Signed-off-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2025-08-24 18:07:58 +08:00
Johannes Sixt
93ff79ed41 Merge branch 'docglobs' of github.com:ilyagr/gitk
* 'docglobs' of github.com:ilyagr/gitk:
  gitk: Mention globs in description of preference to hide custom refs

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-04 18:20:32 +02:00
Ilya Grigoriev
98a5b85644 gitk: Mention globs in description of preference to hide custom refs
This clarifies that one has to enter e.g. `jj/keep/*` and not just
`jj/keep`.

Follows up on 2441e19.

Signed-off-by: Ilya Grigoriev <ilyagr@users.noreply.github.com>
2025-08-03 19:27:33 -07:00
Johannes Sixt
148e914f77 Merge branch 'ml/tcltk-9'
* ml/tcltk-9:
  gitk: allow Tcl/Tk 9.0+
  gitk: use -profile tcl8 on encoding conversions
  gitk: use -profile tcl8 for file input with Tcl 9
  gitk: Tcl9 doesn't expand ~, use $env(HOME)
  gitk: switch to -translation binary
  gitk: update scrolling for TclTk 8.7+ / TIP 474

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-01 18:39:15 +02:00
Johannes Sixt
ffe115e43a Merge branch 'oa/hide-more-refs'
* oa/hide-more-refs:
  gitk: Add user preference to hide specific references

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-01 18:38:08 +02:00
Johannes Sixt
e51b17efec Merge branch 'ml/abandon-old-version'
* ml/abandon-old-version:
  gitk: restore ui colors after cancelling config dialog
  gitk: set config dialog color swatches in one place

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-01 18:36:15 +02:00
Johannes Sixt
cb5607e06c Merge branch 'master' of github.com:alshopov/gitk
* 'master' of github.com:alshopov/gitk:
  gitk i18n: Remove the locations within the Bulgarian translation
  gitk i18n: Update Bulgarian translation (322t)

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-01 18:35:44 +02:00
Johannes Sixt
f896039388 Merge branch 'mr/sort-refs-by-type'
* mr/sort-refs-by-type:
  gitk: filter invisible upstream refs from reference list
  gitk: avoid duplicated upstream refs

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-08-01 18:35:16 +02:00
Michael Rappazzo
9965cc771b gitk: filter invisible upstream refs from reference list
In refill_reflist, upstream refs are now only included if their
commits are visible in the current view. This prevents display
issues like multiple highlighted branches when clicking entries.

Signed-off-by: Michael Rappazzo <michael.rappazzo@infor.com>
2025-07-31 08:32:49 -04:00
Johannes Sixt
b28119551b gitk: avoid duplicated upstream refs
It is possible that multiple local branches track the same upstream.
In this case, the refs dialog lists the tracked upstream branch
multiple times. This is undesirable. Make them unique.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-07-30 08:44:51 +02:00
Alexander Shopov
79be55fa57 gitk i18n: Remove the locations within the Bulgarian translation
This makes sending diffs via mail list easier and
brings the po-file in line with git po-file.

Signed-off-by: Alexander Shopov <ash@kambanaria.org>
2025-07-29 19:51:41 +02:00
Alexander Shopov
74d9e38a0d gitk i18n: Update Bulgarian translation (322t)
Signed-off-by: Alexander Shopov <ash@kambanaria.org>
2025-07-29 19:49:02 +02:00
Johannes Sixt
2d3f3f0127 gitk: remove header of now empty section "General options"
An earlier commit remove the only option that was available under
"General options". We don't need the header for the empty section.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-07-22 18:34:21 +02:00
Johannes Sixt
0f3d030de5 Merge branch 'ml/abandon-old-version' (early part)
* 'ml/abandon-old-version' (early part):
  gitk: allow horizontal commit-graph scrolling
  gitk: update aqua scrolling for TclTk 8.6 / TIP171
  gitk: update x11 scrolling for TclTk 8.6 / TIP 171
  gitk: update win32 scrolling for Tk 8.6 / TIP 171
  gitk: mousewheel scrolling functions for Tk 8.6
  gitk: wheel scrolling multiplier preference
  gitk: separate x11 / win32 / aqua Mouse bindings
  gitk: remove non-ttk support code
  gitk: replace ${NS} with ttk
  gitk: always use themed Tk (ttk)
  gitk: use $config_variables as list for save/restore
  gitk: remove implementations for Tcl/Tk < 8.6
  gitk: Make TclTk 8.6 the minimum, allow 8.7
  gitk: remove code targeting git <= 1.7.2
  gitk: require git >= 2.20
2025-07-22 18:29:54 +02:00
Johannes Sixt
e2874c6496 Merge branch 'mr/sort-refs-by-type'
* mr/sort-refs-by-type:
  gitk: separate upstream refs when using the sort-by-type option
  gitk: make 'sort-refs-by-type' optional and persistent
  gitk: sort by ref type on the 'tags and heads' view
2025-07-22 18:13:31 +02:00
Johannes Sixt
cf9d3c1ccd Merge branch 'ti/support-sha256'
* ti/support-sha256:
  gitk: Add support of SHA256 repositories
2025-07-22 18:04:55 +02:00
Michael Rappazzo
c0fb4353c2 gitk: separate upstream refs when using the sort-by-type option
Since the upstream refs of local refs may be of more significance in the
context of the local refs, they are sorted after local refs and before the
remainder of the remote refs.

Signed-off-by: Michael Rappazzo <michael.rappazzo@infor.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-07-20 10:17:24 +02:00
Michael Rappazzo
9abe70db6c gitk: make 'sort-refs-by-type' optional and persistent
On the 'tags and heads' view, add an option to enable or disable
'Sort refs by type'.  This option is read from and written to the
config file.  Clicking on the option will update the refs in the
view.

Signed-off-by: Michael Rappazzo <michael.rappazzo@infor.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-07-20 10:12:17 +02:00
Michael Rappazzo
aa1a3e0993 gitk: sort by ref type on the 'tags and heads' view
In the 'tags and heads' view, the list of refs was globally sorted,
which caused the local ref list to be split around other ref list types.

This change re-orders the view to be: local refs, remote refs, tags,
and then other refs.

Signed-off-by: Michael Rappazzo <rappazzo@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-07-20 10:09:34 +02:00
Johannes Sixt
8e34d8b148 gitk: choosefont - remove a stray debugging line
This output was added in d93f1713b0 ("gitk: Use themed tk widgets",
2009-04-17), we can assume, by accident.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-07-17 13:14:55 +02:00
Mark Levedahl
4e605b7bc0 gitk: allow Tcl/Tk 9.0+
Tcl/Tk 9.0 has been released, and has shipped in Fedora 42. Prior
patches in this sequence have addressed known incompatibilities, so gitk
is now operating with Tcl9. So, let's allow Tcl9.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-07-16 23:02:38 -04:00
Mark Levedahl
ac222bc02d gitk: use -profile tcl8 on encoding conversions
gitk in the prior commit learned to apply -profile tcl8 to all input
data streams, avoiding errors on non-binary data streams whose encoding
is not utf-8. But, gitk also consumes binary data streams (generally blobs
from commits), and internally decodes this to support various displays.

With Tcl9, errors occur in this decoding for the same reasons described
in the previous commit: basically, the underlying data was not validated
to conform to the given encoding, and this source encoding may not be
utf-8. gitk performs this decoding using Tcl's '[encoding convert from'
operator.

For example, the 7th commit in gitk's history has the extended ascii
value 0xA9, so

	gitk 9a40c50c1e

in gitk's repository raises an exception. The error log has:

unexpected byte sequence starting at index 11: '\xA9'
    while executing
"encoding convertfrom $diffencoding $line"
    (procedure "parseblobdiffline" line 135)
    invoked from within
"parseblobdiffline $ids $line"
    (procedure "getblobdiffline" line 16)
    invoked from within
"getblobdiffline file6 9a40c50c1e05c0658b7a7c68b56d615eb6f170dd"
    ("eval" body line 1)
    invoked from within
"eval $script"
    (procedure "dorunq" line 11)
    invoked from within
"dorunq"
    ("after" script)

This problem has a similar fix to the prior issue: we must use the tlc8
profile when converting this data. Do so, again only on Tcl9 as Tcl8.6
does not recognize -profile, and only Tcl 9.0 makes strict the default.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-07-16 23:02:38 -04:00
Mark Levedahl
aa1b8d31ac gitk: use -profile tcl8 for file input with Tcl 9
gitk invokes many git commands expecting output in utf-8 encoding, but
git accepts extended ascii (code page unknown) as utf-8 without
validating, so cannot guarantee valid utf-8 on output.  In particular,
using any extended ascii code page, of which there are many, has long
been acceptable given that everyone on a project is aware of and uses
that same code page to view all data. utf-8 accepts only 7-bit ascii
characters in single bytes, and any characters outside of that base set
require at least two bytes.

Tcl is a string based language, and transcodes all input data to an
internal unicode format, and to whatever format is requested on output:
"pure" binary is recoded using iso8859-1.  Tcl8.x silently recodes
invalid utf-8 as binary data, so extended ascii characters maintain
their binary value on output but may not display correctly.

Tcl 8.7 added three profiles to control this behaviour: strict (raises
exceptions), replace (replaces each invalid byte with ?), and the
default tcl8 maintaining the old behavior.  Tcl 9 changes the default
profile to strict, meaning any invalid utf-8 raises an exception that
gitk does not handle.

An example of this in the git repository is commit 7eb93c8965 ("[PATCH]
Simplify git script", 2005-09-07). This includes extended ascii
characters in the author name and commit message. As a result, gitk +
Tcl 9 cannot view the git repository at any point beyond that commit.
Note: Tcl 9.0 has a bug, to be fixed in 9.1, where this particular
condition results in a memory error causing Tcl to crash [1].

The tcl8 profile used so far has acceptable behavior given gitk's
acceptance: this allows gitk to accept extended ascii though it may
display incorrectly.  Let's continue that behavior by overriding open to
use the tcl8 profile on Tcl9 and later: Tcl 8.6 does not understand
fconfigure -profile, and Tcl 8.7 maintains the tcl8 profile.

[1] Per https://core.tcl-lang.org/tcl/tktview/73bb42fb3f35cd613af6fcea465e35bbfd352216

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
2025-07-16 23:02:38 -04:00