38
38
import java .io .File ;
39
39
import java .io .FileOutputStream ;
40
40
import java .io .IOException ;
41
+ import java .net .URI ;
41
42
import java .net .URL ;
42
43
import java .nio .charset .StandardCharsets ;
43
44
import java .nio .file .Files ;
@@ -91,6 +92,7 @@ class FileHistoryCacheTest {
91
92
private boolean savedFetchHistoryWhenNotInCache ;
92
93
private boolean savedIsHandleHistoryOfRenamedFiles ;
93
94
private boolean savedIsTagsEnabled ;
95
+ private boolean savedIsIndexer ;
94
96
95
97
@ BeforeAll
96
98
static void setUpClass () throws Exception {
@@ -117,6 +119,9 @@ void setUp() throws Exception {
117
119
savedFetchHistoryWhenNotInCache = env .isFetchHistoryWhenNotInCache ();
118
120
savedIsHandleHistoryOfRenamedFiles = env .isHandleHistoryOfRenamedFiles ();
119
121
savedIsTagsEnabled = env .isTagsEnabled ();
122
+ savedIsIndexer = env .isIndexer ();
123
+
124
+ env .setIndexer (true );
120
125
}
121
126
122
127
/**
@@ -134,6 +139,7 @@ void tearDown() {
134
139
env .setIncludedNames (new Filter ());
135
140
env .setHandleHistoryOfRenamedFiles (savedIsHandleHistoryOfRenamedFiles );
136
141
env .setTagsEnabled (savedIsTagsEnabled );
142
+ env .setIndexer (savedIsIndexer );
137
143
}
138
144
139
145
/**
@@ -254,12 +260,13 @@ void testStoreAndGetIncrementalTags() throws Exception {
254
260
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
255
261
assertTrue (reposRoot .exists ());
256
262
263
+ env .setTagsEnabled (true );
264
+
265
+ // It is necessary to call getRepository() only after tags were enabled
266
+ // to produce list of tags.
257
267
Repository repo = RepositoryFactory .getRepository (reposRoot );
258
268
assertNotNull (repo );
259
269
260
- // Enable tagging of history entries.
261
- repo .setTagsEnabled (true );
262
-
263
270
History historyToStore = repo .getHistory (reposRoot );
264
271
assertNotNull (historyToStore );
265
272
@@ -434,19 +441,22 @@ void testRenameFileThenDoIncrementalReindex() throws Exception {
434
441
// The test expects support for renamed files.
435
442
env .setHandleHistoryOfRenamedFiles (true );
436
443
444
+ // Use tags for better coverage.
445
+ env .setTagsEnabled (true );
446
+
447
+ // It is necessary to call getRepository() only after tags were enabled
448
+ // to produce list of tags.
437
449
Repository repo = RepositoryFactory .getRepository (reposRoot );
438
450
assertNotNull (repo );
439
451
440
- // Use tags for better coverage.
441
- repo .setTagsEnabled (true );
442
-
443
452
// Generate history index.
444
453
History historyToStore = repo .getHistory (reposRoot );
445
454
cache .store (historyToStore , repo );
446
455
447
456
// Import changesets which rename one of the files in the repository.
448
- MercurialRepositoryTest .runHgCommand (reposRoot , "import" ,
449
- Paths .get (getClass ().getResource ("/history/hg-export-renamed.txt" ).toURI ()).toString ());
457
+ URL url = getClass ().getResource ("/history/hg-export-renamed.txt" );
458
+ assertNotNull (url );
459
+ MercurialRepositoryTest .runHgCommand (reposRoot , "import" , Paths .get (url .toURI ()).toString ());
450
460
451
461
// Perform incremental reindex.
452
462
repo .createCache (cache , cache .getLatestCachedRevision (repo ));
@@ -548,42 +558,46 @@ void testRenameFileThenDoIncrementalReindex() throws Exception {
548
558
void testRenamedFilePlusChangesBranched () throws Exception {
549
559
File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
550
560
assertTrue (reposRoot .exists ());
551
- History updatedHistory ;
552
561
553
562
// Branch the repo and add one changeset.
554
- runHgCommand (reposRoot , "unbundle" ,
555
- Paths .get (getClass ().getResource ("/history/hg-branch.bundle" ).toURI ()).toString ());
563
+ URL url = getClass ().getResource ("/history/hg-branch.bundle" );
564
+ assertNotNull (url );
565
+ runHgCommand (reposRoot , "unbundle" , Paths .get (url .toURI ()).toString ());
556
566
557
567
// Import changesets which rename one of the files in the default branch.
558
- runHgCommand (reposRoot , "import" ,
559
- Paths .get (getClass ().getResource ("/history/hg-export-renamed.txt" ).toURI ()).toString ());
568
+ url = getClass ().getResource ("/history/hg-export-renamed.txt" );
569
+ assertNotNull (url );
570
+ runHgCommand (reposRoot , "import" , Paths .get (url .toURI ()).toString ());
560
571
561
572
// Switch to the newly created branch.
562
573
runHgCommand (reposRoot , "update" , "mybranch" );
563
574
575
+ // Use tags for better coverage.
576
+ env .setTagsEnabled (true );
577
+
578
+ // It is necessary to call getRepository() only after tags were enabled
579
+ // to produce list of tags.
564
580
Repository repo = RepositoryFactory .getRepository (reposRoot );
565
581
assertNotNull (repo );
566
582
567
583
// The test expects support for renamed files.
568
584
repo .setHandleRenamedFiles (true );
569
585
570
- // Use tags for better coverage.
571
- repo .setTagsEnabled (true );
572
-
573
586
// Generate history index.
574
587
History historyToStore = repo .getHistory (reposRoot );
575
588
cache .store (historyToStore , repo );
576
589
577
590
// Import changesets which rename the file in the new branch.
578
- runHgCommand (reposRoot , "import" ,
579
- Paths .get (getClass ().getResource ("/history/hg-export-renamed-branched.txt" ).toURI ()).toString ());
591
+ url = getClass ().getResource ("/history/hg-export-renamed-branched.txt" );
592
+ assertNotNull (url );
593
+ runHgCommand (reposRoot , "import" , Paths .get (url .toURI ()).toString ());
580
594
581
595
// Perform incremental reindex.
582
596
repo .createCache (cache , cache .getLatestCachedRevision (repo ));
583
597
584
598
// Check complete list of history entries for the renamed file.
585
599
File testFile = new File (reposRoot .toString () + File .separatorChar + "blog.txt" );
586
- updatedHistory = cache .get (testFile , repo , false );
600
+ History updatedHistory = cache .get (testFile , repo , false );
587
601
588
602
HistoryEntry e0 = new HistoryEntry (
589
603
"15:709c7a27f9fa" ,
@@ -978,7 +992,6 @@ void testNoHistoryFetch() throws Exception {
978
992
env .setFetchHistoryWhenNotInCache (false );
979
993
980
994
// Pretend we are done with first phase of indexing.
981
- env .setIndexer (true );
982
995
HistoryGuru .getInstance ().setHistoryIndexDone ();
983
996
984
997
// First try repo with ability to fetch history for directories.
0 commit comments