Skip to content

do not deep copy history entries #3248

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 2 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions opengrok-indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ Portions Copyright (c) 2020-2020, Lubos Kosco <[email protected]>.
<artifactId>micrometer-registry-statsd</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,38 +102,32 @@ private void doFileHistory(String filename, List<HistoryEntry> 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();
}
}
Expand All @@ -143,10 +137,7 @@ private void doFileHistory(String filename, List<HistoryEntry> 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)
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();

/**
Expand Down Expand Up @@ -276,24 +279,25 @@ TreeSet<TagEntry> 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<TagEntry> 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();
Expand Down