-
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 2 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()); | ||
|
@@ -1610,37 +1610,4 @@ public ConfigurationException(String message) { | |
super(message); | ||
} | ||
} | ||
|
||
/** | ||
* Check if configuration is populated and self-consistent. | ||
* @throws ConfigurationException on error | ||
*/ | ||
public void checkConfiguration() throws ConfigurationException { | ||
|
||
if (getSourceRoot() == null) { | ||
throw new ConfigurationException("Source root is not specified."); | ||
} | ||
|
||
if (getDataRoot() == null) { | ||
throw new ConfigurationException("Data root is not specified."); | ||
} | ||
|
||
if (!new File(getSourceRoot()).canRead()) { | ||
throw new ConfigurationException("Source root directory '" + getSourceRoot() + "' must be readable."); | ||
} | ||
|
||
if (!new File(getDataRoot()).canWrite()) { | ||
throw new ConfigurationException("Data root directory '" + getDataRoot() + "' must be writable."); | ||
} | ||
|
||
if (!isHistoryEnabled() && isHistoryBasedReindex()) { | ||
LOGGER.log(Level.INFO, "History based reindex is on, however history is off. " + | ||
"History has to be enabled for history based reindex."); | ||
} | ||
|
||
if (!isHistoryCache() && isHistoryBasedReindex()) { | ||
LOGGER.log(Level.INFO, "History based reindex is on, however history cache is off. " + | ||
"History cache has to be enabled for history based reindex."); | ||
} | ||
} | ||
} |
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 file object | ||
* @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
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
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.