31
31
import java .text .DateFormat ;
32
32
import java .text .ParseException ;
33
33
import java .util .ArrayList ;
34
+ import java .util .Collections ;
35
+ import java .util .Comparator ;
34
36
import java .util .HashMap ;
37
+ import java .util .List ;
35
38
import java .util .logging .Level ;
36
39
import java .util .logging .Logger ;
37
40
@@ -50,7 +53,7 @@ private enum ParseState {
50
53
}
51
54
52
55
private History history ;
53
- private CVSRepository repository = new CVSRepository ();
56
+ private CVSRepository cvsrepo = new CVSRepository ();
54
57
55
58
/**
56
59
* Process the output from the log command and insert the HistoryEntries
@@ -61,7 +64,7 @@ private enum ParseState {
61
64
*/
62
65
@ Override
63
66
public void processStream (InputStream input ) throws IOException {
64
- DateFormat df = repository .getDateFormat ();
67
+ DateFormat df = cvsrepo .getDateFormat ();
65
68
ArrayList <HistoryEntry > entries = new ArrayList <HistoryEntry >();
66
69
67
70
BufferedReader in = new BufferedReader (new InputStreamReader (input ));
@@ -169,9 +172,9 @@ public void processStream(InputStream input) throws IOException {
169
172
* @return object representing the file's history
170
173
*/
171
174
History parse (File file , Repository repos ) throws HistoryException {
172
- repository = (CVSRepository ) repos ;
175
+ cvsrepo = (CVSRepository ) repos ;
173
176
try {
174
- Executor executor = repository .getHistoryLogExecutor (file );
177
+ Executor executor = cvsrepo .getHistoryLogExecutor (file );
175
178
int status = executor .exec (true , this );
176
179
177
180
if (status != 0 ) {
@@ -183,6 +186,19 @@ History parse(File file, Repository repos) throws HistoryException {
183
186
file .getAbsolutePath () + "\" " , e );
184
187
}
185
188
189
+ // In case there is a branch, the log entries can be returned in
190
+ // unsorted order (as a result of using '-r1.1:branch' for 'cvs log')
191
+ // so they need to be sorted according to revision.
192
+ if (cvsrepo .getBranch () != null && !cvsrepo .getBranch ().isEmpty ()) {
193
+ List <HistoryEntry > entries = history .getHistoryEntries ();
194
+ Collections .sort (entries , new Comparator <HistoryEntry >() {
195
+ public int compare (HistoryEntry o1 , HistoryEntry o2 ) {
196
+ return o2 .getRevision ().compareTo (o1 .getRevision ());
197
+ }
198
+ });
199
+ history .setHistoryEntries (entries );
200
+ }
201
+
186
202
return history ;
187
203
}
188
204
0 commit comments