From 2f9df1fd1bd3b993002d600f94f6d28115c5f1b3 Mon Sep 17 00:00:00 2001
From: Georg Seibt <seibt@fim.uni-passau.de>
Date: Fri, 21 Oct 2016 15:33:27 +0200
Subject: [PATCH] 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

---
 .../fim/seibt/gitwrapper/repo/Repository.java | 32 ++++++++++++-------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
index 5642588..4a5edc0 100644
--- a/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
+++ b/src/de/uni_passau/fim/seibt/gitwrapper/repo/Repository.java
@@ -1,8 +1,5 @@
 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() : "");
                 }
-- 
GitLab