@@ -64,8 +64,11 @@ class FileHistoryCache implements HistoryCache {
64
64
private static final Logger LOGGER = LoggerFactory .getLogger (FileHistoryCache .class );
65
65
66
66
private final Object lock = new Object ();
67
+
67
68
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
+
69
72
private boolean historyIndexDone = false ;
70
73
71
74
@ Override
@@ -105,13 +108,19 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
105
108
hist = repository .getHistory (srcFile );
106
109
}
107
110
111
+ File file = new File (root , filename );
112
+
108
113
if (hist == null ) {
109
114
hist = new History ();
110
115
111
116
// 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 .
113
118
for (HistoryEntry ent : historyEntries ) {
114
- ent .strip ();
119
+ if (file .isDirectory () && filename .equals (repository .getDirectoryName ())) {
120
+ ent .stripTags ();
121
+ } else {
122
+ ent .strip ();
123
+ }
115
124
}
116
125
117
126
// add all history entries
@@ -127,8 +136,8 @@ private void doFileHistory(String filename, List<HistoryEntry> historyEntries,
127
136
repository .assignTagsInHistory (hist );
128
137
}
129
138
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 ()) ) {
132
141
storeFile (hist , file , repository , !renamed );
133
142
}
134
143
}
@@ -189,6 +198,10 @@ private static File getCachedFile(File file) throws HistoryException {
189
198
add = File .separator ;
190
199
}
191
200
sb .append (add );
201
+ if (file .isDirectory ()) {
202
+ sb .append (File .separator );
203
+ sb .append (DIRECTORY_FILE_PREFIX );
204
+ }
192
205
sb .append (".gz" );
193
206
} catch (IOException e ) {
194
207
throw new HistoryException ("Failed to get path relative to " +
@@ -391,6 +404,10 @@ public void store(History history, Repository repository)
391
404
"Storing history for repo {0}" ,
392
405
new Object [] {repository .getDirectoryName ()});
393
406
407
+ // Firstly store the history for the top-level directory.
408
+ doFileHistory (repository .getDirectoryName (), history .getHistoryEntries (),
409
+ env , repository , env .getSourceRootFile (), null , false );
410
+
394
411
HashMap <String , List <HistoryEntry >> map =
395
412
new HashMap <>();
396
413
0 commit comments