Skip to content

Commit d998216

Browse files
author
Vladimir Kotal
committed
do not deep copy history entries
1 parent 09fa92b commit d998216

File tree

2 files changed

+26
-41
lines changed

2 files changed

+26
-41
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/FileHistoryCache.java

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -102,38 +102,32 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
102102
Repository repository, File srcFile, File root, boolean renamed)
103103
throws HistoryException {
104104

105-
History hist = null;
105+
File file = new File(root, filename);
106+
// Only store directory history for the top-level directory.
107+
if (file.isDirectory() && !filename.equals(repository.getDirectoryName())) {
108+
LOGGER.log(Level.FINE, "Not storing history cache for {0}: not top level directory", file);
109+
return;
110+
}
106111

107112
/*
108113
* If the file was renamed (in the changesets that are being indexed),
109114
* its history is not stored in the historyEntries so it needs to be acquired
110115
* directly from the repository.
111-
* This ensures that complete history of the file (across renames)
112-
* will be saved.
116+
* This ensures that complete history of the file (across renames) will be saved.
113117
*/
118+
History hist;
114119
if (renamed) {
115120
hist = repository.getHistory(srcFile);
121+
} else {
122+
hist = new History(historyEntries);
116123
}
117124

118-
File file = new File(root, filename);
119-
120-
if (hist == null) {
121-
hist = new History();
122-
123-
// File based history cache does not store files for individual
124-
// changesets so strip them unless it is history for the repository.
125-
for (HistoryEntry ent : historyEntries) {
126-
if (file.isDirectory() && filename.equals(repository.getDirectoryName())) {
127-
ent.stripTags();
128-
} else {
129-
ent.strip();
130-
}
131-
}
132-
133-
// add all history entries
134-
hist.setHistoryEntries(historyEntries);
135-
} else {
136-
for (HistoryEntry ent : hist.getHistoryEntries()) {
125+
// File based history cache does not store files for individual
126+
// changesets so strip them unless it is history for the repository.
127+
for (HistoryEntry ent : hist.getHistoryEntries()) {
128+
if (file.isDirectory()) {
129+
ent.stripTags();
130+
} else {
137131
ent.strip();
138132
}
139133
}
@@ -143,10 +137,7 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
143137
repository.assignTagsInHistory(hist);
144138
}
145139

146-
// Only store directory history for the top-level.
147-
if (!file.isDirectory() || filename.equals(repository.getDirectoryName())) {
148-
storeFile(hist, file, repository, !renamed);
149-
}
140+
storeFile(hist, file, repository, !renamed);
150141
}
151142

152143
private boolean isRenamedFile(String filename, Repository repository, History history)
@@ -462,15 +453,8 @@ public void store(History history, Repository repository)
462453
list = new ArrayList<>();
463454
map.put(s, list);
464455
}
465-
/*
466-
* We need to do deep copy in order to have different tags
467-
* per each commit.
468-
*/
469-
if (env.isTagsEnabled() && repository.hasFileBasedTags()) {
470-
list.add(new HistoryEntry(e));
471-
} else {
472-
list.add(e);
473-
}
456+
457+
list.add(e);
474458
}
475459
}
476460

opengrok-indexer/src/main/java/org/opengrok/indexer/history/Repository.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,24 +276,25 @@ TreeSet<TagEntry> getTagList() {
276276
* tags to changesets which actually exist in the history of given file.
277277
* Must be implemented repository-specific.
278278
*
279-
* @see getTagList
280-
* @param hist History we want to assign tags to.
279+
* @see #getTagList
280+
* @param hist History object we want to assign tags to.
281281
*/
282282
void assignTagsInHistory(History hist) {
283283
if (hist == null) {
284284
return;
285285
}
286+
286287
if (this.getTagList() == null) {
287288
throw new IllegalStateException("getTagList() is null");
288289
}
290+
289291
Iterator<TagEntry> it = this.getTagList().descendingIterator();
290292
TagEntry lastTagEntry = null;
291-
// Go through all commits of given file
292293
for (HistoryEntry ent : hist.getHistoryEntries()) {
293294
// Assign all tags created since the last revision
294-
// Revision in this HistoryEntry must be already specified!
295-
// TODO is there better way to do this? We need to "repeat"
296-
// last element returned by call to next()
295+
// Revision in this HistoryEntry must be already specified !
296+
// TODO: is there better way to do this? We need to "repeat"
297+
// last element returned by call to next()
297298
while (lastTagEntry != null || it.hasNext()) {
298299
if (lastTagEntry == null) {
299300
lastTagEntry = it.next();

0 commit comments

Comments
 (0)