Browse Source

Null-annotated Repository class and fixed related compiler errors

org.eclipse.jgit.lib.Repository class is an example of the API which
should be written with Java 8 java.util.Optional<T> type. Unfortunately
this API is already released and widely used. The good clients are
currently doing their best with checking return values for null and bad
clients do not know how bad their code is.

I've tried not to change any logic and to be as less intrusive as
possible. Most of the JGit code was well prepared to this, only few
classes needed some smaller fixes.

This change fixes all compiler errors in JGit and replaces possible
NPE's with either appropriate exceptions, avoiding multiple "Nullable
return" method calls or early returning from the method.

Because annotating getDirectory() and getFS() as Nullable would cause
lot of additional changes in JGit and EGit they are postponed.

Change-Id: Ie8369d2c9c5fac5ce83b3b1b9bc217d7b55502a3
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
stable-4.3
Andrey Loskutov 9 years ago
parent
commit
1020f40813
  1. 1
      org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
  2. 10
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java
  3. 3
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
  4. 10
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java
  5. 7
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
  6. 5
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  7. 7
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
  8. 1
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java
  9. 2
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  10. 6
      org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java
  11. 11
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
  12. 5
      org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java
  13. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
  14. 12
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java
  15. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/RefRename.java
  16. 112
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  17. 5
      org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
  18. 15
      org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java
  19. 5
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
  20. 6
      org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java
  21. 3
      org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java

1
org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties

@ -143,6 +143,7 @@ notAJgitCommand={0} is not a jgit command
notARevision=Not a revision: {0} notARevision=Not a revision: {0}
notATree={0} is not a tree notATree={0} is not a tree
notAValidRefName={0} is not a valid ref name notAValidRefName={0} is not a valid ref name
notAValidCommitName={0} is not a valid commit name
notAnIndexFile={0} is not an index file notAnIndexFile={0} is not an index file
notAnObject={0} is not an object notAnObject={0} is not an object
notFound=!! NOT FOUND !! notFound=!! NOT FOUND !!

10
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Branch.java

