diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Project.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Project.java index 5966db9fc30..d194a4c9e79 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Project.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/Project.java @@ -103,6 +103,11 @@ public class Project implements Comparable, Nameable, Serializable { */ private Boolean mergeCommitsEnabled = null; + /** + * This flag enables/disables per project tagging of history entries. + */ + private Boolean tagsEnabled = null; + /** * Username to used for repository authentication. This is propagated to all repositories of this project. */ @@ -285,6 +290,13 @@ public boolean isMergeCommitsEnabled() { return mergeCommitsEnabled != null && mergeCommitsEnabled; } + /** + * @return whether tagging of history entries is on + */ + public boolean isTagsEnabled() { + return tagsEnabled != null && tagsEnabled; + } + /** * @param flag true if project should handle renamed files, false otherwise. */ @@ -341,6 +353,13 @@ public final void setMergeCommitsEnabled(boolean flag) { this.mergeCommitsEnabled = flag; } + /** + * @param flag whether to tag history entries + */ + public final void setTagsEnabled(boolean flag) { + this.tagsEnabled = flag; + } + /** * @return true if this project handles renamed files. */ @@ -555,6 +574,10 @@ public final void completeWithDefaults() { if (historyBasedReindex == null) { setHistoryBasedReindex(env.isHistoryBasedReindex()); } + + if (tagsEnabled == null) { + setTagsEnabled(env.isTagsEnabled()); + } } /** diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BazaarRepository.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BazaarRepository.java index 361e954b275..844e3aeb0fb 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BazaarRepository.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BazaarRepository.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. * Portions Copyright (c) 2017, 2018, Chris Fraire . */ package org.opengrok.indexer.history; @@ -206,7 +206,7 @@ History getHistory(File file, String sinceRevision) throws HistoryException { History result = new BazaarHistoryParser(this).parse(file, sinceRevision); // Assign tags to changesets they represent // We don't need to check if this repository supports tags, because we know it:-) - if (env.isTagsEnabled()) { + if (this.isTagsEnabled()) { assignTagsInHistory(result); } return result; diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BitKeeperRepository.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BitKeeperRepository.java index a1b09ca004a..917d5552093 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BitKeeperRepository.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/BitKeeperRepository.java @@ -293,7 +293,7 @@ History getHistory(File file, String sinceRevision) throws HistoryException { // Assign tags to changesets they represent // We don't need to check if this repository supports tags, // because we know it :-) - if (env.isTagsEnabled()) { + if (this.isTagsEnabled()) { assignTagsInHistory(history); } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java index 14c75967647..056e2fd68bb 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java @@ -129,7 +129,7 @@ private void doFileHistory(String filename, History history, Repository reposito } // Assign tags to changesets they represent. - if (env.isTagsEnabled() && repository.hasFileBasedTags()) { + if (repository.isTagsEnabled() && repository.hasFileBasedTags()) { repository.assignTagsInHistory(history); } @@ -183,7 +183,7 @@ static History readHistory(File cacheFile, Repository repository) throws IOExcep History history = new History(historyEntryList); // Read tags from separate file. - if (env.isTagsEnabled() && repository.hasFileBasedTags()) { + if (repository.isTagsEnabled() && repository.hasFileBasedTags()) { File tagFile = getTagsFile(cacheFile); try (SmileParser parser = factory.createParser(tagFile)) { parser.setCodec(mapper); @@ -290,11 +290,11 @@ public void storeFile(History history, File file, Repository repository) throws * * @param histNew history object to store * @param file file to store the history object into - * @param repo repository for the file + * @param repository repository for the file * @param mergeHistory whether to merge the history with existing or store the histNew as is * @throws HistoryException if there was any problem with history cache generation */ - private void storeFile(History histNew, File file, Repository repo, boolean mergeHistory) throws HistoryException { + private void storeFile(History histNew, File file, Repository repository, boolean mergeHistory) throws HistoryException { File cacheFile; try { cacheFile = getCachedFile(file); @@ -321,7 +321,7 @@ private void storeFile(History histNew, File file, Repository repo, boolean merg throw new HistoryException("Failed to write history", ioe); } - boolean assignTags = env.isTagsEnabled() && repo.hasFileBasedTags(); + boolean assignTags = repository.isTagsEnabled() && repository.hasFileBasedTags(); // Append the contents of the pre-existing cache file to the temporary file. if (mergeHistory && cacheFile.exists()) { @@ -353,7 +353,7 @@ private void storeFile(History histNew, File file, Repository repo, boolean merg // to this somewhat crude solution of re-tagging from scratch. if (assignTags) { histNew.strip(); - repo.assignTagsInHistory(histNew); + repository.assignTagsInHistory(histNew); } } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java index 33eac3aa22f..f6271bc46a3 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java @@ -415,7 +415,7 @@ final void createCache(HistoryCache cache, String sinceRevision) throws HistoryE void finishCreateCache(HistoryCache cache, History history, String tillRevision) throws CacheException { // We need to refresh list of tags for incremental reindex. RuntimeEnvironment env = RuntimeEnvironment.getInstance(); - if (env.isTagsEnabled() && this.hasFileBasedTags()) { + if (this.isTagsEnabled() && this.hasFileBasedTags()) { this.buildTagList(new File(this.getDirectoryName()), CommandTimeoutType.INDEXER); } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryFactory.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryFactory.java index 2cfa07acd34..aaffb5ce5e8 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryFactory.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryFactory.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. * Portions Copyright (c) 2017, 2020, Chris Fraire . */ package org.opengrok.indexer.history; @@ -215,11 +215,11 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo }); } - if (repo.getType() == null || repo.getType().length() == 0) { + if (repo.getType() == null || repo.getType().isEmpty()) { repo.setType(repo.getClass().getSimpleName()); } - if (repo.getParent() == null || repo.getParent().length() == 0) { + if (repo.getParent() == null || repo.getParent().isEmpty()) { try { repo.setParent(repo.determineParent(cmdType)); } catch (IOException ex) { @@ -229,7 +229,7 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo } } - if (repo.getBranch() == null || repo.getBranch().length() == 0) { + if (repo.getBranch() == null || repo.getBranch().isEmpty()) { try { repo.setBranch(repo.determineBranch(cmdType)); } catch (IOException ex) { @@ -239,7 +239,7 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo } } - if (repo.getCurrentVersion() == null || repo.getCurrentVersion().length() == 0) { + if (repo.getCurrentVersion() == null || repo.getCurrentVersion().isEmpty()) { try { repo.setCurrentVersion(repo.determineCurrentVersion(cmdType)); } catch (IOException ex) { @@ -249,14 +249,16 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType, bo } } + // This has to be called before building tag list below as it depends on the repository properties + // inherited from the project/configuration. + repo.fillFromProject(); + // If this repository displays tags only for files changed by tagged // revision, we need to prepare list of all tags in advance. - if (cmdType.equals(CommandTimeoutType.INDEXER) && env.isTagsEnabled() && repo.hasFileBasedTags()) { + if (cmdType.equals(CommandTimeoutType.INDEXER) && repo.isTagsEnabled() && repo.hasFileBasedTags()) { repo.buildTagList(file, cmdType); } - repo.fillFromProject(); - break; } } diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java index 6efcb31b65c..470a744d069 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryInfo.java @@ -84,6 +84,8 @@ public class RepositoryInfo implements Serializable { @DTOElement private boolean mergeCommitsEnabled; @DTOElement + private boolean tagsEnabled; + @DTOElement private boolean historyBasedReindex; @DTOElement private String username; @@ -112,6 +114,7 @@ public RepositoryInfo(RepositoryInfo orig) { this.handleRenamedFiles = orig.handleRenamedFiles; this.mergeCommitsEnabled = orig.mergeCommitsEnabled; this.historyBasedReindex = orig.historyBasedReindex; + this.tagsEnabled = orig.tagsEnabled; this.username = orig.username; this.password = orig.password; } @@ -145,6 +148,13 @@ public boolean isMergeCommitsEnabled() { return this.mergeCommitsEnabled; } + /** + * @return whether history entries should be tagged + */ + public boolean isTagsEnabled() { + return this.tagsEnabled; + } + /** * @param flag true if the repository should handle merge commits, false otherwise. */ @@ -152,6 +162,13 @@ public void setMergeCommitsEnabled(boolean flag) { this.mergeCommitsEnabled = flag; } + /** + * @param flag whether to tag history entries + */ + public void setTagsEnabled(boolean flag) { + this.tagsEnabled = flag; + } + /** * @return true if history based reindex is enabled for the repository, false otherwise */ @@ -399,6 +416,7 @@ public void fillFromProject() { setAnnotationCacheEnabled(proj.isAnnotationCacheEnabled()); setHandleRenamedFiles(proj.isHandleRenamedFiles()); setMergeCommitsEnabled(proj.isMergeCommitsEnabled()); + setTagsEnabled(proj.isTagsEnabled()); setHistoryBasedReindex(proj.isHistoryBasedReindex()); setUsername(proj.getUsername()); setPassword(proj.getPassword()); @@ -410,6 +428,7 @@ public void fillFromProject() { setAnnotationCacheEnabled(env.isAnnotationCacheEnabled()); setHandleRenamedFiles(env.isHandleHistoryOfRenamedFiles()); setMergeCommitsEnabled(env.isMergeCommitsEnabled()); + setTagsEnabled(env.isTagsEnabled()); setHistoryBasedReindex(env.isHistoryBasedReindex()); } } @@ -458,7 +477,7 @@ public String toString() { if (!isHistoryCacheEnabled()) { stringBuilder.append("historyCache=off"); } else { - stringBuilder.append("historyCache=on,"); + stringBuilder.append("historyCache=on"); } if (isHandleRenamedFiles()) { @@ -480,6 +499,13 @@ public String toString() { stringBuilder.append("annotationCache=off"); } + stringBuilder.append(","); + if (isTagsEnabled()) { + stringBuilder.append("tagsEnabled=on"); + } else { + stringBuilder.append("tagsEnabled=off"); + } + if (getUsername() != null) { stringBuilder.append(","); stringBuilder.append("username:set"); diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryWithHistoryTraversal.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryWithHistoryTraversal.java index 19d3f812fca..dbcc46eb9e4 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryWithHistoryTraversal.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryWithHistoryTraversal.java @@ -116,7 +116,7 @@ public History getHistory(File file, String sinceRevision, String tillRevision, historyCollector.latestRev); // Assign tags to changesets they represent. - if (RuntimeEnvironment.getInstance().isTagsEnabled() && hasFileBasedTags()) { + if (this.isTagsEnabled() && hasFileBasedTags()) { assignTagsInHistory(history); } @@ -155,7 +155,7 @@ protected void doCreateCache(HistoryCache cache, String sinceRevision, File dire historyCollector.latestRev); // Assign tags to changesets they represent. - if (env.isTagsEnabled() && hasFileBasedTags()) { + if (this.isTagsEnabled() && hasFileBasedTags()) { assignTagsInHistory(history); } @@ -197,7 +197,7 @@ protected void doCreateCache(HistoryCache cache, String sinceRevision, File dire historyCollector.latestRev); // Assign tags to changesets they represent. - if (env.isTagsEnabled() && hasFileBasedTags()) { + if (this.isTagsEnabled() && hasFileBasedTags()) { assignTagsInHistory(history); } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ProjectTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ProjectTest.java index d7917c7ea32..bea2e7c594d 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ProjectTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/configuration/ProjectTest.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. */ package org.opengrok.indexer.configuration; @@ -149,6 +149,7 @@ void testMergeProjects1() { env.setBugPattern("([1-9][0-9]{6,7})"); env.setReviewPage("http://example.com/reviewPage"); env.setReviewPattern("([A-Z]{2}ARC[ \\\\/]\\\\d{4}/\\\\d{3})"); + env.setTagsEnabled(!new Configuration().isTagsEnabled()); Project p1 = new Project(); assertNotNull(p1); @@ -161,7 +162,8 @@ void testMergeProjects1() { () -> assertEquals(env.getBugPage(), p1.getBugPage()), () -> assertEquals(env.getBugPattern(), p1.getBugPattern()), () -> assertEquals(env.getReviewPage(), p1.getReviewPage()), - () -> assertEquals(env.getReviewPattern(), p1.getReviewPattern()) + () -> assertEquals(env.getReviewPattern(), p1.getReviewPattern()), + () -> assertEquals(env.isTagsEnabled(), p1.isTagsEnabled()) ); } @@ -205,6 +207,7 @@ void testMergeProjects2() { p1.setTabSize(new Project().getTabSize() + 9737); p1.setNavigateWindowEnabled(true); p1.setHandleRenamedFiles(true); + p1.setTagsEnabled(true); final String customBugPage = "http://example.com/bugPage"; p1.setBugPage(customBugPage); final String customBugPattern = "([1-9][0-1]{6,7})"; @@ -220,11 +223,12 @@ void testMergeProjects2() { () -> assertNotNull(p1), () -> assertTrue(p1.isNavigateWindowEnabled(), "Navigate window should be turned on"), () -> assertTrue(p1.isHandleRenamedFiles(), "Renamed file handling should be true"), + () -> assertTrue(p1.isTagsEnabled(), "Tags should be turned on"), () -> assertEquals(new Project().getTabSize() + 9737, p1.getTabSize()), - () -> assertEquals(p1.getBugPage(), customBugPage), - () -> assertEquals(p1.getBugPattern(), customBugPattern), - () -> assertEquals(p1.getReviewPage(), customReviewPage), - () -> assertEquals(p1.getReviewPattern(), customReviewPattern) + () -> assertEquals(customBugPage, p1.getBugPage()), + () -> assertEquals(customBugPattern, p1.getBugPattern()), + () -> assertEquals(customReviewPage, p1.getReviewPage()), + () -> assertEquals(customReviewPattern, p1.getReviewPattern()) ); } diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/FileHistoryCacheTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/FileHistoryCacheTest.java index ceeed564aac..830dd9e3cbc 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/FileHistoryCacheTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/FileHistoryCacheTest.java @@ -38,6 +38,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.net.URL; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -90,6 +91,7 @@ class FileHistoryCacheTest { private boolean savedFetchHistoryWhenNotInCache; private boolean savedIsHandleHistoryOfRenamedFiles; private boolean savedIsTagsEnabled; + private boolean savedIsIndexer; @BeforeAll static void setUpClass() throws Exception { @@ -103,7 +105,9 @@ static void setUpClass() throws Exception { @BeforeEach void setUp() throws Exception { repositories = new TestRepository(); - repositories.create(getClass().getResource("/repositories")); + URL url = getClass().getResource("/repositories"); + assertNotNull(url); + repositories.create(url); // Needed for HistoryGuru to operate normally. env.setRepositories(repositories.getSourceRoot()); @@ -114,6 +118,9 @@ void setUp() throws Exception { savedFetchHistoryWhenNotInCache = env.isFetchHistoryWhenNotInCache(); savedIsHandleHistoryOfRenamedFiles = env.isHandleHistoryOfRenamedFiles(); savedIsTagsEnabled = env.isTagsEnabled(); + savedIsIndexer = env.isIndexer(); + + env.setIndexer(true); } /** @@ -131,6 +138,7 @@ void tearDown() { env.setIncludedNames(new Filter()); env.setHandleHistoryOfRenamedFiles(savedIsHandleHistoryOfRenamedFiles); env.setTagsEnabled(savedIsTagsEnabled); + env.setIndexer(savedIsIndexer); } /** @@ -241,19 +249,25 @@ void testStoreAndGetNotRenamed() throws Exception { /** * Test tagging by creating history cache for repository with one tag and - * then importing couple of changesets which add both file changes and tags. + * then importing a couple of changesets which add both file changes and tags. * The last history entry before the import is important as it needs to be - * retagged when old history is merged with the new one. + * re-tagged when old history is merged with the new one. */ @EnabledForRepository(MERCURIAL) @Test void testStoreAndGetIncrementalTags() throws Exception { - // Enable tagging of history entries. + File reposRoot = new File(repositories.getSourceRoot(), "mercurial"); + assertTrue(reposRoot.exists()); + env.setTagsEnabled(true); - File reposRoot = new File(repositories.getSourceRoot(), "mercurial"); + // It is necessary to call getRepository() only after tags were enabled + // to produce list of tags. Repository repo = RepositoryFactory.getRepository(reposRoot); + assertNotNull(repo); + History historyToStore = repo.getHistory(reposRoot); + assertNotNull(historyToStore); // Store the history. cache.store(historyToStore, repo); @@ -429,16 +443,19 @@ void testRenameFileThenDoIncrementalReindex() throws Exception { // Use tags for better coverage. env.setTagsEnabled(true); - // Generate history index. // It is necessary to call getRepository() only after tags were enabled // to produce list of tags. Repository repo = RepositoryFactory.getRepository(reposRoot); + assertNotNull(repo); + + // Generate history index. History historyToStore = repo.getHistory(reposRoot); cache.store(historyToStore, repo); // Import changesets which rename one of the files in the repository. - MercurialRepositoryTest.runHgCommand(reposRoot, "import", - Paths.get(getClass().getResource("/history/hg-export-renamed.txt").toURI()).toString()); + URL url = getClass().getResource("/history/hg-export-renamed.txt"); + assertNotNull(url); + MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(url.toURI()).toString()); // Perform incremental reindex. repo.createCache(cache, cache.getLatestCachedRevision(repo)); @@ -539,42 +556,47 @@ void testRenameFileThenDoIncrementalReindex() throws Exception { @Test void testRenamedFilePlusChangesBranched() throws Exception { File reposRoot = new File(repositories.getSourceRoot(), "mercurial"); - History updatedHistory; - - // The test expects support for renamed files. - env.setHandleHistoryOfRenamedFiles(true); - - // Use tags for better coverage. - env.setTagsEnabled(true); + assertTrue(reposRoot.exists()); // Branch the repo and add one changeset. - runHgCommand(reposRoot, "unbundle", - Paths.get(getClass().getResource("/history/hg-branch.bundle").toURI()).toString()); + URL url = getClass().getResource("/history/hg-branch.bundle"); + assertNotNull(url); + runHgCommand(reposRoot, "unbundle", Paths.get(url.toURI()).toString()); // Import changesets which rename one of the files in the default branch. - runHgCommand(reposRoot, "import", - Paths.get(getClass().getResource("/history/hg-export-renamed.txt").toURI()).toString()); + url = getClass().getResource("/history/hg-export-renamed.txt"); + assertNotNull(url); + runHgCommand(reposRoot, "import", Paths.get(url.toURI()).toString()); // Switch to the newly created branch. runHgCommand(reposRoot, "update", "mybranch"); - // Generate history index. + // Use tags for better coverage. + env.setTagsEnabled(true); + // It is necessary to call getRepository() only after tags were enabled // to produce list of tags. Repository repo = RepositoryFactory.getRepository(reposRoot); + assertNotNull(repo); + + // The test expects support for renamed files. + repo.setHandleRenamedFiles(true); + + // Generate history index. History historyToStore = repo.getHistory(reposRoot); cache.store(historyToStore, repo); // Import changesets which rename the file in the new branch. - runHgCommand(reposRoot, "import", - Paths.get(getClass().getResource("/history/hg-export-renamed-branched.txt").toURI()).toString()); + url = getClass().getResource("/history/hg-export-renamed-branched.txt"); + assertNotNull(url); + runHgCommand(reposRoot, "import", Paths.get(url.toURI()).toString()); // Perform incremental reindex. repo.createCache(cache, cache.getLatestCachedRevision(repo)); // Check complete list of history entries for the renamed file. File testFile = new File(reposRoot.toString() + File.separatorChar + "blog.txt"); - updatedHistory = cache.get(testFile, repo, false); + History updatedHistory = cache.get(testFile, repo, false); HistoryEntry e0 = new HistoryEntry( "15:709c7a27f9fa", @@ -969,7 +991,6 @@ void testNoHistoryFetch() throws Exception { env.setFetchHistoryWhenNotInCache(false); // Pretend we are done with first phase of indexing. - env.setIndexer(true); HistoryGuru.getInstance().setHistoryIndexDone(); // First try repo with ability to fetch history for directories. diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryGuruTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryGuruTest.java index 9b6a8ed0dd9..e3e7b6e2474 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryGuruTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/HistoryGuruTest.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved. * Portions Copyright (c) 2019, 2020, Chris Fraire . */ package org.opengrok.indexer.history; @@ -466,18 +466,18 @@ void testGetLastHistoryEntryNonexistent() throws Exception { void testGetLastHistoryEntryVsIndexer(boolean isIndexerParam) throws HistoryException { boolean isIndexer = env.isIndexer(); env.setIndexer(isIndexerParam); - boolean isTagsEnabled = env.isTagsEnabled(); - env.setTagsEnabled(true); HistoryGuru instance = HistoryGuru.getInstance(); File file = new File(repository.getSourceRoot(), "git"); assertTrue(file.exists()); + Repository gitRepo = HistoryGuru.getInstance().getRepository(file); + assertNotNull(gitRepo); + gitRepo.setTagsEnabled(true); if (isIndexerParam) { assertThrows(IllegalStateException.class, () -> instance.getLastHistoryEntry(file, true, true)); } else { assertNotNull(instance.getLastHistoryEntry(file, true, true)); } env.setIndexer(isIndexer); - env.setTagsEnabled(isTagsEnabled); } @Test diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/RepositoryInfoTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/RepositoryInfoTest.java index 01a2c862e34..9fa50e10567 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/history/RepositoryInfoTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/history/RepositoryInfoTest.java @@ -109,14 +109,22 @@ void testFillFromProjectUsernamePassword() { private static Stream provideArgumentsForTestHistoryAndAnnotationFields() { return Stream.of( - Arguments.of(true, true, true), - Arguments.of(true, true, false), - Arguments.of(true, false, true), - Arguments.of(false, true, true), - Arguments.of(true, false, false), - Arguments.of(false, false, true), - Arguments.of(false, true, false), - Arguments.of(false, false, false) + Arguments.of(true, true, true, true), + Arguments.of(true, true, true, false), + Arguments.of(true, true, false, true), + Arguments.of(true, true, false, false), + Arguments.of(true, false, true, true), + Arguments.of(true, false, true, false), + Arguments.of(false, true, true, true), + Arguments.of(false, true, true, false), + Arguments.of(true, false, false, true), + Arguments.of(true, false, false, false), + Arguments.of(false, false, true, true), + Arguments.of(false, false, true, false), + Arguments.of(false, true, false, true), + Arguments.of(false, true, false, false), + Arguments.of(false, false, false, true), + Arguments.of(false, false, false, false) ); } @@ -128,7 +136,8 @@ private static Stream provideArgumentsForTestHistoryAndAnnotationFiel */ @ParameterizedTest @MethodSource("provideArgumentsForTestHistoryAndAnnotationFields") - void testHistoryAndAnnotationFields(boolean isProjectPresent, boolean historyEnabled, boolean useAnnotationCache) { + void testHistoryAndAnnotationFields(boolean isProjectPresent, boolean historyEnabled, boolean useAnnotationCache, + boolean tagsEnabled) { RuntimeEnvironment env = RuntimeEnvironment.getInstance(); env.setProjectsEnabled(true); @@ -139,10 +148,12 @@ void testHistoryAndAnnotationFields(boolean isProjectPresent, boolean historyEna project.setPath(dirName); project.setAnnotationCacheEnabled(useAnnotationCache); project.setHistoryEnabled(historyEnabled); + project.setTagsEnabled(tagsEnabled); env.setProjects(Map.of(projectName, project)); } else { env.setProjects(Collections.emptyMap()); env.setHistoryEnabled(historyEnabled); + env.setTagsEnabled(tagsEnabled); env.setAnnotationCacheEnabled(useAnnotationCache); } @@ -151,5 +162,6 @@ void testHistoryAndAnnotationFields(boolean isProjectPresent, boolean historyEna repositoryInfo.fillFromProject(); assertEquals(historyEnabled, repositoryInfo.isHistoryEnabled()); assertEquals(useAnnotationCache, repositoryInfo.isAnnotationCacheEnabled()); + assertEquals(tagsEnabled, repositoryInfo.isTagsEnabled()); } }