Skip to content
Snippets Groups Projects
Commit 071d321d authored by Florian Heck's avatar Florian Heck
Browse files

formatting and minor edits

parent b56c47f1
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,12 @@ import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor; ...@@ -4,9 +4,12 @@ import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Logger;
public class Branch extends Reference { public class Branch extends Reference {
private static final Logger LOG = Logger.getLogger(Branch.class.getCanonicalName());
Branch(Repository repo, String name) { Branch(Repository repo, String name) {
super(repo, name); super(repo, name);
} }
...@@ -20,6 +23,7 @@ public class Branch extends Reference { ...@@ -20,6 +23,7 @@ public class Branch extends Reference {
if (!repo.checkout(this)) { if (!repo.checkout(this)) {
return false; return false;
} }
Optional<ProcessExecutor.ExecRes> fetch = git.exec(repo.getDir(), "pull"); Optional<ProcessExecutor.ExecRes> fetch = git.exec(repo.getDir(), "pull");
Function<ProcessExecutor.ExecRes, Boolean> toBoolean = res -> { Function<ProcessExecutor.ExecRes, Boolean> toBoolean = res -> {
boolean failed = git.failed(res); boolean failed = git.failed(res);
...@@ -46,6 +50,7 @@ public class Branch extends Reference { ...@@ -46,6 +50,7 @@ public class Branch extends Reference {
/** /**
* Reruns the branch name * Reruns the branch name
*
* @return the branch name * @return the branch name
*/ */
public String getName() { public String getName() {
......
...@@ -3,6 +3,7 @@ package de.uni_passau.fim.seibt.gitwrapper.repo; ...@@ -3,6 +3,7 @@ package de.uni_passau.fim.seibt.gitwrapper.repo;
import java.time.Instant; import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -10,6 +11,7 @@ import java.util.regex.Pattern; ...@@ -10,6 +11,7 @@ import java.util.regex.Pattern;
* A {@link Commit} made in a {@link Repository}. * A {@link Commit} made in a {@link Repository}.
*/ */
public class Commit extends Reference { public class Commit extends Reference {
private static final Logger LOG = Logger.getLogger(Commit.class.getCanonicalName());
// since there is no porcelain format for this command, this regex is might depend on the git version // since there is no porcelain format for this command, this regex is might depend on the git version
private static final Pattern TREE_INFO = Pattern.compile("tree (.{40})\\nparent (.{40})\\n"); private static final Pattern TREE_INFO = Pattern.compile("tree (.{40})\\nparent (.{40})\\n");
......
...@@ -59,7 +59,7 @@ public class DummyCommit extends Commit { ...@@ -59,7 +59,7 @@ public class DummyCommit extends Commit {
} }
private void setterWarning() { private void setterWarning() {
LOG.warning(() -> "Ignoring a setter call on the DummyCommit for " + repo); LOG.finest(() -> "Ignoring a setter call on the DummyCommit for " + repo);
// TODO gets called often while parsing blame lines, maybe change level // TODO gets called often while parsing blame lines, maybe change level
} }
} }
...@@ -8,7 +8,8 @@ import java.util.logging.Logger; ...@@ -8,7 +8,8 @@ import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class Reference { public abstract class Reference {
protected static final Logger LOG = Logger.getLogger(Commit.class.getCanonicalName());
private static final Logger LOG = Logger.getLogger(Reference.class.getCanonicalName());
protected final String id; protected final String id;
protected final Repository repo; protected final Repository repo;
...@@ -32,7 +33,6 @@ public abstract class Reference { ...@@ -32,7 +33,6 @@ public abstract class Reference {
* @return the merge base or an empty {@link Optional} if there is no merge base or an exception occurred * @return the merge base or an empty {@link Optional} if there is no merge base or an exception occurred
*/ */
public Optional<Commit> getMergeBase(Reference other) { public Optional<Commit> getMergeBase(Reference other) {
if (!repo.equals(other.repo)) { if (!repo.equals(other.repo)) {
LOG.warning(() -> { LOG.warning(() -> {
String msg = "Failed to obtain a merge base for %s and %s as they are not from the same repository."; String msg = "Failed to obtain a merge base for %s and %s as they are not from the same repository.";
...@@ -67,10 +67,11 @@ public abstract class Reference { ...@@ -67,10 +67,11 @@ public abstract class Reference {
* @param other the {@link Reference} to merge * @param other the {@link Reference} to merge
* @return <code>false</code>, if the merge failed, or contains conflicts. * @return <code>false</code>, if the merge failed, or contains conflicts.
*/ */
public Boolean merge(Reference other) { public boolean merge(Reference other) {
if (!repo.checkout(this)) { if (!repo.checkout(this)) {
return false; return false;
} }
Optional<ProcessExecutor.ExecRes> mergeBase = git.exec(repo.getDir(), "merge", "-n", "-q", other.getId()); Optional<ProcessExecutor.ExecRes> mergeBase = git.exec(repo.getDir(), "merge", "-n", "-q", other.getId());
Function<ProcessExecutor.ExecRes, Boolean> toBoolean = res -> { Function<ProcessExecutor.ExecRes, Boolean> toBoolean = res -> {
if (git.failed(res)) { if (git.failed(res)) {
...@@ -106,7 +107,7 @@ public abstract class Reference { ...@@ -106,7 +107,7 @@ public abstract class Reference {
} }
@Override @Override
public boolean equals(Object o) { public final boolean equals(Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
...@@ -120,7 +121,7 @@ public abstract class Reference { ...@@ -120,7 +121,7 @@ public abstract class Reference {
} }
@Override @Override
public int hashCode() { public final int hashCode() {
return Objects.hash(repo, id); return Objects.hash(repo, id);
} }
......
...@@ -214,7 +214,6 @@ public class Repository { ...@@ -214,7 +214,6 @@ public class Repository {
* @return the {@link Commit} or an empty {@link Optional} if the ID is invalid or an exception occurs * @return the {@link Commit} or an empty {@link Optional} if the ID is invalid or an exception occurs
*/ */
public Optional<Commit> getCommit(String id) { public Optional<Commit> getCommit(String id) {
if (commits.containsKey(id)) { if (commits.containsKey(id)) {
return Optional.of(commits.get(id)); return Optional.of(commits.get(id));
} }
...@@ -327,7 +326,6 @@ public class Repository { ...@@ -327,7 +326,6 @@ public class Repository {
* @see FileUtils#copyDirectory(File, File) * @see FileUtils#copyDirectory(File, File)
*/ */
public Optional<Repository> copy(File destination) { public Optional<Repository> copy(File destination) {
try { try {
if (destination.exists() && destination.isDirectory()) { if (destination.exists() && destination.isDirectory()) {
LOG.warning(() -> String.format("%s already exists. Merging source and destination directories.", destination)); LOG.warning(() -> String.format("%s already exists. Merging source and destination directories.", destination));
...@@ -455,9 +453,11 @@ public class Repository { ...@@ -455,9 +453,11 @@ public class Repository {
other.put(headerKey, lineScanner.nextLine().trim()); other.put(headerKey, lineScanner.nextLine().trim());
} }
} }
if (authorInstant != null && authorTZ != null) { if (authorInstant != null && authorTZ != null) {
commit.setAuthorTime(OffsetDateTime.ofInstant(authorInstant, authorTZ)); commit.setAuthorTime(OffsetDateTime.ofInstant(authorInstant, authorTZ));
} }
if (committerInstant != null && committerTZ != null) { if (committerInstant != null && committerTZ != null) {
commit.setCommitterTime(OffsetDateTime.ofInstant(committerInstant, committerTZ)); commit.setCommitterTime(OffsetDateTime.ofInstant(committerInstant, committerTZ));
} }
......
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