git-gui: Cache the GIT_COMMITTER_IDENT value on first sign-off.
[gitweb.git] / git-gui
diff --git a/git-gui b/git-gui
index 1b1ffee5ea3edb5b90fbc866e01e52fa51043c11..ad3aa0727c55a8e62609cec658108e7ecf3dedd6 100755 (executable)
--- a/git-gui
+++ b/git-gui
@@ -1398,19 +1398,28 @@ proc do_include_all {} {
        }
 }
 
+set GIT_COMMITTER_IDENT {}
+
 proc do_signoff {} {
-       global ui_comm
+       global ui_comm GIT_COMMITTER_IDENT
 
-       catch {
-               set me [exec git var GIT_COMMITTER_IDENT]
-               if {[regexp {(.*) [0-9]+ [-+0-9]+$} $me me name]} {
-                       set str "Signed-off-by: $name"
-                       if {[$ui_comm get {end -1c linestart} {end -1c}] != $str} {
-                               $ui_comm insert end "\n"
-                               $ui_comm insert end $str
-                               $ui_comm see end
-                       }
+       if {$GIT_COMMITTER_IDENT == {}} {
+               if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
+                       error_popup "Unable to obtain your identity:\n$err"
+                       return
                }
+               if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
+                       $me me GIT_COMMITTER_IDENT]} {
+                       error_popup "Invalid GIT_COMMITTER_IDENT:\n$me"
+                       return
+               }
+       }
+
+       set str "Signed-off-by: $GIT_COMMITTER_IDENT"
+       if {[$ui_comm get {end -1c linestart} {end -1c}] != $str} {
+               $ui_comm insert end "\n"
+               $ui_comm insert end $str
+               $ui_comm see end
        }
 }