diff --git a/opengrok-indexer/pom.xml b/opengrok-indexer/pom.xml index e9b521790fb..4425dc9a097 100644 --- a/opengrok-indexer/pom.xml +++ b/opengrok-indexer/pom.xml @@ -215,6 +215,11 @@ Portions Copyright (c) 2020-2020, Lubos Kosco . micrometer-registry-statsd ${micrometer.version} + + org.jetbrains + annotations + 20.1.0 + 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 ddd461db506..d70c28500ac 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 @@ -102,38 +102,32 @@ private void doFileHistory(String filename, List historyEntries, Repository repository, File srcFile, File root, boolean renamed) throws HistoryException { - History hist = null; + File file = new File(root, filename); + // Only store directory history for the top-level directory. + if (file.isDirectory() && !filename.equals(repository.getDirectoryName())) { + LOGGER.log(Level.FINE, "Not storing history cache for {0}: not top level directory", file); + return; + } /* * If the file was renamed (in the changesets that are being indexed), * its history is not stored in the historyEntries so it needs to be acquired * directly from the repository. - * This ensures that complete history of the file (across renames) - * will be saved. + * This ensures that complete history of the file (across renames) will be saved. */ + History hist; if (renamed) { hist = repository.getHistory(srcFile); + } else { + hist = new History(historyEntries); } - File file = new File(root, filename); - - if (hist == null) { - hist = new History(); - - // File based history cache does not store files for individual - // changesets so strip them unless it is history for the repository. - for (HistoryEntry ent : historyEntries) { - if (file.isDirectory() && filename.equals(repository.getDirectoryName())) { - ent.stripTags(); - } else { - ent.strip(); - } - } - - // add all history entries - hist.setHistoryEntries(historyEntries); - } else { - for (HistoryEntry ent : hist.getHistoryEntries()) { + // File based history cache does not store files for individual + // changesets so strip them unless it is history for the repository. + for (HistoryEntry ent : hist.getHistoryEntries()) { + if (file.isDirectory()) { + ent.stripTags(); + } else { ent.strip(); } } @@ -143,10 +137,7 @@ private void doFileHistory(String filename, List historyEntries, repository.assignTagsInHistory(hist); } - // Only store directory history for the top-level. - if (!file.isDirectory() || filename.equals(repository.getDirectoryName())) { - storeFile(hist, file, repository, !renamed); - } + storeFile(hist, file, repository, !renamed); } private boolean isRenamedFile(String filename, Repository repository, History history) @@ -462,15 +453,8 @@ public void store(History history, Repository repository) list = new ArrayList<>(); map.put(s, list); } - /* - * We need to do deep copy in order to have different tags - * per each commit. - */ - if (env.isTagsEnabled() && repository.hasFileBasedTags()) { - list.add(new HistoryEntry(e)); - } else { - list.add(e); - } + + list.add(e); } } 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 34ae50492c0..b40b78b312e 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 @@ -51,6 +51,8 @@ import org.opengrok.indexer.util.BufferSink; import org.opengrok.indexer.util.Executor; +import org.jetbrains.annotations.NotNull; + /** * An interface for an external repository. * @@ -95,6 +97,7 @@ public abstract class Repository extends RepositoryInfo { * * @return {@code true} if the repository can get history for directories */ + @NotNull abstract boolean hasHistoryForDirectories(); /** @@ -276,24 +279,25 @@ TreeSet getTagList() { * tags to changesets which actually exist in the history of given file. * Must be implemented repository-specific. * - * @see getTagList - * @param hist History we want to assign tags to. + * @see #getTagList + * @param hist History object we want to assign tags to. */ void assignTagsInHistory(History hist) { if (hist == null) { return; } + if (this.getTagList() == null) { throw new IllegalStateException("getTagList() is null"); } + Iterator it = this.getTagList().descendingIterator(); TagEntry lastTagEntry = null; - // Go through all commits of given file for (HistoryEntry ent : hist.getHistoryEntries()) { // Assign all tags created since the last revision - // Revision in this HistoryEntry must be already specified! - // TODO is there better way to do this? We need to "repeat" - // last element returned by call to next() + // Revision in this HistoryEntry must be already specified ! + // TODO: is there better way to do this? We need to "repeat" + // last element returned by call to next() while (lastTagEntry != null || it.hasNext()) { if (lastTagEntry == null) { lastTagEntry = it.next();