Skip to content

Commit 71a0e9c

Browse files
committed
get complete history of files in CVS repository (across branch points)
fixes #1633
1 parent 314d473 commit 71a0e9c

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

src/org/opensolaris/opengrok/history/CVSHistoryParser.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
import java.text.DateFormat;
3232
import java.text.ParseException;
3333
import java.util.ArrayList;
34+
import java.util.Collections;
35+
import java.util.Comparator;
3436
import java.util.HashMap;
37+
import java.util.List;
3538
import java.util.logging.Level;
3639
import java.util.logging.Logger;
3740

@@ -50,7 +53,7 @@ private enum ParseState {
5053
}
5154

5255
private History history;
53-
private CVSRepository repository = new CVSRepository();
56+
private CVSRepository cvsrepo = new CVSRepository();
5457

5558
/**
5659
* Process the output from the log command and insert the HistoryEntries
@@ -61,7 +64,7 @@ private enum ParseState {
6164
*/
6265
@Override
6366
public void processStream(InputStream input) throws IOException {
64-
DateFormat df = repository.getDateFormat();
67+
DateFormat df = cvsrepo.getDateFormat();
6568
ArrayList<HistoryEntry> entries = new ArrayList<HistoryEntry>();
6669

6770
BufferedReader in = new BufferedReader(new InputStreamReader(input));
@@ -169,9 +172,9 @@ public void processStream(InputStream input) throws IOException {
169172
* @return object representing the file's history
170173
*/
171174
History parse(File file, Repository repos) throws HistoryException {
172-
repository = (CVSRepository) repos;
175+
cvsrepo = (CVSRepository) repos;
173176
try {
174-
Executor executor = repository.getHistoryLogExecutor(file);
177+
Executor executor = cvsrepo.getHistoryLogExecutor(file);
175178
int status = executor.exec(true, this);
176179

177180
if (status != 0) {
@@ -183,6 +186,19 @@ History parse(File file, Repository repos) throws HistoryException {
183186
file.getAbsolutePath() + "\"", e);
184187
}
185188

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+
186202
return history;
187203
}
188204

src/org/opensolaris/opengrok/history/CVSRepository.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ Executor getHistoryLogExecutor(final File file) throws IOException {
207207
cmd.add("log");
208208

209209
if (getBranch() != null && !getBranch().isEmpty()) {
210-
// Just generate THIS branch history, we don't care about the other
211-
// branches which are not checked out.
212-
cmd.add("-r" + branch);
210+
// Generate history on this branch and follow up to the origin.
211+
cmd.add("-r1.1:" + branch);
213212
} else {
214213
// Get revisions on this branch only (otherwise the revisions
215214
// list produced by the cvs log command would be unsorted).

test/org/opensolaris/opengrok/history/CVSRepositoryTest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,15 @@ public void testGetBranchNoBranch() throws Exception {
142142
}
143143

144144
/**
145-
* Get the CVS repository, create new branch and verify getBranch() returns it
146-
* and check newly added commits annotate with branch revision numbers.
145+
* Get the CVS repository, create new branch, change a file and verify that
146+
* getBranch() returns the branch and check newly added commits annotate
147+
* with branch revision numbers.
148+
* Last, check that history entries of the file follow through before the
149+
* branch was created.
147150
* @throws Exception
148151
*/
149152
@Test
150-
public void testGetBranchNewBranch() throws Exception {
153+
public void testNewBranch() throws Exception {
151154
setUpTestRepository();
152155
File root = new File(repository.getSourceRoot(), "cvs_test/cvsrepo");
153156

@@ -176,6 +179,12 @@ public void testGetBranchNewBranch() throws Exception {
176179
// Check that annotation for the changed line has branch revision.
177180
Annotation annotation = cvsrepo.annotate(mainC, null);
178181
assertEquals("1.2.2.1", annotation.getRevision(1));
182+
183+
History mainCHistory = cvsrepo.getHistory(mainC);
184+
assertEquals(3, mainCHistory.getHistoryEntries().size());
185+
assertEquals("1.2.2.1", mainCHistory.getHistoryEntries().get(0).getRevision());
186+
assertEquals("1.2", mainCHistory.getHistoryEntries().get(1).getRevision());
187+
assertEquals("1.1", mainCHistory.getHistoryEntries().get(2).getRevision());
179188
}
180189

181190
/**

0 commit comments

Comments
 (0)