Skip to content

Commit c8d58df

Browse files
author
Vladimir Kotal
committed
use native paths
1 parent f2037bd commit c8d58df

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,14 @@ History getHistory(File file, String sinceRevision) throws HistoryException {
595595
return result;
596596
}
597597

598+
private static String getNativePath(String path) {
599+
if (!File.separator.equals("/")) {
600+
return path.replace("/", File.separator);
601+
}
602+
603+
return path;
604+
}
605+
598606
private void getFiles(org.eclipse.jgit.lib.Repository repository,
599607
RevCommit oldCommit, RevCommit newCommit,
600608
Set<String> files, List<String> renamedFiles)
@@ -610,10 +618,10 @@ private void getFiles(org.eclipse.jgit.lib.Repository repository,
610618

611619
for (DiffEntry diff : diffs) {
612620
if (diff.getChangeType() != DiffEntry.ChangeType.DELETE) {
613-
files.add(getDirectoryNameRelative() + "/" + diff.getNewPath());
621+
files.add(getDirectoryNameRelative() + File.separator + getNativePath(diff.getNewPath()));
614622
}
615623
if (diff.getChangeType() == DiffEntry.ChangeType.RENAME && isHandleRenamedFiles()) {
616-
renamedFiles.add(diff.getNewPath());
624+
renamedFiles.add(getNativePath(diff.getNewPath()));
617625
}
618626
}
619627
}

opengrok-indexer/src/test/java/org/opengrok/indexer/history/GitRepositoryTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,35 +547,39 @@ public void testHistory(boolean renamedHandling) throws Exception {
547547
new HistoryEntry("84599b3c", new Date(1485438707000L),
548548
"Kryštof Tulinger <[email protected]>", null,
549549
" renaming directories\n\n", true,
550-
Set.of("/git/moved2/renamed2.c")),
550+
Set.of(File.separator + Paths.get("git", "moved2", "renamed2.c"))),
551551
new HistoryEntry("67dfbe26", new Date(1485263397000L),
552552
"Kryštof Tulinger <[email protected]>", null,
553553
" renaming renamed -> renamed2\n\n", true,
554-
Set.of("/git/moved/renamed2.c")),
554+
Set.of(File.separator + Paths.get("git", "moved", "renamed2.c"))),
555555
new HistoryEntry("1086eaf5", new Date(1485263368000L),
556556
"Kryštof Tulinger <[email protected]>", null,
557557
" adding some lines into renamed.c\n\n", true,
558-
Set.of("/git/moved/renamed.c")),
558+
Set.of(File.separator + Paths.get("git", "moved", "renamed.c"))),
559559
new HistoryEntry("b6413947", new Date(1485263264000L),
560560
"Kryštof Tulinger <[email protected]>", null,
561561
" moved renamed.c to new location\n\n", true,
562-
Set.of("/git/moved/renamed.c")),
562+
Set.of(File.separator + Paths.get("git", "moved", "renamed.c"))),
563563
new HistoryEntry("ce4c98ec", new Date(1485263232000L), // start in the sub-test below
564564
"Kryštof Tulinger <[email protected]>", null,
565565
" adding simple file for renamed file testing\n\n", true,
566-
Set.of("/git/renamed.c")),
566+
Set.of(File.separator + Paths.get("git", "renamed.c"))),
567567
new HistoryEntry("aa35c258", new Date(1218571965000L),
568568
"Trond Norbye <[email protected]>", null,
569569
" Add lint make target and fix lint warnings\n\n", true,
570-
Set.of("/git/Makefile", "/git/main.c")),
570+
Set.of(File.separator + Paths.get("git", "Makefile"),
571+
File.separator + Paths.get("git", "main.c"))),
571572
new HistoryEntry("84821564", new Date(1218571643000L),
572573
"Trond Norbye <[email protected]>", null,
573574
" Add the result of a make on Solaris x86\n\n", true,
574-
Set.of("/git/main.o", "/git/testsprog")),
575+
Set.of(File.separator + Paths.get("git", "main.o"),
576+
File.separator + Paths.get("git", "testsprog"))),
575577
new HistoryEntry("bb74b7e8", new Date(1218571573000L),
576578
"Trond Norbye <[email protected]>", null,
577579
" Added a small test program\n\n", true,
578-
Set.of("/git/Makefile", "/git/header.h", "/git/main.c")));
580+
Set.of(File.separator + Paths.get("git", "Makefile"),
581+
File.separator + Paths.get("git", "header.h"),
582+
File.separator + Paths.get("git", "main.c"))));
579583

580584
List<String> expectedRenamedFiles = List.of("moved/renamed2.c", "moved2/renamed2.c", "moved/renamed.c");
581585

0 commit comments

Comments
 (0)