Skip to content

Commit ec5b57e

Browse files
committed
control the fallback to repository#getHistory()
1 parent f990832 commit ec5b57e

File tree

5 files changed

+36
-22
lines changed

5 files changed

+36
-22
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public final class Configuration {
205205
* Set to false if we want to disable fetching history of individual files
206206
* (by running appropriate SCM command) when the history is not found
207207
* in history cache for repositories capable of fetching history for
208-
* directories. This option affects file based history cache only.
208+
* directories.
209209
*/
210210
private boolean fetchHistoryWhenNotInCache;
211211
/*

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

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

2020
/*
21-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -638,6 +638,14 @@ private void createDirectoriesForFiles(Set<String> files, Repository repository,
638638
@Override
639639
public History get(File file, Repository repository, boolean withFiles)
640640
throws HistoryException, ForbiddenSymlinkException {
641+
642+
return get(file, repository, withFiles, env.isFetchHistoryWhenNotInCache());
643+
}
644+
645+
@Override
646+
public History get(File file, Repository repository, boolean withFiles, boolean fallback)
647+
throws HistoryException, ForbiddenSymlinkException {
648+
641649
File cacheFile = getCachedFile(file);
642650
if (isUpToDate(file, cacheFile)) {
643651
try {
@@ -661,9 +669,8 @@ public History get(File file, Repository repository, boolean withFiles)
661669
* since the history of all files in this repository should have been
662670
* fetched in the first phase of indexing.
663671
*/
664-
if (isHistoryIndexDone() && repository.isHistoryEnabled() &&
665-
repository.hasHistoryForDirectories() &&
666-
!env.isFetchHistoryWhenNotInCache()) {
672+
if (isHistoryIndexDone() && repository.isHistoryEnabled() && repository.hasHistoryForDirectories() &&
673+
!fallback) {
667674
return null;
668675
}
669676

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

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

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

2525
import java.io.File;
2626
import java.util.Date;
2727
import java.util.Map;
28+
29+
import org.jetbrains.annotations.Nullable;
2830
import org.opengrok.indexer.util.ForbiddenSymlinkException;
2931

3032
interface HistoryCache {
@@ -51,17 +53,23 @@ interface HistoryCache {
5153
* parsing the history information in the repository.
5254
*
5355
* @param file The file to retrieve history for
54-
* @param repository The external repository to read the history from (can
55-
* be <code>null</code>)
56-
* @param withFiles A flag saying whether or not the returned history
57-
* should include a list of files touched by each changeset. If false,
58-
* the implementation is allowed to skip the file list, but it doesn't
59-
* have to.
56+
* @param repository The external repository to read the history from (can be <code>null</code>)
57+
* @param withFiles A flag saying whether the returned history should include a list of files
58+
* touched by each changeset. If false, the implementation is allowed to skip the file list,
59+
* but it doesn't have to.
60+
* @param fallback whether to fall back to {@link Repository#getHistory(File)}
61+
* if the history cannot be retrieved from the cache
6062
* @throws HistoryException if the history cannot be fetched
6163
* @throws ForbiddenSymlinkException if symbolic-link checking encounters
6264
* an ineligible link
6365
*/
64-
History get(File file, Repository repository, boolean withFiles)
66+
History get(File file, @Nullable Repository repository, boolean withFiles, boolean fallback)
67+
throws HistoryException, ForbiddenSymlinkException;
68+
69+
/**
70+
* Usually a wrapper of {@link HistoryCache#get(File, Repository, boolean, boolean)}.
71+
*/
72+
History get(File file, @Nullable Repository repository, boolean withFiles)
6573
throws HistoryException, ForbiddenSymlinkException;
6674

6775
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ boolean isRepoHistoryEligible(Repository repo, File file, boolean ui) {
241241
}
242242

243243
@Nullable
244-
private History getHistoryFromCache(File file, Repository repository, boolean withFiles, boolean ui)
244+
private History getHistoryFromCache(File file, Repository repository, boolean withFiles, boolean fallback)
245245
throws HistoryException, ForbiddenSymlinkException {
246246

247247
if (useCache() && historyCache.supportsRepository(repository)) {
248-
return historyCache.get(file, repository, withFiles);
248+
return historyCache.get(file, repository, withFiles, fallback);
249249
}
250250

251251
return null;
@@ -268,7 +268,7 @@ public HistoryEntry getLastHistoryEntry(File file, boolean ui) throws HistoryExc
268268

269269
History history;
270270
try {
271-
history = getHistoryFromCache(file, repository, false, ui);
271+
history = getHistoryFromCache(file, repository, false, false);
272272
if (history != null) {
273273
HistoryEntry lastHistoryEntry = history.getLastHistoryEntry();
274274
if (lastHistoryEntry != null) {
@@ -306,7 +306,7 @@ public History getHistory(File file, boolean withFiles, boolean ui) throws Histo
306306

307307
History history;
308308
try {
309-
history = getHistoryFromCache(file, repository, withFiles, ui);
309+
history = getHistoryFromCache(file, repository, withFiles, true);
310310
if (history != null) {
311311
return history;
312312
}
@@ -315,7 +315,7 @@ public History getHistory(File file, boolean withFiles, boolean ui) throws Histo
315315
return null;
316316
}
317317

318-
return repository.getHistory(file);
318+
return null;
319319
}
320320

321321
/**

opengrok-indexer/src/test/java/org/opengrok/indexer/history/FileHistoryCacheTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,18 +887,17 @@ void testRenamedFile() throws Exception {
887887
updatedHistory.getHistoryEntries(), false);
888888
}
889889

890-
private void checkNoHistoryFetchRepo(String reponame, String filename, boolean hasHistory) throws Exception {
890+
private void checkNoHistoryFetchRepo(String repoName, String filename, boolean hasHistory) throws Exception {
891891

892-
File reposRoot = new File(repositories.getSourceRoot(), reponame);
892+
File reposRoot = new File(repositories.getSourceRoot(), repoName);
893893
Repository repo = RepositoryFactory.getRepository(reposRoot);
894894

895895
// Make sure the file exists in the repository.
896896
File repoFile = new File(reposRoot, filename);
897897
assertTrue(repoFile.exists());
898898

899899
// Try to fetch the history for given file. With default setting of
900-
// FetchHistoryWhenNotInCache this should create corresponding file
901-
// in history cache.
900+
// FetchHistoryWhenNotInCache this should get the history even if not in cache.
902901
History retrievedHistory = cache.get(repoFile, repo, true);
903902
assertEquals(hasHistory, retrievedHistory != null);
904903
}

0 commit comments

Comments
 (0)