{"thread":{"id":"17512","subject":"[PATCH git-gui v2 0/2] Teach git-gui to use --primer.","startedAt":"2009-02-02T19:31:59Z","lastAt":"2009-02-02T19:32:01Z","messageCount":3,"participants":["Keith Cascio"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"102884","messageId":"1233603121-1430-1-git-send-email-keith@cs.ucla.edu","threadId":"17512","inReplyTo":null,"subject":"[PATCH git-gui v2 0/2] Teach git-gui to use --primer.","fromName":"Keith Cascio","fromEmail":"keith@cs.ucla.edu","sentAt":"2009-02-02T19:31:59Z","receivedAt":"2009-02-02T19:31:59Z","isPatch":true,"sender":{"key":"keith@cs.ucla.edu","avatar":"https://gravatar.com/avatar/c5ec3a8f1cd1f449fdf8bdb7125fdbfd10b729507f32cbf0aa4ad07b4f7127ae?d=mp&s=160"},"body":"The next two patches teach git-gui to take advantage of the new diff.primer\nfeature from my other patch.  This enhancement includes menu-driven white\nspace ignore settings.  To see this patch in action: apply the diff.primer\npatch to git.git, apply this patch to git-gui.git, fire up git-gui, modify a\nfile, then right-click on the diff panel and look for the new \"White Space\"\nsub-menu.\n\nKeith Cascio (2):\n Teach git-gui to use --primer.\n Hooks for new config variable \"diff.primer\".\n\n git-gui.sh     |   51 ++++++++++++++++++++++++++++++++++++++++++\n lib/diff.tcl   |    9 ++++++-\n lib/option.tcl |   57 +++++++++++++++++++++++++++++++++++++++++++----\n 3 files changed, 110 insertions(+), 7 deletions(-)\n"},{"id":"102885","messageId":"1233603121-1430-2-git-send-email-keith@cs.ucla.edu","threadId":"17512","inReplyTo":"1233603121-1430-1-git-send-email-keith@cs.ucla.edu","subject":"[PATCH git-gui v2 1/2] Teach git-gui to use --primer.","fromName":"Keith Cascio","fromEmail":"keith@cs.ucla.edu","sentAt":"2009-02-02T19:32:00Z","receivedAt":"2009-02-02T19:32:00Z","isPatch":true,"sender":{"key":"keith@cs.ucla.edu","avatar":"https://gravatar.com/avatar/c5ec3a8f1cd1f449fdf8bdb7125fdbfd10b729507f32cbf0aa4ad07b4f7127ae?d=mp&s=160"},"body":"Teach git-gui to use --primer.\nAlso teach it to check diff's exit code instead of relying on piped\noutput, which could be altered as a consequence of primer options.\n\nSigned-off-by: Keith Cascio <keith@cs.ucla.edu>\n---\n lib/diff.tcl |    9 +++++++--\n 1 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/lib/diff.tcl b/lib/diff.tcl\nindex bbbf15c..0e1e4a3 100644\n--- a/lib/diff.tcl\n+++ b/lib/diff.tcl\n@@ -276,6 +276,8 @@ proc start_show_diff {cont_info {add_opts {}}} {\n \t}\n \n \tlappend cmd -p\n+\tlappend cmd --exit-code\n+\tlappend cmd --primer\n \tlappend cmd --no-color\n \tif {$repo_config(gui.diffcontext) >= 1} {\n \t\tlappend cmd \"-U$repo_config(gui.diffcontext)\"\n@@ -310,6 +312,7 @@ proc read_diff {fd cont_info} {\n \tglobal ui_diff diff_active\n \tglobal is_3way_diff is_conflict_diff current_diff_header\n \tglobal current_diff_queue\n+\tglobal errorCode\n \n \t$ui_diff conf -state normal\n \twhile {[gets $fd line] >= 0} {\n@@ -397,7 +400,9 @@ proc read_diff {fd cont_info} {\n \t$ui_diff conf -state disabled\n \n \tif {[eof $fd]} {\n-\t\tclose $fd\n+\t\tfconfigure $fd -blocking 1\n+\t\tcatch { close $fd } err\n+\t\tset diff_exit_status $errorCode\n \n \t\tif {$current_diff_queue ne {}} {\n \t\t\tadvance_diff_queue $cont_info\n@@ -413,7 +418,7 @@ proc read_diff {fd cont_info} {\n \t\t}\n \t\tui_ready\n \n-\t\tif {[$ui_diff index end] eq {2.0}} {\n+\t\tif {$diff_exit_status eq \"NONE\"} {\n \t\t\thandle_empty_diff\n \t\t}\n \t\tset callback [lindex $cont_info 1]\n-- \n1.6.1\n"},{"id":"102887","messageId":"1233603121-1430-3-git-send-email-keith@cs.ucla.edu","threadId":"17512","inReplyTo":"1233603121-1430-2-git-send-email-keith@cs.ucla.edu","subject":"[PATCH git-gui v2 2/2] Hooks for new config variable \"diff.primer\".","fromName":"Keith Cascio","fromEmail":"keith@cs.ucla.edu","sentAt":"2009-02-02T19:32:01Z","receivedAt":"2009-02-02T19:32:01Z","isPatch":true,"sender":{"key":"keith@cs.ucla.edu","avatar":"https://gravatar.com/avatar/c5ec3a8f1cd1f449fdf8bdb7125fdbfd10b729507f32cbf0aa4ad07b4f7127ae?d=mp&s=160"},"body":"Hooks for new config variable \"diff.primer\".\nAdd three checkboxes to both sides of options panel (local/global).  Add a\nsub-menu named \"White Space\" to diff-panel right-click context menu, with\nthree checkboxes.\n\nSigned-off-by: Keith Cascio <keith@cs.ucla.edu>\n---\n git-gui.sh     |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++\n lib/option.tcl |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++----\n 2 files changed, 103 insertions(+), 5 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex e018e07..5d93351 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -3075,10 +3075,43 @@ $ui_diff tag conf d>>>>>>> \\\n \n $ui_diff tag raise sel\n \n+proc mirror_diff_state {} {\n+\tglobal  diff__ignore_space_at_eol diff__ignore_space_change diff__ignore_all_space\n+\n+\tset key  \"diff.primer\"\n+\tset ddo [git config --get $key]\n+\tset diff__ignore_space_at_eol [expr {[string match \"*--ignore-space-at-eol*\" $ddo] ? \"true\" : \"false\"}]\n+\tset diff__ignore_space_change [expr {[string match \"*--ignore-space-change*\" $ddo] ? \"true\" : \"false\"}]\n+\tset diff__ignore_all_space    [expr {[string match \"*--ignore-all-space*\"    $ddo] ? \"true\" : \"false\"}]\n+}\n+\n+proc adjust_command_line { flag value str } {\n+\tif {$value eq \"true\"} {\n+\t  if { ! [string match \"*$flag*\" $str ] } {\n+\t    set              str [concat $str $flag] }\n+\t} else { regsub       -- $flag   $str \"\" str }\n+\treturn                           $str\n+}\n+\n+proc record_diff_state {} {\n+\tglobal  diff__ignore_space_at_eol diff__ignore_space_change diff__ignore_all_space\n+\n+\tset key  \"diff.primer\"\n+\tset ddo [git config --get $key]\n+\tset ddo [adjust_command_line --ignore-space-at-eol $diff__ignore_space_at_eol $ddo]\n+\tset ddo [adjust_command_line --ignore-space-change $diff__ignore_space_change $ddo]\n+\tset ddo [adjust_command_line --ignore-all-space    $diff__ignore_all_space    $ddo]\n+\n+\tgit config $key $ddo\n+\treshow_diff\n+}\n+\n # -- Diff Body Context Menu\n #\n \n proc create_common_diff_popup {ctxm} {\n+\tglobal  diff__ignore_space_at_eol diff__ignore_space_change diff__ignore_all_space\n+\n \t$ctxm add command \\\n \t\t-label [mc \"Show Less Context\"] \\\n \t\t-command show_less_context\n@@ -3087,6 +3120,24 @@ proc create_common_diff_popup {ctxm} {\n \t\t-label [mc \"Show More Context\"] \\\n \t\t-command show_more_context\n \tlappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]\n+\tmirror_diff_state\n+\tset whitespacemenu $ctxm.ws\n+\tmenu $whitespacemenu -postcommand mirror_diff_state\n+\t$ctxm add cascade \\\n+\t\t-label [mc \"White Space\"] \\\n+\t\t-menu $whitespacemenu\n+\t$whitespacemenu add checkbutton \\\n+\t\t-label [mc \"--ignore-space-at-eol\"] \\\n+\t\t-variable diff__ignore_space_at_eol -onvalue \"true\" -offvalue \"false\" \\\n+\t\t-command record_diff_state\n+\t$whitespacemenu add checkbutton \\\n+\t\t-label [mc \"--ignore-space-change\"] \\\n+\t\t-variable diff__ignore_space_change -onvalue \"true\" -offvalue \"false\" \\\n+\t\t-command record_diff_state\n+\t$whitespacemenu add checkbutton \\\n+\t\t-label [mc \"--ignore-all-space\"   ] \\\n+\t\t-variable diff__ignore_all_space    -onvalue \"true\" -offvalue \"false\" \\\n+\t\t-command record_diff_state\n \t$ctxm add separator\n \t$ctxm add command \\\n \t\t-label [mc Refresh] \\\ndiff --git a/lib/option.tcl b/lib/option.tcl\nindex 1d55b49..fbdf4e8 100644\n--- a/lib/option.tcl\n+++ b/lib/option.tcl\n@@ -28,6 +28,7 @@ proc save_config {} {\n \tglobal repo_config global_config system_config\n \tglobal repo_config_new global_config_new\n \tglobal ui_comm_spell\n+\tglobal ddo diff_primer_global diff_primer_repo pseudovariables\n \n \tforeach option $font_descs {\n \t\tset name [lindex $option 0]\n@@ -46,17 +47,40 @@ proc save_config {} {\n \t\tunset global_config_new(gui.$font^^size)\n \t}\n \n+\tforeach name [get_diff_primer] {\n+\t\tset diff_option [string range $name 8 [string length $name]]\n+\t\tset ifound      [lsearch     $diff_primer_global $diff_option]\n+\t\tif {$global_config_new($name) eq \"true\"} {\n+\t\t  if {$ifound <  0} { lappend diff_primer_global $diff_option }\n+\t\t} else {\n+\t\t  if {$ifound >= 0} { set     diff_primer_global [lreplace $diff_primer_global $ifound $ifound]}\n+\t\t}\n+\t\tset ifound      [lsearch     $diff_primer_repo   $diff_option]\n+\t\tif {  $repo_config_new($name) eq \"true\"} {\n+\t\t  if {$ifound <  0} { lappend diff_primer_repo   $diff_option }\n+\t\t} else {\n+\t\t  if {$ifound >= 0} { set     diff_primer_repo   [lreplace $diff_primer_repo   $ifound $ifound]}\n+\t\t}\n+\t}\n+\tarray unset default_config gui.diff--ignore-*\n+\tset    default_config($ddo) \"\"\n+\tset global_config_new($ddo) [join    $diff_primer_global]\n+\tset   repo_config_new($ddo) [join    $diff_primer_repo  ]\n+\n \tforeach name [array names default_config] {\n \t\tset value $global_config_new($name)\n-\t\tif {$value ne $global_config($name)} {\n-\t\t\tif {$value eq $system_config($name)} {\n+\t\tset value_global [expr {[info exists global_config($name)] ? $global_config($name) : \"\"}]\n+\t\tset value_system [expr {[info exists system_config($name)] ? $system_config($name) : \"\"}]\n+\t\tset value_repo   [expr {[info exists   repo_config($name)] ?   $repo_config($name) : \"\"}]\n+\t\tif {$value ne $value_global} {\n+\t\t\tif {$value eq $value_system} {\n \t\t\t\tcatch {git config --global --unset $name}\n \t\t\t} else {\n \t\t\t\tregsub -all \"\\[{}\\]\" $value {\"} value\n \t\t\t\tgit config --global $name $value\n \t\t\t}\n \t\t\tset global_config($name) $value\n-\t\t\tif {$value eq $repo_config($name)} {\n+\t\t\tif {$value eq $value_repo} {\n \t\t\t\tcatch {git config --unset $name}\n \t\t\t\tset repo_config($name) $value\n \t\t\t}\n@@ -65,8 +89,10 @@ proc save_config {} {\n \n \tforeach name [array names default_config] {\n \t\tset value $repo_config_new($name)\n-\t\tif {$value ne $repo_config($name)} {\n-\t\t\tif {$value eq $global_config($name)} {\n+\t\tset value_global [expr {[info exists global_config($name)] ? $global_config($name) : \"\"}]\n+\t\tset value_repo   [expr {[info exists   repo_config($name)] ?   $repo_config($name) : \"\"}]\n+\t\tif {$value ne $value_repo} {\n+\t\t\tif {$value eq $value_global} {\n \t\t\t\tcatch {git config --unset $name}\n \t\t\t} else {\n \t\t\t\tregsub -all \"\\[{}\\]\" $value {\"} value\n@@ -88,10 +114,23 @@ proc save_config {} {\n \t}\n }\n \n+proc get_diff_primer {} {\n+\tglobal repo_config global_config\n+\tglobal ddo diff_primer_global diff_primer_repo pseudovariables\n+\n+\tset ddo \"diff.primer\"\n+\tset diff_primer_global [expr {[info exists global_config($ddo)] ? [split $global_config($ddo)] : [list]}]\n+\tset diff_primer_repo   [expr {[info exists   repo_config($ddo)] ? [split   $repo_config($ddo)] : [list]}]\n+\tset pseudovariables [list \"gui.diff--ignore-space-at-eol\" \"gui.diff--ignore-space-change\" \"gui.diff--ignore-all-space\"]\n+\n+\treturn $pseudovariables\n+}\n+\n proc do_options {} {\n \tglobal repo_config global_config font_descs\n \tglobal repo_config_new global_config_new\n \tglobal ui_comm_spell\n+\tglobal ddo diff_primer_global diff_primer_repo pseudovariables\n \n \tarray unset repo_config_new\n \tarray unset global_config_new\n@@ -108,6 +147,11 @@ proc do_options {} {\n \tforeach name [array names global_config] {\n \t\tset global_config_new($name) $global_config($name)\n \t}\n+\tforeach name [get_diff_primer] {\n+\t\tset diff_option [string range $name 8 [string length $name]]\n+\t\tset global_config_new($name) [expr {[lsearch $diff_primer_global $diff_option] < 0 ? \"false\" : \"true\"}]\n+\t\tset   repo_config_new($name) [expr {[lsearch $diff_primer_repo   $diff_option] < 0 ? \"false\" : \"true\"}]\n+\t}\n \n \tset w .options_editor\n \ttoplevel $w\n@@ -150,6 +194,9 @@ proc do_options {} {\n \t\t{i-20..200 gui.copyblamethreshold {mc \"Minimum Letters To Blame Copy On\"}}\n \t\t{i-0..300 gui.blamehistoryctx {mc \"Blame History Context Radius (days)\"}}\n \t\t{i-1..99 gui.diffcontext {mc \"Number of Diff Context Lines\"}}\n+\t\t{b gui.diff--ignore-space-at-eol {mc \"Diff Ignore Trailing White Space\"            }}\n+\t\t{b gui.diff--ignore-space-change {mc \"Diff Ignore Changes In Amount Of White Space\"}}\n+\t\t{b gui.diff--ignore-all-space    {mc \"Diff Ignore All White Space\"                 }}\n \t\t{i-0..99 gui.commitmsgwidth {mc \"Commit Message Text Width\"}}\n \t\t{t gui.newbranchtemplate {mc \"New Branch Name Template\"}}\n \t\t{c gui.encoding {mc \"Default File Contents Encoding\"}}\n-- \n1.6.1\n"}]}