Skip to content

Commit 436dad0

Browse files
committed
Merge branch 'ml/abandon-old-versions'
* ml/abandon-old-versions: git-gui: eliminate _search_exe git-gui: remove procs gitexec and _git_cmd git-gui: use dashless 'git cmd' form for read/write git-gui: default to full copy for linked worktrees git-gui: use git-clone git-gui: remove unused git-version git-gui: use git_init to create new repository dir git-gui: git-remote is always available git-gui: git merge understands --strategy=recursive git-gui: git-diff knows submodules and textconv git-gui: git-blame understands -w and textconv git-gui: git rev-parse knows show_toplevel git-gui: use git-branch --show-current git-gui: git-diff-index always knows submodules git-gui: git ls-files knows --exclude-standard git-gui: require git >= 2.36 Signed-off-by: Johannes Sixt <[email protected]>
2 parents 594810d + f4b7ad5 commit 436dad0

File tree

7 files changed

+92
-685
lines changed

7 files changed

+92
-685
lines changed

git-gui.sh

Lines changed: 33 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,8 @@ proc is_Cygwin {} {
7979

8080
if {[is_Windows]} {
8181
set _path_sep {;}
82-
set _search_exe .exe
8382
} else {
8483
set _path_sep {:}
85-
set _search_exe {}
8684
}
8785

8886
if {[is_Windows]} {
@@ -112,15 +110,15 @@ set env(PATH) [join $_search_path $_path_sep]
112110
113111
if {[is_Windows]} {
114112
proc _which {what args} {
115-
global _search_exe _search_path
113+
global _search_path
116114
117115
if {[lsearch -exact $args -script] >= 0} {
118116
set suffix {}
119-
} elseif {[string match *$_search_exe [string tolower $what]]} {
117+
} elseif {[string match *.exe [string tolower $what]]} {
120118
# The search string already has the file extension
121119
set suffix {}
122120
} else {
123-
set suffix $_search_exe
121+
set suffix .exe
124122
}
125123
126124
foreach p $_search_path {
@@ -363,7 +361,6 @@ set _appname {Git Gui}
363361
set _gitdir {}
364362
set _gitworktree {}
365363
set _isbare {}
366-
set _gitexec {}
367364
set _githtmldir {}
368365
set _reponame {}
369366
set _shellpath {@@SHELL_PATH@@}
@@ -428,20 +425,6 @@ proc gitdir {args} {
428425
return [eval [list file join $_gitdir] $args]
429426
}
430427
431-
proc gitexec {args} {
432-
global _gitexec
433-
if {$_gitexec eq {}} {
434-
if {[catch {set _gitexec [git --exec-path]} err]} {
435-
error "Git not installed?\n\n$err"
436-
}
437-
set _gitexec [file normalize $_gitexec]
438-
}
439-
if {$args eq {}} {
440-
return $_gitexec
441-
}
442-
return [eval [list file join $_gitexec] $args]
443-
}
444-
445428
proc githtmldir {args} {
446429
global _githtmldir
447430
if {$_githtmldir eq {}} {
@@ -574,56 +557,6 @@ proc _trace_exec {cmd} {
574557
575558
#'" fix poor old emacs font-lock mode
576559

577-
proc _git_cmd {name} {
578-
global _git_cmd_path
579-
580-
if {[catch {set v $_git_cmd_path($name)}]} {
581-
switch -- $name {
582-
version -
583-
--version -
584-
--exec-path { return [list $::_git $name] }
585-
}
586-
587-
set p [gitexec git-$name$::_search_exe]
588-
if {[file exists $p]} {
589-
set v [list $p]
590-
} elseif {[is_Windows] && [file exists [gitexec git-$name]]} {
591-
# Try to determine what sort of magic will make
592-
# git-$name go and do its thing, because native
593-
# Tcl on Windows doesn't know it.
594-
#
595-
set p [gitexec git-$name]
596-
set f [safe_open_file $p r]
597-
set s [gets $f]
598-
close $f
599-
600-
switch -glob -- [lindex $s 0] {
601-
#!*sh { set i sh }
602-
#!*perl { set i perl }
603-
#!*python { set i python }
604-
default { error "git-$name is not supported: $s" }
605-
}
606-
607-
upvar #0 _$i interp
608-
if {![info exists interp]} {
609-
set interp [_which $i]
610-
}
611-
if {$interp eq {}} {
612-
error "git-$name requires $i (not in PATH)"
613-
}
614-
set v [concat [list $interp] [lrange $s 1 end] [list $p]]
615-
} else {
616-
# Assume it is builtin to git somehow and we
617-
# aren't actually able to see a file for it.
618-
#
619-
set v [list $::_git $name]
620-
}
621-
set _git_cmd_path($name) $v
622-
}
623-
return $v
624-
}
625-
626-
# Run a shell command connected via pipes on stdout.
627560
# This is for use with textconv filters and uses sh -c "..." to allow it to
628561
# contain a command with arguments. We presume this
629562
# to be a shellscript that the configured shell (/bin/sh by default) knows
@@ -679,30 +612,30 @@ proc safe_open_command {cmd {redir {}}} {
679612
}
680613

681614
proc git_read {cmd {redir {}}} {
682-
set cmdp [_git_cmd [lindex $cmd 0]]
683-
set cmd [lrange $cmd 1 end]
615+
global _git
616+
set cmdp [concat [list $_git] $cmd]
684617

685-
return [safe_open_command [concat $cmdp $cmd] $redir]
618+
return [safe_open_command $cmdp $redir]
686619
}
687620

688621
proc git_read_nice {cmd} {
622+
global _git
689623
set opt [list]
690624

691625
_lappend_nice opt
692626

693-
set cmdp [_git_cmd [lindex $cmd 0]]
694-
set cmd [lrange $cmd 1 end]
627+
set cmdp [concat [list $_git] $cmd]
695628

696-
return [safe_open_command [concat $opt $cmdp $cmd]]
629+
return [safe_open_command [concat $opt $cmdp]]
697630
}
698631

699632
proc git_write {cmd} {
633+
global _git
700634
set cmd [make_arglist_safe $cmd]
701-
set cmdp [_git_cmd [lindex $cmd 0]]
702-
set cmd [lrange $cmd 1 end]
635+
set cmdp [concat [list $_git] $cmd]
703636

704-
_trace_exec [concat $cmdp $cmd]
705-
return [open [concat [list | ] $cmdp $cmd] w]
637+
_trace_exec $cmdp
638+
return [open [concat [list | ] $cmdp] w]
706639
}
707640

708641
proc githook_read {hook_name args} {
@@ -742,27 +675,8 @@ proc sq {value} {
742675
proc load_current_branch {} {
743676
global current_branch is_detached
744677

745-
set fd [safe_open_file [gitdir HEAD] r]
746-
fconfigure $fd -translation binary -encoding utf-8
747-
if {[gets $fd ref] < 1} {
748-
set ref {}
749-
}
750-
close $fd
751-
752-
set pfx {ref: refs/heads/}
753-
set len [string length $pfx]
754-
if {[string equal -length $len $pfx $ref]} {
755-
# We're on a branch. It might not exist. But
756-
# HEAD looks good enough to be a branch.
757-
#
758-
set current_branch [string range $ref $len end]
759-
set is_detached 0
760-
} else {
761-
# Assume this is a detached head.
762-
#
763-
set current_branch HEAD
764-
set is_detached 1
765-
}
678+
set current_branch [git branch --show-current]
679+
set is_detached [expr [string length $current_branch] == 0]
766680
}
767681

768682
auto_load tk_optionMenu
@@ -981,6 +895,8 @@ if {$_git eq {}} {
981895
##
982896
## version check
983897

898+
set MIN_GIT_VERSION 2.36
899+
984900
if {[catch {set _git_version [git --version]} err]} {
985901
catch {wm withdraw .}
986902
tk_messageBox \
@@ -991,9 +907,10 @@ if {[catch {set _git_version [git --version]} err]} {
991907
992908
$err
993909
994-
[appname] requires Git 1.5.0 or later."
910+
[appname] requires Git $MIN_GIT_VERSION or later."
995911
exit 1
996912
}
913+
997914
if {![regsub {^git version } $_git_version {} _git_version]} {
998915
catch {wm withdraw .}
999916
tk_messageBox \
@@ -1018,85 +935,21 @@ proc get_trimmed_version {s} {
1018935
set _real_git_version $_git_version
1019936
set _git_version [get_trimmed_version $_git_version]
1020937

1021-
if {![regexp {^[1-9]+(\.[0-9]+)+$} $_git_version]} {
1022-
catch {wm withdraw .}
1023-
if {[tk_messageBox \
1024-
-icon warning \
1025-
-type yesno \
1026-
-default no \
1027-
-title "[appname]: warning" \
1028-
-message [mc "Git version cannot be determined.
1029-
1030-
%s claims it is version '%s'.
938+
if {[catch {set vcheck [package vcompare $_git_version $MIN_GIT_VERSION]}] ||
939+
[expr $vcheck < 0] } {
1031940

1032-
%s requires at least Git 1.5.0 or later.
1033-
1034-
Assume '%s' is version 1.5.0?
1035-
" $_git $_real_git_version [appname] $_real_git_version]] eq {yes}} {
1036-
set _git_version 1.5.0
1037-
} else {
1038-
exit 1
1039-
}
1040-
}
1041-
unset _real_git_version
1042-
1043-
proc git-version {args} {
1044-
global _git_version
1045-
1046-
switch [llength $args] {
1047-
0 {
1048-
return $_git_version
1049-
}
1050-
1051-
2 {
1052-
set op [lindex $args 0]
1053-
set vr [lindex $args 1]
1054-
set cm [package vcompare $_git_version $vr]
1055-
return [expr $cm $op 0]
1056-
}
1057-
1058-
4 {
1059-
set type [lindex $args 0]
1060-
set name [lindex $args 1]
1061-
set parm [lindex $args 2]
1062-
set body [lindex $args 3]
1063-
1064-
if {($type ne {proc} && $type ne {method})} {
1065-
error "Invalid arguments to git-version"
1066-
}
1067-
if {[llength $body] < 2 || [lindex $body end-1] ne {default}} {
1068-
error "Last arm of $type $name must be default"
1069-
}
1070-
1071-
foreach {op vr cb} [lrange $body 0 end-2] {
1072-
if {[git-version $op $vr]} {
1073-
return [uplevel [list $type $name $parm $cb]]
1074-
}
1075-
}
1076-
1077-
return [uplevel [list $type $name $parm [lindex $body end]]]
1078-
}
1079-
1080-
default {
1081-
error "git-version >= x"
1082-
}
1083-
1084-
}
1085-
}
1086-
1087-
if {[git-version < 1.5]} {
941+
set msg1 [mc "Insufficient git version, require: "]
942+
set msg2 [mc "git returned:"]
943+
set message "$msg1 $MIN_GIT_VERSION\n$msg2 $_real_git_version"
1088944
catch {wm withdraw .}
1089945
tk_messageBox \
1090946
-icon error \
1091947
-type ok \
1092948
-title [mc "git-gui: fatal error"] \
1093-
-message "[appname] requires Git 1.5.0 or later.
1094-
1095-
You are using [git-version]:
1096-
1097-
[git --version]"
949+
-message $message
1098950
exit 1
1099951
}
952+
unset _real_git_version
1100953

1101954
######################################################################
1102955
##
@@ -1261,7 +1114,7 @@ citool {
12611114

12621115
# Suggest our implementation of askpass, if none is set
12631116
if {![info exists env(SSH_ASKPASS)]} {
1264-
set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1117+
set env(SSH_ASKPASS) [file join [git --exec-path] git-gui--askpass]
12651118
}
12661119

12671120
######################################################################
@@ -1282,6 +1135,9 @@ if {[catch {
12821135
load_config 1
12831136
apply_config
12841137
choose_repository::pick
1138+
if {![file isdirectory $_gitdir]} {
1139+
exit 1
1140+
}
12851141
set picked 1
12861142
}
12871143

@@ -1312,20 +1168,7 @@ if {![file isdirectory $_gitdir]} {
13121168
load_config 0
13131169
apply_config
13141170

1315-
# v1.7.0 introduced --show-toplevel to return the canonical work-tree
1316-
if {[package vcompare $_git_version 1.7.0] >= 0} {
1317-
set _gitworktree [git rev-parse --show-toplevel]
1318-
} else {
1319-
# try to set work tree from environment, core.worktree or use
1320-
# cdup to obtain a relative path to the top of the worktree. If
1321-
# run from the top, the ./ prefix ensures normalize expands pwd.
1322-
if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {
1323-
set _gitworktree [get_config core.worktree]
1324-
if {$_gitworktree eq ""} {
1325-
set _gitworktree [file normalize ./[git rev-parse --show-cdup]]
1326-
}
1327-
}
1328-
}
1171+
set _gitworktree [git rev-parse --show-toplevel]
13291172

13301173
if {$_prefix ne {}} {
13311174
if {$_gitworktree eq {}} {
@@ -1551,30 +1394,15 @@ proc rescan_stage2 {fd after} {
15511394
close $fd
15521395
}
15531396

1554-
if {[package vcompare $::_git_version 1.6.3] >= 0} {
1555-
set ls_others [list --exclude-standard]
1556-
} else {
1557-
set ls_others [list --exclude-per-directory=.gitignore]
1558-
if {[have_info_exclude]} {
1559-
lappend ls_others "--exclude-from=[gitdir info exclude]"
1560-
}
1561-
set user_exclude [get_config core.excludesfile]
1562-
if {$user_exclude ne {} && [file readable $user_exclude]} {
1563-
lappend ls_others "--exclude-from=[file normalize $user_exclude]"
1564-
}
1565-
}
1397+
set ls_others [list --exclude-standard]
15661398

15671399
set buf_rdi {}
15681400
set buf_rdf {}
15691401
set buf_rlo {}
15701402

15711403
set rescan_active 2
15721404
ui_status [mc "Scanning for modified files ..."]
1573-
if {[git-version >= "1.7.2"]} {
1574-
set fd_di [git_read [list diff-index --cached --ignore-submodules=dirty -z [PARENT]]]
1575-
} else {
1576-
set fd_di [git_read [list diff-index --cached -z [PARENT]]]
1577-
}
1405+
set fd_di [git_read [list diff-index --cached --ignore-submodules=dirty -z [PARENT]]]
15781406
set fd_df [git_read [list diff-files -z]]
15791407

15801408
fconfigure $fd_di -blocking 0 -translation binary -encoding binary

lib/about.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ proc do_about {} {
4444

4545
set d {}
4646
append d "git wrapper: $::_git\n"
47-
append d "git exec dir: [gitexec]\n"
47+
append d "git exec dir: [git --exec-path]\n"
4848
append d "git-gui lib: $oguilib"
4949

5050
paddedlabel $w.vers -text $v

0 commit comments

Comments
 (0)