Skip to content

Commit bfe4344

Browse files
committed
Merge branch 'os/preserve-author' into pu
2 parents be44aee + cfe616b commit bfe4344

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

lib/commit.tcl

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (C) 2006, 2007 Shawn Pearce
33

44
proc load_last_commit {} {
5-
global HEAD PARENT MERGE_HEAD commit_type ui_comm
5+
global HEAD PARENT MERGE_HEAD commit_type ui_comm commit_author
66
global repo_config
77

88
if {[llength $PARENT] == 0} {
@@ -34,6 +34,8 @@ You are currently in the middle of a merge that has not been fully completed. Y
3434
lappend parents [string range $line 7 end]
3535
} elseif {[string match {encoding *} $line]} {
3636
set enc [string tolower [string range $line 9 end]]
37+
} elseif {[regexp "author (.*)\\s<(.*)>\\s(\\d.*$)" $line all name email time]} {
38+
set commit_author [list name $name email $email date $time]
3739
}
3840
}
3941
set msg [read $fd]
@@ -106,9 +108,10 @@ proc do_signoff {} {
106108
}
107109

108110
proc create_new_commit {} {
109-
global commit_type ui_comm
111+
global commit_type ui_comm commit_author
110112

111113
set commit_type normal
114+
unset -nocomplain commit_author
112115
$ui_comm delete 0.0 end
113116
$ui_comm edit reset
114117
$ui_comm edit modified false
@@ -322,11 +325,12 @@ proc commit_writetree {curHEAD msg_p} {
322325
}
323326

324327
proc commit_committree {fd_wt curHEAD msg_p} {
325-
global HEAD PARENT MERGE_HEAD commit_type
328+
global HEAD PARENT MERGE_HEAD commit_type commit_author
326329
global current_branch
327330
global ui_comm selected_commit_type
328331
global file_states selected_paths rescan_active
329332
global repo_config
333+
global env
330334

331335
gets $fd_wt tree_id
332336
if {[catch {close $fd_wt} err]} {
@@ -366,6 +370,9 @@ A rescan will be automatically started now.
366370
}
367371
}
368372

373+
if {[info exists commit_author]} {
374+
set old_author [commit_author_ident $commit_author]
375+
}
369376
# -- Create the commit.
370377
#
371378
set cmd [list commit-tree $tree_id]
@@ -381,8 +388,14 @@ A rescan will be automatically started now.
381388
error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"]
382389
ui_status [mc "Commit failed."]
383390
unlock_index
391+
unset -nocomplain commit_author
392+
commit_author_reset $old_author
384393
return
385394
}
395+
if {[info exists commit_author]} {
396+
unset -nocomplain commit_author
397+
commit_author_reset $old_author
398+
}
386399

387400
# -- Update the HEAD ref.
388401
#
@@ -509,3 +522,20 @@ proc commit_postcommit_wait {fd_ph cmt_id} {
509522
}
510523
fconfigure $fd_ph -blocking 0
511524
}
525+
526+
proc commit_author_ident {details} {
527+
global env
528+
array set author $details
529+
set old [array get env GIT_AUTHOR_*]
530+
set env(GIT_AUTHOR_NAME) $author(name)
531+
set env(GIT_AUTHOR_EMAIL) $author(email)
532+
set env(GIT_AUTHOR_DATE) $author(date)
533+
return $old
534+
}
535+
proc commit_author_reset {details} {
536+
global env
537+
unset env(GIT_AUTHOR_NAME) env(GIT_AUTHOR_EMAIL) env(GIT_AUTHOR_DATE)
538+
if {$details ne {}} {
539+
array set env $details
540+
}
541+
}

0 commit comments

Comments
 (0)