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

return an Optional<List> from getMergeCommits() as an empty Optional indicates...

return an Optional<List> from getMergeCommits() as an empty Optional indicates failure whereas an empty List indicates absence of merge commits, store SUMMARY and BOUNDARY header fields in the 'other' Map
parent a32012a0
No related branches found
No related tags found
No related merge requests found
package de.uni_passau.fim.seibt.gitwrapper.repo;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
......@@ -10,12 +7,24 @@ import java.nio.file.Paths;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Optional;
import java.util.Scanner;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
import org.apache.commons.io.FileUtils;
/**
* A git {@link Repository}.
*/
......@@ -150,11 +159,12 @@ public class Repository {
}
/**
* Returns a list of all merge commits in this repository.
* Optionally returns a list of all merge commits in this repository. An empty {@link Optional} will be returned
* if there is an error retrieving the merge commits.
*
* @return the merge commits
* @return the list of merge commits
*/
public List<Commit> getMergeCommits() {
public Optional<List<Commit>> getMergeCommits() {
Optional<ExecRes> revList = git.exec(dir, "rev-list", "--all", "--merges");
Function<ExecRes, List<Commit>> toCommitList = res -> {
......@@ -180,7 +190,7 @@ public class Repository {
return Arrays.stream(lines).map(this::getCommitUnchecked).collect(Collectors.toList());
};
return revList.map(toCommitList).orElse(Collections.emptyList());
return revList.map(toCommitList);
}
/**
......@@ -464,11 +474,9 @@ public class Repository {
commitFile = dir.toPath().resolve(Paths.get(lineScanner.nextLine().trim())).toFile();
break;
case SUMMARY:
// Skip the summary of the commit as it is just the first line of its message (for which there is a getter).
break;
// We do not explicitly store the summary of the commit as it is just the first line of its message (for which there is a getter).
case BOUNDARY:
// We do not store the information that this commit was the boundary of the 'git blame' call.
break;
// We do not explicitly store the information that this commit was the boundary of the 'git blame' call.
default:
other.put(headerKey, lineScanner.hasNextLine() ? lineScanner.nextLine().trim() : "");
}
......
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