Skip to content

Commit b4f6090

Browse files
Fixing how commit logs are parsed for commits including newlinesi
closes ruby-git#125
1 parent 97e1fff commit b4f6090

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

lib/git/lib.rb

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ def full_log_commits(opts={})
9696

9797
process_commit_log_data(full_log)
9898
end
99-
100-
10199

102100
def revparse(string)
103101
return string if string =~ /[A-Fa-f0-9]{40}/ # passing in a sha - just no-op it
@@ -153,44 +151,43 @@ def process_commit_data(data, sha = nil, indent = 4)
153151
return hsh
154152
end
155153

156-
def process_commit_log_data(data, sha = nil, indent = 4)
154+
def process_commit_log_data(data)
157155
in_message = false
158156

159-
if sha
160-
hsh = {'sha' => sha, 'message' => '', 'parent' => []}
161-
else
162-
hsh_array = []
163-
end
157+
hsh_array = []
158+
159+
hsh = nil
164160

165161
data.each do |line|
166162
line = line.chomp
167-
if line == ''
168-
in_message = !in_message
169-
elsif in_message
170-
hsh['message'] << line[indent..-1] << "\n"
171-
else
172-
data = line.split
173-
key = data.shift
174-
value = data.join(' ')
175-
if key == 'commit'
176-
sha = value
163+
164+
if line[0].nil?
165+
in_message = !in_message
166+
next
167+
end
168+
169+
if in_message
170+
hsh['message'] << "#{line[4..-1]}\n"
171+
next
172+
end
173+
174+
key, *value = line.split
175+
value = value.join(' ')
176+
177+
case key
178+
when 'commit'
177179
hsh_array << hsh if hsh
178-
hsh = {'sha' => sha, 'message' => '', 'parent' => []}
179-
end
180-
if key == 'parent'
181-
hsh[key] << value
180+
hsh = {'sha' => value, 'message' => '', 'parent' => []}
181+
when 'parent'
182+
hsh['parent'] << value
182183
else
183184
hsh[key] = value
184-
end
185185
end
186186
end
187187

188-
if hsh_array
189-
hsh_array << hsh if hsh
190-
hsh_array
191-
else
192-
hsh
193-
end
188+
hsh_array << hsh if hsh
189+
190+
return hsh_array
194191
end
195192

196193
def object_contents(sha, &block)
@@ -748,6 +745,7 @@ def command(cmd, opts = [], chdir = true, redirect = '', &block)
748745
if chdir && (Dir.getwd != path)
749746
Dir.chdir(path) { out = run_command(git_cmd, &block) }
750747
else
748+
751749
out = run_command(git_cmd, &block)
752750
end
753751

0 commit comments

Comments
 (0)