git-gui: Additional early feature development.
* Run refresh before diff-index. * Load saved commit message during rescan. * Save current commit message (if any) during quit. * Add Signed-off-by line to commit buffer. * Batch update-index invocations through --stdin. * Better highlight which file is in the diff viewer. * Key bindings for signoff, check-in all and commit. * Improved formatting of status table within source. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 6, 2006 at 16:07 UTC
131f503b7262b001eae434182feb08cb5e6fa4be
1 file changed
+214
-56
git-gui
+214
-56
@@ -13,16 +13,30 @@ exec wish "$0" -- "$@"
13
## status
14
15
set status_active 0
16
+set diff_active 0
17
+set checkin_active 0
18
+set update_index_fd {}
19
+
20
+proc is_busy {} {
21
+ global status_active diff_active checkin_active update_index_fd
22
+
23
+ if {$status_active > 0
24
+ || $diff_active
25
+ || $checkin_active
26
+ || $update_index_fd != {}} {
27
+ return 1
28
+ }
29
+ return 0
30
+}
31
32
proc update_status {} {
33
global gitdir HEAD commit_type
19
- global ui_index ui_other ui_status_value
34
+ global ui_index ui_other ui_status_value ui_comm
35
global status_active file_states
36
22
- if {$status_active > 0} return
37
+ if {[is_busy]} return
38
39
array unset file_states
25
- set ui_status_value {Refreshing file status...}
40
foreach w [list $ui_index $ui_other] {
41
$w conf -state normal
42
$w delete 0.0 end
@@ -35,6 +49,31 @@ proc update_status {} {
49
set commit_type normal
50
}
51
52
+ if {![$ui_comm edit modified]
53
+ || [string trim [$ui_comm get 0.0 end]] == {}} {
54
+ if {[load_message GITGUI_MSG]} {
55
+ } elseif {[load_message MERGE_MSG]} {
56
+ } elseif {[load_message SQUASH_MSG]} {
57
+ }
58
+ $ui_comm edit modified false
59
+ }
60
+
61
+ set status_active 1
62
+ set ui_status_value {Refreshing file status...}
63
+ set fd_rf [open "| git update-index -q --unmerged --refresh" r]
64
+ fconfigure $fd_rf -blocking 0 -translation binary
65
+ fileevent $fd_rf readable [list read_refresh $fd_rf]
66
+}
67
+
68
+proc read_refresh {fd} {
69
+ global gitdir HEAD commit_type
70
+ global ui_index ui_other ui_status_value ui_comm
71
+ global status_active file_states
72
+
73
+ read $fd
74
+ if {![eof $fd]} return
75
+ close $fd
76
+
77
set ls_others [list | git ls-files --others -z \
78
--exclude-per-directory=.gitignore]
79
set info_exclude [file join $gitdir info exclude]
@@ -42,10 +81,11 @@ proc update_status {} {
81
lappend ls_others "--exclude-from=$info_exclude"
82
}
83
84
+ set status_active 3
85
+ set ui_status_value {Scanning for modified files ...}
86
set fd_di [open "| git diff-index --cached -z $HEAD" r]
87
set fd_df [open "| git diff-files -z" r]
88
set fd_lo [open $ls_others r]
48
- set status_active 3
89
90
fconfigure $fd_di -blocking 0 -translation binary
91
fconfigure $fd_df -blocking 0 -translation binary
@@ -55,6 +95,23 @@ proc update_status {} {
95
fileevent $fd_lo readable [list read_ls_others $fd_lo]
96
}
97
98
+proc load_message {file} {
99
+ global gitdir ui_comm
100
+
101
+ set f [file join $gitdir $file]
102
+ if {[file exists $f]} {
103
+ if {[catch {set fd [open $f r]}]} {
104
+ return 0
105
+ }
106
+ set content [read $fd]
107
+ close $fd
108
+ $ui_comm delete 0.0 end
109
+ $ui_comm insert end $content
110
+ return 1
111
+ }
112
+ return 0
113
+}
114
+
115
proc read_diff_index {fd} {
116
global buf_rdi
117
@@ -115,8 +172,6 @@ proc status_eof {fd buf} {
172
##
173
## diff
174
118
-set diff_active 0
119
-
175
proc clear_diff {} {
176
global ui_diff ui_fname_value ui_fstatus_value
177
@@ -128,11 +183,10 @@ proc clear_diff {} {
183
}
184
185
proc show_diff {path} {
131
- global file_states HEAD status_active diff_3way diff_active
186
+ global file_states HEAD diff_3way diff_active
187
global ui_diff ui_fname_value ui_fstatus_value ui_status_value
188
134
- if {$status_active > 0} return
135
- if {$diff_active} return
189
+ if {[is_busy]} return
190
191
clear_diff
192
set s $file_states($path)
@@ -156,6 +210,7 @@ proc show_diff {path} {
210
set content [read $fd]
211
close $fd
212
} err ]} {
213
+ set diff_active 0
214
set ui_status_value "Unable to display $path"
215
error_popup "Error loading file:\n$err"
216
return
@@ -168,12 +223,13 @@ proc show_diff {path} {
223
}
224
225
if {[catch {set fd [open $cmd r]} err]} {
226
+ set diff_active 0
227
set ui_status_value "Unable to display $path"
228
error_popup "Error loading diff:\n$err"
229
return
230
}
231
176
- fconfigure $fd -blocking 0
232
+ fconfigure $fd -blocking 0 -translation binary
233
fileevent $fd readable [list read_diff $fd]
234
}
235
@@ -353,6 +409,32 @@ proc display_file {path state} {
409
}
410
}
411
412
+proc with_update_index {body} {
413
+ global update_index_fd
414
+
415
+ if {$update_index_fd == {}} {
416
+ set update_index_fd [open \
417
+ "| git update-index --add --remove -z --stdin" \
418
+ w]
419
+ fconfigure $update_index_fd -translation binary
420
+ uplevel 1 $body
421
+ close $update_index_fd
422
+ set update_index_fd {}
423
+ } else {
424
+ uplevel 1 $body
425
+ }
426
+}
427
+
428
+proc update_index {path} {
429
+ global update_index_fd
430
+
431
+ if {$update_index_fd == {}} {
432
+ error {not in with_update_index}
433
+ } else {
434
+ puts -nonewline $update_index_fd "$path\0"
435
+ }
436
+}
437
+
438
proc toggle_mode {path} {
439
global file_states
440
@@ -361,27 +443,14 @@ proc toggle_mode {path} {
443
444
switch -- $m {
445
AM -
364
- _O {
365
- set new A*
366
- set cmd [list exec git update-index --add $path]
367
- }
368
- MM {
369
- set new M*
370
- set cmd [list exec git update-index $path]
371
- }
372
- _D {
373
- set new D*
374
- set cmd [list exec git update-index --remove $path]
375
- }
376
- default {
377
- return
378
- }
446
+ _O {set new A*}
447
+ _M -
448
+ MM {set new M*}
449
+ _D {set new D*}
450
+ default {return}
451
}
452
381
- if {[catch {eval $cmd} err]} {
382
- error_popup "Error processing file:\n$err"
383
- return
384
- }
453
+ with_update_index {update_index $path}
454
display_file $path $new
455
}
456
@@ -416,10 +485,10 @@ static unsigned char mod_bits[] = {
485
0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
486
} -maskdata $filemask
487
419
-image create bitmap file_tick -background white -foreground "#007000" -data {
420
-#define file_tick_width 14
421
-#define file_tick_height 15
422
-static unsigned char file_tick_bits[] = {
488
+image create bitmap file_fulltick -background white -foreground "#007000" -data {
489
+#define file_fulltick_width 14
490
+#define file_fulltick_height 15
491
+static unsigned char file_fulltick_bits[] = {
492
0xfe, 0x01, 0x02, 0x1a, 0x02, 0x0c, 0x02, 0x0c, 0x02, 0x16, 0x02, 0x16,
493
0x02, 0x13, 0x00, 0x13, 0x86, 0x11, 0x8c, 0x11, 0xd8, 0x10, 0xf2, 0x10,
494
0x62, 0x10, 0x02, 0x10, 0xfe, 0x1f};
@@ -461,27 +530,31 @@ static unsigned char file_merge_bits[] = {
530
0xfa, 0x17, 0x02, 0x10, 0xfe, 0x1f};
531
} -maskdata $filemask
532
533
+set max_status_desc 0
534
foreach i {
465
- {__ i "Unmodified" plain}
466
- {_M i "Modified" mod}
467
- {M_ i "Checked in" tick}
468
- {MM i "Partially checked in" parttick}
469
-
470
- {_O o "Untracked" plain}
471
- {A_ o "Added" tick}
472
- {AM o "Partially added" parttick}
473
-
474
- {_D i "Missing" question}
475
- {D_ i "Removed" removed}
476
- {DD i "Removed" removed}
477
- {DO i "Partially removed" removed}
478
-
479
- {UM i "Merge conflicts" merge}
480
- {U_ i "Merge conflicts" merge}
535
+ {__ i plain "Unmodified"}
536
+ {_M i mod "Modified"}
537
+ {M_ i fulltick "Checked in"}
538
+ {MM i parttick "Partially checked in"}
539
+
540
+ {_O o plain "Untracked"}
541
+ {A_ o fulltick "Added"}
542
+ {AM o parttick "Partially added"}
543
+
544
+ {_D i question "Missing"}
545
+ {D_ i removed "Removed"}
546
+ {DD i removed "Removed"}
547
+ {DO i removed "Removed (still exists)"}
548
+
549
+ {UM i merge "Merge conflicts"}
550
+ {U_ i merge "Merge conflicts"}
551
} {
552
+ if {$max_status_desc < [string length [lindex $i 3]]} {
553
+ set max_status_desc [string length [lindex $i 3]]
554
+ }
555
set all_cols([lindex $i 0]) [lindex $i 1]
483
- set all_descs([lindex $i 0]) [lindex $i 2]
484
- set all_icons([lindex $i 0]) file_[lindex $i 3]
556
+ set all_icons([lindex $i 0]) file_[lindex $i 2]
557
+ set all_descs([lindex $i 0]) [lindex $i 3]
558
}
559
unset filemask i
560
@@ -521,6 +594,20 @@ proc do_gitk {} {
594
}
595
596
proc do_quit {} {
597
+ global gitdir ui_comm
598
+
599
+ set save [file join $gitdir GITGUI_MSG]
600
+ if {[$ui_comm edit modified]
601
+ && [string trim [$ui_comm get 0.0 end]] != {}} {
602
+ catch {
603
+ set fd [open $save w]
604
+ puts $fd [string trim [$ui_comm get 0.0 end]]
605
+ close $fd
606
+ }
607
+ } elseif {[file exists $save]} {
608
+ file delete $save
609
+ }
610
+
611
destroy .
612
}
613
@@ -528,9 +615,52 @@ proc do_rescan {} {
615
update_status
616
}
617
618
+proc do_checkin_all {} {
619
+ global checkin_active ui_status_value
620
+
621
+ if {[is_busy]} return
622
+
623
+ set checkin_active 1
624
+ set ui_status_value {Checking in all files...}
625
+ after 1 {
626
+ with_update_index {
627
+ foreach path [array names file_states] {
628
+ set s $file_states($path)
629
+ set m [lindex $s 0]
630
+ switch -- $m {
631
+ AM -
632
+ MM -
633
+ _M -
634
+ _D {toggle_mode $path}
635
+ }
636
+ }
637
+ }
638
+ set checkin_active 0
639
+ set ui_status_value {Ready.}
640
+ }
641
+}
642
+
643
+proc do_signoff {} {
644
+ global ui_comm
645
+
646
+ catch {
647
+ set me [exec git var GIT_COMMITTER_IDENT]
648
+ if {[regexp {(.*) [0-9]+ [-+0-9]+$} $me me name]} {
649
+ set str "Signed-off-by: $name"
650
+ if {[$ui_comm get {end -1c linestart} {end -1c}] != $str} {
651
+ $ui_comm insert end "\n"
652
+ $ui_comm insert end $str
653
+ $ui_comm see end
654
+ }
655
+ }
656
+ }
657
+}
658
+
659
# shift == 1: left click
660
# 3: right click
661
proc click {w x y shift wx wy} {
662
+ global ui_index ui_other
663
+
664
set pos [split [$w index @$x,$y] .]
665
set lno [lindex $pos 0]
666
set col [lindex $pos 1]
@@ -538,6 +668,9 @@ proc click {w x y shift wx wy} {
668
if {$path == {}} return
669
670
if {$col > 0 && $shift == 1} {
671
+ $ui_index tag remove in_diff 0.0 end
672
+ $ui_other tag remove in_diff 0.0 end
673
+ $w tag add in_diff $lno.0 [expr $lno + 1].0
674
show_diff $path
675
}
676
}
@@ -549,7 +682,7 @@ proc unclick {w x y} {
682
set path [$w get $lno.1 $lno.end]
683
if {$path == {}} return
684
552
- if {$col == 0} {
685
+ if {$col == 0 && ![is_busy]} {
686
toggle_mode $path
687
}
688
}
@@ -584,6 +717,15 @@ menu .mbar.commit
717
.mbar.commit add command -label Rescan \
718
-command do_rescan \
719
-font $mainfont
720
+.mbar.commit add command -label {Check-in All Files} \
721
+ -command do_checkin_all \
722
+ -font $mainfont
723
+.mbar.commit add command -label {Sign Off} \
724
+ -command do_signoff \
725
+ -font $mainfont
726
+.mbar.commit add command -label Commit \
727
+ -command do_commit \
728
+ -font $mainfont
729
730
# -- Fetch Menu
731
menu .mbar.fetch
@@ -633,10 +775,13 @@ pack .vpane.files.other.sb -side right -fill y
775
pack $ui_other -side left -fill both -expand 1
776
.vpane.files add .vpane.files.other -sticky nsew
777
778
+$ui_index tag conf in_diff -font [concat $mainfont bold]
779
+$ui_other tag conf in_diff -font [concat $mainfont bold]
780
+
781
# -- Diff Header
782
set ui_fname_value {}
783
set ui_fstatus_value {}
639
-frame .vpane.diff -height 100 -width 100
784
+frame .vpane.diff -height 50 -width 400
785
frame .vpane.diff.header
786
label .vpane.diff.header.l1 -text {File:} -font $mainfont
787
label .vpane.diff.header.l2 -textvariable ui_fname_value \
@@ -645,7 +790,7 @@ label .vpane.diff.header.l2 -textvariable ui_fname_value \
790
-font $mainfont
791
label .vpane.diff.header.l3 -text {Status:} -font $mainfont
792
label .vpane.diff.header.l4 -textvariable ui_fstatus_value \
648
- -width 20 \
793
+ -width $max_status_desc \
794
-anchor w \
795
-justify left \
796
-font $mainfont
@@ -658,7 +803,7 @@ pack .vpane.diff.header.l3 -side right
803
frame .vpane.diff.body
804
set ui_diff .vpane.diff.body.t
805
text $ui_diff -background white -borderwidth 0 \
661
- -width 40 -height 20 \
806
+ -width 80 -height 15 \
807
-font $difffont \
808
-xscrollcommand {.vpane.diff.body.sbx set} \
809
-yscrollcommand {.vpane.diff.body.sby set} \
@@ -693,19 +838,27 @@ label .vpane.commarea.buttons.l -text {} \
838
-justify left \
839
-font $mainfont
840
pack .vpane.commarea.buttons.l -side top -fill x
841
+pack .vpane.commarea.buttons -side left -fill y
842
+
843
button .vpane.commarea.buttons.rescan -text {Rescan} \
844
-command do_rescan \
845
-font $mainfont
846
pack .vpane.commarea.buttons.rescan -side top -fill x
847
+
848
button .vpane.commarea.buttons.ciall -text {Check-in All} \
849
-command do_checkin_all \
850
-font $mainfont
851
pack .vpane.commarea.buttons.ciall -side top -fill x
852
+
853
+button .vpane.commarea.buttons.signoff -text {Sign Off} \
854
+ -command do_signoff \
855
+ -font $mainfont
856
+pack .vpane.commarea.buttons.signoff -side top -fill x
857
+
858
button .vpane.commarea.buttons.commit -text {Commit} \
859
-command do_commit \
860
-font $mainfont
861
pack .vpane.commarea.buttons.commit -side top -fill x
708
-pack .vpane.commarea.buttons -side left -fill y
862
863
# -- Commit Message Buffer
864
frame .vpane.commarea.buffer
@@ -741,6 +894,11 @@ bind . <Destroy> do_quit
894
bind . <Key-F5> do_rescan
895
bind . <M1-Key-r> do_rescan
896
bind . <M1-Key-R> do_rescan
897
+bind . <M1-Key-s> do_signoff
898
+bind . <M1-Key-S> do_signoff
899
+bind . <M1-Key-u> do_checkin_all
900
+bind . <M1-Key-U> do_checkin_all
901
+bind . <M1-Key-Return> do_commit
902
bind . <M1-Key-q> do_quit
903
bind . <M1-Key-Q> do_quit
904
foreach i [list $ui_index $ui_other] {