* Re: [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis
From: Siddh Raman Pant @ 2026-05-21 4:13 UTC (permalink / raw)
To: gitster@pobox.com
Cc: git@vger.kernel.org, newren@gmail.com, ps@pks.im,
code@khaugsbakk.name
In-Reply-To: <xmqqpl2p38s4.fsf@gitster.g>
[-- Attachment #1: Type: text/plain, Size: 1219 bytes --]
On Thu, May 21 2026 at 05:58:59 +0530, Junio C Hamano wrote:
> Siddh Raman Pant <siddh.raman.pant@oracle.com> writes:
>
> > On Wed, May 20 2026 at 05:17:51 +0530, Junio C Hamano wrote:
> > > This has nothing to do with "external notes" topic, no?
> >
> > Yeah, but since I added the command line flag I found it doesn't
> > mention the existing flags.
> >
> > Fixing it in the "external notes" commit would be bad, so I put it
> > before that, since it also then provides a logical place to add new
> > flags.
>
> What I meant was that it would have been better as a standalone
> patch that is unrelated to the (now) 8-patch topic for the external
> notes. That way, it can move faster without waiting for the rest.
>
> Unless this patch has complex semantic or textual conflicts that
> makes it easier to manage together with the external notes series,
> that is. I think adding [--notes=...] to one existing line (this
> patch) and adding a new line with [--[no-]external] on it (the main
> part of the topic) can be done in parallel and it is not too much to
> ask for the integrator to merge them on the receiving end.
Ok sure, I'll send it as a standalone patch.
Thanks,
Siddh
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply
* Re: [PATCH 7/9] notes: support an external command to display notes
From: Siddh Raman Pant @ 2026-05-21 4:12 UTC (permalink / raw)
To: git@vger.kernel.org, calvinwan@google.com, gitster@pobox.com,
newren@gmail.com, sandals@crustytoothpaste.net, ps@pks.im,
code@khaugsbakk.name
In-Reply-To: <ag5b4O7-k-3QBR4W@fruit.crustytoothpaste.net>
[-- Attachment #1: Type: text/plain, Size: 2380 bytes --]
On Thu, May 21 2026 at 06:42:00 +0530, brian m. carlson wrote:
> > Assisted-by: Codex:gpt-5.5-xhigh-fast
>
> Just a question here: was this written in whole or in part by Codex, or
> was it just used as a reference to ask questions? I ask because the
> style of notes-external.c differs quite a bit from the style we use (for
> one, the horizontal rule comments) and we have this in
AI tools typically don't generate comments in code like in this series,
you can see by trying out for yourself. Each comment is hand-written by
me. Sorry, I'll remove those lines in v2 after this discussion.
AI was used for review, and providing the initial skeletal, which I
changed significantly.
> SubmittingPatches:
>
> The Developer's Certificate of Origin requires contributors to certify
> that they know the origin of their contributions to the project and
> that they have the right to submit it under the project's license.
> It's not yet clear that this can be legally satisfied when submitting
> significant amount of content that has been generated by AI tools.
>
> [...]
>
> To avoid these issues, we will reject anything that looks AI
> generated, that sounds overly formal or bloated, that looks like AI
> slop, that looks good on the surface but makes no sense, or that
> senders don’t understand or cannot explain.
Please tell me why this change is a slop and doesn't make sense.
If I wanted to mislead here, I would not have used the "Assisted-by"
trailer, which is now being used in kernel land:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#using-assisted-by
There have already been commits in the git.git history having the
Assisted-by trailer.
> I'll note that it also has a lot of global variables, which are common
> in the codebase but we're trying to move away from,
Is there a new facility to store the config without a global variable?
If the issue is the number, I can make a housing struct if you want.
> and it's more
> verbose in commenting than we'd normally see elsewhere in the codebase.
I added comments to explain the code clearly as it's being followed,
especially since this is a new feature and I wanted the intent to be
clear.
If you could tell me which comments to remove, that would be great.
Thanks,
Siddh
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply
* Re: [PATCH v2] git-jump: pick a mode automatically when invoked without arguments
From: Junio C Hamano @ 2026-05-21 1:30 UTC (permalink / raw)
To: Greg Hurrell via GitGitGadget
Cc: git, Jeff King, Greg Hurrell, Erik Cervin Edin, Greg Hurrell
In-Reply-To: <xmqqik8h36al.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
>> +mode_auto() {
>> + if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true"; then
>> + usage >&2
>> + exit 1
>> + fi
>
> That looks like a basic safety measure, which is good.
>
>> + if test -n "$(git ls-files -u "$@")"; then
>> + mode_merge "$@"
>> + elif ! git diff --quiet "$@"; then
>> + mode_diff "$@"
>> + elif ! git diff --check >/dev/null 2>&1; then
>
> Shouldn't this "diff --check" be restricted by "$@" if given?
>> + mode_ws "$@"
If there are any unstaged changes (possibly with whitespace errors),
'git diff --quiet' would exit with non-zero, so "elif ! git diff
--quiet" would be taken and we do mode_diff. The user cannot rely
on "auto" to trigger mode_ws to check whitespace errors in the
working tree files because of this. If there is no unstaged
changes, 'git diff --quiet' woudl exit with zero, so the control
comes to "git diff --check", but then there is nothing mode_ws to
work on in that case, right? So it is not clear to me in what
situation this auto selection of mode_ws would help us.
>> + else
>> + usage >&2
>> + exit 1
>> + fi
>> +}
^ permalink raw reply
* Re: [PATCH v2] git-jump: pick a mode automatically when invoked without arguments
From: Junio C Hamano @ 2026-05-21 1:22 UTC (permalink / raw)
To: Greg Hurrell via GitGitGadget
Cc: git, Jeff King, Greg Hurrell, Erik Cervin Edin, Greg Hurrell
In-Reply-To: <pull.2108.v2.git.1779280307112.gitgitgadget@gmail.com>
"Greg Hurrell via GitGitGadget" <gitgitgadget@gmail.com> writes:
> If none of the interesting cases listed above applies, then auto mode
> falls back to the existing usage-and-exit behavior.
If more than one interesting cases apply, what happens, and what
should happen?
> diff --git a/contrib/git-jump/README b/contrib/git-jump/README
> index 3211841305..ac35792e55 100644
> --- a/contrib/git-jump/README
> +++ b/contrib/git-jump/README
> @@ -75,8 +75,20 @@ git jump grep foo_bar
> # arbitrary grep options
> git jump grep -i foo_bar
>
> +# jump to places with conflict markers or whitespace errors
> +# (as reported by # `git diff --check`)
Is "#" after "reported by" intended?
> diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump
> index 8d1d5d79a6..43d3b42a41 100755
> --- a/contrib/git-jump/git-jump
> +++ b/contrib/git-jump/git-jump
> @@ -2,10 +2,11 @@
>
> usage() {
> cat <<\EOF
> -usage: git jump [--stdout] <mode> [<args>]
> +usage: git jump [--stdout] [<mode>] [<args>]
So "git jump --stdout foo.c" should mean "git jump --stdout auto
foo.c", OK.
> @@ -16,6 +17,10 @@ grep: elements are grep hits. Arguments are given to git grep or, if
>
> ws: elements are whitespace errors. Arguments are given to diff --check.
>
> +auto: select one of the other modes based on worktree state;
> + "merge" if there are unmerged paths, "diff" if there are
> + unstaged changes, "ws" if there are whitespace errors.
> +
> If the optional argument `--stdout` is given, print the quickfix
> lines to standard output instead of feeding it to the editor.
> EOF
> @@ -82,6 +87,23 @@ mode_ws() {
> git diff --check "$@"
> }
>
> +mode_auto() {
> + if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true"; then
> + usage >&2
> + exit 1
> + fi
That looks like a basic safety measure, which is good.
> + if test -n "$(git ls-files -u "$@")"; then
> + mode_merge "$@"
> + elif ! git diff --quiet "$@"; then
> + mode_diff "$@"
> + elif ! git diff --check >/dev/null 2>&1; then
Shouldn't this "diff --check" be restricted by "$@" if given?
> + mode_ws "$@"
> + else
> + usage >&2
> + exit 1
> + fi
> +}
^ permalink raw reply
* Re: [PATCH 7/9] notes: support an external command to display notes
From: brian m. carlson @ 2026-05-21 1:12 UTC (permalink / raw)
To: Siddh Raman Pant
Cc: git, Calvin Wan, Patrick Steinhardt, Elijah Newren,
Kristoffer Haugsbakk, Junio C Hamano
In-Reply-To: <9619077369f1a567bd505b1de1e4f672a5cd1950.1779207350.git.siddh.raman.pant@oracle.com>
[-- Attachment #1: Type: text/plain, Size: 2473 bytes --]
On 2026-05-19 at 16:30:36, Siddh Raman Pant wrote:
> git notes is a very very helpful feature to show user-supplied
> information about a commit alongside its message transparently.
>
> For distributed teams working on large git repos (huge number of
> branches/refs, files, etc.) and using the notes feature to mark
> information on git commits, a TOCTOU race can happen due to very
> large size of the repo and notes ref:
> - Person A updates a note for commit X.
> - Person A pushes the notes but it takes some time.
> - Person B fetches notes and doesn't find the updated note.
> - Person B can come to know of it only when he overwrites it
> and encounters a push failure.
>
> This problem excaberates on scale.
>
> One solution to this is a realtime fetch or faster updation via
> external means, but unfortunately we lose the coherence in the
> display of information, and the user would end up reinventing
> git log.
>
> So let's add support for an external command to display the notes.
>
> We split the addition of documentation and tests from this commit for
> easier review. The new help text added in Documentation/ in the next
> commit should make the usage clear.
>
> Assisted-by: Codex:gpt-5.5-xhigh-fast
Just a question here: was this written in whole or in part by Codex, or
was it just used as a reference to ask questions? I ask because the
style of notes-external.c differs quite a bit from the style we use (for
one, the horizontal rule comments) and we have this in
SubmittingPatches:
The Developer's Certificate of Origin requires contributors to certify
that they know the origin of their contributions to the project and
that they have the right to submit it under the project's license.
It's not yet clear that this can be legally satisfied when submitting
significant amount of content that has been generated by AI tools.
[...]
To avoid these issues, we will reject anything that looks AI
generated, that sounds overly formal or bloated, that looks like AI
slop, that looks good on the surface but makes no sense, or that
senders don’t understand or cannot explain.
I'll note that it also has a lot of global variables, which are common
in the codebase but we're trying to move away from, and it's more
verbose in commenting than we'd normally see elsewhere in the codebase.
--
brian m. carlson (they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 325 bytes --]
^ permalink raw reply
* Re: [PATCH 1/9] Documentation/git-range-diff: add missing notes options in synopsis
From: Junio C Hamano @ 2026-05-21 0:28 UTC (permalink / raw)
To: Siddh Raman Pant
Cc: git@vger.kernel.org, newren@gmail.com, ps@pks.im,
code@khaugsbakk.name
In-Reply-To: <b3958381907244ca06a39e2fc116eec113a6bc85.camel@oracle.com>
Siddh Raman Pant <siddh.raman.pant@oracle.com> writes:
> On Wed, May 20 2026 at 05:17:51 +0530, Junio C Hamano wrote:
>> This has nothing to do with "external notes" topic, no?
>
> Yeah, but since I added the command line flag I found it doesn't
> mention the existing flags.
>
> Fixing it in the "external notes" commit would be bad, so I put it
> before that, since it also then provides a logical place to add new
> flags.
What I meant was that it would have been better as a standalone
patch that is unrelated to the (now) 8-patch topic for the external
notes. That way, it can move faster without waiting for the rest.
Unless this patch has complex semantic or textual conflicts that
makes it easier to manage together with the external notes series,
that is. I think adding [--notes=...] to one existing line (this
patch) and adding a new line with [--[no-]external] on it (the main
part of the topic) can be done in parallel and it is not too much to
ask for the integrator to merge them on the receiving end.
Thanks.
^ permalink raw reply
* [PATCH v2 11/11] git-gui: add gui and pick as explicit subcommands
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui accepts subcommands blame | browser | citool, and assumes the
subcommand is 'gui' if none is actually given, But, git-gui also has a
repository picker (choose_repository::pick) that can create a new
repository + worktree, or choose an existing one, switch to that, and
the run the gui. The user has no direct control over invoking the
picker, instead the picker is triggered by failure in the repository /
worktree discovery process: this includes being started in a directory
not controlled by git, which is probably the intended use case.
The picker can appear when the user has no intention of creating a new
worktree, and the user cannot use the picker to create a new worktree
inside another.
So, add two explicit subcommands:
gui - Run the gui if repository/worktree discovery succeeds, or die
with an error message, but never run the picker.
pick - First run the picker, regardless, then start the gui in
the chosen worktree.
Nothing in this changes the prior behavior, the alternates above must be
explicitly selected to see any change.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index ae609f86f1..299c1a0292 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1024,6 +1024,8 @@ proc load_config {include_global} {
##
## feature option selection
+enable_option picker
+enable_option gitdir_discovery
if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
unset _junk
} else {
@@ -1035,6 +1037,9 @@ if {$subcommand eq {gui.sh}} {
if {$subcommand eq {gui} && [llength $argv] > 0} {
set subcommand [lindex $argv 0]
set argv [lrange $argv 1 end]
+ if {$subcommand eq {gui}} {
+ disable_option picker
+ }
}
enable_option multicommit
@@ -1050,6 +1055,7 @@ blame {
disable_option multicommit
disable_option branch
disable_option transport
+ disable_option picker
}
citool {
enable_option singlecommit
@@ -1058,6 +1064,7 @@ citool {
disable_option multicommit
disable_option branch
disable_option transport
+ disable_option picker
while {[llength $argv] > 0} {
set a [lindex $argv 0]
@@ -1080,6 +1087,9 @@ citool {
set argv [lrange $argv 1 end]
}
}
+pick {
+ disable_option gitdir_discovery
+}
}
######################################################################
@@ -1174,7 +1184,7 @@ proc unset_gitdir_vars {} {
# find repository.
set _gitdir {}
-if {$_gitdir eq {}} {
+if {[is_enabled gitdir_discovery]} {
if {[catch {
set _gitdir [git rev-parse --absolute-git-dir]
} err]} {
@@ -1186,7 +1196,7 @@ if {$_gitdir eq {}} {
}
set picked 0
-if {$_gitdir eq {}} {
+if {$_gitdir eq {} && [is_enabled picker]} {
unset_gitdir_vars
load_config 1
apply_config
@@ -1202,6 +1212,12 @@ if {$_gitdir eq {}} {
set picked 1
}
+if {$_gitdir eq {}} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Git directory not found:"] "\n\n$err"]
+ exit 1
+}
+
# find worktree, continue without if not required
if {[catch {
set _gitworktree [git rev-parse --show-toplevel]
@@ -3137,14 +3153,15 @@ blame {
return
}
citool -
-gui {
+gui -
+pick {
if {[llength $argv] != 0} {
usage
}
# fall through to setup UI for commits
}
default {
- set err "[mc usage:] $argv0 \[{blame|browser|citool}\]"
+ set err "[mc usage:] $argv0 \[{blame|browser|citool|gui|pick}\]"
if {[tk windowingsystem] eq "win32"} {
wm withdraw .
tk_messageBox -icon error -message $err \
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 10/11] git-gui: adapt blame/browser parsing for bare operation
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui's blame and browser subcommands do not work with bare
repositories, but they should per commit c52c94524b ("git-gui: Allow
blame/browser subcommands on bare repositories", 2007-07-17). Assuming
that commit worked, something changed since reintroducing a hard-coded
dependency upon a worktree.
The basic issue goes back to 3e45ee1ef2 ("git-gui: Smarter command line
parsing for browser, blame", 2007-05-08), which seeks to implement
command line parsing similar to git blame. That commit introduces
depencies upon the worktree to decide which argument is rev or path.
Looking at builtin/blame.c in git around line 1120:
* (1) if dashdash_pos != 0, it is either
* "blame [revisions] -- <path>" or
* "blame -- <path> <rev>"
*
* (2) otherwise, it is one of the two:
* "blame [revisions] <path>"
* "blame <path> <rev>"
shows the clear intent: rev and path may be swapped in input so both
meanings must be tried, but -- may be used to designate which is the
path forcing or precluding trying the swapped arguments.
With a worktree, git gui correctly swaps the arguments if the given path
exists in the worktree. git blame does this using the git repository.
But, git-gui sometimes interprets the -- to have an exactly opposite
meaning:
git blame Makefile gitgui-0.19.0 works
git gui blame Makefile gitgui-0.19.0 works
git blame -- Makefile gitgui-0.19.0 works
git gui blame -- Makefile gitgui-0.19.0 works
git blame Makefile -- gitgui-0.19.0 fails (correctly)
git gui blame Makefile -- gitgui-0.19.0 works (should fail)
git blame gitgui-0.19.0 -- Makefile works (correctly)
git gui blame gitgui-0.19.0 -- Makefile fails (should work)
It is possible to patch the code to operate without a worktree, but this
will make the commands operate differently with and without a worktree,
won't fix the parsing issues above, and won't address the issues that
can arise when using a worktree to help decisions on a different rev
with file/directory conflicts, etc.
So, let's rework the parser so that it uses -- as does git blame, and
uses git ls-tree to query the given revision for existence and type of
path rather than basing this upon a possibly unrelated worktree. Also,
abort early when the given path is not found, or does not match the need
(file or directory). This fixes some current cases where git-gui will
open a window with no content, possibly also with an error message.
This does not change whether or how git-gui uses staged and unstaged
content in the current worktree for blame display.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 151 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 87 insertions(+), 64 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index d373457901..ae609f86f1 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -3014,100 +3014,123 @@ proc normalize_relpath {path} {
}
}
+proc find_path_type {head path} {
+ if {$path eq {./}} {
+ # the root-tree exists in every rev, ls-tree gives data on the contents,
+ # not the type of tree itself. So, if the rev exists, return {tree}
+ if {[catch {set objtype [git ls-tree $head]}]} {
+ set objtype {}
+ } else {
+ set objtype {tree}
+ }
+ } else {
+ # test that the path exists in head, ls-tree gives info on the path only
+ if {[catch {set objtype [git ls-tree {--format=%(objecttype)} $head $path]}]} {
+ set objtype {}
+ }
+ }
+ return $objtype
+}
+
# -- Not a normal commit type invocation? Do that instead!
#
switch -- $subcommand {
browser -
blame {
if {$subcommand eq "blame"} {
- set subcommand_args {[--line=<num>] rev? path}
+ set subcommand_args {[--line=<num>] <[rev] [--] filename | [--] filename rev>}
+ set required_objtype blob
} else {
- set subcommand_args {rev? path}
+ set subcommand_args {<[rev] [--] directory | [--] directory rev>}
+ set required_objtype tree
}
- if {$argv eq {}} usage
+ set maxargs [llength $subcommand_args]
+ set nargs [llength $argv]
+ if {$nargs < 1 || $nargs > $maxargs} usage
set head {}
+ set althead {}
set path {}
+ set altpath {}
+ set canswap 1
set jump_spec {}
- set is_path 0
- foreach a $argv {
- set p [file join $_prefix $a]
- if {$is_path || [file exists $p]} {
- if {$path ne {}} usage
- set path [normalize_relpath $p]
- break
- } elseif {$a eq {--}} {
- if {$path ne {}} {
- if {$head ne {}} usage
- set head $path
- set path {}
+ # assume: [--line=num] [head] [--] path as the possible arguments, in order.
+ # head and path may need a swap later.
+ for {set iarg 0} {$iarg < $nargs} {incr iarg} {
+ set arg [lindex $argv $iarg]
+ if {$arg eq {--}} {
+ # next arg is the path, prevent or FORCE swap?
+ if {$iarg == $nargs - 2} {
+ set canswap 0
+ } elseif {$iarg == $nargs - 3} {
+ set canswap 2
+ } else {
+ usage
}
- set is_path 1
- } elseif {[regexp {^--line=(\d+)$} $a a lnum]} {
- if {$jump_spec ne {} || $head ne {}} usage
+ } elseif {[regexp {^--line=(\d+)$} $arg arg lnum]} {
+ # --line can only be the first arg
+ if {$iarg != 0 || $maxargs < 4} usage
set jump_spec [list $lnum]
+ } elseif {$iarg == $nargs - 1} {
+ # assume final argument is path
+ set path [normalize_relpath [file join $_prefix $arg]]
+ set althead $arg
} elseif {$head eq {}} {
- if {$head ne {}} usage
- set head $a
- set is_path 1
+ # assume the other argument is head
+ set head $arg
+ set altpath [normalize_relpath [file join $_prefix $arg]]
} else {
usage
}
}
- unset is_path
-
- if {$head ne {} && $path eq {}} {
- if {[string index $head 0] eq {/}} {
- set path [normalize_relpath $head]
- set head {}
- } else {
- set path [normalize_relpath $_prefix$head]
- set head {}
- }
- }
+ # no swapping allowed if head not given, use current branch (HEAD)
if {$head eq {}} {
load_current_branch
- } else {
- if {[regexp [string map "@@ [expr $hashlength - 1]" {^[0-9a-f]{1,@@}$}] $head]} {
- if {[catch {
- set head [git rev-parse --verify $head]
- } err]} {
- if {[tk windowingsystem] eq "win32"} {
- tk_messageBox -icon error -title [mc Error] -message $err
- } else {
- puts stderr $err
- }
- exit 1
- }
+ set head $current_branch
+ set canswap 0
+ }
+
+ # -- before "rev" arg means we got -- path head
+ if {$canswap == 2} {
+ set head $althead
+ set path $altpath
+ set canswap 0
+ }
+
+ set objtype [find_path_type $head $path]
+ if {$objtype eq {} && $canswap} {
+ set objtype [find_path_type $althead $altpath]
+ if {$objtype ne {}} {
+ set head $althead
+ set path $altpath
}
- set current_branch $head
+ }
+ set current_branch $head
+
+ # check that path exists in head, and objtype matches need
+ if {$objtype ne $required_objtype} {
+ switch -- $required_objtype {
+ tree {set err [strcat \
+ [mc "'%s' is not a directory in rev '%s'" $path $head]]}
+ blob {set err [strcat \
+ [mc "'%s' is not a filename in rev '%s'" $path $head]]}
+ }
+ if {[tk windowingsystem] eq "win32"} {
+ catch {wm withdraw .}
+ error_popup $err
+ } else {
+ puts stderr $err
+ }
+ exit 1
}
wm deiconify .
switch -- $subcommand {
browser {
- if {$jump_spec ne {}} usage
- if {$head eq {}} {
- if {$path ne {} && [file isdirectory $path]} {
- set head $current_branch
- } else {
- set head $path
- set path {}
- }
- }
browser::new $head $path
}
- blame {
- if {$head eq {} && ![file exists $path]} {
- catch {wm withdraw .}
- tk_messageBox \
- -icon error \
- -type ok \
- -title [mc "git-gui: fatal error"] \
- -message [mc "fatal: cannot stat path %s: No such file or directory" $path]
- exit 1
- }
+ blame {
blame::new $head $path $jump_spec
}
}
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 09/11] git-gui: allow specifying path '.' to the browser
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
Invoking "git-gui browser rev ." should show the file browser for the
commitish rev, starting at the current directory. When the current
directory is the working tree root, this errors out in normalize_relpath
because the '.' is removed, yielding an empty list as argument to [file
join ...]. The browser function demands "./" in this case, so make it
so. (./ works on Windows as well because g4w accepts posix file
naming).
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/git-gui.sh b/git-gui.sh
index a72d8a59ec..d373457901 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -3007,7 +3007,11 @@ proc normalize_relpath {path} {
}
lappend elements $item
}
- return [eval file join $elements]
+ if {$elements ne {}} {
+ return [eval file join $elements]
+ } else {
+ return {./}
+ }
}
# -- Not a normal commit type invocation? Do that instead!
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 08/11] git-gui: use HEAD as current branch when detached (bug fix)
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
commit f87a36b697 ("git-gui: use git-branch --show-current", 2024-02-12)
changed git-gui to use git-branch to access refs, rather than directly
reading files as doing the latter is not compatible with the reftable
backend. git branch --show-current reports an empty branch name when the
head is detached, and in this case load_current_branch needs to report
HEAD using special case logic as it did prior to the above commit. Make
it do so.
This addresses an issue with git-gui browser failing with a detached
head.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 3 +++
1 file changed, 3 insertions(+)
diff --git a/git-gui.sh b/git-gui.sh
index aeb7ed3548..a72d8a59ec 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -648,6 +648,9 @@ proc load_current_branch {} {
set current_branch [git branch --show-current]
set is_detached [expr [string length $current_branch] == 0]
+ if {$is_detached} {
+ set current_branch {HEAD}
+ }
}
auto_load tk_optionMenu
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 03/11] git-gui: use --absolute-git-dir
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui uses git rev-parse --git-dir to get the pathname of the
discovered git repository. The returned value can be relative, and is
'.' if the current directory is the top of the repository directory
itself. git-gui has code to change '.' to [pwd] in this case so that
subsequent logic runs.
But, git rev-parse supports --absolute-git-dir from fac60b8925
("rev-parse: add option for absolute or relative path formatting",
2020-12-13), and included in git 2.31. git-gui requires git >= 2.36, so
this more useful form is always available. Use --absolute-git-dir to
always get an absolute path, avoiding the need for other checks, and
delete the now unneeded code to fix a relative _gitdir.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index 4a736190a9..233c975786 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1146,7 +1146,7 @@ if {[catch {
&& [catch {
# beware that from the .git dir this sets _gitdir to .
# and _prefix to the empty string
- set _gitdir [git rev-parse --git-dir]
+ set _gitdir [git rev-parse --absolute-git-dir]
set _prefix [git rev-parse --show-prefix]
} err]} {
load_config 1
@@ -1155,7 +1155,7 @@ if {[catch {
exit 1
}
if {[catch {
- set _gitdir [git rev-parse --git-dir]
+ set _gitdir [git rev-parse --absolute-git-dir]
} err]} {
catch {wm withdraw .}
error_popup [strcat [mc "Unusable repo/worktree:"] " [pwd] "\n\n$err"]
@@ -1175,13 +1175,6 @@ if {$hashalgorithm eq "sha1"} {
exit 1
}
-# we expand the _gitdir when it's just a single dot (i.e. when we're being
-# run from the .git dir itself) lest the routines to find the worktree
-# get confused
-if {$_gitdir eq "."} {
- set _gitdir [pwd]
-}
-
if {![file isdirectory $_gitdir]} {
catch {wm withdraw .}
error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 07/11] git-gui: try harder to find worktree from gitdir
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui, since 87cd09f43e ("git-gui: work from the .git dir",
2010-01-23), has had the intent to allow starting from inside a
repository, then switching to the parent directory if that is a valid
worktree.
This certainly hasn't worked since 2d92ab32fd ("rev-parse: make
--show-toplevel without a worktree an error", 2019-11-19) in git, but
breaking this git-gui feature was unintentional.
There are (at least) 3 cases where the gitdir can tell us where the
worktree is, and we would like all to work:
- core.worktree is set, and points to a valid worktree. This is already
handled by git rev-parse --show-toplevel, even when not in the worktree.
There is nothing more to do in this case.
- the gitdir is embedded in a worktree as subdirectory .git. The parent
is (or at least should be) a valid worktree. This worked long ago.
- the gitdir is a worktree specific directory (under
<mainrepo>/worktrees/worktree_name), within which there is a file
"gitdir" pointing to .git in the worktree. git gui never learned to
handle this case.
Let's handle the latter two cases. Always check that the discovered
worktree is valid and points to the already discovered gitdir according
to git rev-parse. This avoids issues that may arise because we are
discovering from the gitdir up, rather than the worktree down, and file
system non-posix behavior or misconfiguration of git might cause
confusion. For instance, a manually moved worktree might not be where
the gitdir points.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/git-gui.sh b/git-gui.sh
index 8fe25fe188..aeb7ed3548 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1100,6 +1100,41 @@ unset argv0dir
##
## repository setup
+proc find_worktree_from_gitdir {} {
+ # Directory 'parent' of a repository named 'parent/.git' might be the worktree.
+ # Assure parent is a worktree and using the git repository already discovered.
+ # Also, handle case of being in a worktree's gitdir, where file "gitdir" points to
+ # gitlink file .git in the real worktree.
+ set worktree {}
+ if {[file tail $::_gitdir] eq {.git}} {
+ if {[catch {
+ set gitdir_parent [file dirname $::_gitdir]
+ set worktree [git -C $gitdir_parent rev-parse --show-toplevel]
+ set parent_gitdir [git -C $worktree rev-parse --absolute-git-dir]
+ if {$::_gitdir ne $parent_gitdir} {
+ set worktree {}
+ }
+ }]} {
+ set worktree {}
+ }
+ } elseif [file exists {gitdir}] {
+ if {[catch {
+ set fd_gitdir [open {gitdir} {r}]
+ set gitlink_parent [file dirname [read $fd_gitdir]]
+ catch {close $fd_gitdir}
+ set worktree [git -C $gitlink_parent rev-parse --show-toplevel]
+ set parent_gitdir [git -C $worktree rev-parse --absolute-git-dir]
+ if {$::_gitdir ne $parent_gitdir} {
+ set worktree {}
+ }
+ }]} {
+ catch {close $fd_gitdir}
+ set worktree {}
+ }
+ }
+ return $worktree
+}
+
proc is_gitvars_error {err} {
set havevars 0
set GIT_DIR {}
@@ -1176,6 +1211,13 @@ if {[catch {
set _prefix {}
}
+if {[is_bare]} {
+ # Maybe we are in an embedded or worktree specific gitdir
+ if {[set _gitworktree [find_worktree_from_gitdir]] ne {}} {
+ set _prefix {}
+ }
+}
+
if {![is_bare]} {
if {[catch {
cd $_gitworktree
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 06/11] git-gui: use git rev-parse for worktree discovery
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git gui uses a combination of tcl code and git invocations to determine
the worktree and the location with respect to the worktree root
(_prefix). But, git rev-parse provides all of this information directly,
and assures full error and configuration checking are done by git
itself. The entirety of discovery in normal configurations involves
git rev-parse --show-toplevel (gets worktree root)
git rev-parse --show-prefix (shows location wrt the root)
An error thrown on either of these lines means the worktree discovered
by git is unusable, or git did not discover a worktree because the
current directory is inside the repository. If the user has defined
GIT_DIR or GIT_WORK_TREE, this is a user configuration error and git-gui
should stop.
Otherwise, the blame or browser subcommands can be used without a
worktree.
A separate error might occur when changing to the root of the discovered
worktree. The cause would be file system related and completely outside
of git's control. So, the final "cd $worktree_root" is separately
trapped.
Discovery of the repository and the worktree must be guarded to trap
errors: the intent is that any configuration problems are caught during
discovery, and later processing need not include error trapping and
recovery. So, move all worktree discovery code to be immediately after
repository discovery.
This does move configuration loading to occur after worktree discovery
rather than before. None of the code executed in worktree discovery has
any option controlled by a git-gui configuration variable, so no impact
is expected. git itself will always read the repository configuration,
including worktree specific configuration data if that exists, so this
is unaffected by when git-gui loads its own config data, and we cannot
be sure the full worktree dependent configuration can be loaded before
full discovery is complete.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 64 +++++++++++++++++++++++++-----------------------------
1 file changed, 30 insertions(+), 34 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index 936c309e59..8fe25fe188 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1164,6 +1164,36 @@ if {$_gitdir eq {}} {
set picked 1
}
+# find worktree, continue without if not required
+if {[catch {
+ set _gitworktree [git rev-parse --show-toplevel]
+ set _prefix [git rev-parse --show-prefix]
+} err]} {
+ if {[is_gitvars_error $err]} {
+ exit 1
+ }
+ set _gitworktree {}
+ set _prefix {}
+}
+
+if {![is_bare]} {
+ if {[catch {
+ cd $_gitworktree
+ } err]} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Cannot change to discovered worktree: "] \
+ "$_gitworktree" "\n\n$err"]
+ exit 1;
+ }
+} elseif {![is_enabled bare]} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Cannot use bare repository:"] "\n\n" $_gitdir]
+ exit 1
+}
+
+# repository and worktree config are complete, export them
+set_gitdir_vars
+
# Use object format as hash algorithm (either "sha1" or "sha256")
set hashalgorithm [git rev-parse --show-object-format]
if {$hashalgorithm eq "sha1"} {
@@ -1179,37 +1209,6 @@ if {$hashalgorithm eq "sha1"} {
load_config 0
apply_config
-set _gitworktree [git rev-parse --show-toplevel]
-
-if {$_prefix ne {}} {
- if {$_gitworktree eq {}} {
- regsub -all {[^/]+/} $_prefix ../ cdup
- } else {
- set cdup $_gitworktree
- }
- if {[catch {cd $cdup} err]} {
- catch {wm withdraw .}
- error_popup [strcat [mc "Cannot move to top of working directory:"] "\n\n$err"]
- exit 1
- }
- set _gitworktree [pwd]
- unset cdup
-} elseif {![is_enabled bare]} {
- if {[is_bare]} {
- catch {wm withdraw .}
- error_popup [strcat [mc "Cannot use bare repository:"] "\n\n$_gitdir"]
- exit 1
- }
- if {$_gitworktree eq {}} {
- set _gitworktree [file dirname $_gitdir]
- }
- if {[catch {cd $_gitworktree} err]} {
- catch {wm withdraw .}
- error_popup [strcat [mc "No working directory"] " $_gitworktree:\n\n$err"]
- exit 1
- }
- set _gitworktree [pwd]
-}
set _reponame [file split [file normalize $_gitdir]]
if {[lindex $_reponame end] eq {.git}} {
set _reponame [lindex $_reponame end-1]
@@ -1217,9 +1216,6 @@ if {[lindex $_reponame end] eq {.git}} {
set _reponame [lindex $_reponame end]
}
-# Export the final paths
-set_gitdir_vars
-
######################################################################
##
## global init
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 05/11] git-gui: simplify [is_bare] to report if a worktree is known
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui includes proc is_bare, used in several places to make decisions
on whether a worktree exists, but also in discovery to tell if a
worktree can be supported.
But, is_bare is out of date with regard to multiple worktrees, safe
repository guards, and possibly other relevant features known to git
rev-parse. Also, is_bare caches its result on the first call, so is not
useful if a later step in the discovery process finds a worktree.
So, simplify is_bare to report whether git-gui has a worktree or is
working only from a repository.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 25 +------------------------
1 file changed, 1 insertion(+), 24 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index c61a6cbd8f..936c309e59 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -372,7 +372,6 @@ if {[tk windowingsystem] eq "aqua"} {
set _appname {Git Gui}
set _gitdir {}
set _gitworktree {}
-set _isbare {}
set _githtmldir {}
set _prefix {}
set _reponame {}
@@ -524,29 +523,7 @@ proc get_config {name} {
}
proc is_bare {} {
- global _isbare
- global _gitdir
- global _gitworktree
-
- if {$_isbare eq {}} {
- if {[catch {
- set _bare [git rev-parse --is-bare-repository]
- switch -- $_bare {
- true { set _isbare 1 }
- false { set _isbare 0}
- default { throw }
- }
- }]} {
- if {[is_config_true core.bare]
- || ($_gitworktree eq {}
- && [lindex [file split $_gitdir] end] ne {.git})} {
- set _isbare 1
- } else {
- set _isbare 0
- }
- }
- }
- return $_isbare
+ return [expr {$::_gitworktree eq {}}]
}
######################################################################
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 04/11] git-gui: use rev-parse exclusively to find a repository
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui attempts to use env(GIT_DIR) directly as the git repository,
accepting GIT_DIR if it is a directory. Only if that fails is git
rev-parse used to discover the repository. But, this avoids all of
git-core's validity checking on a repository, thus possibly deferring an
error to a later step, possibly unexpected. Repository validation should
be part of initial setup so that later processing does not need error
trapping for configuration errors.
Let's just invoke rev-parse so all error checking is done.
While here, let's cleanup the error handling.
Stop if an error occurs and the user set GIT_DIR or GIT_WORK_TREE.
Use of either or both of those variables is supported by git, but their
use also means the user has taken responsibility that they are correct,
so a failure is something the user must address.
Otherwise on error, continue the existing behavior and show the
repository picker. But, let's move the possible invocation of
repository_chooser::pick to a separate code block. This permits adding
separate conditions on using pick indepent of repository discovery, and
will be exploited later in the series. Note that the picker always
returns with the current directory in the root of a worktree with the
git repository is in the .git subdirectory. The variable "picked" is
used by git-gui to automatically execute the "Explore Working Copy" menu
item after the repository picker is run. This is controlled by config
variable gui.autoexplore, and happens after all discovery is complete.
Remove a later check on whether _gitdir is a directory: that code
cannot be reached without rev-parse already validating the repository.
_prefix should not be set before worktree discovery: the prefix is only
known after the worktree is found, and at this point we have only
discovered the repository. This is true even when running the repository
picker: that option provides a list of prior selections, and does no
validation on the list beyond checking that the directories exist. For
now, just initialize _prefix along with other global variables.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 48 +++++++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index 233c975786..c61a6cbd8f 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -374,6 +374,7 @@ set _gitdir {}
set _gitworktree {}
set _isbare {}
set _githtmldir {}
+set _prefix {}
set _reponame {}
set _shellpath {@@SHELL_PATH@@}
@@ -1122,6 +1123,24 @@ unset argv0dir
##
## repository setup
+proc is_gitvars_error {err} {
+ set havevars 0
+ set GIT_DIR {}
+ set GIT_WORK_TREE {}
+ catch {set GIT_DIR $::env(GIT_DIR); set havevars 1}
+ catch {set GIT_WORK_TREE $::env(GIT_WORK_TREE) ; set havevars 1}
+
+ if {$havevars} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Invalid configuration:"] \
+ "\n" "GIT_DIR: " $GIT_DIR \
+ "\n" "GIT_WORK_TREE: " $GIT_WORK_TREE \
+ "\n\n$err"]
+ return 1
+ }
+ return 0
+}
+
proc set_gitdir_vars {} {
global _gitdir _gitworktree env
if {$_gitdir ne {}} {
@@ -1138,17 +1157,22 @@ proc unset_gitdir_vars {} {
catch {unset env(GIT_WORK_TREE)}
}
-set picked 0
-if {[catch {
- set _gitdir $env(GIT_DIR)
- set _prefix {}
- }]
- && [catch {
- # beware that from the .git dir this sets _gitdir to .
- # and _prefix to the empty string
+# find repository.
+set _gitdir {}
+if {$_gitdir eq {}} {
+ if {[catch {
set _gitdir [git rev-parse --absolute-git-dir]
- set _prefix [git rev-parse --show-prefix]
} err]} {
+ if {[is_gitvars_error $err]} {
+ exit 1
+ }
+ set _gitdir {}
+ }
+}
+
+set picked 0
+if {$_gitdir eq {}} {
+ unset_gitdir_vars
load_config 1
apply_config
if {![choose_repository::pick]} {
@@ -1160,7 +1184,6 @@ if {[catch {
catch {wm withdraw .}
error_popup [strcat [mc "Unusable repo/worktree:"] " [pwd] "\n\n$err"]
}
- set _prefix {}
set picked 1
}
@@ -1175,11 +1198,6 @@ if {$hashalgorithm eq "sha1"} {
exit 1
}
-if {![file isdirectory $_gitdir]} {
- catch {wm withdraw .}
- error_popup [strcat [mc "Git directory not found:"] "\n\n$_gitdir"]
- exit 1
-}
# _gitdir exists, so try loading the config
load_config 0
apply_config
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 02/11] git-gui: return status from choose_repository::pick
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
The repository picker (choose_repository::pick) on success always
returns with the current directory at the root of the selected worktree,
and with the global variable _gitdir holding the name of the git
repository, possibly as a relative path. On failure, _gitdir = {}. If
the selection was from the "recent" list, no validation has occurred.
There are too many side effects in this interface. Note that the picker
only supports worktrees with a .git entry in the worktree root, so git
repository and worktree discovery will work starting in the current
directory on return. So, let's change pick to return a 0/1 value, 1
meaning a worktreee + repo was selected and the current directory is the
worktree root, and leave validation and setting of _gitdir,
_gitworktree, and _prefix to the caller. Note: pick actually does not
return if something was not selected, rather it terminates git-gui.
But, let's pretend at the call site that pick returns 0/false instead.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 10 ++++++++--
lib/choose_repository.tcl | 21 ++++++++-------------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index 4ba25da7b6..4a736190a9 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1151,10 +1151,16 @@ if {[catch {
} err]} {
load_config 1
apply_config
- choose_repository::pick
- if {![file isdirectory $_gitdir]} {
+ if {![choose_repository::pick]} {
exit 1
}
+ if {[catch {
+ set _gitdir [git rev-parse --git-dir]
+ } err]} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Unusable repo/worktree:"] " [pwd] "\n\n$err"]
+ }
+ set _prefix {}
set picked 1
}
diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
index 7e1462a20c..4b06afee93 100644
--- a/lib/choose_repository.tcl
+++ b/lib/choose_repository.tcl
@@ -15,7 +15,7 @@ field w_recentlist ; # Listbox containing recent repositories
field w_localpath ; # Entry widget bound to local_path
field done 0 ; # Finished picking the repository?
-field clone_ok false ; # clone succeeeded
+field pick_ok 0 ; # true if repo pick/clone succeeded
field local_path {} ; # Where this repository is locally
field origin_url {} ; # Where we are cloning from
field origin_name origin ; # What we shall call 'origin'
@@ -220,6 +220,8 @@ constructor pick {} {
if {$top eq {.}} {
eval destroy [winfo children $top]
}
+
+ return $pick_ok
}
method _center {} {
@@ -327,8 +329,7 @@ method _git_init {} {
}
_append_recentrepos [pwd]
- set ::_gitdir .git
- set ::_prefix {}
+ set pick_ok 1
return 1
}
@@ -409,6 +410,7 @@ method _do_new2 {} {
if {![_git_init $this]} {
return
}
+ set pick_ok 1
set done 1
}
@@ -621,7 +623,7 @@ method _do_clone2 {} {
}
tkwait variable @done
- if {!$clone_ok} {
+ if {!$pick_ok} {
error_popup [mc "Clone failed."]
return
}
@@ -632,18 +634,12 @@ method _do_clone2_done {ok} {
if {$ok} {
if {[catch {
cd $local_path
- set ::_gitdir .git
- set ::_prefix {}
_append_recentrepos [pwd]
} err]} {
set ok 0
}
}
- if {!$ok} {
- set ::_gitdir {}
- set ::_prefix {}
- }
- set clone_ok $ok
+ set pick_ok $ok
set done 1
}
@@ -721,8 +717,7 @@ method _do_open2 {} {
}
_append_recentrepos [pwd]
- set ::_gitdir $actualgit
- set ::_prefix {}
+ set pick_ok 1
set done 1
}
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 01/11] git-gui: guard set/unset of GIT_DIR and GIT_WORK_TREE
From: Mark Levedahl @ 2026-05-20 20:24 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260520202411.108764-1-mlevedahl@gmail.com>
git-gui unconditionally exports _gitdir as GIT_DIR, and _gitworktree as
GIT_WORK_TREE, to the environment, and furthermore unconditionally
unsets these environment variables in many
git gui must have a repository, so _gitdir can never be empty and its
export is always valid if repository discovery completes successfully.
git gui might not find a worktree, so _gitworktree can be empty. While
having no worktree is valid for blame/browser subcommands, exporting
GIT_WORK_TREE=<empty> is not valid. Rather, an empty GIT_WORK_TREE
raises errors in git builtins, for instance 'git branch --show-current'
as used by git, and causes breakage. This is one cause of git blame /
git browser not working without a worktree.
A user may set GIT_DIR and/or GIT_WORK_TREE to override git's normal
discovery rules, including repository configuration of core.worktree
and/or worktree specific gitdirs. It is always safe to export the
absolute pathnames of the discovered values, even though they may not be
needed. However, the gitdir might not be found from the worktree without
GIT_DIR being set. Furthermore, the worktree defined by the discovered
gitdir might be overridden by GIT_WORK_TREE set before git-gui started.
So, it is also sometimes necessary that one or both of these variables
is set.
So, let's provide two procs, one to unset GIT_DIR / GIT_WORK_TREE if
they are set, one to set GIT_DIR and, if not empty, GIT_WORK_TREE, so
all call sites do the same thing, and problems with _gitworktree == {}
are avoided.
Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
git-gui.sh | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index 23fe76e498..4ba25da7b6 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1122,6 +1122,22 @@ unset argv0dir
##
## repository setup
+proc set_gitdir_vars {} {
+ global _gitdir _gitworktree env
+ if {$_gitdir ne {}} {
+ set env(GIT_DIR) $_gitdir
+ }
+ if {$_gitworktree ne {}} {
+ set env(GIT_WORK_TREE) $_gitworktree
+ }
+}
+
+proc unset_gitdir_vars {} {
+ global env
+ catch {unset env(GIT_DIR)}
+ catch {unset env(GIT_WORK_TREE)}
+}
+
set picked 0
if {[catch {
set _gitdir $env(GIT_DIR)
@@ -1207,8 +1223,8 @@ if {[lindex $_reponame end] eq {.git}} {
set _reponame [lindex $_reponame end]
}
-set env(GIT_DIR) $_gitdir
-set env(GIT_WORK_TREE) $_gitworktree
+# Export the final paths
+set_gitdir_vars
######################################################################
##
@@ -2007,7 +2023,7 @@ proc incr_font_size {font {amt 1}} {
proc do_gitk {revs {is_submodule false}} {
global current_diff_path file_states current_diff_side ui_index
- global _gitdir _gitworktree
+ global _gitworktree
# -- Always start gitk through whatever we were loaded with. This
# lets us bypass using shell process on Windows systems.
@@ -2017,8 +2033,6 @@ proc do_gitk {revs {is_submodule false}} {
if {$exe eq {}} {
error_popup [mc "Couldn't find gitk in PATH"]
} else {
- global env
-
set pwd [pwd]
if {!$is_submodule} {
@@ -2050,13 +2064,11 @@ proc do_gitk {revs {is_submodule false}} {
# TODO we could make life easier (start up faster?) for gitk
# by setting these to the appropriate values to allow gitk
# to skip the heuristics to find their proper value
- unset env(GIT_DIR)
- unset env(GIT_WORK_TREE)
+ unset_gitdir_vars
}
safe_exec_bg [concat $cmd $revs "--" "--"]
- set env(GIT_DIR) $_gitdir
- set env(GIT_WORK_TREE) $_gitworktree
+ set_gitdir_vars
cd $pwd
if {[info exists main_status]} {
@@ -2079,21 +2091,16 @@ proc do_git_gui {} {
if {$exe eq {}} {
error_popup [mc "Couldn't find git gui in PATH"]
} else {
- global env
- global _gitdir _gitworktree
-
# see note in do_gitk about unsetting these vars when
# running tools in a submodule
- unset env(GIT_DIR)
- unset env(GIT_WORK_TREE)
+ unset_gitdir_vars
set pwd [pwd]
cd $current_diff_path
safe_exec_bg [concat $exe gui]
- set env(GIT_DIR) $_gitdir
- set env(GIT_WORK_TREE) $_gitworktree
+ set_gitdir_vars
cd $pwd
set status_operation [$::main_status \
--
2.54.0.99.14
^ permalink raw reply related
* [PATCH v2 00/11] Improve git gui operation without a worktree
From: Mark Levedahl @ 2026-05-20 20:23 UTC (permalink / raw)
To: git; +Cc: j6t, egg_mushroomcow, bootaina702, Mark Levedahl
In-Reply-To: <20260514143322.865587-1-mlevedahl@gmail.com>
git gui has a number of inter-related problems that result in problems
during startup from anything but a checked out worktree pointing at a
valid git repository. Some of the symptoms are:
- blame / browser subcommands, and launching gitk, are intended to be
useful without a worktree, but fail to work.
- unlike git, git-gui is supposed to use the parent directory as a
worktree if started from the .git subdirectory in the very common
single worktree + embedded git repository format. This does not
work.
- git-gui includes a repository picker allowing a user to select a
worktree from a list and/or start a new repo+worktree: this dialog can
appear at unexpected times, masking useful error feedback on
configuration problems.
This patch series addresses the above issues, substantially rewriting
the initial repository/worktree process to rely upon git rev-parse so
that git's knowledge of access rules, repository configuration, and use
of GIT_DIR / GIT_WORK_TREE (or git --gitdir / --work-tree) is used
throughout, replacing code largely based upon what git did in 2008. This
also means that git gui will naturally gain any new rules implmented in
git-core.
With this, git-gui only exports GIT_WORK_TREE when non-empty.
GIT_WORK_TREE is needed, and must be exported, if the user is overriding
core.worktree in the git repository. But, GIT_WORK_TREE cannot be used
to specify the lack of a worktree, so exporting an empty GIT_WORK_TREE
is one of the problems fixed by this series.
v2 of this series is a very substantial rewrite driven by j6t's review,
with patches reoranized and squashed, interfaces to the repository
chooser changed, a different code structure to allow user control of the
repository picker, a different approach to fixing the command line
parser for blame / browser, and other more minor changes. Patches
for fixing blame / browser are now after all discovery refactoring as
they cannot be tested without some of those fixes.
Many subtle things are fixed beyond the list at the top, including
better compatibility with git blame and repeatable browser / blame
operation for specific revs not in the worktree, regardless of the
worktree state. j6t indicated that in the git-gui project, the following
fails in the current release:
cd lib
GIT_DIR=$PWD/../.git GIT_WORK_TREE=$PWD/.. ../git-gui.sh browser origin/master .
This is due to a _prefix issue, and is fixed as of the patch
git-gui: use git rev-parse for worktree discovery
Mark Levedahl (11):
git-gui: guard set/unset of GIT_DIR and GIT_WORK_TREE
git-gui: return status from choose_repository::pick
git-gui: use --absolute-git-dir
git-gui: use rev-parse exclusively to find a repository
git-gui: simplify [is_bare] to report if a worktree is known
git-gui: use git rev-parse for worktree discovery
git-gui: try harder to find worktree from gitdir
git-gui: use HEAD as current branch when detached (bug fix)
git-gui: allow specifying path '.' to the browser
git-gui: adapt blame/browser parsing for bare operation
git-gui: add gui and pick as explicit subcommands
git-gui.sh | 412 +++++++++++++++++++++++---------------
lib/choose_repository.tcl | 21 +-
2 files changed, 257 insertions(+), 176 deletions(-)
Interdiff against v1:
diff --git a/git-gui.sh b/git-gui.sh
index c56aeeff88..299c1a0292 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -648,6 +648,9 @@ proc load_current_branch {} {
set current_branch [git branch --show-current]
set is_detached [expr [string length $current_branch] == 0]
+ if {$is_detached} {
+ set current_branch {HEAD}
+ }
}
auto_load tk_optionMenu
@@ -1021,7 +1024,8 @@ proc load_config {include_global} {
##
## feature option selection
-set run_picker_on_error 1
+enable_option picker
+enable_option gitdir_discovery
if {[regexp {^git-(.+)$} [file tail $argv0] _junk subcommand]} {
unset _junk
} else {
@@ -1031,9 +1035,11 @@ if {$subcommand eq {gui.sh}} {
set subcommand gui
}
if {$subcommand eq {gui} && [llength $argv] > 0} {
- set run_picker_on_error 0
set subcommand [lindex $argv 0]
set argv [lrange $argv 1 end]
+ if {$subcommand eq {gui}} {
+ disable_option picker
+ }
}
enable_option multicommit
@@ -1049,7 +1055,7 @@ blame {
disable_option multicommit
disable_option branch
disable_option transport
- set run_picker_on_error 0
+ disable_option picker
}
citool {
enable_option singlecommit
@@ -1058,7 +1064,7 @@ citool {
disable_option multicommit
disable_option branch
disable_option transport
- set run_picker_on_error 0
+ disable_option picker
while {[llength $argv] > 0} {
set a [lindex $argv 0]
@@ -1081,6 +1087,9 @@ citool {
set argv [lrange $argv 1 end]
}
}
+pick {
+ disable_option gitdir_discovery
+}
}
######################################################################
@@ -1104,21 +1113,39 @@ unset argv0dir
##
## repository setup
-proc is_parent_worktree {} {
- # Directory 'parent' of a repository named 'parent/.git' might be the worktree
- set ok 0
+proc find_worktree_from_gitdir {} {
+ # Directory 'parent' of a repository named 'parent/.git' might be the worktree.
+ # Assure parent is a worktree and using the git repository already discovered.
+ # Also, handle case of being in a worktree's gitdir, where file "gitdir" points to
+ # gitlink file .git in the real worktree.
+ set worktree {}
if {[file tail $::_gitdir] eq {.git}} {
- set gitdir_parent [file join $::_gitdir {..}]
- set expected_worktree [file normalize $gitdir_parent]
- catch {set git_worktree [git -C $gitdir_parent rev-parse --show-toplevel]}
- if {[string compare $expected_worktree $git_worktree] == 0} {
- set ::_prefix {}
- set ::_gitworktree $git_worktree
- cd $git_worktree
- set ok 1
+ if {[catch {
+ set gitdir_parent [file dirname $::_gitdir]
+ set worktree [git -C $gitdir_parent rev-parse --show-toplevel]
+ set parent_gitdir [git -C $worktree rev-parse --absolute-git-dir]
+ if {$::_gitdir ne $parent_gitdir} {
+ set worktree {}
+ }
+ }]} {
+ set worktree {}
+ }
+ } elseif [file exists {gitdir}] {
+ if {[catch {
+ set fd_gitdir [open {gitdir} {r}]
+ set gitlink_parent [file dirname [read $fd_gitdir]]
+ catch {close $fd_gitdir}
+ set worktree [git -C $gitlink_parent rev-parse --show-toplevel]
+ set parent_gitdir [git -C $worktree rev-parse --absolute-git-dir]
+ if {$::_gitdir ne $parent_gitdir} {
+ set worktree {}
+ }
+ }]} {
+ catch {close $fd_gitdir}
+ set worktree {}
}
}
- return $ok
+ return $worktree
}
proc is_gitvars_error {err} {
@@ -1155,62 +1182,76 @@ proc unset_gitdir_vars {} {
catch {unset env(GIT_WORK_TREE)}
}
+# find repository.
+set _gitdir {}
+if {[is_enabled gitdir_discovery]} {
+ if {[catch {
+ set _gitdir [git rev-parse --absolute-git-dir]
+ } err]} {
+ if {[is_gitvars_error $err]} {
+ exit 1
+ }
+ set _gitdir {}
+ }
+}
+
set picked 0
-proc pick_repo {} {
+if {$_gitdir eq {} && [is_enabled picker]} {
unset_gitdir_vars
load_config 1
apply_config
- choose_repository::pick
- set _gitdir [git rev-parse --absolute-git-dir]
- set _prefix {}
+ if {![choose_repository::pick]} {
+ exit 1
+ }
+ if {[catch {
+ set _gitdir [git rev-parse --absolute-git-dir]
+ } err]} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Unusable repo/worktree:"] " [pwd] "\n\n$err"]
+ }
set picked 1
}
-# run repository picker if explicitly requested
-switch -- $subcommand {
- pick {
- pick_repo
- set subcommand gui
- set run_picker_on_error 0
- }
-}
-
-# find repository.
-if {[catch {
- set _gitdir [git rev-parse --absolute-git-dir]
-} err]} {
- if {[is_gitvars_error $err]} {
- exit 1
- }
- if {$run_picker_on_error} {
- pick_repo
- } else {
- catch {wm withdraw .}
- error_popup [strcat [mc "Git directory not found:"] "\n\n$err"]
- exit 1
- }
+if {$_gitdir eq {}} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Git directory not found:"] "\n\n$err"]
+ exit 1
}
# find worktree, continue without if not required
if {[catch {
set _gitworktree [git rev-parse --show-toplevel]
set _prefix [git rev-parse --show-prefix]
- cd $_gitworktree
} err]} {
if {[is_gitvars_error $err]} {
exit 1
}
set _gitworktree {}
set _prefix {}
- if {[is_enabled bare]} {
- cd $_gitdir
- } elseif {![is_parent_worktree]} {
- catch {wm withdraw .}
- error_popup [strcat [mc "Cannot use bare repository:"] "\n\n" $_gitdir]
- exit 1
+}
+
+if {[is_bare]} {
+ # Maybe we are in an embedded or worktree specific gitdir
+ if {[set _gitworktree [find_worktree_from_gitdir]] ne {}} {
+ set _prefix {}
}
}
+if {![is_bare]} {
+ if {[catch {
+ cd $_gitworktree
+ } err]} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Cannot change to discovered worktree: "] \
+ "$_gitworktree" "\n\n$err"]
+ exit 1;
+ }
+} elseif {![is_enabled bare]} {
+ catch {wm withdraw .}
+ error_popup [strcat [mc "Cannot use bare repository:"] "\n\n" $_gitdir]
+ exit 1
+}
+
# repository and worktree config are complete, export them
set_gitdir_vars
@@ -1229,8 +1270,6 @@ if {$hashalgorithm eq "sha1"} {
load_config 0
apply_config
-
-# Derive a human-readable repository name
set _reponame [file split [file normalize $_gitdir]]
if {[lindex $_reponame end] eq {.git}} {
set _reponame [lindex $_reponame end-1]
@@ -2035,7 +2074,7 @@ proc incr_font_size {font {amt 1}} {
proc do_gitk {revs {is_submodule false}} {
global current_diff_path file_states current_diff_side ui_index
- global _gitdir _gitworktree
+ global _gitworktree
# -- Always start gitk through whatever we were loaded with. This
# lets us bypass using shell process on Windows systems.
@@ -2045,8 +2084,6 @@ proc do_gitk {revs {is_submodule false}} {
if {$exe eq {}} {
error_popup [mc "Couldn't find gitk in PATH"]
} else {
- global env
-
set pwd [pwd]
if {!$is_submodule} {
@@ -2105,9 +2142,6 @@ proc do_git_gui {} {
if {$exe eq {}} {
error_popup [mc "Couldn't find git gui in PATH"]
} else {
- global env
- global _gitdir _gitworktree
-
# see note in do_gitk about unsetting these vars when
# running tools in a submodule
unset_gitdir_vars
@@ -2992,77 +3026,135 @@ proc normalize_relpath {path} {
if {$elements ne {}} {
return [eval file join $elements]
} else {
- return {}
+ return {./}
}
}
+proc find_path_type {head path} {
+ if {$path eq {./}} {
+ # the root-tree exists in every rev, ls-tree gives data on the contents,
+ # not the type of tree itself. So, if the rev exists, return {tree}
+ if {[catch {set objtype [git ls-tree $head]}]} {
+ set objtype {}
+ } else {
+ set objtype {tree}
+ }
+ } else {
+ # test that the path exists in head, ls-tree gives info on the path only
+ if {[catch {set objtype [git ls-tree {--format=%(objecttype)} $head $path]}]} {
+ set objtype {}
+ }
+ }
+ return $objtype
+}
+
# -- Not a normal commit type invocation? Do that instead!
#
switch -- $subcommand {
browser -
blame {
if {$subcommand eq "blame"} {
- set subcommand_args {[--line=<num>] rev? path}
+ set subcommand_args {[--line=<num>] <[rev] [--] filename | [--] filename rev>}
+ set required_objtype blob
} else {
- set subcommand_args {rev? path}
+ set subcommand_args {<[rev] [--] directory | [--] directory rev>}
+ set required_objtype tree
}
- if {$argv eq {}} usage
- set head {}
- set path {}
- set jump_spec {}
+ set maxargs [llength $subcommand_args]
set nargs [llength $argv]
- if {$nargs < 1} {
- usage
- }
- set argn 0
- foreach a $argv {
- set argn [expr {$argn + 1}]
+ if {$nargs < 1 || $nargs > $maxargs} usage
+ set head {}
+ set althead {}
+ set path {}
+ set altpath {}
+ set canswap 1
+ set jump_spec {}
- if {$argn < $nargs} {
- # revision or line number
- if {[regexp {^--line=(\d+)$} $a a lnum]} {
- set jump_spec [list $lnum]
+ # assume: [--line=num] [head] [--] path as the possible arguments, in order.
+ # head and path may need a swap later.
+ for {set iarg 0} {$iarg < $nargs} {incr iarg} {
+ set arg [lindex $argv $iarg]
+ if {$arg eq {--}} {
+ # next arg is the path, prevent or FORCE swap?
+ if {$iarg == $nargs - 2} {
+ set canswap 0
+ } elseif {$iarg == $nargs - 3} {
+ set canswap 2
} else {
- set head $a
+ usage
}
+ } elseif {[regexp {^--line=(\d+)$} $arg arg lnum]} {
+ # --line can only be the first arg
+ if {$iarg != 0 || $maxargs < 4} usage
+ set jump_spec [list $lnum]
+ } elseif {$iarg == $nargs - 1} {
+ # assume final argument is path
+ set path [normalize_relpath [file join $_prefix $arg]]
+ set althead $arg
+ } elseif {$head eq {}} {
+ # assume the other argument is head
+ set head $arg
+ set altpath [normalize_relpath [file join $_prefix $arg]]
} else {
- set path [normalize_relpath $a]
+ usage
}
}
+ # no swapping allowed if head not given, use current branch (HEAD)
if {$head eq {}} {
load_current_branch
set head $current_branch
- } else {
- if {[regexp [string map "@@ [expr $hashlength - 1]" {^[0-9a-f]{1,@@}$}] $head]} {
- if {[catch {
- set head [git rev-parse --verify $head]
- } err]} {
- if {[tk windowingsystem] eq "win32"} {
- tk_messageBox -icon error -title [mc Error] -message $err
- } else {
- puts stderr $err
- }
- exit 1
- }
+ set canswap 0
+ }
+
+ # -- before "rev" arg means we got -- path head
+ if {$canswap == 2} {
+ set head $althead
+ set path $altpath
+ set canswap 0
+ }
+
+ set objtype [find_path_type $head $path]
+ if {$objtype eq {} && $canswap} {
+ set objtype [find_path_type $althead $altpath]
+ if {$objtype ne {}} {
+ set head $althead
+ set path $altpath
}
- set current_branch $head
+ }
+ set current_branch $head
+
+ # check that path exists in head, and objtype matches need
+ if {$objtype ne $required_objtype} {
+ switch -- $required_objtype {
+ tree {set err [strcat \
+ [mc "'%s' is not a directory in rev '%s'" $path $head]]}
+ blob {set err [strcat \
+ [mc "'%s' is not a filename in rev '%s'" $path $head]]}
+ }
+ if {[tk windowingsystem] eq "win32"} {
+ catch {wm withdraw .}
+ error_popup $err
+ } else {
+ puts stderr $err
+ }
+ exit 1
}
wm deiconify .
switch -- $subcommand {
browser {
- if {$jump_spec ne {}} usage
browser::new $head $path
}
- blame {
+ blame {
blame::new $head $path $jump_spec
}
}
return
}
citool -
-gui {
+gui -
+pick {
if {[llength $argv] != 0} {
usage
}
diff --git a/lib/choose_repository.tcl b/lib/choose_repository.tcl
index 7e1462a20c..4b06afee93 100644
--- a/lib/choose_repository.tcl
+++ b/lib/choose_repository.tcl
@@ -15,7 +15,7 @@ field w_recentlist ; # Listbox containing recent repositories
field w_localpath ; # Entry widget bound to local_path
field done 0 ; # Finished picking the repository?
-field clone_ok false ; # clone succeeeded
+field pick_ok 0 ; # true if repo pick/clone succeeded
field local_path {} ; # Where this repository is locally
field origin_url {} ; # Where we are cloning from
field origin_name origin ; # What we shall call 'origin'
@@ -220,6 +220,8 @@ constructor pick {} {
if {$top eq {.}} {
eval destroy [winfo children $top]
}
+
+ return $pick_ok
}
method _center {} {
@@ -327,8 +329,7 @@ method _git_init {} {
}
_append_recentrepos [pwd]
- set ::_gitdir .git
- set ::_prefix {}
+ set pick_ok 1
return 1
}
@@ -409,6 +410,7 @@ method _do_new2 {} {
if {![_git_init $this]} {
return
}
+ set pick_ok 1
set done 1
}
@@ -621,7 +623,7 @@ method _do_clone2 {} {
}
tkwait variable @done
- if {!$clone_ok} {
+ if {!$pick_ok} {
error_popup [mc "Clone failed."]
return
}
@@ -632,18 +634,12 @@ method _do_clone2_done {ok} {
if {$ok} {
if {[catch {
cd $local_path
- set ::_gitdir .git
- set ::_prefix {}
_append_recentrepos [pwd]
} err]} {
set ok 0
}
}
- if {!$ok} {
- set ::_gitdir {}
- set ::_prefix {}
- }
- set clone_ok $ok
+ set pick_ok $ok
set done 1
}
@@ -721,8 +717,7 @@ method _do_open2 {} {
}
_append_recentrepos [pwd]
- set ::_gitdir $actualgit
- set ::_prefix {}
+ set pick_ok 1
set done 1
}
--
2.54.0.99.14
^ permalink raw reply related
* Re: [BUG] "git diff --word-diff" gives a diff while they are only space changes
From: Michael Montalbo @ 2026-05-20 20:21 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Chris Torek, Johannes Sixt, vincent, git
In-Reply-To: <xmqqo6ic8564.fsf@gitster.g>
On Mon, May 18, 2026 at 8:11 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Chris Torek <chris.torek@gmail.com> writes:
>
> > Call it an "implementation note" (or, if you like, a "practical
> > consideration"?).
> > Something along these lines might work...
> >
> > Implementation Note
> >
> > The --word-diff option currently operates by taking the same
> > line by line diff that you get without the option, then massaging
> > the result into a word-by-word difference. This may cause an
> > unnecessarily-larger diff than you would see with a more-clever
> > implementation. If and when Git acquires a more-clever
> > implementation, the output may change. Note that this is
> > similar to the --diff-algorithm option, which may change the
> > output.
> >
> > Regardless of which algorithm is used, _any_ diff simply shows
> > _a_ way to achieve some particular change. It's impossible for
> > any algorithm to tell whether someone deleted two lines and
> > then put one back exactly as it appeared earlier, saving the
> > resulting text, vs deleting a single line, for instance. Only a
> > keystroke-by-keystroke logger would be able to tell what the
> > human operator actually typed into some editor. Git does
> > not have that information, and having it is not desired.
> >
> > Chris
>
> I understand your frustration in the second paragraph ;-) but let's
> not go there. The first paragraph is excellent. It gives readers a
> clear enough explanation to understand what is happening and stop
> complaining where there is nothing to complain about (which is
> already hinted by the "Note that" at the end).
>
Thanks for the ideas, Chris. Here is my attempt at synthesizing Chris'
suggestions and Junio's feedback:
The `--word-diff` option operates by taking the same line-by-line
diff that is produced without the option and computing
word-by-word changes within each hunk. This may produce a
larger diff than a dedicated word-diff tool would. If Git
acquires a different implementation in the future, the output
may change. Note that this is similar to the `--diff-algorithm`
option, which may also change the output.
Does this work?
^ permalink raw reply
* Re: [PATCH 4/8] pack-bitmap: consolidate `find_object_pos()` success path
From: Taylor Blau @ 2026-05-20 17:12 UTC (permalink / raw)
To: SZEDER Gábor
Cc: git, Junio C Hamano, Jeff King, Elijah Newren, Derrick Stolee
In-Reply-To: <ag3IXa3lKLmQC1tD@szeder.dev>
On Wed, May 20, 2026 at 04:42:37PM +0200, SZEDER Gábor wrote:
> On Tue, May 19, 2026 at 12:12:44PM -0400, Taylor Blau wrote:
> > Both sides of `find_object_pos()` report success in the same way by
> > setting the optional `found` out-parameter and return the resolved
> > bitmap position.
> >
> > Prepare for adding more bookkeeping around object-position lookups by
> > storing the result in a local `pos` variable and sharing the success
>
> This 'pos' variable will only be declared in the next commit,
> resulting in an error building this commit:
>
> pack-bitmap-write.c: In function ‘find_object_pos’:
> pack-bitmap-write.c:227:17: error: ‘pos’ undeclared (first use in this function)
> 227 | pos = oe_in_pack_pos(writer->to_pack, entry) + base_objects;
> | ^~~
> pack-bitmap-write.c:227:17: note: each undeclared identifier is reported only once for each function it appears in
> make: *** [Makefile:2917: pack-bitmap-write.o] Error 1
Thanks for spotting. I had split the patch that immediately follows this
one into two to make the latter easier to read, but have no idea how
this snuck through.
It's fixed by declaring `pos` in this commit:
--- 8< ---
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 6483fdc7daf..42ed22feacc 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -217,6 +217,7 @@ static uint32_t find_object_pos(struct bitmap_writer *writer,
const struct object_id *oid, int *found)
{
struct object_entry *entry;
+ uint32_t pos;
entry = packlist_find(writer->to_pack, oid);
if (entry) {
--- >8 ---
, but I'll send a re-roll after the rest of the series has been
reviewed.
Thanks,
Taylor
^ permalink raw reply related
* Re: [PATCH v8] revision.c: implement --max-count-oldest
From: Mirko Faina @ 2026-05-20 16:42 UTC (permalink / raw)
To: Junio C Hamano
Cc: git, Jeff King, Jean-Noël Avila, Patrick Steinhardt,
Tian Yuchen, Ben Knoble, Johannes Sixt, Chris Torek, Mirko Faina
In-Reply-To: <xmqq7boy4o05.fsf@gitster.g>
On Wed, May 20, 2026 at 03:02:34PM +0900, Junio C Hamano wrote:
> Mirko Faina <mroik@delayed.space> writes:
>
> > --max-count is a commit limiting option sets a maximum amount of commits
> > to be shown. If a user wants to see only the first N commits of the
> > history (the oldest commits) they'd have to do something like
> >
> > git log $(git rev-list HEAD | tail -n N | head -n 1)
> >
> > This is not very user-friendly.
> >
> > Teach get_revision() the --max-count-oldest option.
> >
> > Signed-off-by: Mirko Faina <mroik@delayed.space>
> > ---
>
> This breaks CI
>
> https://github.com/git/git/actions/runs/26138986677/job/76880268854#step:4:2072
>
> Squash something like this to fix.
>
> --- >8 ---
> Subject: [PATCH] SQUASH??? test portability and other fixes
>
> * "test_when_finished" should use "rm -f", not an error-detecting
> "rm", as the execution may not have reached to the point to create
> the "actual" file it is removing.
>
> * Do not hide exit status of "git log" by piping its output into
> another process.
>
> * Do not expect output of "wc -l" is portable. macOS puts extra
> whitespaces in front, while GNU/Linux does not.
> ---
> t/t4202-log.sh | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
Sorry about that. And thank you for the fix.
^ permalink raw reply
* Re: [PATCH] commit: fall back to full read when maybe_tree is NULL
From: Derrick Stolee @ 2026-05-20 16:22 UTC (permalink / raw)
To: Jeff King, Junio C Hamano; +Cc: git, Rasmus Villemoes, Daniel Mach
In-Reply-To: <20260519061534.GA1709881@coredump.intra.peff.net>
On 5/19/2026 2:15 AM, Jeff King wrote:
> On Tue, May 19, 2026 at 02:56:51PM +0900, Junio C Hamano wrote:
>> Looks quite straight-forward. Don't you need to pay attention to
>> r->hash_algo and call parse_oid_hex_algop() instead?
>>
>> Or are we pretty much sure that "r" is always "the_repository" here,
>> in which case parse_oid_hex() that uses "the_hash_algo" would be
>> sufficient?
>
> No, I didn't even think about it, since the use of the_hash_algo is
> hidden behind the function. We definitely should use the hash algo from
> "r", since we have access to it. I'm not even sure if you can have repos
> of two different hashes loaded in the same process at this point, but
> certainly it is the correct long-term direction.
>
> Here's a re-roll with the one-line fixup:
>
> diff --git a/commit.c b/commit.c
> index cfc87ad185..499a9602ad 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -448,7 +448,7 @@ static void load_tree_from_commit_contents(struct repository *r, struct commit *
>
> if (type == OBJ_COMMIT &&
> skip_prefix(buf, "tree ", &p) &&
> - !parse_oid_hex(p, &tree_oid, &p) &&
> + !parse_oid_hex_algop(p, &tree_oid, &p, r->hash_algo) &&
> *p == '\n')
> set_commit_tree(commit, lookup_tree(r, &tree_oid));
>
I figured that this was already tested via the test variable that
runs the test with SHA256, but the multi-repo case is an interesting
one that I'm sure would catch us at some point in the future.
I'm happy with the re-roll here.
Thanks,
-Stolee
^ permalink raw reply
* Re: [PATCH] commit: fall back to full read when maybe_tree is NULL
From: Derrick Stolee @ 2026-05-20 16:20 UTC (permalink / raw)
To: Jeff King, git; +Cc: Rasmus Villemoes, Daniel Mach
In-Reply-To: <20260519050513.GA1635924@coredump.intra.peff.net>
On 5/19/2026 1:05 AM, Jeff King wrote:
> When we load a commit object from the commit graph (rather than reading
> the object contents), we don't fill in its "maybe_tree" entry, but
> rather wait to lazy-load it. This goes back to 7b8a21dba1 (commit-graph:
> lazy-load trees for commits, 2018-04-06), and saves the work of
> instantiating tree objects that nobody cares about.
>
> But it creates a data dependency: now the commit struct depends on the
> graph file to do that lazy load. This is a problem if we close the graph
> file; now we have a commit struct that claims to be parsed but is
> missing some of its data.
> Reported twice recently:
>
> - https://lore.kernel.org/git/87h5onsi0f.fsf@prevas.dk/
>
> - https://lore.kernel.org/git/6ae85515-9373-4c9e-90d2-5e4176590c5b@suse.com/
>
> I don't why we suddenly got two reports. AFAICT the bug goes back to
> 2018, though it would become more prominent as use of commit graphs
> increased.
Likely, this may have changed with the switch to using geometric
maintenance instead of gc maintenance by default in Git 2.54.0. That
perhaps increased the amount of commit-graphs being present.
> +static void load_tree_from_commit_contents(struct repository *r, struct commit *commit)
> +{
> + enum object_type type;
> + unsigned long size;
> + char *buf;
> + const char *p;
> + struct object_id tree_oid;
> +
> + buf = odb_read_object(r->objects, &commit->object.oid, &type, &size);
> + if (!buf)
> + return;
> +
> + if (type == OBJ_COMMIT &&
> + skip_prefix(buf, "tree ", &p) &&
> + !parse_oid_hex(p, &tree_oid, &p) &&
> + *p == '\n')
> + set_commit_tree(commit, lookup_tree(r, &tree_oid));
> +
> + free(buf);
> +}
> +
I like this focused parsing of the commit contents. I also briefly
considered "unparsing" the commit, but you make a good point in your
message why a focused parse here is important, especially around
munging of the parent list.
> struct tree *repo_get_commit_tree(struct repository *r,
> const struct commit *commit)
> {
> @@ -443,7 +464,17 @@ struct tree *repo_get_commit_tree(struct repository *r,
> if (commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
> return get_commit_tree_in_graph(r, commit);
>
> - return NULL;
> + /*
> + * This is either a corrupt commit, or one which we partially loaded
> + * from a graph file but then subsequently threw away the graph data.
> + *
> + * Optimistically assume it's the latter and try to reload from
> + * scratch. This gives a performance penalty if it really is a corrupt
> + * commit, but presumably that happens rarely (and only once per
> + * process).
> + */
> + load_tree_from_commit_contents(r, (struct commit *)commit);
> + return commit->maybe_tree;
> }
I agree that this is the right place to insert this logic.
> +test_expect_success 'dissociate from repo with commit graph' '
> + git init orig &&
> + # We are trying to make sure the dissociated repo can
> + # find the tree of the tip commit, so the test could still
> + # serve its purpose with an empty tree. But having actual
> + # content future-proofs us against any kind of internal
> + # empty-tree optimizations.
> + echo content >orig/file &&
> + git -C orig add . &&
> + git -C orig commit -m foo &&
> +
> + # We will use graph.git as our "local" source to dissociate
> + # from.
> + git clone --bare orig graph.git &&
> + git -C graph.git commit-graph write --reachable &&
> +
> + # And then finally clone orig, using graph.git to get our objects. This
> + # must be non-bare so that we perform the checkout step, which will
> + # need to access the tree of HEAD, which we will have originally loaded
> + # via the commit graph.
> + git clone --no-local --reference graph.git --dissociate orig clone
> +'
> +
Thanks for the clear extra coverage here.
-Stolee
^ permalink raw reply
* Re: [PATCH 4/8] pack-bitmap: consolidate `find_object_pos()` success path
From: SZEDER Gábor @ 2026-05-20 14:42 UTC (permalink / raw)
To: Taylor Blau; +Cc: git, Junio C Hamano, Jeff King, Elijah Newren, Derrick Stolee
In-Reply-To: <c9a560660949c53575a9b1e81160d25212a1f484.1779207127.git.me@ttaylorr.com>
On Tue, May 19, 2026 at 12:12:44PM -0400, Taylor Blau wrote:
> Both sides of `find_object_pos()` report success in the same way by
> setting the optional `found` out-parameter and return the resolved
> bitmap position.
>
> Prepare for adding more bookkeeping around object-position lookups by
> storing the result in a local `pos` variable and sharing the success
This 'pos' variable will only be declared in the next commit,
resulting in an error building this commit:
pack-bitmap-write.c: In function ‘find_object_pos’:
pack-bitmap-write.c:227:17: error: ‘pos’ undeclared (first use in this function)
227 | pos = oe_in_pack_pos(writer->to_pack, entry) + base_objects;
| ^~~
pack-bitmap-write.c:227:17: note: each undeclared identifier is reported only once for each function it appears in
make: *** [Makefile:2917: pack-bitmap-write.o] Error 1
> return path between the packlist and MIDX cases.
>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
> pack-bitmap-write.c | 17 ++++++++---------
> 1 file changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
> index 651ad467469..6483fdc7daf 100644
> --- a/pack-bitmap-write.c
> +++ b/pack-bitmap-write.c
> @@ -224,23 +224,22 @@ static uint32_t find_object_pos(struct bitmap_writer *writer,
> if (writer->midx)
> base_objects = writer->midx->num_objects +
> writer->midx->num_objects_in_base;
> -
> - if (found)
> - *found = 1;
> - return oe_in_pack_pos(writer->to_pack, entry) + base_objects;
> + pos = oe_in_pack_pos(writer->to_pack, entry) + base_objects;
> } else if (writer->midx) {
> - uint32_t at, pos;
> + uint32_t at;
>
> if (!bsearch_midx(oid, writer->midx, &at))
> goto missing;
> if (midx_to_pack_pos(writer->midx, at, &pos) < 0)
> goto missing;
> -
> - if (found)
> - *found = 1;
> - return pos;
> + } else {
> + goto missing;
> }
>
> + if (found)
> + *found = 1;
> + return pos;
> +
> missing:
> if (found)
> *found = 0;
> --
> 2.54.0.rc1.84.g30ce254312c
>
^ permalink raw reply
* Re: [PATCH] log: let --follow follow renames in merge commits
From: Miklos Vajna @ 2026-05-20 13:28 UTC (permalink / raw)
To: Elijah Newren, Jeff King; +Cc: git
In-Reply-To: <xmqqo6ib7vlp.fsf@gitster.g>
Hi Elijah, Jeff,
On Tue, May 19, 2026 at 03:37:54PM +0900, Junio C Hamano <gitster@pobox.com> wrote:
> > :-) Should I just wait more or should I resend this?
>
> Rather, ask other reviewers
I did a small improvement to how 'git log --follow' works, as in if the
rename happens inside the merge commit itself, then the rename was
detected "vs the first parent", but it wasn't detected "vs other
parents", which is painful with a "subtree" merge commit.
I'm not sure if it adds value, but I can append a one-paragraph summary
of Junio's comment in this thread to the end the commit message, to be
more explicit that the inherent limitation of the current log follow
design (single path, once a rename is detected, we only care about the
new path) is not changed with the patch, this is just a fix patch so
'git log' works better, similar to how 'git blame' already does.
May I ask you to review the patch?
Thanks,
Miklos
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox