1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.merge;
11
12 import java.util.List;
13
14 import org.eclipse.jgit.lib.PersonIdent;
15 import org.eclipse.jgit.lib.Ref;
16 import org.eclipse.jgit.revwalk.RevCommit;
17 import org.eclipse.jgit.util.GitDateFormatter;
18 import org.eclipse.jgit.util.GitDateFormatter.Format;
19
20
21
22
23
24
25 public class SquashMessageFormatter {
26
27 private GitDateFormatter dateFormatter;
28
29
30
31
32 public SquashMessageFormatter() {
33 dateFormatter = new GitDateFormatter(Format.DEFAULT);
34 }
35
36
37
38
39
40
41
42
43
44 public String format(List<RevCommit> squashedCommits, Ref target) {
45 StringBuilder sb = new StringBuilder();
46 sb.append("Squashed commit of the following:\n");
47 for (RevCommit c : squashedCommits) {
48 sb.append("\ncommit ");
49 sb.append(c.getName());
50 sb.append("\n");
51 sb.append(toString(c.getAuthorIdent()));
52 sb.append("\n\t");
53 sb.append(c.getShortMessage());
54 sb.append("\n");
55 }
56 return sb.toString();
57 }
58
59 private String toString(PersonIdent author) {
60 final StringBuilder a = new StringBuilder();
61
62 a.append("Author: ");
63 a.append(author.getName());
64 a.append(" <");
65 a.append(author.getEmailAddress());
66 a.append(">\n");
67 a.append("Date: ");
68 a.append(dateFormatter.formatDate(author));
69 a.append("\n");
70
71 return a.toString();
72 }
73 }