{"thread":{"id":"34914","subject":"[PATCH] git-gui: Modify push dialog to support Gerrit review","startedAt":"2013-09-12T09:21:40Z","lastAt":"2013-09-12T09:21:40Z","messageCount":1,"participants":["Joergen Edelbo"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"227515","messageId":"20130912093535.421691218BA@jed-dev-01.labnet","threadId":"34914","inReplyTo":null,"subject":"[PATCH] git-gui: Modify push dialog to support Gerrit review","fromName":"Joergen Edelbo","fromEmail":"jed@napatech.com","sentAt":"2013-09-12T09:21:40Z","receivedAt":"2013-09-12T09:21:40Z","isPatch":true,"sender":{"key":"jed@napatech.com","avatar":null},"body":"Problem: It is not possible to push for Gerrit review as you will\nalways try to push to \"refs/heads/...\" on the remote.\n\nChanges done:\n\nAdd an option in the Push dialog to select \"Gerrit review\" and a\ncorresponding entry for a branch name. If this option is selected,\npush the changes to \"refs/for/<gerrit-branch>/<local branch>\". In\nthis way the local branch names will be used as topic branches on\nGerrit.\n\nIf you are on a detached HEAD, then add a \"HEAD\" entry in the branch\nselection list. If this is selected, push HEAD:HEAD in the normal\ncase and HEAD:refs/for/<gerrit_branch> in the Gerrit case.\n\nThe Gerrit branch to push to is controlled by gerrit.reviewbranch\nconfiguration option.\n---\nHi again,\n\nSeems like this discussion has died out. Is there no perspective in\nchanging git-gui to support Gerrit better?\n\nAnyway here is what I consider my final shot at a solution. Compared\nto the last one, this commit can handle the case when you work on a \ndetached HEAD, and the Gerrit branch to push to is handled by a\nconfiguration option.\n\nBR JÃ¸rgen Edelbo\n\n git-gui.sh        |    1 +\n lib/option.tcl    |    1 +\n lib/transport.tcl |   48 +++++++++++++++++++++++++++++++++++++++++++++---\n 3 files changed, 47 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui.sh b/git-gui.sh\nindex b62ae4a..3228654 100755\n--- a/git-gui.sh\n+++ b/git-gui.sh\n@@ -901,6 +901,7 @@ set default_config(gui.diffcontext) 5\n set default_config(gui.diffopts) {}\n set default_config(gui.commitmsgwidth) 75\n set default_config(gui.newbranchtemplate) {}\n+set default_config(gerrit.reviewbranch) {}\n set default_config(gui.spellingdictionary) {}\n set default_config(gui.fontui) [font configure font_ui]\n set default_config(gui.fontdiff) [font configure font_diff]\ndiff --git a/lib/option.tcl b/lib/option.tcl\nindex 23c9ae7..ffa4226 100644\n--- a/lib/option.tcl\n+++ b/lib/option.tcl\n@@ -157,6 +157,7 @@ proc do_options {} {\n \t\t{t gui.diffopts {mc \"Additional Diff Parameters\"}}\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{t gerrit.reviewbranch {mc \"Gerrit Review Branch\"}}\n \t\t{c gui.encoding {mc \"Default File Contents Encoding\"}}\n \t\t{b gui.warndetachedcommit {mc \"Warn before committing to a detached head\"}}\n \t\t{s gui.stageuntracked {mc \"Staging of untracked files\"} {list \"yes\" \"no\" \"ask\"}}\ndiff --git a/lib/transport.tcl b/lib/transport.tcl\nindex e5d211e..9b1cfc5 100644\n--- a/lib/transport.tcl\n+++ b/lib/transport.tcl\n@@ -61,6 +61,7 @@ proc push_to {remote} {\n \n proc start_push_anywhere_action {w} {\n \tglobal push_urltype push_remote push_url push_thin push_tags\n+\tglobal gerrit_review gerrit_branch\n \tglobal push_force\n \tglobal repo_config\n \n@@ -95,7 +96,19 @@ proc start_push_anywhere_action {w} {\n \t\tset cnt 0\n \t\tforeach i [$w.source.l curselection] {\n \t\t\tset b [$w.source.l get $i]\n-\t\t\tlappend cmd \"refs/heads/$b:refs/heads/$b\"\n+\t\t\tif {$gerrit_review && $gerrit_branch ne {}} {\n+\t\t\t\tswitch $b {\n+\t\t\t\t$gerrit_branch\t{ lappend cmd \"refs/heads/$b:refs/for/$gerrit_branch\" }\n+\t\t\t\tHEAD\t\t{ lappend cmd \"HEAD:refs/for/$gerrit_branch\" }\n+\t\t\t\tdefault\t\t{ lappend cmd \"refs/heads/$b:refs/for/$gerrit_branch/$b\" }\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tif {$b eq HEAD} {\n+\t\t\t\t\tlappend cmd \"HEAD:HEAD\"\n+\t\t\t\t} else {\n+\t\t\t\t\tlappend cmd \"refs/heads/$b:refs/heads/$b\"\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tincr cnt\n \t\t}\n \t\tif {$cnt == 0} {\n@@ -118,9 +131,10 @@ trace add variable push_remote write \\\n \t[list radio_selector push_urltype remote]\n \n proc do_push_anywhere {} {\n-\tglobal all_remotes current_branch\n+\tglobal all_remotes current_branch is_detached\n \tglobal push_urltype push_remote push_url push_thin push_tags\n-\tglobal push_force use_ttk NS\n+\tglobal gerrit_review gerrit_branch\n+\tglobal push_force use_ttk NS repo_config\n \n \tset w .push_setup\n \ttoplevel $w\n@@ -149,6 +163,11 @@ proc do_push_anywhere {} {\n \t\t-height 10 \\\n \t\t-width 70 \\\n \t\t-selectmode extended\n+\tif {$is_detached} {\n+\t\t$w.source.l insert end HEAD\n+\t\t$w.source.l select set end\n+\t\t$w.source.l yview end\n+\t}\n \tforeach h [load_all_heads] {\n \t\t$w.source.l insert end $h\n \t\tif {$h eq $current_branch} {\n@@ -215,13 +234,36 @@ proc do_push_anywhere {} {\n \t\t-text [mc \"Include tags\"] \\\n \t\t-variable push_tags\n \tgrid $w.options.tags -columnspan 2 -sticky w\n+\t${NS}::checkbutton $w.options.gerrit \\\n+\t\t-text [mc \"Gerrit review.  Branch: \"] \\\n+\t\t-variable gerrit_review\n+\t${NS}::entry $w.options.gerrit_br \\\n+\t\t-width 50 \\\n+\t\t-textvariable gerrit_branch \\\n+\t\t-validate key \\\n+\t\t-validatecommand {\n+\t\t\tif {%d == 1 && [regexp {\\s} %S]} {return 0}\n+\t\t\tif {%d == 1 && [string length %S] > 0} {\n+\t\t\t\tset gerrit_review 1\n+\t\t\t}\n+\t\t\tif {[string length %P] == 0} {\n+\t\t\t\tset gerrit_review 0\n+\t\t\t}\n+\t\t\treturn 1\n+\t\t}\n+\tgrid $w.options.gerrit $w.options.gerrit_br -sticky we -padx {0 5}\n \tgrid columnconfigure $w.options 1 -weight 1\n \tpack $w.options -anchor nw -fill x -pady 5 -padx 5\n \n+\tif ![info exists gerrit_branch] { \n+\t\tset gerrit_branch {}\n+\t\tcatch {set gerrit_branch $repo_config(gerrit.reviewbranch)}\n+\t}\n \tset push_url {}\n \tset push_force 0\n \tset push_thin 0\n \tset push_tags 0\n+\tset gerrit_review [expr {$gerrit_branch ne {}}]\n \n \tbind $w <Visibility> \"grab $w; focus $w.buttons.create\"\n \tbind $w <Key-Escape> \"destroy $w\"\n-- \n1.7.9.5\n"}]}