aboutsummaryrefslogtreecommitdiff
path: root/git-gui/lib
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2008-09-25 08:41:07 -0700
committerShawn O. Pearce <spearce@spearce.org>2008-09-25 08:41:07 -0700
commit1500f7bc1366e71edb7e8a31f3cf5614e9591cc2 (patch)
tree350805ff81d52e8c3a0eb0c8d71ae78662969664 /git-gui/lib
parentc9c6cc8d7db312b9e8502f8d55422b8309cde2f3 (diff)
parent3e34838caf796e67c057a136d1fdfe1d4286a003 (diff)
downloadgit-1500f7bc1366e71edb7e8a31f3cf5614e9591cc2.tar.gz
git-1500f7bc1366e71edb7e8a31f3cf5614e9591cc2.tar.xz
Merge git://repo.or.cz/git-gui
* git://repo.or.cz/git-gui: git-gui: Reenable staging unmerged files by clicking the icon. git-gui: Support the encoding menu in gui blame. git-gui: Optimize encoding name resolution using a lookup table. git-gui: Allow forcing display encoding for diffs using a submenu. git-gui: Add a menu of available encodings. git-gui: Cleanup handling of the default encoding. git-gui: Assume `blame --incremental` output is in UTF-8 git-gui: Use gitattribute "encoding" for file content display git-gui: Add support for calling out to the prepare-commit-msg hook git-gui: Hide commit related UI during citool --nocommit git-gui: Add more integration options to citool. git-gui: Updated German translation. git-gui: I18n fix sentence parts into full sentences for translation again. git-gui: Restore ability to Stage Working Copy for conflicts. git-gui: Fix Blame Parent & Context for working copy lines.
Diffstat (limited to 'git-gui/lib')
-rw-r--r--git-gui/lib/blame.tcl59
-rw-r--r--git-gui/lib/commit.tcl8
-rw-r--r--git-gui/lib/diff.tcl75
-rw-r--r--git-gui/lib/encoding.tcl250
-rw-r--r--git-gui/lib/mergetool.tcl39
-rw-r--r--git-gui/lib/option.tcl35
6 files changed, 395 insertions, 71 deletions
diff --git a/git-gui/lib/blame.tcl b/git-gui/lib/blame.tcl
index 827c85d67..eb61374d2 100644
--- a/git-gui/lib/blame.tcl
+++ b/git-gui/lib/blame.tcl
@@ -256,9 +256,16 @@ constructor new {i_commit i_path i_jump} {
$w.ctxm add command \
-label [mc "Copy Commit"] \
-command [cb _copycommit]
+ $w.ctxm add separator
+ menu $w.ctxm.enc
+ build_encoding_menu $w.ctxm.enc [cb _setencoding]
+ $w.ctxm add cascade \
+ -label [mc "Encoding"] \
+ -menu $w.ctxm.enc
$w.ctxm add command \
-label [mc "Do Full Copy Detection"] \
-command [cb _fullcopyblame]
+ $w.ctxm add separator
$w.ctxm add command \
-label [mc "Show History Context"] \
-command [cb _gitkcommit]
@@ -399,7 +406,10 @@ method _load {jump} {
} else {
set fd [git_read cat-file blob "$commit:$path"]
}
- fconfigure $fd -blocking 0 -translation lf -encoding binary
+ fconfigure $fd \
+ -blocking 0 \
+ -translation lf \
+ -encoding [get_path_encoding $path]
fileevent $fd readable [cb _read_file $fd $jump]
set current_fd $fd
}
@@ -508,7 +518,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
}
lappend options -- $path
set fd [eval git_read --nice blame $options]
- fconfigure $fd -blocking 0 -translation lf -encoding binary
+ fconfigure $fd -blocking 0 -translation lf -encoding utf-8
fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
set current_fd $fd
set blame_lines 0
@@ -788,6 +798,16 @@ method _click {cur_w pos} {
_showcommit $this $cur_w $lno
}
+method _setencoding {enc} {
+ force_path_encoding $path $enc
+ _load $this [list \
+ $highlight_column \
+ $highlight_line \
+ [lindex [$w_file xview] 0] \
+ [lindex [$w_file yview] 0] \
+ ]
+}
+
method _load_commit {cur_w cur_d pos} {
upvar #0 $cur_d line_data
set lno [lindex [split [$cur_w index $pos] .] 0]
@@ -881,12 +901,6 @@ method _showcommit {cur_w lno} {
set enc [tcl_encoding $enc]
if {$enc ne {}} {
set msg [encoding convertfrom $enc $msg]
- set author_name [encoding convertfrom $enc $author_name]
- set committer_name [encoding convertfrom $enc $committer_name]
- set header($cmit,author) $author_name
- set header($cmit,committer) $committer_name
- set header($cmit,summary) \
- [encoding convertfrom $enc $header($cmit,summary)]
}
set msg [string trim $msg]
}
@@ -942,9 +956,20 @@ method _format_offset_date {base offset} {
}
method _gitkcommit {} {
+ global nullid
+
set dat [_get_click_amov_info $this]
if {$dat ne {}} {
set cmit [lindex $dat 0]
+
+ # If the line belongs to the working copy, use HEAD instead
+ if {$cmit eq $nullid} {
+ if {[catch {set cmit [git rev-parse --verify HEAD]} err]} {
+ error_popup [strcat [mc "Cannot find HEAD commit:"] "\n\n$err"]
+ return;
+ }
+ }
+
set radius [get_config gui.blamehistoryctx]
set cmdline [list --select-commit=$cmit]
@@ -981,12 +1006,20 @@ method _gitkcommit {} {
}
method _blameparent {} {
+ global nullid
+
set dat [_get_click_amov_info $this]
if {$dat ne {}} {
set cmit [lindex $dat 0]
set new_path [lindex $dat 1]
- if {[catch {set cparent [git rev-parse --verify "$cmit^"]}]} {
+ # Allow using Blame Parent on lines modified in the working copy
+ if {$cmit eq $nullid} {
+ set parent_ref "HEAD"
+ } else {
+ set parent_ref "$cmit^"
+ }
+ if {[catch {set cparent [git rev-parse --verify $parent_ref]} err]} {
error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
return;
}
@@ -996,8 +1029,12 @@ method _blameparent {} {
# Generate a diff between the commit and its parent,
# and use the hunks to update the line number.
# Request zero context to simplify calculations.
- if {[catch {set fd [eval git_read diff-tree \
- --unified=0 $cparent $cmit $new_path]} err]} {
+ if {$cmit eq $nullid} {
+ set diffcmd [list diff-index --unified=0 $cparent -- $new_path]
+ } else {
+ set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
+ }
+ if {[catch {set fd [eval git_read $diffcmd]} err]} {
$status stop [mc "Unable to display parent"]
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
return
diff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl
index 297731562..334514996 100644
--- a/git-gui/lib/commit.tcl
+++ b/git-gui/lib/commit.tcl
@@ -168,7 +168,7 @@ File %s cannot be committed by this program.
}
}
}
- if {!$files_ready && ![string match *merge $curType]} {
+ if {!$files_ready && ![string match *merge $curType] && ![is_enabled nocommit]} {
info_popup [mc "No changes to commit.
You must stage at least 1 file before you can commit.
@@ -177,6 +177,8 @@ You must stage at least 1 file before you can commit.
return
}
+ if {[is_enabled nocommitmsg]} { do_quit 0 }
+
# -- A message is required.
#
set msg [string trim [$ui_comm get 1.0 end]]
@@ -212,6 +214,8 @@ A good commit message has the following format:
puts $msg_wt $msg
close $msg_wt
+ if {[is_enabled nocommit]} { do_quit 0 }
+
# -- Run the pre-commit hook.
#
set fd_ph [githook_read pre-commit]
@@ -410,7 +414,7 @@ A rescan will be automatically started now.
set ::GITGUI_BCK_exists 0
}
- if {[is_enabled singlecommit]} do_quit
+ if {[is_enabled singlecommit]} { do_quit 0 }
# -- Update in memory status
#
diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index a30c80a93..abe502d97 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -40,6 +40,15 @@ proc reshow_diff {} {
}
}
+proc force_diff_encoding {enc} {
+ global current_diff_path
+
+ if {$current_diff_path ne {}} {
+ force_path_encoding $current_diff_path $enc
+ reshow_diff
+ }
+}
+
proc handle_empty_diff {} {
global current_diff_path file_states file_lists
@@ -60,9 +69,9 @@ A rescan will be automatically started to find other files which may have the sa
rescan ui_ready 0
}
-proc show_diff {path w {lno {}} {scroll_pos {}}} {
+proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
global file_states file_lists
- global is_3way_diff diff_active repo_config
+ global is_3way_diff is_conflict_diff diff_active repo_config
global ui_diff ui_index ui_workdir
global current_diff_path current_diff_side current_diff_header
global current_diff_queue
@@ -83,36 +92,42 @@ proc show_diff {path w {lno {}} {scroll_pos {}}} {
set s $file_states($path)
set m [lindex $s 0]
+ set is_conflict_diff 0
set current_diff_path $path
set current_diff_side $w
set current_diff_queue {}
ui_status [mc "Loading diff of %s..." [escape_path $path]]
+ set cont_info [list $scroll_pos $callback]
+
if {[string first {U} $m] >= 0} {
- merge_load_stages $path [list show_unmerged_diff $scroll_pos]
+ merge_load_stages $path [list show_unmerged_diff $cont_info]
} elseif {$m eq {_O}} {
- show_other_diff $path $w $m $scroll_pos
+ show_other_diff $path $w $m $cont_info
} else {
- start_show_diff $scroll_pos
+ start_show_diff $cont_info
}
}
-proc show_unmerged_diff {scroll_pos} {
+proc show_unmerged_diff {cont_info} {
global current_diff_path current_diff_side
- global merge_stages ui_diff
+ global merge_stages ui_diff is_conflict_diff
global current_diff_queue
if {$merge_stages(2) eq {}} {
+ set is_conflict_diff 1
lappend current_diff_queue \
[list "LOCAL: deleted\nREMOTE:\n" d======= \
[list ":1:$current_diff_path" ":3:$current_diff_path"]]
} elseif {$merge_stages(3) eq {}} {
+ set is_conflict_diff 1
lappend current_diff_queue \
[list "REMOTE: deleted\nLOCAL:\n" d======= \
[list ":1:$current_diff_path" ":2:$current_diff_path"]]
} elseif {[lindex $merge_stages(1) 0] eq {120000}
|| [lindex $merge_stages(2) 0] eq {120000}
|| [lindex $merge_stages(3) 0] eq {120000}} {
+ set is_conflict_diff 1
lappend current_diff_queue \
[list "LOCAL:\n" d======= \
[list ":1:$current_diff_path" ":2:$current_diff_path"]]
@@ -120,14 +135,14 @@ proc show_unmerged_diff {scroll_pos} {
[list "REMOTE:\n" d======= \
[list ":1:$current_diff_path" ":3:$current_diff_path"]]
} else {
- start_show_diff $scroll_pos
+ start_show_diff $cont_info
return
}
- advance_diff_queue $scroll_pos
+ advance_diff_queue $cont_info
}
-proc advance_diff_queue {scroll_pos} {
+proc advance_diff_queue {cont_info} {
global current_diff_queue ui_diff
set item [lindex $current_diff_queue 0]
@@ -137,10 +152,10 @@ proc advance_diff_queue {scroll_pos} {
$ui_diff insert end [lindex $item 0] [lindex $item 1]
$ui_diff conf -state disabled
- start_show_diff $scroll_pos [lindex $item 2]
+ start_show_diff $cont_info [lindex $item 2]
}
-proc show_other_diff {path w m scroll_pos} {
+proc show_other_diff {path w m cont_info} {
global file_states file_lists
global is_3way_diff diff_active repo_config
global ui_diff ui_index ui_workdir
@@ -165,7 +180,9 @@ proc show_other_diff {path w m scroll_pos} {
}
file {
set fd [open $path r]
- fconfigure $fd -eofchar {}
+ fconfigure $fd \
+ -eofchar {} \
+ -encoding [get_path_encoding $path]
set content [read $fd $max_sz]
close $fd
set sz [file size $path]
@@ -217,16 +234,21 @@ proc show_other_diff {path w m scroll_pos} {
$ui_diff conf -state disabled
set diff_active 0
unlock_index
+ set scroll_pos [lindex $cont_info 0]
if {$scroll_pos ne {}} {
update
$ui_diff yview moveto $scroll_pos
}
ui_ready
+ set callback [lindex $cont_info 1]
+ if {$callback ne {}} {
+ eval $callback
+ }
return
}
}
-proc start_show_diff {scroll_pos {add_opts {}}} {
+proc start_show_diff {cont_info {add_opts {}}} {
global file_states file_lists
global is_3way_diff diff_active repo_config
global ui_diff ui_index ui_workdir
@@ -279,14 +301,14 @@ proc start_show_diff {scroll_pos {add_opts {}}} {
set ::current_diff_inheader 1
fconfigure $fd \
-blocking 0 \
- -encoding binary \
- -translation binary
- fileevent $fd readable [list read_diff $fd $scroll_pos]
+ -encoding [get_path_encoding $path] \
+ -translation lf
+ fileevent $fd readable [list read_diff $fd $cont_info]
}
-proc read_diff {fd scroll_pos} {
+proc read_diff {fd cont_info} {
global ui_diff diff_active
- global is_3way_diff current_diff_header
+ global is_3way_diff is_conflict_diff current_diff_header
global current_diff_queue
$ui_diff conf -state normal
@@ -334,6 +356,7 @@ proc read_diff {fd scroll_pos} {
{--} {set tags d_--}
{++} {
if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} {
+ set is_conflict_diff 1
set line [string replace $line 0 1 { }]
set tags d$op
} else {
@@ -353,6 +376,7 @@ proc read_diff {fd scroll_pos} {
{-} {set tags d_-}
{+} {
if {[regexp {^\+([<>]{7} |={7})} $line _g op]} {
+ set is_conflict_diff 1
set line [string replace $line 0 0 { }]
set tags d$op
} else {
@@ -377,12 +401,13 @@ proc read_diff {fd scroll_pos} {
close $fd
if {$current_diff_queue ne {}} {
- advance_diff_queue $scroll_pos
+ advance_diff_queue $cont_info
return
}
set diff_active 0
unlock_index
+ set scroll_pos [lindex $cont_info 0]
if {$scroll_pos ne {}} {
update
$ui_diff yview moveto $scroll_pos
@@ -392,6 +417,10 @@ proc read_diff {fd scroll_pos} {
if {[$ui_diff index end] eq {2.0}} {
handle_empty_diff
}
+ set callback [lindex $cont_info 1]
+ if {$callback ne {}} {
+ eval $callback
+ }
}
}
@@ -432,8 +461,9 @@ proc apply_hunk {x y} {
}
if {[catch {
+ set enc [get_path_encoding $current_diff_path]
set p [eval git_write $apply_cmd]
- fconfigure $p -translation binary -encoding binary
+ fconfigure $p -translation binary -encoding $enc
puts -nonewline $p $current_diff_header
puts -nonewline $p [$ui_diff get $s_lno $e_lno]
close $p} err]} {
@@ -601,8 +631,9 @@ proc apply_line {x y} {
set patch "@@ -$hln,$n +$hln,[eval expr $n $sign 1] @@\n$patch"
if {[catch {
+ set enc [get_path_encoding $current_diff_path]
set p [eval git_write $apply_cmd]
- fconfigure $p -translation binary -encoding binary
+ fconfigure $p -translation binary -encoding $enc
puts -nonewline $p $current_diff_header
puts -nonewline $p $patch
close $p} err]} {
diff --git a/git-gui/lib/encoding.tcl b/git-gui/lib/encoding.tcl
index 7f06b0d47..32668fc9c 100644
--- a/git-gui/lib/encoding.tcl
+++ b/git-gui/lib/encoding.tcl
@@ -206,7 +206,7 @@ set encoding_aliases {
{ ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
{ GBK CP936 MS936 windows-936 }
{ JIS_Encoding csJISEncoding }
- { Shift_JIS MS_Kanji csShiftJIS }
+ { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
{ Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
EUC-JP }
{ Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
@@ -240,37 +240,227 @@ set encoding_aliases {
{ Big5 csBig5 }
}
+set encoding_groups {
+ {"" ""
+ {"Unicode" UTF-8}
+ {"Western" ISO-8859-1}}
+ {we "West European"
+ {"Western" ISO-8859-15 CP-437 CP-850 MacRoman CP-1252 Windows-1252}
+ {"Celtic" ISO-8859-14}
+ {"Greek" ISO-8859-14 ISO-8859-7 CP-737 CP-869 MacGreek CP-1253 Windows-1253}
+ {"Icelandic" MacIceland MacIcelandic CP-861}
+ {"Nordic" ISO-8859-10 CP-865}
+ {"Portuguese" CP-860}
+ {"South European" ISO-8859-3}}
+ {ee "East European"
+ {"Baltic" CP-775 ISO-8859-4 ISO-8859-13 CP-1257 Windows-1257}
+ {"Central European" CP-852 ISO-8859-2 MacCE CP-1250 Windows-1250}
+ {"Croatian" MacCroatian}
+ {"Cyrillic" CP-855 ISO-8859-5 ISO-IR-111 KOI8-R MacCyrillic CP-1251 Windows-1251}
+ {"Russian" CP-866}
+ {"Ukrainian" KOI8-U MacUkraine MacUkrainian}
+ {"Romanian" ISO-8859-16 MacRomania MacRomanian}}
+ {ea "East Asian"
+ {"Generic" ISO-2022}
+ {"Chinese Simplified" GB2312 GB1988 GB12345 GB2312-RAW GBK EUC-CN GB18030 HZ ISO-2022-CN}
+ {"Chinese Traditional" Big5 Big5-HKSCS EUC-TW CP-950}
+ {"Japanese" EUC-JP ISO-2022-JP Shift-JIS JIS-0212 JIS-0208 JIS-0201 CP-932 MacJapan}
+ {"Korean" EUC-KR UHC JOHAB ISO-2022-KR CP-949 KSC5601}}
+ {sa "SE & SW Asian"
+ {"Armenian" ARMSCII-8}
+ {"Georgian" GEOSTD8}
+ {"Thai" TIS-620 ISO-8859-11 CP-874 Windows-874 MacThai}
+ {"Turkish" CP-857 CP857 ISO-8859-9 MacTurkish CP-1254 Windows-1254}
+ {"Vietnamese" TCVN VISCII VPS CP-1258 Windows-1258}
+ {"Hindi" MacDevanagari}
+ {"Gujarati" MacGujarati}
+ {"Gurmukhi" MacGurmukhi}}
+ {me "Middle Eastern"
+ {"Arabic" ISO-8859-6 Windows-1256 CP-1256 CP-864 MacArabic}
+ {"Farsi" MacFarsi}
+ {"Hebrew" ISO-8859-8-I Windows-1255 CP-1255 ISO-8859-8 CP-862 MacHebrew}}
+ {mi "Misc"
+ {"7-bit" ASCII}
+ {"16-bit" Unicode}
+ {"Legacy" CP-863 EBCDIC}
+ {"Symbol" Symbol Dingbats MacDingbats MacCentEuro}}
+}
+
+proc build_encoding_table {} {
+ global encoding_aliases encoding_lookup_table
+
+ # Prepare the lookup list; cannot use lsort -nocase because
+ # of compatibility issues with older Tcl (e.g. in msysgit)
+ set names [list]
+ foreach item [encoding names] {
+ lappend names [list [string tolower $item] $item]
+ }
+ set names [lsort -ascii -index 0 $names]
+ # neither can we use lsearch -index
+ set lnames [list]
+ foreach item $names {
+ lappend lnames [lindex $item 0]
+ }
+
+ foreach grp $encoding_aliases {
+ set target {}
+ foreach item $grp {
+ set i [lsearch -sorted -ascii $lnames \
+ [string tolower $item]]
+ if {$i >= 0} {
+ set target [lindex $names $i 1]
+ break
+ }
+ }
+ if {$target eq {}} continue
+ foreach item $grp {
+ set encoding_lookup_table([string tolower $item]) $target
+ }
+ }
+
+ foreach item $names {
+ set encoding_lookup_table([lindex $item 0]) [lindex $item 1]
+ }
+}
+
proc tcl_encoding {enc} {
- global encoding_aliases
- set names [encoding names]
- set lcnames [string tolower $names]
- set enc [string tolower $enc]
- set i [lsearch -exact $lcnames $enc]
- if {$i < 0} {
- # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
- if {[regsub {^iso[-_]} $enc iso encx]} {
- set i [lsearch -exact $lcnames $encx]
+ global encoding_lookup_table
+ if {$enc eq {}} {
+ return {}
+ }
+ if {![info exists encoding_lookup_table]} {
+ build_encoding_table
+ }
+ set enc [string tolower $enc]
+ if {![info exists encoding_lookup_table($enc)]} {
+ # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
+ if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
+ set enc $encx
+ }
+ }
+ if {[info exists encoding_lookup_table($enc)]} {
+ return $encoding_lookup_table($enc)
+ } else {
+ return {}
+ }
+}
+
+proc force_path_encoding {path enc} {
+ global path_encoding_overrides last_encoding_override
+
+ set enc [tcl_encoding $enc]
+ if {$enc eq {}} {
+ catch { unset last_encoding_override }
+ catch { unset path_encoding_overrides($path) }
+ } else {
+ set last_encoding_override $enc
+ if {$path ne {}} {
+ set path_encoding_overrides($path) $enc
+ }
+ }
+}
+
+proc get_path_encoding {path} {
+ global path_encoding_overrides last_encoding_override
+
+ if {[info exists last_encoding_override]} {
+ set tcl_enc $last_encoding_override
+ } else {
+ set tcl_enc [tcl_encoding [get_config gui.encoding]]
}
- }
- if {$i < 0} {
- foreach l $encoding_aliases {
- set ll [string tolower $l]
- if {[lsearch -exact $ll $enc] < 0} continue
- # look through the aliases for one that tcl knows about
- foreach e $ll {
- set i [lsearch -exact $lcnames $e]
- if {$i < 0} {
- if {[regsub {^iso[-_]} $e iso ex]} {
- set i [lsearch -exact $lcnames $ex]
- }
+ if {$tcl_enc eq {}} {
+ set tcl_enc [encoding system]
+ }
+ if {$path ne {}} {
+ if {[info exists path_encoding_overrides($path)]} {
+ set enc2 $path_encoding_overrides($path)
+ } else {
+ set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
+ }
+ if {$enc2 ne {}} {
+ set tcl_enc $enc2
+ }
+ }
+ return $tcl_enc
+}
+
+proc build_encoding_submenu {parent grp cmd} {
+ global used_encodings
+
+ set mid [lindex $grp 0]
+ set gname [mc [lindex $grp 1]]
+
+ set smenu {}
+ foreach subset [lrange $grp 2 end] {
+ set name [mc [lindex $subset 0]]
+
+ foreach enc [lrange $subset 1 end] {
+ set tcl_enc [tcl_encoding $enc]
+ if {$tcl_enc eq {}} continue
+
+ if {$smenu eq {}} {
+ if {$mid eq {}} {
+ set smenu $parent
+ } else {
+ set smenu "$parent.$mid"
+ menu $smenu
+ $parent add cascade \
+ -label $gname \
+ -menu $smenu
+ }
+ }
+
+ if {$name ne {}} {
+ set lbl "$name ($enc)"
+ } else {
+ set lbl $enc
+ }
+ $smenu add command \
+ -label $lbl \
+ -command [concat $cmd [list $tcl_enc]]
+
+ lappend used_encodings $tcl_enc
+ }
+ }
+}
+
+proc popup_btn_menu {m b} {
+ tk_popup $m [winfo pointerx $b] [winfo pointery $b]
+}
+
+proc build_encoding_menu {emenu cmd {nodef 0}} {
+ $emenu configure -postcommand \
+ [list do_build_encoding_menu $emenu $cmd $nodef]
+}
+
+proc do_build_encoding_menu {emenu cmd {nodef 0}} {
+ global used_encodings encoding_groups
+
+ $emenu configure -postcommand {}
+
+ if {!$nodef} {
+ $emenu add command \
+ -label [mc "Default"] \
+ -command [concat $cmd [list {}]]
+ }
+ set sysenc [encoding system]
+ $emenu add command \
+ -label [mc "System (%s)" $sysenc] \
+ -command [concat $cmd [list $sysenc]]
+
+ # Main encoding tree
+ set used_encodings [list identity]
+ $emenu add separator
+ foreach grp $encoding_groups {
+ build_encoding_submenu $emenu $grp $cmd
+ }
+
+ # Add unclassified encodings
+ set unused_grp [list [mc Other]]
+ foreach enc [encoding names] {
+ if {[lsearch -exact $used_encodings $enc] < 0} {
+ lappend unused_grp $enc
}
- if {$i >= 0} break
- }
- break
}
- }
- if {$i >= 0} {
- return [lindex $names $i]
- }
- return {}
+ build_encoding_submenu $emenu [list other [mc Other] $unused_grp] $cmd
}
diff --git a/git-gui/lib/mergetool.tcl b/git-gui/lib/mergetool.tcl
index 79c58bc7b..6ab5701d9 100644
--- a/git-gui/lib/mergetool.tcl
+++ b/git-gui/lib/mergetool.tcl
@@ -5,24 +5,51 @@ proc merge_resolve_one {stage} {
global current_diff_path
switch -- $stage {
- 1 { set target [mc "the base version"] }
- 2 { set target [mc "this branch"] }
- 3 { set target [mc "the other branch"] }
+ 1 { set targetquestion [mc "Force resolution to the base version?"] }
+ 2 { set targetquestion [mc "Force resolution to this branch?"] }
+ 3 { set targetquestion [mc "Force resolution to the other branch?"] }
}
- set op_question [mc "Force resolution to %s?
-Note that the diff shows only conflicting changes.
+ set op_question [strcat $targetquestion "\n" \
+[mc "Note that the diff shows only conflicting changes.
%s will be overwritten.
This operation can be undone only by restarting the merge." \
- $target [short_path $current_diff_path]]
+ [short_path $current_diff_path]]]
if {[ask_popup $op_question] eq {yes}} {
merge_load_stages $current_diff_path [list merge_force_stage $stage]
}
}
+proc merge_stage_workdir {path w lno} {
+ global current_diff_path diff_active
+
+ if {$diff_active} return
+
+ if {$path ne $current_diff_path} {
+ show_diff $path $w $lno {} [list do_merge_stage_workdir $path]
+ } else {
+ do_merge_stage_workdir $path
+ }
+}
+
+proc do_merge_stage_workdir {path} {
+ global current_diff_path is_conflict_diff
+
+ if {$path ne $current_diff_path} return;
+
+ if {$is_conflict_diff} {
+ if {[ask_popup [mc "File %s seems to have unresolved conflicts, still stage?" \
+ [short_path $path]]] ne {yes}} {
+ return
+ }
+ }
+
+ merge_add_resolution $path
+}
+
proc merge_add_resolution {path} {
global current_diff_path ui_workdir
diff --git a/git-gui/lib/option.tcl b/git-gui/lib/option.tcl
index 9b865f6a7..c80c93987 100644
--- a/git-gui/lib/option.tcl
+++ b/git-gui/lib/option.tcl
@@ -1,6 +1,28 @@
# git-gui options editor
# Copyright (C) 2006, 2007 Shawn Pearce
+proc config_check_encodings {} {
+ global repo_config_new global_config_new
+
+ set enc $global_config_new(gui.encoding)
+ if {$enc eq {}} {
+ set global_config_new(gui.encoding) [encoding system]
+ } elseif {[tcl_encoding $enc] eq {}} {
+ error_popup [mc "Invalid global encoding '%s'" $enc]
+ return 0
+ }
+
+ set enc $repo_config_new(gui.encoding)
+ if {$enc eq {}} {
+ set repo_config_new(gui.encoding) [encoding system]
+ } elseif {[tcl_encoding $enc] eq {}} {
+ error_popup [mc "Invalid repo encoding '%s'" $enc]
+ return 0
+ }
+
+ return 1
+}
+
proc save_config {} {
global default_config font_descs
global repo_config global_config
@@ -130,6 +152,7 @@ proc do_options {} {
{i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
{i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
{t gui.newbranchtemplate {mc "New Branch Name Template"}}
+ {c gui.encoding {mc "Default File Contents Encoding"}}
} {
set type [lindex $option 0]
set name [lindex $option 1]
@@ -159,6 +182,7 @@ proc do_options {} {
pack $w.$f.$optid.v -side right -anchor e -padx 5
pack $w.$f.$optid -side top -anchor w -fill x
}
+ c -
t {
frame $w.$f.$optid
label $w.$f.$optid.l -text "$text:"
@@ -171,6 +195,16 @@ proc do_options {} {
pack $w.$f.$optid.v -side left -anchor w \
-fill x -expand 1 \
-padx 5
+ if {$type eq {c}} {
+ menu $w.$f.$optid.m
+ build_encoding_menu $w.$f.$optid.m \
+ [list set ${f}_config_new($name)] 1
+ button $w.$f.$optid.b \
+ -text [mc "Change"] \
+ -command [list popup_btn_menu \
+ $w.$f.$optid.m $w.$f.$optid.b]
+ pack $w.$f.$optid.b -side left -anchor w
+ }
pack $w.$f.$optid -side top -anchor w -fill x
}
}
@@ -275,6 +309,7 @@ proc do_restore_defaults {} {
}
proc do_save_config {w} {
+ if {![config_check_encodings]} return
if {[catch {save_config} err]} {
error_popup [strcat [mc "Failed to completely save options:"] "\n\n$err"]
}