Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2091] Minor Enhancements to Existing Regex Code #2115

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/reposense/authorship/FileInfoExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ public List<FileInfo> getEditedFileInfos(RepoConfiguration config, String lastCo
*/
public Set<Path> getFiles(RepoConfiguration repoConfig, boolean isBinaryFile) {
List<String> modifiedFileList = GitDiff.getModifiedFilesList(Paths.get(repoConfig.getRepoRoot()));
Pattern tabSplitter = Pattern.compile("\t");

// Gets rid of files with invalid directory name and filters by the {@code isBinaryFile} flag
return modifiedFileList.stream()
.filter(file -> isBinaryFile == file.startsWith(BINARY_FILE_LINE_DIFF_RESULT))
.map(file -> file.split("\t")[2])
.map(file -> tabSplitter.split(file)[2])
.filter(FileUtil::isValidPathWithLogging)
.map(filteredFile -> Paths.get(filteredFile))
.map(Paths::get)
.collect(Collectors.toCollection(HashSet::new));
}

Expand All @@ -160,11 +161,12 @@ private void setLinesToTrack(FileInfo fileInfo, String fileDiffResult) {
String[] linesChangedChunk = fileDiffResult.split(LINE_CHUNKS_SEPARATOR);
List<LineInfo> lineInfos = fileInfo.getLines();
int fileLinePointer = 0;
Pattern newlineSplitter = Pattern.compile("\n");

// skips the header, index starts from 1
for (int sectionIndex = 1; sectionIndex < linesChangedChunk.length; sectionIndex++) {
String linesChangedInSection = linesChangedChunk[sectionIndex];
String[] linesChanged = linesChangedInSection.split("\n");
String[] linesChanged = newlineSplitter.split(linesChangedInSection);
int startingLineNumber = getStartingLineNumber(linesChanged[LINE_CHANGED_HEADER_INDEX]);

// mark all untouched lines between sections as untracked
Expand Down
Loading