48
48
import java .util .LinkedList ;
49
49
import java .util .List ;
50
50
import java .util .Map ;
51
+ import java .util .Set ;
51
52
52
53
import org .apache .commons .lang3 .time .DateUtils ;
53
54
import org .eclipse .jgit .api .Git ;
60
61
import org .junit .jupiter .params .provider .ValueSource ;
61
62
import org .mockito .Mockito ;
62
63
import org .opengrok .indexer .condition .EnabledForRepository ;
64
+ import org .opengrok .indexer .configuration .CommandTimeoutType ;
63
65
import org .opengrok .indexer .configuration .Filter ;
64
66
import org .opengrok .indexer .configuration .IgnoredNames ;
65
67
import org .opengrok .indexer .configuration .RuntimeEnvironment ;
73
75
*/
74
76
class FileHistoryCacheTest {
75
77
78
+ private static final String SUBVERSION_REPO_LOC = "subversion" ;
79
+
76
80
private static final String SVN_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ;
77
81
78
82
private final RuntimeEnvironment env = RuntimeEnvironment .getInstance ();
@@ -633,7 +637,7 @@ void testRenamedFilePlusChangesBranched() throws Exception {
633
637
void testMultipleRenamedFiles () throws Exception {
634
638
createSvnRepository ();
635
639
636
- File reposRoot = new File (repositories .getSourceRoot (), "subversion" );
640
+ File reposRoot = new File (repositories .getSourceRoot (), SUBVERSION_REPO_LOC );
637
641
History updatedHistory ;
638
642
639
643
// The test expects support for renamed files.
@@ -645,7 +649,7 @@ void testMultipleRenamedFiles() throws Exception {
645
649
cache .store (historyToStore , repo );
646
650
647
651
// Check complete list of history entries for the renamed file.
648
- File testFile = new File (reposRoot .toString () + File . separatorChar + "FileZ.txt" );
652
+ File testFile = new File (reposRoot .toString (), "FileZ.txt" );
649
653
updatedHistory = cache .get (testFile , repo , false );
650
654
assertEquals (3 , updatedHistory .getHistoryEntries ().size ());
651
655
@@ -677,6 +681,82 @@ void testMultipleRenamedFiles() throws Exception {
677
681
assertSameEntries (histConstruct .getHistoryEntries (), updatedHistory .getHistoryEntries (), false );
678
682
}
679
683
684
+
685
+ /**
686
+ * For an Subversion repository, verify we can get a list of files that were in a directory
687
+ * at the point it was renamed.
688
+ */
689
+ @ EnabledForRepository (SUBVERSION )
690
+ @ Test
691
+ void testSubversionFilesInDirectoryLog () throws Exception {
692
+ createSvnRepository ();
693
+
694
+ File reposRoot = new File (repositories .getSourceRoot (), SUBVERSION_REPO_LOC );
695
+
696
+ // The test expects support for renamed files.
697
+ env .setHandleHistoryOfRenamedFiles (true );
698
+
699
+ // Generate history index.
700
+ SubversionRepository svnRepo = (SubversionRepository ) RepositoryFactory .getRepository (reposRoot );
701
+ Set <String > files = svnRepo .getFilesInDirectoryAtRevision (
702
+ Path .of (SUBVERSION_REPO_LOC , "renamedFolder" ).toString (), "12" , CommandTimeoutType .INDEXER );
703
+ assertEquals (
704
+ Set .of (Path .of (SUBVERSION_REPO_LOC , "renamedFolder" , "FileInRenamedFolder.txt" ).toString ()), files );
705
+ }
706
+
707
+
708
+ /**
709
+ * Make sure produces correct history for a file which was in a directory that was renamed.
710
+ */
711
+ @ EnabledForRepository (SUBVERSION )
712
+ @ Test
713
+ void testRenamedDirectory () throws Exception {
714
+ createSvnRepository ();
715
+
716
+ File reposRoot = new File (repositories .getSourceRoot (), SUBVERSION_REPO_LOC );
717
+ History updatedHistory ;
718
+
719
+ // The test expects support for renamed files.
720
+ env .setHandleHistoryOfRenamedFiles (true );
721
+
722
+ // Generate history index.
723
+ Repository repo = RepositoryFactory .getRepository (reposRoot );
724
+ History historyToStore = repo .getHistory (reposRoot );
725
+ cache .store (historyToStore , repo );
726
+
727
+ // Check complete list of history entries for the file in the renamed folder.
728
+ File testFile = Path .of (reposRoot .toString (), "renamedFolder" , "FileInRenamedFolder.txt" ).toFile ();
729
+ updatedHistory = cache .get (testFile , repo , false );
730
+ assertEquals (3 , updatedHistory .getHistoryEntries ().size ());
731
+
732
+ HistoryEntry e0 = new HistoryEntry (
733
+ "14" ,
734
+ DateUtils .parseDate ("2021-03-02T11:34:28.030Z" , SVN_DATE_FORMAT ),
735
+ "RichardH" ,
736
+ "Update to renamed file." ,
737
+ true );
738
+ HistoryEntry e1 = new HistoryEntry (
739
+ "13" ,
740
+ DateUtils .parseDate ("2021-03-02T08:54:54.693Z" , SVN_DATE_FORMAT ),
741
+ "RichardH" ,
742
+ "rename folder" ,
743
+ true );
744
+ HistoryEntry e2 = new HistoryEntry (
745
+ "12" ,
746
+ DateUtils .parseDate ("2021-03-02T08:54:30.615Z" , SVN_DATE_FORMAT ),
747
+ "RichardH" ,
748
+ "added file to new folder" ,
749
+ true );
750
+
751
+ History histConstruct = new History ();
752
+ LinkedList <HistoryEntry > entriesConstruct = new LinkedList <>();
753
+ entriesConstruct .add (e0 );
754
+ entriesConstruct .add (e1 );
755
+ entriesConstruct .add (e2 );
756
+ histConstruct .setHistoryEntries (entriesConstruct );
757
+ assertSameEntries (histConstruct .getHistoryEntries (), updatedHistory .getHistoryEntries (), false );
758
+ }
759
+
680
760
private void createSvnRepository () throws Exception {
681
761
var svnLog = FileHistoryCacheTest .class .getResource ("/history/svnlog.dump" );
682
762
Path tempDir = Files .createTempDirectory ("opengrok" );
@@ -697,7 +777,7 @@ private void createSvnRepository() throws Exception {
697
777
assertEquals (0 , svnLoadRepoFromDumpProcess .waitFor ());
698
778
699
779
var svnCheckoutProcess = new ProcessBuilder ("svn" , "checkout" , Path .of (repo ).toUri ().toString (),
700
- Path .of (repositories .getSourceRoot ()).resolve ("subversion" ).toString ())
780
+ Path .of (repositories .getSourceRoot ()).resolve (SUBVERSION_REPO_LOC ).toString ())
701
781
.start ();
702
782
assertEquals (0 , svnCheckoutProcess .waitFor ());
703
783
}
@@ -784,7 +864,7 @@ void testRenamedFileHistoryWithPerPartes(int maxCount) throws Exception {
784
864
void testRenamedFile () throws Exception {
785
865
createSvnRepository ();
786
866
787
- File reposRoot = new File (repositories .getSourceRoot (), "subversion" );
867
+ File reposRoot = new File (repositories .getSourceRoot (), SUBVERSION_REPO_LOC );
788
868
History updatedHistory ;
789
869
790
870
// The test expects support for renamed files.
@@ -796,8 +876,7 @@ void testRenamedFile() throws Exception {
796
876
cache .store (historyToStore , repo );
797
877
798
878
// Check complete list of history entries for the renamed file.
799
- File testFile = new File (reposRoot .toString () + File .separatorChar
800
- + "subfolder" + File .separatorChar + "TestFileRenamedAgain.txt" );
879
+ File testFile = Path .of (reposRoot .toString (), "subfolder" , "TestFileRenamedAgain.txt" ).toFile ();
801
880
updatedHistory = cache .get (testFile , repo , false );
802
881
assertEquals (4 , updatedHistory .getHistoryEntries ().size ());
803
882
0 commit comments