Skip to content

Commit 22ffbc5

Browse files
idodeclareVladimir Kotal
authored andcommitted
Fix #2919 Fix #2797 Fix #981 Fix #878 Fix #502 Perforce refactoring
- Run a p4-changes and p4-filelog, and integrate the results, so only two p4 commands are needed for History for a directory tree. - Parse file names from p4 commands so that HistoryEntry instances have defined files. - Recognize binary file log for annotations.
1 parent 8049938 commit 22ffbc5

File tree

5 files changed

+315
-192
lines changed

5 files changed

+315
-192
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.history;
2425

@@ -49,19 +50,23 @@ public class PerforceAnnotationParser implements Executor.StreamHandler {
4950
*/
5051
private final Annotation annotation;
5152

53+
private final PerforceRepository repo;
54+
5255
private final File file;
5356

5457
private final String rev;
5558

5659
private static final Pattern ANNOTATION_PATTERN
5760
= Pattern.compile("^(\\d+): .*");
58-
61+
5962
/**
63+
* @param repo defined instance
6064
* @param file the file being annotated
6165
* @param rev revision to be annotated
6266
*/
63-
public PerforceAnnotationParser(File file, String rev) {
67+
public PerforceAnnotationParser(PerforceRepository repo, File file, String rev) {
6468
annotation = new Annotation(file.getName());
69+
this.repo = repo;
6570
this.file = file;
6671
this.rev = rev;
6772
}
@@ -77,8 +82,9 @@ public Annotation getAnnotation() {
7782

7883
@Override
7984
public void processStream(InputStream input) throws IOException {
80-
List<HistoryEntry> revisions
81-
= PerforceHistoryParser.getRevisions(file, rev).getHistoryEntries();
85+
// Pass null for revision to get all history for the file.
86+
PerforceHistoryParser parser = new PerforceHistoryParser(repo);
87+
List<HistoryEntry> revisions = parser.getRevisions(file, null).getHistoryEntries();
8288
HashMap<String, String> revAuthor = new HashMap<>();
8389
for (HistoryEntry entry : revisions) {
8490
// a.addDesc(entry.getRevision(), entry.getMessage());
@@ -90,6 +96,11 @@ public void processStream(InputStream input) throws IOException {
9096
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input))) {
9197
while ((line = reader.readLine()) != null) {
9298
++lineno;
99+
if (line.equals("(... files differ ...)")) {
100+
// Perforce knows as a binary file?
101+
continue;
102+
}
103+
93104
Matcher matcher = ANNOTATION_PATTERN.matcher(line);
94105
if (matcher.find()) {
95106
String revision = matcher.group(1);

0 commit comments

Comments
 (0)