Skip to content
Snippets Groups Projects
Commit c227ee60 authored by Georg Seibt's avatar Georg Seibt :nerd:
Browse files

add a method for retrieving the paths affected by a commit

parent 58bda64b
No related branches found
No related tags found
No related merge requests found
package de.uni_passau.fim.seibt.gitwrapper.repo;
import java.nio.file.Path;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -73,6 +77,41 @@ public class Commit extends Reference {
return res.map(toBoolean);
}
/**
* Returns the paths that were affected by this {@link Commit}.
*
* @return optionally the {@link List} of {@link Path Paths}
*/
public Optional<List<Path>> getAffectedPaths() {
Optional<ExecRes> res = git.exec(repo.getDir(), "show", "--name-only", "--pretty=format:", id);
Function<ExecRes, List<Path>> toPaths = execRes -> {
Supplier<String> errorMsg = () -> "Failed to determine the paths affected by '" + this + "'.";
if (git.failed(execRes)) {
LOG.warning(errorMsg);
return null;
}
String[] lines = execRes.getStdOutTrimmed().split("\\R");
List<Path> paths = new ArrayList<>();
for (String line : lines) {
Optional<Path> oPath = git.getPath(line);
if (oPath.isPresent()) {
paths.add(oPath.get());
} else {
LOG.warning(errorMsg);
return null;
}
}
return paths;
};
return res.map(toPaths);
}
/**
* Returns the author of this commit.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment