Collection<Commit> commits = new ArrayList<Commit>();
BufferedReader r = new BufferedReader(new StringReader(log));
try {
String line;
Commit current = new Commit();
while ((line = r.readLine()) != null) {
if (line == null || line.trim().equals(""))
continue;
else {
if (line.startsWith("commit")) {
if (current.isValid()) {
commits.add(current);
current = new Commit();
}
current.setHash(line.replaceAll("commit", "").trim());
}
else if (line.startsWith("Author"))
current.setAuthor(line.replaceAll("Author:", "").trim());
else if (line.startsWith("Date")) {
String dateString = line.replaceAll("Date:", "").trim();
current.setDate(Constants.GIT_DATE.parse(dateString));
}
else if (line.startsWith(" ")) {
current.setMessage(current.getMessage() + "\n" + line);
}
else {
Matcher m = nameAndStatus.matcher(line);
while (m.find()) {
NameAndStatus change = new NameAndStatus(m.group(2), m.group(1));
current.getChanges().add(change);
}
}
}
}
if (current.isValid()) {
commits.add(current);
}
}
catch (IOException e) {
throw new RuntimeException(e);