-
Notifications
You must be signed in to change notification settings - Fork 788
avoid global isHistoryEnabled() checks in favor of per repository check #4746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3fca07a
avoid global isHistoryEnabled() checks in favor of per repository check
vladak ca93f73
enable history
vladak 991f7ae
revert config check changes
vladak 1d5af14
adjust comment
vladak e10ca93
use isEmpty()
vladak 1ea1285
add test for populateDocument() vs history override
vladak ed6c159
cleanup
vladak 9dd6d56
rename
vladak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2017, 2021, Chris Fraire <[email protected]>. | ||
*/ | ||
package org.opengrok.indexer.analysis; | ||
|
@@ -596,7 +596,7 @@ public void populateDocument(Document doc, File file, String path, AbstractAnaly | |
doc.add(new SortedDocValuesField(QueryBuilder.FULLPATH, | ||
new BytesRef(file.getAbsolutePath()))); | ||
|
||
if (RuntimeEnvironment.getInstance().isHistoryEnabled()) { | ||
if (HistoryGuru.getInstance().repositorySupportsHistory(file)) { | ||
populateDocumentHistory(doc, file); | ||
} | ||
doc.add(new Field(QueryBuilder.DATE, date, string_ft_stored_nanalyzed_norms)); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>. | ||
* Portions Copyright (c) 2020, Aleksandr Kirillov <[email protected]>. | ||
*/ | ||
|
@@ -580,7 +580,7 @@ public Configuration() { | |
setHandleHistoryOfRenamedFiles(false); | ||
setHistoryBasedReindex(true); | ||
setHistoryCache(true); | ||
setHistoryEnabled(true); | ||
setHistoryEnabled(false); | ||
vladak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setHitsPerPage(25); | ||
setIgnoredNames(new IgnoredNames()); | ||
setIncludedNames(new Filter()); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>. | ||
*/ | ||
package org.opengrok.indexer.history; | ||
|
@@ -54,7 +54,6 @@ | |
import org.opengrok.indexer.analysis.AnalyzerFactory; | ||
import org.opengrok.indexer.analysis.AnalyzerGuru; | ||
import org.opengrok.indexer.configuration.CommandTimeoutType; | ||
import org.opengrok.indexer.configuration.Configuration; | ||
import org.opengrok.indexer.configuration.Configuration.RemoteSCM; | ||
import org.opengrok.indexer.configuration.OpenGrokThreadFactory; | ||
import org.opengrok.indexer.configuration.PathAccepter; | ||
|
@@ -630,6 +629,14 @@ public boolean hasHistory(File file) { | |
} | ||
} | ||
|
||
return repositorySupportsHistory(file); | ||
} | ||
|
||
/** | ||
* @param file {@link File} object for a file under source root | ||
* @return whether related {@link Repository} and settings allow for history retrieval | ||
*/ | ||
public boolean repositorySupportsHistory(File file) { | ||
Repository repo = getRepository(file); | ||
if (repo == null) { | ||
LOGGER.finest(() -> String.format("cannot find repository for '%s' to check history presence", | ||
|
@@ -642,7 +649,7 @@ public boolean hasHistory(File file) { | |
} | ||
|
||
// This should return true for Annotate view. | ||
Configuration.RemoteSCM globalRemoteSupport = env.getRemoteScmSupported(); | ||
RemoteSCM globalRemoteSupport = env.getRemoteScmSupported(); | ||
boolean remoteSupported = ((globalRemoteSupport == RemoteSCM.ON) | ||
|| (globalRemoteSupport == RemoteSCM.UIONLY) | ||
|| (globalRemoteSupport == RemoteSCM.DIRBASED) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected]>. | ||
* Portions Copyright (c) 2020, 2023, Ric Harris <[email protected]>. | ||
*/ | ||
|
@@ -55,6 +55,7 @@ | |
import org.apache.commons.lang3.time.DateUtils; | ||
import org.eclipse.jgit.api.Git; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.EnabledOnOs; | ||
|
@@ -90,6 +91,12 @@ class FileHistoryCacheTest { | |
private boolean savedIsHandleHistoryOfRenamedFiles; | ||
private boolean savedIsTagsEnabled; | ||
|
||
@BeforeAll | ||
static void setUpClass() throws Exception { | ||
RuntimeEnvironment env = RuntimeEnvironment.getInstance(); | ||
env.setHistoryEnabled(true); | ||
} | ||
|
||
/** | ||
* Set up the test environment with repositories and a cache instance. | ||
*/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
opengrok-indexer/src/test/java/org/opengrok/indexer/index/AnalyzerGuruDocumentTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* CDDL HEADER START | ||
* | ||
* The contents of this file are subject to the terms of the | ||
* Common Development and Distribution License (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* | ||
* See LICENSE.txt included in this distribution for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing Covered Code, include this CDDL HEADER in each | ||
* file and include the License file at LICENSE.txt. | ||
* If applicable, add the following below this CDDL HEADER, with the | ||
* fields enclosed by brackets "[]" replaced with your own identifying | ||
* information: Portions Copyright [yyyy] [name of copyright owner] | ||
* | ||
* CDDL HEADER END | ||
*/ | ||
|
||
/* | ||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
*/ | ||
package org.opengrok.indexer.index; | ||
|
||
import org.apache.lucene.document.Document; | ||
import org.apache.lucene.document.TextField; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
import org.opengrok.indexer.analysis.AbstractAnalyzer; | ||
import org.opengrok.indexer.analysis.AnalyzerGuru; | ||
import org.opengrok.indexer.configuration.CommandTimeoutType; | ||
import org.opengrok.indexer.configuration.RuntimeEnvironment; | ||
import org.opengrok.indexer.history.HistoryGuru; | ||
import org.opengrok.indexer.history.Repository; | ||
import org.opengrok.indexer.history.RepositoryFactory; | ||
import org.opengrok.indexer.search.QueryBuilder; | ||
import org.opengrok.indexer.util.NullWriter; | ||
import org.opengrok.indexer.util.TestRepository; | ||
|
||
import java.io.File; | ||
import java.io.Writer; | ||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.Mockito.atLeast; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class AnalyzerGuruDocumentTest { | ||
private RuntimeEnvironment env; | ||
|
||
private static TestRepository testRepository; | ||
|
||
@BeforeEach | ||
void setUpClass() throws Exception { | ||
env = RuntimeEnvironment.getInstance(); | ||
|
||
testRepository = new TestRepository(); | ||
URL resourceURL = HistoryGuru.class.getResource("/repositories"); | ||
assertNotNull(resourceURL); | ||
testRepository.create(resourceURL); | ||
|
||
env.setSourceRoot(testRepository.getSourceRoot()); | ||
env.setDataRoot(testRepository.getDataRoot()); | ||
env.setHistoryEnabled(true); | ||
env.setProjectsEnabled(true); | ||
RepositoryFactory.initializeIgnoredNames(env); | ||
|
||
// Restore the project and repository information. | ||
env.setProjects(new HashMap<>()); | ||
env.setRepositories(testRepository.getSourceRoot()); | ||
HistoryGuru.getInstance().invalidateRepositories(env.getRepositories(), CommandTimeoutType.INDEXER); | ||
env.generateProjectRepositoriesMap(); | ||
} | ||
|
||
@AfterEach | ||
void tearDownClass() throws Exception { | ||
testRepository.destroy(); | ||
} | ||
|
||
/** | ||
* {@link AnalyzerGuru#populateDocument(Document, File, String, AbstractAnalyzer, Writer)} should populate | ||
* the history of the document only if the repository related to the file allows for it. | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(booleans = {false, true}) | ||
void testPopulateDocumentHistory(boolean historyEnabled) throws Exception { | ||
AnalyzerGuru analyzerGuru = new AnalyzerGuru(); | ||
Document doc = Mockito.mock(Document.class); | ||
Path filePath = Path.of(env.getSourceRootPath(), "git", "main.c"); | ||
File file = filePath.toFile(); | ||
assertTrue(file.exists()); | ||
HistoryGuru histGuru = HistoryGuru.getInstance(); | ||
Repository repository = histGuru.getRepository(file); | ||
assertNotNull(repository); | ||
repository.setHistoryEnabled(historyEnabled); | ||
String relativePath = env.getPathRelativeToSourceRoot(file); | ||
analyzerGuru.populateDocument(doc, file, relativePath, | ||
IndexDatabase.getAnalyzerFor(file, relativePath), new NullWriter()); | ||
ArgumentCaptor<TextField> argument = ArgumentCaptor.forClass(TextField.class); | ||
verify(doc, atLeast(1)).add(argument.capture()); | ||
assertEquals(historyEnabled, | ||
argument.getAllValues().stream().anyMatch(e -> e.name().equals(QueryBuilder.HIST))); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>. | ||
*/ | ||
package org.opengrok.indexer.search.context; | ||
|
@@ -64,9 +64,12 @@ class HistoryContextTest { | |
|
||
@BeforeAll | ||
static void setUpClass() throws Exception { | ||
RuntimeEnvironment env = RuntimeEnvironment.getInstance(); | ||
env.setHistoryEnabled(true); | ||
|
||
repositories = new TestRepository(); | ||
repositories.create(HistoryContextTest.class.getResource("/repositories")); | ||
RuntimeEnvironment.getInstance().setRepositories(repositories.getSourceRoot()); | ||
env.setRepositories(repositories.getSourceRoot()); | ||
} | ||
|
||
@AfterAll | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.