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

added missing documentation

parent b0a22783
Branches
Tags
No related merge requests found
......@@ -6,10 +6,19 @@ import java.util.Optional;
import java.util.function.Function;
import java.util.logging.Logger;
/**
* A {@link Branch} is a named {@link Reference} to a git branch pointing to an {@link Commit}.
*/
public class Branch extends Reference {
private static final Logger LOG = Logger.getLogger(Branch.class.getCanonicalName());
/**
* Constructs an object referencing an existing git branch.
*
* @param repo the repo this branch is part of
* @param name the branch name
*/
Branch(Repository repo, String name) {
super(repo, name);
}
......@@ -19,7 +28,7 @@ public class Branch extends Reference {
*
* @return true if the pull was successful
*/
public Boolean pull() {
public boolean pull() {
if (!repo.checkout(this)) {
return false;
}
......@@ -49,7 +58,7 @@ public class Branch extends Reference {
}
/**
* Reruns the branch name
* Reruns the branch name.
*
* @return the branch name
*/
......
......@@ -11,6 +11,7 @@ import java.util.regex.Pattern;
* A {@link Commit} made in a {@link Repository}.
*/
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
......@@ -19,7 +20,6 @@ public class Commit extends Reference {
private static final Pattern COMMITTER_INFO = Pattern.compile("committer (.*?)<(.*?)> (\\d+) ([+-]\\d{4})\\n");
private static final Pattern EMPTY_LINE = Pattern.compile("^\\s*$", Pattern.MULTILINE);
private String message;
private String author;
......
......@@ -60,6 +60,6 @@ public class DummyCommit extends Commit {
private void setterWarning() {
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
}
}
package de.uni_passau.fim.seibt.gitwrapper.repo;
import static de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.asList;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
import de.uni_passau.fim.seibt.gitwrapper.process.ToolNotWorkingException;
import de.uni_passau.fim.seibt.gitwrapper.process.ToolWrapper;
import java.io.File;
import java.util.HashMap;
......@@ -13,9 +15,7 @@ import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.ExecRes;
import de.uni_passau.fim.seibt.gitwrapper.process.ToolNotWorkingException;
import de.uni_passau.fim.seibt.gitwrapper.process.ToolWrapper;
import static de.uni_passau.fim.seibt.gitwrapper.process.ProcessExecutor.asList;
/**
* A wrapper for executing git commands.
......@@ -127,6 +127,12 @@ public class GitWrapper extends ToolWrapper {
return res.map(toRepo);
}
/**
* Imports an existing repository.
*
* @param directory the path to the repository
* @return the {@link Repository} if the import was successful or an empty {@link Optional} if there was an error
*/
public Optional<Repository> importRepository(File directory) {
if (!isGitDir(directory)) {
return Optional.empty();
......
......@@ -10,6 +10,11 @@ import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;
/**
* A git object referencing a tree-ish object.
* @see Commit
* @see Branch
*/
public abstract class Reference {
private static final Logger LOG = Logger.getLogger(Reference.class.getCanonicalName());
......@@ -24,6 +29,12 @@ public abstract class Reference {
this.git = repo.getGit();
}
/**
* Returns the id of this reference. This can be a SHA1 hash or a reference name, but must resolve to a
* valid git object.
*
* @return the id
*/
public String getId() {
return id;
}
......
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;
......@@ -7,24 +10,12 @@ import java.nio.file.Paths;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneId;
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.*;
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}.
*/
......@@ -159,7 +150,7 @@ public class Repository {
}
/**
* Returns the merge commits in this repository.
* Returns a list of all merge commits in this repository.
*
* @return the merge commits
*/
......@@ -195,7 +186,7 @@ public class Repository {
/**
* Returns the {@link Commit} currently pointed at by <code>HEAD</code>.
*
* @return the <code>HEAD</code> commit
* @return the <code>HEAD</code> commit or an empty {@link Optional} if there was an error
*/
public Optional<Commit> getCurrentHEAD() {
Optional<ExecRes> revParse = git.exec(dir, "rev-parse", "HEAD");
......@@ -219,6 +210,8 @@ public class Repository {
* @param id
* the ID for the {@link Commit}
* @return the {@link Commit}
*
* @see #getCommit(String)
*/
Commit getCommitUnchecked(String id) {
return commits.computeIfAbsent(id, theID -> new Commit(this, theID));
......
......@@ -11,8 +11,19 @@ import java.util.regex.Pattern;
public class Status {
private static final Pattern STATUS_ENTRY = Pattern.compile("(.?.) (?:.*? )?(.*?)\0");
/**
* The commit, this {@link Status} is based on.
*/
public final String id;
/**
* A map of files which were changed since the last commit (with id {@link #id}) and their status codes.
*/
public final Map<Path, String> changed;
/**
* A map of files which are in an unmerged state and their status codes.
*/
public final Map<Path, String> unmerged;
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment