Class: GitCommitMailer
- Inherits:
-
Object
show all
- Defined in:
- lib/git-commit-mailer/info.rb,
lib/git-commit-mailer.rb,
lib/git-commit-mailer/version.rb,
lib/git-commit-mailer/file-diff.rb,
lib/git-commit-mailer/push-info.rb,
lib/git-commit-mailer/commit-info.rb,
lib/git-commit-mailer/mail-body-formatter.rb,
lib/git-commit-mailer/html-mail-body-formatter.rb,
lib/git-commit-mailer/text-mail-body-formatter.rb
Overview
Copyright © 2009 Ryo Onodera <[email protected]> Copyright © 2012-2014 Kouhei Sutou <[email protected]>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.
Defined Under Namespace
Classes: CommitInfo, FileDiff, HTMLMailBodyFormatter, Info, MailBodyFormatter, NoParentCommit, PushInfo, TextMailBodyFormatter
Constant Summary
collapse
- KILO_SIZE =
1000
- DEFAULT_MAX_SIZE =
"100M"
- VERSION =
"1.0.0"
- URL =
"https://github.com/clear-code/git-commit-mailer"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GitCommitMailer.
525
526
527
|
# File 'lib/git-commit-mailer.rb', line 525
def initialize(to)
@to = to
end
|
Instance Attribute Details
#add_diff=(value) ⇒ Object
Sets the attribute add_diff
515
516
517
|
# File 'lib/git-commit-mailer.rb', line 515
def add_diff=(value)
@add_diff = value
end
|
#add_html=(value) ⇒ Object
Sets the attribute add_html
515
516
517
|
# File 'lib/git-commit-mailer.rb', line 515
def add_html=(value)
@add_html = value
end
|
#date ⇒ Object
574
575
576
|
# File 'lib/git-commit-mailer.rb', line 574
def date
@date || Time.now
end
|
#from(info) ⇒ Object
557
558
559
560
561
562
563
564
565
566
567
568
|
# File 'lib/git-commit-mailer.rb', line 557
def from(info)
if @from
if /\A[^\s<]+@[^\s>]\z/ =~ @from
@from
else
"#{info.author_name} <#{@from}>"
end
else
"#{info.author_name} <#{info.author_email}>"
end
end
|
#from_domain ⇒ Object
Returns the value of attribute from_domain.
517
518
519
|
# File 'lib/git-commit-mailer.rb', line 517
def from_domain
@from_domain
end
|
#git_bin_path ⇒ Object
578
579
580
|
# File 'lib/git-commit-mailer.rb', line 578
def git_bin_path
ENV['GIT_BIN_PATH'] || @git_bin_path
end
|
#github_base_url ⇒ Object
Returns the value of attribute github_base_url.
520
521
522
|
# File 'lib/git-commit-mailer.rb', line 520
def github_base_url
@github_base_url
end
|
#github_repository ⇒ Object
Returns the value of attribute github_repository.
520
521
522
|
# File 'lib/git-commit-mailer.rb', line 520
def github_repository
@github_repository
end
|
#github_user ⇒ Object
Returns the value of attribute github_user.
520
521
522
|
# File 'lib/git-commit-mailer.rb', line 520
def github_user
@github_user
end
|
#gitlab_project_uri ⇒ Object
Returns the value of attribute gitlab_project_uri.
521
522
523
|
# File 'lib/git-commit-mailer.rb', line 521
def gitlab_project_uri
@gitlab_project_uri
end
|
#max_diff_size ⇒ Object
Returns the value of attribute max_diff_size.
517
518
519
|
# File 'lib/git-commit-mailer.rb', line 517
def max_diff_size
@max_diff_size
end
|
#max_size ⇒ Object
Returns the value of attribute max_size.
517
518
519
|
# File 'lib/git-commit-mailer.rb', line 517
def max_size
@max_size
end
|
#name=(value) ⇒ Object
522
523
524
|
# File 'lib/git-commit-mailer.rb', line 522
def name=(value)
@name = value
end
|
#new_revision ⇒ Object
Returns the value of attribute new_revision.
513
514
515
|
# File 'lib/git-commit-mailer.rb', line 513
def new_revision
@new_revision
end
|
#old_revision ⇒ Object
Returns the value of attribute old_revision.
513
514
515
|
# File 'lib/git-commit-mailer.rb', line 513
def old_revision
@old_revision
end
|
#port ⇒ Object
Returns the value of attribute port.
518
519
520
|
# File 'lib/git-commit-mailer.rb', line 518
def port
@port
end
|
#reference ⇒ Object
Returns the value of attribute reference.
513
514
515
|
# File 'lib/git-commit-mailer.rb', line 513
def reference
@reference
end
|
#repository ⇒ Object
570
571
572
|
# File 'lib/git-commit-mailer.rb', line 570
def repository
@repository || Dir.pwd
end
|
#repository_browser ⇒ Object
Returns the value of attribute repository_browser.
519
520
521
|
# File 'lib/git-commit-mailer.rb', line 519
def repository_browser
@repository_browser
end
|
#repository_uri ⇒ Object
Returns the value of attribute repository_uri.
517
518
519
|
# File 'lib/git-commit-mailer.rb', line 517
def repository_uri
@repository_uri
end
|
Returns the value of attribute rss_path.
518
519
520
|
# File 'lib/git-commit-mailer.rb', line 518
def
@rss_path
end
|
Returns the value of attribute rss_uri.
518
519
520
|
# File 'lib/git-commit-mailer.rb', line 518
def
@rss_uri
end
|
#send_per_to=(value) ⇒ Object
Sets the attribute send_per_to
514
515
516
|
# File 'lib/git-commit-mailer.rb', line 514
def send_per_to=(value)
@send_per_to = value
end
|
#send_push_mail=(value) ⇒ Object
Sets the attribute send_push_mail
515
516
517
|
# File 'lib/git-commit-mailer.rb', line 515
def send_push_mail=(value)
@send_push_mail = value
end
|
#sender ⇒ Object
Returns the value of attribute sender.
517
518
519
|
# File 'lib/git-commit-mailer.rb', line 517
def sender
@sender
end
|
#server ⇒ Object
Returns the value of attribute server.
518
519
520
|
# File 'lib/git-commit-mailer.rb', line 518
def server
@server
end
|
#show_path=(value) ⇒ Object
Sets the attribute show_path
515
516
517
|
# File 'lib/git-commit-mailer.rb', line 515
def show_path=(value)
@show_path = value
end
|
#sleep_per_mail ⇒ Object
Returns the value of attribute sleep_per_mail.
523
524
525
|
# File 'lib/git-commit-mailer.rb', line 523
def sleep_per_mail
@sleep_per_mail
end
|
#to ⇒ Object
Returns the value of attribute to.
513
514
515
|
# File 'lib/git-commit-mailer.rb', line 513
def to
@to
end
|
#track_remote=(value) ⇒ Object
Sets the attribute track_remote
516
517
518
|
# File 'lib/git-commit-mailer.rb', line 516
def track_remote=(value)
@track_remote = value
end
|
#verbose=(value) ⇒ Object
Sets the attribute verbose
522
523
524
|
# File 'lib/git-commit-mailer.rb', line 522
def verbose=(value)
@verbose = value
end
|
Class Method Details
.execute(command, working_directory = nil, &block) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/git-commit-mailer.rb', line 65
def execute(command, working_directory=nil, &block)
if ENV["DEBUG"]
suppress_stderr = ""
else
suppress_stderr = " 2> /dev/null"
end
script = "#{command} #{suppress_stderr}"
puts script if ENV["DEBUG"]
result = nil
with_working_direcotry(working_directory) do
if block_given?
IO.popen(script, "w+", &block)
else
result = `#{script} 2>&1`
end
end
raise "execute failed: #{command}\n#{result}" unless $?.exitstatus.zero?
result.force_encoding("UTF-8") if result.respond_to?(:force_encoding)
result
end
|
119
120
121
122
123
124
125
|
# File 'lib/git-commit-mailer.rb', line 119
def (address)
if /<(.+?)>/ =~ address
$1
else
address
end
end
|
127
128
129
130
131
132
133
134
|
# File 'lib/git-commit-mailer.rb', line 127
def (mail)
begin
= mail.lines.grep(/\AFrom: .*\Z/)[0]
(.rstrip.sub(/From: /, ""))
rescue
raise '"From:" header is not found in mail.'
end
end
|
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/git-commit-mailer.rb', line 136
def (mail)
to_value = nil
if /^To:(.*\r?\n(?:^\s+.*)*)/ni =~ mail
to_value = $1
else
raise "'To:' header is not found in mail:\n#{mail}"
end
= to_value.gsub(/".*?"/n, "")
.split(/\s*,\s*/n).collect do |address|
(address.strip)
end
end
|
180
181
182
183
184
185
186
187
188
189
|
# File 'lib/git-commit-mailer.rb', line 180
def format_size(size)
return "no limit" if size.nil?
return "#{size}B" if size < KILO_SIZE
size /= KILO_SIZE.to_f
return "#{size}KB" if size < KILO_SIZE
size /= KILO_SIZE.to_f
return "#{size}MB" if size < KILO_SIZE
size /= KILO_SIZE.to_f
"#{size}GB"
end
|
.git(git_bin_path, repository, command, &block) ⇒ Object
108
109
110
111
112
113
|
# File 'lib/git-commit-mailer.rb', line 108
def git(git_bin_path, repository, command, &block)
$executing_git ||= SpentTime.new("executing git commands")
$executing_git.spend do
execute("#{git_bin_path} --git-dir=#{shell_escape(repository)} #{command}", &block)
end
end
|
.parse(argv) ⇒ Object
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/git-commit-mailer.rb', line 169
def parse(argv)
options = make_options
parser = make_parser(options)
argv = argv.dup
parser.parse!(argv)
to = argv
[to, options]
end
|
.parse_options_and_create(argv = nil) ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/git-commit-mailer.rb', line 160
def parse_options_and_create(argv=nil)
argv ||= ARGV
to, options = parse(argv)
to += options.to
mailer = new(to.compact)
apply_options(mailer, options)
mailer
end
|
.send_mail(server, port, from, to, mail) ⇒ Object
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/git-commit-mailer.rb', line 149
def send_mail(server, port, from, to, mail)
$sending_mail ||= SpentTime.new("sending mails")
$sending_mail.spend do
Net::SMTP.start(server, port) do |smtp|
smtp.open_message_stream(from, to) do |f|
f.print(mail)
end
end
end
end
|
.shell_escape(string) ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/git-commit-mailer.rb', line 97
def shell_escape(string)
if string.respond_to? :force_encoding
bytes = string.dup.force_encoding("ascii-8bit")
else
bytes = string
end
Shellwords.escape(bytes)
end
|
.short_revision(revision) ⇒ Object
115
116
117
|
# File 'lib/git-commit-mailer.rb', line 115
def short_revision(revision)
revision[0, 7]
end
|
.with_working_direcotry(working_directory) ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'lib/git-commit-mailer.rb', line 87
def with_working_direcotry(working_directory)
if working_directory
Dir.chdir(working_directory) do
yield
end
else
yield
end
end
|
.x_mailer ⇒ Object
61
62
63
|
# File 'lib/git-commit-mailer.rb', line 61
def x_mailer
"#{name} #{VERSION}; #{URL}"
end
|
Instance Method Details
#add_diff? ⇒ Boolean
1143
1144
1145
|
# File 'lib/git-commit-mailer.rb', line 1143
def add_diff?
@add_diff
end
|
#add_html? ⇒ Boolean
1147
1148
1149
|
# File 'lib/git-commit-mailer.rb', line 1147
def add_html?
@add_html
end
|
#annotated_tag_content ⇒ Object
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
|
# File 'lib/git-commit-mailer.rb', line 939
def annotated_tag_content
message = ''
tagger = git("for-each-ref --format='%(taggername)' #{@reference}").strip
tagged = git("for-each-ref --format='%(taggerdate:rfc2822)' #{@reference}").strip
message << " tagged by #{tagger}\n"
message << " on #{format_time(Time.rfc2822(tagged))}\n\n"
tag_content = git("cat-file tag #{@new_revision}").split("\n")
tag_content.shift while not tag_content.first.empty?
tag_content.shift
message << tag_content.join("\n") + "\n"
message
end
|
#collect_new_commits ⇒ Object
836
837
838
839
840
841
842
843
|
# File 'lib/git-commit-mailer.rb', line 836
def collect_new_commits
commits = []
git("rev-list #{@old_revision}..#{@new_revision} #{excluded_revisions}").lines.
reverse_each do |revision|
commits << revision.strip
end
commits
end
|
699
700
701
702
703
704
705
706
|
# File 'lib/git-commit-mailer.rb', line 699
def collect_push_information
change_type = detect_change_type
revision_type = detect_revision_type(change_type)
reference_type = detect_reference_type(revision_type)
messsage, commits = make_push_message(reference_type, change_type)
[reference_type, change_type, messsage, commits]
end
|
#create_commit_info(*args) ⇒ Object
533
534
535
|
# File 'lib/git-commit-mailer.rb', line 533
def create_commit_info(*args)
CommitInfo.new(self, *args)
end
|
#create_push_info(*args) ⇒ Object
529
530
531
|
# File 'lib/git-commit-mailer.rb', line 529
def create_push_info(*args)
PushInfo.new(self, *args)
end
|
608
609
610
611
612
613
|
# File 'lib/git-commit-mailer.rb', line 608
def delete_tags
git("rev-parse --symbolic --tags").lines.each do |reference|
reference.rstrip!
git("tag -d %s" % GitCommitMailer.shell_escape(reference))
end
end
|
#detect_change_type ⇒ Object
638
639
640
641
642
643
644
645
646
647
648
649
650
|
# File 'lib/git-commit-mailer.rb', line 638
def detect_change_type
if old_revision =~ /0{40}/ and new_revision =~ /0{40}/
raise "Invalid revision hash"
elsif old_revision !~ /0{40}/ and new_revision !~ /0{40}/
:update
elsif old_revision =~ /0{40}/
:create
elsif new_revision =~ /0{40}/
:delete
else
raise "Invalid revision hash"
end
end
|
#detect_object_type(object_name) ⇒ Object
652
653
654
|
# File 'lib/git-commit-mailer.rb', line 652
def detect_object_type(object_name)
git("cat-file -t #{object_name}").strip
end
|
#detect_reference_type(revision_type) ⇒ Object
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
# File 'lib/git-commit-mailer.rb', line 665
def detect_reference_type(revision_type)
if reference =~ /refs\/tags\/.*/ and revision_type == "commit"
:unannotated_tag
elsif reference =~ /refs\/tags\/.*/ and revision_type == "tag"
:annotated_tag
elsif reference =~ /refs\/(heads|remotes\/origin)\/.*/ and revision_type == "commit"
:branch
elsif reference =~ /refs\/remotes\/.*/ and revision_type == "commit"
throw :no_email
else
raise "Unknown type of update to #@reference (#{revision_type})"
end
end
|
#detect_revision_type(change_type) ⇒ Object
656
657
658
659
660
661
662
663
|
# File 'lib/git-commit-mailer.rb', line 656
def detect_revision_type(change_type)
case change_type
when :create, :update
detect_object_type(new_revision)
when :delete
detect_object_type(old_revision)
end
end
|
#determine_prominent_author ⇒ Object
1065
1066
1067
1068
1069
1070
|
# File 'lib/git-commit-mailer.rb', line 1065
def determine_prominent_author
end
|
#excluded_revisions ⇒ Object
708
709
710
711
712
713
714
715
716
717
718
|
# File 'lib/git-commit-mailer.rb', line 708
def excluded_revisions
current_reference_revision = git("rev-parse #@reference").strip
git("rev-parse --not --branches --remotes").lines.find_all do |line|
line.strip!
not line.index(current_reference_revision)
end.collect do |line|
GitCommitMailer.shell_escape(line)
end.join(' ')
end
|
#explain_rewind ⇒ Object
741
742
743
744
745
746
747
748
749
750
751
752
753
|
# File 'lib/git-commit-mailer.rb', line 741
def explain_rewind
<<EOF
This update discarded existing revisions and left the branch pointing at
a previous point in the repository history.
* -- * -- N (#{short_new_revision})
\\
O <- O <- O (#{short_old_revision})
The removed revisions are not necessarilly gone - if another reference
still refers to them they will stay in the repository.
EOF
end
|
#explain_rewind_and_new_commits ⇒ Object
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
|
# File 'lib/git-commit-mailer.rb', line 755
def explain_rewind_and_new_commits
<<EOF
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B <- O <- O <- O (#{short_old_revision})
\\
N -> N -> N (#{short_new_revision})
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
EOF
end
|
#explain_special_case ⇒ Object
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
|
# File 'lib/git-commit-mailer.rb', line 812
def explain_special_case
baserev = git("merge-base #{@old_revision} #{@new_revision}").strip
rewind_only = false
if baserev == new_revision
explanation = explain_rewind
rewind_only = true
else
explanation = explain_rewind_and_new_commits
end
[rewind_only, explanation]
end
|
#fetch ⇒ Object
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
|
# File 'lib/git-commit-mailer.rb', line 615
def fetch
updated_references = []
old_references = origin_references
delete_tags
git("fetch --force --tags")
git("fetch --force")
new_references = origin_references
old_references.each do |reference, revision|
if revision != new_references[reference]
updated_references << [revision, new_references[reference], reference]
end
end
new_references.each do |reference, revision|
if revision != old_references[reference] updated_references << [old_references[reference], revision, reference]
end
end
updated_references.sort do |reference_change1, reference_change2|
reference_change1.last <=> reference_change2.last
end.uniq
end
|
#find_branch_name_from_its_descendant_revision(revision) ⇒ Object
1010
1011
1012
1013
1014
1015
1016
|
# File 'lib/git-commit-mailer.rb', line 1010
def find_branch_name_from_its_descendant_revision(revision)
begin
name = git("name-rev --name-only --refs refs/heads/* #{revision}").strip
revision = parent_commit(revision)
end until name.sub(/([~^][0-9]+)*\z/, '') == name
name
end
|
1159
1160
1161
|
# File 'lib/git-commit-mailer.rb', line 1159
def format_time(time)
time.strftime('%Y-%m-%d %X %z (%a, %d %b %Y)')
end
|
#get_record(revision, record) ⇒ Object
541
542
543
|
# File 'lib/git-commit-mailer.rb', line 541
def get_record(revision, record)
get_records(revision, [record]).first
end
|
#get_records(revision, records) ⇒ Object
545
546
547
548
549
550
551
|
# File 'lib/git-commit-mailer.rb', line 545
def get_records(revision, records)
GitCommitMailer.git(git_bin_path, @repository,
"log -n 1 --pretty=format:'#{records.join('%n')}%n' " +
"#{revision}").lines.collect do |line|
line.strip
end
end
|
#git(command, &block) ⇒ Object
537
538
539
|
# File 'lib/git-commit-mailer.rb', line 537
def git(command, &block)
GitCommitMailer.git(git_bin_path, @repository, command, &block)
end
|
#make_infos ⇒ Object
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
|
# File 'lib/git-commit-mailer.rb', line 1082
def make_infos
catch(:no_email) do
@push_info = create_push_info(old_revision, new_revision, reference,
*collect_push_information)
if @push_info.branch_changed?
@push_info.commits.each do |revision|
commit_info = create_commit_info(reference, revision)
@commit_infos << commit_info
@commit_info_map[revision] = commit_info
end
end
end
post_process_infos
end
|
#make_mails ⇒ Object
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
|
# File 'lib/git-commit-mailer.rb', line 1098
def make_mails
if send_per_to?
@push_mails = @to.collect do |to|
make_mail(@push_info, [to])
end
else
@push_mails = [make_mail(@push_info, @to)]
end
@commit_mails = []
@commit_infos.each do |info|
if send_per_to?
@to.each do |to|
@commit_mails << make_mail(info, [to])
end
else
@commit_mails << make_mail(info, @to)
end
end
end
|
#make_push_message(reference_type, change_type) ⇒ Object
687
688
689
690
691
692
693
694
695
696
697
|
# File 'lib/git-commit-mailer.rb', line 687
def make_push_message(reference_type, change_type)
unless [:branch, :annotated_tag, :unannotated_tag].include?(reference_type)
raise "unexpected reference_type"
end
unless [:update, :create, :delete].include?(change_type)
raise "unexpected change_type"
end
method_name = "process_#{change_type}_#{reference_type}"
__send__(method_name)
end
|
#origin_references ⇒ Object
598
599
600
601
602
603
604
605
606
|
# File 'lib/git-commit-mailer.rb', line 598
def origin_references
references = Hash.new("0" * 40)
git("rev-parse --symbolic-full-name --tags --remotes").lines.each do |reference|
reference.rstrip!
next if reference =~ %r!\Arefs/remotes! and reference !~ %r!\Arefs/remotes/origin!
references[reference] = git("rev-parse %s" % GitCommitMailer.shell_escape(reference)).rstrip
end
references
end
|
#parent_commit(revision) ⇒ Object
921
922
923
924
925
926
927
|
# File 'lib/git-commit-mailer.rb', line 921
def parent_commit(revision)
begin
git("rev-parse #{revision}^").strip
rescue
raise NoParentCommit
end
end
|
#post_process_infos ⇒ Object
1055
1056
1057
1058
1059
1060
1061
1062
1063
|
# File 'lib/git-commit-mailer.rb', line 1055
def post_process_infos
commit_infos = @commit_infos.dup
commit_infos.reverse_each do |commit_info|
traverse_merge_commit(commit_info) if commit_info.merge?
end
end
|
#previous_tag_by_revision(revision) ⇒ Object
929
930
931
932
933
934
935
936
937
|
# File 'lib/git-commit-mailer.rb', line 929
def previous_tag_by_revision(revision)
begin
git("describe --abbrev=0 #{parent_commit(revision)}").strip
rescue NoParentCommit
end
end
|
#process_annotated_tag ⇒ Object
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
|
# File 'lib/git-commit-mailer.rb', line 958
def process_annotated_tag
message = ''
tag_object = git("for-each-ref --format='%(*objectname)' #{@reference}").strip
tag_type = git("for-each-ref --format='%(*objecttype)' #{@reference}").strip
case tag_type
when "commit"
message << " tagging #{tag_object} (#{tag_type})\n"
previous_tag = previous_tag_by_revision(@new_revision)
message << " replaces #{previous_tag}\n" if previous_tag
message << annotated_tag_content
message << short_log_from_previous_tag(previous_tag)
else
message << " tagging #{tag_object} (#{tag_type})\n"
message << " length #{git("cat-file -s #{tag_object}").strip} bytes\n"
message << annotated_tag_content
end
message
end
|
#process_backward_update ⇒ Object
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
|
# File 'lib/git-commit-mailer.rb', line 772
def process_backward_update
fast_forward = false
revision_found = false
commits_summary = []
git("rev-list #{@new_revision}..#{@old_revision}").lines.each do |revision|
revision_found ||= true
revision.strip!
short_revision = GitCommitMailer.short_revision(revision)
subject = get_record(revision, '%s')
commits_summary << "discards #{short_revision} #{subject}\n"
end
unless revision_found
fast_forward = true
subject = get_record(old_revision, '%s')
commits_summary << " from #{short_old_revision} #{subject}\n"
end
[fast_forward, commits_summary]
end
|
#process_create_annotated_tag ⇒ Object
878
879
880
881
882
|
# File 'lib/git-commit-mailer.rb', line 878
def process_create_annotated_tag
"Annotated tag (#{@reference}) is created.\n" +
" at #{@new_revision} (tag)\n" +
process_annotated_tag
end
|
#process_create_branch ⇒ Object
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
# File 'lib/git-commit-mailer.rb', line 720
def process_create_branch
message = "Branch (#{@reference}) is created.\n"
commits = []
commit_list = []
git("rev-list #{@new_revision} #{excluded_revisions}").lines.
reverse_each do |revision|
revision.strip!
short_revision = GitCommitMailer.short_revision(revision)
commits << revision
subject = get_record(revision, '%s')
commit_list << " via #{short_revision} #{subject}\n"
end
if commit_list.length > 0
commit_list[-1].sub!(/\A via /, ' at ')
message << commit_list.join
end
[message, commits]
end
|
#process_create_unannotated_tag ⇒ Object
980
981
982
983
984
985
986
|
# File 'lib/git-commit-mailer.rb', line 980
def process_create_unannotated_tag
raise "unexpected" unless detect_object_type(@new_revision) == "commit"
"Unannotated tag (#{@reference}) is created.\n" +
" at #{@new_revision} (commit)\n\n" +
process_unannotated_tag(@new_revision)
end
|
#process_delete_annotated_tag ⇒ Object
891
892
893
894
895
896
897
|
# File 'lib/git-commit-mailer.rb', line 891
def process_delete_annotated_tag
"Annotated tag (#{@reference}) is deleted.\n" +
" was #{@old_revision}\n\n" +
git("show -s --pretty=oneline #{@old_revision}").sub(/^Tagger.*$/, '').
sub(/^Date.*$/, '').
sub(/\n{2,}/, "\n\n")
end
|
#process_delete_branch ⇒ Object
872
873
874
875
876
|
# File 'lib/git-commit-mailer.rb', line 872
def process_delete_branch
"Branch (#{@reference}) is deleted.\n" +
" was #{@old_revision}\n\n" +
git("show -s --pretty=oneline #{@old_revision}")
end
|
#process_delete_unannotated_tag ⇒ Object
998
999
1000
1001
1002
1003
1004
|
# File 'lib/git-commit-mailer.rb', line 998
def process_delete_unannotated_tag
raise "unexpected" unless detect_object_type(@old_revision) == "commit"
"Unannotated tag (#{@reference}) is deleted.\n" +
" was #{@old_revision} (commit)\n\n" +
process_unannotated_tag(@old_revision)
end
|
#process_forward_update ⇒ Object
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
|
# File 'lib/git-commit-mailer.rb', line 795
def process_forward_update
commits_summary = []
git("rev-list #{@old_revision}..#{@new_revision}").lines.each do |revision|
revision.strip!
short_revision = GitCommitMailer.short_revision(revision)
subject = get_record(revision, '%s')
commits_summary << " via #{short_revision} #{subject}\n"
end
commits_summary
end
|
#process_reference_change(old_revision, new_revision, reference) ⇒ Object
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
|
# File 'lib/git-commit-mailer.rb', line 1119
def process_reference_change(old_revision, new_revision, reference)
reset(old_revision, new_revision, reference)
make_infos
make_mails
if
end
[@push_mails, @commit_mails]
end
|
#process_unannotated_tag(revision) ⇒ Object
1006
1007
1008
|
# File 'lib/git-commit-mailer.rb', line 1006
def process_unannotated_tag(revision)
git("show --no-color --root -s --pretty=short #{revision}")
end
|
#process_update_annotated_tag ⇒ Object
884
885
886
887
888
889
|
# File 'lib/git-commit-mailer.rb', line 884
def process_update_annotated_tag
"Annotated tag (#{@reference}) is updated.\n" +
" to #{@new_revision} (tag)\n" +
" from #{@old_revision} (which is now obsolete)\n" +
process_annotated_tag
end
|
#process_update_branch ⇒ Object
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
|
# File 'lib/git-commit-mailer.rb', line 845
def process_update_branch
message = "Branch (#{@reference}) is updated.\n"
fast_forward, backward_commits_summary = process_backward_update
forward_commits_summary = process_forward_update
commits_summary = backward_commits_summary + forward_commits_summary.reverse
unless fast_forward
rewind_only, explanation = explain_special_case
message << explanation
end
message << "\n"
message << commits_summary.join
unless rewind_only
new_commits = collect_new_commits
end
if rewind_only or new_commits.empty?
message << "\n"
message << "No new revisions were added by this update.\n"
end
[message, new_commits]
end
|
#process_update_unannotated_tag ⇒ Object
988
989
990
991
992
993
994
995
996
|
# File 'lib/git-commit-mailer.rb', line 988
def process_update_unannotated_tag
raise "unexpected" unless detect_object_type(@new_revision) == "commit"
raise "unexpected" unless detect_object_type(@old_revision) == "commit"
"Unannotated tag (#{@reference}) is updated.\n" +
" to #{@new_revision} (commit)\n" +
" from #{@old_revision} (commit)\n\n" +
process_unannotated_tag(@new_revision)
end
|
#reset(old_revision, new_revision, reference) ⇒ Object
1072
1073
1074
1075
1076
1077
1078
1079
1080
|
# File 'lib/git-commit-mailer.rb', line 1072
def reset(old_revision, new_revision, reference)
@old_revision = old_revision
@new_revision = new_revision
@reference = reference
@push_info = nil
@commit_infos = []
@commit_info_map = {}
end
|
#send_all_mails ⇒ Object
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
|
# File 'lib/git-commit-mailer.rb', line 1131
def send_all_mails
if send_push_mail?
@push_mails.each do |mail|
send_mail(mail)
end
end
@commit_mails.each do |mail|
send_mail(mail)
end
end
|
#send_per_to? ⇒ Boolean
553
554
555
|
# File 'lib/git-commit-mailer.rb', line 553
def send_per_to?
@send_per_to
end
|
#send_push_mail? ⇒ Boolean
1155
1156
1157
|
# File 'lib/git-commit-mailer.rb', line 1155
def send_push_mail?
@send_push_mail
end
|
#short_log(revision_specifier) ⇒ Object
899
900
901
902
903
904
905
906
|
# File 'lib/git-commit-mailer.rb', line 899
def short_log(revision_specifier)
log = git("rev-list --pretty=short #{GitCommitMailer.shell_escape(revision_specifier)}")
git("shortlog") do |git|
git.write(log)
git.close_write
return git.read
end
end
|
#short_log_from_previous_tag(previous_tag) ⇒ Object
908
909
910
911
912
913
914
915
916
|
# File 'lib/git-commit-mailer.rb', line 908
def short_log_from_previous_tag(previous_tag)
if previous_tag
short_log("#{previous_tag}..#{@new_revision}")
else
short_log(@new_revision)
end
end
|
#short_new_revision ⇒ Object
#short_old_revision ⇒ Object
#show_path? ⇒ Boolean
1151
1152
1153
|
# File 'lib/git-commit-mailer.rb', line 1151
def show_path?
@show_path
end
|
#track_remote? ⇒ Boolean
582
583
584
|
# File 'lib/git-commit-mailer.rb', line 582
def track_remote?
@track_remote
end
|
#traverse_merge_commit(merge_commit) ⇒ Object
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
|
# File 'lib/git-commit-mailer.rb', line 1018
def traverse_merge_commit(merge_commit)
first_grand_parent = parent_commit(merge_commit.first_parent)
[merge_commit.first_parent, *merge_commit.other_parents].each do |revision|
is_traversing_first_parent = (revision == merge_commit.first_parent)
base_revision = git("merge-base #{first_grand_parent} #{revision}").strip
base_revisions = [@old_revision, base_revision]
descendant_revision = merge_commit.revision
until base_revisions.index(revision)
commit_info = @commit_info_map[revision]
if commit_info
commit_info.reference = @reference
else
commit_info = create_commit_info(@reference, revision)
index = @commit_infos.index(@commit_info_map[descendant_revision])
@commit_infos.insert(index, commit_info)
@commit_info_map[revision] = commit_info
end
merge_message = "Merged #{merge_commit.short_revision}: #{merge_commit.subject}"
if not is_traversing_first_parent and not commit_info.merge_status.index(merge_message)
commit_info.merge_status << merge_message
commit_info.merge_revisions << merge_commit.revision
end
if commit_info.merge?
traverse_merge_commit(commit_info)
base_revision = git("merge-base #{first_grand_parent} #{commit_info.first_parent}").strip
base_revisions << base_revision unless base_revisions.index(base_revision)
end
descendant_revision, revision = revision, commit_info.first_parent
end
end
end
|
#verbose? ⇒ Boolean
586
587
588
|
# File 'lib/git-commit-mailer.rb', line 586
def verbose?
@verbose
end
|