Skip to content

Commit 400829b

Browse files
vladakVladimir Kotal
authored and
Vladimir Kotal
committed
cache history for top-level directory in repository
fixes #1716
1 parent c185897 commit 400829b

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/org/opensolaris/opengrok/history/FileHistoryCache.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ class FileHistoryCache implements HistoryCache {
6464
private static final Logger LOGGER = LoggerFactory.getLogger(FileHistoryCache.class);
6565

6666
private final Object lock = new Object();
67+
6768
private final static String historyCacheDirName = "historycache";
68-
private final String latestRevFileName = "OpenGroklatestRev";
69+
private final static String latestRevFileName = "OpenGroklatestRev";
70+
private final static String DIRECTORY_FILE_PREFIX = "OpenGrokDirHist";
71+
6972
private boolean historyIndexDone = false;
7073

7174
@Override
@@ -105,13 +108,19 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
105108
hist = repository.getHistory(srcFile);
106109
}
107110

111+
File file = new File(root, filename);
112+
108113
if (hist == null) {
109114
hist = new History();
110115

111116
// File based history cache does not store files for individual
112-
// changesets so strip them.
117+
// changesets so strip them unless it is history for the repository.
113118
for (HistoryEntry ent : historyEntries) {
114-
ent.strip();
119+
if (file.isDirectory() && filename.equals(repository.getDirectoryName())) {
120+
ent.stripTags();
121+
} else {
122+
ent.strip();
123+
}
115124
}
116125

117126
// add all history entries
@@ -127,8 +136,8 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
127136
repository.assignTagsInHistory(hist);
128137
}
129138

130-
File file = new File(root, filename);
131-
if (!file.isDirectory()) {
139+
// Only store directory history for the top-level.
140+
if (!file.isDirectory() || filename.equals(repository.getDirectoryName())) {
132141
storeFile(hist, file, repository, !renamed);
133142
}
134143
}
@@ -189,6 +198,10 @@ private static File getCachedFile(File file) throws HistoryException {
189198
add = File.separator;
190199
}
191200
sb.append(add);
201+
if (file.isDirectory()) {
202+
sb.append(File.separator);
203+
sb.append(DIRECTORY_FILE_PREFIX);
204+
}
192205
sb.append(".gz");
193206
} catch (IOException e) {
194207
throw new HistoryException("Failed to get path relative to " +
@@ -391,6 +404,10 @@ public void store(History history, Repository repository)
391404
"Storing history for repo {0}",
392405
new Object[] {repository.getDirectoryName()});
393406

407+
// Firstly store the history for the top-level directory.
408+
doFileHistory(repository.getDirectoryName(), history.getHistoryEntries(),
409+
env, repository, env.getSourceRootFile(), null, false);
410+
394411
HashMap<String, List<HistoryEntry>> map =
395412
new HashMap<>();
396413

src/org/opensolaris/opengrok/history/HistoryEntry.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,24 @@ public void setChangeRequests(List<String> changeRequests) {
209209
}
210210

211211
/**
212-
* Remove "unneeded" info such as multiline history and files list
212+
* Remove list of files and tags.
213213
*/
214214
public void strip() {
215+
stripFiles();
216+
stripTags();
217+
}
218+
219+
/**
220+
* Remove list of files.
221+
*/
222+
public void stripFiles() {
215223
files.clear();
224+
}
225+
226+
/**
227+
* Remove tags.
228+
*/
229+
public void stripTags() {
216230
tags = null;
217231
}
218232
}

0 commit comments

Comments
 (0)