import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.eclipse.jgit.annotations.NonNull;
+import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.attributes.AttributesNodeProvider;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.errors.AmbiguousObjectException;
}
/** @return listeners observing only events on this repository. */
+ @NonNull
public ListenerList getListenerList() {
return myListeners;
}
*/
public abstract void create(boolean bare) throws IOException;
- /** @return local metadata directory; null if repository isn't local. */
+ /**
+ * @return local metadata directory; {@code null} if repository isn't local.
+ */
+ /*
+ * TODO This method should be annotated as Nullable, because in some
+ * specific configurations metadata is not located in the local file system
+ * (for example in memory databases). In "usual" repositories this
+ * annotation would only cause compiler errors at places where the actual
+ * directory can never be null.
+ */
public File getDirectory() {
return gitDir;
}
/**
* @return the object database which stores this repository's data.
*/
+ @NonNull
public abstract ObjectDatabase getObjectDatabase();
/** @return a new inserter to create objects in {@link #getObjectDatabase()} */
+ @NonNull
public ObjectInserter newObjectInserter() {
return getObjectDatabase().newInserter();
}
/** @return a new reader to read objects from {@link #getObjectDatabase()} */
+ @NonNull
public ObjectReader newObjectReader() {
return getObjectDatabase().newReader();
}
/** @return the reference database which stores the reference namespace. */
+ @NonNull
public abstract RefDatabase getRefDatabase();
/**
* @return the configuration of this repository
*/
+ @NonNull
public abstract StoredConfig getConfig();
/**
* instance for each use.
* @since 4.2
*/
+ @NonNull
public abstract AttributesNodeProvider createAttributesNodeProvider();
/**
- * @return the used file system abstraction
+ * @return the used file system abstraction, or or {@code null} if
+ * repository isn't local.
+ */
+ /*
+ * TODO This method should be annotated as Nullable, because in some
+ * specific configurations metadata is not located in the local file system
+ * (for example in memory databases). In "usual" repositories this
+ * annotation would only cause compiler errors at places where the actual
+ * directory can never be null.
*/
public FS getFS() {
return fs;
* @throws IOException
* the object store cannot be accessed.
*/
+ @NonNull
public ObjectLoader open(final AnyObjectId objectId)
throws MissingObjectException, IOException {
return getObjectDatabase().open(objectId);
* @throws IOException
* the object store cannot be accessed.
*/
+ @NonNull
public ObjectLoader open(AnyObjectId objectId, int typeHint)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
* a symbolic ref was passed in and could not be resolved back
* to the base ref, as the symbolic ref could not be read.
*/
+ @NonNull
public RefUpdate updateRef(final String ref) throws IOException {
return updateRef(ref, false);
}
* a symbolic ref was passed in and could not be resolved back
* to the base ref, as the symbolic ref could not be read.
*/
+ @NonNull
public RefUpdate updateRef(final String ref, final boolean detach) throws IOException {
return getRefDatabase().newUpdate(ref, detach);
}
* the rename could not be performed.
*
*/
+ @NonNull
public RefRename renameRef(final String fromRef, final String toRef) throws IOException {
return getRefDatabase().newRename(fromRef, toRef);
}
*
* @param revstr
* A git object references expression
- * @return an ObjectId or null if revstr can't be resolved to any ObjectId
+ * @return an ObjectId or {@code null} if revstr can't be resolved to any
+ * ObjectId
* @throws AmbiguousObjectException
* {@code revstr} contains an abbreviated ObjectId and this
* repository contains more than one object which match to the
* @throws IOException
* on serious errors
*/
+ @Nullable
public ObjectId resolve(final String revstr)
throws AmbiguousObjectException, IncorrectObjectTypeException,
RevisionSyntaxException, IOException {
* expects a branch or revision id.
*
* @param revstr
- * @return object id or ref name from resolved expression
+ * @return object id or ref name from resolved expression or {@code null} if
+ * given expression cannot be resolved
* @throws AmbiguousObjectException
* @throws IOException
*/
+ @Nullable
public String simplify(final String revstr)
throws AmbiguousObjectException, IOException {
try (RevWalk rw = new RevWalk(this)) {
}
}
+ @Nullable
private Object resolve(final RevWalk rw, final String revstr)
throws IOException {
char[] revChars = revstr.toCharArray();
return true;
}
+ @Nullable
private RevObject parseSimple(RevWalk rw, String revstr) throws IOException {
ObjectId id = resolveSimple(revstr);
return id != null ? rw.parseAny(id) : null;
}
+ @Nullable
private ObjectId resolveSimple(final String revstr) throws IOException {
if (ObjectId.isId(revstr))
return ObjectId.fromString(revstr);
return null;
}
+ @Nullable
private String resolveReflogCheckout(int checkoutNo)
throws IOException {
ReflogReader reader = getReflogReader(Constants.HEAD);
return rw.parseCommit(entry.getNewId());
}
+ @Nullable
private ObjectId resolveAbbreviation(final String revstr) throws IOException,
AmbiguousObjectException {
AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr);
getRefDatabase().close();
}
+ @NonNull
@SuppressWarnings("nls")
public String toString() {
String desc;
- if (getDirectory() != null)
- desc = getDirectory().getPath();
+ File directory = getDirectory();
+ if (directory != null)
+ desc = directory.getPath();
else
desc = getClass().getSimpleName() + "-" //$NON-NLS-1$
+ System.identityHashCode(this);
* current ObjectId in hexadecimal string format.
*
* @return name of current branch (for example {@code refs/heads/master}),
- * an ObjectId in hex format if the current branch is detached,
- * or null if the repository is corrupt and has no HEAD reference.
+ * an ObjectId in hex format if the current branch is detached, or
+ * {@code null} if the repository is corrupt and has no HEAD
+ * reference.
* @throws IOException
*/
+ @Nullable
public String getFullBranch() throws IOException {
Ref head = getRef(Constants.HEAD);
if (head == null)
* leading prefix {@code refs/heads/} is removed from the reference before
* it is returned to the caller.
*
- * @return name of current branch (for example {@code master}), an
- * ObjectId in hex format if the current branch is detached,
- * or null if the repository is corrupt and has no HEAD reference.
+ * @return name of current branch (for example {@code master}), an ObjectId
+ * in hex format if the current branch is detached, or {@code null}
+ * if the repository is corrupt and has no HEAD reference.
* @throws IOException
*/
+ @Nullable
public String getBranch() throws IOException {
String name = getFullBranch();
if (name != null)
return shortenRefName(name);
- return name;
+ return null;
}
/**
*
* @return unmodifiable collection of other known objects.
*/
+ @NonNull
public Set<ObjectId> getAdditionalHaves() {
return Collections.emptySet();
}
* the name of the ref to lookup. May be a short-hand form, e.g.
* "master" which is is automatically expanded to
* "refs/heads/master" if "refs/heads/master" already exists.
- * @return the Ref with the given name, or null if it does not exist
+ * @return the Ref with the given name, or {@code null} if it does not exist
* @throws IOException
*/
+ @Nullable
public Ref getRef(final String name) throws IOException {
return getRefDatabase().getRef(name);
}
/**
* @return mutable map of all known refs (heads, tags, remotes).
*/
+ @NonNull
public Map<String, Ref> getAllRefs() {
try {
return getRefDatabase().getRefs(RefDatabase.ALL);
* of the entry contains the ref with the full tag name
* ("refs/tags/v1.0").
*/
+ @NonNull
public Map<String, Ref> getTags() {
try {
return getRefDatabase().getRefs(Constants.R_TAGS);
* will be true and getPeeledObjectId will contain the peeled object
* (or null).
*/
+ @NonNull
public Ref peel(final Ref ref) {
try {
return getRefDatabase().peel(ref);
/**
* @return a map with all objects referenced by a peeled ref.
*/
+ @NonNull
public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() {
Map<String, Ref> allRefs = getAllRefs();
Map<AnyObjectId, Set<Ref>> ret = new HashMap<AnyObjectId, Set<Ref>>(allRefs.size());
}
/**
- * @return the index file location
+ * @return the index file location or {@code null} if repository isn't
+ * local.
* @throws NoWorkTreeException
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @NonNull
public File getIndexFile() throws NoWorkTreeException {
if (isBare())
throw new NoWorkTreeException();
* the index file is using a format or extension that this
* library does not support.
*/
+ @NonNull
public DirCache readDirCache() throws NoWorkTreeException,
CorruptObjectException, IOException {
return DirCache.read(this);
* the index file is using a format or extension that this
* library does not support.
*/
+ @NonNull
public DirCache lockDirCache() throws NoWorkTreeException,
CorruptObjectException, IOException {
// we want DirCache to inform us so that we can inform registered
/**
* @return an important state
*/
+ @NonNull
public RepositoryState getRepositoryState() {
if (isBare() || getDirectory() == null)
return RepositoryState.BARE;
* @return normalized repository relative path or the empty
* string if the file is not relative to the work directory.
*/
+ @NonNull
public static String stripWorkDir(File workDir, File file) {
final String filePath = file.getPath();
final String workDirPath = workDir.getPath();
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @NonNull
public File getWorkTree() throws NoWorkTreeException {
if (isBare())
throw new NoWorkTreeException();
*
* @return a more user friendly ref name
*/
+ @NonNull
public static String shortenRefName(String refName) {
if (refName.startsWith(Constants.R_HEADS))
return refName.substring(Constants.R_HEADS.length());
* @return the remote branch name part of <code>refName</code>, i.e. without
* the <code>refs/remotes/<remote></code> prefix, if
* <code>refName</code> represents a remote tracking branch;
- * otherwise null.
+ * otherwise {@code null}.
* @since 3.4
*/
+ @Nullable
public String shortenRemoteBranchName(String refName) {
for (String remote : getRemoteNames()) {
String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
* @return the remote name part of <code>refName</code>, i.e. without the
* <code>refs/remotes/<remote></code> prefix, if
* <code>refName</code> represents a remote tracking branch;
- * otherwise null.
+ * otherwise {@code null}.
* @since 3.4
*/
+ @Nullable
public String getRemoteName(String refName) {
for (String remote : getRemoteNames()) {
String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
/**
* @param refName
- * @return a {@link ReflogReader} for the supplied refname, or null if the
- * named ref does not exist.
+ * @return a {@link ReflogReader} for the supplied refname, or {@code null}
+ * if the named ref does not exist.
* @throws IOException
* the ref could not be accessed.
* @since 3.0
*/
+ @Nullable
public abstract ReflogReader getReflogReader(String refName)
throws IOException;
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @Nullable
public String readMergeCommitMsg() throws IOException, NoWorkTreeException {
return readCommitMsgFile(Constants.MERGE_MSG);
}
* See {@link #isBare()}.
* @since 4.0
*/
+ @Nullable
public String readCommitEditMsg() throws IOException, NoWorkTreeException {
return readCommitMsgFile(Constants.COMMIT_EDITMSG);
}
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @Nullable
public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null)
throw new NoWorkTreeException();
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @Nullable
public ObjectId readCherryPickHead() throws IOException,
NoWorkTreeException {
if (isBare() || getDirectory() == null)
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @Nullable
public ObjectId readRevertHead() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null)
throw new NoWorkTreeException();
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @Nullable
public ObjectId readOrigHead() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null)
throw new NoWorkTreeException();
* if this is bare, which implies it has no working directory.
* See {@link #isBare()}.
*/
+ @Nullable
public String readSquashCommitMsg() throws IOException {
return readCommitMsgFile(Constants.SQUASH_MSG);
}
writeCommitMsg(squashMsgFile, msg);
}
+ @Nullable
private String readCommitMsgFile(String msgFilename) throws IOException {
if (isBare() || getDirectory() == null)
throw new NoWorkTreeException();
* Read a file from the git directory.
*
* @param filename
- * @return the raw contents or null if the file doesn't exist or is empty
+ * @return the raw contents or {@code null} if the file doesn't exist or is
+ * empty
* @throws IOException
*/
+ @Nullable
private byte[] readGitDirectoryFile(String filename) throws IOException {
File file = new File(getDirectory(), filename);
try {
* @throws IOException
* @since 3.2
*/
+ @NonNull
public List<RebaseTodoLine> readRebaseTodo(String path,
boolean includeComments)
throws IOException {
* @return the names of all known remotes
* @since 3.4
*/
+ @NonNull
public Set<String> getRemoteNames() {
return getConfig()
.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);