From a9786bb42ff4fa4b8031ab69215a66cf329d8324 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 8 Sep 2008 11:18:52 +0400 Subject: git-gui: Fix Blame Parent & Context for working copy lines. Make Blame Parent Commit and Show History Context work properly for lines blamed on the working copy. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 10d8a44..9fbee24 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1025,6 +1025,9 @@ set current_diff_path {} set is_3way_diff 0 set selected_commit_type new +set nullid "0000000000000000000000000000000000000000" +set nullid2 "0000000000000000000000000000000000000001" + ###################################################################### ## ## task management diff --git a/lib/blame.tcl b/lib/blame.tcl index 827c85d..0d635cd 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -942,9 +942,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 +992,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 +1015,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 -- cgit v0.10.2-6-g49f6 From 2fe5b2ee42897a3acc78e5ddaace3775eb2713ca Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 8 Sep 2008 20:37:11 +0400 Subject: git-gui: Restore ability to Stage Working Copy for conflicts. Tools like rerere leave files marked as conflicts in the index, while actually resolving them in the working copy. Also, some people like to use an external editor to resolve conflicts. This patch restores functionality previously removed in commit 617ceee653 by adding a new context menu item. It still ensures that the user does not stage conflicting files accidentally by clicking on the icon instead of the name. Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 9fbee24..1044ab9 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2902,6 +2902,11 @@ $ctxmmg add command \ -command {merge_resolve_one 1} lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] $ctxmmg add separator +$ctxmmg add command \ + -label [mc "Stage Working Copy"] \ + -command {merge_resolve_one 0} +lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] +$ctxmmg add separator create_common_diff_popup $ctxmmg proc popup_diff_menu {ctxm ctxmmg x y X Y} { diff --git a/lib/mergetool.tcl b/lib/mergetool.tcl index 79c58bc..dd2315b 100644 --- a/lib/mergetool.tcl +++ b/lib/mergetool.tcl @@ -5,6 +5,12 @@ proc merge_resolve_one {stage} { global current_diff_path switch -- $stage { + 0 { # Stage without confirmation, to minimize + # disruption of the rerere workflow + merge_add_resolution $current_diff_path + return + } + 1 { set target [mc "the base version"] } 2 { set target [mc "this branch"] } 3 { set target [mc "the other branch"] } -- cgit v0.10.2-6-g49f6 From 8b56a18dea33e8b55810b4e561279b118bc1ada8 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Fri, 12 Sep 2008 11:17:38 +0200 Subject: git-gui: I18n fix sentence parts into full sentences for translation again. For translations, it is almost always impossible to correctly translate parts of sentences in almost any other language. Hence, messages like this must be re-organized into full sentences. Signed-off-by: Christian Stimming Signed-off-by: Shawn O. Pearce diff --git a/lib/mergetool.tcl b/lib/mergetool.tcl index dd2315b..a44a725 100644 --- a/lib/mergetool.tcl +++ b/lib/mergetool.tcl @@ -11,18 +11,18 @@ proc merge_resolve_one {stage} { return } - 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] -- cgit v0.10.2-6-g49f6 From 146ed90f020bb19446020d9b858242f176777797 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Sat, 13 Sep 2008 10:24:47 +0200 Subject: git-gui: Updated German translation. Signed-off-by: Shawn O. Pearce diff --git a/po/de.po b/po/de.po index fa43947..793cca1 100644 --- a/po/de.po +++ b/po/de.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: git-gui\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-08-02 08:58+0200\n" -"PO-Revision-Date: 2008-08-02 09:09+0200\n" +"POT-Creation-Date: 2008-09-13 10:20+0200\n" +"PO-Revision-Date: 2008-09-13 10:24+0200\n" "Last-Translator: Christian Stimming \n" "Language-Team: German\n" "MIME-Version: 1.0\n" @@ -110,7 +110,15 @@ msgstr "Teilweise bereitgestellt zum Eintragen" msgid "Staged for commit, missing" msgstr "Bereitgestellt zum Eintragen, fehlend" -#: git-gui.sh:1597 +#: git-gui.sh:1658 +msgid "File type changed, not staged" +msgstr "Dateityp geändert, nicht bereitgestellt" + +#: git-gui.sh:1659 +msgid "File type changed, staged" +msgstr "Dateityp geändert, bereitgestellt" + +#: git-gui.sh:1661 msgid "Untracked, not staged" msgstr "Nicht unter Versionskontrolle, nicht bereitgestellt" @@ -396,15 +404,7 @@ msgstr "Alle kopieren" msgid "File:" msgstr "Datei:" -#: git-gui.sh:2589 -msgid "Apply/Reverse Hunk" -msgstr "Kontext anwenden/umkehren" - -#: git-gui.sh:2696 -msgid "Apply/Reverse Line" -msgstr "Zeile anwenden/umkehren" - -#: git-gui.sh:2711 +#: git-gui.sh:2834 msgid "Refresh" msgstr "Aktualisieren" @@ -416,7 +416,35 @@ msgstr "Schriftgröße verkleinern" msgid "Increase Font Size" msgstr "Schriftgröße vergrößern" -#: git-gui.sh:2646 +#: git-gui.sh:2870 +msgid "Apply/Reverse Hunk" +msgstr "Kontext anwenden/umkehren" + +#: git-gui.sh:2875 +msgid "Apply/Reverse Line" +msgstr "Zeile anwenden/umkehren" + +#: git-gui.sh:2885 +msgid "Run Merge Tool" +msgstr "Zusammenführungswerkzeug" + +#: git-gui.sh:2890 +msgid "Use Remote Version" +msgstr "Entfernte Version benutzen" + +#: git-gui.sh:2894 +msgid "Use Local Version" +msgstr "Lokale Version benutzen" + +#: git-gui.sh:2898 +msgid "Revert To Base" +msgstr "Ursprüngliche Version benutzen" + +#: git-gui.sh:2906 +msgid "Stage Working Copy" +msgstr "Arbeitskopie bereitstellen" + +#: git-gui.sh:2925 msgid "Unstage Hunk From Commit" msgstr "Kontext aus Bereitstellung herausnehmen" @@ -498,7 +526,15 @@ msgstr "Version kopieren" msgid "Do Full Copy Detection" msgstr "Volle Kopie-Erkennung" -#: lib/blame.tcl:388 +#: lib/blame.tcl:263 +msgid "Show History Context" +msgstr "Historien-Kontext anzeigen" + +#: lib/blame.tcl:266 +msgid "Blame Parent Commit" +msgstr "Elternversion annotieren" + +#: lib/blame.tcl:394 #, tcl-format msgid "Reading %s..." msgstr "%s lesen..." @@ -547,7 +583,19 @@ msgstr "Eintragender:" msgid "Original File:" msgstr "Ursprüngliche Datei:" -#: lib/blame.tcl:925 +#: lib/blame.tcl:990 +msgid "Cannot find parent commit:" +msgstr "Elternversion kann nicht gefunden werden:" + +#: lib/blame.tcl:1001 +msgid "Unable to display parent" +msgstr "Elternversion kann nicht angezeigt werden" + +#: lib/blame.tcl:1002 lib/diff.tcl:191 +msgid "Error loading diff:" +msgstr "Fehler beim Laden des Vergleichs:" + +#: lib/blame.tcl:1142 msgid "Originally By:" msgstr "Ursprünglich von:" @@ -1494,11 +1542,7 @@ msgstr "Git-Projektarchiv (Unterprojekt)" msgid "* Binary file (not showing content)." msgstr "* Binärdatei (Inhalt wird nicht angezeigt)" -#: lib/diff.tcl:185 -msgid "Error loading diff:" -msgstr "Fehler beim Laden des Vergleichs:" - -#: lib/diff.tcl:303 +#: lib/diff.tcl:313 msgid "Failed to unstage selected hunk." msgstr "" "Fehler beim Herausnehmen des gewählten Kontexts aus der Bereitstellung." @@ -1586,6 +1630,15 @@ msgstr "" msgid "Do Nothing" msgstr "Nichts tun" +#: lib/index.tcl:419 +msgid "Reverting selected files" +msgstr "Änderungen in gewählten Dateien verwerfen" + +#: lib/index.tcl:423 +#, tcl-format +msgid "Reverting %s" +msgstr "Änderungen in %s verwerfen" + #: lib/merge.tcl:13 msgid "" "Cannot merge while amending.\n" @@ -1730,6 +1783,96 @@ msgstr "Abbruch fehlgeschlagen." msgid "Abort completed. Ready." msgstr "Abbruch durchgeführt. Bereit." +#: lib/mergetool.tcl:14 +msgid "Force resolution to the base version?" +msgstr "Konflikt durch Basisversion ersetzen?" + +#: lib/mergetool.tcl:15 +msgid "Force resolution to this branch?" +msgstr "Konflikt durch diesen Zweig ersetzen?" + +#: lib/mergetool.tcl:16 +msgid "Force resolution to the other branch?" +msgstr "Konflikt durch anderen Zweig ersetzen?" + +#: lib/mergetool.tcl:20 +#, tcl-format +msgid "" +"Note that the diff shows only conflicting changes.\n" +"\n" +"%s will be overwritten.\n" +"\n" +"This operation can be undone only by restarting the merge." +msgstr "" +"Hinweis: Der Vergleich zeigt nur konfliktverursachende Änderungen an.\n" +"\n" +"»%s« wird überschrieben.\n" +"\n" +"Diese Operation kann nur rückgängig gemacht werden, wenn die\n" +"Zusammenführung erneut gestartet wird." + +#: lib/mergetool.tcl:32 +#, tcl-format +msgid "Adding resolution for %s" +msgstr "Auflösung hinzugefügt für %s" + +#: lib/mergetool.tcl:119 +msgid "Cannot resolve deletion or link conflicts using a tool" +msgstr "" +"Konflikte durch gelöschte Dateien oder symbolische Links können nicht durch " +"das Zusamenführungswerkzeug gelöst werden." + +#: lib/mergetool.tcl:124 +msgid "Conflict file does not exist" +msgstr "Konflikt-Datei existiert nicht" + +#: lib/mergetool.tcl:236 +#, tcl-format +msgid "Not a GUI merge tool: '%s'" +msgstr "Kein GUI Zusammenführungswerkzeug: »%s«" + +#: lib/mergetool.tcl:240 +#, tcl-format +msgid "Unsupported merge tool '%s'" +msgstr "Unbekanntes Zusammenführungswerkzeug: »%s«" + +#: lib/mergetool.tcl:275 +msgid "Merge tool is already running, terminate it?" +msgstr "Zusammenführungswerkzeug läuft bereits. Soll es abgebrochen werden?" + +#: lib/mergetool.tcl:295 +#, tcl-format +msgid "" +"Error retrieving versions:\n" +"%s" +msgstr "" +"Fehler beim Abrufen der Dateiversionen:\n" +"%s" + +#: lib/mergetool.tcl:315 +#, tcl-format +msgid "" +"Could not start the merge tool:\n" +"\n" +"%s" +msgstr "" +"Zusammenführungswerkzeug konnte nicht gestartet werden:\n" +"\n" +"%s" + +#: lib/mergetool.tcl:319 +msgid "Running merge tool..." +msgstr "Zusammenführungswerkzeug starten..." + +#: lib/mergetool.tcl:347 lib/mergetool.tcl:363 +msgid "Merge tool failed." +msgstr "Zusammenführungswerkzeug fehlgeschlagen." + +#: lib/mergetool.tcl:353 +#, tcl-format +msgid "File %s unchanged, still accept as resolved?" +msgstr "Datei »%s« unverändert. Trotzdem Konflikt als gelöst akzeptieren?" + #: lib/option.tcl:95 msgid "Restore Defaults" msgstr "Voreinstellungen wiederherstellen" @@ -1767,7 +1910,11 @@ msgstr "Ausführlichkeit der Zusammenführen-Meldungen" msgid "Show Diffstat After Merge" msgstr "Vergleichsstatistik nach Zusammenführen anzeigen" -#: lib/option.tcl:123 +#: lib/option.tcl:122 +msgid "Use Merge Tool" +msgstr "Zusammenführungswerkzeug" + +#: lib/option.tcl:124 msgid "Trust File Modification Timestamps" msgstr "Auf Dateiänderungsdatum verlassen" @@ -1788,6 +1935,10 @@ msgid "Minimum Letters To Blame Copy On" msgstr "Mindestzahl Zeichen für Kopie-Annotieren" #: lib/option.tcl:128 +msgid "Blame History Context Radius (days)" +msgstr "Anzahl Tage für Historien-Kontext" + +#: lib/option.tcl:129 msgid "Number of Diff Context Lines" msgstr "Anzahl der Kontextzeilen beim Vergleich" -- cgit v0.10.2-6-g49f6 From 1e65c6225dea2e15df81f6c91927cb0b8fab443c Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 12 Sep 2008 22:43:49 +0400 Subject: git-gui: Add more integration options to citool. - Make citool return nonzero exit code if it did not commit. - Add a mode where it does not actually commit and simply exits with zero code. Commit message is either disabled, or simply dumped to GITGUI_EDITMSG before exiting. - Add an option to immediately start it in amend mode. Rationale: 1) Use 'git citool --nocommit' instead of mergetool in scripts. 2) Use 'git citool --amend' to edit commits while rebasing. Signed-off-by: Alexander Gavrilov Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 1044ab9..c4ccc66 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -948,10 +948,32 @@ blame { } citool { enable_option singlecommit + enable_option retcode disable_option multicommit disable_option branch disable_option transport + + while {[llength $argv] > 0} { + set a [lindex $argv 0] + switch -- $a { + --amend { + enable_option initialamend + } + --nocommit { + enable_option nocommit + enable_option nocommitmsg + } + --commitmsg { + disable_option nocommitmsg + } + default { + break + } + } + + set argv [lrange $argv 1 end] + } } } @@ -1108,6 +1130,20 @@ proc PARENT {} { return $empty_tree } +proc force_amend {} { + global selected_commit_type + global HEAD PARENT MERGE_HEAD commit_type + + repository_state newType newHEAD newMERGE_HEAD + set HEAD $newHEAD + set PARENT $newHEAD + set MERGE_HEAD $newMERGE_HEAD + set commit_type $newType + + set selected_commit_type amend + do_select_commit_type +} + proc rescan {after {honor_trustmtime 1}} { global HEAD PARENT MERGE_HEAD commit_type global ui_index ui_workdir ui_comm @@ -1754,11 +1790,19 @@ proc do_gitk {revs} { } set is_quitting 0 +set ret_code 1 -proc do_quit {} { +proc terminate_me {win} { + global ret_code + if {$win ne {.}} return + exit $ret_code +} + +proc do_quit {{rc {1}}} { global ui_comm is_quitting repo_config commit_type global GITGUI_BCK_exists GITGUI_BCK_i global ui_comm_spell + global ret_code if {$is_quitting} return set is_quitting 1 @@ -1813,6 +1857,7 @@ proc do_quit {} { } } + set ret_code $rc destroy . } @@ -2215,6 +2260,14 @@ if {[is_enabled branch]} { # -- Commit Menu # +proc commit_btn_caption {} { + if {[is_enabled nocommit]} { + return [mc "Done"] + } else { + return [mc Commit@@verb] + } +} + if {[is_enabled multicommit] || [is_enabled singlecommit]} { menu .mbar.commit @@ -2280,7 +2333,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { -command do_signoff \ -accelerator $M1T-S - .mbar.commit add command -label [mc Commit@@verb] \ + .mbar.commit add command -label [commit_btn_caption] \ -command do_commit \ -accelerator $M1T-Return lappend disable_on_lock \ @@ -2608,7 +2661,7 @@ button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ -command do_signoff pack .vpane.lower.commarea.buttons.signoff -side top -fill x -button .vpane.lower.commarea.buttons.commit -text [mc Commit@@verb] \ +button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \ -command do_commit pack .vpane.lower.commarea.buttons.commit -side top -fill x lappend disable_on_lock \ @@ -2618,6 +2671,13 @@ button .vpane.lower.commarea.buttons.push -text [mc Push] \ -command do_push_anywhere pack .vpane.lower.commarea.buttons.push -side top -fill x +if {[is_enabled nocommitmsg]} { + .vpane.lower.commarea.buttons.signoff configure -state disabled +} +if {[is_enabled nocommit]} { + .vpane.lower.commarea.buttons.push configure -state disabled +} + # -- Commit Message Buffer # frame .vpane.lower.commarea.buffer @@ -3199,7 +3259,20 @@ lock_index begin-read if {![winfo ismapped .]} { wm deiconify . } -after 1 do_rescan +after 1 { + if {[is_enabled initialamend]} { + force_amend + } else { + do_rescan + } + + if {[is_enabled nocommitmsg]} { + $ui_comm configure -state disabled -background gray + } +} if {[is_enabled multicommit]} { after 1000 hint_gc } +if {[is_enabled retcode]} { + bind . {+terminate_me %W} +} diff --git a/lib/commit.tcl b/lib/commit.tcl index 2977315..3345149 100644 --- a/lib/commit.tcl +++ b/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 # -- cgit v0.10.2-6-g49f6 From 1e02b32e7212d4f5f596a7161dc7c5cb76ac965d Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 24 Sep 2008 09:48:20 -0700 Subject: git-gui: Hide commit related UI during citool --nocommit If the user started git-gui as "git citool --nocommit" then they don't need the new commit / amend commit radio buttons, or the sign off button in the UI. Rather than use up space with options the user cannot activate they are simply not installed into the UI. Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index c4ccc66..1939001 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2271,23 +2271,25 @@ proc commit_btn_caption {} { if {[is_enabled multicommit] || [is_enabled singlecommit]} { menu .mbar.commit - .mbar.commit add radiobutton \ - -label [mc "New Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value new - lappend disable_on_lock \ - [list .mbar.commit entryconf [.mbar.commit index last] -state] - - .mbar.commit add radiobutton \ - -label [mc "Amend Last Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value amend - lappend disable_on_lock \ - [list .mbar.commit entryconf [.mbar.commit index last] -state] - - .mbar.commit add separator + if {![is_enabled nocommit]} { + .mbar.commit add radiobutton \ + -label [mc "New Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value new + lappend disable_on_lock \ + [list .mbar.commit entryconf [.mbar.commit index last] -state] + + .mbar.commit add radiobutton \ + -label [mc "Amend Last Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value amend + lappend disable_on_lock \ + [list .mbar.commit entryconf [.mbar.commit index last] -state] + + .mbar.commit add separator + } .mbar.commit add command -label [mc Rescan] \ -command ui_do_rescan \ @@ -2329,9 +2331,11 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { .mbar.commit add separator - .mbar.commit add command -label [mc "Sign Off"] \ - -command do_signoff \ - -accelerator $M1T-S + if {![is_enabled nocommit]} { + .mbar.commit add command -label [mc "Sign Off"] \ + -command do_signoff \ + -accelerator $M1T-S + } .mbar.commit add command -label [commit_btn_caption] \ -command do_commit \ @@ -2657,9 +2661,11 @@ pack .vpane.lower.commarea.buttons.incall -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.incall conf -state} -button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ - -command do_signoff -pack .vpane.lower.commarea.buttons.signoff -side top -fill x +if {![is_enabled nocommit]} { + button .vpane.lower.commarea.buttons.signoff -text [mc "Sign Off"] \ + -command do_signoff + pack .vpane.lower.commarea.buttons.signoff -side top -fill x +} button .vpane.lower.commarea.buttons.commit -text [commit_btn_caption] \ -command do_commit @@ -2667,15 +2673,10 @@ pack .vpane.lower.commarea.buttons.commit -side top -fill x lappend disable_on_lock \ {.vpane.lower.commarea.buttons.commit conf -state} -button .vpane.lower.commarea.buttons.push -text [mc Push] \ - -command do_push_anywhere -pack .vpane.lower.commarea.buttons.push -side top -fill x - -if {[is_enabled nocommitmsg]} { - .vpane.lower.commarea.buttons.signoff configure -state disabled -} -if {[is_enabled nocommit]} { - .vpane.lower.commarea.buttons.push configure -state disabled +if {![is_enabled nocommit]} { + button .vpane.lower.commarea.buttons.push -text [mc Push] \ + -command do_push_anywhere + pack .vpane.lower.commarea.buttons.push -side top -fill x } # -- Commit Message Buffer @@ -2684,20 +2685,24 @@ frame .vpane.lower.commarea.buffer frame .vpane.lower.commarea.buffer.header set ui_comm .vpane.lower.commarea.buffer.t set ui_coml .vpane.lower.commarea.buffer.header.l -radiobutton .vpane.lower.commarea.buffer.header.new \ - -text [mc "New Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value new -lappend disable_on_lock \ - [list .vpane.lower.commarea.buffer.header.new conf -state] -radiobutton .vpane.lower.commarea.buffer.header.amend \ - -text [mc "Amend Last Commit"] \ - -command do_select_commit_type \ - -variable selected_commit_type \ - -value amend -lappend disable_on_lock \ - [list .vpane.lower.commarea.buffer.header.amend conf -state] + +if {![is_enabled nocommit]} { + radiobutton .vpane.lower.commarea.buffer.header.new \ + -text [mc "New Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value new + lappend disable_on_lock \ + [list .vpane.lower.commarea.buffer.header.new conf -state] + radiobutton .vpane.lower.commarea.buffer.header.amend \ + -text [mc "Amend Last Commit"] \ + -command do_select_commit_type \ + -variable selected_commit_type \ + -value amend + lappend disable_on_lock \ + [list .vpane.lower.commarea.buffer.header.amend conf -state] +} + label $ui_coml \ -anchor w \ -justify left @@ -2715,8 +2720,11 @@ proc trace_commit_type {varname args} { } trace add variable commit_type write trace_commit_type pack $ui_coml -side left -fill x -pack .vpane.lower.commarea.buffer.header.amend -side right -pack .vpane.lower.commarea.buffer.header.new -side right + +if {![is_enabled nocommit]} { + pack .vpane.lower.commarea.buffer.header.amend -side right + pack .vpane.lower.commarea.buffer.header.new -side right +} text $ui_comm -background white -foreground black \ -borderwidth 1 \ -- cgit v0.10.2-6-g49f6 From 2cd1fd1f6da5243226779acb17be9132d53ec4a9 Mon Sep 17 00:00:00 2001 From: Joshua Williams Date: Wed, 24 Sep 2008 14:11:53 -0500 Subject: git-gui: Add support for calling out to the prepare-commit-msg hook Signed-off-by: Joshua Williams Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 1939001..cb0fcac 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1170,6 +1170,7 @@ proc rescan {after {honor_trustmtime 1}} { || [string trim [$ui_comm get 0.0 end]] eq {})} { if {[string match amend* $commit_type]} { } elseif {[load_message GITGUI_MSG]} { + } elseif {[run_prepare_commit_msg_hook]} { } elseif {[load_message MERGE_MSG]} { } elseif {[load_message SQUASH_MSG]} { } @@ -1269,6 +1270,70 @@ proc load_message {file} { return 0 } +proc run_prepare_commit_msg_hook {} { + global pch_error + + # prepare-commit-msg requires PREPARE_COMMIT_MSG exist. From git-gui + # it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an + # empty file but existant file. + + set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a] + + if {[file isfile [gitdir MERGE_MSG]]} { + set pcm_source "merge" + set fd_mm [open [gitdir MERGE_MSG] r] + puts -nonewline $fd_pcm [read $fd_mm] + close $fd_mm + } elseif {[file isfile [gitdir SQUASH_MSG]]} { + set pcm_source "squash" + set fd_sm [open [gitdir SQUASH_MSG] r] + puts -nonewline $fd_pcm [read $fd_sm] + close $fd_sm + } else { + set pcm_source "" + } + + close $fd_pcm + + set fd_ph [githook_read prepare-commit-msg \ + [gitdir PREPARE_COMMIT_MSG] $pcm_source] + if {$fd_ph eq {}} { + catch {file delete [gitdir PREPARE_COMMIT_MSG]} + return 0; + } + + ui_status [mc "Calling prepare-commit-msg hook..."] + set pch_error {} + + fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} + fileevent $fd_ph readable \ + [list prepare_commit_msg_hook_wait $fd_ph] + + return 1; +} + +proc prepare_commit_msg_hook_wait {fd_ph} { + global pch_error + + append pch_error [read $fd_ph] + fconfigure $fd_ph -blocking 1 + if {[eof $fd_ph]} { + if {[catch {close $fd_ph}]} { + ui_status [mc "Commit declined by prepare-commit-msg hook."] + hook_failed_popup prepare-commit-msg $pch_error + catch {file delete [gitdir PREPARE_COMMIT_MSG]} + exit 1 + } else { + load_message PREPARE_COMMIT_MSG + } + set pch_error {} + catch {file delete [gitdir PREPARE_COMMIT_MSG]} + return + } + fconfigure $fd_ph -blocking 0 + catch {file delete [gitdir PREPARE_COMMIT_MSG]} +} + proc read_diff_index {fd after} { global buf_rdi -- cgit v0.10.2-6-g49f6 From 1ffca60f0b0395e1e593e64d66e7ed3c47d8517e Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 23 Jan 2008 00:37:10 -0500 Subject: git-gui: Use gitattribute "encoding" for file content display Most folks using git-gui on internationalized files have complained that it doesn't recognize UTF-8 correctly. In the past we have just ignored the problem and showed the file contents as binary/US-ASCII, which is wrong no matter how you look at it. This really should be a per-file attribute, managed by .gitattributes, so we now pull the "encoding" attribute data for the given path from the .gitattributes (if available) and use that, falling back to UTF-8 if the attributes are unavailable, git-check-attr is broken, or an encoding for this path not specified. We apply the encoding anytime we show file content, which currently is limited to only the diff viewer and the blame viewer. Signed-off-by: Shawn O. Pearce diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f96112d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* encoding=US-ASCII +git-gui.sh encoding=UTF-8 +/po/*.po encoding=UTF-8 diff --git a/git-gui.sh b/git-gui.sh index cb0fcac..4a76235 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -521,6 +521,19 @@ proc kill_file_process {fd} { } } +proc gitattr {path attr default} { + if {[catch {set r [git check-attr $attr -- $path]}]} { + set r unspecified + } else { + set r [join [lrange [split $r :] 2 end] :] + regsub {^ } $r {} r + } + if {$r eq {unspecified}} { + return $default + } + return $r +} + proc sq {value} { regsub -all ' $value "'\\''" value return "'$value'" diff --git a/lib/blame.tcl b/lib/blame.tcl index 0d635cd..9464a59 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -399,7 +399,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 [tcl_encoding [gitattr $path encoding UTF-8]] fileevent $fd readable [cb _read_file $fd $jump] set current_fd $fd } diff --git a/lib/diff.tcl b/lib/diff.tcl index a30c80a..b0ecfbc 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -164,8 +164,11 @@ proc show_other_diff {path w m scroll_pos} { set sz [string length $content] } file { + set enc [gitattr $path encoding UTF-8] set fd [open $path r] - fconfigure $fd -eofchar {} + fconfigure $fd \ + -eofchar {} \ + -encoding [tcl_encoding $enc] set content [read $fd $max_sz] close $fd set sz [file size $path] @@ -279,8 +282,8 @@ proc start_show_diff {scroll_pos {add_opts {}}} { set ::current_diff_inheader 1 fconfigure $fd \ -blocking 0 \ - -encoding binary \ - -translation binary + -encoding [tcl_encoding [gitattr $path encoding UTF-8]] \ + -translation lf fileevent $fd readable [list read_diff $fd $scroll_pos] } -- cgit v0.10.2-6-g49f6 From 696235c6c1c85085fd55ff849663d44c51464e69 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 23 Jan 2008 00:39:50 -0500 Subject: git-gui: Assume `blame --incremental` output is in UTF-8 Most commits have author name encoded in UTF-8, but the incremental blame output dumps raw bytes and doesn't give us the encoding header from the commit. Rather than fixing up tooltip data after we have viewed that particular commit in the blame viewer we can assume all names are in UTF-8. This is still going to cause problems when the author name is not encoded in UTF-8, but the only (efficient) way to solve that is to add an "encoding" header to the blame --incremental mode output, as otherwise we need to run `git cat-file commit $sha1` for each and every commit identified and that would be horribly expensive on any platform. Signed-off-by: Shawn O. Pearce diff --git a/lib/blame.tcl b/lib/blame.tcl index 9464a59..7535adb 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -511,7 +511,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 @@ -884,12 +884,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] } -- cgit v0.10.2-6-g49f6 From 72e6b002021e45255f568fc0c885d82de75ae935 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 18 Sep 2008 01:07:32 +0400 Subject: git-gui: Cleanup handling of the default encoding. - Make diffs and blame default to the system (locale) encoding instead of hard-coding UTF-8. - Add a gui.encoding option to allow overriding it. - gitattributes still have the final word. The rationale for this is Windows support: 1) Windows people are accustomed to using legacy encodings for text files. For many of them defaulting to utf-8 will be counter-intuitive. 2) Windows doesn't support utf-8 locales, and switching the system encoding is a real pain. Thus the option. This patch also adds proper encoding conversion to Apply Hunk/Line. Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 4a76235..b37148b 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -678,6 +678,7 @@ set default_config(merge.verbosity) 2 set default_config(user.name) {} set default_config(user.email) {} +set default_config(gui.encoding) [encoding system] set default_config(gui.matchtrackingbranch) false set default_config(gui.pruneduringfetch) false set default_config(gui.trustmtime) false diff --git a/lib/blame.tcl b/lib/blame.tcl index 7535adb..84d55b5 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -402,7 +402,7 @@ method _load {jump} { fconfigure $fd \ -blocking 0 \ -translation lf \ - -encoding [tcl_encoding [gitattr $path encoding UTF-8]] + -encoding [get_path_encoding $path] fileevent $fd readable [cb _read_file $fd $jump] set current_fd $fd } diff --git a/lib/diff.tcl b/lib/diff.tcl index b0ecfbc..8fefc5d 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -164,11 +164,10 @@ proc show_other_diff {path w m scroll_pos} { set sz [string length $content] } file { - set enc [gitattr $path encoding UTF-8] set fd [open $path r] fconfigure $fd \ -eofchar {} \ - -encoding [tcl_encoding $enc] + -encoding [get_path_encoding $path] set content [read $fd $max_sz] close $fd set sz [file size $path] @@ -282,7 +281,7 @@ proc start_show_diff {scroll_pos {add_opts {}}} { set ::current_diff_inheader 1 fconfigure $fd \ -blocking 0 \ - -encoding [tcl_encoding [gitattr $path encoding UTF-8]] \ + -encoding [get_path_encoding $path] \ -translation lf fileevent $fd readable [list read_diff $fd $scroll_pos] } @@ -435,8 +434,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]} { @@ -604,8 +604,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/lib/encoding.tcl b/lib/encoding.tcl index 7f06b0d..e186b0c 100644 --- a/lib/encoding.tcl +++ b/lib/encoding.tcl @@ -274,3 +274,17 @@ proc tcl_encoding {enc} { } return {} } + +proc get_path_encoding {path} { + set tcl_enc [tcl_encoding [get_config gui.encoding]] + if {$tcl_enc eq {}} { + set tcl_enc [encoding system] + } + if {$path ne {}} { + set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]] + if {$enc2 ne {}} { + set tcl_enc $enc2 + } + } + return $tcl_enc +} diff --git a/lib/option.tcl b/lib/option.tcl index 9b865f6..40af44e 100644 --- a/lib/option.tcl +++ b/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"}} + {t gui.encoding {mc "Default File Contents Encoding"}} } { set type [lindex $option 0] set name [lindex $option 1] @@ -275,6 +298,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"] } -- cgit v0.10.2-6-g49f6 From 50102c5687db83db48b9705e07de16d07cef7cd9 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 18 Sep 2008 01:07:33 +0400 Subject: git-gui: Add a menu of available encodings. To make encoding selection easier, add a menu that lists available encodings to the Options window. Menu structure is borrowed from Firefox. Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/lib/encoding.tcl b/lib/encoding.tcl index e186b0c..2c1eda3 100644 --- a/lib/encoding.tcl +++ b/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,6 +240,52 @@ 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 tcl_encoding {enc} { global encoding_aliases set names [encoding names] @@ -248,7 +294,7 @@ proc tcl_encoding {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]} { + if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} { set i [lsearch -exact $lcnames $encx] } } @@ -260,7 +306,7 @@ proc tcl_encoding {enc} { foreach e $ll { set i [lsearch -exact $lcnames $e] if {$i < 0} { - if {[regsub {^iso[-_]} $e iso ex]} { + if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} { set i [lsearch -exact $lcnames $ex] } } @@ -288,3 +334,84 @@ proc get_path_encoding {path} { } 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 + } + } + build_encoding_submenu $emenu [list other [mc Other] $unused_grp] $cmd +} diff --git a/lib/option.tcl b/lib/option.tcl index 40af44e..c80c939 100644 --- a/lib/option.tcl +++ b/lib/option.tcl @@ -152,7 +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"}} - {t gui.encoding {mc "Default File Contents Encoding"}} + {c gui.encoding {mc "Default File Contents Encoding"}} } { set type [lindex $option 0] set name [lindex $option 1] @@ -182,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:" @@ -194,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 } } -- cgit v0.10.2-6-g49f6 From 3fe0162362f80262ed1965f19c1f57f298931c94 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 18 Sep 2008 01:07:34 +0400 Subject: git-gui: Allow forcing display encoding for diffs using a submenu. Add a submenu to allow dynamically changing the encoding to use for diffs. Encoding settings are remembered while git-gui runs. The rules are: 1) Encoding set for a specific file overrides gitattributes. 2) Last explicitly set value of the encoding overrides gui.encoding Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index b37148b..03c450d 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -3010,6 +3010,14 @@ proc create_common_diff_popup {ctxm} { -command {incr_font_size font_diff 1} lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] $ctxm add separator + set emenu $ctxm.enc + menu $emenu + build_encoding_menu $emenu [list force_diff_encoding] + $ctxm add cascade \ + -label [mc "Encoding"] \ + -menu $emenu + lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] + $ctxm add separator $ctxm add command -label [mc "Options..."] \ -command do_options } diff --git a/lib/diff.tcl b/lib/diff.tcl index 8fefc5d..b616296 100644 --- a/lib/diff.tcl +++ b/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 diff --git a/lib/encoding.tcl b/lib/encoding.tcl index 2c1eda3..b2ee38c 100644 --- a/lib/encoding.tcl +++ b/lib/encoding.tcl @@ -321,13 +321,38 @@ proc tcl_encoding {enc} { 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} { - set tcl_enc [tcl_encoding [get_config gui.encoding]] + 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 {$tcl_enc eq {}} { set tcl_enc [encoding system] } if {$path ne {}} { - set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]] + 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 } -- cgit v0.10.2-6-g49f6 From a1c3feb7fac7fe90ff8a05779d7db9cf77e79ae1 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 18 Sep 2008 01:07:35 +0400 Subject: git-gui: Optimize encoding name resolution using a lookup table. Encoding menu construction does almost a hundred of encoding resolutions, which with the old implementation led to a small but noticeable delay. Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/lib/encoding.tcl b/lib/encoding.tcl index b2ee38c..32668fc 100644 --- a/lib/encoding.tcl +++ b/lib/encoding.tcl @@ -286,39 +286,63 @@ set encoding_groups { {"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|cp|ibm|jis)[-_]} $enc {\1} encx]} { - set i [lsearch -exact $lcnames $encx] + global encoding_lookup_table + if {$enc eq {}} { + return {} + } + if {![info exists encoding_lookup_table]} { + build_encoding_table } - } - 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|cp|ibm|jis)[-_]} $e {\1} ex]} { - set i [lsearch -exact $lcnames $ex] - } + 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 {$i >= 0} break - } - break } - } - if {$i >= 0} { - return [lindex $names $i] - } - return {} + if {[info exists encoding_lookup_table($enc)]} { + return $encoding_lookup_table($enc) + } else { + return {} + } } proc force_path_encoding {path enc} { -- cgit v0.10.2-6-g49f6 From 6fc835a3f36146006bb33362368cf9d314877e51 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 18 Sep 2008 01:07:36 +0400 Subject: git-gui: Support the encoding menu in gui blame. Allow dynamically changing the encoding from the blame viewer as well. Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/lib/blame.tcl b/lib/blame.tcl index 84d55b5..eb61374 100644 --- a/lib/blame.tcl +++ b/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] @@ -791,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] -- cgit v0.10.2-6-g49f6 From 3e34838caf796e67c057a136d1fdfe1d4286a003 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sat, 20 Sep 2008 12:19:18 +0400 Subject: git-gui: Reenable staging unmerged files by clicking the icon. This restores functionality of the file icon for unmerged files. Safety is enforced by loading the diff and checking for lines that look like conflict markers. If such lines are found, or the conflict involves deletion and/or symlinks, a confirmation dialog is presented. Otherwise, the icon immediately stages the working copy version of the file. Includes a revert of 2fe5b2ee42897a3acc78e5ddaace3775eb2713ca (Restore ability to Stage Working Copy for conflicts) Signed-off-by: Alexander Gavrilov Tested-by: Johannes Sixt Signed-off-by: Shawn O. Pearce diff --git a/git-gui.sh b/git-gui.sh index 03c450d..4085e8f 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1059,6 +1059,7 @@ set current_branch {} set is_detached 0 set current_diff_path {} set is_3way_diff 0 +set is_conflict_diff 0 set selected_commit_type new set nullid "0000000000000000000000000000000000000000" @@ -2078,19 +2079,21 @@ proc toggle_or_diff {w x y} { $ui_index tag remove in_sel 0.0 end $ui_workdir tag remove in_sel 0.0 end - # Do not stage files with conflicts + # Determine the state of the file if {[info exists file_states($path)]} { set state [lindex $file_states($path) 0] } else { set state {__} } - if {[string first {U} $state] >= 0} { - set col 1 - } - # Restage the file, or simply show the diff if {$col == 0 && $y > 1} { + # Conflicts need special handling + if {[string first {U} $state] >= 0} { + merge_stage_workdir $path $w $lno + return + } + if {[string index $state 1] eq {O}} { set mmask {} } else { @@ -3057,11 +3060,6 @@ $ctxmmg add command \ -command {merge_resolve_one 1} lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] $ctxmmg add separator -$ctxmmg add command \ - -label [mc "Stage Working Copy"] \ - -command {merge_resolve_one 0} -lappend diff_actions [list $ctxmmg entryconf [$ctxmmg index last] -state] -$ctxmmg add separator create_common_diff_popup $ctxmmg proc popup_diff_menu {ctxm ctxmmg x y X Y} { diff --git a/lib/diff.tcl b/lib/diff.tcl index b616296..abe502d 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -69,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 @@ -92,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"]] @@ -129,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] @@ -146,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 @@ -228,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 @@ -292,12 +303,12 @@ proc start_show_diff {scroll_pos {add_opts {}}} { -blocking 0 \ -encoding [get_path_encoding $path] \ -translation lf - fileevent $fd readable [list read_diff $fd $scroll_pos] + 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 @@ -345,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 { @@ -364,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 { @@ -388,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 @@ -403,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 + } } } diff --git a/lib/mergetool.tcl b/lib/mergetool.tcl index a44a725..6ab5701 100644 --- a/lib/mergetool.tcl +++ b/lib/mergetool.tcl @@ -5,12 +5,6 @@ proc merge_resolve_one {stage} { global current_diff_path switch -- $stage { - 0 { # Stage without confirmation, to minimize - # disruption of the rerere workflow - merge_add_resolution $current_diff_path - return - } - 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?"] } @@ -29,6 +23,33 @@ This operation can be undone only by restarting the merge." \ } } +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 -- cgit v0.10.2-6-g49f6