@@ -122,6 +122,14 @@ set _reponame {}
122122set _iscygwin {}
123123set _search_path {}
124124
125+ set _trace [lsearch -exact $argv --trace]
126+ if {$_trace >= 0} {
127+ set argv [lreplace $argv $_trace $_trace ]
128+ set _trace 1
129+ } else {
130+ set _trace 0
131+ }
132+
125133proc appname {} {
126134 global _appname
127135 return $_appname
@@ -245,6 +253,21 @@ proc get_config {name} {
245253# #
246254# # handy utils
247255
256+ proc _trace_exec {cmd} {
257+ if {!$::_trace } return
258+ set d {}
259+ foreach v $cmd {
260+ if {$d ne {}} {
261+ append d { }
262+ }
263+ if {[regexp {[ \t\r\n'"$?*]} $v ]} {
264+ set v [sq $v ]
265+ }
266+ append d $v
267+ }
268+ puts stderr $d
269+ }
270+
248271proc _git_cmd {name} {
249272 global _git_cmd_path
250273
@@ -339,7 +362,7 @@ proc _lappend_nice {cmd_var} {
339362}
340363
341364proc git {args} {
342- set opt [ list exec ]
365+ set opt [ list ]
343366
344367 while {1} {
345368 switch -- [ lindex $args 0] {
@@ -359,12 +382,18 @@ proc git {args} {
359382 set cmdp [ _git_cmd [lindex $args 0] ]
360383 set args [ lrange $args 1 end]
361384
362- return [ eval $opt $cmdp $args ]
385+ _trace_exec [ concat $opt $cmdp $args ]
386+ set result [ eval exec $opt $cmdp $args ]
387+ if {$::_trace } {
388+ puts stderr " < $result "
389+ }
390+ return $result
363391}
364392
365393proc _open_stdout_stderr {cmd} {
394+ _trace_exec $cmd
366395 if {[ catch {
367- set fd [open $cmd r]
396+ set fd [open [ concat [ list | ] $cmd ] r]
368397 } err]} {
369398 if { [ lindex $cmd end] eq {2>@1}
370399 && $err eq {can not find channel named " 1" }
@@ -375,6 +404,7 @@ proc _open_stdout_stderr {cmd} {
375404 # to try to start it a second time.
376405 #
377406 set fd [ open [concat \
407+ [list | ] \
378408 [ lrange $cmd 0 end-1] \
379409 [ list |& cat] \
380410 ] r]
@@ -387,7 +417,7 @@ proc _open_stdout_stderr {cmd} {
387417}
388418
389419proc git_read {args} {
390- set opt [ list | ]
420+ set opt [ list ]
391421
392422 while {1} {
393423 switch -- [ lindex $args 0] {
@@ -415,7 +445,7 @@ proc git_read {args} {
415445}
416446
417447proc git_write {args} {
418- set opt [ list | ]
448+ set opt [ list ]
419449
420450 while {1} {
421451 switch -- [ lindex $args 0] {
@@ -435,7 +465,8 @@ proc git_write {args} {
435465 set cmdp [ _git_cmd [lindex $args 0] ]
436466 set args [ lrange $args 1 end]
437467
438- return [ open [concat $opt $cmdp $args ] w]
468+ _trace_exec [ concat $opt $cmdp $args ]
469+ return [ open [concat [list | ] $opt $cmdp $args ] w]
439470}
440471
441472proc githook_read {hook_name args} {
@@ -455,12 +486,12 @@ proc githook_read {hook_name args} {
455486 }
456487
457488 set scr {if test -x " $1 " ;then exec " $@" ;fi}
458- set sh_c [ list | $interp -c $scr $interp $pchook ]
489+ set sh_c [ list $interp -c $scr $interp $pchook ]
459490 return [ _open_stdout_stderr [concat $sh_c $args ] ]
460491 }
461492
462493 if {[ file executable $pchook ] } {
463- return [ _open_stdout_stderr [concat [list | $pchook ] $args ]]
494+ return [ _open_stdout_stderr [concat [list $pchook ] $args ]]
464495 }
465496
466497 return {}
@@ -1096,27 +1127,18 @@ proc rescan {after {honor_trustmtime 1}} {
10961127}
10971128
10981129if {[ is_Cygwin] } {
1099- set is_git_info_link {}
11001130 set is_git_info_exclude {}
11011131 proc have_info_exclude {} {
1102- global is_git_info_link is_git_info_exclude
1103-
1104- if {$is_git_info_link eq {}} {
1105- set is_git_info_link [ file isfile [gitdir info.lnk] ]
1106- }
1132+ global is_git_info_exclude
11071133
1108- if {$is_git_info_link } {
1109- if {$is_git_info_exclude eq {}} {
1110- if {[ catch {exec test -f [gitdir info exclude] }]} {
1111- set is_git_info_exclude 0
1112- } else {
1113- set is_git_info_exclude 1
1114- }
1134+ if {$is_git_info_exclude eq {}} {
1135+ if {[ catch {exec test -f [gitdir info exclude] }]} {
1136+ set is_git_info_exclude 0
1137+ } else {
1138+ set is_git_info_exclude 1
11151139 }
1116- return $is_git_info_exclude
1117- } else {
1118- return [ file readable [gitdir info exclude] ]
11191140 }
1141+ return $is_git_info_exclude
11201142 }
11211143} else {
11221144 proc have_info_exclude {} {
0 commit comments