-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsvnhistory
executable file
·168 lines (121 loc) · 3.96 KB
/
svnhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env ruby
class Change
attr_accessor :author, :time, :description
def initialize
@description = ""
end
# Combine multiple lines of text into long run-on lines. Empty
# lines of text denote paragraphs. Lines beginning with '*'
# are also recognised as bullet point lists.
def combine_lines(input)
result = ""
input.each_line do |s|
s = s.chomp
if result.length > 0 && result[-1, 1] != "\n"
# Don't do any of this if we just started a new line
if s =~ /^\s*$/
# empty line; make this break a paragraph.
result += "\n\n"
elsif s =~ /^\s*\*/
# bullet point
result += "\n"
else
result += " "
end
end
result += s
end
result
end
# Reformat the description and break into lines
def break_lines(input)
result = ""
input.each_line do |s|
if s =~ /^\s*$/
# empty line
result += "\n"
else
# Amount to indent each line by so that they align
# with the initial bullet point (if this line is a
# bullet point)
indent_length = if s =~ /^(\s*\*\s*)/
$1.length
else
0
end
# Split this line into words, then add them to nextline
# one at a time until it reaches a 70 character limit.
nextline = s[0, indent_length]
s = s[indent_length, s.length]
words = s.split(/\s+/)
words.each do |word|
# If the next word will run over the limit, break
# onto a new line.
if nextline.length > indent_length \
&& nextline.length + word.length + 1 > 70
result += nextline + "\n"
nextline = " " * indent_length
end
# Space to separate from the previous word, but only
# if this is not the start of a line
if nextline.length > indent_length
if nextline[-1, 1] == "."
# Two spaces after a period
nextline += " "
end
nextline += " "
end
nextline += word
end
# Print the last "unfinished" line
if nextline.length > indent_length
result += nextline + "\n"
end
end
end
result
end
def remove_trailing_newlines(s)
while s[-2, 2] == "\n\n"
s = s.chop
end
s
end
def print_change
puts "#{@time} #{@author}"
puts "\t"
munged = combine_lines(@description)
munged = break_lines(munged)
munged = remove_trailing_newlines(munged)
munged.each_line do |s|
puts "\t" + s
end
puts
end
end
changes = []
IO.popen("svn log .") do |io|
current_change = nil
io.each_line do |s|
s = s.chomp
if s =~ /^-+$/
# start of a new change
if current_change != nil
changes.push(current_change)
end
current_change = Change.new
elsif current_change.author == nil
# first line of new change
fields = s.split(/ \| /)
current_change.author = fields[1]
# time
timebits = fields[2].split(/\s+/)
current_change.time = timebits[0] + " " + timebits[1]
else
current_change.description += s + "\n"
end
end
end
changes.each do |change|
change.print_change
end