@ -154,10 +154,14 @@ class Branch extends TextBuiltin {
startBranch = Constants.HEAD; startBranch = Constants.HEAD;
Ref startRef = db.getRef(startBranch); Ref startRef = db.getRef(startBranch);
ObjectId startAt = db.resolve(startBranch + "^0"); //$NON-NLS-1$ ObjectId startAt = db.resolve(startBranch + "^0"); //$NON-NLS-1$
if (startRef != null) if (startRef != null) {
startBranch = startRef.getName(); startBranch = startRef.getName();
else } else if (startAt != null) {
startBranch = startAt.name(); startBranch = startAt.name();
} else {
throw die(MessageFormat.format(
CLIText.get().notAValidCommitName, startBranch));
}
startBranch = Repository.shortenRefName(startBranch); startBranch = Repository.shortenRefName(startBranch);
String newRefName = newHead; String newRefName = newHead;
if (!newRefName.startsWith(Constants.R_HEADS)) if (!newRefName.startsWith(Constants.R_HEADS))
@ -249,7 +253,7 @@ class Branch extends TextBuiltin {
String current = db.getBranch(); String current = db.getBranch();
ObjectId head = db.resolve(Constants.HEAD); ObjectId head = db.resolve(Constants.HEAD);
for (String branch : branches) { for (String branch : branches) {
if (current.equals(branch)) { if (branch.equals(current)) {
throw die(MessageFormat.format(CLIText.get().cannotDeleteTheBranchWhichYouAreCurrentlyOn, branch)); throw die(MessageFormat.format(CLIText.get().cannotDeleteTheBranchWhichYouAreCurrentlyOn, branch));
} }
RefUpdate update = db.updateRef((remote ? Constants.R_REMOTES RefUpdate update = db.updateRef((remote ? Constants.R_REMOTES

3
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java

@ -96,6 +96,9 @@ class Commit extends TextBuiltin {
commitCmd.setAmend(amend); commitCmd.setAmend(amend);
commitCmd.setAll(all); commitCmd.setAll(all);
Ref head = db.getRef(Constants.HEAD); Ref head = db.getRef(Constants.HEAD);
if (head == null) {
throw die(CLIText.get().onBranchToBeBorn);
}
RevCommit commit; RevCommit commit;
try { try {
commit = commitCmd.call(); commit = commitCmd.call();

10
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Merge.java

@ -120,7 +120,7 @@ class Merge extends TextBuiltin {
throw die(MessageFormat.format( throw die(MessageFormat.format(
CLIText.get().refDoesNotExistOrNoCommit, ref)); CLIText.get().refDoesNotExistOrNoCommit, ref));
Ref oldHead = db.getRef(Constants.HEAD); Ref oldHead = getOldHead();
MergeResult result; MergeResult result;
try (Git git = new Git(db)) { try (Git git = new Git(db)) {
MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy) MergeCommand mergeCmd = git.merge().setStrategy(mergeStrategy)
@ -205,6 +205,14 @@ class Merge extends TextBuiltin {
} }
} }
private Ref getOldHead() throws IOException {
Ref oldHead = db.getRef(Constants.HEAD);
if (oldHead == null) {
throw die(CLIText.get().onBranchToBeBorn);
}
return oldHead;
}
private boolean isMergedInto(Ref oldHead, AnyObjectId src) private boolean isMergedInto(Ref oldHead, AnyObjectId src)
throws IOException { throws IOException {
try (RevWalk revWalk = new RevWalk(db)) { try (RevWalk revWalk = new RevWalk(db)) {

7
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java

@ -242,9 +242,10 @@ class DiffAlgorithms extends TextBuiltin {
} }
}); });
if (db.getDirectory() != null) { File directory = db.getDirectory();
String name = db.getDirectory().getName(); if (directory != null) {
File parent = db.getDirectory().getParentFile(); String name = directory.getName();
File parent = directory.getParentFile();
if (name.equals(Constants.DOT_GIT) && parent != null) if (name.equals(Constants.DOT_GIT) && parent != null)
name = parent.getName(); name = parent.getName();
outw.println(name + ": start at " + startId.name()); outw.println(name + ": start at " + startId.name());

5
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -117,9 +117,12 @@ class RebuildCommitGraph extends TextBuiltin {
@Override @Override
protected void run() throws Exception { protected void run() throws Exception {
if (!really && !db.getRefDatabase().getRefs(ALL).isEmpty()) { if (!really && !db.getRefDatabase().getRefs(ALL).isEmpty()) {
File directory = db.getDirectory();
String absolutePath = directory == null ? "null" //$NON-NLS-1$
: directory.getAbsolutePath();
errw.println( errw.println(
MessageFormat.format(CLIText.get().fatalThisProgramWillDestroyTheRepository MessageFormat.format(CLIText.get().fatalThisProgramWillDestroyTheRepository
, db.getDirectory().getAbsolutePath(), REALLY)); , absolutePath, REALLY));
throw die(CLIText.get().needApprovalToDestroyCurrentRepository); throw die(CLIText.get().needApprovalToDestroyCurrentRepository);
} }
if (!refList.isFile()) if (!refList.isFile())

7
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java

@ -341,9 +341,10 @@ class TextHashFunctions extends TextBuiltin {
} }
} }
if (db.getDirectory() != null) { File directory = db.getDirectory();
String name = db.getDirectory().getName(); if (directory != null) {
File parent = db.getDirectory().getParentFile(); String name = directory.getName();
File parent = directory.getParentFile();
if (name.equals(Constants.DOT_GIT) && parent != null) if (name.equals(Constants.DOT_GIT) && parent != null)
name = parent.getName(); name = parent.getName();
outw.println(name + ":"); //$NON-NLS-1$ outw.println(name + ":"); //$NON-NLS-1$

1
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java

@ -202,6 +202,7 @@ public class CLIText extends TranslationBundle {
/***/ public String notARevision; /***/ public String notARevision;
/***/ public String notATree; /***/ public String notATree;
/***/ public String notAValidRefName; /***/ public String notAValidRefName;
/***/ public String notAValidCommitName;
/***/ public String notAnIndexFile; /***/ public String notAnIndexFile;
/***/ public String notAnObject; /***/ public String notAnObject;
/***/ public String notFound; /***/ public String notFound;

2
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties

@ -45,6 +45,7 @@ cannotBeCombined=Cannot be combined.
cannotBeRecursiveWhenTreesAreIncluded=TreeWalk shouldn't be recursive when tree objects are included. cannotBeRecursiveWhenTreesAreIncluded=TreeWalk shouldn't be recursive when tree objects are included.
cannotChangeActionOnComment=Cannot change action on comment line in git-rebase-todo file, old action: {0}, new action: {1}. cannotChangeActionOnComment=Cannot change action on comment line in git-rebase-todo file, old action: {0}, new action: {1}.
cannotChangeToComment=Cannot change a non-comment line to a comment line. cannotChangeToComment=Cannot change a non-comment line to a comment line.
cannotCheckoutFromUnbornBranch=Cannot checkout from unborn branch
cannotCheckoutOursSwitchBranch=Checking out ours/theirs is only possible when checking out index, not when switching branches. cannotCheckoutOursSwitchBranch=Checking out ours/theirs is only possible when checking out index, not when switching branches.
cannotCombineSquashWithNoff=Cannot combine --squash with --no-ff. cannotCombineSquashWithNoff=Cannot combine --squash with --no-ff.
cannotCombineTreeFilterWithRevFilter=Cannot combine TreeFilter {0} with RevFilter {1}. cannotCombineTreeFilterWithRevFilter=Cannot combine TreeFilter {0} with RevFilter {1}.
@ -345,6 +346,7 @@ invalidPathReservedOnWindows=Invalid path (''{0}'' is reserved on Windows): {1}
invalidReflogRevision=Invalid reflog revision: {0} invalidReflogRevision=Invalid reflog revision: {0}
invalidRefName=Invalid ref name: {0} invalidRefName=Invalid ref name: {0}
invalidRemote=Invalid remote: {0} invalidRemote=Invalid remote: {0}
invalidRepositoryStateNoHead=Invalid repository --- cannot read HEAD
invalidShallowObject=invalid shallow object {0}, expected commit invalidShallowObject=invalid shallow object {0}, expected commit
invalidStageForPath=Invalid stage {0} for path {1} invalidStageForPath=Invalid stage {0} for path {1}
invalidTagOption=Invalid tag option: {0} invalidTagOption=Invalid tag option: {0}

6
org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java

@ -222,6 +222,12 @@ public class CheckoutCommand extends GitCommand<Ref> {
} }
Ref headRef = repo.getRef(Constants.HEAD); Ref headRef = repo.getRef(Constants.HEAD);
if (headRef == null) {
// TODO Git CLI supports checkout from unborn branch, we should
// also allow this
throw new UnsupportedOperationException(
JGitText.get().cannotCheckoutFromUnbornBranch);
}
String shortHeadRef = getShortBranchName(headRef); String shortHeadRef = getShortBranchName(headRef);
String refLogMessage = "checkout: moving from " + shortHeadRef; //$NON-NLS-1$ String refLogMessage = "checkout: moving from " + shortHeadRef; //$NON-NLS-1$
ObjectId branch; ObjectId branch;

11
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

@ -668,12 +668,13 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
} }
private void writeRewrittenHashes() throws RevisionSyntaxException, private void writeRewrittenHashes() throws RevisionSyntaxException,
IOException { IOException, RefNotFoundException {
File currentCommitFile = rebaseState.getFile(CURRENT_COMMIT); File currentCommitFile = rebaseState.getFile(CURRENT_COMMIT);
if (!currentCommitFile.exists()) if (!currentCommitFile.exists())
return; return;
String head = repo.resolve(Constants.HEAD).getName(); ObjectId headId = getHead().getObjectId();
String head = headId.getName();
String currentCommits = rebaseState.readFile(CURRENT_COMMIT); String currentCommits = rebaseState.readFile(CURRENT_COMMIT);
for (String current : currentCommits.split("\n")) //$NON-NLS-1$ for (String current : currentCommits.split("\n")) //$NON-NLS-1$
RebaseState RebaseState
@ -743,8 +744,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private void resetSoftToParent() throws IOException, private void resetSoftToParent() throws IOException,
GitAPIException, CheckoutConflictException { GitAPIException, CheckoutConflictException {
Ref orig_head = repo.getRef(Constants.ORIG_HEAD); Ref ref = repo.getRef(Constants.ORIG_HEAD);
ObjectId orig_headId = orig_head.getObjectId(); ObjectId orig_head = ref == null ? null : ref.getObjectId();
try { try {
// we have already commited the cherry-picked commit. // we have already commited the cherry-picked commit.
// what we need is to have changes introduced by this // what we need is to have changes introduced by this
@ -755,7 +756,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
} finally { } finally {
// set ORIG_HEAD back to where we started because soft // set ORIG_HEAD back to where we started because soft
// reset moved it // reset moved it
repo.writeOrigHead(orig_headId); repo.writeOrigHead(orig_head);
} }
} }

5
org.eclipse.jgit/src/org/eclipse/jgit/api/RenameBranchCommand.java

@ -51,6 +51,7 @@ import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.RefAlreadyExistsException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException;
import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
@ -121,6 +122,10 @@ public class RenameBranchCommand extends GitCommand<Ref> {
fullOldName = ref.getName(); fullOldName = ref.getName();
} else { } else {
fullOldName = repo.getFullBranch(); fullOldName = repo.getFullBranch();
if (fullOldName == null) {
throw new NoHeadException(
JGitText.get().invalidRepositoryStateNoHead);
}
if (ObjectId.isId(fullOldName)) if (ObjectId.isId(fullOldName))
throw new DetachedHeadException(); throw new DetachedHeadException();
} }

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -104,6 +104,7 @@ public class JGitText extends TranslationBundle {
/***/ public String cannotBeRecursiveWhenTreesAreIncluded; /***/ public String cannotBeRecursiveWhenTreesAreIncluded;
/***/ public String cannotChangeActionOnComment; /***/ public String cannotChangeActionOnComment;
/***/ public String cannotChangeToComment; /***/ public String cannotChangeToComment;
/***/ public String cannotCheckoutFromUnbornBranch;
/***/ public String cannotCheckoutOursSwitchBranch; /***/ public String cannotCheckoutOursSwitchBranch;
/***/ public String cannotCombineSquashWithNoff; /***/ public String cannotCombineSquashWithNoff;
/***/ public String cannotCombineTreeFilterWithRevFilter; /***/ public String cannotCombineTreeFilterWithRevFilter;
@ -411,6 +412,7 @@ public class JGitText extends TranslationBundle {
/***/ public String invalidURL; /***/ public String invalidURL;
/***/ public String invalidWildcards; /***/ public String invalidWildcards;
/***/ public String invalidRefSpec; /***/ public String invalidRefSpec;
/***/ public String invalidRepositoryStateNoHead;
/***/ public String invalidWindowSize; /***/ public String invalidWindowSize;
/***/ public String isAStaticFlagAndHasNorevWalkInstance; /***/ public String isAStaticFlagAndHasNorevWalkInstance;
/***/ public String JRELacksMD5Implementation; /***/ public String JRELacksMD5Implementation;

12
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java

@ -90,6 +90,7 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Ref.Storage; import org.eclipse.jgit.lib.Ref.Storage;
import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.RefDatabase;
import org.eclipse.jgit.lib.ReflogEntry; import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.revwalk.ObjectWalk; import org.eclipse.jgit.revwalk.ObjectWalk;
import org.eclipse.jgit.revwalk.RevObject; import org.eclipse.jgit.revwalk.RevObject;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
@ -592,7 +593,11 @@ public class GC {
* @throws IOException * @throws IOException
*/ */
private Set<ObjectId> listRefLogObjects(Ref ref, long minTime) throws IOException { private Set<ObjectId> listRefLogObjects(Ref ref, long minTime) throws IOException {
List<ReflogEntry> rlEntries = repo.getReflogReader(ref.getName()) ReflogReader reflogReader = repo.getReflogReader(ref.getName());
if (reflogReader == null) {
return Collections.emptySet();
}
List<ReflogEntry> rlEntries = reflogReader
.getReverseEntries(); .getReverseEntries();
if (rlEntries == null || rlEntries.isEmpty()) if (rlEntries == null || rlEntries.isEmpty())
return Collections.<ObjectId> emptySet(); return Collections.<ObjectId> emptySet();
@ -635,10 +640,7 @@ public class GC {
*/ */
private Set<ObjectId> listNonHEADIndexObjects() private Set<ObjectId> listNonHEADIndexObjects()
throws CorruptObjectException, IOException { throws CorruptObjectException, IOException {
try { if (repo.isBare()) {
if (repo.getIndexFile() == null)
return Collections.emptySet();
} catch (NoWorkTreeException e) {
return Collections.emptySet(); return Collections.emptySet();
} }
try (TreeWalk treeWalk = new TreeWalk(repo)) { try (TreeWalk treeWalk = new TreeWalk(repo)) {

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefRename.java

@ -170,7 +170,7 @@ public abstract class RefRename {
*/ */
protected boolean needToUpdateHEAD() throws IOException { protected boolean needToUpdateHEAD() throws IOException {
Ref head = source.getRefDatabase().getRef(Constants.HEAD); Ref head = source.getRefDatabase().getRef(Constants.HEAD);
if (head.isSymbolic()) { if (head != null && head.isSymbolic()) {
head = head.getTarget(); head = head.getTarget();
return head.getName().equals(source.getName()); return head.getName().equals(source.getName());
} }

112
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -64,6 +64,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; 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.attributes.AttributesNodeProvider;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.errors.AmbiguousObjectException; import org.eclipse.jgit.errors.AmbiguousObjectException;
@ -138,6 +140,7 @@ public abstract class Repository implements AutoCloseable {
} }
/** @return listeners observing only events on this repository. */ /** @return listeners observing only events on this repository. */
@NonNull
public ListenerList getListenerList() { public ListenerList getListenerList() {
return myListeners; return myListeners;
} }
@ -182,7 +185,16 @@ public abstract class Repository implements AutoCloseable {
*/ */
public abstract void create(boolean bare) throws IOException; 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() { public File getDirectory() {
return gitDir; return gitDir;
} }
@ -190,24 +202,29 @@ public abstract class Repository implements AutoCloseable {
/** /**
* @return the object database which stores this repository's data. * @return the object database which stores this repository's data.
*/ */
@NonNull
public abstract ObjectDatabase getObjectDatabase(); public abstract ObjectDatabase getObjectDatabase();
/** @return a new inserter to create objects in {@link #getObjectDatabase()} */ /** @return a new inserter to create objects in {@link #getObjectDatabase()} */
@NonNull
public ObjectInserter newObjectInserter() { public ObjectInserter newObjectInserter() {
return getObjectDatabase().newInserter(); return getObjectDatabase().newInserter();
} }
/** @return a new reader to read objects from {@link #getObjectDatabase()} */ /** @return a new reader to read objects from {@link #getObjectDatabase()} */
@NonNull
public ObjectReader newObjectReader() { public ObjectReader newObjectReader() {
return getObjectDatabase().newReader(); return getObjectDatabase().newReader();
} }
/** @return the reference database which stores the reference namespace. */ /** @return the reference database which stores the reference namespace. */
@NonNull
public abstract RefDatabase getRefDatabase(); public abstract RefDatabase getRefDatabase();
/** /**
* @return the configuration of this repository * @return the configuration of this repository
*/ */
@NonNull
public abstract StoredConfig getConfig(); public abstract StoredConfig getConfig();
/** /**
@ -217,11 +234,20 @@ public abstract class Repository implements AutoCloseable {
* instance for each use. * instance for each use.
* @since 4.2 * @since 4.2
*/ */
@NonNull
public abstract AttributesNodeProvider createAttributesNodeProvider(); 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() { public FS getFS() {
return fs; return fs;
@ -255,6 +281,7 @@ public abstract class Repository implements AutoCloseable {
* @throws IOException * @throws IOException
* the object store cannot be accessed. * the object store cannot be accessed.
*/ */
@NonNull
public ObjectLoader open(final AnyObjectId objectId) public ObjectLoader open(final AnyObjectId objectId)
throws MissingObjectException, IOException { throws MissingObjectException, IOException {
return getObjectDatabase().open(objectId); return getObjectDatabase().open(objectId);
@ -282,6 +309,7 @@ public abstract class Repository implements AutoCloseable {
* @throws IOException * @throws IOException
* the object store cannot be accessed. * the object store cannot be accessed.
*/ */
@NonNull
public ObjectLoader open(AnyObjectId objectId, int typeHint) public ObjectLoader open(AnyObjectId objectId, int typeHint)
throws MissingObjectException, IncorrectObjectTypeException, throws MissingObjectException, IncorrectObjectTypeException,
IOException { IOException {
@ -300,6 +328,7 @@ public abstract class Repository implements AutoCloseable {
* a symbolic ref was passed in and could not be resolved back * a symbolic ref was passed in and could not be resolved back
* to the base ref, as the symbolic ref could not be read. * to the base ref, as the symbolic ref could not be read.
*/ */
@NonNull
public RefUpdate updateRef(final String ref) throws IOException { public RefUpdate updateRef(final String ref) throws IOException {
return updateRef(ref, false); return updateRef(ref, false);
} }
@ -318,6 +347,7 @@ public abstract class Repository implements AutoCloseable {
* a symbolic ref was passed in and could not be resolved back * a symbolic ref was passed in and could not be resolved back
* to the base ref, as the symbolic ref could not be read. * to the base ref, as the symbolic ref could not be read.
*/ */
@NonNull
public RefUpdate updateRef(final String ref, final boolean detach) throws IOException { public RefUpdate updateRef(final String ref, final boolean detach) throws IOException {
return getRefDatabase().newUpdate(ref, detach); return getRefDatabase().newUpdate(ref, detach);
} }
@ -334,6 +364,7 @@ public abstract class Repository implements AutoCloseable {
* the rename could not be performed. * the rename could not be performed.
* *
*/ */
@NonNull
public RefRename renameRef(final String fromRef, final String toRef) throws IOException { public RefRename renameRef(final String fromRef, final String toRef) throws IOException {
return getRefDatabase().newRename(fromRef, toRef); return getRefDatabase().newRename(fromRef, toRef);
} }
@ -373,7 +404,8 @@ public abstract class Repository implements AutoCloseable {
* *
* @param revstr * @param revstr
* A git object references expression * 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 * @throws AmbiguousObjectException
* {@code revstr} contains an abbreviated ObjectId and this * {@code revstr} contains an abbreviated ObjectId and this
* repository contains more than one object which match to the * repository contains more than one object which match to the
@ -387,6 +419,7 @@ public abstract class Repository implements AutoCloseable {
* @throws IOException * @throws IOException
* on serious errors * on serious errors
*/ */
@Nullable
public ObjectId resolve(final String revstr) public ObjectId resolve(final String revstr)
throws AmbiguousObjectException, IncorrectObjectTypeException, throws AmbiguousObjectException, IncorrectObjectTypeException,
RevisionSyntaxException, IOException { RevisionSyntaxException, IOException {
@ -408,10 +441,12 @@ public abstract class Repository implements AutoCloseable {
* expects a branch or revision id. * expects a branch or revision id.
* *
* @param revstr * @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 AmbiguousObjectException
* @throws IOException * @throws IOException
*/ */
@Nullable
public String simplify(final String revstr) public String simplify(final String revstr)
throws AmbiguousObjectException, IOException { throws AmbiguousObjectException, IOException {
try (RevWalk rw = new RevWalk(this)) { try (RevWalk rw = new RevWalk(this)) {
@ -425,6 +460,7 @@ public abstract class Repository implements AutoCloseable {
} }
} }
@Nullable
private Object resolve(final RevWalk rw, final String revstr) private Object resolve(final RevWalk rw, final String revstr)
throws IOException { throws IOException {
char[] revChars = revstr.toCharArray(); char[] revChars = revstr.toCharArray();
@ -728,11 +764,13 @@ public abstract class Repository implements AutoCloseable {
return true; return true;
} }
@Nullable
private RevObject parseSimple(RevWalk rw, String revstr) throws IOException { private RevObject parseSimple(RevWalk rw, String revstr) throws IOException {
ObjectId id = resolveSimple(revstr); ObjectId id = resolveSimple(revstr);
return id != null ? rw.parseAny(id) : null; return id != null ? rw.parseAny(id) : null;
} }
@Nullable
private ObjectId resolveSimple(final String revstr) throws IOException { private ObjectId resolveSimple(final String revstr) throws IOException {
if (ObjectId.isId(revstr)) if (ObjectId.isId(revstr))
return ObjectId.fromString(revstr); return ObjectId.fromString(revstr);
@ -760,6 +798,7 @@ public abstract class Repository implements AutoCloseable {
return null; return null;
} }
@Nullable
private String resolveReflogCheckout(int checkoutNo) private String resolveReflogCheckout(int checkoutNo)
throws IOException { throws IOException {
ReflogReader reader = getReflogReader(Constants.HEAD); ReflogReader reader = getReflogReader(Constants.HEAD);
@ -801,6 +840,7 @@ public abstract class Repository implements AutoCloseable {
return rw.parseCommit(entry.getNewId()); return rw.parseCommit(entry.getNewId());
} }
@Nullable
private ObjectId resolveAbbreviation(final String revstr) throws IOException, private ObjectId resolveAbbreviation(final String revstr) throws IOException,
AmbiguousObjectException { AmbiguousObjectException {
AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr); AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr);
@ -837,11 +877,13 @@ public abstract class Repository implements AutoCloseable {
getRefDatabase().close(); getRefDatabase().close();
} }
@NonNull
@SuppressWarnings("nls") @SuppressWarnings("nls")
public String toString() { public String toString() {
String desc; String desc;
if (getDirectory() != null) File directory = getDirectory();
desc = getDirectory().getPath(); if (directory != null)
desc = directory.getPath();
else else
desc = getClass().getSimpleName() + "-" //$NON-NLS-1$ desc = getClass().getSimpleName() + "-" //$NON-NLS-1$
+ System.identityHashCode(this); + System.identityHashCode(this);
@ -861,10 +903,12 @@ public abstract class Repository implements AutoCloseable {
* current ObjectId in hexadecimal string format. * current ObjectId in hexadecimal string format.
* *
* @return name of current branch (for example {@code refs/heads/master}), * @return name of current branch (for example {@code refs/heads/master}),
* an ObjectId in hex format if the current branch is detached, * an ObjectId in hex format if the current branch is detached, or
* or null if the repository is corrupt and has no HEAD reference. * {@code null} if the repository is corrupt and has no HEAD
* reference.
* @throws IOException * @throws IOException
*/ */
@Nullable
public String getFullBranch() throws IOException { public String getFullBranch() throws IOException {
Ref head = getRef(Constants.HEAD); Ref head = getRef(Constants.HEAD);
if (head == null) if (head == null)
@ -883,16 +927,17 @@ public abstract class Repository implements AutoCloseable {
* leading prefix {@code refs/heads/} is removed from the reference before * leading prefix {@code refs/heads/} is removed from the reference before
* it is returned to the caller. * it is returned to the caller.
* *
* @return name of current branch (for example {@code master}), an * @return name of current branch (for example {@code master}), an ObjectId
* ObjectId in hex format if the current branch is detached, * in hex format if the current branch is detached, or {@code null}
* or null if the repository is corrupt and has no HEAD reference. * if the repository is corrupt and has no HEAD reference.
* @throws IOException * @throws IOException
*/ */
@Nullable
public String getBranch() throws IOException { public String getBranch() throws IOException {
String name = getFullBranch(); String name = getFullBranch();
if (name != null) if (name != null)
return shortenRefName(name); return shortenRefName(name);
return name; return null;
} }
/** /**
@ -905,6 +950,7 @@ public abstract class Repository implements AutoCloseable {
* *
* @return unmodifiable collection of other known objects. * @return unmodifiable collection of other known objects.
*/ */
@NonNull
public Set<ObjectId> getAdditionalHaves() { public Set<ObjectId> getAdditionalHaves() {
return Collections.emptySet(); return Collections.emptySet();
} }
@ -916,9 +962,10 @@ public abstract class Repository implements AutoCloseable {
* the name of the ref to lookup. May be a short-hand form, e.g. * the name of the ref to lookup. May be a short-hand form, e.g.
* "master" which is is automatically expanded to * "master" which is is automatically expanded to
* "refs/heads/master" if "refs/heads/master" already exists. * "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 * @throws IOException
*/ */
@Nullable
public Ref getRef(final String name) throws IOException { public Ref getRef(final String name) throws IOException {
return getRefDatabase().getRef(name); return getRefDatabase().getRef(name);
} }
@ -926,6 +973,7 @@ public abstract class Repository implements AutoCloseable {
/** /**
* @return mutable map of all known refs (heads, tags, remotes). * @return mutable map of all known refs (heads, tags, remotes).
*/ */
@NonNull
public Map<String, Ref> getAllRefs() { public Map<String, Ref> getAllRefs() {
try { try {
return getRefDatabase().getRefs(RefDatabase.ALL); return getRefDatabase().getRefs(RefDatabase.ALL);
@ -939,6 +987,7 @@ public abstract class Repository implements AutoCloseable {
* of the entry contains the ref with the full tag name * of the entry contains the ref with the full tag name
* ("refs/tags/v1.0"). * ("refs/tags/v1.0").
*/ */
@NonNull
public Map<String, Ref> getTags() { public Map<String, Ref> getTags() {
try { try {
return getRefDatabase().getRefs(Constants.R_TAGS); return getRefDatabase().getRefs(Constants.R_TAGS);
@ -960,6 +1009,7 @@ public abstract class Repository implements AutoCloseable {
* will be true and getPeeledObjectId will contain the peeled object * will be true and getPeeledObjectId will contain the peeled object
* (or null). * (or null).
*/ */
@NonNull
public Ref peel(final Ref ref) { public Ref peel(final Ref ref) {
try { try {
return getRefDatabase().peel(ref); return getRefDatabase().peel(ref);
@ -974,6 +1024,7 @@ public abstract class Repository implements AutoCloseable {
/** /**
* @return a map with all objects referenced by a peeled ref. * @return a map with all objects referenced by a peeled ref.
*/ */
@NonNull
public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() { public Map<AnyObjectId, Set<Ref>> getAllRefsByPeeledObjectId() {
Map<String, Ref> allRefs = getAllRefs(); Map<String, Ref> allRefs = getAllRefs();
Map<AnyObjectId, Set<Ref>> ret = new HashMap<AnyObjectId, Set<Ref>>(allRefs.size()); Map<AnyObjectId, Set<Ref>> ret = new HashMap<AnyObjectId, Set<Ref>>(allRefs.size());
@ -998,11 +1049,13 @@ public abstract class Repository implements AutoCloseable {
} }
/** /**
* @return the index file location * @return the index file location or {@code null} if repository isn't
* local.
* @throws NoWorkTreeException * @throws NoWorkTreeException
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@NonNull
public File getIndexFile() throws NoWorkTreeException { public File getIndexFile() throws NoWorkTreeException {
if (isBare()) if (isBare())
throw new NoWorkTreeException(); throw new NoWorkTreeException();
@ -1027,6 +1080,7 @@ public abstract class Repository implements AutoCloseable {
* the index file is using a format or extension that this * the index file is using a format or extension that this
* library does not support. * library does not support.
*/ */
@NonNull
public DirCache readDirCache() throws NoWorkTreeException, public DirCache readDirCache() throws NoWorkTreeException,
CorruptObjectException, IOException { CorruptObjectException, IOException {
return DirCache.read(this); return DirCache.read(this);
@ -1051,6 +1105,7 @@ public abstract class Repository implements AutoCloseable {
* the index file is using a format or extension that this * the index file is using a format or extension that this
* library does not support. * library does not support.
*/ */
@NonNull
public DirCache lockDirCache() throws NoWorkTreeException, public DirCache lockDirCache() throws NoWorkTreeException,
CorruptObjectException, IOException { CorruptObjectException, IOException {
// we want DirCache to inform us so that we can inform registered // we want DirCache to inform us so that we can inform registered
@ -1076,6 +1131,7 @@ public abstract class Repository implements AutoCloseable {
/** /**
* @return an important state * @return an important state
*/ */
@NonNull
public RepositoryState getRepositoryState() { public RepositoryState getRepositoryState() {
if (isBare() || getDirectory() == null) if (isBare() || getDirectory() == null)
return RepositoryState.BARE; return RepositoryState.BARE;
@ -1218,6 +1274,7 @@ public abstract class Repository implements AutoCloseable {
* @return normalized repository relative path or the empty * @return normalized repository relative path or the empty
* string if the file is not relative to the work directory. * string if the file is not relative to the work directory.
*/ */
@NonNull
public static String stripWorkDir(File workDir, File file) { public static String stripWorkDir(File workDir, File file) {
final String filePath = file.getPath(); final String filePath = file.getPath();
final String workDirPath = workDir.getPath(); final String workDirPath = workDir.getPath();
@ -1252,6 +1309,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@NonNull
public File getWorkTree() throws NoWorkTreeException { public File getWorkTree() throws NoWorkTreeException {
if (isBare()) if (isBare())
throw new NoWorkTreeException(); throw new NoWorkTreeException();
@ -1275,6 +1333,7 @@ public abstract class Repository implements AutoCloseable {
* *
* @return a more user friendly ref name * @return a more user friendly ref name
*/ */
@NonNull
public static String shortenRefName(String refName) { public static String shortenRefName(String refName) {
if (refName.startsWith(Constants.R_HEADS)) if (refName.startsWith(Constants.R_HEADS))
return refName.substring(Constants.R_HEADS.length()); return refName.substring(Constants.R_HEADS.length());
@ -1290,9 +1349,10 @@ public abstract class Repository implements AutoCloseable {
* @return the remote branch name part of <code>refName</code>, i.e. without * @return the remote branch name part of <code>refName</code>, i.e. without
* the <code>refs/remotes/&lt;remote&gt;</code> prefix, if * the <code>refs/remotes/&lt;remote&gt;</code> prefix, if
* <code>refName</code> represents a remote tracking branch; * <code>refName</code> represents a remote tracking branch;
* otherwise null. * otherwise {@code null}.
* @since 3.4 * @since 3.4
*/ */
@Nullable
public String shortenRemoteBranchName(String refName) { public String shortenRemoteBranchName(String refName) {
for (String remote : getRemoteNames()) { for (String remote : getRemoteNames()) {
String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$ String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
@ -1307,9 +1367,10 @@ public abstract class Repository implements AutoCloseable {
* @return the remote name part of <code>refName</code>, i.e. without the * @return the remote name part of <code>refName</code>, i.e. without the
* <code>refs/remotes/&lt;remote&gt;</code> prefix, if * <code>refs/remotes/&lt;remote&gt;</code> prefix, if
* <code>refName</code> represents a remote tracking branch; * <code>refName</code> represents a remote tracking branch;
* otherwise null. * otherwise {@code null}.
* @since 3.4 * @since 3.4
*/ */
@Nullable
public String getRemoteName(String refName) { public String getRemoteName(String refName) {
for (String remote : getRemoteNames()) { for (String remote : getRemoteNames()) {
String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$ String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$
@ -1321,12 +1382,13 @@ public abstract class Repository implements AutoCloseable {
/** /**
* @param refName * @param refName
* @return a {@link ReflogReader} for the supplied refname, or null if the * @return a {@link ReflogReader} for the supplied refname, or {@code null}
* named ref does not exist. * if the named ref does not exist.
* @throws IOException * @throws IOException
* the ref could not be accessed. * the ref could not be accessed.
* @since 3.0 * @since 3.0
*/ */
@Nullable
public abstract ReflogReader getReflogReader(String refName) public abstract ReflogReader getReflogReader(String refName)
throws IOException; throws IOException;
@ -1342,6 +1404,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@Nullable
public String readMergeCommitMsg() throws IOException, NoWorkTreeException { public String readMergeCommitMsg() throws IOException, NoWorkTreeException {
return readCommitMsgFile(Constants.MERGE_MSG); return readCommitMsgFile(Constants.MERGE_MSG);
} }
@ -1376,6 +1439,7 @@ public abstract class Repository implements AutoCloseable {
* See {@link #isBare()}. * See {@link #isBare()}.
* @since 4.0 * @since 4.0
*/ */
@Nullable
public String readCommitEditMsg() throws IOException, NoWorkTreeException { public String readCommitEditMsg() throws IOException, NoWorkTreeException {
return readCommitMsgFile(Constants.COMMIT_EDITMSG); return readCommitMsgFile(Constants.COMMIT_EDITMSG);
} }
@ -1410,6 +1474,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@Nullable
public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException { public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null) if (isBare() || getDirectory() == null)
throw new NoWorkTreeException(); throw new NoWorkTreeException();
@ -1453,6 +1518,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@Nullable
public ObjectId readCherryPickHead() throws IOException, public ObjectId readCherryPickHead() throws IOException,
NoWorkTreeException { NoWorkTreeException {
if (isBare() || getDirectory() == null) if (isBare() || getDirectory() == null)
@ -1476,6 +1542,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@Nullable
public ObjectId readRevertHead() throws IOException, NoWorkTreeException { public ObjectId readRevertHead() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null) if (isBare() || getDirectory() == null)
throw new NoWorkTreeException(); throw new NoWorkTreeException();
@ -1541,6 +1608,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@Nullable
public ObjectId readOrigHead() throws IOException, NoWorkTreeException { public ObjectId readOrigHead() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null) if (isBare() || getDirectory() == null)
throw new NoWorkTreeException(); throw new NoWorkTreeException();
@ -1561,6 +1629,7 @@ public abstract class Repository implements AutoCloseable {
* if this is bare, which implies it has no working directory. * if this is bare, which implies it has no working directory.
* See {@link #isBare()}. * See {@link #isBare()}.
*/ */
@Nullable
public String readSquashCommitMsg() throws IOException { public String readSquashCommitMsg() throws IOException {
return readCommitMsgFile(Constants.SQUASH_MSG); return readCommitMsgFile(Constants.SQUASH_MSG);
} }
@ -1582,6 +1651,7 @@ public abstract class Repository implements AutoCloseable {
writeCommitMsg(squashMsgFile, msg); writeCommitMsg(squashMsgFile, msg);
} }
@Nullable
private String readCommitMsgFile(String msgFilename) throws IOException { private String readCommitMsgFile(String msgFilename) throws IOException {
if (isBare() || getDirectory() == null) if (isBare() || getDirectory() == null)
throw new NoWorkTreeException(); throw new NoWorkTreeException();
@ -1615,9 +1685,11 @@ public abstract class Repository implements AutoCloseable {
* Read a file from the git directory. * Read a file from the git directory.
* *
* @param filename * @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 * @throws IOException
*/ */
@Nullable
private byte[] readGitDirectoryFile(String filename) throws IOException { private byte[] readGitDirectoryFile(String filename) throws IOException {
File file = new File(getDirectory(), filename); File file = new File(getDirectory(), filename);
try { try {
@ -1674,6 +1746,7 @@ public abstract class Repository implements AutoCloseable {
* @throws IOException * @throws IOException
* @since 3.2 * @since 3.2
*/ */
@NonNull
public List<RebaseTodoLine> readRebaseTodo(String path, public List<RebaseTodoLine> readRebaseTodo(String path,
boolean includeComments) boolean includeComments)
throws IOException { throws IOException {
@ -1703,6 +1776,7 @@ public abstract class Repository implements AutoCloseable {
* @return the names of all known remotes * @return the names of all known remotes
* @since 3.4 * @since 3.4
*/ */
@NonNull
public Set<String> getRemoteNames() { public Set<String> getRemoteNames() {
return getConfig() return getConfig()
.getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION);

5
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

@ -786,11 +786,6 @@ public class ResolveMerger extends ThreeWayMerger {
private File writeMergedFile(MergeResult<RawText> result) private File writeMergedFile(MergeResult<RawText> result)
throws FileNotFoundException, IOException { throws FileNotFoundException, IOException {
File workTree = db.getWorkTree(); File workTree = db.getWorkTree();
if (workTree == null)
// TODO: This should be handled by WorkingTreeIterators which
// support write operations
throw new UnsupportedOperationException();
FS fs = db.getFS(); FS fs = db.getFS();
File of = new File(workTree, tw.getPathString()); File of = new File(workTree, tw.getPathString());
File parentFolder = of.getParentFile(); File parentFolder = of.getParentFile();

15
org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java

@ -42,6 +42,7 @@
*/ */
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import java.io.File;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -85,12 +86,16 @@ public class HMACSHA1NonceGenerator implements NonceGenerator {
public synchronized String createNonce(Repository repo, long timestamp) public synchronized String createNonce(Repository repo, long timestamp)
throws IllegalStateException { throws IllegalStateException {
String path; String path;
if (repo instanceof DfsRepository) if (repo instanceof DfsRepository) {
path = ((DfsRepository) repo).getDescription().getRepositoryName(); path = ((DfsRepository) repo).getDescription().getRepositoryName();
else if (repo.getDirectory() != null) } else {
path = repo.getDirectory().getPath(); File directory = repo.getDirectory();
else if (directory != null) {
throw new IllegalStateException(); path = directory.getPath();
} else {
throw new IllegalStateException();
}
}
String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$
byte[] rawHmac; byte[] rawHmac;

5
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java

@ -148,8 +148,9 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport {
super(local, uri); super(local, uri);
Properties props = loadProperties(); Properties props = loadProperties();
if (!props.containsKey("tmpdir") && local.getDirectory() != null) //$NON-NLS-1$ File directory = local.getDirectory();
props.put("tmpdir", local.getDirectory().getPath()); //$NON-NLS-1$ if (!props.containsKey("tmpdir") && directory != null) //$NON-NLS-1$
props.put("tmpdir", directory.getPath()); //$NON-NLS-1$
s3 = new AmazonS3(props); s3 = new AmazonS3(props);
bucket = uri.getHost(); bucket = uri.getHost();

6
org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java

@ -46,6 +46,7 @@
package org.eclipse.jgit.transport; package org.eclipse.jgit.transport;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.text.MessageFormat; import java.text.MessageFormat;
@ -235,9 +236,10 @@ public class TransportGitSsh extends SshTransport implements PackTransport {
ProcessBuilder pb = new ProcessBuilder(); ProcessBuilder pb = new ProcessBuilder();
pb.command(args); pb.command(args);
if (local.getDirectory() != null) File directory = local.getDirectory();
if (directory != null)
pb.environment().put(Constants.GIT_DIR_KEY, pb.environment().put(Constants.GIT_DIR_KEY,
local.getDirectory().getPath()); directory.getPath());
try { try {
return pb.start(); return pb.start();

3
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java

@ -168,6 +168,9 @@ public class FS_Win32_Cygwin extends FS_Win32 {
@Override @Override
public File findHook(Repository repository, String hookName) { public File findHook(Repository repository, String hookName) {
final File gitdir = repository.getDirectory(); final File gitdir = repository.getDirectory();
if (gitdir == null) {
return null;
}
final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS) final Path hookPath = gitdir.toPath().resolve(Constants.HOOKS)
.resolve(hookName); .resolve(hookName);
if (Files.isExecutable(hookPath)) if (Files.isExecutable(hookPath))

Loading…
Cancel
Save