Skip to content

Commit 8191342

Browse files
author
Vladimir Kotal
committed
Merge pull request #820 from vladak/store_incr_fix
create file which stores the latest cached revision also when renamed fi...
2 parents 6b54193 + b8f55cb commit 8191342

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ private void storeFile(History histNew, File file) throws HistoryException {
287287
}
288288
}
289289

290+
private void finishStore(Repository repository, String latestRev) {
291+
storeLatestCachedRevision(repository, latestRev);
292+
OpenGrokLogger.getLogger().log(Level.FINE,
293+
"Done storing history for repo {0}",
294+
new Object[] {repository.getDirectoryName()});
295+
}
296+
290297
/**
291298
* Store history for the whole repository in directory hierarchy resembling
292299
* the original repository structure. History of individual files will be
@@ -378,6 +385,7 @@ public void store(History history, Repository repository)
378385
}
379386

380387
if (!RuntimeEnvironment.isRenamedFilesEnabled()) {
388+
finishStore(repository, latestRev);
381389
return;
382390
}
383391

@@ -437,10 +445,7 @@ public void run() {
437445
} catch (InterruptedException ex) {
438446
OpenGrokLogger.getLogger().log(Level.SEVERE, "latch exception" + ex);
439447
}
440-
storeLatestCachedRevision(repository, latestRev);
441-
OpenGrokLogger.getLogger().log(Level.FINE,
442-
"Done storing history for repo {0}",
443-
new Object[] {repository.getDirectoryName()});
448+
finishStore(repository, latestRev);
444449
}
445450

446451
@Override

test/org/opensolaris/opengrok/history/FileHistoryCacheTest.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public class FileHistoryCacheTest extends TestCase {
5050

5151
cache = new FileHistoryCache();
5252
cache.initialize();
53-
54-
// The tests expect support for renamed files.
55-
System.setProperty("org.opensolaris.opengrok.history.RenamedHandlingEnabled", "1");
5653
}
5754

5855
/**
@@ -119,11 +116,37 @@ private void assertSameEntry(HistoryEntry expected, HistoryEntry actual, boolean
119116
}
120117
}
121118

119+
/**
120+
* Basic tests for the {@code store()} method on cache with disabled
121+
* handling of renamed files.
122+
*/
123+
public void testStoreAndGetNotRenamed() throws Exception {
124+
File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
125+
Repository repo = RepositoryFactory.getRepository(reposRoot);
126+
History historyToStore = repo.getHistory(reposRoot);
127+
128+
cache.store(historyToStore, repo);
129+
130+
// This makes sure that the file which contains the latest revision
131+
// has indeed been created.
132+
assertEquals("9:8b340409b3a8", cache.getLatestCachedRevision(repo));
133+
134+
// test reindex
135+
History historyNull = new History();
136+
cache.store(historyNull, repo);
137+
138+
assertEquals("9:8b340409b3a8", cache.getLatestCachedRevision(repo));
139+
}
140+
122141
/**
123142
* Basic tests for the {@code store()} and {@code get()} methods.
124143
*/
125144
public void testStoreAndGet() throws Exception {
126145
File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
146+
147+
// The test expects support for renamed files.
148+
System.setProperty("org.opensolaris.opengrok.history.RenamedHandlingEnabled", "1");
149+
127150
Repository repo = RepositoryFactory.getRepository(reposRoot);
128151
History historyToStore = repo.getHistory(reposRoot);
129152

@@ -234,6 +257,10 @@ public void testStoreAndGet() throws Exception {
234257
public void testRenamedFile() throws Exception {
235258
File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
236259
Repository repo = RepositoryFactory.getRepository(reposRoot);
260+
261+
// The test expects support for renamed files.
262+
System.setProperty("org.opensolaris.opengrok.history.RenamedHandlingEnabled", "1");
263+
237264
History historyToStore = repo.getHistory(reposRoot);
238265

239266
cache.store(historyToStore, repo);

0 commit comments

Comments
 (0)