Skip to content

Commit 77ba40e

Browse files
Vladimir Kotalahornace
authored andcommitted
filter extra history entries by hand
1 parent 8dc1fbc commit 77ba40e

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/MercurialHistoryParser.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.text.ParseException;
3434
import java.util.ArrayList;
3535
import java.util.Date;
36+
import java.util.Iterator;
3637
import java.util.List;
3738
import java.util.logging.Level;
3839
import java.util.logging.Logger;
@@ -70,6 +71,7 @@ class MercurialHistoryParser implements Executor.StreamHandler {
7071
* @param file the file or directory to get history for
7172
* @param sinceRevision the changeset right before the first one to fetch, or
7273
* {@code null} if all changesets should be fetched
74+
* @param tillRevision end revision or {@code null}
7375
* @return history for the specified file or directory
7476
* @throws HistoryException if an error happens when parsing the history
7577
*/
@@ -97,9 +99,24 @@ History parse(File file, String sinceRevision, String tillRevision) throws Histo
9799
repository.removeAndVerifyOldestChangeset(entries, sinceRevision);
98100
}
99101

102+
// TODO: add comment
103+
if (repository.isHandleRenamedFiles() && file.isFile() && tillRevision != null) {
104+
removeChangesets(entries, tillRevision);
105+
}
106+
100107
return new History(entries, renamedFiles);
101108
}
102109

110+
private void removeChangesets(List<HistoryEntry> entries, String tillRevision) {
111+
for (Iterator<HistoryEntry> iter = entries.listIterator(); iter.hasNext(); ) {
112+
HistoryEntry entry = iter.next();
113+
if (entry.getRevision().equals(tillRevision)) {
114+
break;
115+
}
116+
iter.remove();
117+
}
118+
}
119+
103120
/**
104121
* Process the output from the {@code hg log} command and collect
105122
* {@link HistoryEntry} elements.

opengrok-indexer/src/main/java/org/opengrok/indexer/history/MercurialRepository.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,12 @@ Executor getHistoryLogExecutor(File file, String sinceRevision, String tillRevis
223223
//
224224
// Getting history for individual files should only be done when generating history for renamed files
225225
// so the fact that filtering on sinceRevision does not work does not matter there as history
226-
// from the initial changeset is needed. The tillRevision filtering works.
227-
226+
// from the initial changeset is needed. The tillRevision filtering works however not
227+
// in combination with --follow.
228228
if (this.isHandleRenamedFiles()) {
229229
// When using --follow, the returned revisions are from newest to oldest, hence no reverse() is needed.
230230
cmd.add("--follow");
231231
}
232-
233-
// Note: assumes one of them is not null
234-
if ((sinceRevision != null) || (tillRevision != null)) {
235-
cmd.add("-r");
236-
StringBuilder stringBuilder = new StringBuilder();
237-
if (sinceRevision != null) {
238-
stringBuilder.append(getRevisionNum(sinceRevision));
239-
}
240-
stringBuilder.append(":");
241-
if (tillRevision != null) {
242-
stringBuilder.append(getRevisionNum(tillRevision));
243-
}
244-
cmd.add(stringBuilder.toString());
245-
}
246232
}
247233

248234
cmd.add("--template");
@@ -584,7 +570,7 @@ History getHistory(File file, String sinceRevision, String tillRevision) throws
584570
// so no sinceRevision filter is needed.
585571
// See findOriginalName() code for more details.
586572
History result = new MercurialHistoryParser(this).parse(file, sinceRevision, tillRevision);
587-
573+
588574
// Assign tags to changesets they represent.
589575
// We don't need to check if this repository supports tags,
590576
// because we know it :-)

0 commit comments

Comments
 (0)