git-gui: avoid persisting modified author identity

Commit 7e71adc77f fixes a problem with git-gui failing to pick up the original author identity during a commit --amend operation. However, the new author details then become persistent for the remainder of the session. This commit fixes this by ensuring the environment variables are reset and the author information reset once the commit is completed. The relevant changes were reworked to reduce global variables. Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>

Pat Thoyts committed Oct 6, 2016 at 14:04 UTC cfe616bcb14a4574235d301f5e6b12efeda9768d
1 file changed +31 -20
lib/commit.tcl
+31 -20
@@ -1,13 +1,8 @@
1 # git-gui misc. commit reading/writing support
2 # Copyright (C) 2006, 2007 Shawn Pearce
3
4 -set author_name ""
5 -set author_email ""
6 -set author_date ""
7 -
4 proc load_last_commit {} {
9 - global HEAD PARENT MERGE_HEAD commit_type ui_comm
10 - global author_name author_email author_date
5 + global HEAD PARENT MERGE_HEAD commit_type ui_comm commit_author
6 global repo_config
7
8 if {[llength $PARENT] == 0} {
@@ -40,9 +35,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
35 } elseif {[string match {encoding *} $line]} {
36 set enc [string tolower [string range $line 9 end]]
37 } elseif {[regexp "author (.*)\\s<(.*)>\\s(\\d.*$)" $line all name email time]} {
43 - set author_name $name
44 - set author_email $email
45 - set author_date $time
38 + set commit_author [list name $name email $email date $time]
39 }
40 }
41 set msg [read $fd]
@@ -115,13 +108,10 @@ proc do_signoff {} {
108 }
109
110 proc create_new_commit {} {
118 - global commit_type ui_comm
119 - global author_name author_email author_date
111 + global commit_type ui_comm commit_author
112
113 set commit_type normal
122 - set author_name ""
123 - set author_email ""
124 - set author_date ""
114 + unset -nocomplain commit_author
115 $ui_comm delete 0.0 end
116 $ui_comm edit reset
117 $ui_comm edit modified false
@@ -335,12 +325,12 @@ proc commit_writetree {curHEAD msg_p} {
325 }
326
327 proc commit_committree {fd_wt curHEAD msg_p} {
338 - global HEAD PARENT MERGE_HEAD commit_type
328 + global HEAD PARENT MERGE_HEAD commit_type commit_author
329 global current_branch
330 global ui_comm selected_commit_type
331 global file_states selected_paths rescan_active
332 global repo_config
343 - global env author_name author_email author_date
333 + global env
334
335 gets $fd_wt tree_id
336 if {[catch {close $fd_wt} err]} {
@@ -380,10 +370,8 @@ A rescan will be automatically started now.
370 }
371 }
372
383 - if {$author_name ne ""} {
384 - set env(GIT_AUTHOR_NAME) $author_name
385 - set env(GIT_AUTHOR_EMAIL) $author_email
386 - set env(GIT_AUTHOR_DATE) $author_date
373 + if {[info exists commit_author]} {
374 + set old_author [commit_author_ident $commit_author]
375 }
376 # -- Create the commit.
377 #
@@ -397,8 +385,14 @@ A rescan will be automatically started now.
385 error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"]
386 ui_status [mc "Commit failed."]
387 unlock_index
388 + unset -nocomplain commit_author
389 + commit_author_reset $old_author
390 return
391 }
392 + if {[info exists commit_author]} {
393 + unset -nocomplain commit_author
394 + commit_author_reset $old_author
395 + }
396
397 # -- Update the HEAD ref.
398 #
@@ -525,3 +519,20 @@ proc commit_postcommit_wait {fd_ph cmt_id} {
519 }
520 fconfigure $fd_ph -blocking 0
521 }
522 +
523 +proc commit_author_ident {details} {
524 + global env
525 + array set author $details
526 + set old [array get env GIT_AUTHOR_*]
527 + set env(GIT_AUTHOR_NAME) $author(name)
528 + set env(GIT_AUTHOR_EMAIL) $author(email)
529 + set env(GIT_AUTHOR_DATE) $author(date)
530 + return $old
531 +}
532 +proc commit_author_reset {details} {
533 + global env
534 + unset env(GIT_AUTHOR_NAME) env(GIT_AUTHOR_EMAIL) env(GIT_AUTHOR_DATE)
535 + if {$details ne {}} {
536 + array set env $details
537 + }
538 +}