Skip to content

Commit 7d450db

Browse files
authored
report progress when getting boundary changesets (#4238)
1 parent eab79dc commit 7d450db

File tree

5 files changed

+65
-21
lines changed

5 files changed

+65
-21
lines changed

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

2525
import org.jetbrains.annotations.TestOnly;
2626
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2727
import org.opengrok.indexer.logger.LoggerFactory;
28+
import org.opengrok.indexer.util.Progress;
2829
import org.opengrok.indexer.util.Statistics;
2930

3031
import java.util.ArrayList;
@@ -74,6 +75,24 @@ int getMaxCount() {
7475
return maxCount;
7576
}
7677

78+
static class IdWithProgress {
79+
private final Progress progress;
80+
private final String id;
81+
82+
IdWithProgress(String id, Progress progress) {
83+
this.id = id;
84+
this.progress = progress;
85+
}
86+
87+
public String getId() {
88+
return id;
89+
}
90+
91+
public Progress getProgress() {
92+
return progress;
93+
}
94+
}
95+
7796
/**
7897
* @param sinceRevision start revision ID
7998
* @return immutable list of revision IDs denoting the intervals
@@ -82,25 +101,33 @@ int getMaxCount() {
82101
public synchronized List<String> getBoundaryChangesetIDs(String sinceRevision) throws HistoryException {
83102
reset();
84103

85-
LOGGER.log(Level.FINE, "getting boundary changesets for ''{0}''", repository.getDirectoryName());
104+
Level logLevel = Level.FINE;
105+
if (RuntimeEnvironment.getInstance().isPrintProgress()) {
106+
logLevel = Level.INFO;
107+
}
108+
109+
LOGGER.log(logLevel, "getting boundary changesets for {0}", repository);
86110
Statistics stat = new Statistics();
87111

88-
repository.accept(sinceRevision, this::visit);
112+
try (Progress progress = new Progress(LOGGER, String.format("changesets visited of %s", this.repository))) {
113+
repository.accept(sinceRevision, this::visit, progress);
114+
}
89115

90116
// The changesets need to go from oldest to newest.
91117
Collections.reverse(result);
92118

93-
stat.report(LOGGER, Level.FINE,
94-
String.format("Done getting boundary changesets for ''%s'' (%d entries)",
95-
repository.getDirectoryName(), result.size()));
119+
stat.report(LOGGER, logLevel,
120+
String.format("Done getting boundary changesets for %s (%d entries)",
121+
repository, result.size()));
96122

97123
return List.copyOf(result);
98124
}
99125

100-
private void visit(String id) {
126+
private void visit(IdWithProgress arg) {
101127
if (cnt != 0 && cnt % maxCount == 0) {
102-
result.add(id);
128+
result.add(arg.getId());
103129
}
104130
cnt++;
131+
arg.getProgress().increment();
105132
}
106133
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
2323
* Portions Copyright (c) 2019, Krystof Tulinger <[email protected]>.
2424
*/
@@ -85,6 +85,7 @@
8585
import org.opengrok.indexer.configuration.RuntimeEnvironment;
8686
import org.opengrok.indexer.logger.LoggerFactory;
8787
import org.opengrok.indexer.util.ForbiddenSymlinkException;
88+
import org.opengrok.indexer.util.Progress;
8889

8990
import static org.opengrok.indexer.history.History.TAGS_SEPARATOR;
9091

@@ -448,7 +449,9 @@ public int getPerPartesCount() {
448449
return MAX_CHANGESETS;
449450
}
450451

451-
public void accept(String sinceRevision, Consumer<String> visitor) throws HistoryException {
452+
public void accept(String sinceRevision, Consumer<BoundaryChangesets.IdWithProgress> visitor, Progress progress)
453+
throws HistoryException {
454+
452455
try (org.eclipse.jgit.lib.Repository repository = getJGitRepository(getDirectoryName());
453456
RevWalk walk = new RevWalk(repository)) {
454457

@@ -459,7 +462,7 @@ public void accept(String sinceRevision, Consumer<String> visitor) throws Histor
459462

460463
for (RevCommit commit : walk) {
461464
// Do not abbreviate the Id as this could cause AmbiguousObjectException in getHistory().
462-
visitor.accept(commit.getId().name());
465+
visitor.accept(new BoundaryChangesets.IdWithProgress(commit.getId().name(), progress));
463466
}
464467
} catch (IOException e) {
465468
throw new HistoryException(e);

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

2525
import org.opengrok.indexer.util.Executor;
26+
import org.opengrok.indexer.util.Progress;
2627

2728
import java.io.BufferedReader;
2829
import java.io.File;
@@ -33,11 +34,15 @@
3334

3435
class MercurialHistoryParserRevisionsOnly implements Executor.StreamHandler {
3536
private final MercurialRepository repository;
36-
private final Consumer<String> visitor;
37+
private final Consumer<BoundaryChangesets.IdWithProgress> visitor;
3738

38-
MercurialHistoryParserRevisionsOnly(MercurialRepository repository, Consumer<String> visitor) {
39+
private final Progress progress;
40+
41+
MercurialHistoryParserRevisionsOnly(MercurialRepository repository,
42+
Consumer<BoundaryChangesets.IdWithProgress> visitor, Progress progress) {
3943
this.repository = repository;
4044
this.visitor = visitor;
45+
this.progress = progress;
4146
}
4247

4348
void parse(File file, String sinceRevision) throws HistoryException {
@@ -61,7 +66,7 @@ public void processStream(InputStream input) throws IOException {
6166
try (BufferedReader in = new BufferedReader(new InputStreamReader(input))) {
6267
String s;
6368
while ((s = in.readLine()) != null) {
64-
visitor.accept(s);
69+
visitor.accept(new BoundaryChangesets.IdWithProgress(s, progress));
6570
}
6671
}
6772
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2017, 2019, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -47,6 +47,7 @@
4747
import org.opengrok.indexer.util.BufferSink;
4848
import org.opengrok.indexer.util.Executor;
4949
import org.opengrok.indexer.util.LazilyInstantiate;
50+
import org.opengrok.indexer.util.Progress;
5051

5152
/**
5253
* Access to a Mercurial repository.
@@ -566,8 +567,10 @@ History getHistory(File file) throws HistoryException {
566567
return getHistory(file, null);
567568
}
568569

569-
public void accept(String sinceRevision, Consumer<String> visitor) throws HistoryException {
570-
new MercurialHistoryParserRevisionsOnly(this, visitor).
570+
public void accept(String sinceRevision, Consumer<BoundaryChangesets.IdWithProgress> visitor, Progress progress)
571+
throws HistoryException {
572+
573+
new MercurialHistoryParserRevisionsOnly(this, visitor, progress).
571574
parse(new File(getDirectoryName()), sinceRevision);
572575
}
573576

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opengrok.indexer.history;
2424

2525
import org.opengrok.indexer.configuration.RuntimeEnvironment;
2626
import org.opengrok.indexer.logger.LoggerFactory;
27+
import org.opengrok.indexer.util.Progress;
2728
import org.opengrok.indexer.util.Statistics;
2829

2930
import java.io.File;
@@ -65,12 +66,17 @@ public int getPerPartesCount() {
6566
* Traverse the changesets using the visitor pattern.
6667
* @param sinceRevision start revision
6768
* @param visitor consumer of revisions
69+
* @param progress {@link Progress} instance
6870
* @throws HistoryException on error during history retrieval
6971
*/
70-
public abstract void accept(String sinceRevision, Consumer<String> visitor) throws HistoryException;
72+
public abstract void accept(String sinceRevision, Consumer<BoundaryChangesets.IdWithProgress> visitor,
73+
Progress progress)
74+
throws HistoryException;
7175

7276
@Override
73-
protected void doCreateCache(HistoryCache cache, String sinceRevision, File directory) throws HistoryException, CacheException {
77+
protected void doCreateCache(HistoryCache cache, String sinceRevision, File directory)
78+
throws HistoryException, CacheException {
79+
7480
if (!RuntimeEnvironment.getInstance().isHistoryCachePerPartesEnabled()) {
7581
LOGGER.log(Level.INFO, "repository {0} supports per partes history cache creation however " +
7682
"it is disabled in the configuration. Generating history cache as whole.", this);

0 commit comments

Comments
 (0)