diff options
Diffstat (limited to 'org.eclipse.jgit')
367 files changed, 3606 insertions, 3525 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters index d4a059110b..e51bf20c22 100644 --- a/org.eclipse.jgit/.settings/.api_filters +++ b/org.eclipse.jgit/.settings/.api_filters @@ -1,66 +1,18 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <component id="org.eclipse.jgit" version="2"> - <resource path="META-INF/MANIFEST.MF"> - <filter id="924844039"> + <resource path="src/org/eclipse/jgit/lib/ObjectIdSerializer.java" type="org.eclipse.jgit.lib.ObjectIdSerializer"> + <filter id="1141899266"> <message_arguments> - <message_argument value="4.11.1"/> - <message_argument value="4.11.0"/> + <message_argument value="4.11"/> + <message_argument value="5.0"/> + <message_argument value="readWithoutMarker(InputStream)"/> </message_arguments> </filter> - </resource> - <resource path="src/org/eclipse/jgit/diff/DiffEntry.java" type="org.eclipse.jgit.diff.DiffEntry"> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.diff.DiffEntry"/> - <message_argument value="diffAttribute"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants"> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.lib.ConfigConstants"/> - <message_argument value="CONFIG_KEY_REQUIRED"/> - </message_arguments> - </filter> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.lib.ConfigConstants"/> - <message_argument value="CONFIG_SECTION_LFS"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jgit/merge/ResolveMerger.java" type="org.eclipse.jgit.merge.ResolveMerger"> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.merge.ResolveMerger"/> - <message_argument value="workingTreeOptions"/> - </message_arguments> - </filter> - </resource> - <resource path="src/org/eclipse/jgit/storage/pack/PackStatistics.java" type="org.eclipse.jgit.storage.pack.PackStatistics$Accumulator"> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/> - <message_argument value="advertised"/> - </message_arguments> - </filter> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/> - <message_argument value="haves"/> - </message_arguments> - </filter> - <filter id="336658481"> - <message_arguments> - <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/> - <message_argument value="timeNegotiating"/> - </message_arguments> - </filter> - <filter id="336658481"> + <filter id="1141899266"> <message_arguments> - <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/> - <message_argument value="wants"/> + <message_argument value="4.11"/> + <message_argument value="5.0"/> + <message_argument value="writeWithoutMarker(OutputStream, AnyObjectId)"/> </message_arguments> </filter> </resource> diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF index b6268169d6..90906d5c9d 100644 --- a/org.eclipse.jgit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/MANIFEST.MF @@ -3,12 +3,12 @@ Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Automatic-Module-Name: org.eclipse.jgit Bundle-SymbolicName: org.eclipse.jgit -Bundle-Version: 4.11.2.qualifier +Bundle-Version: 5.0.3.qualifier Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.jgit.annotations;version="4.11.2", - org.eclipse.jgit.api;version="4.11.2"; +Export-Package: org.eclipse.jgit.annotations;version="5.0.3", + org.eclipse.jgit.api;version="5.0.3"; uses:="org.eclipse.jgit.revwalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.diff, @@ -22,52 +22,52 @@ Export-Package: org.eclipse.jgit.annotations;version="4.11.2", org.eclipse.jgit.submodule, org.eclipse.jgit.transport, org.eclipse.jgit.merge", - org.eclipse.jgit.api.errors;version="4.11.2";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.errors", - org.eclipse.jgit.attributes;version="4.11.2", - org.eclipse.jgit.blame;version="4.11.2"; + org.eclipse.jgit.api.errors;version="5.0.3";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.errors", + org.eclipse.jgit.attributes;version="5.0.3", + org.eclipse.jgit.blame;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.revwalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.diff", - org.eclipse.jgit.diff;version="4.11.2"; + org.eclipse.jgit.diff;version="5.0.3"; uses:="org.eclipse.jgit.patch, org.eclipse.jgit.lib, org.eclipse.jgit.treewalk, org.eclipse.jgit.revwalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.util", - org.eclipse.jgit.dircache;version="4.11.2"; + org.eclipse.jgit.dircache;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.treewalk, org.eclipse.jgit.util, org.eclipse.jgit.events, org.eclipse.jgit.attributes", - org.eclipse.jgit.errors;version="4.11.2"; + org.eclipse.jgit.errors;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.internal.storage.pack, org.eclipse.jgit.transport, org.eclipse.jgit.dircache", - org.eclipse.jgit.events;version="4.11.2";uses:="org.eclipse.jgit.lib", - org.eclipse.jgit.fnmatch;version="4.11.2", - org.eclipse.jgit.gitrepo;version="4.11.2"; + org.eclipse.jgit.events;version="5.0.3";uses:="org.eclipse.jgit.lib", + org.eclipse.jgit.fnmatch;version="5.0.3", + org.eclipse.jgit.gitrepo;version="5.0.3"; uses:="org.eclipse.jgit.api, org.eclipse.jgit.lib, org.eclipse.jgit.revwalk, org.xml.sax.helpers, org.xml.sax", - org.eclipse.jgit.gitrepo.internal;version="4.11.2";x-internal:=true, - org.eclipse.jgit.hooks;version="4.11.2";uses:="org.eclipse.jgit.lib", - org.eclipse.jgit.ignore;version="4.11.2", - org.eclipse.jgit.ignore.internal;version="4.11.2";x-friends:="org.eclipse.jgit.test", - org.eclipse.jgit.internal;version="4.11.2";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.test", - org.eclipse.jgit.internal.fsck;version="4.11.2";x-friends:="org.eclipse.jgit.test", - org.eclipse.jgit.internal.ketch;version="4.11.2";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", - org.eclipse.jgit.internal.storage.dfs;version="4.11.2"; + org.eclipse.jgit.gitrepo.internal;version="5.0.3";x-internal:=true, + org.eclipse.jgit.hooks;version="5.0.3";uses:="org.eclipse.jgit.lib", + org.eclipse.jgit.ignore;version="5.0.3", + org.eclipse.jgit.ignore.internal;version="5.0.3";x-friends:="org.eclipse.jgit.test", + org.eclipse.jgit.internal;version="5.0.3";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.test", + org.eclipse.jgit.internal.fsck;version="5.0.3";x-friends:="org.eclipse.jgit.test", + org.eclipse.jgit.internal.ketch;version="5.0.3";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", + org.eclipse.jgit.internal.storage.dfs;version="5.0.3"; x-friends:="org.eclipse.jgit.test, org.eclipse.jgit.http.server, org.eclipse.jgit.http.test, org.eclipse.jgit.lfs.test", - org.eclipse.jgit.internal.storage.file;version="4.11.2"; + org.eclipse.jgit.internal.storage.file;version="5.0.3"; x-friends:="org.eclipse.jgit.test, org.eclipse.jgit.junit, org.eclipse.jgit.junit.http, @@ -75,12 +75,12 @@ Export-Package: org.eclipse.jgit.annotations;version="4.11.2", org.eclipse.jgit.lfs, org.eclipse.jgit.pgm, org.eclipse.jgit.pgm.test", - org.eclipse.jgit.internal.storage.io;version="4.11.2";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", - org.eclipse.jgit.internal.storage.pack;version="4.11.2";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", - org.eclipse.jgit.internal.storage.reftable;version="4.11.2"; + org.eclipse.jgit.internal.storage.io;version="5.0.3";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", + org.eclipse.jgit.internal.storage.pack;version="5.0.3";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", + org.eclipse.jgit.internal.storage.reftable;version="5.0.3"; x-friends:="org.eclipse.jgit.http.test,org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", - org.eclipse.jgit.internal.storage.reftree;version="4.11.2";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", - org.eclipse.jgit.lib;version="4.11.2"; + org.eclipse.jgit.internal.storage.reftree;version="5.0.3";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm", + org.eclipse.jgit.lib;version="5.0.3"; uses:="org.eclipse.jgit.revwalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.util, @@ -90,33 +90,33 @@ Export-Package: org.eclipse.jgit.annotations;version="4.11.2", org.eclipse.jgit.treewalk, org.eclipse.jgit.transport, org.eclipse.jgit.submodule", - org.eclipse.jgit.lib.internal;version="4.11.2";x-internal:=true, - org.eclipse.jgit.merge;version="4.11.2"; + org.eclipse.jgit.lib.internal;version="5.0.3";x-internal:=true, + org.eclipse.jgit.merge;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.treewalk, org.eclipse.jgit.revwalk, org.eclipse.jgit.diff, org.eclipse.jgit.dircache, org.eclipse.jgit.api", - org.eclipse.jgit.nls;version="4.11.2", - org.eclipse.jgit.notes;version="4.11.2"; + org.eclipse.jgit.nls;version="5.0.3", + org.eclipse.jgit.notes;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.treewalk, org.eclipse.jgit.revwalk, org.eclipse.jgit.merge", - org.eclipse.jgit.patch;version="4.11.2";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.diff", - org.eclipse.jgit.revplot;version="4.11.2";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.revwalk", - org.eclipse.jgit.revwalk;version="4.11.2"; + org.eclipse.jgit.patch;version="5.0.3";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.diff", + org.eclipse.jgit.revplot;version="5.0.3";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.revwalk", + org.eclipse.jgit.revwalk;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.treewalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.diff, org.eclipse.jgit.revwalk.filter", - org.eclipse.jgit.revwalk.filter;version="4.11.2";uses:="org.eclipse.jgit.revwalk,org.eclipse.jgit.lib,org.eclipse.jgit.util", - org.eclipse.jgit.storage.file;version="4.11.2";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.util", - org.eclipse.jgit.storage.pack;version="4.11.2";uses:="org.eclipse.jgit.lib", - org.eclipse.jgit.submodule;version="4.11.2";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.treewalk.filter,org.eclipse.jgit.treewalk", - org.eclipse.jgit.transport;version="4.11.2"; + org.eclipse.jgit.revwalk.filter;version="5.0.3";uses:="org.eclipse.jgit.revwalk,org.eclipse.jgit.lib,org.eclipse.jgit.util", + org.eclipse.jgit.storage.file;version="5.0.3";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.util", + org.eclipse.jgit.storage.pack;version="5.0.3";uses:="org.eclipse.jgit.lib", + org.eclipse.jgit.submodule;version="5.0.3";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.treewalk.filter,org.eclipse.jgit.treewalk", + org.eclipse.jgit.transport;version="5.0.3"; uses:="org.eclipse.jgit.transport.resolver, org.eclipse.jgit.revwalk, org.eclipse.jgit.internal.storage.pack, @@ -128,24 +128,24 @@ Export-Package: org.eclipse.jgit.annotations;version="4.11.2", org.eclipse.jgit.transport.http, org.eclipse.jgit.errors, org.eclipse.jgit.storage.pack", - org.eclipse.jgit.transport.http;version="4.11.2";uses:="javax.net.ssl", - org.eclipse.jgit.transport.resolver;version="4.11.2";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.transport", - org.eclipse.jgit.treewalk;version="4.11.2"; + org.eclipse.jgit.transport.http;version="5.0.3";uses:="javax.net.ssl", + org.eclipse.jgit.transport.resolver;version="5.0.3";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.transport", + org.eclipse.jgit.treewalk;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.revwalk, org.eclipse.jgit.attributes, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.util, org.eclipse.jgit.dircache", - org.eclipse.jgit.treewalk.filter;version="4.11.2";uses:="org.eclipse.jgit.treewalk", - org.eclipse.jgit.util;version="4.11.2"; + org.eclipse.jgit.treewalk.filter;version="5.0.3";uses:="org.eclipse.jgit.treewalk", + org.eclipse.jgit.util;version="5.0.3"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.transport.http, org.eclipse.jgit.storage.file, org.ietf.jgss", - org.eclipse.jgit.util.io;version="4.11.2", - org.eclipse.jgit.util.sha1;version="4.11.2", - org.eclipse.jgit.util.time;version="4.11.2" + org.eclipse.jgit.util.io;version="5.0.3", + org.eclipse.jgit.util.sha1;version="5.0.3", + org.eclipse.jgit.util.time;version="5.0.3" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", com.jcraft.jsch;version="[0.1.37,0.2.0)", diff --git a/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF index bbd66fddf6..185ee82cf5 100644 --- a/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF @@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.jgit - Sources Bundle-SymbolicName: org.eclipse.jgit.source Bundle-Vendor: Eclipse.org - JGit -Bundle-Version: 4.11.2.qualifier -Eclipse-SourceBundle: org.eclipse.jgit;version="4.11.2.qualifier";roots="." +Bundle-Version: 5.0.3.qualifier +Eclipse-SourceBundle: org.eclipse.jgit;version="5.0.3.qualifier";roots="." diff --git a/org.eclipse.jgit/pom.xml b/org.eclipse.jgit/pom.xml index cb05734c63..ae9ea6d4d3 100644 --- a/org.eclipse.jgit/pom.xml +++ b/org.eclipse.jgit/pom.xml @@ -53,7 +53,7 @@ <parent> <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit-parent</artifactId> - <version>4.11.2-SNAPSHOT</version> + <version>5.0.3-SNAPSHOT</version> </parent> <artifactId>org.eclipse.jgit</artifactId> diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index 0d8ba01e22..576d0c7699 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -225,6 +225,8 @@ credentialPassword=Password credentialUsername=Username daemonAlreadyRunning=Daemon already running daysAgo={0} days ago +deepenNotWithDeepen=Cannot combine deepen with deepen-not +deepenSinceWithDeepen=Cannot combine deepen with deepen-since deleteBranchUnexpectedResult=Delete branch returned unexpected result {0} deleteFileFailed=Could not delete file {0} deleteRequiresZeroNewId=Delete requires new ID to be zero @@ -309,6 +311,7 @@ fileIsTooLarge=File is too large: {0} fileModeNotSetForPath=FileMode not set for path {0} filterExecutionFailed=Execution of filter command ''{0}'' on file ''{1}'' failed filterExecutionFailedRc=Execution of filter command ''{0}'' on file ''{1}'' failed with return code ''{2}'', message on stderr: ''{3}'' +filterRequiresCapability=filter requires server to advertise that capability findingGarbage=Finding garbage flagIsDisposed={0} is disposed. flagNotFromThis={0} not from this. @@ -360,6 +363,7 @@ invalidCommitParentNumber=Invalid commit parent number invalidDepth=Invalid depth: {0} invalidEncryption=Invalid encryption invalidExpandWildcard=ExpandFromSource on a refspec that can have mismatched wildcards does not make sense. +invalidFilter=Invalid filter: {0} invalidGitdirRef = Invalid .git reference in file ''{0}'' invalidGitType=invalid git type: {0} invalidId=Invalid id: {0} @@ -394,6 +398,7 @@ invalidStageForPath=Invalid stage {0} for path {1} invalidSystemProperty=Invalid system property ''{0}'': ''{1}''; using default value {2} invalidTagOption=Invalid tag option: {0} invalidTimeout=Invalid timeout: {0} +invalidTimestamp=Invalid timestamp in {0} invalidTimeUnitValue2=Invalid time unit value: {0}.{1}={2} invalidTimeUnitValue3=Invalid time unit value: {0}.{1}.{2}={3} invalidTreeZeroLengthName=Cannot append a tree entry with zero-length name @@ -625,6 +630,7 @@ sourceIsNotAWildcard=Source is not a wildcard. sourceRefDoesntResolveToAnyObject=Source ref {0} doesn''t resolve to any object. sourceRefNotSpecifiedForRefspec=Source ref not specified for refspec: {0} squashCommitNotUpdatingHEAD=Squash commit -- not updating HEAD +sshCommandFailed=Execution of ssh command ''{0}'' failed with error ''{1}'' sshUserNameError=Jsch error: failed to set SSH user name correctly to ''{0}''; using ''{1}'' picked up from SSH config file. sslFailureExceptionMessage=Secure connection to {0} could not be stablished because of SSL problems sslFailureInfo=A secure connection to {0}\ncould not be established because the server''s certificate could not be validated. @@ -666,6 +672,7 @@ threadInterruptedWhileRunning="Current thread interrupted while running {0}" timeIsUncertain=Time is uncertain timerAlreadyTerminated=Timer already terminated tooManyCommands=Too many commands +tooManyFilters=Too many "filter" lines in request tooManyIncludeRecursions=Too many recursions; circular includes in config file(s)? topologicalSortRequired=Topological sort required. transactionAborted=transaction aborted @@ -707,6 +714,7 @@ unexpectedEndOfInput=Unexpected end of input unexpectedEofInPack=Unexpected EOF in partially created pack unexpectedHunkTrailer=Unexpected hunk trailer unexpectedOddResult=odd: {0} + {1} - {2} +unexpectedPacketLine=unexpected {0} unexpectedRefReport={0}: unexpected ref report: {1} unexpectedReportLine=unexpected report line: {0} unexpectedReportLine2={0} unexpected report line: {1} @@ -721,6 +729,7 @@ unknownObjectType=Unknown object type {0}. unknownObjectType2=unknown unknownRepositoryFormat=Unknown repository format unknownRepositoryFormat2=Unknown repository format "{0}"; expected "0". +unknownTransportCommand=unknown command {0} unknownZlibError=Unknown zlib error. unmergedPath=Unmerged path: {0} unmergedPaths=Repository contains unmerged paths diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java index 10397f8ac9..27bb5a90b9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java @@ -157,30 +157,6 @@ public class ArchiveCommand extends GitCommand<OutputStream> { * * @param out * archive object from createArchiveOutputStream - * @param path - * full filename relative to the root of the archive (with - * trailing '/' for directories) - * @param mode - * mode (for example FileMode.REGULAR_FILE or - * FileMode.SYMLINK) - * @param loader - * blob object with data for this entry (null for - * directories) - * @throws IOException - * thrown by the underlying output stream for I/O errors - * @deprecated use - * {@link #putEntry(Closeable, ObjectId, String, FileMode, ObjectLoader)} - * instead - */ - @Deprecated - void putEntry(T out, String path, FileMode mode, - ObjectLoader loader) throws IOException; - - /** - * Write an entry to an archive. - * - * @param out - * archive object from createArchiveOutputStream * @param tree * the tag, commit, or tree object to produce an archive for * @param path diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java index f45e39e069..65b72f7d95 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java @@ -288,7 +288,7 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> { * @return {@code this} * @since 3.1 */ - public CherryPickCommand setReflogPrefix(final String prefix) { + public CherryPickCommand setReflogPrefix(String prefix) { this.reflogPrefix = prefix; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 79b0efbe6d..5c06bac1f2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -191,12 +191,12 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { throw new InvalidRemoteException( MessageFormat.format(JGitText.get().invalidURL, uri)); } - Repository repository = null; + @SuppressWarnings("resource") // Closed by caller + Repository repository = init(); FetchResult fetchResult = null; Thread cleanupHook = new Thread(() -> cleanup()); Runtime.getRuntime().addShutdownHook(cleanupHook); try { - repository = init(); fetchResult = fetch(repository, u); } catch (IOException ioe) { if (repository != null) { @@ -306,7 +306,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { return command.call(); } - private List<RefSpec> calculateRefSpecs(final String dst) { + private List<RefSpec> calculateRefSpecs(String dst) { RefSpec wcrs = new RefSpec(); wcrs = wcrs.setForceUpdate(true); wcrs = wcrs.setSourceDestination(Constants.R_HEADS + "*", dst); //$NON-NLS-1$ @@ -315,7 +315,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { specs.add(wcrs); else if (branchesToClone != null && branchesToClone.size() > 0) { - for (final String selectedRef : branchesToClone) + for (String selectedRef : branchesToClone) if (wcrs.matchSource(selectedRef)) specs.add(wcrs.expandFromSource(selectedRef)); } @@ -386,12 +386,9 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { if (!update.call().isEmpty()) { SubmoduleWalk walk = SubmoduleWalk.forIndex(clonedRepo); while (walk.next()) { - Repository subRepo = walk.getRepository(); - if (subRepo != null) { - try { + try (Repository subRepo = walk.getRepository()) { + if (subRepo != null) { cloneSubmodules(subRepo); - } finally { - subRepo.close(); } } } @@ -413,7 +410,7 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { } Ref foundBranch = null; - for (final Ref r : result.getAdvertisedRefs()) { + for (Ref r : result.getAdvertisedRefs()) { final String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; @@ -443,11 +440,11 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { clonedRepo.getConfig().save(); } - private RevCommit parseCommit(final Repository clonedRepo, final Ref ref) + private RevCommit parseCommit(Repository clonedRepo, Ref ref) throws MissingObjectException, IncorrectObjectTypeException, IOException { final RevCommit commit; - try (final RevWalk rw = new RevWalk(clonedRepo)) { + try (RevWalk rw = new RevWalk(clonedRepo)) { commit = rw.parseCommit(ref.getObjectId()); } return commit; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index f2572835fc..d07532c092 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java @@ -54,7 +54,7 @@ import java.util.List; import org.eclipse.jgit.api.errors.AbortedByHookException; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; -import org.eclipse.jgit.api.errors.EmtpyCommitException; +import org.eclipse.jgit.api.errors.EmptyCommitException; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.NoFilepatternException; @@ -238,7 +238,7 @@ public class CommitCommand extends GitCommand<RevCommit> { RevCommit headCommit = rw.parseCommit(headId); headCommit.getTree(); if (indexTreeId.equals(headCommit.getTree())) { - throw new EmtpyCommitException( + throw new EmptyCommitException( JGitText.get().emptyCommit); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java index 29baf4cd63..ba6f3f11b4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java @@ -43,6 +43,9 @@ */ package org.eclipse.jgit.api; +import static org.eclipse.jgit.lib.Constants.HEAD; +import static org.eclipse.jgit.lib.Constants.R_HEADS; + import java.io.IOException; import java.text.MessageFormat; @@ -78,7 +81,7 @@ public class CreateBranchCommand extends GitCommand<Ref> { private SetupUpstreamMode upstreamMode; - private String startPoint = Constants.HEAD; + private String startPoint = HEAD; private RevCommit startCommit; @@ -121,7 +124,7 @@ public class CreateBranchCommand extends GitCommand<Ref> { try (RevWalk revWalk = new RevWalk(repo)) { Ref refToCheck = repo.findRef(name); boolean exists = refToCheck != null - && refToCheck.getName().startsWith(Constants.R_HEADS); + && refToCheck.getName().startsWith(R_HEADS); if (!force && exists) throw new RefAlreadyExistsException(MessageFormat.format( JGitText.get().refAlreadyExists1, name)); @@ -153,7 +156,7 @@ public class CreateBranchCommand extends GitCommand<Ref> { else refLogMessage = "branch: Created from commit " + baseCommit; //$NON-NLS-1$ - } else if (startPointFullName.startsWith(Constants.R_HEADS) + } else if (startPointFullName.startsWith(R_HEADS) || startPointFullName.startsWith(Constants.R_REMOTES)) { baseBranch = startPointFullName; if (exists) @@ -171,7 +174,7 @@ public class CreateBranchCommand extends GitCommand<Ref> { + startPointFullName; } - RefUpdate updateRef = repo.updateRef(Constants.R_HEADS + name); + RefUpdate updateRef = repo.updateRef(R_HEADS + name); updateRef.setNewObjectId(startAt); updateRef.setRefLogMessage(refLogMessage, false); Result updateResult; @@ -279,17 +282,34 @@ public class CreateBranchCommand extends GitCommand<Ref> { } private String getStartPointOrHead() { - return startPoint != null ? startPoint : Constants.HEAD; + return startPoint != null ? startPoint : HEAD; } private void processOptions() throws InvalidRefNameException { if (name == null - || !Repository.isValidRefName(Constants.R_HEADS + name)) + || !Repository.isValidRefName(R_HEADS + name) + || !isValidBranchName(name)) throw new InvalidRefNameException(MessageFormat.format(JGitText .get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$ } /** + * Check if the given branch name is valid + * + * @param branchName + * branch name to check + * @return {@code true} if the branch name is valid + * + * @since 5.0 + */ + public static boolean isValidBranchName(String branchName) { + if (HEAD.equals(branchName)) { + return false; + } + return !branchName.startsWith("-"); //$NON-NLS-1$ + } + + /** * Set the name of the new branch * * @param name diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java index 01fe4aa9ee..4d5e499571 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java @@ -104,6 +104,11 @@ public class DescribeCommand extends GitCommand<String> { private List<IMatcher> matchers = new ArrayList<>(); /** + * Whether to use all tags (incl. lightweight) or not + */ + private boolean useTags = false; + + /** * Constructor for DescribeCommand. * * @param repo @@ -173,6 +178,22 @@ public class DescribeCommand extends GitCommand<String> { return this; } + /** + * Instead of using only the annotated tags, use any tag found in refs/tags + * namespace. This option enables matching lightweight (non-annotated) tags + * or not. + * + * @param tags + * <code>true</code> enables matching lightweight (non-annotated) + * tags like setting option --tags in c git + * @return {@code this} + * @since 5.0 + */ + public DescribeCommand setTags(boolean tags) { + this.useTags = tags; + return this; + } + private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { return String.format( @@ -224,12 +245,16 @@ public class DescribeCommand extends GitCommand<String> { } } - private ObjectId getObjectIdFromRef(Ref r) { - ObjectId key = repo.peel(r).getPeeledObjectId(); - if (key == null) { - key = r.getObjectId(); + private ObjectId getObjectIdFromRef(Ref r) throws JGitInternalException { + try { + ObjectId key = repo.getRefDatabase().peel(r).getPeeledObjectId(); + if (key == null) { + key = r.getObjectId(); + } + return key; + } catch (IOException e) { + throw new JGitInternalException(e.getMessage(), e); } - return key; } /** @@ -242,12 +267,14 @@ public class DescribeCommand extends GitCommand<String> { public String call() throws GitAPIException { try { checkCallable(); - - if (target == null) + if (target == null) { setTarget(Constants.HEAD); + } - Collection<Ref> tagList = repo.getRefDatabase().getRefs(R_TAGS).values(); + Collection<Ref> tagList = repo.getRefDatabase() + .getRefsByPrefix(R_TAGS); Map<ObjectId, List<Ref>> tags = tagList.stream() + .filter(this::filterLightweightTags) .collect(Collectors.groupingBy(this::getObjectIdFromRef)); // combined flags of all the candidate instances @@ -371,4 +398,22 @@ public class DescribeCommand extends GitCommand<String> { w.close(); } } + + /** + * Whether we use lightweight tags or not for describe Candidates + * + * @param ref + * reference under inspection + * @return true if it should be used for describe or not regarding + * {@link org.eclipse.jgit.api.DescribeCommand#useTags} + */ + @SuppressWarnings("null") + private boolean filterLightweightTags(Ref ref) { + ObjectId id = ref.getObjectId(); + try { + return this.useTags || (id != null && (w.parseTag(id) != null)); + } catch (IOException e) { + return false; + } + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java index 5d178bc13c..73e93a1c94 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java @@ -105,6 +105,8 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> { private Callback callback; + private boolean isForceUpdate; + /** * Callback for status of fetch operation. * @@ -198,7 +200,8 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> { .setTagOpt(tagOption) .setCheckFetchedObjects(checkFetchedObjects) .setRemoveDeletedRefs(isRemoveDeletedRefs()) - .setThin(thin).setRefSpecs(refSpecs) + .setThin(thin) + .setRefSpecs(applyOptions(refSpecs)) .setDryRun(dryRun) .setRecurseSubmodules(recurseMode); configure(f); @@ -237,8 +240,8 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> { transport.setTagOpt(tagOption); transport.setFetchThin(thin); configure(transport); - - FetchResult result = transport.fetch(monitor, refSpecs); + FetchResult result = transport.fetch(monitor, + applyOptions(refSpecs)); if (!repo.isBare()) { fetchSubmodules(result); } @@ -261,6 +264,17 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> { } + private List<RefSpec> applyOptions(List<RefSpec> refSpecs2) { + if (!isForceUpdate()) { + return refSpecs2; + } + List<RefSpec> updated = new ArrayList<>(3); + for (RefSpec refSpec : refSpecs2) { + updated.add(refSpec.setForceUpdate(true)); + } + return updated; + } + /** * Set the mode to be used for recursing into submodules. * @@ -517,4 +531,27 @@ public class FetchCommand extends TransportCommand<FetchCommand, FetchResult> { this.callback = callback; return this; } + + /** + * Whether fetch --force option is enabled + * + * @return whether refs affected by the fetch are updated forcefully + * @since 5.0 + */ + public boolean isForceUpdate() { + return this.isForceUpdate; + } + + /** + * Set fetch --force option + * + * @param force + * whether to update refs affected by the fetch forcefully + * @return this command + * @since 5.0 + */ + public FetchCommand setForceUpdate(boolean force) { + this.isForceUpdate = force; + return this; + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java index cdae782c6c..28a27a90e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListBranchCommand.java @@ -187,6 +187,6 @@ public class ListBranchCommand extends GitCommand<List<Ref>> { } private Collection<Ref> getRefs(String prefix) throws IOException { - return repo.getRefDatabase().getRefs(prefix).values(); + return repo.getRefDatabase().getRefsByPrefix(prefix); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java index 9161211d7f..01c1991846 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ListTagCommand.java @@ -47,7 +47,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Map; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; @@ -78,11 +77,11 @@ public class ListTagCommand extends GitCommand<List<Ref>> { @Override public List<Ref> call() throws GitAPIException { checkCallable(); - Map<String, Ref> refList; List<Ref> tags = new ArrayList<>(); try (RevWalk revWalk = new RevWalk(repo)) { - refList = repo.getRefDatabase().getRefs(Constants.R_TAGS); - for (Ref ref : refList.values()) { + List<Ref> refList = repo.getRefDatabase() + .getRefsByPrefix(Constants.R_TAGS); + for (Ref ref : refList) { tags.add(ref); } } catch (IOException e) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java index fd6c1fa1be..cf3d35fe89 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java @@ -42,13 +42,10 @@ */ package org.eclipse.jgit.api; -import static org.eclipse.jgit.lib.RefDatabase.ALL; - import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; -import java.util.Map; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; @@ -275,10 +272,9 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> { * the references could not be accessed */ public LogCommand all() throws IOException { - Map<String, Ref> refs = getRepository().getRefDatabase().getRefs(ALL); - for (Ref ref : refs.values()) { + for (Ref ref : getRepository().getRefDatabase().getRefs()) { if(!ref.isPeeled()) - ref = getRepository().peel(ref); + ref = getRepository().getRefDatabase().peel(ref); ObjectId objectId = ref.getPeeledObjectId(); if (objectId == null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java index cd50cae4fb..b8fa74de79 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java @@ -112,6 +112,8 @@ public class MergeCommand extends GitCommand<MergeResult> { private String message; + private boolean insertChangeId; + private ProgressMonitor monitor = NullProgressMonitor.INSTANCE; /** @@ -253,7 +255,7 @@ public class MergeCommand extends GitCommand<MergeResult> { refLogMessage.append(ref.getName()); // handle annotated tags - ref = repo.peel(ref); + ref = repo.getRefDatabase().peel(ref); ObjectId objectId = ref.getPeeledObjectId(); if (objectId == null) objectId = ref.getObjectId(); @@ -392,6 +394,7 @@ public class MergeCommand extends GitCommand<MergeResult> { try (Git git = new Git(getRepository())) { newHeadId = git.commit() .setReflogComment(refLogMessage.toString()) + .setInsertChangeId(insertChangeId) .call().getId(); } mergeStatus = MergeStatus.MERGED; @@ -619,6 +622,23 @@ public class MergeCommand extends GitCommand<MergeResult> { } /** + * If set to true a change id will be inserted into the commit message + * + * An existing change id is not replaced. An initial change id (I000...) + * will be replaced by the change id. + * + * @param insertChangeId + * whether to insert a change id + * @return {@code this} + * @since 5.0 + */ + public MergeCommand setInsertChangeId(boolean insertChangeId) { + checkCallable(); + this.insertChangeId = insertChangeId; + return this; + } + + /** * The progress monitor associated with the diff operation. By default, this * is set to <code>NullProgressMonitor</code> * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java index a9d9759a74..a2b200706b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/NameRevCommand.java @@ -251,8 +251,7 @@ public class NameRevCommand extends GitCommand<Map<ObjectId, String>> { * prefix added by {@link #addPrefix(String)}. * * @param prefix - * prefix to add; see - * {@link org.eclipse.jgit.lib.RefDatabase#getRefs(String)} + * prefix to add; the prefix must end with a slash * @return {@code this} */ public NameRevCommand addPrefix(String prefix) { @@ -279,7 +278,8 @@ public class NameRevCommand extends GitCommand<Map<ObjectId, String>> { if (refs == null) refs = new ArrayList<>(); try { - for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_TAGS).values()) { + for (Ref ref : repo.getRefDatabase() + .getRefsByPrefix(Constants.R_TAGS)) { ObjectId id = ref.getObjectId(); if (id != null && (walk.parseAny(id) instanceof RevTag)) addRef(ref); @@ -325,7 +325,7 @@ public class NameRevCommand extends GitCommand<Map<ObjectId, String>> { private void addPrefix(String prefix, Map<ObjectId, String> nonCommits, FIFORevQueue pending) throws IOException { - for (Ref ref : repo.getRefDatabase().getRefs(prefix).values()) + for (Ref ref : repo.getRefDatabase().getRefsByPrefix(prefix)) addRef(ref, nonCommits, pending); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java index 19bdd35778..459451feae 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java @@ -153,7 +153,8 @@ public class PushCommand extends final List<Transport> transports; transports = Transport.openAll(repo, remote, Transport.Operation.PUSH); - for (final Transport transport : transports) { + for (@SuppressWarnings("resource") // Explicitly closed in finally + final Transport transport : transports) { transport.setPushThin(thin); transport.setPushAtomic(atomic); if (receivePack != null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index da1ff06ae5..98c16b8931 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -1734,23 +1734,17 @@ public class RebaseCommand extends GitCommand<RebaseResult> { String content) throws IOException { File file = new File(parentDir, name); - FileOutputStream fos = new FileOutputStream(file); - try { + try (FileOutputStream fos = new FileOutputStream(file)) { fos.write(content.getBytes(Constants.CHARACTER_ENCODING)); fos.write('\n'); - } finally { - fos.close(); } } private static void appendToFile(File file, String content) throws IOException { - FileOutputStream fos = new FileOutputStream(file, true); - try { + try (FileOutputStream fos = new FileOutputStream(file, true)) { fos.write(content.getBytes(Constants.CHARACTER_ENCODING)); fos.write('\n'); - } finally { - fos.close(); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteAddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteAddCommand.java index c43c5c6f98..a8fdcd29f5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteAddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RemoteAddCommand.java @@ -86,9 +86,12 @@ public class RemoteAddCommand extends GitCommand<RemoteConfig> { * * @param name * a remote name + * @return this instance + * @since 5.0 */ - public void setName(String name) { + public RemoteAddCommand setName(String name) { this.name = name; + return this; } /** @@ -96,9 +99,12 @@ public class RemoteAddCommand extends GitCommand<RemoteConfig> { * * @param uri * an URL for the remote + * @return this instance + * @since 5.0 */ - public void setUri(URIish uri) { + public RemoteAddCommand setUri(URIish uri) { this.uri = uri; + return this; } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java index be446f9447..13ce4e7690 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java @@ -245,7 +245,7 @@ public class ResetCommand extends GitCommand<Ref> { } } - private RevCommit parseCommit(final ObjectId commitId) { + private RevCommit parseCommit(ObjectId commitId) { try (RevWalk rw = new RevWalk(repo)) { return rw.parseCommit(commitId); } catch (IOException e) { @@ -360,7 +360,7 @@ public class ResetCommand extends GitCommand<Ref> { private void resetIndexForPaths(ObjectId commitTree) { DirCache dc = null; - try (final TreeWalk tw = new TreeWalk(repo)) { + try (TreeWalk tw = new TreeWalk(repo)) { dc = repo.lockDirCache(); DirCacheBuilder builder = dc.builder(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java index 088aa15e57..d2f4be84bd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RmCommand.java @@ -154,7 +154,7 @@ public class RmCommand extends GitCommand<DirCache> { DirCache dc = null; List<String> actuallyDeletedFiles = new ArrayList<>(); - try (final TreeWalk tw = new TreeWalk(repo)) { + try (TreeWalk tw = new TreeWalk(repo)) { dc = repo.lockDirCache(); DirCacheBuilder builder = dc.builder(); tw.reset(); // drop the first empty tree, which we do not need here diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java index 5f7928d4d8..01d070cbd9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java @@ -111,7 +111,7 @@ public class StashApplyCommand extends GitCommand<ObjectId> { * the {@link org.eclipse.jgit.lib.Repository} to apply the stash * to */ - public StashApplyCommand(final Repository repo) { + public StashApplyCommand(Repository repo) { super(repo); } @@ -125,7 +125,7 @@ public class StashApplyCommand extends GitCommand<ObjectId> { * name of the stash {@code Ref} to apply * @return {@code this} */ - public StashApplyCommand setStashRef(final String stashRef) { + public StashApplyCommand setStashRef(String stashRef) { this.stashRef = stashRef; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java index 3495ff8a9d..c32890d8a4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java @@ -195,7 +195,7 @@ public class StashCreateCommand extends GitCommand<RevCommit> { private RevCommit parseCommit(final ObjectReader reader, final ObjectId headId) throws IOException { - try (final RevWalk walk = new RevWalk(reader)) { + try (RevWalk walk = new RevWalk(reader)) { return walk.parseCommit(headId); } } @@ -303,12 +303,9 @@ public class StashCreateCommand extends GitCommand<RevCommit> { entry.setLastModified(wtIter.getEntryLastModified()); entry.setFileMode(wtIter.getEntryFileMode()); long contentLength = wtIter.getEntryContentLength(); - InputStream in = wtIter.openEntryStream(); - try { + try (InputStream in = wtIter.openEntryStream()) { entry.setObjectId(inserter.insert( Constants.OBJ_BLOB, contentLength, in)); - } finally { - in.close(); } if (indexIter == null && headIter == null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java index cd8f8e6c96..7f02aabc0a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashDropCommand.java @@ -107,7 +107,7 @@ public class StashDropCommand extends GitCommand<ObjectId> { * the 0-based index of the stash reference * @return {@code this} */ - public StashDropCommand setStashRef(final int stashRef) { + public StashDropCommand setStashRef(int stashRef) { if (stashRef < 0) throw new IllegalArgumentException(); @@ -124,7 +124,7 @@ public class StashDropCommand extends GitCommand<ObjectId> { * {@link #setStashRef(int)} * @return {@code this} */ - public StashDropCommand setAll(final boolean all) { + public StashDropCommand setAll(boolean all) { this.all = all; return this; } @@ -138,7 +138,7 @@ public class StashDropCommand extends GitCommand<ObjectId> { } } - private RefUpdate createRefUpdate(final Ref stashRef) throws IOException { + private RefUpdate createRefUpdate(Ref stashRef) throws IOException { RefUpdate update = repo.updateRef(R_STASH); update.disableRefLog(); update.setExpectedOldObjectId(stashRef.getObjectId()); @@ -146,7 +146,7 @@ public class StashDropCommand extends GitCommand<ObjectId> { return update; } - private void deleteRef(final Ref stashRef) { + private void deleteRef(Ref stashRef) { try { Result result = createRefUpdate(stashRef).delete(); if (Result.FORCED != result) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java index 6451b709f0..f316b2366f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashListCommand.java @@ -72,7 +72,7 @@ public class StashListCommand extends GitCommand<Collection<RevCommit>> { * * @param repo a {@link org.eclipse.jgit.lib.Repository} object. */ - public StashListCommand(final Repository repo) { + public StashListCommand(Repository repo) { super(repo); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java index 1aa050f560..9538d2be6c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleAddCommand.java @@ -88,7 +88,7 @@ public class SubmoduleAddCommand extends * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. */ - public SubmoduleAddCommand(final Repository repo) { + public SubmoduleAddCommand(Repository repo) { super(repo); } @@ -99,7 +99,7 @@ public class SubmoduleAddCommand extends * (with <code>/</code> as separator) * @return this command */ - public SubmoduleAddCommand setPath(final String path) { + public SubmoduleAddCommand setPath(String path) { this.path = path; return this; } @@ -111,7 +111,7 @@ public class SubmoduleAddCommand extends * a {@link java.lang.String} object. * @return this command */ - public SubmoduleAddCommand setURI(final String uri) { + public SubmoduleAddCommand setURI(String uri) { this.uri = uri; return this; } @@ -125,7 +125,7 @@ public class SubmoduleAddCommand extends * a {@link org.eclipse.jgit.lib.ProgressMonitor} object. * @return this command */ - public SubmoduleAddCommand setProgressMonitor(final ProgressMonitor monitor) { + public SubmoduleAddCommand setProgressMonitor(ProgressMonitor monitor) { this.monitor = monitor; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java index 6af27d704c..2db12b8e25 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java @@ -77,7 +77,7 @@ public class SubmoduleInitCommand extends GitCommand<Collection<String>> { * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. */ - public SubmoduleInitCommand(final Repository repo) { + public SubmoduleInitCommand(Repository repo) { super(repo); paths = new ArrayList<>(); } @@ -89,7 +89,7 @@ public class SubmoduleInitCommand extends GitCommand<Collection<String>> { * (with <code>/</code> as separator) * @return this command */ - public SubmoduleInitCommand addPath(final String path) { + public SubmoduleInitCommand addPath(String path) { paths.add(path); return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java index 97ae668078..0606c5b8d4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java @@ -77,7 +77,7 @@ public class SubmoduleStatusCommand extends * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. */ - public SubmoduleStatusCommand(final Repository repo) { + public SubmoduleStatusCommand(Repository repo) { super(repo); paths = new ArrayList<>(); } @@ -89,7 +89,7 @@ public class SubmoduleStatusCommand extends * (with <code>/</code> as separator) * @return this command */ - public SubmoduleStatusCommand addPath(final String path) { + public SubmoduleStatusCommand addPath(String path) { paths.add(path); return this; } @@ -130,16 +130,14 @@ public class SubmoduleStatusCommand extends id); // Report uninitialized if no submodule repository - Repository subRepo = generator.getRepository(); - if (subRepo == null) - return new SubmoduleStatus(SubmoduleStatusType.UNINITIALIZED, path, - id); + ObjectId headId = null; + try (Repository subRepo = generator.getRepository()) { + if (subRepo == null) { + return new SubmoduleStatus(SubmoduleStatusType.UNINITIALIZED, + path, id); + } - ObjectId headId; - try { headId = subRepo.resolve(Constants.HEAD); - } finally { - subRepo.close(); } // Report uninitialized if no HEAD commit in submodule repository diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java index d22d820c32..7cf4b73af0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java @@ -79,7 +79,7 @@ public class SubmoduleSyncCommand extends GitCommand<Map<String, String>> { * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. */ - public SubmoduleSyncCommand(final Repository repo) { + public SubmoduleSyncCommand(Repository repo) { super(repo); paths = new ArrayList<>(); } @@ -91,7 +91,7 @@ public class SubmoduleSyncCommand extends GitCommand<Map<String, String>> { * (with <code>/</code> as separator) * @return this command */ - public SubmoduleSyncCommand addPath(final String path) { + public SubmoduleSyncCommand addPath(String path) { paths.add(path); return this; } @@ -104,7 +104,7 @@ public class SubmoduleSyncCommand extends GitCommand<Map<String, String>> { * @return shortened branch name, null on failures * @throws java.io.IOException */ - protected String getHeadBranch(final Repository subRepo) throws IOException { + protected String getHeadBranch(Repository subRepo) throws IOException { Ref head = subRepo.exactRef(Constants.HEAD); if (head != null && head.isSymbolic()) return Repository.shortenRefName(head.getLeaf().getName()); @@ -132,30 +132,31 @@ public class SubmoduleSyncCommand extends GitCommand<Map<String, String>> { path, ConfigConstants.CONFIG_KEY_URL, remoteUrl); synced.put(path, remoteUrl); - Repository subRepo = generator.getRepository(); - if (subRepo == null) - continue; + try (Repository subRepo = generator.getRepository()) { + if (subRepo == null) { + continue; + } + + StoredConfig subConfig; + String branch; - StoredConfig subConfig; - String branch; - try { subConfig = subRepo.getConfig(); // Get name of remote associated with current branch and // fall back to default remote name as last resort branch = getHeadBranch(subRepo); String remote = null; - if (branch != null) + if (branch != null) { remote = subConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants.CONFIG_KEY_REMOTE); - if (remote == null) + } + if (remote == null) { remote = Constants.DEFAULT_REMOTE_NAME; + } subConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION, remote, ConfigConstants.CONFIG_KEY_URL, remoteUrl); subConfig.save(); - } finally { - subRepo.close(); } } if (!synced.isEmpty()) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java index 3362d46f10..398f21ebce 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java @@ -103,7 +103,7 @@ public class SubmoduleUpdateCommand extends * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. */ - public SubmoduleUpdateCommand(final Repository repo) { + public SubmoduleUpdateCommand(Repository repo) { super(repo); paths = new ArrayList<>(); } @@ -132,7 +132,7 @@ public class SubmoduleUpdateCommand extends * @return this command * @since 4.9 */ - public SubmoduleUpdateCommand setFetch(final boolean fetch) { + public SubmoduleUpdateCommand setFetch(boolean fetch) { this.fetch = fetch; return this; } @@ -144,11 +144,43 @@ public class SubmoduleUpdateCommand extends * (with <code>/</code> as separator) * @return this command */ - public SubmoduleUpdateCommand addPath(final String path) { + public SubmoduleUpdateCommand addPath(String path) { paths.add(path); return this; } + private Repository getOrCloneSubmodule(SubmoduleWalk generator, String url) + throws IOException, GitAPIException { + Repository repository = generator.getRepository(); + if (repository == null) { + if (callback != null) { + callback.cloningSubmodule(generator.getPath()); + } + CloneCommand clone = Git.cloneRepository(); + configure(clone); + clone.setURI(url); + clone.setDirectory(generator.getDirectory()); + clone.setGitDir( + new File(new File(repo.getDirectory(), Constants.MODULES), + generator.getPath())); + if (monitor != null) { + clone.setProgressMonitor(monitor); + } + repository = clone.call().getRepository(); + } else if (this.fetch) { + if (fetchCallback != null) { + fetchCallback.fetchingSubmodule(generator.getPath()); + } + FetchCommand fetchCommand = Git.wrap(repository).fetch(); + if (monitor != null) { + fetchCommand.setProgressMonitor(monitor); + } + configure(fetchCommand); + fetchCommand.call(); + } + return repository; + } + /** * {@inheritDoc} * @@ -175,34 +207,8 @@ public class SubmoduleUpdateCommand extends if (url == null) continue; - Repository submoduleRepo = generator.getRepository(); - // Clone repository if not present - if (submoduleRepo == null) { - if (callback != null) { - callback.cloningSubmodule(generator.getPath()); - } - CloneCommand clone = Git.cloneRepository(); - configure(clone); - clone.setURI(url); - clone.setDirectory(generator.getDirectory()); - clone.setGitDir(new File(new File(repo.getDirectory(), - Constants.MODULES), generator.getPath())); - if (monitor != null) - clone.setProgressMonitor(monitor); - submoduleRepo = clone.call().getRepository(); - } else if (this.fetch) { - if (fetchCallback != null) { - fetchCallback.fetchingSubmodule(generator.getPath()); - } - FetchCommand fetchCommand = Git.wrap(submoduleRepo).fetch(); - if (monitor != null) { - fetchCommand.setProgressMonitor(monitor); - } - configure(fetchCommand); - fetchCommand.call(); - } - - try (RevWalk walk = new RevWalk(submoduleRepo)) { + try (Repository submoduleRepo = getOrCloneSubmodule(generator, + url); RevWalk walk = new RevWalk(submoduleRepo)) { RevCommit commit = walk .parseCommit(generator.getObjectId()); @@ -237,8 +243,6 @@ public class SubmoduleUpdateCommand extends generator.getPath()); } } - } finally { - submoduleRepo.close(); } updated.add(generator.getPath()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/TransportCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/TransportCommand.java index 9c915377d0..d34bb5d4cf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/TransportCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/TransportCommand.java @@ -80,7 +80,7 @@ public abstract class TransportCommand<C extends GitCommand, T> extends * * @param repo a {@link org.eclipse.jgit.lib.Repository} object. */ - protected TransportCommand(final Repository repo) { + protected TransportCommand(Repository repo) { super(repo); setCredentialsProvider(CredentialsProvider.getDefault()); } @@ -147,7 +147,7 @@ public abstract class TransportCommand<C extends GitCommand, T> extends * a {@link org.eclipse.jgit.transport.Transport} object. * @return {@code this} */ - protected C configure(final Transport transport) { + protected C configure(Transport transport) { if (credentialsProvider != null) transport.setCredentialsProvider(credentialsProvider); transport.setTimeout(timeout); @@ -164,7 +164,7 @@ public abstract class TransportCommand<C extends GitCommand, T> extends * a {@link org.eclipse.jgit.api.TransportCommand} object. * @return {@code this} */ - protected C configure(final TransportCommand childCommand) { + protected C configure(TransportCommand childCommand) { childCommand.setCredentialsProvider(credentialsProvider); childCommand.setTimeout(timeout); childCommand.setTransportConfigCallback(transportConfigCallback); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/AbortedByHookException.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/AbortedByHookException.java index db6440b55f..db6440b55f 100755..100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/AbortedByHookException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/AbortedByHookException.java diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/EmtpyCommitException.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/EmptyCommitException.java index ea0e7183c6..87e1a6af91 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/EmtpyCommitException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/EmptyCommitException.java @@ -40,30 +40,30 @@ package org.eclipse.jgit.api.errors; /** * Exception thrown when a newly created commit does not contain any changes * - * @since 4.2 + * @since 5.0 */ -public class EmtpyCommitException extends GitAPIException { // TODO: Correct spelling of this class name in 5.0 +public class EmptyCommitException extends GitAPIException { private static final long serialVersionUID = 1L; /** - * Constructor for EmtpyCommitException + * Constructor for EmptyCommitException * * @param message * error message * @param cause * a {@link java.lang.Throwable} */ - public EmtpyCommitException(String message, Throwable cause) { + public EmptyCommitException(String message, Throwable cause) { super(message, cause); } /** - * Constructor for EmtpyCommitException. + * Constructor for EmptyCommitException. * * @param message * error message */ - public EmtpyCommitException(String message) { + public EmptyCommitException(String message) { super(message); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/StashApplyFailureException.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/StashApplyFailureException.java index 517b512664..b12c032f88 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/StashApplyFailureException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/errors/StashApplyFailureException.java @@ -26,7 +26,7 @@ public class StashApplyFailureException extends GitAPIException { * @param message * error message */ - public StashApplyFailureException(final String message) { + public StashApplyFailureException(String message) { super(message); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java index 2eb313f603..106737805c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java @@ -108,7 +108,7 @@ final class ReverseWalk extends RevWalk { return children.length; } - ReverseCommit getChild(final int nth) { + ReverseCommit getChild(int nth) { return children[nth]; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffConfig.java index 063cefffa6..21dca6b78c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffConfig.java @@ -76,7 +76,7 @@ public class DiffConfig { private final int renameLimit; - private DiffConfig(final Config rc) { + private DiffConfig(Config rc) { noPrefix = rc.getBoolean(ConfigConstants.CONFIG_DIFF_SECTION, ConfigConstants.CONFIG_KEY_NOPREFIX, false); renameDetectionType = parseRenameDetectionType(rc.getString( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java index 2e29b81779..7aaa50030f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java @@ -222,7 +222,7 @@ public class DiffFormatter implements AutoCloseable { * modification and after the last modification within a hunk of * the modified file. */ - public void setContext(final int lineCount) { + public void setContext(int lineCount) { if (lineCount < 0) throw new IllegalArgumentException( JGitText.get().contextMustBeNonNegative); @@ -235,7 +235,7 @@ public class DiffFormatter implements AutoCloseable { * @param count * number of digits to show in an ObjectId. */ - public void setAbbreviationLength(final int count) { + public void setAbbreviationLength(int count) { if (count < 0) throw new IllegalArgumentException( JGitText.get().abbreviationLengthMustBeNonNegative); @@ -742,7 +742,7 @@ public class DiffFormatter implements AutoCloseable { * @throws java.io.IOException * writing to the supplied stream failed. */ - public void format(final FileHeader head, final RawText a, final RawText b) + public void format(FileHeader head, RawText a, RawText b) throws IOException { // Reuse the existing FileHeader as-is by blindly copying its // header lines, but avoiding its hunks. Instead we recreate @@ -768,7 +768,7 @@ public class DiffFormatter implements AutoCloseable { * the text B which was compared * @throws java.io.IOException */ - public void format(final EditList edits, final RawText a, final RawText b) + public void format(EditList edits, RawText a, RawText b) throws IOException { for (int curIdx = 0; curIdx < edits.size();) { Edit curEdit = edits.get(curIdx); @@ -816,12 +816,12 @@ public class DiffFormatter implements AutoCloseable { * the line number within text * @throws java.io.IOException */ - protected void writeContextLine(final RawText text, final int line) + protected void writeContextLine(RawText text, int line) throws IOException { writeLine(' ', text, line); } - private static boolean isEndOfLineMissing(final RawText text, final int line) { + private static boolean isEndOfLineMissing(RawText text, int line) { return line + 1 == text.size() && text.isMissingNewlineAtEnd(); } @@ -834,7 +834,7 @@ public class DiffFormatter implements AutoCloseable { * the line number within text * @throws java.io.IOException */ - protected void writeAddedLine(final RawText text, final int line) + protected void writeAddedLine(RawText text, int line) throws IOException { writeLine('+', text, line); } @@ -848,7 +848,7 @@ public class DiffFormatter implements AutoCloseable { * the line number within text * @throws java.io.IOException */ - protected void writeRemovedLine(final RawText text, final int line) + protected void writeRemovedLine(RawText text, int line) throws IOException { writeLine('-', text, line); } @@ -878,7 +878,7 @@ public class DiffFormatter implements AutoCloseable { out.write('\n'); } - private void writeRange(final char prefix, final int begin, final int cnt) + private void writeRange(char prefix, int begin, int cnt) throws IOException { out.write(' '); out.write(prefix); @@ -1213,7 +1213,7 @@ public class DiffFormatter implements AutoCloseable { o.write(encode("+++ " + newp + "\n")); //$NON-NLS-1$ //$NON-NLS-2$ } - private int findCombinedEnd(final List<Edit> edits, final int i) { + private int findCombinedEnd(List<Edit> edits, int i) { int end = i + 1; while (end < edits.size() && (combineA(edits, end) || combineB(edits, end))) @@ -1221,15 +1221,15 @@ public class DiffFormatter implements AutoCloseable { return end - 1; } - private boolean combineA(final List<Edit> e, final int i) { + private boolean combineA(List<Edit> e, int i) { return e.get(i).getBeginA() - e.get(i - 1).getEndA() <= 2 * context; } - private boolean combineB(final List<Edit> e, final int i) { + private boolean combineB(List<Edit> e, int i) { return e.get(i).getBeginB() - e.get(i - 1).getEndB() <= 2 * context; } - private static boolean end(final Edit edit, final int a, final int b) { + private static boolean end(Edit edit, int a, int b) { return edit.getEndA() <= a && edit.getEndB() <= b; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java index 775d11a46b..5c876e87fd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/Edit.java @@ -94,7 +94,7 @@ public class Edit { * @param bs * beginB: start and end of region in sequence B; 0 based. */ - public Edit(final int as, final int bs) { + public Edit(int as, int bs) { this(as, as, bs, bs); } @@ -110,7 +110,7 @@ public class Edit { * @param be * endB: end of region in sequence B; must be > = bs. */ - public Edit(final int as, final int ae, final int bs, final int be) { + public Edit(int as, int ae, int bs, int be) { beginA = as; endA = ae; @@ -279,7 +279,7 @@ public class Edit { /** {@inheritDoc} */ @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (o instanceof Edit) { final Edit e = (Edit) o; return this.beginA == e.beginA && this.endA == e.endA diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiffIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiffIndex.java index 04c79fcd1b..3f813d811f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiffIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/HistogramDiffIndex.java @@ -230,7 +230,7 @@ final class HistogramDiffIndex<S extends Sequence> { return true; } - private int tryLongestCommonSequence(final int bPtr) { + private int tryLongestCommonSequence(int bPtr) { int bNext = bPtr + 1; int rIdx = table[hash(b, bPtr)]; for (long rec; rIdx != 0; rIdx = recNext(rec)) { @@ -328,7 +328,7 @@ final class HistogramDiffIndex<S extends Sequence> { return ((int) rec) & REC_CNT_MASK; } - private static int tableBits(final int sz) { + private static int tableBits(int sz) { int bits = 31 - Integer.numberOfLeadingZeros(sz); if (bits == 0) bits = 1; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java index 646f264e09..caaffe349b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/MyersDiff.java @@ -359,7 +359,7 @@ if (k < beginK || k > endK) abstract int getLeft(int x); abstract int getRight(int x); abstract boolean isBetter(int left, int right); - abstract void adjustMinMaxK(final int k, final int x); + abstract void adjustMinMaxK(int k, int x); abstract boolean meets(int d, int k, int x, long snake); final long newSnake(int k, int x) { @@ -469,22 +469,22 @@ if (k < beginK || k > endK) } @Override - final int getLeft(final int x) { + final int getLeft(int x) { return x; } @Override - final int getRight(final int x) { + final int getRight(int x) { return x + 1; } @Override - final boolean isBetter(final int left, final int right) { + final boolean isBetter(int left, int right) { return left > right; } @Override - final void adjustMinMaxK(final int k, final int x) { + final void adjustMinMaxK(int k, int x) { if (x >= endA || k + x >= endB) { if (k > backward.middleK) maxK = k; @@ -517,22 +517,22 @@ if (k < beginK || k > endK) } @Override - final int getLeft(final int x) { + final int getLeft(int x) { return x - 1; } @Override - final int getRight(final int x) { + final int getRight(int x) { return x; } @Override - final boolean isBetter(final int left, final int right) { + final boolean isBetter(int left, int right) { return left < right; } @Override - final void adjustMinMaxK(final int k, final int x) { + final void adjustMinMaxK(int k, int x) { if (x <= beginA || k + x <= beginB) { if (k > forward.middleK) maxK = k; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java index ec88ce4ff7..bd41d90680 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawText.java @@ -88,12 +88,29 @@ public class RawText extends Sequence { * The entire array (indexes 0 through length-1) is used as the content. * * @param input - * the content array. The array is never modified, so passing - * through cached arrays is safe. + * the content array. The object retains a reference to this + * array, so it should be immutable. */ - public RawText(final byte[] input) { + public RawText(byte[] input) { + this(input, RawParseUtils.lineMap(input, 0, input.length)); + } + + /** + * Create a new sequence from the existing content byte array and the line + * map indicating line boundaries. + * + * @param input + * the content array. The object retains a reference to this + * array, so it should be immutable. + * @param lineMap + * an array with 1-based offsets for the start of each line. + * The first and last entries should be {@link Integer#MIN_VALUE} + * and an offset one past the end of the last line, respectively. + * @since 5.0 + */ + public RawText(byte[] input, IntList lineMap) { content = input; - lines = RawParseUtils.lineMap(content, 0, content.length); + lines = lineMap; } /** @@ -147,7 +164,7 @@ public class RawText extends Sequence { * @throws java.io.IOException * the stream write operation failed. */ - public void writeLine(final OutputStream out, final int i) + public void writeLine(OutputStream out, int i) throws IOException { int start = getStart(i); int end = getEnd(i); @@ -221,11 +238,11 @@ public class RawText extends Sequence { return RawParseUtils.decode(content, start, end); } - private int getStart(final int i) { + private int getStart(int i) { return lines.get(i + 1); } - private int getEnd(final int i) { + private int getEnd(int i) { return lines.get(i + 2); } @@ -325,7 +342,8 @@ public class RawText extends Sequence { * @throws java.io.IOException * if the input could not be read. */ - public static RawText load(ObjectLoader ldr, int threshold) throws IOException, BinaryBlobException { + public static RawText load(ObjectLoader ldr, int threshold) + throws IOException, BinaryBlobException { long sz = ldr.getSize(); if (sz > threshold) { @@ -369,7 +387,7 @@ public class RawText extends Sequence { System.arraycopy(head, 0, data, 0, head.length); IO.readFully(stream, data, off, (int) (sz-off)); - return new RawText(data); + return new RawText(data, RawParseUtils.lineMapOrBinary(data, 0, (int) sz)); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java index ed2eebb858..1e68c2f416 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/RawTextComparator.java @@ -77,7 +77,7 @@ public abstract class RawTextComparator extends SequenceComparator<RawText> { } @Override - protected int hashRegion(final byte[] raw, int ptr, final int end) { + protected int hashRegion(byte[] raw, int ptr, int end) { int hash = 5381; for (; ptr < end; ptr++) hash = ((hash << 5) + hash) + (raw[ptr] & 0xff); @@ -164,7 +164,7 @@ public abstract class RawTextComparator extends SequenceComparator<RawText> { } @Override - protected int hashRegion(final byte[] raw, int ptr, int end) { + protected int hashRegion(byte[] raw, int ptr, int end) { int hash = 5381; ptr = trimLeadingWhitespace(raw, ptr, end); for (; ptr < end; ptr++) @@ -199,7 +199,7 @@ public abstract class RawTextComparator extends SequenceComparator<RawText> { } @Override - protected int hashRegion(final byte[] raw, int ptr, int end) { + protected int hashRegion(byte[] raw, int ptr, int end) { int hash = 5381; end = trimTrailingWhitespace(raw, ptr, end); for (; ptr < end; ptr++) @@ -244,7 +244,7 @@ public abstract class RawTextComparator extends SequenceComparator<RawText> { } @Override - protected int hashRegion(final byte[] raw, int ptr, int end) { + protected int hashRegion(byte[] raw, int ptr, int end) { int hash = 5381; end = trimTrailingWhitespace(raw, ptr, end); while (ptr < end) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java index 8b4d2ec8fc..5897ffb758 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java @@ -147,23 +147,17 @@ public class SimilarityIndex { private void hashLargeObject(ObjectLoader obj) throws IOException, TableFullException { - ObjectStream in1 = obj.openStream(); boolean text; - try { + try (ObjectStream in1 = obj.openStream()) { text = !RawText.isBinary(in1); - } finally { - in1.close(); } - ObjectStream in2 = obj.openStream(); - try { + try (ObjectStream in2 = obj.openStream()) { hash(in2, in2.getSize(), text); - } finally { - in2.close(); } } - void hash(byte[] raw, int ptr, final int end) throws TableFullException { + void hash(byte[] raw, int ptr, int end) throws TableFullException { final boolean text = !RawText.isBinary(raw); hashedCnt = 0; while (ptr < end) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/BaseDirCacheEditor.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/BaseDirCacheEditor.java index 0228f4d3cc..aa229f79b9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/BaseDirCacheEditor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/BaseDirCacheEditor.java @@ -85,7 +85,7 @@ abstract class BaseDirCacheEditor { * estimated number of entries the editor will have upon * completion. This sizes the initial entry table. */ - protected BaseDirCacheEditor(final DirCache dc, final int ecnt) { + protected BaseDirCacheEditor(DirCache dc, int ecnt) { cache = dc; entries = new DirCacheEntry[ecnt]; } @@ -111,7 +111,7 @@ abstract class BaseDirCacheEditor { * @param newEntry * the new entry to add. */ - protected void fastAdd(final DirCacheEntry newEntry) { + protected void fastAdd(DirCacheEntry newEntry) { if (entries.length == entryCnt) { final DirCacheEntry[] n = new DirCacheEntry[(entryCnt + 16) * 3 / 2]; System.arraycopy(entries, 0, n, 0, entryCnt); @@ -140,7 +140,7 @@ abstract class BaseDirCacheEditor { * @param cnt * number of entries to copy. */ - protected void fastKeep(final int pos, int cnt) { + protected void fastKeep(int pos, int cnt) { if (entryCnt + cnt > entries.length) { final int m1 = (entryCnt + 16) * 3 / 2; final int m2 = entryCnt + cnt; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java index cc431dbdf2..14653fe17f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -45,16 +45,16 @@ package org.eclipse.jgit.dircache; +import static java.nio.charset.StandardCharsets.ISO_8859_1; + import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.EOFException; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.security.DigestOutputStream; import java.security.MessageDigest; import java.text.MessageFormat; @@ -87,6 +87,7 @@ import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.NB; import org.eclipse.jgit.util.TemporaryBuffer; +import org.eclipse.jgit.util.io.SilentFileInputStream; /** * Support for the Git dircache (aka index file). @@ -112,7 +113,7 @@ public class DirCache { static final Comparator<DirCacheEntry> ENT_CMP = new Comparator<DirCacheEntry>() { @Override - public int compare(final DirCacheEntry o1, final DirCacheEntry o2) { + public int compare(DirCacheEntry o1, DirCacheEntry o2) { final int cr = cmp(o1, o2); if (cr != 0) return cr; @@ -120,11 +121,11 @@ public class DirCache { } }; - static int cmp(final DirCacheEntry a, final DirCacheEntry b) { + static int cmp(DirCacheEntry a, DirCacheEntry b) { return cmp(a.path, a.path.length, b); } - static int cmp(final byte[] aPath, final int aLen, final DirCacheEntry b) { + static int cmp(byte[] aPath, int aLen, DirCacheEntry b) { return cmp(aPath, aLen, b.path, b.path.length); } @@ -188,7 +189,7 @@ public class DirCache { * the index file is using a format or extension that this * library does not support. */ - public static DirCache read(final Repository repository) + public static DirCache read(Repository repository) throws CorruptObjectException, IOException { final DirCache c = read(repository.getIndexFile(), repository.getFS()); c.repository = repository; @@ -215,7 +216,7 @@ public class DirCache { * the index file is using a format or extension that this * library does not support. */ - public static DirCache read(final File indexLocation, final FS fs) + public static DirCache read(File indexLocation, FS fs) throws CorruptObjectException, IOException { final DirCache c = new DirCache(indexLocation, fs); c.read(); @@ -244,7 +245,7 @@ public class DirCache { * the index file is using a format or extension that this * library does not support. */ - public static DirCache lock(final File indexLocation, final FS fs) + public static DirCache lock(File indexLocation, FS fs) throws CorruptObjectException, IOException { final DirCache c = new DirCache(indexLocation, fs); if (!c.lock()) @@ -372,7 +373,7 @@ public class DirCache { * the file system abstraction which will be necessary to perform * certain file system operations. */ - public DirCache(final File indexLocation, final FS fs) { + public DirCache(File indexLocation, FS fs) { liveFile = indexLocation; clear(); } @@ -403,7 +404,7 @@ public class DirCache { return new DirCacheEditor(this, entryCnt + 16); } - void replace(final DirCacheEntry[] e, final int cnt) { + void replace(DirCacheEntry[] e, int cnt) { sortedEntries = e; entryCnt = cnt; tree = null; @@ -429,18 +430,10 @@ public class DirCache { if (!liveFile.exists()) clear(); else if (snapshot == null || snapshot.isModified(liveFile)) { - try { - final FileInputStream inStream = new FileInputStream(liveFile); - try { - clear(); - readFrom(inStream); - } finally { - try { - inStream.close(); - } catch (IOException err2) { - // Ignore any close failures. - } - } + try (SilentFileInputStream inStream = new SilentFileInputStream( + liveFile)) { + clear(); + readFrom(inStream); } catch (FileNotFoundException fnfe) { if (liveFile.exists()) { // Panic: the index file exists but we can't read it @@ -480,7 +473,7 @@ public class DirCache { readIndexChecksum = NO_CHECKSUM; } - private void readFrom(final InputStream inStream) throws IOException, + private void readFrom(InputStream inStream) throws IOException, CorruptObjectException { final BufferedInputStream in = new BufferedInputStream(inStream); final MessageDigest md = Constants.newMessageDigest(); @@ -588,12 +581,11 @@ public class DirCache { } } - private static String formatExtensionName(final byte[] hdr) - throws UnsupportedEncodingException { - return "'" + new String(hdr, 0, 4, "ISO-8859-1") + "'"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private static String formatExtensionName(byte[] hdr) { + return "'" + new String(hdr, 0, 4, ISO_8859_1) + "'"; //$NON-NLS-1$ //$NON-NLS-2$ } - private static boolean is_DIRC(final byte[] hdr) { + private static boolean is_DIRC(byte[] hdr) { if (hdr.length < SIG_DIRC.length) return false; for (int i = 0; i < SIG_DIRC.length; i++) @@ -656,7 +648,7 @@ public class DirCache { } } - void writeTo(File dir, final OutputStream os) throws IOException { + void writeTo(File dir, OutputStream os) throws IOException { final MessageDigest foot = Constants.newMessageDigest(); final DigestOutputStream dos = new DigestOutputStream(os, foot); @@ -710,6 +702,8 @@ public class DirCache { } if (writeTree) { + @SuppressWarnings("resource") // Explicitly closed in try block, and + // destroyed in finally TemporaryBuffer bb = new TemporaryBuffer.LocalFile(dir, 5 << 20); try { tree.write(tmp, bb); @@ -743,16 +737,18 @@ public class DirCache { final LockFile tmp = myLock; requireLocked(tmp); myLock = null; - if (!tmp.commit()) + if (!tmp.commit()) { return false; + } snapshot = tmp.getCommitSnapshot(); if (indexChangedListener != null - && !Arrays.equals(readIndexChecksum, writeIndexChecksum)) - indexChangedListener.onIndexChanged(new IndexChangedEvent()); + && !Arrays.equals(readIndexChecksum, writeIndexChecksum)) { + indexChangedListener.onIndexChanged(new IndexChangedEvent(true)); + } return true; } - private void requireLocked(final LockFile tmp) { + private void requireLocked(LockFile tmp) { if (liveFile == null) throw new IllegalStateException(JGitText.get().dirCacheIsNotLocked); if (tmp == null) @@ -783,7 +779,7 @@ public class DirCache { * the index; pass to {@link #getEntry(int)} to obtain the entry * information. If < 0 the entry does not exist in the index. */ - public int findEntry(final String path) { + public int findEntry(String path) { final byte[] p = Constants.encode(path); return findEntry(p, p.length); } @@ -839,7 +835,7 @@ public class DirCache { * entry position of the path that should be skipped. * @return position of the next entry whose path is after the input. */ - public int nextEntry(final int position) { + public int nextEntry(int position) { DirCacheEntry last = sortedEntries[position]; int nextIdx = position + 1; while (nextIdx < entryCnt) { @@ -852,7 +848,7 @@ public class DirCache { return nextIdx; } - int nextEntry(final byte[] p, final int pLen, int nextIdx) { + int nextEntry(byte[] p, int pLen, int nextIdx) { while (nextIdx < entryCnt) { final DirCacheEntry next = sortedEntries[nextIdx]; if (!DirCacheTree.peq(p, next.path, pLen)) @@ -886,7 +882,7 @@ public class DirCache { * position of the entry to get. * @return the entry at position <code>i</code>. */ - public DirCacheEntry getEntry(final int i) { + public DirCacheEntry getEntry(int i) { return sortedEntries[i]; } @@ -897,7 +893,7 @@ public class DirCache { * the path to search for. * @return the entry for the given <code>path</code>. */ - public DirCacheEntry getEntry(final String path) { + public DirCacheEntry getEntry(String path) { final int i = findEntry(path); return i < 0 ? null : sortedEntries[i]; } @@ -946,7 +942,7 @@ public class DirCache { * @return the cache tree; null if there is no current cache tree available * and <code>build</code> was false. */ - public DirCacheTree getCacheTree(final boolean build) { + public DirCacheTree getCacheTree(boolean build) { if (build) { if (tree == null) tree = new DirCacheTree(); @@ -972,7 +968,7 @@ public class DirCache { * @throws java.io.IOException * an unexpected error occurred writing to the object store. */ - public ObjectId writeTree(final ObjectInserter ow) + public ObjectId writeTree(ObjectInserter ow) throws UnmergedPathException, IOException { return getCacheTree(true).writeTree(sortedEntries, 0, 0, ow); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuildIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuildIterator.java index 6e3682a3e2..e80544e48b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuildIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuildIterator.java @@ -96,7 +96,7 @@ public class DirCacheBuildIterator extends DirCacheIterator { * the cache builder for the cache to walk. The cache must be * already loaded into memory. */ - public DirCacheBuildIterator(final DirCacheBuilder dcb) { + public DirCacheBuildIterator(DirCacheBuilder dcb) { super(dcb.getDirCache()); builder = dcb; } @@ -109,7 +109,7 @@ public class DirCacheBuildIterator extends DirCacheIterator { /** {@inheritDoc} */ @Override - public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) + public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException { if (currentSubtree == null) throw new IncorrectObjectTypeException(getEntryObjectId(), diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java index 2ff7bb9aea..c5ff9ac41d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheBuilder.java @@ -83,7 +83,7 @@ public class DirCacheBuilder extends BaseDirCacheEditor { * estimated number of entries the builder will have upon * completion. This sizes the initial entry table. */ - protected DirCacheBuilder(final DirCache dc, final int ecnt) { + protected DirCacheBuilder(DirCache dc, int ecnt) { super(dc, ecnt); } @@ -102,7 +102,7 @@ public class DirCacheBuilder extends BaseDirCacheEditor { * @throws java.lang.IllegalArgumentException * If the FileMode of the entry was not set by the caller. */ - public void add(final DirCacheEntry newEntry) { + public void add(DirCacheEntry newEntry) { if (newEntry.getRawMode() == 0) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().fileModeNotSetForPath, @@ -131,7 +131,7 @@ public class DirCacheBuilder extends BaseDirCacheEditor { * @param cnt * number of entries to copy. */ - public void keep(final int pos, int cnt) { + public void keep(int pos, int cnt) { beforeAdd(cache.getEntry(pos)); fastKeep(pos, cnt); } @@ -227,7 +227,7 @@ public class DirCacheBuilder extends BaseDirCacheEditor { replace(); } - private void beforeAdd(final DirCacheEntry newEntry) { + private void beforeAdd(DirCacheEntry newEntry) { if (sorted && entryCnt > 0) { final DirCacheEntry lastEntry = entries[entryCnt - 1]; final int cr = DirCache.cmp(lastEntry, newEntry); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java index 30e3a3cf12..74ba97fb8d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEditor.java @@ -77,7 +77,7 @@ import org.eclipse.jgit.util.Paths; public class DirCacheEditor extends BaseDirCacheEditor { private static final Comparator<PathEdit> EDIT_CMP = new Comparator<PathEdit>() { @Override - public int compare(final PathEdit o1, final PathEdit o2) { + public int compare(PathEdit o1, PathEdit o2) { final byte[] a = o1.path; final byte[] b = o2.path; return cmp(a, a.length, b, b.length); @@ -96,7 +96,7 @@ public class DirCacheEditor extends BaseDirCacheEditor { * estimated number of entries the editor will have upon * completion. This sizes the initial entry table. */ - protected DirCacheEditor(final DirCache dc, final int ecnt) { + protected DirCacheEditor(DirCache dc, int ecnt) { super(dc, ecnt); edits = new ArrayList<>(); } @@ -111,7 +111,7 @@ public class DirCacheEditor extends BaseDirCacheEditor { * @param edit * another edit command. */ - public void add(final PathEdit edit) { + public void add(PathEdit edit) { edits.add(edit); } @@ -304,7 +304,7 @@ public class DirCacheEditor extends BaseDirCacheEditor { * @param entryPath * path of the file within the repository. */ - public PathEdit(final String entryPath) { + public PathEdit(String entryPath) { path = Constants.encode(entryPath); } @@ -319,7 +319,7 @@ public class DirCacheEditor extends BaseDirCacheEditor { * entry instance to match path of. Only the path of this * entry is actually considered during command evaluation. */ - public PathEdit(final DirCacheEntry ent) { + public PathEdit(DirCacheEntry ent) { path = ent.path; } @@ -374,7 +374,7 @@ public class DirCacheEditor extends BaseDirCacheEditor { * @param entryPath * path of the file within the repository. */ - public DeletePath(final String entryPath) { + public DeletePath(String entryPath) { super(entryPath); } @@ -385,12 +385,12 @@ public class DirCacheEditor extends BaseDirCacheEditor { * entry instance to remove. Only the path of this entry is * actually considered during command evaluation. */ - public DeletePath(final DirCacheEntry ent) { + public DeletePath(DirCacheEntry ent) { super(ent); } @Override - public void apply(final DirCacheEntry ent) { + public void apply(DirCacheEntry ent) { throw new UnsupportedOperationException(JGitText.get().noApplyInDelete); } } @@ -440,7 +440,7 @@ public class DirCacheEditor extends BaseDirCacheEditor { } @Override - public void apply(final DirCacheEntry ent) { + public void apply(DirCacheEntry ent) { throw new UnsupportedOperationException(JGitText.get().noApplyInDelete); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java index 7c03c64946..fee9f51000 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -227,7 +227,7 @@ public class DirCacheEntry { * "\0". These sequences are not permitted in a git tree object * or DirCache file. */ - public DirCacheEntry(final String newPath) { + public DirCacheEntry(String newPath) { this(Constants.encode(newPath), STAGE_0); } @@ -244,7 +244,7 @@ public class DirCacheEntry { * or DirCache file. Or if {@code stage} is outside of the * range 0..3, inclusive. */ - public DirCacheEntry(final String newPath, final int stage) { + public DirCacheEntry(String newPath, int stage) { this(Constants.encode(newPath), stage); } @@ -258,7 +258,7 @@ public class DirCacheEntry { * "\0". These sequences are not permitted in a git tree object * or DirCache file. */ - public DirCacheEntry(final byte[] newPath) { + public DirCacheEntry(byte[] newPath) { this(newPath, STAGE_0); } @@ -276,7 +276,7 @@ public class DirCacheEntry { * range 0..3, inclusive. */ @SuppressWarnings("boxing") - public DirCacheEntry(byte[] path, final int stage) { + public DirCacheEntry(byte[] path, int stage) { checkPath(path); if (stage < 0 || 3 < stage) throw new IllegalArgumentException(MessageFormat.format( @@ -312,7 +312,7 @@ public class DirCacheEntry { System.arraycopy(src.info, src.infoOffset, info, 0, INFO_LEN); } - void write(final OutputStream os) throws IOException { + void write(OutputStream os) throws IOException { final int len = isExtended() ? INFO_LEN_EXTENDED : INFO_LEN; final int pathLen = path.length; os.write(info, infoOffset, len); @@ -343,7 +343,7 @@ public class DirCacheEntry { * nanoseconds component of the index's last modified time. * @return true if extra careful checks should be used. */ - public final boolean mightBeRacilyClean(final int smudge_s, final int smudge_ns) { + public final boolean mightBeRacilyClean(int smudge_s, int smudge_ns) { // If the index has a modification time then it came from disk // and was not generated from scratch in memory. In such cases // the entry is 'racily clean' if the entry's cached modification @@ -420,7 +420,7 @@ public class DirCacheEntry { * true to ignore apparent modifications; false to look at last * modified to detect file modifications. */ - public void setAssumeValid(final boolean assume) { + public void setAssumeValid(boolean assume) { if (assume) info[infoOffset + P_FLAGS] |= ASSUME_VALID; else @@ -518,7 +518,7 @@ public class DirCacheEntry { * {@link org.eclipse.jgit.lib.FileMode#TREE}, or any other type * code not permitted in a tree object. */ - public void setFileMode(final FileMode mode) { + public void setFileMode(FileMode mode) { switch (mode.getBits() & FileMode.TYPE_MASK) { case FileMode.TYPE_MISSING: case FileMode.TYPE_TREE: @@ -548,7 +548,7 @@ public class DirCacheEntry { * @param when * new cached creation time of the file, in milliseconds. */ - public void setCreationTime(final long when) { + public void setCreationTime(long when) { encodeTS(P_CTIME, when); } @@ -572,7 +572,7 @@ public class DirCacheEntry { * @param when * new cached modification date of the file, in milliseconds. */ - public void setLastModified(final long when) { + public void setLastModified(long when) { encodeTS(P_MTIME, when); } @@ -604,7 +604,7 @@ public class DirCacheEntry { * new cached size of the file, as bytes. If the file is larger * than 2G, cast it to (int) before calling this method. */ - public void setLength(final int sz) { + public void setLength(int sz) { NB.encodeInt32(info, infoOffset + P_SIZE, sz); } @@ -614,7 +614,7 @@ public class DirCacheEntry { * @param sz * new cached size of the file, as bytes. */ - public void setLength(final long sz) { + public void setLength(long sz) { setLength((int) sz); } @@ -638,7 +638,7 @@ public class DirCacheEntry { * {@link org.eclipse.jgit.lib.ObjectId#zeroId()} to remove the * current identifier. */ - public void setObjectId(final AnyObjectId id) { + public void setObjectId(AnyObjectId id) { id.copyRawTo(idBuffer(), idOffset()); } @@ -651,7 +651,7 @@ public class DirCacheEntry { * @param p * position to read the first byte of data from. */ - public void setObjectIdFromRaw(final byte[] bs, final int p) { + public void setObjectIdFromRaw(byte[] bs, int p) { final int n = Constants.OBJECT_ID_LENGTH; System.arraycopy(bs, p, idBuffer(), idOffset(), n); } @@ -704,7 +704,7 @@ public class DirCacheEntry { * @param src * the entry to copy ObjectId and meta fields from. */ - public void copyMetaData(final DirCacheEntry src) { + public void copyMetaData(DirCacheEntry src) { copyMetaData(src, false); } @@ -719,7 +719,7 @@ public class DirCacheEntry { * @param keepStage * if true, the stage attribute will not be copied */ - void copyMetaData(final DirCacheEntry src, boolean keepStage) { + void copyMetaData(DirCacheEntry src, boolean keepStage) { int origflags = NB.decodeUInt16(info, infoOffset + P_FLAGS); int newflags = NB.decodeUInt16(src.info, src.infoOffset + P_FLAGS); System.arraycopy(src.info, src.infoOffset, info, infoOffset, INFO_LEN); @@ -741,14 +741,14 @@ public class DirCacheEntry { return (info[infoOffset + P_FLAGS] & EXTENDED) != 0; } - private long decodeTS(final int pIdx) { + private long decodeTS(int pIdx) { final int base = infoOffset + pIdx; final int sec = NB.decodeInt32(info, base); final int ms = NB.decodeInt32(info, base + 4) / 1000000; return 1000L * sec + ms; } - private void encodeTS(final int pIdx, final long when) { + private void encodeTS(int pIdx, long when) { final int base = infoOffset + pIdx; NB.encodeInt32(info, base, (int) (when / 1000)); NB.encodeInt32(info, base + 4, ((int) (when % 1000)) * 1000000); @@ -771,7 +771,7 @@ public class DirCacheEntry { } } - static String toString(final byte[] path) { + static String toString(byte[] path) { return Constants.CHARSET.decode(ByteBuffer.wrap(path)).toString(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java index d768216db6..19c916f810 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheIterator.java @@ -114,7 +114,7 @@ public class DirCacheIterator extends AbstractTreeIterator { * @param dc * the cache to walk. It must be already loaded into memory. */ - public DirCacheIterator(final DirCache dc) { + public DirCacheIterator(DirCache dc) { cache = dc; tree = dc.getCacheTree(true); treeStart = 0; @@ -124,7 +124,7 @@ public class DirCacheIterator extends AbstractTreeIterator { parseEntry(); } - DirCacheIterator(final DirCacheIterator p, final DirCacheTree dct) { + DirCacheIterator(DirCacheIterator p, DirCacheTree dct) { super(p, p.path, p.pathLen + 1); cache = p.cache; tree = dct; @@ -137,7 +137,7 @@ public class DirCacheIterator extends AbstractTreeIterator { /** {@inheritDoc} */ @Override - public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) + public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException { if (currentSubtree == null) throw new IncorrectObjectTypeException(getEntryObjectId(), diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java index dc825d4dc7..b605f3ca8e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java @@ -82,7 +82,7 @@ public class DirCacheTree { private static final Comparator<DirCacheTree> TREE_CMP = new Comparator<DirCacheTree>() { @Override - public int compare(final DirCacheTree o1, final DirCacheTree o2) { + public int compare(DirCacheTree o1, DirCacheTree o2) { final byte[] a = o1.encodedName; final byte[] b = o2.encodedName; final int aLen = a.length; @@ -185,7 +185,7 @@ public class DirCacheTree { childCnt = subcnt; } - void write(final byte[] tmp, final OutputStream os) throws IOException { + void write(byte[] tmp, OutputStream os) throws IOException { int ptr = tmp.length; tmp[--ptr] = '\n'; ptr = RawParseUtils.formatBase10(tmp, ptr, childCnt); @@ -248,7 +248,7 @@ public class DirCacheTree { * index of the child to obtain. * @return the child tree. */ - public DirCacheTree getChild(final int i) { + public DirCacheTree getChild(int i) { return children[i]; } @@ -389,7 +389,7 @@ public class DirCacheTree { return size; } - private void appendName(final StringBuilder r) { + private void appendName(StringBuilder r) { if (parent != null) { parent.appendName(r); r.append(getNameString()); @@ -404,7 +404,7 @@ public class DirCacheTree { return encodedName.length; } - final boolean contains(final byte[] a, int aOff, final int aLen) { + final boolean contains(byte[] a, int aOff, int aLen) { final byte[] e = encodedName; final int eLen = e.length; for (int eOff = 0; eOff < eLen && aOff < aLen; eOff++, aOff++) @@ -503,7 +503,7 @@ public class DirCacheTree { removeChild(childCnt - 1); } - private void insertChild(final int stIdx, final DirCacheTree st) { + private void insertChild(int stIdx, DirCacheTree st) { final DirCacheTree[] c = children; if (childCnt + 1 <= c.length) { if (stIdx < childCnt) @@ -524,14 +524,14 @@ public class DirCacheTree { childCnt++; } - private void removeChild(final int stIdx) { + private void removeChild(int stIdx) { final int n = --childCnt; if (stIdx < n) System.arraycopy(children, stIdx + 1, children, stIdx, n - stIdx); children[n] = null; } - static boolean peq(final byte[] a, final byte[] b, int aLen) { + static boolean peq(byte[] a, byte[] b, int aLen) { if (b.length < aLen) return false; for (aLen--; aLen >= 0; aLen--) @@ -540,7 +540,7 @@ public class DirCacheTree { return true; } - private static int namecmp(final byte[] a, int aPos, final DirCacheTree ct) { + private static int namecmp(byte[] a, int aPos, DirCacheTree ct) { if (ct == null) return -1; final byte[] b = ct.encodedName; @@ -557,7 +557,7 @@ public class DirCacheTree { return aLen - bLen; } - private static int slash(final byte[] a, int aPos) { + private static int slash(byte[] a, int aPos) { final int aLen = a.length; for (; aPos < aLen; aPos++) if (a[aPos] == '/') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/CompoundException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/CompoundException.java index 62ff990883..1df70e3501 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/CompoundException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/CompoundException.java @@ -56,10 +56,10 @@ import org.eclipse.jgit.internal.JGitText; public class CompoundException extends Exception { private static final long serialVersionUID = 1L; - private static String format(final Collection<Throwable> causes) { + private static String format(Collection<Throwable> causes) { final StringBuilder msg = new StringBuilder(); msg.append(JGitText.get().failureDueToOneOfTheFollowing); - for (final Throwable c : causes) { + for (Throwable c : causes) { msg.append(" "); //$NON-NLS-1$ msg.append(c.getMessage()); msg.append("\n"); //$NON-NLS-1$ @@ -75,7 +75,7 @@ public class CompoundException extends Exception { * @param why * Two or more exceptions that may have been the problem. */ - public CompoundException(final Collection<Throwable> why) { + public CompoundException(Collection<Throwable> why) { super(format(why)); causeList = Collections.unmodifiableList(new ArrayList<>(why)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/ConfigInvalidException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/ConfigInvalidException.java index a7e1d02b49..24f43cfcd5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/ConfigInvalidException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/ConfigInvalidException.java @@ -55,7 +55,7 @@ public class ConfigInvalidException extends Exception { * @param message * why the configuration is invalid. */ - public ConfigInvalidException(final String message) { + public ConfigInvalidException(String message) { super(message); } @@ -67,7 +67,7 @@ public class ConfigInvalidException extends Exception { * @param cause * root cause of the error. */ - public ConfigInvalidException(final String message, final Throwable cause) { + public ConfigInvalidException(String message, Throwable cause) { super(message, cause); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/EntryExistsException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/EntryExistsException.java index 8dd0d539fc..b97d237b28 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/EntryExistsException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/EntryExistsException.java @@ -61,7 +61,7 @@ public class EntryExistsException extends IOException { * * @param name workdir relative file name */ - public EntryExistsException(final String name) { + public EntryExistsException(String name) { super(MessageFormat.format(JGitText.get().treeEntryAlreadyExists, name)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java index a6471217e1..785cb95bf2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java @@ -56,7 +56,7 @@ public class IllegalTodoFileModification extends Exception { * @param msg * error message */ - public IllegalTodoFileModification(final String msg) { + public IllegalTodoFileModification(String msg) { super(msg); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IncorrectObjectTypeException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IncorrectObjectTypeException.java index 7ba3a006d6..5abd0c347b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IncorrectObjectTypeException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IncorrectObjectTypeException.java @@ -70,7 +70,7 @@ public class IncorrectObjectTypeException extends IOException { * @param id SHA-1 * @param type object type */ - public IncorrectObjectTypeException(final ObjectId id, final String type) { + public IncorrectObjectTypeException(ObjectId id, String type) { super(MessageFormat.format(JGitText.get().objectIsNotA, id.name(), type)); } @@ -82,7 +82,7 @@ public class IncorrectObjectTypeException extends IOException { * @param id SHA-1 * @param type object type */ - public IncorrectObjectTypeException(final ObjectId id, final int type) { + public IncorrectObjectTypeException(ObjectId id, int type) { this(id, Constants.typeString(type)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexReadException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexReadException.java index 70f650dde6..e07d308207 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexReadException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexReadException.java @@ -63,7 +63,7 @@ public class IndexReadException extends IOException { * @param s * message */ - public IndexReadException(final String s) { + public IndexReadException(String s) { super(s); } @@ -75,7 +75,7 @@ public class IndexReadException extends IOException { * @param cause * root cause exception */ - public IndexReadException(final String s, final Throwable cause) { + public IndexReadException(String s, Throwable cause) { super(s); initCause(cause); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexWriteException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexWriteException.java index de19c06683..34fd7a8942 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexWriteException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IndexWriteException.java @@ -60,7 +60,7 @@ public class IndexWriteException extends IOException { * * @param s message */ - public IndexWriteException(final String s) { + public IndexWriteException(String s) { super(s); } @@ -70,7 +70,7 @@ public class IndexWriteException extends IOException { * @param s message * @param cause root cause exception */ - public IndexWriteException(final String s, final Throwable cause) { + public IndexWriteException(String s, Throwable cause) { super(s); initCause(cause); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java index 09bb4a914f..b37d20d58f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingBundlePrerequisiteException.java @@ -56,10 +56,10 @@ import org.eclipse.jgit.transport.URIish; public class MissingBundlePrerequisiteException extends TransportException { private static final long serialVersionUID = 1L; - private static String format(final Map<ObjectId, String> missingCommits) { + private static String format(Map<ObjectId, String> missingCommits) { final StringBuilder r = new StringBuilder(); r.append(JGitText.get().missingPrerequisiteCommits); - for (final Map.Entry<ObjectId, String> e : missingCommits.entrySet()) { + for (Map.Entry<ObjectId, String> e : missingCommits.entrySet()) { r.append("\n "); //$NON-NLS-1$ r.append(e.getKey().name()); if (e.getValue() != null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingObjectException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingObjectException.java index f6aa092db4..c6c47f9591 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingObjectException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/MissingObjectException.java @@ -69,7 +69,7 @@ public class MissingObjectException extends IOException { * @param id SHA-1 * @param type object type */ - public MissingObjectException(final ObjectId id, final String type) { + public MissingObjectException(ObjectId id, String type) { super(MessageFormat.format(JGitText.get().missingObject, type, id.name())); missing = id.copy(); } @@ -81,7 +81,7 @@ public class MissingObjectException extends IOException { * @param id SHA-1 * @param type object type */ - public MissingObjectException(final ObjectId id, final int type) { + public MissingObjectException(ObjectId id, int type) { this(id, Constants.typeString(type)); } @@ -94,7 +94,7 @@ public class MissingObjectException extends IOException { * @param type * object type */ - public MissingObjectException(final AbbreviatedObjectId id, final int type) { + public MissingObjectException(AbbreviatedObjectId id, int type) { super(MessageFormat.format(JGitText.get().missingObject, Constants .typeString(type), id.name())); missing = null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoPackSignatureException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoPackSignatureException.java index 28e9788974..8c2e872973 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoPackSignatureException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoPackSignatureException.java @@ -60,7 +60,7 @@ public class NoPackSignatureException extends IOException { * @param why * description of the type of error. */ - public NoPackSignatureException(final String why) { + public NoPackSignatureException(String why) { super(why); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoRemoteRepositoryException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoRemoteRepositoryException.java index fe073d5648..524968d524 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoRemoteRepositoryException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/NoRemoteRepositoryException.java @@ -59,7 +59,7 @@ public class NoRemoteRepositoryException extends TransportException { * @param s * message */ - public NoRemoteRepositoryException(final URIish uri, final String s) { + public NoRemoteRepositoryException(URIish uri, String s) { super(uri, s); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/NotSupportedException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/NotSupportedException.java index 124680eccb..114e662fb4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/NotSupportedException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/NotSupportedException.java @@ -58,7 +58,7 @@ public class NotSupportedException extends IOException { * * @param s message describing the issue */ - public NotSupportedException(final String s) { + public NotSupportedException(String s) { super(s); } @@ -70,7 +70,7 @@ public class NotSupportedException extends IOException { * @param why * a lower level implementation specific issue. */ - public NotSupportedException(final String s, final Throwable why) { + public NotSupportedException(String s, Throwable why) { super(s); initCause(why); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/ObjectWritingException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/ObjectWritingException.java index 8af1991b14..bbee42f18f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/ObjectWritingException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/ObjectWritingException.java @@ -58,7 +58,7 @@ public class ObjectWritingException extends IOException { * * @param s message */ - public ObjectWritingException(final String s) { + public ObjectWritingException(String s) { super(s); } @@ -68,7 +68,7 @@ public class ObjectWritingException extends IOException { * @param s message * @param cause root cause exception */ - public ObjectWritingException(final String s, final Throwable cause) { + public ObjectWritingException(String s, Throwable cause) { super(s); initCause(cause); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackInvalidException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackInvalidException.java index 9886e15dda..a83de06262 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackInvalidException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackInvalidException.java @@ -61,7 +61,7 @@ public class PackInvalidException extends IOException { * @param path * path of the invalid pack file. */ - public PackInvalidException(final File path) { + public PackInvalidException(File path) { this(path.getAbsolutePath()); } @@ -71,7 +71,7 @@ public class PackInvalidException extends IOException { * @param path * path of the invalid pack file. */ - public PackInvalidException(final String path) { + public PackInvalidException(String path) { super(MessageFormat.format(JGitText.get().packFileInvalid, path)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackMismatchException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackMismatchException.java index 5b9a4b93b9..ea1e65b221 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackMismatchException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackMismatchException.java @@ -57,7 +57,7 @@ public class PackMismatchException extends IOException { * @param why * description of the type of error. */ - public PackMismatchException(final String why) { + public PackMismatchException(String why) { super(why); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackProtocolException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackProtocolException.java index 44bc16492d..dd13740f1e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackProtocolException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/PackProtocolException.java @@ -62,7 +62,7 @@ public class PackProtocolException extends TransportException { * @param s * message, which may be shown to an end-user. */ - public PackProtocolException(final URIish uri, final String s) { + public PackProtocolException(URIish uri, String s) { super(uri + ": " + s); //$NON-NLS-1$ } @@ -88,7 +88,7 @@ public class PackProtocolException extends TransportException { * @param s * message, which may be shown to an end-user. */ - public PackProtocolException(final String s) { + public PackProtocolException(String s) { super(s); } @@ -100,7 +100,7 @@ public class PackProtocolException extends TransportException { * @param cause * root cause exception */ - public PackProtocolException(final String s, final Throwable cause) { + public PackProtocolException(String s, Throwable cause) { super(s); initCause(cause); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java index aabb46ad42..04fd8ea6d5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/RepositoryNotFoundException.java @@ -60,7 +60,7 @@ public class RepositoryNotFoundException extends TransportException { * @param location * description of the repository not found, usually file path. */ - public RepositoryNotFoundException(final File location) { + public RepositoryNotFoundException(File location) { this(location.getPath()); } @@ -72,7 +72,7 @@ public class RepositoryNotFoundException extends TransportException { * @param why * why the repository does not exist. */ - public RepositoryNotFoundException(final File location, Throwable why) { + public RepositoryNotFoundException(File location, Throwable why) { this(location.getPath(), why); } @@ -82,7 +82,7 @@ public class RepositoryNotFoundException extends TransportException { * @param location * description of the repository not found, usually file path. */ - public RepositoryNotFoundException(final String location) { + public RepositoryNotFoundException(String location) { super(message(location)); } @@ -98,7 +98,7 @@ public class RepositoryNotFoundException extends TransportException { super(message(location), why); } - private static String message(final String location) { + private static String message(String location) { return MessageFormat.format(JGitText.get().repositoryNotFound, location); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/RevWalkException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/RevWalkException.java index 82654e8bd0..f6852b59ff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/RevWalkException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/RevWalkException.java @@ -65,7 +65,7 @@ public class RevWalkException extends RuntimeException { * @param cause * the checked exception that describes why the walk failed. */ - public RevWalkException(final Throwable cause) { + public RevWalkException(Throwable cause) { super(JGitText.get().walkFailure, cause); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/StoredObjectRepresentationNotAvailableException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/StoredObjectRepresentationNotAvailableException.java index 8fa14c7d38..611fd66aab 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/StoredObjectRepresentationNotAvailableException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/StoredObjectRepresentationNotAvailableException.java @@ -56,21 +56,6 @@ public class StoredObjectRepresentationNotAvailableException extends Exception { * * @param otp * the object whose current representation is no longer present. - * @deprecated use - * {@link #StoredObjectRepresentationNotAvailableException(ObjectToPack, Throwable)} - * instead. - * @since 3.0 - */ - @Deprecated - public StoredObjectRepresentationNotAvailableException(ObjectToPack otp) { - // Do nothing. - } - - /** - * Construct an error for an object. - * - * @param otp - * the object whose current representation is no longer present. * @param cause * cause * @since 4.10 diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/SymlinksNotSupportedException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/SymlinksNotSupportedException.java index 60d7aa098f..dc59c8c321 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/SymlinksNotSupportedException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/SymlinksNotSupportedException.java @@ -58,7 +58,7 @@ public class SymlinksNotSupportedException extends IOException { * * @param s name of link in tree or workdir */ - public SymlinksNotSupportedException(final String s) { + public SymlinksNotSupportedException(String s) { super(s); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/TransportException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/TransportException.java index 86dea8284f..5fecf0ea53 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/TransportException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/TransportException.java @@ -64,7 +64,7 @@ public class TransportException extends IOException { * @param s * message */ - public TransportException(final URIish uri, final String s) { + public TransportException(URIish uri, String s) { super(uri.setPass(null) + ": " + s); //$NON-NLS-1$ } @@ -90,7 +90,7 @@ public class TransportException extends IOException { * @param s * message */ - public TransportException(final String s) { + public TransportException(String s) { super(s); } @@ -102,7 +102,7 @@ public class TransportException extends IOException { * @param cause * root cause exception */ - public TransportException(final String s, final Throwable cause) { + public TransportException(String s, Throwable cause) { super(s); initCause(cause); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnmergedPathException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnmergedPathException.java index 4fc534b944..6de9153c0e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnmergedPathException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnmergedPathException.java @@ -63,7 +63,7 @@ public class UnmergedPathException extends IOException { * @param dce * the first non-zero stage of the unmerged path. */ - public UnmergedPathException(final DirCacheEntry dce) { + public UnmergedPathException(DirCacheEntry dce) { super(MessageFormat.format(JGitText.get().unmergedPath, dce.getPathString())); entry = dce; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedCredentialItem.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedCredentialItem.java index 88c2ef6238..9bab68797c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedCredentialItem.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedCredentialItem.java @@ -62,7 +62,7 @@ public class UnsupportedCredentialItem extends RuntimeException { * @param s * message */ - public UnsupportedCredentialItem(final URIish uri, final String s) { + public UnsupportedCredentialItem(URIish uri, String s) { super(uri.setPass(null) + ": " + s); //$NON-NLS-1$ } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackIndexVersionException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackIndexVersionException.java index 0b7ccf5777..0a4fef11f0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackIndexVersionException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackIndexVersionException.java @@ -62,7 +62,7 @@ public class UnsupportedPackIndexVersionException extends IOException { * @param version * pack index version */ - public UnsupportedPackIndexVersionException(final int version) { + public UnsupportedPackIndexVersionException(int version) { super(MessageFormat.format(JGitText.get().unsupportedPackIndexVersion, Integer.valueOf(version))); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackVersionException.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackVersionException.java index 23611867be..cbf8f3a6da 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackVersionException.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/UnsupportedPackVersionException.java @@ -62,7 +62,7 @@ public class UnsupportedPackVersionException extends IOException { * @param version * pack version */ - public UnsupportedPackVersionException(final long version) { + public UnsupportedPackVersionException(long version) { super(MessageFormat.format(JGitText.get().unsupportedPackVersion, Long.valueOf(version))); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/events/IndexChangedEvent.java b/org.eclipse.jgit/src/org/eclipse/jgit/events/IndexChangedEvent.java index 647ec8a20c..dcce86a33c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/events/IndexChangedEvent.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/events/IndexChangedEvent.java @@ -47,6 +47,28 @@ package org.eclipse.jgit.events; * Describes a change to one or more paths in the index file. */ public class IndexChangedEvent extends RepositoryEvent<IndexChangedListener> { + private boolean internal; + + /** + * Notify that the index changed + * + * @param internal + * {@code true} if the index was changed by the same + * JGit process + * @since 5.0 + */ + public IndexChangedEvent(boolean internal) { + this.internal = internal; + } + + /** + * @return {@code true} if the index was changed by the same JGit process + * @since 5.0 + */ + public boolean isInternal() { + return internal; + } + /** {@inheritDoc} */ @Override public Class<IndexChangedListener> getListenerType() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/CharacterHead.java b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/CharacterHead.java index 98aee0eef2..7039c3d618 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/CharacterHead.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/CharacterHead.java @@ -53,14 +53,14 @@ final class CharacterHead extends AbstractHead { * @param expectedCharacter * expected {@code char} */ - protected CharacterHead(final char expectedCharacter) { + protected CharacterHead(char expectedCharacter) { super(false); this.expectedCharacter = expectedCharacter; } /** {@inheritDoc} */ @Override - protected final boolean matches(final char c) { + protected final boolean matches(char c) { return c == expectedCharacter; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java index 56630395b2..bfcc580ba4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/FileNameMatcher.java @@ -105,7 +105,7 @@ public class FileNameMatcher { * @param headsStartValue * must be a list which will never be modified. */ - private FileNameMatcher(final List<Head> headsStartValue) { + private FileNameMatcher(List<Head> headsStartValue) { this(headsStartValue, headsStartValue); } @@ -315,7 +315,7 @@ public class FileNameMatcher { * @param c new character to append * @return true to continue, false if the matcher can stop appending */ - private boolean extendStringToMatchByOneCharacter(final char c) { + private boolean extendStringToMatchByOneCharacter(char c) { final List<Head> newHeads = listForLocalUseage; newHeads.clear(); List<Head> lastAddedHeads = null; @@ -357,7 +357,7 @@ public class FileNameMatcher { * extends the string which is matched against the patterns of * this class. */ - public void append(final String stringToMatch) { + public void append(String stringToMatch) { for (int i = 0; i < stringToMatch.length(); i++) { final char c = stringToMatch.charAt(i); if (!extendStringToMatchByOneCharacter(c)) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/GroupHead.java b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/GroupHead.java index 965d90085f..1dc5931ca2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/GroupHead.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/GroupHead.java @@ -61,7 +61,7 @@ final class GroupHead extends AbstractHead { private final boolean inverse; - GroupHead(String pattern, final String wholePattern) + GroupHead(String pattern, String wholePattern) throws InvalidPatternException { super(false); this.characterClasses = new ArrayList<>(); @@ -132,7 +132,7 @@ final class GroupHead extends AbstractHead { /** {@inheritDoc} */ @Override - protected final boolean matches(final char c) { + protected final boolean matches(char c) { for (CharacterPattern pattern : characterClasses) { if (pattern.matches(c)) { return !inverse; @@ -214,7 +214,7 @@ final class GroupHead extends AbstractHead { private static final class OneCharacterPattern implements CharacterPattern { private char expectedCharacter; - OneCharacterPattern(final char c) { + OneCharacterPattern(char c) { this.expectedCharacter = c; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/RestrictedWildCardHead.java b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/RestrictedWildCardHead.java index c132e28156..45e6ed2947 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/RestrictedWildCardHead.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/RestrictedWildCardHead.java @@ -47,14 +47,14 @@ package org.eclipse.jgit.fnmatch; final class RestrictedWildCardHead extends AbstractHead { private final char excludedCharacter; - RestrictedWildCardHead(final char excludedCharacter, final boolean star) { + RestrictedWildCardHead(char excludedCharacter, boolean star) { super(star); this.excludedCharacter = excludedCharacter; } /** {@inheritDoc} */ @Override - protected final boolean matches(final char c) { + protected final boolean matches(char c) { return c != excludedCharacter; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/WildCardHead.java b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/WildCardHead.java index c806e23134..07362aa967 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/WildCardHead.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/fnmatch/WildCardHead.java @@ -51,7 +51,7 @@ final class WildCardHead extends AbstractHead { /** {@inheritDoc} */ @Override - protected final boolean matches(final char c) { + protected final boolean matches(char c) { return true; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java index 8b8df87978..80fd3cf1a4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java @@ -413,7 +413,7 @@ public class RepoCommand extends GitCommand<RevCommit> { * a {@link org.eclipse.jgit.lib.ProgressMonitor} * @return this command */ - public RepoCommand setProgressMonitor(final ProgressMonitor monitor) { + public RepoCommand setProgressMonitor(ProgressMonitor monitor) { this.monitor = monitor; return this; } @@ -448,7 +448,7 @@ public class RepoCommand extends GitCommand<RevCommit> { * the author's {@link org.eclipse.jgit.lib.PersonIdent} * @return this command */ - public RepoCommand setAuthor(final PersonIdent author) { + public RepoCommand setAuthor(PersonIdent author) { this.author = author; return this; } @@ -463,7 +463,7 @@ public class RepoCommand extends GitCommand<RevCommit> { * object. * @return this command */ - public RepoCommand setRemoteReader(final RemoteReader callback) { + public RepoCommand setRemoteReader(RemoteReader callback) { this.callback = callback; return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java index e827612d23..7ba83c7cbf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java @@ -131,18 +131,10 @@ public class RepoProject implements Comparable<RepoProject> { File srcFile = new File(repo.getWorkTree(), path + "/" + src); //$NON-NLS-1$ File destFile = new File(repo.getWorkTree(), dest); - FileInputStream input = new FileInputStream(srcFile); - try { - FileOutputStream output = new FileOutputStream(destFile); - try { - FileChannel channel = input.getChannel(); - output.getChannel().transferFrom( - channel, 0, channel.size()); - } finally { - output.close(); - } - } finally { - input.close(); + try (FileInputStream input = new FileInputStream(srcFile); + FileOutputStream output = new FileOutputStream(destFile)) { + FileChannel channel = input.getChannel(); + output.getChannel().transferFrom(channel, 0, channel.size()); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java index ad43e2ca83..8a61d1b0b1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.hooks; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -158,7 +158,7 @@ abstract class GitHook<T> implements Callable<T> { PrintStream hookErrRedirect = null; try { hookErrRedirect = new PrintStream(errorByteArray, false, - UTF_8.name()); + CHARSET.name()); } catch (UnsupportedEncodingException e) { // UTF-8 is guaranteed to be available } @@ -167,7 +167,7 @@ abstract class GitHook<T> implements Callable<T> { hookErrRedirect, getStdinArgs()); if (result.isExecutedWithError()) { throw new AbortedByHookException( - new String(errorByteArray.toByteArray(), UTF_8), + new String(errorByteArray.toByteArray(), CHARSET), getHookName(), result.getExitCode()); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/Hooks.java b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/Hooks.java index 79395ed23f..b801d6872b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/Hooks.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/Hooks.java @@ -115,7 +115,11 @@ public class Hooks { outputStream); if (hook != null) { if (hook.isNativeHookPresent()) { - throw new IllegalStateException(MessageFormat + PrintStream ps = outputStream; + if (ps == null) { + ps = System.out; + } + ps.println(MessageFormat .format(JGitText.get().lfsHookConflict, repo)); } return hook; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java index 1224df4226..d570fde36f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java @@ -163,35 +163,6 @@ public class IgnoreNode { * (uses '/' and not '\'). * @param isDirectory * true if the target item is a directory. - * @param negateFirstMatch - * true if the first match should be negated - * @deprecated negateFirstMatch is not honored anymore - * @return status of the path. - * @since 3.6 - */ - @Deprecated - public MatchResult isIgnored(String entryPath, boolean isDirectory, - boolean negateFirstMatch) { - final Boolean result = checkIgnored(entryPath, isDirectory); - if (result == null) { - return negateFirstMatch - ? MatchResult.CHECK_PARENT_NEGATE_FIRST_MATCH - : MatchResult.CHECK_PARENT; - } - - return result.booleanValue() ? MatchResult.IGNORED - : MatchResult.NOT_IGNORED; - } - - /** - * Determine if an entry path matches an ignore rule. - * - * @param entryPath - * the path to test. The path must be relative to this ignore - * node's own repository path, and in repository path format - * (uses '/' and not '\'). - * @param isDirectory - * true if the target item is a directory. * @return Boolean.TRUE, if the entry is ignored; Boolean.FALSE, if the * entry is forced to be not ignored (negated match); or null, if * undetermined diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 4e947f8f01..a52fab926a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -286,6 +286,8 @@ public class JGitText extends TranslationBundle { /***/ public String credentialUsername; /***/ public String daemonAlreadyRunning; /***/ public String daysAgo; + /***/ public String deepenNotWithDeepen; + /***/ public String deepenSinceWithDeepen; /***/ public String deleteBranchUnexpectedResult; /***/ public String deleteFileFailed; /***/ public String deleteRequiresZeroNewId; @@ -370,6 +372,7 @@ public class JGitText extends TranslationBundle { /***/ public String fileModeNotSetForPath; /***/ public String filterExecutionFailed; /***/ public String filterExecutionFailedRc; + /***/ public String filterRequiresCapability; /***/ public String findingGarbage; /***/ public String flagIsDisposed; /***/ public String flagNotFromThis; @@ -421,6 +424,7 @@ public class JGitText extends TranslationBundle { /***/ public String invalidDepth; /***/ public String invalidEncryption; /***/ public String invalidExpandWildcard; + /***/ public String invalidFilter; /***/ public String invalidGitdirRef; /***/ public String invalidGitType; /***/ public String invalidId; @@ -454,6 +458,7 @@ public class JGitText extends TranslationBundle { /***/ public String invalidSystemProperty; /***/ public String invalidTagOption; /***/ public String invalidTimeout; + /***/ public String invalidTimestamp; /***/ public String invalidTimeUnitValue2; /***/ public String invalidTimeUnitValue3; /***/ public String invalidTreeZeroLengthName; @@ -686,6 +691,7 @@ public class JGitText extends TranslationBundle { /***/ public String sourceRefDoesntResolveToAnyObject; /***/ public String sourceRefNotSpecifiedForRefspec; /***/ public String squashCommitNotUpdatingHEAD; + /***/ public String sshCommandFailed; /***/ public String sshUserNameError; /***/ public String sslFailureExceptionMessage; /***/ public String sslFailureInfo; @@ -728,6 +734,7 @@ public class JGitText extends TranslationBundle { /***/ public String timeIsUncertain; /***/ public String timerAlreadyTerminated; /***/ public String tooManyCommands; + /***/ public String tooManyFilters; /***/ public String tooManyIncludeRecursions; /***/ public String topologicalSortRequired; /***/ public String transportExceptionBadRef; @@ -768,6 +775,7 @@ public class JGitText extends TranslationBundle { /***/ public String unexpectedEofInPack; /***/ public String unexpectedHunkTrailer; /***/ public String unexpectedOddResult; + /***/ public String unexpectedPacketLine; /***/ public String unexpectedRefReport; /***/ public String unexpectedReportLine; /***/ public String unexpectedReportLine2; @@ -782,6 +790,7 @@ public class JGitText extends TranslationBundle { /***/ public String unknownObjectType2; /***/ public String unknownRepositoryFormat; /***/ public String unknownRepositoryFormat2; + /***/ public String unknownTransportCommand; /***/ public String unknownZlibError; /***/ public String unmergedPath; /***/ public String unmergedPaths; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/KetchSystem.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/KetchSystem.java index 1908d6c98a..d1d4f67d86 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/KetchSystem.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/KetchSystem.java @@ -260,7 +260,7 @@ public class KetchSystem { * @throws java.net.URISyntaxException * a follower configuration contains an unsupported URI. */ - public KetchLeader createLeader(final Repository repo) + public KetchLeader createLeader(Repository repo) throws URISyntaxException { KetchLeader leader = new KetchLeader(this) { @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/LocalReplica.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/LocalReplica.java index 9c37a90cee..7ddde6337f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/LocalReplica.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/LocalReplica.java @@ -122,7 +122,7 @@ public class LocalReplica extends KetchReplica { /** {@inheritDoc} */ @Override - protected void startPush(final ReplicaPushRequest req) { + protected void startPush(ReplicaPushRequest req) { getSystem().getExecutor().execute(new Runnable() { @Override public void run() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/RemoteGitReplica.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/RemoteGitReplica.java index 674da1fc68..b61274ef4a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/RemoteGitReplica.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/RemoteGitReplica.java @@ -138,7 +138,7 @@ public class RemoteGitReplica extends KetchReplica { /** {@inheritDoc} */ @Override - protected void startPush(final ReplicaPushRequest req) { + protected void startPush(ReplicaPushRequest req) { getSystem().getExecutor().execute(new Runnable() { @Override public void run() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java index 14dc80fc97..46879529b5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCache.java @@ -181,7 +181,7 @@ public final class DfsBlockCache { private Ref clockHand; @SuppressWarnings("unchecked") - private DfsBlockCache(final DfsBlockCacheConfig cfg) { + private DfsBlockCache(DfsBlockCacheConfig cfg) { tableSize = tableSize(cfg); if (tableSize < 1) throw new IllegalArgumentException(JGitText.get().tSizeMustBeGreaterOrEqual1); @@ -330,7 +330,7 @@ public final class DfsBlockCache { return blockSize; } - private static int tableSize(final DfsBlockCacheConfig cfg) { + private static int tableSize(DfsBlockCacheConfig cfg) { final int wsz = cfg.getBlockSize(); final long limit = cfg.getBlockLimit(); if (wsz <= 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java index cd7901b357..dd7cb89c96 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheConfig.java @@ -106,7 +106,7 @@ public class DfsBlockCacheConfig { * pack file data; must be positive. * @return {@code this} */ - public DfsBlockCacheConfig setBlockLimit(final long newLimit) { + public DfsBlockCacheConfig setBlockLimit(long newLimit) { if (newLimit <= 0) { throw new IllegalArgumentException(MessageFormat.format( JGitText.get().blockLimitNotPositive, @@ -135,7 +135,7 @@ public class DfsBlockCacheConfig { * The value must be a power of 2. * @return {@code this} */ - public DfsBlockCacheConfig setBlockSize(final int newSize) { + public DfsBlockCacheConfig setBlockSize(int newSize) { int size = Math.max(512, newSize); if ((size & (size - 1)) != 0) { throw new IllegalArgumentException( @@ -206,7 +206,7 @@ public class DfsBlockCacheConfig { * configuration to read properties from. * @return {@code this} */ - public DfsBlockCacheConfig fromConfig(final Config rc) { + public DfsBlockCacheConfig fromConfig(Config rc) { long cfgBlockLimit = rc.getLong( CONFIG_CORE_SECTION, CONFIG_DFS_SECTION, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java index 69989a451e..ca11fb9265 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollector.java @@ -403,7 +403,7 @@ public class DfsGarbageCollector { } private Collection<Ref> getAllRefs() throws IOException { - Collection<Ref> refs = refdb.getRefs(RefDatabase.ALL).values(); + Collection<Ref> refs = refdb.getRefs(); List<Ref> addl = refdb.getAdditionalRefs(); if (!addl.isEmpty()) { List<Ref> all = new ArrayList<>(refs.size() + addl.size()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java index eb0a527c5f..0d9e2c1d79 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java @@ -68,6 +68,7 @@ import java.util.zip.DeflaterOutputStream; import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.LargeObjectException; @@ -309,6 +310,15 @@ public class DfsInserter extends ObjectInserter { Collections.sort(objectList); } + @Nullable + private TemporaryBuffer.Heap maybeGetTemporaryBuffer( + List<PackedObjectInfo> list) { + if (list.size() <= 58000) { + return new TemporaryBuffer.Heap(2 << 20); + } + return null; + } + PackIndex writePackIndex(DfsPackDescription pack, byte[] packHash, List<PackedObjectInfo> list) throws IOException { pack.setIndexVersion(INDEX_VERSION); @@ -317,27 +327,20 @@ public class DfsInserter extends ObjectInserter { // If there are less than 58,000 objects, the entire index fits in under // 2 MiB. Callers will probably need the index immediately, so buffer // the index in process and load from the buffer. - TemporaryBuffer.Heap buf = null; PackIndex packIndex = null; - if (list.size() <= 58000) { - buf = new TemporaryBuffer.Heap(2 << 20); - index(buf, packHash, list); - packIndex = PackIndex.read(buf.openInputStream()); - } - - try (DfsOutputStream os = db.writeFile(pack, INDEX)) { - CountingOutputStream cnt = new CountingOutputStream(os); - if (buf != null) + try (TemporaryBuffer.Heap buf = maybeGetTemporaryBuffer(list); + DfsOutputStream os = db.writeFile(pack, INDEX); + CountingOutputStream cnt = new CountingOutputStream(os)) { + if (buf != null) { + index(buf, packHash, list); + packIndex = PackIndex.read(buf.openInputStream()); buf.writeTo(cnt, null); - else + } else { index(cnt, packHash, list); + } pack.addFileExt(INDEX); pack.setBlockSize(INDEX, os.blockSize()); pack.setFileSize(INDEX, cnt.getCount()); - } finally { - if (buf != null) { - buf.close(); - } } return packIndex; } @@ -403,7 +406,7 @@ public class DfsInserter extends ObjectInserter { } @Override - public void write(final int b) throws IOException { + public void write(int b) throws IOException { hdrBuf[0] = (byte) b; write(hdrBuf, 0, 1); } @@ -666,6 +669,7 @@ public class DfsInserter extends ObjectInserter { @Override public ObjectStream openStream() throws IOException { + @SuppressWarnings("resource") // Explicitly closed below final DfsReader ctx = db.newReader(); if (srcPack != packKey) { try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java index 42b1a479d8..ca54ee22ea 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java @@ -497,7 +497,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase { } while (!packList.compareAndSet(o, n)); } - PackList scanPacks(final PackList original) throws IOException { + PackList scanPacks(PackList original) throws IOException { PackList o, n; synchronized (packList) { do { @@ -546,7 +546,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase { } } - if (newPacks.isEmpty()) + if (newPacks.isEmpty() && newReftables.isEmpty()) return new PackListImpl(NO_PACKS.packs, NO_PACKS.reftables); if (!foundNew) { old.clearDirty(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjectToPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjectToPack.java index 3a04d70dbb..5f4dee2264 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjectToPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjectToPack.java @@ -60,7 +60,7 @@ class DfsObjectToPack extends ObjectToPack { /** Length of the data section of the object. */ long length; - DfsObjectToPack(AnyObjectId src, final int type) { + DfsObjectToPack(AnyObjectId src, int type) { super(src, type); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java index ab7633281c..b43b9b1780 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java @@ -268,8 +268,7 @@ public class DfsPackCompactor { pc.setReuseDeltas(true); pc.setReuseObjects(true); - PackWriter pw = new PackWriter(pc, ctx); - try { + try (PackWriter pw = new PackWriter(pc, ctx)) { pw.setDeltaBaseAsOffset(true); pw.setReuseDeltaCommits(false); @@ -285,8 +284,6 @@ public class DfsPackCompactor { writeIndex(objdb, outDesc, pw); PackStatistics stats = pw.getStatistics(); - pw.close(); - pw = null; outDesc.setPackStats(stats); newStats = stats; @@ -296,10 +293,6 @@ public class DfsPackCompactor { objdb.rollbackPack(Collections.singletonList(outDesc)); } } - } finally { - if (pw != null) { - pw.close(); - } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java index 7e360421ac..05b8f61a42 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java @@ -209,8 +209,7 @@ public final class DfsPackFile extends BlockBasedFile { try { ctx.stats.readIdx++; long start = System.nanoTime(); - ReadableChannel rc = ctx.db.openFile(desc, INDEX); - try { + try (ReadableChannel rc = ctx.db.openFile(desc, INDEX)) { InputStream in = Channels.newInputStream(rc); int wantSize = 8192; int bs = rc.blockSize(); @@ -221,7 +220,6 @@ public final class DfsPackFile extends BlockBasedFile { idx = PackIndex.read(new BufferedInputStream(in, bs)); ctx.stats.readIdxBytes += rc.position(); } finally { - rc.close(); ctx.stats.readIdxMicros += elapsedMicros(start); } } catch (EOFException e) { @@ -276,10 +274,9 @@ public final class DfsPackFile extends BlockBasedFile { long size; PackBitmapIndex idx; - try { - ctx.stats.readBitmap++; - long start = System.nanoTime(); - ReadableChannel rc = ctx.db.openFile(desc, BITMAP_INDEX); + ctx.stats.readBitmap++; + long start = System.nanoTime(); + try (ReadableChannel rc = ctx.db.openFile(desc, BITMAP_INDEX)) { try { InputStream in = Channels.newInputStream(rc); int wantSize = 8192; @@ -293,7 +290,6 @@ public final class DfsPackFile extends BlockBasedFile { in, idx(ctx), getReverseIdx(ctx)); } finally { size = rc.position(); - rc.close(); ctx.stats.readIdxBytes += size; ctx.stats.readIdxMicros += elapsedMicros(start); } @@ -443,6 +439,7 @@ public final class DfsPackFile extends BlockBasedFile { private void copyPackThroughCache(PackOutputStream out, DfsReader ctx) throws IOException { + @SuppressWarnings("resource") // Explicitly closed in finally block ReadableChannel rc = null; try { long position = 12; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderOptions.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderOptions.java index bf14d18e32..2ea5c39769 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderOptions.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsReaderOptions.java @@ -115,7 +115,7 @@ public class DfsReaderOptions { * {@link org.eclipse.jgit.lib.ObjectStream}. * @return {@code this} */ - public DfsReaderOptions setStreamFileThreshold(final int newLimit) { + public DfsReaderOptions setStreamFileThreshold(int newLimit) { streamFileThreshold = Math.max(0, newLimit); return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java index 197681658e..5169e929e4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsRepository.java @@ -133,7 +133,7 @@ public abstract class DfsRepository extends Repository { /** {@inheritDoc} */ @Override - public void notifyIndexChanged() { + public void notifyIndexChanged(boolean internal) { // Do not send notifications. // There is no index, as there is no working tree. } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java index 8793d83126..c11f696708 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.dfs; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.util.Arrays; @@ -67,7 +67,7 @@ public abstract class DfsStreamKey { */ public static DfsStreamKey of(DfsRepositoryDescription repo, String name, @Nullable PackExt ext) { - return new ByteArrayDfsStreamKey(repo, name.getBytes(UTF_8), ext); + return new ByteArrayDfsStreamKey(repo, name.getBytes(CHARSET), ext); } final int hash; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java index fa2c5291c6..37d8d1c01d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/LargePackedWholeObject.java @@ -104,31 +104,34 @@ final class LargePackedWholeObject extends ObjectLoader { /** {@inheritDoc} */ @Override public ObjectStream openStream() throws MissingObjectException, IOException { + PackInputStream packIn; + // ctx is closed by PackInputStream, or explicitly in the finally block + @SuppressWarnings("resource") DfsReader ctx = db.newReader(); - InputStream in; try { - in = new PackInputStream(pack, objectOffset + headerLength, ctx); - } catch (IOException packGone) { - // If the pack file cannot be pinned into the cursor, it - // probably was repacked recently. Go find the object - // again and open the stream from that location instead. - // try { + packIn = new PackInputStream( + pack, objectOffset + headerLength, ctx); + ctx = null; // owned by packIn + } catch (IOException packGone) { + // If the pack file cannot be pinned into the cursor, it + // probably was repacked recently. Go find the object + // again and open the stream from that location instead. ObjectId obj = pack.getReverseIdx(ctx).findObject(objectOffset); return ctx.open(obj, type).openStream(); - } finally { - ctx.close(); } } finally { - ctx.close(); + if (ctx != null) { + ctx.close(); + } } // Align buffer to inflater size, at a larger than default block. // This reduces the number of context switches from the // caller down into the pack stream inflation. int bufsz = 8192; - in = new BufferedInputStream( - new InflaterInputStream(in, ctx.inflater(), bufsz), + InputStream in = new BufferedInputStream( + new InflaterInputStream(packIn, packIn.ctx.inflater(), bufsz), bufsz); return new ObjectStream.Filter(type, size, in); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java index d88011c3ae..b859d9df33 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/PackInputStream.java @@ -47,7 +47,7 @@ import java.io.IOException; import java.io.InputStream; final class PackInputStream extends InputStream { - private final DfsReader ctx; + final DfsReader ctx; private final DfsPackFile pack; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java index 6ade4386ac..1da4304487 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java @@ -213,22 +213,6 @@ public class BitmapIndexImpl implements BitmapIndex { } @Override - public boolean add(AnyObjectId objectId, int type) { - int position = bitmapIndex.findOrInsert(objectId, type); - if (bitset.contains(position)) - return false; - - Bitmap entry = bitmapIndex.getBitmap(objectId); - if (entry != null) { - or(entry); - return false; - } - - bitset.set(position); - return true; - } - - @Override public boolean contains(AnyObjectId objectId) { int position = bitmapIndex.findPosition(objectId); return 0 <= position && bitset.contains(position); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteArrayWindow.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteArrayWindow.java index 338df4a8e1..c6fdeb0d1f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteArrayWindow.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteArrayWindow.java @@ -58,14 +58,14 @@ import org.eclipse.jgit.internal.storage.pack.PackOutputStream; final class ByteArrayWindow extends ByteWindow { private final byte[] array; - ByteArrayWindow(final PackFile pack, final long o, final byte[] b) { + ByteArrayWindow(PackFile pack, long o, byte[] b) { super(pack, o, b.length); array = b; } /** {@inheritDoc} */ @Override - protected int copy(final int p, final byte[] b, final int o, int n) { + protected int copy(int p, byte[] b, int o, int n) { n = Math.min(array.length - p, n); System.arraycopy(array, p, b, o, n); return n; @@ -73,7 +73,7 @@ final class ByteArrayWindow extends ByteWindow { /** {@inheritDoc} */ @Override - protected int setInput(final int pos, final Inflater inf) + protected int setInput(int pos, Inflater inf) throws DataFormatException { int n = array.length - pos; inf.setInput(array, pos, n); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteBufferWindow.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteBufferWindow.java index 4dcf133e08..8e7904f882 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteBufferWindow.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteBufferWindow.java @@ -60,14 +60,14 @@ import org.eclipse.jgit.internal.storage.pack.PackOutputStream; final class ByteBufferWindow extends ByteWindow { private final ByteBuffer buffer; - ByteBufferWindow(final PackFile pack, final long o, final ByteBuffer b) { + ByteBufferWindow(PackFile pack, long o, ByteBuffer b) { super(pack, o, b.capacity()); buffer = b; } /** {@inheritDoc} */ @Override - protected int copy(final int p, final byte[] b, final int o, int n) { + protected int copy(int p, byte[] b, int o, int n) { final ByteBuffer s = buffer.slice(); s.position(p); n = Math.min(s.remaining(), n); @@ -92,7 +92,7 @@ final class ByteBufferWindow extends ByteWindow { /** {@inheritDoc} */ @Override - protected int setInput(final int pos, final Inflater inf) + protected int setInput(int pos, Inflater inf) throws DataFormatException { final ByteBuffer s = buffer.slice(); s.position(pos); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteWindow.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteWindow.java index 7963ceac47..60073f39d3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteWindow.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ByteWindow.java @@ -76,7 +76,7 @@ abstract class ByteWindow { * @param n * size of the byte window */ - protected ByteWindow(final PackFile p, final long s, final int n) { + protected ByteWindow(PackFile p, long s, int n) { pack = p; start = s; end = start + n; @@ -86,7 +86,7 @@ abstract class ByteWindow { return (int) (end - start); } - final boolean contains(final PackFile neededFile, final long neededPos) { + final boolean contains(PackFile neededFile, long neededPos) { return pack == neededFile && start <= neededPos && neededPos < end; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CachedObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CachedObjectDirectory.java index e810ae0e27..7f7ecc268d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CachedObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/CachedObjectDirectory.java @@ -181,11 +181,11 @@ class CachedObjectDirectory extends FileObjectDatabase { /** {@inheritDoc} */ @Override - public boolean has(final AnyObjectId objectId) throws IOException { + public boolean has(AnyObjectId objectId) throws IOException { return has(objectId, null); } - private boolean has(final AnyObjectId objectId, Set<AlternateHandle.Id> skips) + private boolean has(AnyObjectId objectId, Set<AlternateHandle.Id> skips) throws IOException { if (unpackedObjects.contains(objectId)) { return true; @@ -205,7 +205,7 @@ class CachedObjectDirectory extends FileObjectDatabase { } @Override - ObjectLoader openObject(final WindowCursor curs, final AnyObjectId objectId) + ObjectLoader openObject(WindowCursor curs, AnyObjectId objectId) throws IOException { return openObject(curs, objectId, null); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/DeltaBaseCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/DeltaBaseCache.java index b3979894e4..ed73e72232 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/DeltaBaseCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/DeltaBaseCache.java @@ -52,7 +52,7 @@ class DeltaBaseCache { static final SoftReference<Entry> DEAD; - private static int hash(final long position) { + private static int hash(long position) { return (((int) position) << 22) >>> 22; } @@ -82,7 +82,7 @@ class DeltaBaseCache { cache = new Slot[CACHE_SZ]; } - Entry get(final PackFile pack, final long position) { + Entry get(PackFile pack, long position) { Slot e = cache[hash(position)]; if (e == null) return null; @@ -136,7 +136,7 @@ class DeltaBaseCache { } } - private void moveToHead(final Slot e) { + private void moveToHead(Slot e) { unlink(e); e.lruPrev = null; e.lruNext = lruHead; @@ -147,7 +147,7 @@ class DeltaBaseCache { lruHead = e; } - private void unlink(final Slot e) { + private void unlink(Slot e) { final Slot prev = e.lruPrev; final Slot next = e.lruNext; if (prev != null) @@ -156,7 +156,7 @@ class DeltaBaseCache { next.lruPrev = prev; } - private void clearEntry(final Slot e) { + private void clearEntry(Slot e) { openByteCount -= e.sz; e.provider = null; e.data = DEAD; @@ -168,7 +168,7 @@ class DeltaBaseCache { final int type; - Entry(final byte[] aData, final int aType) { + Entry(byte[] aData, int aType) { data = aData; type = aType; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index 9b82210e6c..d02888a872 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -46,8 +46,6 @@ package org.eclipse.jgit.internal.storage.file; -import static org.eclipse.jgit.lib.RefDatabase.ALL; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -125,6 +123,10 @@ public class FileRepository extends Repository { private final FileBasedConfig repoConfig; private final RefDatabase refs; private final ObjectDirectory objectDatabase; + + private final Object snapshotLock = new Object(); + + // protected by snapshotLock private FileSnapshot snapshot; /** @@ -147,7 +149,7 @@ public class FileRepository extends Repository { * accessed. * @see FileRepositoryBuilder */ - public FileRepository(final File gitDir) throws IOException { + public FileRepository(File gitDir) throws IOException { this(new FileRepositoryBuilder().setGitDir(gitDir).setup()); } @@ -161,7 +163,7 @@ public class FileRepository extends Repository { * accessed. * @see FileRepositoryBuilder */ - public FileRepository(final String gitDir) throws IOException { + public FileRepository(String gitDir) throws IOException { this(new File(gitDir)); } @@ -174,7 +176,7 @@ public class FileRepository extends Repository { * the user configuration file or repository configuration file * cannot be accessed. */ - public FileRepository(final BaseRepositoryBuilder options) throws IOException { + public FileRepository(BaseRepositoryBuilder options) throws IOException { super(options); if (StringUtils.isEmptyOrNull(SystemReader.getInstance().getenv( @@ -240,8 +242,9 @@ public class FileRepository extends Repository { Long.valueOf(repositoryFormatVersion))); } - if (!isBare()) + if (!isBare()) { snapshot = FileSnapshot.save(getIndexFile()); + } } private void loadSystemConfig() throws IOException { @@ -531,34 +534,43 @@ public class FileRepository extends Repository { * index file could not be opened, read, or is not recognized as * a Git pack file index. */ - public void openPack(final File pack) throws IOException { + public void openPack(File pack) throws IOException { objectDatabase.openPack(pack); } /** {@inheritDoc} */ @Override public void scanForRepoChanges() throws IOException { - getRefDatabase().getRefs(ALL); // This will look for changes to refs + getRefDatabase().getRefs(); // This will look for changes to refs detectIndexChanges(); } /** Detect index changes. */ private void detectIndexChanges() { - if (isBare()) + if (isBare()) { return; + } File indexFile = getIndexFile(); - if (snapshot == null) - snapshot = FileSnapshot.save(indexFile); - else if (snapshot.isModified(indexFile)) - notifyIndexChanged(); + synchronized (snapshotLock) { + if (snapshot == null) { + snapshot = FileSnapshot.save(indexFile); + return; + } + if (!snapshot.isModified(indexFile)) { + return; + } + } + notifyIndexChanged(false); } /** {@inheritDoc} */ @Override - public void notifyIndexChanged() { - snapshot = FileSnapshot.save(getIndexFile()); - fireEvent(new IndexChangedEvent()); + public void notifyIndexChanged(boolean internal) { + synchronized (snapshotLock) { + snapshot = FileSnapshot.save(getIndexFile()); + } + fireEvent(new IndexChangedEvent(internal)); } /** {@inheritDoc} */ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java index 2165aa2b76..10adc6ccc0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileSnapshot.java @@ -239,7 +239,7 @@ public class FileSnapshot { + ", read: " + f.format(new Date(lastRead)) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ } - private boolean notRacyClean(final long read) { + private boolean notRacyClean(long read) { // The last modified time granularity of FAT filesystems is 2 seconds. // Using 2.5 seconds here provides a reasonably high assurance that // a modification was not missed. @@ -247,7 +247,7 @@ public class FileSnapshot { return read - lastModified > 2500; } - private boolean isModified(final long currLastModified) { + private boolean isModified(long currLastModified) { // Any difference indicates the path was modified. // if (lastModified != currLastModified) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index 767fffcf0f..3fab484f29 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -768,7 +768,8 @@ public class GC { * @throws java.io.IOException */ public void packRefs() throws IOException { - Collection<Ref> refs = repo.getRefDatabase().getRefs(Constants.R_REFS).values(); + Collection<Ref> refs = repo.getRefDatabase() + .getRefsByPrefix(Constants.R_REFS); List<String> refsToBePacked = new ArrayList<>(refs.size()); pm.beginTask(JGitText.get().packRefs, refs.size()); try { @@ -834,7 +835,7 @@ public class GC { } List<ObjectIdSet> excluded = new LinkedList<>(); - for (final PackFile f : repo.getObjectDatabase().getPacks()) { + for (PackFile f : repo.getObjectDatabase().getPacks()) { checkCancelled(); if (f.shouldBeKept()) excluded.add(f.getIndex()); @@ -1056,7 +1057,7 @@ public class GC { */ private Collection<Ref> getAllRefs() throws IOException { RefDatabase refdb = repo.getRefDatabase(); - Collection<Ref> refs = refdb.getRefs(RefDatabase.ALL).values(); + Collection<Ref> refs = refdb.getRefs(); List<Ref> addl = refdb.getAdditionalRefs(); if (!addl.isEmpty()) { List<Ref> all = new ArrayList<>(refs.size() + addl.size()); @@ -1364,7 +1365,7 @@ public class GC { } RefDatabase refDb = repo.getRefDatabase(); - for (Ref r : refDb.getRefs(RefDatabase.ALL).values()) { + for (Ref r : refDb.getRefs()) { Storage storage = r.getStorage(); if (storage == Storage.LOOSE || storage == Storage.LOOSE_PACKED) ret.numberOfLooseRefs++; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java index 82458c1acf..0e587ce827 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.file; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.File; import java.io.IOException; @@ -171,6 +171,6 @@ class GcLog { if (content.length() > 0) { nonEmpty = true; } - lock.write(content.getBytes(UTF_8)); + lock.write(content.getBytes(CHARSET)); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java index 3d0e9c7189..c82d52e79c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.file; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.File; @@ -86,7 +86,7 @@ public class LazyObjectIdSetFile implements ObjectIdSet { private ObjectIdOwnerMap<Entry> load() { ObjectIdOwnerMap<Entry> r = new ObjectIdOwnerMap<>(); try (FileInputStream fin = new FileInputStream(src); - Reader rin = new InputStreamReader(fin, UTF_8); + Reader rin = new InputStreamReader(fin, CHARSET); BufferedReader br = new BufferedReader(rin)) { MutableObjectId id = new MutableObjectId(); for (String line; (line = br.readLine()) != null;) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectToPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectToPack.java index 55eeb95ce5..ed5cbfcf5d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectToPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LocalObjectToPack.java @@ -58,7 +58,7 @@ class LocalObjectToPack extends ObjectToPack { /** Length of the data section of the object. */ long length; - LocalObjectToPack(AnyObjectId src, final int type) { + LocalObjectToPack(AnyObjectId src, int type) { super(src, type); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java index bc23dcce27..da9a050bc3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.internal.storage.file; +import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -74,7 +76,6 @@ import org.eclipse.jgit.util.FileUtils; * name. */ public class LockFile { - static final String SUFFIX = ".lock"; //$NON-NLS-1$ /** * Unlock the given file. @@ -88,7 +89,7 @@ public class LockFile { * a {@link java.io.File} object. * @return true if unlocked, false if unlocking failed */ - public static boolean unlock(final File file) { + public static boolean unlock(File file) { final File lockFile = getLockFile(file); final int flags = FileUtils.RETRY | FileUtils.SKIP_MISSING; try { @@ -106,14 +107,15 @@ public class LockFile { * @return lock file */ static File getLockFile(File file) { - return new File(file.getParentFile(), file.getName() + SUFFIX); + return new File(file.getParentFile(), + file.getName() + LOCK_SUFFIX); } /** Filter to skip over active lock files when listing a directory. */ static final FilenameFilter FILTER = new FilenameFilter() { @Override public boolean accept(File dir, String name) { - return !name.endsWith(SUFFIX); + return !name.endsWith(LOCK_SUFFIX); } }; @@ -136,26 +138,8 @@ public class LockFile { * * @param f * the file that will be locked. - * @param fs - * the file system abstraction which will be necessary to perform - * certain file system operations. - * @deprecated use - * {@link org.eclipse.jgit.internal.storage.file.LockFile#LockFile(File)} - * instead - */ - @Deprecated - public LockFile(final File f, final FS fs) { - ref = f; - lck = getLockFile(ref); - } - - /** - * Create a new lock for any file. - * - * @param f - * the file that will be locked. */ - public LockFile(final File f) { + public LockFile(File f) { ref = f; lck = getLockFile(ref); } @@ -271,7 +255,7 @@ public class LockFile { * the temporary file could not be written. The lock is released * before throwing the underlying exception to the caller. */ - public void write(final ObjectId id) throws IOException { + public void write(ObjectId id) throws IOException { byte[] buf = new byte[Constants.OBJECT_ID_STRING_LENGTH + 1]; id.copyTo(buf, 0); buf[Constants.OBJECT_ID_STRING_LENGTH] = '\n'; @@ -292,7 +276,7 @@ public class LockFile { * the temporary file could not be written. The lock is released * before throwing the underlying exception to the caller. */ - public void write(final byte[] content) throws IOException { + public void write(byte[] content) throws IOException { requireLock(); try { if (fsync) { @@ -338,18 +322,18 @@ public class LockFile { return new OutputStream() { @Override - public void write(final byte[] b, final int o, final int n) + public void write(byte[] b, int o, int n) throws IOException { out.write(b, o, n); } @Override - public void write(final byte[] b) throws IOException { + public void write(byte[] b) throws IOException { out.write(b); } @Override - public void write(final int b) throws IOException { + public void write(int b) throws IOException { out.write(b); } @@ -389,7 +373,7 @@ public class LockFile { * @param on * true if the commit method must remember the modification time. */ - public void setNeedStatInformation(final boolean on) { + public void setNeedStatInformation(boolean on) { setNeedSnapshot(on); } @@ -400,7 +384,7 @@ public class LockFile { * @param on * true if the commit method must remember the FileSnapshot. */ - public void setNeedSnapshot(final boolean on) { + public void setNeedSnapshot(boolean on) { needSnapshot = on; } @@ -410,7 +394,7 @@ public class LockFile { * @param on * true if dirty data should be forced to the drive. */ - public void setFSync(final boolean on) { + public void setFSync(boolean on) { fsync = on; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java index 92b53ad44a..51c5702fc2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectory.java @@ -257,7 +257,7 @@ public class ObjectDirectory extends FileObjectDatabase { // Fully close all loaded alternates and clear the alternate list. AlternateHandle[] alt = alternates.get(); if (alt != null && alternates.compareAndSet(alt, null)) { - for(final AlternateHandle od : alt) + for(AlternateHandle od : alt) od.close(); } } @@ -278,7 +278,7 @@ public class ObjectDirectory extends FileObjectDatabase { * Add a single existing pack to the list of available pack files. */ @Override - public PackFile openPack(final File pack) + public PackFile openPack(File pack) throws IOException { final String p = pack.getName(); if (p.length() != 50 || !p.startsWith("pack-") || !p.endsWith(".pack")) //$NON-NLS-1$ //$NON-NLS-2$ @@ -619,7 +619,7 @@ public class ObjectDirectory extends FileObjectDatabase { WindowCursor curs, Set<AlternateHandle.Id> skips) throws IOException { PackList pList = packList.get(); SEARCH: for (;;) { - for (final PackFile p : pList.packs) { + for (PackFile p : pList.packs) { try { LocalObjectRepresentation rep = p.representation(curs, otp); p.resetTransientErrorCount(); @@ -814,7 +814,7 @@ public class ObjectDirectory extends FileObjectDatabase { return shallowCommitsIds; } - private void insertPack(final PackFile pf) { + private void insertPack(PackFile pf) { PackList o, n; do { o = packList.get(); @@ -837,7 +837,7 @@ public class ObjectDirectory extends FileObjectDatabase { } while (!packList.compareAndSet(o, n)); } - private void removePack(final PackFile deadPack) { + private void removePack(PackFile deadPack) { PackList o, n; do { o = packList.get(); @@ -855,7 +855,7 @@ public class ObjectDirectory extends FileObjectDatabase { deadPack.close(); } - private static int indexOf(final PackFile[] list, final PackFile pack) { + private static int indexOf(PackFile[] list, PackFile pack) { for (int i = 0; i < list.length; i++) { if (list[i] == pack) return i; @@ -863,7 +863,7 @@ public class ObjectDirectory extends FileObjectDatabase { return -1; } - private PackList scanPacks(final PackList original) { + private PackList scanPacks(PackList original) { synchronized (packList) { PackList o, n; do { @@ -882,13 +882,13 @@ public class ObjectDirectory extends FileObjectDatabase { } } - private PackList scanPacksImpl(final PackList old) { + private PackList scanPacksImpl(PackList old) { final Map<String, PackFile> forReuse = reuseMap(old); final FileSnapshot snapshot = FileSnapshot.save(packDirectory); final Set<String> names = listPackDirectory(); final List<PackFile> list = new ArrayList<>(names.size() >> 2); boolean foundNew = false; - for (final String indexName : names) { + for (String indexName : names) { // Must match "pack-[0-9a-f]{40}.idx" to be an index. // if (indexName.length() != 49 || !indexName.endsWith(".idx")) //$NON-NLS-1$ @@ -931,7 +931,7 @@ public class ObjectDirectory extends FileObjectDatabase { return old; } - for (final PackFile p : forReuse.values()) { + for (PackFile p : forReuse.values()) { p.close(); } @@ -943,9 +943,9 @@ public class ObjectDirectory extends FileObjectDatabase { return new PackList(snapshot, r); } - private static Map<String, PackFile> reuseMap(final PackList old) { + private static Map<String, PackFile> reuseMap(PackList old) { final Map<String, PackFile> forReuse = new HashMap<>(); - for (final PackFile p : old.packs) { + for (PackFile p : old.packs) { if (p.invalid()) { // The pack instance is corrupted, and cannot be safely used // again. Do not include it in our reuse map. @@ -974,7 +974,7 @@ public class ObjectDirectory extends FileObjectDatabase { if (nameList == null) return Collections.emptySet(); final Set<String> nameSet = new HashSet<>(nameList.length << 1); - for (final String name : nameList) { + for (String name : nameList) { if (name.startsWith("pack-")) //$NON-NLS-1$ nameSet.add(name); } @@ -1033,12 +1033,12 @@ public class ObjectDirectory extends FileObjectDatabase { return l.toArray(new AlternateHandle[l.size()]); } - private static BufferedReader open(final File f) + private static BufferedReader open(File f) throws FileNotFoundException { return new BufferedReader(new FileReader(f)); } - private AlternateHandle openAlternate(final String location) + private AlternateHandle openAlternate(String location) throws IOException { final File objdir = fs.resolve(objects, location); return openAlternate(objdir); @@ -1076,7 +1076,7 @@ public class ObjectDirectory extends FileObjectDatabase { /** All known packs, sorted by {@link PackFile#SORT}. */ final PackFile[] packs; - PackList(final FileSnapshot monitor, final PackFile[] packs) { + PackList(FileSnapshot monitor, PackFile[] packs) { this.snapshot = monitor; this.packs = packs; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java index e06f72167e..e5a54e372c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryInserter.java @@ -78,7 +78,7 @@ class ObjectDirectoryInserter extends ObjectInserter { private Deflater deflate; - ObjectDirectoryInserter(final FileObjectDatabase dest, final Config cfg) { + ObjectDirectoryInserter(FileObjectDatabase dest, Config cfg) { db = dest; config = cfg.get(WriteConfig.KEY); } @@ -117,7 +117,7 @@ class ObjectDirectoryInserter extends ObjectInserter { /** {@inheritDoc} */ @Override - public ObjectId insert(final int type, long len, final InputStream is) + public ObjectId insert(int type, long len, InputStream is) throws IOException { return insert(type, len, is, false); } @@ -267,7 +267,7 @@ class ObjectDirectoryInserter extends ObjectInserter { } } - void writeHeader(OutputStream out, final int type, long len) + void writeHeader(OutputStream out, int type, long len) throws IOException { out.write(Constants.encodedTypeString(type)); out.write((byte) ' '); @@ -279,7 +279,7 @@ class ObjectDirectoryInserter extends ObjectInserter { return File.createTempFile("noz", null, db.getDirectory()); //$NON-NLS-1$ } - DeflaterOutputStream compress(final OutputStream out) { + DeflaterOutputStream compress(OutputStream out) { if (deflate == null) deflate = new Deflater(config.getCompression()); else diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java index 5dcba6001a..0cec2d5a85 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java @@ -153,7 +153,7 @@ public class ObjectDirectoryPackParser extends PackParser { * @param empty * true to enable keeping an empty pack. */ - public void setKeepEmpty(final boolean empty) { + public void setKeepEmpty(boolean empty) { keepEmpty = empty; } @@ -429,8 +429,7 @@ public class ObjectDirectoryPackParser extends PackParser { private void writeIdx() throws IOException { List<PackedObjectInfo> list = getSortedObjectList(null /* by ObjectId */); - final FileOutputStream os = new FileOutputStream(tmpIdx); - try { + try (FileOutputStream os = new FileOutputStream(tmpIdx)) { final PackIndexWriter iw; if (indexVersion <= 0) iw = PackIndexWriter.createOldestPossible(os, list); @@ -438,12 +437,10 @@ public class ObjectDirectoryPackParser extends PackParser { iw = PackIndexWriter.createVersion(os, indexVersion); iw.write(list, packHash); os.getChannel().force(true); - } finally { - os.close(); } } - private PackLock renameAndOpenPack(final String lockMessage) + private PackLock renameAndOpenPack(String lockMessage) throws IOException { if (!keepEmpty && getObjectCount() == 0) { cleanupTemporaryFiles(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java index 21a1c7fcb3..6772e2c905 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java @@ -44,7 +44,6 @@ package org.eclipse.jgit.internal.storage.file; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; @@ -53,6 +52,7 @@ import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.util.io.SilentFileInputStream; import com.googlecode.javaewah.EWAHCompressedBitmap; @@ -93,19 +93,15 @@ public abstract class PackBitmapIndex { public static PackBitmapIndex open( File idxFile, PackIndex packIndex, PackReverseIndex reverseIndex) throws IOException { - final FileInputStream fd = new FileInputStream(idxFile); - try { - return read(fd, packIndex, reverseIndex); - } catch (IOException ioe) { - throw new IOException(MessageFormat - .format(JGitText.get().unreadablePackIndex, - idxFile.getAbsolutePath()), - ioe); - } finally { + try (SilentFileInputStream fd = new SilentFileInputStream( + idxFile)) { try { - fd.close(); - } catch (IOException err2) { - // ignore + return read(fd, packIndex, reverseIndex); + } catch (IOException ioe) { + throw new IOException( + MessageFormat.format(JGitText.get().unreadablePackIndex, + idxFile.getAbsolutePath()), + ioe); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java index d5219c7a05..71f64ae11f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackFile.java @@ -103,7 +103,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { /** Sorts PackFiles to be most recently created to least recently created. */ public static final Comparator<PackFile> SORT = new Comparator<PackFile>() { @Override - public int compare(final PackFile a, final PackFile b) { + public int compare(PackFile a, PackFile b) { return b.packLastModified - a.packLastModified; } }; @@ -162,7 +162,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { * @param extensions * additional pack file extensions with the same base as the pack */ - public PackFile(final File packFile, int extensions) { + public PackFile(File packFile, int extensions) { this.packFile = packFile; this.packLastModified = (int) (packFile.lastModified() >> 10); this.extensions = extensions; @@ -251,7 +251,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { * @throws java.io.IOException * the index file cannot be loaded into memory. */ - public boolean hasObject(final AnyObjectId id) throws IOException { + public boolean hasObject(AnyObjectId id) throws IOException { final long offset = idx().findOffset(id); return 0 < offset && !isCorrupt(offset); } @@ -279,7 +279,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { * @throws IOException * the pack file or the index could not be read. */ - ObjectLoader get(final WindowCursor curs, final AnyObjectId id) + ObjectLoader get(WindowCursor curs, AnyObjectId id) throws IOException { final long offset = idx().findOffset(id); return 0 < offset && !isCorrupt(offset) ? load(curs, offset) : null; @@ -344,7 +344,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { * @throws IOException * the index file cannot be loaded into memory. */ - ObjectId findObjectForOffset(final long offset) throws IOException { + ObjectId findObjectForOffset(long offset) throws IOException { return getReverseIdx().findObject(offset); } @@ -692,7 +692,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { } } - ByteArrayWindow read(final long pos, int size) throws IOException { + ByteArrayWindow read(long pos, int size) throws IOException { synchronized (readLock) { if (length < pos + size) size = (int) (length - pos); @@ -703,7 +703,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { } } - ByteWindow mmap(final long pos, int size) throws IOException { + ByteWindow mmap(long pos, int size) throws IOException { synchronized (readLock) { if (length < pos + size) size = (int) (length - pos); @@ -760,7 +760,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { } } - ObjectLoader load(final WindowCursor curs, long pos) + ObjectLoader load(WindowCursor curs, long pos) throws IOException, LargeObjectException { try { final byte[] ib = curs.tempId; @@ -949,7 +949,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { return hdr; } - int getObjectType(final WindowCursor curs, long pos) throws IOException { + int getObjectType(WindowCursor curs, long pos) throws IOException { final byte[] ib = curs.tempId; for (;;) { readFully(pos, ib, 0, 20, curs); @@ -996,13 +996,13 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { } } - long getObjectSize(final WindowCursor curs, final AnyObjectId id) + long getObjectSize(WindowCursor curs, AnyObjectId id) throws IOException { final long offset = idx().findOffset(id); return 0 < offset ? getObjectSize(curs, offset) : -1; } - long getObjectSize(final WindowCursor curs, final long pos) + long getObjectSize(WindowCursor curs, long pos) throws IOException { final byte[] ib = curs.tempId; readFully(pos, ib, 0, 20, curs); @@ -1100,7 +1100,7 @@ public class PackFile implements Iterable<PackIndex.MutableEntry> { } } - private long findEndOffset(final long startOffset) + private long findEndOffset(long startOffset) throws IOException, CorruptObjectException { final long maxOffset = length - 20; return getReverseIdx().findNextOffset(startOffset, maxOffset); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java index acfd9c4719..72699b0438 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java @@ -45,7 +45,6 @@ package org.eclipse.jgit.internal.storage.file; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -64,6 +63,7 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdSet; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.NB; +import org.eclipse.jgit.util.io.SilentFileInputStream; /** * Access path to locate objects by {@link org.eclipse.jgit.lib.ObjectId} in a @@ -94,21 +94,15 @@ public abstract class PackIndex * the file exists but could not be read due to security errors, * unrecognized data version, or unexpected data corruption. */ - public static PackIndex open(final File idxFile) throws IOException { - final FileInputStream fd = new FileInputStream(idxFile); - try { - return read(fd); + public static PackIndex open(File idxFile) throws IOException { + try (SilentFileInputStream fd = new SilentFileInputStream( + idxFile)) { + return read(fd); } catch (IOException ioe) { - throw new IOException(MessageFormat - .format(JGitText.get().unreadablePackIndex, + throw new IOException( + MessageFormat.format(JGitText.get().unreadablePackIndex, idxFile.getAbsolutePath()), ioe); - } finally { - try { - fd.close(); - } catch (IOException err2) { - // ignore - } } } @@ -145,7 +139,7 @@ public abstract class PackIndex return new PackIndexV1(fd, hdr); } - private static boolean isTOC(final byte[] h) { + private static boolean isTOC(byte[] h) { final byte[] toc = PackIndexWriter.TOC; for (int i = 0; i < toc.length; i++) if (h[i] != toc[i]) @@ -163,7 +157,7 @@ public abstract class PackIndex * the object to look for. Must not be null. * @return true if the object is listed in this index; false otherwise. */ - public boolean hasObject(final AnyObjectId id) { + public boolean hasObject(AnyObjectId id) { return findOffset(id) != -1; } @@ -247,7 +241,7 @@ public abstract class PackIndex * negative, but still valid. * @return the ObjectId for the corresponding entry. */ - public final ObjectId getObjectId(final int nthPosition) { + public final ObjectId getObjectId(int nthPosition) { if (nthPosition >= 0) return getObjectId((long) nthPosition); final int u31 = nthPosition >>> 1; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java index 8ea31e4fa0..4444dd691f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV1.java @@ -113,14 +113,14 @@ class PackIndexV1 extends PackIndex { @Override public long getOffset64Count() { long n64 = 0; - for (final MutableEntry e : this) { + for (MutableEntry e : this) { if (e.getOffset() >= Integer.MAX_VALUE) n64++; } return n64; } - private int findLevelOne(final long nthPosition) { + private int findLevelOne(long nthPosition) { int levelOne = Arrays.binarySearch(idxHeader, nthPosition + 1); if (levelOne >= 0) { // If we hit the bucket exactly the item is in the bucket, or @@ -137,14 +137,14 @@ class PackIndexV1 extends PackIndex { return levelOne; } - private int getLevelTwo(final long nthPosition, final int levelOne) { + private int getLevelTwo(long nthPosition, int levelOne) { final long base = levelOne > 0 ? idxHeader[levelOne - 1] : 0; return (int) (nthPosition - base); } /** {@inheritDoc} */ @Override - public ObjectId getObjectId(final long nthPosition) { + public ObjectId getObjectId(long nthPosition) { final int levelOne = findLevelOne(nthPosition); final int p = getLevelTwo(nthPosition, levelOne); final int dataIdx = idOffset(p); @@ -161,7 +161,7 @@ class PackIndexV1 extends PackIndex { /** {@inheritDoc} */ @Override - public long findOffset(final AnyObjectId objId) { + public long findOffset(AnyObjectId objId) { final int levelOne = objId.getFirstByte(); byte[] data = idxdata[levelOne]; if (data == null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java index 9f6201f9a7..a9606cfa2d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexV2.java @@ -176,7 +176,7 @@ class PackIndexV2 extends PackIndex { return offset64.length / 8; } - private int findLevelOne(final long nthPosition) { + private int findLevelOne(long nthPosition) { int levelOne = Arrays.binarySearch(fanoutTable, nthPosition + 1); if (levelOne >= 0) { // If we hit the bucket exactly the item is in the bucket, or @@ -193,14 +193,14 @@ class PackIndexV2 extends PackIndex { return levelOne; } - private int getLevelTwo(final long nthPosition, final int levelOne) { + private int getLevelTwo(long nthPosition, int levelOne) { final long base = levelOne > 0 ? fanoutTable[levelOne - 1] : 0; return (int) (nthPosition - base); } /** {@inheritDoc} */ @Override - public ObjectId getObjectId(final long nthPosition) { + public ObjectId getObjectId(long nthPosition) { final int levelOne = findLevelOne(nthPosition); final int p = getLevelTwo(nthPosition, levelOne); final int p4 = p << 2; @@ -209,7 +209,7 @@ class PackIndexV2 extends PackIndex { /** {@inheritDoc} */ @Override - public long getOffset(final long nthPosition) { + public long getOffset(long nthPosition) { final int levelOne = findLevelOne(nthPosition); final int levelTwo = getLevelTwo(nthPosition, levelOne); return getOffset(levelOne, levelTwo); @@ -217,7 +217,7 @@ class PackIndexV2 extends PackIndex { /** {@inheritDoc} */ @Override - public long findOffset(final AnyObjectId objId) { + public long findOffset(AnyObjectId objId) { final int levelOne = objId.getFirstByte(); final int levelTwo = binarySearchLevelTwo(objId, levelOne); if (levelTwo == -1) @@ -225,7 +225,7 @@ class PackIndexV2 extends PackIndex { return getOffset(levelOne, levelTwo); } - private long getOffset(final int levelOne, final int levelTwo) { + private long getOffset(int levelOne, int levelTwo) { final long p = NB.decodeUInt32(offset32[levelOne], levelTwo << 2); if ((p & IS_O64) != 0) return NB.decodeUInt64(offset64, (8 * (int) (p & ~IS_O64))); @@ -290,7 +290,7 @@ class PackIndexV2 extends PackIndex { return (p << 2) + p; // p * 5 } - private int binarySearchLevelTwo(final AnyObjectId objId, final int levelOne) { + private int binarySearchLevelTwo(AnyObjectId objId, int levelOne) { final int[] data = names[levelOne]; int high = offset32[levelOne].length >>> 2; if (high == 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java index b92f7b207c..553f7c9a19 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriter.java @@ -123,7 +123,7 @@ public abstract class PackIndexWriter { */ public static int oldestPossibleFormat( final List<? extends PackedObjectInfo> objs) { - for (final PackedObjectInfo oe : objs) { + for (PackedObjectInfo oe : objs) { if (!PackIndexWriterV1.canStore(oe)) return 2; } @@ -180,7 +180,7 @@ public abstract class PackIndexWriter { * the stream this instance outputs to. If not already buffered * it will be automatically wrapped in a buffered stream. */ - protected PackIndexWriter(final OutputStream dst) { + protected PackIndexWriter(OutputStream dst) { out = new DigestOutputStream(dst instanceof BufferedOutputStream ? dst : new BufferedOutputStream(dst), Constants.newMessageDigest()); @@ -250,7 +250,7 @@ public abstract class PackIndexWriter { * @throws java.io.IOException * an error occurred while writing to the output stream. */ - protected void writeTOC(final int version) throws IOException { + protected void writeTOC(int version) throws IOException { out.write(TOC); NB.encodeInt32(tmp, 0, version); out.write(tmp, 0, 4); @@ -269,11 +269,11 @@ public abstract class PackIndexWriter { */ protected void writeFanOutTable() throws IOException { final int[] fanout = new int[256]; - for (final PackedObjectInfo po : entries) + for (PackedObjectInfo po : entries) fanout[po.getFirstByte() & 0xff]++; for (int i = 1; i < 256; i++) fanout[i] += fanout[i - 1]; - for (final int n : fanout) { + for (int n : fanout) { NB.encodeInt32(tmp, 0, n); out.write(tmp, 0, 4); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV1.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV1.java index f220e7a6c6..877f7c8cd7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV1.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV1.java @@ -58,7 +58,7 @@ import org.eclipse.jgit.util.NB; * @see PackIndexV1 */ class PackIndexWriterV1 extends PackIndexWriter { - static boolean canStore(final PackedObjectInfo oe) { + static boolean canStore(PackedObjectInfo oe) { // We are limited to 4 GB per pack as offset is 32 bit unsigned int. // return oe.getOffset() >>> 1 < Integer.MAX_VALUE; @@ -73,7 +73,7 @@ class PackIndexWriterV1 extends PackIndexWriter { protected void writeImpl() throws IOException { writeFanOutTable(); - for (final PackedObjectInfo oe : entries) { + for (PackedObjectInfo oe : entries) { if (!canStore(oe)) throw new IOException(JGitText.get().packTooLargeForIndexVersion1); NB.encodeInt32(tmp, 0, (int) oe.getOffset()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV2.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV2.java index a18ccaf9ea..9505d35b71 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV2.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndexWriterV2.java @@ -76,12 +76,12 @@ class PackIndexWriterV2 extends PackIndexWriter { } private void writeObjectNames() throws IOException { - for (final PackedObjectInfo oe : entries) + for (PackedObjectInfo oe : entries) oe.copyRawTo(out); } private void writeCRCs() throws IOException { - for (final PackedObjectInfo oe : entries) { + for (PackedObjectInfo oe : entries) { NB.encodeInt32(tmp, 0, oe.getCRC()); out.write(tmp, 0, 4); } @@ -89,7 +89,7 @@ class PackIndexWriterV2 extends PackIndexWriter { private void writeOffset32() throws IOException { int o64 = 0; - for (final PackedObjectInfo oe : entries) { + for (PackedObjectInfo oe : entries) { final long o = oe.getOffset(); if (o <= MAX_OFFSET_32) NB.encodeInt32(tmp, 0, (int) o); @@ -100,7 +100,7 @@ class PackIndexWriterV2 extends PackIndexWriter { } private void writeOffset64() throws IOException { - for (final PackedObjectInfo oe : entries) { + for (PackedObjectInfo oe : entries) { final long o = oe.getOffset(); if (MAX_OFFSET_32 < o) { NB.encodeInt64(tmp, 0, o); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java index 7ff269694b..0ce3cc93ce 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackInserter.java @@ -438,7 +438,7 @@ public class PackInserter extends ObjectInserter { } @Override - public void write(final int b) throws IOException { + public void write(int b) throws IOException { hdrBuf[0] = (byte) b; write(hdrBuf, 0, 1); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java index 82f0da1c8c..0fb8911ba5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java @@ -65,7 +65,7 @@ public class PackLock { * @param fs * the filesystem abstraction used by the repository. */ - public PackLock(final File packFile, final FS fs) { + public PackLock(File packFile, FS fs) { final File p = packFile.getParentFile(); final String n = packFile.getName(); keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java index 944af26dc5..dfe23ba79c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackReverseIndex.java @@ -88,7 +88,7 @@ public class PackReverseIndex { * @param packIndex * forward index - entries to (reverse) index. */ - public PackReverseIndex(final PackIndex packIndex) { + public PackReverseIndex(PackIndex packIndex) { index = packIndex; final long cnt = index.getObjectCount(); @@ -107,7 +107,7 @@ public class PackReverseIndex { long maxOffset = 0; int ith = 0; - for (final MutableEntry me : index) { + for (MutableEntry me : index) { final long o = me.getOffset(); offsetsBySha1[ith++] = o; if (o > maxOffset) @@ -155,7 +155,7 @@ public class PackReverseIndex { * start offset of object to find. * @return object id for this offset, or null if no object was found. */ - public ObjectId findObject(final long offset) { + public ObjectId findObject(long offset) { final int ith = binarySearch(offset); if (ith < 0) return null; @@ -177,7 +177,7 @@ public class PackReverseIndex { * @throws org.eclipse.jgit.errors.CorruptObjectException * when there is no object with the provided offset. */ - public long findNextOffset(final long offset, final long maxOffset) + public long findNextOffset(long offset, long maxOffset) throws CorruptObjectException { final int ith = binarySearch(offset); if (ith < 0) @@ -195,7 +195,7 @@ public class PackReverseIndex { return binarySearch(offset); } - private int binarySearch(final long offset) { + private int binarySearch(long offset) { int bucket = (int) (offset / bucketSize); int low = bucket == 0 ? 0 : offsetIndex[bucket - 1]; int high = offsetIndex[bucket]; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 73ea77d47f..836cd2cc6e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -208,7 +208,7 @@ public class RefDirectory extends RefDatabase { private List<Integer> retrySleepMs = RETRY_SLEEP_MS; - RefDirectory(final FileRepository db) { + RefDirectory(FileRepository db) { final FS fs = db.getFS(); parent = db; gitDir = db.getDirectory(); @@ -345,7 +345,7 @@ public class RefDirectory extends RefDatabase { /** {@inheritDoc} */ @Override - public Ref getRef(final String needle) throws IOException { + public Ref getRef(String needle) throws IOException { final RefList<Ref> packed = getPackedRefs(); Ref ref = null; for (String prefix : SEARCH_PATH) { @@ -434,7 +434,7 @@ public class RefDirectory extends RefDatabase { RefList.Builder<LooseRef> newLoose; - LooseScanner(final RefList<LooseRef> curLoose) { + LooseScanner(RefList<LooseRef> curLoose) { this.curLoose = curLoose; } @@ -545,7 +545,7 @@ public class RefDirectory extends RefDatabase { /** {@inheritDoc} */ @Override - public Ref peel(final Ref ref) throws IOException { + public Ref peel(Ref ref) throws IOException { final Ref leaf = ref.getLeaf(); if (leaf.isPeeled() || leaf.getObjectId() == null) return ref; @@ -567,7 +567,7 @@ public class RefDirectory extends RefDatabase { return recreate(ref, newLeaf); } - private ObjectIdRef doPeel(final Ref leaf) throws MissingObjectException, + private ObjectIdRef doPeel(Ref leaf) throws MissingObjectException, IOException { try (RevWalk rw = new RevWalk(getRepository())) { RevObject obj = rw.parseAny(leaf.getObjectId()); @@ -581,7 +581,7 @@ public class RefDirectory extends RefDatabase { } } - private static Ref recreate(final Ref old, final ObjectIdRef leaf) { + private static Ref recreate(Ref old, ObjectIdRef leaf) { if (old.isSymbolic()) { Ref dst = recreate(old.getTarget(), leaf); return new SymbolicRef(old.getName(), dst); @@ -971,7 +971,7 @@ public class RefDirectory extends RefDatabase { } } - private RefList<Ref> parsePackedRefs(final BufferedReader br) + private RefList<Ref> parsePackedRefs(BufferedReader br) throws IOException { RefList.Builder<Ref> all = new RefList.Builder<>(); Ref last = null; @@ -1023,7 +1023,7 @@ public class RefDirectory extends RefDatabase { return all.toRefList(); } - private static String copy(final String src, final int off, final int end) { + private static String copy(String src, int off, int end) { // Don't use substring since it could leave a reference to the much // larger existing string. Force construction of a full new object. return new StringBuilder(end - off).append(src, off, end).toString(); @@ -1189,7 +1189,7 @@ public class RefDirectory extends RefDatabase { return new LooseUnpeeled(otherSnapshot, name, id); } - private static boolean isSymRef(final byte[] buf, int n) { + private static boolean isSymRef(byte[] buf, int n) { if (n < 6) return false; return /**/buf[0] == 'r' // @@ -1262,18 +1262,18 @@ public class RefDirectory extends RefDatabase { return new File(gitDir, name); } - static int levelsIn(final String name) { + static int levelsIn(String name) { int count = 0; for (int p = name.indexOf('/'); p >= 0; p = name.indexOf('/', p + 1)) count++; return count; } - static void delete(final File file, final int depth) throws IOException { + static void delete(File file, int depth) throws IOException { delete(file, depth, null); } - private static void delete(final File file, final int depth, LockFile rLck) + private static void delete(File file, int depth, LockFile rLck) throws IOException { if (!file.delete() && file.isFile()) { throw new IOException(MessageFormat.format( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryRename.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryRename.java index 202e51f6c8..ec7ec73be8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryRename.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryRename.java @@ -104,7 +104,7 @@ class RefDirectoryRename extends RefRename { objId = source.getOldObjectId(); updateHEAD = needToUpdateHEAD(); tmp = refdb.newTemporaryUpdate(); - try (final RevWalk rw = new RevWalk(refdb.getRepository())) { + try (RevWalk rw = new RevWalk(refdb.getRepository())) { // First backup the source so its never unreachable. tmp.setNewObjectId(objId); tmp.setForceUpdate(true); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java index 4d6b245705..45ce6349a5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java @@ -60,7 +60,7 @@ class RefDirectoryUpdate extends RefUpdate { private boolean shouldDeref; private LockFile lock; - RefDirectoryUpdate(final RefDirectory r, final Ref ref) { + RefDirectoryUpdate(RefDirectory r, Ref ref) { super(ref); database = r; } @@ -106,7 +106,7 @@ class RefDirectoryUpdate extends RefUpdate { /** {@inheritDoc} */ @Override - protected Result doUpdate(final Result status) throws IOException { + protected Result doUpdate(Result status) throws IOException { WriteConfig wc = database.getRepository().getConfig() .get(WriteConfig.KEY); @@ -148,7 +148,7 @@ class RefDirectoryUpdate extends RefUpdate { /** {@inheritDoc} */ @Override - protected Result doDelete(final Result status) throws IOException { + protected Result doDelete(Result status) throws IOException { if (getRef().getStorage() != Ref.Storage.NEW) database.delete(this); return status; @@ -156,7 +156,7 @@ class RefDirectoryUpdate extends RefUpdate { /** {@inheritDoc} */ @Override - protected Result doLink(final String target) throws IOException { + protected Result doLink(String target) throws IOException { WriteConfig wc = database.getRepository().getConfig() .get(WriteConfig.KEY); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java index d99c266144..495c752360 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.internal.storage.file; import static org.eclipse.jgit.lib.Constants.HEAD; +import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; import static org.eclipse.jgit.lib.Constants.R_HEADS; import static org.eclipse.jgit.lib.Constants.R_NOTES; import static org.eclipse.jgit.lib.Constants.R_REFS; @@ -84,7 +85,7 @@ public class ReflogWriter { * @return the name of the ref's lock ref. */ public static String refLockFor(String name) { - return name + LockFile.SUFFIX; + return name + LOCK_SUFFIX; } private final RefDirectory refdb; @@ -219,6 +220,22 @@ public class ReflogWriter { return Constants.encode(r.toString()); } + private FileOutputStream getFileOutputStream(File log) throws IOException { + try { + return new FileOutputStream(log, true); + } catch (FileNotFoundException err) { + File dir = log.getParentFile(); + if (dir.exists()) { + throw err; + } + if (!dir.mkdirs() && !dir.isDirectory()) { + throw new IOException(MessageFormat + .format(JGitText.get().cannotCreateDirectory, dir)); + } + return new FileOutputStream(log, true); + } + } + private ReflogWriter log(String refName, byte[] rec) throws IOException { File log = refdb.logFor(refName); boolean write = forceWrite @@ -228,29 +245,17 @@ public class ReflogWriter { return this; WriteConfig wc = refdb.getRepository().getConfig().get(WriteConfig.KEY); - FileOutputStream out; - try { - out = new FileOutputStream(log, true); - } catch (FileNotFoundException err) { - File dir = log.getParentFile(); - if (dir.exists()) - throw err; - if (!dir.mkdirs() && !dir.isDirectory()) - throw new IOException(MessageFormat.format( - JGitText.get().cannotCreateDirectory, dir)); - out = new FileOutputStream(log, true); - } - try { + try (FileOutputStream out = getFileOutputStream(log)) { if (wc.getFSyncRefFiles()) { FileChannel fc = out.getChannel(); ByteBuffer buf = ByteBuffer.wrap(rec); - while (0 < buf.remaining()) + while (0 < buf.remaining()) { fc.write(buf); + } fc.force(true); - } else + } else { out.write(rec); - } finally { - out.close(); + } } return this; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java index adb05e4d99..cf474afbbe 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObject.java @@ -266,7 +266,7 @@ public class UnpackedObject { } } - static boolean isStandardFormat(final byte[] hdr) { + static boolean isStandardFormat(byte[] hdr) { /* * We must determine if the buffer contains the standard * zlib-deflated stream or the experimental format based diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java index e71284fb62..8cf1d4e219 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCache.java @@ -157,7 +157,7 @@ public class WindowCache { * settings, usually too low of a limit. */ @Deprecated - public static void reconfigure(final WindowCacheConfig cfg) { + public static void reconfigure(WindowCacheConfig cfg) { final WindowCache nc = new WindowCache(cfg); final WindowCache oc = cache; if (oc != null) @@ -178,7 +178,7 @@ public class WindowCache { return cache; } - static final ByteWindow get(final PackFile pack, final long offset) + static final ByteWindow get(PackFile pack, long offset) throws IOException { final WindowCache c = cache; final ByteWindow r = c.getOrLoad(pack, c.toStart(offset)); @@ -193,7 +193,7 @@ public class WindowCache { return r; } - static final void purge(final PackFile pack) { + static final void purge(PackFile pack) { cache.removeAll(pack); } @@ -232,7 +232,7 @@ public class WindowCache { private final AtomicLong openBytes; - private WindowCache(final WindowCacheConfig cfg) { + private WindowCache(WindowCacheConfig cfg) { tableSize = tableSize(cfg); final int lockCount = lockCount(cfg); if (tableSize < 1) @@ -286,11 +286,11 @@ public class WindowCache { return openBytes.get(); } - private int hash(final int packHash, final long off) { + private int hash(int packHash, long off) { return packHash + (int) (off >>> windowSizeShift); } - private ByteWindow load(final PackFile pack, final long offset) + private ByteWindow load(PackFile pack, long offset) throws IOException { if (pack.beginWindowCache()) openFiles.incrementAndGet(); @@ -310,18 +310,18 @@ public class WindowCache { } } - private Ref createRef(final PackFile p, final long o, final ByteWindow v) { + private Ref createRef(PackFile p, long o, ByteWindow v) { final Ref ref = new Ref(p, o, v, queue); openBytes.addAndGet(ref.size); return ref; } - private void clear(final Ref ref) { + private void clear(Ref ref) { openBytes.addAndGet(-ref.size); close(ref.pack); } - private void close(final PackFile pack) { + private void close(PackFile pack) { if (pack.endWindowCache()) openFiles.decrementAndGet(); } @@ -330,11 +330,11 @@ public class WindowCache { return maxFiles < openFiles.get() || maxBytes < openBytes.get(); } - private long toStart(final long offset) { + private long toStart(long offset) { return (offset >>> windowSizeShift) << windowSizeShift; } - private static int tableSize(final WindowCacheConfig cfg) { + private static int tableSize(WindowCacheConfig cfg) { final int wsz = cfg.getPackedGitWindowSize(); final long limit = cfg.getPackedGitLimit(); if (wsz <= 0) @@ -344,7 +344,7 @@ public class WindowCache { return (int) Math.min(5 * (limit / wsz) / 2, 2000000000); } - private static int lockCount(final WindowCacheConfig cfg) { + private static int lockCount(WindowCacheConfig cfg) { return Math.max(cfg.getPackedGitOpenFiles(), 32); } @@ -360,7 +360,7 @@ public class WindowCache { * the object reference was not in the cache and could not be * obtained by {@link #load(PackFile, long)}. */ - private ByteWindow getOrLoad(final PackFile pack, final long position) + private ByteWindow getOrLoad(PackFile pack, long position) throws IOException { final int slot = slot(pack, position); final Entry e1 = table.get(slot); @@ -399,7 +399,7 @@ public class WindowCache { return v; } - private ByteWindow scan(Entry n, final PackFile pack, final long position) { + private ByteWindow scan(Entry n, PackFile pack, long position) { for (; n != null; n = n.next) { final Ref r = n.ref; if (r.pack == pack && r.position == position) { @@ -415,7 +415,7 @@ public class WindowCache { return null; } - private void hit(final Ref r) { + private void hit(Ref r) { // We don't need to be 100% accurate here. Its sufficient that at least // one thread performs the increment. Any other concurrent access at // exactly the same time can simply use the same clock value. @@ -487,7 +487,7 @@ public class WindowCache { * @param pack * the file to purge all entries of. */ - private void removeAll(final PackFile pack) { + private void removeAll(PackFile pack) { for (int s = 0; s < tableSize; s++) { final Entry e1 = table.get(s); boolean hasDead = false; @@ -521,11 +521,11 @@ public class WindowCache { } } - private int slot(final PackFile pack, final long position) { + private int slot(PackFile pack, long position) { return (hash(pack.hash, position) >>> 1) % tableSize; } - private Lock lock(final PackFile pack, final long position) { + private Lock lock(PackFile pack, long position) { return locks[(hash(pack.hash, position) >>> 1) % locks.length]; } @@ -556,7 +556,7 @@ public class WindowCache { */ volatile boolean dead; - Entry(final Entry n, final Ref r) { + Entry(Entry n, Ref r) { next = n; ref = r; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java index 569bfe895f..010c142887 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WindowCursor.java @@ -347,7 +347,7 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs { inf.reset(); } - void pin(final PackFile pack, final long position) + void pin(PackFile pack, long position) throws IOException { final ByteWindow w = window; if (w == null || !w.contains(pack, position)) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WriteConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WriteConfig.java index d9cbbd8f82..23055ee957 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WriteConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/WriteConfig.java @@ -57,7 +57,7 @@ class WriteConfig { private final boolean fsyncRefFiles; - private WriteConfig(final Config rc) { + private WriteConfig(Config rc) { compression = rc.get(CoreConfig.KEY).getCompression(); fsyncObjectFiles = rc.getBoolean("core", "fsyncobjectfiles", false); //$NON-NLS-1$ //$NON-NLS-2$ fsyncRefFiles = rc.getBoolean("core", "fsyncreffiles", false); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BinaryDelta.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BinaryDelta.java index 2565931e05..c7e5ad6232 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BinaryDelta.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/BinaryDelta.java @@ -64,7 +64,7 @@ public class BinaryDelta { * the delta stream, or at least the header of it. * @return the base object's size. */ - public static long getBaseSize(final byte[] delta) { + public static long getBaseSize(byte[] delta) { int p = 0; long baseLen = 0; int c, shift = 0; @@ -83,7 +83,7 @@ public class BinaryDelta { * the delta stream, or at least the header of it. * @return the resulting object's size. */ - public static long getResultSize(final byte[] delta) { + public static long getResultSize(byte[] delta) { int p = 0; // Skip length of the base object. @@ -114,7 +114,7 @@ public class BinaryDelta { * another. * @return patched base */ - public static final byte[] apply(final byte[] base, final byte[] delta) { + public static final byte[] apply(byte[] base, byte[] delta) { return apply(base, delta, null); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndexScanner.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndexScanner.java index 969d02b946..944a9e5e4d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndexScanner.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaIndexScanner.java @@ -89,7 +89,7 @@ class DeltaIndexScanner { } } - private void scan(byte[] raw, final int end) { + private void scan(byte[] raw, int end) { // We scan the input backwards, and always insert onto the // front of the chain. This ensures that chains will have lower // offsets at the front of the chain, allowing us to prefer the @@ -120,7 +120,7 @@ class DeltaIndexScanner { } while (0 <= ptr); } - private static int tableSize(final int worstCaseBlockCnt) { + private static int tableSize(int worstCaseBlockCnt) { int shift = 32 - Integer.numberOfLeadingZeros(worstCaseBlockCnt); int sz = 1 << (shift - 1); if (sz < worstCaseBlockCnt) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaWindow.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaWindow.java index 73b285afc1..a047534fbf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaWindow.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaWindow.java @@ -266,7 +266,7 @@ final class DeltaWindow { deltaBuf = null; } - private boolean delta(final DeltaWindowEntry src) + private boolean delta(DeltaWindowEntry src) throws IOException { // If the sizes are radically different, this is a bad pairing. if (res.size() < src.size() >>> 4) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectToPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectToPack.java index e8c75107b9..a30bf982fa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectToPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/ObjectToPack.java @@ -103,7 +103,7 @@ public class ObjectToPack extends PackedObjectInfo { * @param type * real type code of the object, not its in-pack type. */ - public ObjectToPack(AnyObjectId src, final int type) { + public ObjectToPack(AnyObjectId src, int type) { super(src); flags = type << TYPE_SHIFT; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackOutputStream.java index fd9c1a00d3..7f38a7b51a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackOutputStream.java @@ -107,7 +107,7 @@ public final class PackOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public final void write(final int b) throws IOException { + public final void write(int b) throws IOException { count++; out.write(b); md.update((byte) b); @@ -115,7 +115,7 @@ public final class PackOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public final void write(final byte[] b, int off, int len) + public final void write(byte[] b, int off, int len) throws IOException { while (0 < len) { final int n = Math.min(len, BYTES_TO_WRITE_BEFORE_CANCEL_CHECK); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java index 42df1a6588..36d6f0aebc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java @@ -303,6 +303,8 @@ public class PackWriter implements AutoCloseable { private ObjectCountCallback callback; + private long filterBlobLimit = -1; + /** * Create writer for specified repository. * <p> @@ -312,7 +314,7 @@ public class PackWriter implements AutoCloseable { * @param repo * repository where objects are stored. */ - public PackWriter(final Repository repo) { + public PackWriter(Repository repo) { this(repo, repo.newObjectReader()); } @@ -325,7 +327,7 @@ public class PackWriter implements AutoCloseable { * @param reader * reader to read from the repository with. */ - public PackWriter(final ObjectReader reader) { + public PackWriter(ObjectReader reader) { this(new PackConfig(), reader); } @@ -340,7 +342,7 @@ public class PackWriter implements AutoCloseable { * @param reader * reader to read from the repository with. */ - public PackWriter(final Repository repo, final ObjectReader reader) { + public PackWriter(Repository repo, ObjectReader reader) { this(new PackConfig(repo), reader); } @@ -355,7 +357,7 @@ public class PackWriter implements AutoCloseable { * @param reader * reader to read from the repository with. */ - public PackWriter(final PackConfig config, final ObjectReader reader) { + public PackWriter(PackConfig config, ObjectReader reader) { this(config, reader, null); } @@ -510,7 +512,7 @@ public class PackWriter implements AutoCloseable { * determined by set; this kind of pack is used only for * transport; true - to produce thin pack, false - otherwise. */ - public void setThin(final boolean packthin) { + public void setThin(boolean packthin) { thin = packthin; } @@ -601,7 +603,7 @@ public class PackWriter implements AutoCloseable { * pack; false otherwise - non existing uninteresting objects may * cause {@link org.eclipse.jgit.errors.MissingObjectException} */ - public void setIgnoreMissingUninteresting(final boolean ignore) { + public void setIgnoreMissingUninteresting(boolean ignore) { ignoreMissingUninteresting = ignore; } @@ -639,6 +641,14 @@ public class PackWriter implements AutoCloseable { } /** + * @param bytes exclude blobs of size greater than this + * @since 5.0 + */ + public void setFilterBlobLimit(long bytes) { + filterBlobLimit = bytes; + } + + /** * Returns objects number in a pack file that was created by this writer. * * @return number of objects in pack. @@ -914,7 +924,7 @@ public class PackWriter implements AutoCloseable { * @throws java.io.IOException * a cached pack cannot be examined. */ - public boolean willInclude(final AnyObjectId id) throws IOException { + public boolean willInclude(AnyObjectId id) throws IOException { ObjectToPack obj = objectsMap.get(id); return obj != null && !obj.isEdge(); } @@ -981,7 +991,7 @@ public class PackWriter implements AutoCloseable { * @throws java.io.IOException * the index data could not be written to the supplied stream. */ - public void writeIndex(final OutputStream indexStream) throws IOException { + public void writeIndex(OutputStream indexStream) throws IOException { if (isIndexDisabled()) throw new IOException(JGitText.get().cachedPacksPreventsIndexCreation); @@ -1003,7 +1013,7 @@ public class PackWriter implements AutoCloseable { * @throws java.io.IOException * the index data could not be written to the supplied stream. */ - public void writeBitmapIndex(final OutputStream bitmapIndexStream) + public void writeBitmapIndex(OutputStream bitmapIndexStream) throws IOException { if (writeBitmaps == null) throw new IOException(JGitText.get().bitmapsMustBePrepared); @@ -1516,7 +1526,7 @@ public class PackWriter implements AutoCloseable { // The caller gave us an executor, but it might not do // asynchronous execution. Wrap everything and hope it // can schedule these for us. - for (final DeltaTask task : taskBlock.tasks) { + for (DeltaTask task : taskBlock.tasks) { executor.execute(new Runnable() { @Override public void run() { @@ -1723,7 +1733,7 @@ public class PackWriter implements AutoCloseable { typeStats.deltaBytes += out.length() - otp.getOffset(); } - private TemporaryBuffer.Heap delta(final ObjectToPack otp) + private TemporaryBuffer.Heap delta(ObjectToPack otp) throws IOException { DeltaIndex index = new DeltaIndex(buffer(otp.getDeltaBaseId())); byte[] res = buffer(otp); @@ -1960,7 +1970,7 @@ public class PackWriter implements AutoCloseable { byte[] pathBuf = walker.getPathBuffer(); int pathLen = walker.getPathLength(); bases.addBase(o.getType(), pathBuf, pathLen, pathHash); - addObject(o, pathHash); + filterAndAddObject(o, o.getType(), pathHash); countingMonitor.update(1); } } else { @@ -1970,7 +1980,7 @@ public class PackWriter implements AutoCloseable { continue; if (exclude(o)) continue; - addObject(o, walker.getPathHashCode()); + filterAndAddObject(o, o.getType(), walker.getPathHashCode()); countingMonitor.update(1); } } @@ -2003,7 +2013,7 @@ public class PackWriter implements AutoCloseable { needBitmap.remove(objectId); continue; } - addObject(objectId, obj.getType(), 0); + filterAndAddObject(objectId, obj.getType(), 0); } if (thin) @@ -2040,13 +2050,13 @@ public class PackWriter implements AutoCloseable { * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException * the object is an unsupported type. */ - public void addObject(final RevObject object) + public void addObject(RevObject object) throws IncorrectObjectTypeException { if (!exclude(object)) addObject(object, 0); } - private void addObject(final RevObject object, final int pathHashCode) { + private void addObject(RevObject object, int pathHashCode) { addObject(object, object.getType(), pathHashCode); } @@ -2062,6 +2072,21 @@ public class PackWriter implements AutoCloseable { objectsMap.add(otp); } + // Adds the given object as an object to be packed, first performing + // filtering on blobs at or exceeding a given size. + private void filterAndAddObject(@NonNull AnyObjectId src, int type, + int pathHashCode) throws IOException { + + // Check if this object needs to be rejected, doing the cheaper + // checks first. + boolean reject = filterBlobLimit >= 0 && + type == OBJ_BLOB && + reader.getObjectSize(src, OBJ_BLOB) > filterBlobLimit; + if (!reject) { + addObject(src, type, pathHashCode); + } + } + private boolean exclude(AnyObjectId objectId) { if (excludeInPacks == null) return false; @@ -2223,290 +2248,6 @@ public class PackWriter implements AutoCloseable { return true; } - /** - * Summary of how PackWriter created the pack. - * - * @deprecated Use {@link PackStatistics} instead. - */ - @Deprecated - public static class Statistics { - /** Statistics about a single class of object. */ - public static class ObjectType { - // All requests are forwarded to this object. - private PackStatistics.ObjectType objectType; - - /** - * Wraps an - * {@link org.eclipse.jgit.storage.pack.PackStatistics.ObjectType} - * instance to maintain backwards compatibility with existing API. - * - * @param type - * the wrapped instance - */ - public ObjectType(PackStatistics.ObjectType type) { - objectType = type; - } - - /** - * @return total number of objects output. This total includes the - * value of {@link #getDeltas()}. - */ - public long getObjects() { - return objectType.getObjects(); - } - - /** - * @return total number of deltas output. This may be lower than the - * actual number of deltas if a cached pack was reused. - */ - public long getDeltas() { - return objectType.getDeltas(); - } - - /** - * @return number of objects whose existing representation was - * reused in the output. This count includes - * {@link #getReusedDeltas()}. - */ - public long getReusedObjects() { - return objectType.getReusedObjects(); - } - - /** - * @return number of deltas whose existing representation was reused - * in the output, as their base object was also output or - * was assumed present for a thin pack. This may be lower - * than the actual number of reused deltas if a cached pack - * was reused. - */ - public long getReusedDeltas() { - return objectType.getReusedDeltas(); - } - - /** - * @return total number of bytes written. This size includes the - * object headers as well as the compressed data. This size - * also includes all of {@link #getDeltaBytes()}. - */ - public long getBytes() { - return objectType.getBytes(); - } - - /** - * @return number of delta bytes written. This size includes the - * object headers for the delta objects. - */ - public long getDeltaBytes() { - return objectType.getDeltaBytes(); - } - } - - // All requests are forwarded to this object. - private PackStatistics statistics; - - /** - * Wraps a {@link PackStatistics} object to maintain backwards - * compatibility with existing API. - * - * @param stats - * the wrapped PackStatitics object - */ - public Statistics(PackStatistics stats) { - statistics = stats; - } - - /** - * @return unmodifiable collection of objects to be included in the - * pack. May be null if the pack was hand-crafted in a unit - * test. - */ - public Set<ObjectId> getInterestingObjects() { - return statistics.getInterestingObjects(); - } - - /** - * @return unmodifiable collection of objects that should be excluded - * from the pack, as the peer that will receive the pack already - * has these objects. - */ - public Set<ObjectId> getUninterestingObjects() { - return statistics.getUninterestingObjects(); - } - - /** - * @return unmodifiable collection of the cached packs that were reused - * in the output, if any were selected for reuse. - */ - public Collection<CachedPack> getReusedPacks() { - return statistics.getReusedPacks(); - } - - /** - * @return number of objects in the output pack that went through the - * delta search process in order to find a potential delta base. - */ - public int getDeltaSearchNonEdgeObjects() { - return statistics.getDeltaSearchNonEdgeObjects(); - } - - /** - * @return number of objects in the output pack that went through delta - * base search and found a suitable base. This is a subset of - * {@link #getDeltaSearchNonEdgeObjects()}. - */ - public int getDeltasFound() { - return statistics.getDeltasFound(); - } - - /** - * @return total number of objects output. This total includes the value - * of {@link #getTotalDeltas()}. - */ - public long getTotalObjects() { - return statistics.getTotalObjects(); - } - - /** - * @return the count of objects that needed to be discovered through an - * object walk because they were not found in bitmap indices. - * Returns -1 if no bitmap indices were found. - */ - public long getBitmapIndexMisses() { - return statistics.getBitmapIndexMisses(); - } - - /** - * @return total number of deltas output. This may be lower than the - * actual number of deltas if a cached pack was reused. - */ - public long getTotalDeltas() { - return statistics.getTotalDeltas(); - } - - /** - * @return number of objects whose existing representation was reused in - * the output. This count includes {@link #getReusedDeltas()}. - */ - public long getReusedObjects() { - return statistics.getReusedObjects(); - } - - /** - * @return number of deltas whose existing representation was reused in - * the output, as their base object was also output or was - * assumed present for a thin pack. This may be lower than the - * actual number of reused deltas if a cached pack was reused. - */ - public long getReusedDeltas() { - return statistics.getReusedDeltas(); - } - - /** - * @return total number of bytes written. This size includes the pack - * header, trailer, thin pack, and reused cached pack(s). - */ - public long getTotalBytes() { - return statistics.getTotalBytes(); - } - - /** - * @return size of the thin pack in bytes, if a thin pack was generated. - * A thin pack is created when the client already has objects - * and some deltas are created against those objects, or if a - * cached pack is being used and some deltas will reference - * objects in the cached pack. This size does not include the - * pack header or trailer. - */ - public long getThinPackBytes() { - return statistics.getThinPackBytes(); - } - - /** - * @param typeCode - * object type code, e.g. OBJ_COMMIT or OBJ_TREE. - * @return information about this type of object in the pack. - */ - public ObjectType byObjectType(int typeCode) { - return new ObjectType(statistics.byObjectType(typeCode)); - } - - /** @return true if the resulting pack file was a shallow pack. */ - public boolean isShallow() { - return statistics.isShallow(); - } - - /** @return depth (in commits) the pack includes if shallow. */ - public int getDepth() { - return statistics.getDepth(); - } - - /** - * @return time in milliseconds spent enumerating the objects that need - * to be included in the output. This time includes any restarts - * that occur when a cached pack is selected for reuse. - */ - public long getTimeCounting() { - return statistics.getTimeCounting(); - } - - /** - * @return time in milliseconds spent matching existing representations - * against objects that will be transmitted, or that the client - * can be assumed to already have. - */ - public long getTimeSearchingForReuse() { - return statistics.getTimeSearchingForReuse(); - } - - /** - * @return time in milliseconds spent finding the sizes of all objects - * that will enter the delta compression search window. The - * sizes need to be known to better match similar objects - * together and improve delta compression ratios. - */ - public long getTimeSearchingForSizes() { - return statistics.getTimeSearchingForSizes(); - } - - /** - * @return time in milliseconds spent on delta compression. This is - * observed wall-clock time and does not accurately track CPU - * time used when multiple threads were used to perform the - * delta compression. - */ - public long getTimeCompressing() { - return statistics.getTimeCompressing(); - } - - /** - * @return time in milliseconds spent writing the pack output, from - * start of header until end of trailer. The transfer speed can - * be approximated by dividing {@link #getTotalBytes()} by this - * value. - */ - public long getTimeWriting() { - return statistics.getTimeWriting(); - } - - /** @return total time spent processing this pack. */ - public long getTimeTotal() { - return statistics.getTimeTotal(); - } - - /** - * @return get the average output speed in terms of bytes-per-second. - * {@code getTotalBytes() / (getTimeWriting() / 1000.0)}. - */ - public double getTransferRate() { - return statistics.getTransferRate(); - } - - /** @return formatted message string for display to clients. */ - public String getMessage() { - return statistics.getMessage(); - } - } - private class MutableState { /** Estimated size of a single ObjectToPack instance. */ // Assume 64-bit pointers, since this is just an estimate. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java index ce2ba4a2e1..942d72fe23 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.BlockWriter.compare; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; @@ -138,7 +138,7 @@ class BlockReader { if (blockType == LOG_BLOCK_TYPE) { len -= 9; } - return RawParseUtils.decode(UTF_8, nameBuf, 0, len); + return RawParseUtils.decode(CHARSET, nameBuf, 0, len); } boolean match(byte[] match, boolean matchIsPrefix) { @@ -171,7 +171,7 @@ class BlockReader { } Ref readRef() throws IOException { - String name = RawParseUtils.decode(UTF_8, nameBuf, 0, nameLen); + String name = RawParseUtils.decode(CHARSET, nameBuf, 0, nameLen); switch (valueType & VALUE_TYPE_MASK) { case VALUE_NONE: // delete return newRef(name); @@ -266,7 +266,7 @@ class BlockReader { private String readValueString() { int len = readVarint32(); int end = ptr + len; - String s = RawParseUtils.decode(UTF_8, buf, ptr, end); + String s = RawParseUtils.decode(CHARSET, buf, ptr, end); ptr = end; return s; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java index b3173e838c..3d8fbf4996 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; @@ -440,7 +440,7 @@ class BlockWriter { } private static byte[] nameUtf8(Ref ref) { - return ref.getName().getBytes(UTF_8); + return ref.getName().getBytes(CHARSET); } } @@ -559,13 +559,13 @@ class BlockWriter { this.newId = newId; this.timeSecs = who.getWhen().getTime() / 1000L; this.tz = (short) who.getTimeZoneOffset(); - this.name = who.getName().getBytes(UTF_8); - this.email = who.getEmailAddress().getBytes(UTF_8); - this.msg = message.getBytes(UTF_8); + this.name = who.getName().getBytes(CHARSET); + this.email = who.getEmailAddress().getBytes(CHARSET); + this.msg = message.getBytes(CHARSET); } static byte[] key(String ref, long index) { - byte[] name = ref.getBytes(UTF_8); + byte[] name = ref.getBytes(CHARSET); byte[] key = Arrays.copyOf(name, name.length + 1 + 8); NB.encodeInt64(key, key.length - 8, reverseUpdateIndex(index)); return key; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java index 1fc43c9fac..44bbb16219 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE; @@ -160,7 +160,7 @@ class ReftableOutputStream extends OutputStream { } void writeVarintString(String s) { - writeVarintString(s.getBytes(UTF_8)); + writeVarintString(s.getBytes(CHARSET)); } void writeVarintString(byte[] msg) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java index 74877192f6..5356952b5d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.internal.storage.reftable; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.internal.storage.reftable.BlockReader.decodeBlockLen; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_FOOTER_LEN; @@ -182,7 +182,7 @@ public class ReftableReader extends Reftable { public RefCursor seekRef(String refName) throws IOException { initRefIndex(); - byte[] key = refName.getBytes(UTF_8); + byte[] key = refName.getBytes(CHARSET); boolean prefix = key[key.length - 1] == '/'; RefCursorImpl i = new RefCursorImpl(refEnd, key, prefix); @@ -223,7 +223,7 @@ public class ReftableReader extends Reftable { initLogIndex(); if (logPosition > 0) { byte[] key = LogEntry.key(refName, updateIndex); - byte[] match = refName.getBytes(UTF_8); + byte[] match = refName.getBytes(CHARSET); LogCursorImpl i = new LogCursorImpl(logEnd, match); i.block = seek(LOG_BLOCK_TYPE, key, logIndex, logPosition, logEnd); return i; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTree.java index e9aa110419..5751dd6fa6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTree.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTree.java @@ -279,7 +279,7 @@ public class RefTree { return HEAD.equals(n) || Repository.isValidRefName(n); } - private void apply(DirCacheEditor ed, final Command cmd) { + private void apply(DirCacheEditor ed, Command cmd) { String path = refPath(cmd.getRefName()); Ref oldRef = cmd.getOldRef(); final Ref newRef = cmd.getNewRef(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java index 183468fa35..27daaf0bb2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeDatabase.java @@ -282,7 +282,7 @@ public class RefTreeDatabase extends RefDatabase { public List<Ref> getAdditionalRefs() throws IOException { Collection<Ref> txnRefs; if (txnNamespace != null) { - txnRefs = bootstrap.getRefs(txnNamespace).values(); + txnRefs = bootstrap.getRefsByPrefix(txnNamespace); } else { Ref r = bootstrap.exactRef(txnCommitted); if (r != null && r.getObjectId() != null) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java index 425f7f689a..d105d0d200 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AbbreviatedObjectId.java @@ -74,7 +74,7 @@ public final class AbbreviatedObjectId implements Serializable { * the string to test. * @return true if the string can converted into an AbbreviatedObjectId. */ - public static final boolean isId(final String id) { + public static final boolean isId(String id) { if (id.length() < 2 || Constants.OBJECT_ID_STRING_LENGTH < id.length()) return false; try { @@ -131,7 +131,7 @@ public final class AbbreviatedObjectId implements Serializable { * the string to read from. Must be <= 40 characters. * @return the converted object id. */ - public static final AbbreviatedObjectId fromString(final String str) { + public static final AbbreviatedObjectId fromString(String str) { if (str.length() > Constants.OBJECT_ID_STRING_LENGTH) throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidId, str)); final byte[] b = Constants.encodeASCII(str); @@ -165,7 +165,7 @@ public final class AbbreviatedObjectId implements Serializable { return r << (8 - n) * 4; } - static int mask(final int nibbles, final int word, final int v) { + static int mask(int nibbles, int word, int v) { final int b = (word - 1) * 8; if (b + 8 <= nibbles) { // We have all of the bits required for this word. @@ -244,7 +244,7 @@ public final class AbbreviatedObjectId implements Serializable { * >0 if this abbreviation names an object that is after * <code>other</code>. */ - public final int prefixCompare(final AnyObjectId other) { + public final int prefixCompare(AnyObjectId other) { int cmp; cmp = NB.compareUInt32(w1, mask(1, other.w1)); @@ -280,7 +280,7 @@ public final class AbbreviatedObjectId implements Serializable { * >0 if this abbreviation names an object that is after * <code>other</code>. */ - public final int prefixCompare(final byte[] bs, final int p) { + public final int prefixCompare(byte[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, mask(1, NB.decodeInt32(bs, p))); @@ -316,7 +316,7 @@ public final class AbbreviatedObjectId implements Serializable { * >0 if this abbreviation names an object that is after * <code>other</code>. */ - public final int prefixCompare(final int[] bs, final int p) { + public final int prefixCompare(int[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, mask(1, bs[p])); @@ -347,7 +347,7 @@ public final class AbbreviatedObjectId implements Serializable { return w1 >>> 24; } - private int mask(final int word, final int v) { + private int mask(int word, int v) { return mask(nibbles, word, v); } @@ -359,7 +359,7 @@ public final class AbbreviatedObjectId implements Serializable { /** {@inheritDoc} */ @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (o instanceof AbbreviatedObjectId) { final AbbreviatedObjectId b = (AbbreviatedObjectId) o; return nibbles == b.nibbles && w1 == b.w1 && w2 == b.w2 diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java index 58477657f6..978dd3a729 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java @@ -73,17 +73,19 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { if (firstObjectId == secondObjectId) return true; - // We test word 2 first as odds are someone already used our - // word 1 as a hash code, and applying that came up with these - // two instances we are comparing for equality. Therefore the - // first two words are very likely to be identical. We want to - // break away from collisions as quickly as possible. + // We test word 3 first since the git file-based ODB + // uses the first byte of w1, and we use w2 as the + // hash code, one of those probably came up with these + // two instances which we are comparing for equality. + // Therefore the first two words are very likely to be + // identical. We want to break away from collisions as + // quickly as possible. // - return firstObjectId.w2 == secondObjectId.w2 - && firstObjectId.w3 == secondObjectId.w3 + return firstObjectId.w3 == secondObjectId.w3 && firstObjectId.w4 == secondObjectId.w4 && firstObjectId.w5 == secondObjectId.w5 - && firstObjectId.w1 == secondObjectId.w1; + && firstObjectId.w1 == secondObjectId.w1 + && firstObjectId.w2 == secondObjectId.w2; } int w1; @@ -159,7 +161,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * Compare this ObjectId to another and obtain a sort ordering. */ @Override - public final int compareTo(final AnyObjectId other) { + public final int compareTo(AnyObjectId other) { if (this == other) return 0; @@ -195,7 +197,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. */ - public final int compareTo(final byte[] bs, final int p) { + public final int compareTo(byte[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, NB.decodeInt32(bs, p)); @@ -228,7 +230,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @return a negative integer, zero, or a positive integer as this object is * less than, equal to, or greater than the specified object. */ - public final int compareTo(final int[] bs, final int p) { + public final int compareTo(int[] bs, int p) { int cmp; cmp = NB.compareUInt32(w1, bs[p]); @@ -257,7 +259,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * the abbreviation. * @return true if this ObjectId begins with the abbreviation; else false. */ - public boolean startsWith(final AbbreviatedObjectId abbr) { + public boolean startsWith(AbbreviatedObjectId abbr) { return abbr.prefixCompare(this) == 0; } @@ -274,13 +276,13 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * the other id to compare to. May be null. * @return true only if both ObjectIds have identical bits. */ - public final boolean equals(final AnyObjectId other) { + public final boolean equals(AnyObjectId other) { return other != null ? equals(this, other) : false; } /** {@inheritDoc} */ @Override - public final boolean equals(final Object o) { + public final boolean equals(Object o) { if (o instanceof AnyObjectId) return equals((AnyObjectId) o); else @@ -293,7 +295,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @param w * the buffer to copy to. Must be in big endian order. */ - public void copyRawTo(final ByteBuffer w) { + public void copyRawTo(ByteBuffer w) { w.putInt(w1); w.putInt(w2); w.putInt(w3); @@ -309,7 +311,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @param o * the offset within b to write at. */ - public void copyRawTo(final byte[] b, final int o) { + public void copyRawTo(byte[] b, int o) { NB.encodeInt32(b, o, w1); NB.encodeInt32(b, o + 4, w2); NB.encodeInt32(b, o + 8, w3); @@ -325,7 +327,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @param o * the offset within b to write at. */ - public void copyRawTo(final int[] b, final int o) { + public void copyRawTo(int[] b, int o) { b[o] = w1; b[o + 1] = w2; b[o + 2] = w3; @@ -341,7 +343,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @throws java.io.IOException * the stream writing failed. */ - public void copyRawTo(final OutputStream w) throws IOException { + public void copyRawTo(OutputStream w) throws IOException { writeRawInt(w, w1); writeRawInt(w, w2); writeRawInt(w, w3); @@ -349,7 +351,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { writeRawInt(w, w5); } - private static void writeRawInt(final OutputStream w, int v) + private static void writeRawInt(OutputStream w, int v) throws IOException { w.write(v >>> 24); w.write(v >>> 16); @@ -365,7 +367,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @throws java.io.IOException * the stream writing failed. */ - public void copyTo(final OutputStream w) throws IOException { + public void copyTo(OutputStream w) throws IOException { w.write(toHexByteArray()); } @@ -408,7 +410,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { private static final byte[] hexbyte = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - private static void formatHexByte(final byte[] dst, final int p, int w) { + private static void formatHexByte(byte[] dst, int p, int w) { int o = p + 7; while (o >= p && w != 0) { dst[o--] = hexbyte[w & 0xf]; @@ -426,7 +428,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @throws java.io.IOException * the stream writing failed. */ - public void copyTo(final Writer w) throws IOException { + public void copyTo(Writer w) throws IOException { w.write(toHexCharArray()); } @@ -442,7 +444,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @throws java.io.IOException * the stream writing failed. */ - public void copyTo(final char[] tmp, final Writer w) throws IOException { + public void copyTo(char[] tmp, Writer w) throws IOException { toHexCharArray(tmp); w.write(tmp, 0, Constants.OBJECT_ID_STRING_LENGTH); } @@ -457,7 +459,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * @param w * the string to append onto. */ - public void copyTo(final char[] tmp, final StringBuilder w) { + public void copyTo(char[] tmp, StringBuilder w) { toHexCharArray(tmp); w.append(tmp, 0, Constants.OBJECT_ID_STRING_LENGTH); } @@ -468,7 +470,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { return dst; } - private void toHexCharArray(final char[] dst) { + private void toHexCharArray(char[] dst) { formatHexChar(dst, 0, w1); formatHexChar(dst, 8, w2); formatHexChar(dst, 16, w3); @@ -479,7 +481,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { private static final char[] hexchar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - static void formatHexChar(final char[] dst, final int p, int w) { + static void formatHexChar(char[] dst, int p, int w) { int o = p + 7; while (o >= p && w != 0) { dst[o--] = hexchar[w & 0xf]; @@ -527,7 +529,7 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> { * length of the abbreviated string. * @return SHA-1 abbreviation. */ - public AbbreviatedObjectId abbreviate(final int len) { + public AbbreviatedObjectId abbreviate(int len) { final int a = AbbreviatedObjectId.mask(len, 1, w1); final int b = AbbreviatedObjectId.mask(len, 2, w2); final int c = AbbreviatedObjectId.mask(len, 3, w3); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java index 6919f7ef0f..925b6beadb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.lib; import static org.eclipse.jgit.transport.ReceiveCommand.Result.NOT_ATTEMPTED; import static org.eclipse.jgit.transport.ReceiveCommand.Result.REJECTED_OTHER_REASON; +import static java.util.stream.Collectors.toCollection; import java.io.IOException; import java.text.MessageFormat; @@ -179,7 +180,7 @@ public class BatchRefUpdate { * configuration. * @return {@code this}. */ - public BatchRefUpdate setRefLogIdent(final PersonIdent pi) { + public BatchRefUpdate setRefLogIdent(PersonIdent pi) { refLogIdent = pi; return this; } @@ -528,8 +529,9 @@ public class BatchRefUpdate { } if (!commands2.isEmpty()) { // What part of the name space is already taken - Collection<String> takenNames = new HashSet<>(refdb.getRefs( - RefDatabase.ALL).keySet()); + Collection<String> takenNames = refdb.getRefs().stream() + .map(Ref::getName) + .collect(toCollection(HashSet::new)); Collection<String> takenPrefixes = getTakenPrefixes(takenNames); // Now to the update that may require more room in the name space diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java index fc354db113..9f64f3524a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java @@ -121,19 +121,6 @@ public interface BitmapIndex { * return a reference to the current builder. */ public interface BitmapBuilder extends Bitmap { - /** - * Adds the id and the existing bitmap for the id, if one exists, to the - * bitmap. - * - * @param objectId - * the object ID - * @param type - * the Git object type. See {@link Constants}. - * @return true if the value was not contained or able to be loaded. - * @deprecated use {@link #or} or {@link #addObject} instead. - */ - @Deprecated - boolean add(AnyObjectId objectId, int type); /** * Whether the bitmap has the id set. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java index 3ff92dc739..e008be3a3c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.lib; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.FileNotFoundException; import java.io.IOException; import java.text.MessageFormat; @@ -76,13 +78,12 @@ public class BlobBasedConfig extends Config { * @throws org.eclipse.jgit.errors.ConfigInvalidException * the byte array is not a valid configuration format. */ - public BlobBasedConfig(Config base, final byte[] blob) + public BlobBasedConfig(Config base, byte[] blob) throws ConfigInvalidException { super(base); final String decoded; if (isUtf8(blob)) { - decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, - blob, 3, blob.length); + decoded = RawParseUtils.decode(CHARSET, blob, 3, blob.length); } else { decoded = RawParseUtils.decode(blob); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java index 596da0349c..be53c4b4f6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BranchConfig.java @@ -107,7 +107,7 @@ public class BranchConfig { * @param branchName * the short branch name of the section to read */ - public BranchConfig(final Config config, String branchName) { + public BranchConfig(Config config, String branchName) { this.config = config; this.branchName = branchName; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java index 2217fde049..59a13f6550 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java @@ -243,7 +243,7 @@ public class CommitBuilder { * @param newMessage * the commit message. Should not be null. */ - public void setMessage(final String newMessage) { + public void setMessage(String newMessage) { message = newMessage; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 4d558c9fc2..0e01cca99b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -51,6 +51,8 @@ package org.eclipse.jgit.lib; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; @@ -374,7 +376,7 @@ public class Config { } @SuppressWarnings("unchecked") - private static <T> T[] allValuesOf(final T value) { + private static <T> T[] allValuesOf(T value) { try { return (T[]) value.getClass().getMethod("values").invoke(null); //$NON-NLS-1$ } catch (Exception err) { @@ -513,7 +515,7 @@ public class Config { * order they are declared by the configuration starting from this * instance and progressing through the base. */ - public Set<String> getSubsections(final String section) { + public Set<String> getSubsections(String section) { return getState().getSubsections(section); } @@ -599,7 +601,7 @@ public class Config { * @return the parsed object instance, which is cached inside this config. */ @SuppressWarnings("unchecked") - public <T> T get(final SectionParser<T> parser) { + public <T> T get(SectionParser<T> parser) { final ConfigSnapshot myState = getState(); T obj = (T) myState.cache.get(parser); if (obj == null) { @@ -619,7 +621,7 @@ public class Config { * parser used to obtain the configuration object. * @see #get(SectionParser) */ - public void uncache(final SectionParser<?> parser) { + public void uncache(SectionParser<?> parser) { state.get().cache.remove(parser); } @@ -1008,7 +1010,7 @@ public class Config { */ public String toText() { final StringBuilder out = new StringBuilder(); - for (final ConfigLine e : state.get().entryList) { + for (ConfigLine e : state.get().entryList) { if (e.prefix != null) out.append(e.prefix); if (e.section != null && e.name == null) { @@ -1057,11 +1059,11 @@ public class Config { * the text supplied is not formatted correctly. No changes were * made to {@code this}. */ - public void fromText(final String text) throws ConfigInvalidException { + public void fromText(String text) throws ConfigInvalidException { state.set(newState(fromTextRecurse(text, 1))); } - private List<ConfigLine> fromTextRecurse(final String text, int depth) + private List<ConfigLine> fromTextRecurse(String text, int depth) throws ConfigInvalidException { if (depth > MAX_DEPTH) { throw new ConfigInvalidException( @@ -1166,8 +1168,7 @@ public class Config { String decoded; if (isUtf8(bytes)) { - decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, bytes, 3, - bytes.length); + decoded = RawParseUtils.decode(CHARSET, bytes, 3, bytes.length); } else { decoded = RawParseUtils.decode(bytes); } @@ -1184,7 +1185,7 @@ public class Config { getBaseState()); } - private ConfigSnapshot newState(final List<ConfigLine> entries) { + private ConfigSnapshot newState(List<ConfigLine> entries) { return new ConfigSnapshot(Collections.unmodifiableList(entries), getBaseState()); } @@ -1209,7 +1210,7 @@ public class Config { && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF; } - private static String readSectionName(final StringReader in) + private static String readSectionName(StringReader in) throws ConfigInvalidException { final StringBuilder name = new StringBuilder(); for (;;) { @@ -1248,7 +1249,7 @@ public class Config { return name.toString(); } - private static String readKeyName(final StringReader in) + private static String readKeyName(StringReader in) throws ConfigInvalidException { final StringBuilder name = new StringBuilder(); for (;;) { @@ -1335,7 +1336,7 @@ public class Config { return r.toString(); } - private static String readValue(final StringReader in) + private static String readValue(StringReader in) throws ConfigInvalidException { StringBuilder value = new StringBuilder(); StringBuilder trailingSpaces = null; @@ -1451,7 +1452,7 @@ public class Config { private int pos; - StringReader(final String in) { + StringReader(String in) { buf = in.toCharArray(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigLine.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigLine.java index d5f1d8f085..937ba925c5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigLine.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigLine.java @@ -73,7 +73,7 @@ class ConfigLine { /** The text content after entry. */ String suffix; - ConfigLine forValue(final String newValue) { + ConfigLine forValue(String newValue) { final ConfigLine e = new ConfigLine(); e.prefix = prefix; e.section = section; @@ -91,12 +91,12 @@ class ConfigLine { && eqIgnoreCase(name, aKey); } - boolean match(final String aSection, final String aSubsection) { + boolean match(String aSection, String aSubsection) { return eqIgnoreCase(section, aSection) && eqSameCase(subsection, aSubsection); } - private static boolean eqIgnoreCase(final String a, final String b) { + private static boolean eqIgnoreCase(String a, String b) { if (a == null && b == null) return true; if (a == null || b == null) @@ -104,7 +104,7 @@ class ConfigLine { return StringUtils.equalsIgnoreCase(a, b); } - private static boolean eqSameCase(final String a, final String b) { + private static boolean eqSameCase(String a, String b) { if (a == null && b == null) return true; if (a == null || b == null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index bb85229f82..ecebd54089 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.security.MessageDigest; @@ -226,10 +228,10 @@ public final class Constants { public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' }; /** Native character encoding for commit messages, file names... */ - public static final String CHARACTER_ENCODING = "UTF-8"; + public static final Charset CHARSET; /** Native character encoding for commit messages, file names... */ - public static final Charset CHARSET; + public static final String CHARACTER_ENCODING; /** Default main branch name */ public static final String MASTER = "master"; @@ -475,7 +477,7 @@ public final class Constants { * @param typeCode the type code, from a pack representation. * @return the canonical string name of this type. */ - public static String typeString(final int typeCode) { + public static String typeString(int typeCode) { switch (typeCode) { case OBJ_COMMIT: return TYPE_COMMIT; @@ -500,7 +502,7 @@ public final class Constants { * @param typeCode the type code, from a pack representation. * @return the canonical ASCII encoded name of this type. */ - public static byte[] encodedTypeString(final int typeCode) { + public static byte[] encodedTypeString(int typeCode) { switch (typeCode) { case OBJ_COMMIT: return ENCODED_TYPE_COMMIT; @@ -599,7 +601,7 @@ public final class Constants { * @return a decimal representation of the input integer. The returned array * is the smallest array that will hold the value. */ - public static byte[] encodeASCII(final long s) { + public static byte[] encodeASCII(long s) { return encodeASCII(Long.toString(s)); } @@ -615,7 +617,7 @@ public final class Constants { * the input string contains one or more characters outside of * the 7-bit ASCII character space. */ - public static byte[] encodeASCII(final String s) { + public static byte[] encodeASCII(String s) { final byte[] r = new byte[s.length()]; for (int k = r.length - 1; k >= 0; k--) { final char c = s.charAt(k); @@ -635,7 +637,7 @@ public final class Constants { * default character encoding (UTF-8). * @see #CHARACTER_ENCODING */ - public static byte[] encode(final String str) { + public static byte[] encode(String str) { final ByteBuffer bb = Constants.CHARSET.encode(str); final int len = bb.limit(); if (bb.hasArray() && bb.arrayOffset() == 0) { @@ -652,7 +654,8 @@ public final class Constants { static { if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength()) throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH); - CHARSET = Charset.forName(CHARACTER_ENCODING); + CHARSET = UTF_8; + CHARACTER_ENCODING = CHARSET.name(); } /** name of the file containing the commit msg for a merge commit */ @@ -688,6 +691,13 @@ public final class Constants { public static final ObjectId EMPTY_BLOB_ID = ObjectId .fromString("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"); + /** + * Suffix of lock file name + * + * @since 5.0 + */ + public static final String LOCK_SUFFIX = ".lock"; //$NON-NLS-1$ + private Constants() { // Hide the default constructor } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CoreConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CoreConfig.java index 32a894f795..98de3a91cc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CoreConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CoreConfig.java @@ -166,7 +166,7 @@ public class CoreConfig { DOTGITONLY } - private CoreConfig(final Config rc) { + private CoreConfig(Config rc) { compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION); packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java index 68f881dd1e..891c7f23b4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java @@ -270,8 +270,8 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter { } } - private static boolean match(final String a, final String... cases) { - for (final String b : cases) { + private static boolean match(String a, String... cases) { + for (String b : cases) { if (b != null && b.equalsIgnoreCase(a)) { return true; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileMode.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileMode.java index 7852371648..d4c4d5b40d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileMode.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/FileMode.java @@ -88,7 +88,7 @@ public abstract class FileMode { public static final FileMode TREE = new FileMode(TYPE_TREE, Constants.OBJ_TREE) { @Override - public boolean equals(final int modeBits) { + public boolean equals(int modeBits) { return (modeBits & TYPE_MASK) == TYPE_TREE; } }; @@ -97,7 +97,7 @@ public abstract class FileMode { public static final FileMode SYMLINK = new FileMode(TYPE_SYMLINK, Constants.OBJ_BLOB) { @Override - public boolean equals(final int modeBits) { + public boolean equals(int modeBits) { return (modeBits & TYPE_MASK) == TYPE_SYMLINK; } }; @@ -106,7 +106,7 @@ public abstract class FileMode { public static final FileMode REGULAR_FILE = new FileMode(0100644, Constants.OBJ_BLOB) { @Override - public boolean equals(final int modeBits) { + public boolean equals(int modeBits) { return (modeBits & TYPE_MASK) == TYPE_FILE && (modeBits & 0111) == 0; } }; @@ -115,7 +115,7 @@ public abstract class FileMode { public static final FileMode EXECUTABLE_FILE = new FileMode(0100755, Constants.OBJ_BLOB) { @Override - public boolean equals(final int modeBits) { + public boolean equals(int modeBits) { return (modeBits & TYPE_MASK) == TYPE_FILE && (modeBits & 0111) != 0; } }; @@ -124,7 +124,7 @@ public abstract class FileMode { public static final FileMode GITLINK = new FileMode(TYPE_GITLINK, Constants.OBJ_COMMIT) { @Override - public boolean equals(final int modeBits) { + public boolean equals(int modeBits) { return (modeBits & TYPE_MASK) == TYPE_GITLINK; } }; @@ -133,7 +133,7 @@ public abstract class FileMode { public static final FileMode MISSING = new FileMode(TYPE_MISSING, Constants.OBJ_BAD) { @Override - public boolean equals(final int modeBits) { + public boolean equals(int modeBits) { return modeBits == 0; } }; @@ -145,7 +145,7 @@ public abstract class FileMode { * the mode bits the caller has somehow obtained. * @return the FileMode instance that represents the given bits. */ - public static final FileMode fromBits(final int bits) { + public static final FileMode fromBits(int bits) { switch (bits & TYPE_MASK) { case TYPE_MISSING: if (bits == 0) @@ -165,7 +165,7 @@ public abstract class FileMode { return new FileMode(bits, Constants.OBJ_BAD) { @Override - public boolean equals(final int a) { + public boolean equals(int a) { return bits == a; } }; @@ -177,7 +177,7 @@ public abstract class FileMode { private final int objectType; - private FileMode(int mode, final int expType) { + private FileMode(int mode, int expType) { modeBits = mode; objectType = expType; if (mode != 0) { @@ -206,7 +206,7 @@ public abstract class FileMode { * a int. * @return true if the mode bits represent the same mode as this object */ - public abstract boolean equals(final int modebits); + public abstract boolean equals(int modebits); /** * Copy this mode as a sequence of octal US-ASCII bytes. @@ -222,7 +222,7 @@ public abstract class FileMode { * @throws java.io.IOException * the stream encountered an error during the copy. */ - public void copyTo(final OutputStream os) throws IOException { + public void copyTo(OutputStream os) throws IOException { os.write(octalBytes); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java index 87086cbde0..94b9ddc188 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java @@ -542,10 +542,9 @@ public class IndexDiff { JGitText.get().invalidIgnoreParamSubmodule, smw.getPath()), e); } - Repository subRepo = smw.getRepository(); - if (subRepo != null) { - String subRepoPath = smw.getPath(); - try { + try (Repository subRepo = smw.getRepository()) { + if (subRepo != null) { + String subRepoPath = smw.getPath(); ObjectId subHead = subRepo.resolve("HEAD"); //$NON-NLS-1$ if (subHead != null && !subHead.equals(smw.getObjectId())) { @@ -574,8 +573,6 @@ public class IndexDiff { recordFileMode(subRepoPath, FileMode.GITLINK); } } - } finally { - subRepo.close(); } } } @@ -745,7 +742,7 @@ public class IndexDiff { * @param path a {@link java.lang.String} object. * @return file mode */ - public FileMode getIndexMode(final String path) { + public FileMode getIndexMode(String path) { final DirCacheEntry entry = dirCache.getEntry(path); return entry != null ? entry.getFileMode() : FileMode.MISSING; } @@ -759,7 +756,7 @@ public class IndexDiff { * the given file mode * @since 3.6 */ - public Set<String> getPathsWithIndexMode(final FileMode mode) { + public Set<String> getPathsWithIndexMode(FileMode mode) { Set<String> paths = fileModes.get(mode); if (paths == null) paths = new HashSet<>(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/InflaterCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/InflaterCache.java index a97721c732..dd0f18e165 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/InflaterCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/InflaterCache.java @@ -89,7 +89,7 @@ public class InflaterCache { * the inflater to return. May be null, in which case this method * does nothing. */ - public static void release(final Inflater i) { + public static void release(Inflater i) { if (i != null) { i.reset(); if (releaseImpl(i)) @@ -97,7 +97,7 @@ public class InflaterCache { } } - private static synchronized boolean releaseImpl(final Inflater i) { + private static synchronized boolean releaseImpl(Inflater i) { if (openInflaterCount < SZ) { inflaterCache[openInflaterCount++] = i; return false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java index e492af94b9..8cf0fd05c4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/MutableObjectId.java @@ -162,7 +162,7 @@ public class MutableObjectId extends AnyObjectId { * the raw byte buffer to read from. At least 20 bytes must be * available within this byte array. */ - public void fromRaw(final byte[] bs) { + public void fromRaw(byte[] bs) { fromRaw(bs, 0); } @@ -175,7 +175,7 @@ public class MutableObjectId extends AnyObjectId { * @param p * position to read the first byte of data from. */ - public void fromRaw(final byte[] bs, final int p) { + public void fromRaw(byte[] bs, int p) { w1 = NB.decodeInt32(bs, p); w2 = NB.decodeInt32(bs, p + 4); w3 = NB.decodeInt32(bs, p + 8); @@ -190,7 +190,7 @@ public class MutableObjectId extends AnyObjectId { * the raw int buffer to read from. At least 5 integers must be * available within this integers array. */ - public void fromRaw(final int[] ints) { + public void fromRaw(int[] ints) { fromRaw(ints, 0); } @@ -203,7 +203,7 @@ public class MutableObjectId extends AnyObjectId { * @param p * position to read the first integer of data from. */ - public void fromRaw(final int[] ints, final int p) { + public void fromRaw(int[] ints, int p) { w1 = ints[p]; w2 = ints[p + 1]; w3 = ints[p + 2]; @@ -243,7 +243,7 @@ public class MutableObjectId extends AnyObjectId { * @param offset * position to read the first character from. */ - public void fromString(final byte[] buf, final int offset) { + public void fromString(byte[] buf, int offset) { fromHexString(buf, offset); } @@ -253,14 +253,14 @@ public class MutableObjectId extends AnyObjectId { * @param str * the string to read from. Must be 40 characters long. */ - public void fromString(final String str) { + public void fromString(String str) { if (str.length() != Constants.OBJECT_ID_STRING_LENGTH) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidId, str)); fromHexString(Constants.encodeASCII(str), 0); } - private void fromHexString(final byte[] bs, int p) { + private void fromHexString(byte[] bs, int p) { try { w1 = RawParseUtils.parseHexInt32(bs, p); w2 = RawParseUtils.parseHexInt32(bs, p + 8); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java index a6d2c3f22c..689659b398 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java @@ -1105,7 +1105,7 @@ public class ObjectChecker { * @throws org.eclipse.jgit.errors.CorruptObjectException * if any error was detected. */ - public void checkBlob(final byte[] raw) throws CorruptObjectException { + public void checkBlob(byte[] raw) throws CorruptObjectException { // We can always assume the blob is valid. } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDatabase.java index bbef51da20..93add5c661 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectDatabase.java @@ -121,8 +121,8 @@ public abstract class ObjectDatabase { * @throws java.io.IOException * the object store cannot be accessed. */ - public boolean has(final AnyObjectId objectId) throws IOException { - try (final ObjectReader or = newReader()) { + public boolean has(AnyObjectId objectId) throws IOException { + try (ObjectReader or = newReader()) { return or.has(objectId); } } @@ -141,7 +141,7 @@ public abstract class ObjectDatabase { * @throws java.io.IOException * the object store cannot be accessed. */ - public ObjectLoader open(final AnyObjectId objectId) + public ObjectLoader open(AnyObjectId objectId) throws IOException { return open(objectId, ObjectReader.OBJ_ANY); } @@ -172,7 +172,7 @@ public abstract class ObjectDatabase { public ObjectLoader open(AnyObjectId objectId, int typeHint) throws MissingObjectException, IncorrectObjectTypeException, IOException { - try (final ObjectReader or = newReader()) { + try (ObjectReader or = newReader()) { return or.open(objectId, typeHint); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java index 0e85545531..764f890158 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectId.java @@ -86,7 +86,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * the string to test. * @return true if the string can converted into an ObjectId. */ - public static final boolean isId(final String id) { + public static final boolean isId(String id) { if (id.length() != Constants.OBJECT_ID_STRING_LENGTH) return false; try { @@ -106,7 +106,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * the id to convert. May be null. * @return the hex string conversion of this id's content. */ - public static final String toString(final ObjectId i) { + public static final String toString(ObjectId i) { return i != null ? i.name() : ZEROID_STR; } @@ -157,7 +157,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * available within this byte array. * @return the converted object id. */ - public static final ObjectId fromRaw(final byte[] bs) { + public static final ObjectId fromRaw(byte[] bs) { return fromRaw(bs, 0); } @@ -171,7 +171,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * position to read the first byte of data from. * @return the converted object id. */ - public static final ObjectId fromRaw(final byte[] bs, final int p) { + public static final ObjectId fromRaw(byte[] bs, int p) { final int a = NB.decodeInt32(bs, p); final int b = NB.decodeInt32(bs, p + 4); final int c = NB.decodeInt32(bs, p + 8); @@ -188,7 +188,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * be available within this int array. * @return the converted object id. */ - public static final ObjectId fromRaw(final int[] is) { + public static final ObjectId fromRaw(int[] is) { return fromRaw(is, 0); } @@ -202,7 +202,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * position to read the first integer of data from. * @return the converted object id. */ - public static final ObjectId fromRaw(final int[] is, final int p) { + public static final ObjectId fromRaw(int[] is, int p) { return new ObjectId(is[p], is[p + 1], is[p + 2], is[p + 3], is[p + 4]); } @@ -216,7 +216,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * position to read the first character from. * @return the converted object id. */ - public static final ObjectId fromString(final byte[] buf, final int offset) { + public static final ObjectId fromString(byte[] buf, int offset) { return fromHexString(buf, offset); } @@ -227,14 +227,14 @@ public class ObjectId extends AnyObjectId implements Serializable { * the string to read from. Must be 40 characters long. * @return the converted object id. */ - public static ObjectId fromString(final String str) { + public static ObjectId fromString(String str) { if (str.length() != Constants.OBJECT_ID_STRING_LENGTH) { throw new InvalidObjectIdException(str); } return fromHexString(Constants.encodeASCII(str), 0); } - private static final ObjectId fromHexString(final byte[] bs, int p) { + private static final ObjectId fromHexString(byte[] bs, int p) { try { final int a = RawParseUtils.parseHexInt32(bs, p); final int b = RawParseUtils.parseHexInt32(bs, p + 8); @@ -281,7 +281,7 @@ public class ObjectId extends AnyObjectId implements Serializable { * @param src * another already parsed ObjectId to copy the value out of. */ - protected ObjectId(final AnyObjectId src) { + protected ObjectId(AnyObjectId src) { w1 = src.w1; w2 = src.w2; w3 = src.w3; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdOwnerMap.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdOwnerMap.java index 03a430cab6..9df593375d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdOwnerMap.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdOwnerMap.java @@ -134,7 +134,7 @@ public class ObjectIdOwnerMap<V extends ObjectIdOwnerMap.Entry> * @return the instance mapped to toFind, or null if no mapping exists. */ @SuppressWarnings("unchecked") - public V get(final AnyObjectId toFind) { + public V get(AnyObjectId toFind) { int h = toFind.w1; V obj = directory[h & mask][h >>> SEGMENT_SHIFT]; for (; obj != null; obj = (V) obj.next) @@ -149,7 +149,7 @@ public class ObjectIdOwnerMap<V extends ObjectIdOwnerMap.Entry> * Returns true if this map contains the specified object. */ @Override - public boolean contains(final AnyObjectId toFind) { + public boolean contains(AnyObjectId toFind) { return get(toFind) != null; } @@ -163,7 +163,7 @@ public class ObjectIdOwnerMap<V extends ObjectIdOwnerMap.Entry> * @param newValue * the object to store. */ - public <Q extends V> void add(final Q newValue) { + public <Q extends V> void add(Q newValue) { if (++size == grow) grow(); @@ -194,7 +194,7 @@ public class ObjectIdOwnerMap<V extends ObjectIdOwnerMap.Entry> * {@code get(newValue)} first. */ @SuppressWarnings("unchecked") - public <Q extends V> V addIfAbsent(final Q newValue) { + public <Q extends V> V addIfAbsent(Q newValue) { int h = newValue.w1; V[] table = directory[h & mask]; h >>>= SEGMENT_SHIFT; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java index 001aa9cdd6..cd57bda82e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java @@ -96,7 +96,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> * the object identifier to find. * @return the instance mapped to toFind, or null if no mapping exists. */ - public V get(final AnyObjectId toFind) { + public V get(AnyObjectId toFind) { final int msk = mask; int i = toFind.w1 & msk; final V[] tbl = table; @@ -116,7 +116,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> * Returns true if this map contains the specified object. */ @Override - public boolean contains(final AnyObjectId toFind) { + public boolean contains(AnyObjectId toFind) { return get(toFind) != null; } @@ -131,7 +131,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> * @param newValue * the object to store. */ - public <Q extends V> void add(final Q newValue) { + public <Q extends V> void add(Q newValue) { if (++size == grow) grow(); insert(newValue); @@ -155,7 +155,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> * that would have been returned had the caller used * {@code get(newValue)} first. */ - public <Q extends V> V addIfAbsent(final Q newValue) { + public <Q extends V> V addIfAbsent(Q newValue) { final int msk = mask; int i = newValue.w1 & msk; final V[] tbl = table; @@ -226,7 +226,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> }; } - private void insert(final V newValue) { + private void insert(V newValue) { final int msk = mask; int j = newValue.w1 & msk; final V[] tbl = table; @@ -254,7 +254,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> } @SuppressWarnings("unchecked") - private final V[] createArray(final int sz) { + private final V[] createArray(int sz) { return (V[]) new ObjectId[sz]; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java index 40522ba244..77fa1b2346 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java @@ -361,7 +361,7 @@ public abstract class ObjectInserter implements AutoCloseable { * @throws java.io.IOException * the object could not be stored. */ - public ObjectId insert(final int type, final byte[] data) + public ObjectId insert(int type, byte[] data) throws IOException { return insert(type, data, 0, data.length); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java index 432f5a6cd9..2e52f031cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java @@ -194,8 +194,7 @@ public abstract class ObjectLoader { if (!isLarge()) return getCachedBytes(); - ObjectStream in = openStream(); - try { + try (ObjectStream in = openStream()) { long sz = in.getSize(); if (sizeLimit < sz) throw new LargeObjectException.ExceedsLimit(sizeLimit, sz); @@ -212,8 +211,6 @@ public abstract class ObjectLoader { IO.readFully(in, buf, 0, buf.length); return buf; - } finally { - in.close(); } } @@ -255,8 +252,7 @@ public abstract class ObjectLoader { public void copyTo(OutputStream out) throws MissingObjectException, IOException { if (isLarge()) { - ObjectStream in = openStream(); - try { + try (ObjectStream in = openStream()) { final long sz = in.getSize(); byte[] tmp = new byte[8192]; long copied = 0; @@ -269,15 +265,13 @@ public abstract class ObjectLoader { } if (0 <= in.read()) throw new EOFException(); - } finally { - in.close(); } } else { out.write(getCachedBytes()); } } - private static byte[] cloneArray(final byte[] data) { + private static byte[] cloneArray(byte[] data) { final byte[] copy = new byte[data.length]; System.arraycopy(data, 0, copy, 0, data.length); return copy; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java index 18a11f0015..c16a2b6ab4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java @@ -167,7 +167,7 @@ public class PersonIdent implements Serializable { * * @param repo a {@link org.eclipse.jgit.lib.Repository} object. */ - public PersonIdent(final Repository repo) { + public PersonIdent(Repository repo) { this(repo.getConfig().get(UserConfig.KEY)); } @@ -177,7 +177,7 @@ public class PersonIdent implements Serializable { * @param pi * Original {@link org.eclipse.jgit.lib.PersonIdent} */ - public PersonIdent(final PersonIdent pi) { + public PersonIdent(PersonIdent pi) { this(pi.getName(), pi.getEmailAddress()); } @@ -190,7 +190,7 @@ public class PersonIdent implements Serializable { * @param aEmailAddress * a {@link java.lang.String} object. */ - public PersonIdent(final String aName, final String aEmailAddress) { + public PersonIdent(String aName, String aEmailAddress) { this(aName, aEmailAddress, SystemReader.getInstance().getCurrentTime()); } @@ -221,7 +221,7 @@ public class PersonIdent implements Serializable { * @param tz * time zone */ - public PersonIdent(final PersonIdent pi, final Date when, final TimeZone tz) { + public PersonIdent(PersonIdent pi, Date when, TimeZone tz) { this(pi.getName(), pi.getEmailAddress(), when, tz); } @@ -234,7 +234,7 @@ public class PersonIdent implements Serializable { * @param aWhen * local time */ - public PersonIdent(final PersonIdent pi, final Date aWhen) { + public PersonIdent(PersonIdent pi, Date aWhen) { this(pi.getName(), pi.getEmailAddress(), aWhen.getTime(), pi.tzOffset); } @@ -264,7 +264,7 @@ public class PersonIdent implements Serializable { * @param aTZ * time zone */ - public PersonIdent(final PersonIdent pi, final long aWhen, final int aTZ) { + public PersonIdent(PersonIdent pi, long aWhen, int aTZ) { this(pi.getName(), pi.getEmailAddress(), aWhen, aTZ); } @@ -274,7 +274,7 @@ public class PersonIdent implements Serializable { .getTimezone(when)); } - private PersonIdent(final UserConfig config) { + private PersonIdent(UserConfig config) { this(config.getCommitterName(), config.getCommitterEmail()); } @@ -370,7 +370,7 @@ public class PersonIdent implements Serializable { /** {@inheritDoc} */ @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { if (o instanceof PersonIdent) { final PersonIdent p = (PersonIdent) o; return getName().equals(p.getName()) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java index 06b4b227c8..38716055b5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.lib; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedOutputStream; import java.io.File; @@ -183,7 +183,7 @@ public class RebaseTodoFile { switch (tokenCount) { case 0: String actionToken = new String(buf, tokenBegin, - nextSpace - tokenBegin - 1, UTF_8); + nextSpace - tokenBegin - 1, CHARSET); tokenBegin = nextSpace; action = RebaseTodoLine.Action.parse(actionToken); if (action == null) @@ -192,7 +192,7 @@ public class RebaseTodoFile { case 1: nextSpace = RawParseUtils.next(buf, tokenBegin, ' '); String commitToken = new String(buf, tokenBegin, - nextSpace - tokenBegin - 1, UTF_8); + nextSpace - tokenBegin - 1, CHARSET); tokenBegin = nextSpace; commit = AbbreviatedObjectId.fromString(commitToken); break; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java index 395bb323de..b000558944 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Ref.java @@ -105,7 +105,7 @@ public interface Ref { private final boolean packed; - private Storage(final boolean l, final boolean p) { + private Storage(boolean l, boolean p) { loose = l; packed = p; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefComparator.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefComparator.java index 43d2f3766c..8bcac00876 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefComparator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefComparator.java @@ -62,7 +62,7 @@ public class RefComparator implements Comparator<Ref> { /** {@inheritDoc} */ @Override - public int compare(final Ref o1, final Ref o2) { + public int compare(Ref o1, Ref o2) { return compareTo(o1, o2); } @@ -73,7 +73,7 @@ public class RefComparator implements Comparator<Ref> { * collection to be sorted * @return sorted collection of refs */ - public static Collection<Ref> sort(final Collection<Ref> refs) { + public static Collection<Ref> sort(Collection<Ref> refs) { final List<Ref> r = new ArrayList<>(refs); Collections.sort(r, INSTANCE); return r; @@ -101,7 +101,7 @@ public class RefComparator implements Comparator<Ref> { * the other reference instance. * @return standard Comparator result of < 0, 0, > 0. */ - public static int compareTo(final Ref o1, final Ref o2) { + public static int compareTo(Ref o1, Ref o2) { return o1.getName().compareTo(o2.getName()); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java index 557bdb994f..3170787dd9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.lib; +import static java.util.stream.Collectors.toList; + import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -89,7 +91,10 @@ public abstract class RefDatabase { */ public static final int MAX_SYMBOLIC_REF_DEPTH = 5; - /** Magic value for {@link #getRefs(String)} to return all references. */ + /** + * Magic value for {@link #getRefsByPrefix(String)} to return all + * references. + */ public static final String ALL = "";//$NON-NLS-1$ /** @@ -332,6 +337,29 @@ public abstract class RefDatabase { } /** + * Returns all refs. + * <p> + * This includes {@code HEAD}, branches under {@code ref/heads/}, tags + * under {@code refs/tags/}, etc. It does not include pseudo-refs like + * {@code FETCH_HEAD}; for those, see {@link #getAdditionalRefs}. + * <p> + * Symbolic references to a non-existent ref (for example, + * {@code HEAD} pointing to a branch yet to be born) are not included. + * <p> + * Callers interested in only a portion of the ref hierarchy can call + * {@link #getRefsByPrefix} instead. + * + * @return immutable list of all refs. + * @throws java.io.IOException + * the reference space cannot be accessed. + * @since 5.0 + */ + @NonNull + public List<Ref> getRefs() throws IOException { + return getRefsByPrefix(ALL); + } + + /** * Get a section of the reference namespace. * * @param prefix @@ -343,16 +371,73 @@ public abstract class RefDatabase { * of each key. The map can be an unsorted map. * @throws java.io.IOException * the reference space cannot be accessed. + * @deprecated use {@link #getRefsByPrefix} instead */ @NonNull + @Deprecated public abstract Map<String, Ref> getRefs(String prefix) throws IOException; /** + * Returns refs whose names start with a given prefix. + * <p> + * The default implementation uses {@link #getRefs(String)}. Implementors of + * {@link RefDatabase} should override this method directly if a better + * implementation is possible. + * + * @param prefix string that names of refs should start with; may be + * empty (to return all refs). + * @return immutable list of refs whose names start with {@code prefix}. + * @throws java.io.IOException + * the reference space cannot be accessed. + * @since 5.0 + */ + @NonNull + public List<Ref> getRefsByPrefix(String prefix) throws IOException { + Map<String, Ref> coarseRefs; + int lastSlash = prefix.lastIndexOf('/'); + if (lastSlash == -1) { + coarseRefs = getRefs(ALL); + } else { + coarseRefs = getRefs(prefix.substring(0, lastSlash + 1)); + } + + List<Ref> result; + if (lastSlash + 1 == prefix.length()) { + result = coarseRefs.values().stream().collect(toList()); + } else { + String p = prefix.substring(lastSlash + 1); + result = coarseRefs.entrySet().stream() + .filter(e -> e.getKey().startsWith(p)) + .map(e -> e.getValue()) + .collect(toList()); + } + return Collections.unmodifiableList(result); + } + + /** + * Check if any refs exist in the ref database. + * <p> + * This uses the same definition of refs as {@link #getRefs()}. In + * particular, returns {@code false} in a new repository with no refs + * under {@code refs/} and {@code HEAD} pointing to a branch yet to be + * born, and returns {@code true} in a repository with no refs under + * {@code refs/} and a detached {@code HEAD} pointing to history. + * + * @return true if the database has refs. + * @throws java.io.IOException + * the reference space cannot be accessed. + * @since 5.0 + */ + public boolean hasRefs() throws IOException { + return !getRefs().isEmpty(); + } + + /** * Get the additional reference-like entities from the repository. * <p> * The result list includes non-ref items such as MERGE_HEAD and * FETCH_RESULT cast to be refs. The names of these refs are not returned by - * <code>getRefs(ALL)</code> but are accepted by {@link #getRef(String)} + * <code>getRefs()</code> but are accepted by {@link #getRef(String)} * and {@link #exactRef(String)}. * * @return a list of additional refs diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefRename.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefRename.java index 3d22bb0fc5..a05daa00ab 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefRename.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefRename.java @@ -73,7 +73,7 @@ public abstract class RefRename { * @param dst * operation to create (or overwrite) the destination. */ - protected RefRename(final RefUpdate src, final RefUpdate dst) { + protected RefRename(RefUpdate src, RefUpdate dst) { source = src; destination = dst; @@ -107,7 +107,7 @@ public abstract class RefRename { * automatically determined based on the repository * configuration. */ - public void setRefLogIdent(final PersonIdent pi) { + public void setRefLogIdent(PersonIdent pi) { destination.setRefLogIdent(pi); } @@ -127,7 +127,7 @@ public abstract class RefRename { * @param msg * the message to describe this change. */ - public void setRefLogMessage(final String msg) { + public void setRefLogMessage(String msg) { if (msg == null) disableRefLog(); else diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java index 06a7576db1..5cd593ed5e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java @@ -227,7 +227,7 @@ public abstract class RefUpdate { * @param ref * the reference that will be updated by this operation. */ - protected RefUpdate(final Ref ref) { + protected RefUpdate(Ref ref) { this.ref = ref; oldValue = ref.getObjectId(); refLogMessage = ""; //$NON-NLS-1$ @@ -350,7 +350,7 @@ public abstract class RefUpdate { * @param id * the new value. */ - public void setNewObjectId(final AnyObjectId id) { + public void setNewObjectId(AnyObjectId id) { newValue = id.copy(); } @@ -377,7 +377,7 @@ public abstract class RefUpdate { * Use {@link org.eclipse.jgit.lib.ObjectId#zeroId()} to indicate * expectation of a non-existant ref. */ - public void setExpectedOldObjectId(final AnyObjectId id) { + public void setExpectedOldObjectId(AnyObjectId id) { expValue = id != null ? id.toObjectId() : null; } @@ -396,7 +396,7 @@ public abstract class RefUpdate { * @param b * true if this update should ignore merge tests. */ - public void setForceUpdate(final boolean b) { + public void setForceUpdate(boolean b) { force = b; } @@ -421,7 +421,7 @@ public abstract class RefUpdate { * automatically determined based on the repository * configuration. */ - public void setRefLogIdent(final PersonIdent pi) { + public void setRefLogIdent(PersonIdent pi) { refLogIdent = pi; } @@ -461,7 +461,7 @@ public abstract class RefUpdate { * forced-update) should be appended to the user supplied * message. */ - public void setRefLogMessage(final String msg, final boolean appendStatus) { + public void setRefLogMessage(String msg, boolean appendStatus) { if (msg == null && !appendStatus) disableRefLog(); else if (msg == null && appendStatus) { @@ -615,7 +615,7 @@ public abstract class RefUpdate { * @throws java.io.IOException * an unexpected IO error occurred while writing changes. */ - public Result update(final RevWalk walk) throws IOException { + public Result update(RevWalk walk) throws IOException { requireCanDoUpdate(); try { return result = updateImpl(walk, new Store() { @@ -659,7 +659,7 @@ public abstract class RefUpdate { * @return the result status of the delete. * @throws java.io.IOException */ - public Result delete(final RevWalk walk) throws IOException { + public Result delete(RevWalk walk) throws IOException { final String myName = detachingSymbolicRef ? getRef().getName() : getRef().getLeaf().getName(); @@ -731,7 +731,7 @@ public abstract class RefUpdate { } } - private Result updateImpl(final RevWalk walk, final Store store) + private Result updateImpl(RevWalk walk, Store store) throws IOException { RevObject newObj; RevObject oldObj; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefWriter.java index 90a0350dd7..71ee96363c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RefWriter.java @@ -116,7 +116,7 @@ public abstract class RefWriter { public void writeInfoRefs() throws IOException { final StringWriter w = new StringWriter(); final char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH]; - for (final Ref r : refs) { + for (Ref r : refs) { if (Constants.HEAD.equals(r.getName())) { // Historically HEAD has never been published through // the INFO_REFS file. This is a mistake, but its the @@ -161,7 +161,7 @@ public abstract class RefWriter { */ public void writePackedRefs() throws IOException { boolean peeled = false; - for (final Ref r : refs) { + for (Ref r : refs) { if (r.getStorage().isPacked() && r.isPeeled()) { peeled = true; break; @@ -177,7 +177,7 @@ public abstract class RefWriter { } final char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH]; - for (final Ref r : refs) { + for (Ref r : refs) { if (r.getStorage() != Ref.Storage.PACKED) continue; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 4c0bde1376..29cc19c43c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -48,6 +48,8 @@ package org.eclipse.jgit.lib; +import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; + import java.io.BufferedOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -162,7 +164,7 @@ public abstract class Repository implements AutoCloseable { * @param options * options to configure the repository. */ - protected Repository(final BaseRepositoryBuilder options) { + protected Repository(BaseRepositoryBuilder options) { gitDir = options.getGitDir(); fs = options.getFS(); workTree = options.getWorkTree(); @@ -342,7 +344,7 @@ public abstract class Repository implements AutoCloseable { * the object store cannot be accessed. */ @NonNull - public ObjectLoader open(final AnyObjectId objectId) + public ObjectLoader open(AnyObjectId objectId) throws MissingObjectException, IOException { return getObjectDatabase().open(objectId); } @@ -390,7 +392,7 @@ public abstract class Repository implements AutoCloseable { * to the base ref, as the symbolic ref could not be read. */ @NonNull - public RefUpdate updateRef(final String ref) throws IOException { + public RefUpdate updateRef(String ref) throws IOException { return updateRef(ref, false); } @@ -409,7 +411,7 @@ public abstract class Repository implements AutoCloseable { * 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(String ref, boolean detach) throws IOException { return getRefDatabase().newUpdate(ref, detach); } @@ -425,7 +427,7 @@ public abstract class Repository implements AutoCloseable { * the rename could not be performed. */ @NonNull - public RefRename renameRef(final String fromRef, final String toRef) throws IOException { + public RefRename renameRef(String fromRef, String toRef) throws IOException { return getRefDatabase().newRename(fromRef, toRef); } @@ -480,13 +482,13 @@ public abstract class Repository implements AutoCloseable { * on serious errors */ @Nullable - public ObjectId resolve(final String revstr) + public ObjectId resolve(String revstr) throws AmbiguousObjectException, IncorrectObjectTypeException, RevisionSyntaxException, IOException { try (RevWalk rw = new RevWalk(this)) { Object resolved = resolve(rw, revstr); if (resolved instanceof String) { - final Ref ref = getRef((String)resolved); + final Ref ref = findRef((String) resolved); return ref != null ? ref.getLeaf().getObjectId() : null; } else { return (ObjectId) resolved; @@ -507,7 +509,7 @@ public abstract class Repository implements AutoCloseable { * @throws java.io.IOException */ @Nullable - public String simplify(final String revstr) + public String simplify(String revstr) throws AmbiguousObjectException, IOException { try (RevWalk rw = new RevWalk(this)) { Object resolved = resolve(rw, revstr); @@ -521,7 +523,7 @@ public abstract class Repository implements AutoCloseable { } @Nullable - private Object resolve(final RevWalk rw, final String revstr) + private Object resolve(RevWalk rw, String revstr) throws IOException { char[] revChars = revstr.toCharArray(); RevObject rev = null; @@ -686,6 +688,8 @@ public abstract class Repository implements AutoCloseable { case '@': if (rev != null) throw new RevisionSyntaxException(revstr); + if (i + 1 == revChars.length) + continue; if (i + 1 < revChars.length && revChars[i + 1] != '{') continue; int m; @@ -709,7 +713,7 @@ public abstract class Repository implements AutoCloseable { .format(JGitText.get().invalidRefName, name), revstr); - Ref ref = getRef(name); + Ref ref = findRef(name); name = null; if (ref == null) return null; @@ -762,7 +766,7 @@ public abstract class Repository implements AutoCloseable { .format(JGitText.get().invalidRefName, name), revstr); - Ref ref = getRef(name); + Ref ref = findRef(name); name = null; if (ref == null) return null; @@ -813,7 +817,7 @@ public abstract class Repository implements AutoCloseable { throw new RevisionSyntaxException( MessageFormat.format(JGitText.get().invalidRefName, name), revstr); - if (getRef(name) != null) + if (findRef(name) != null) return name; return resolveSimple(name); } @@ -839,7 +843,7 @@ public abstract class Repository implements AutoCloseable { } @Nullable - private ObjectId resolveSimple(final String revstr) throws IOException { + private ObjectId resolveSimple(String revstr) throws IOException { if (ObjectId.isId(revstr)) return ObjectId.fromString(revstr); @@ -909,7 +913,7 @@ public abstract class Repository implements AutoCloseable { } @Nullable - private ObjectId resolveAbbreviation(final String revstr) throws IOException, + private ObjectId resolveAbbreviation(String revstr) throws IOException, AmbiguousObjectException { AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr); try (ObjectReader reader = newObjectReader()) { @@ -1057,24 +1061,6 @@ public abstract class Repository implements AutoCloseable { * Get a ref by name. * * @param name - * 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 {@code null} if it does not exist - * @throws java.io.IOException - * @deprecated Use {@link #exactRef(String)} or {@link #findRef(String)} - * instead. - */ - @Deprecated - @Nullable - public Ref getRef(final String name) throws IOException { - return findRef(name); - } - - /** - * Get a ref by name. - * - * @param name * the name of the ref to lookup. Must not be a short-hand * form; e.g., "master" is not automatically expanded to * "refs/heads/master". @@ -1083,7 +1069,7 @@ public abstract class Repository implements AutoCloseable { * @since 4.2 */ @Nullable - public Ref exactRef(String name) throws IOException { + public final Ref exactRef(String name) throws IOException { return getRefDatabase().exactRef(name); } @@ -1099,7 +1085,7 @@ public abstract class Repository implements AutoCloseable { * @since 4.2 */ @Nullable - public Ref findRef(String name) throws IOException { + public final Ref findRef(String name) throws IOException { return getRefDatabase().getRef(name); } @@ -1124,7 +1110,9 @@ public abstract class Repository implements AutoCloseable { * @return mutable map of all tags; key is short tag name ("v1.0") and value * of the entry contains the ref with the full tag name * ("refs/tags/v1.0"). + * @deprecated use {@code getRefDatabase().getRefsByPrefix(R_TAGS)} instead */ + @Deprecated @NonNull public Map<String, Ref> getTags() { try { @@ -1147,9 +1135,11 @@ public abstract class Repository implements AutoCloseable { * new Ref object representing the same data as Ref, but isPeeled() * will be true and getPeeledObjectId will contain the peeled object * (or null). + * @deprecated use {@code getRefDatabase().peel(ref)} instead. */ + @Deprecated @NonNull - public Ref peel(final Ref ref) { + public Ref peel(Ref ref) { try { return getRefDatabase().peel(ref); } catch (IOException e) { @@ -1283,7 +1273,7 @@ public abstract class Repository implements AutoCloseable { IndexChangedListener l = new IndexChangedListener() { @Override public void onIndexChanged(IndexChangedEvent event) { - notifyIndexChanged(); + notifyIndexChanged(true); } }; return DirCache.lock(this, l); @@ -1376,12 +1366,14 @@ public abstract class Repository implements AutoCloseable { * @param refName a {@link java.lang.String} object. * @return true if refName is a valid ref name */ - public static boolean isValidRefName(final String refName) { + public static boolean isValidRefName(String refName) { final int len = refName.length(); - if (len == 0) + if (len == 0) { return false; - if (refName.endsWith(".lock")) //$NON-NLS-1$ + } + if (refName.endsWith(LOCK_SUFFIX)) { return false; + } // Refs may be stored as loose files so invalid paths // on the local system must also be invalid refs. @@ -1576,16 +1568,22 @@ public abstract class Repository implements AutoCloseable { } /** - * Force a scan for changed refs. + * Force a scan for changed refs. Fires an IndexChangedEvent(false) if + * changes are detected. * * @throws java.io.IOException */ public abstract void scanForRepoChanges() throws IOException; /** - * Notify that the index changed + * Notify that the index changed by firing an IndexChangedEvent. + * + * @param internal + * {@code true} if the index was changed by the same + * JGit process + * @since 5.0 */ - public abstract void notifyIndexChanged(); + public abstract void notifyIndexChanged(boolean internal); /** * Get a shortened more user friendly ref name @@ -1964,11 +1962,8 @@ public abstract class Repository implements AutoCloseable { private void writeCommitMsg(File msgFile, String msg) throws IOException { if (msg != null) { - FileOutputStream fos = new FileOutputStream(msgFile); - try { + try (FileOutputStream fos = new FileOutputStream(msgFile)) { fos.write(msg.getBytes(Constants.CHARACTER_ENCODING)); - } finally { - fos.close(); } } else { FileUtils.delete(msgFile, FileUtils.SKIP_MISSING); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java index ce7ce8cd87..400342b1bd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java @@ -88,7 +88,7 @@ public class RepositoryCache { * @throws org.eclipse.jgit.errors.RepositoryNotFoundException * there is no repository at the given location. */ - public static Repository open(final Key location) throws IOException, + public static Repository open(Key location) throws IOException, RepositoryNotFoundException { return open(location, true); } @@ -115,7 +115,7 @@ public class RepositoryCache { * There is no repository at the given location, only thrown if * {@code mustExist} is true. */ - public static Repository open(final Key location, final boolean mustExist) + public static Repository open(Key location, boolean mustExist) throws IOException { return cache.openRepository(location, mustExist); } @@ -135,7 +135,7 @@ public class RepositoryCache { * @param db * repository to register. */ - public static void register(final Repository db) { + public static void register(Repository db) { if (db.getDirectory() != null) { FileKey key = FileKey.exact(db.getDirectory(), db.getFS()); cache.registerRepository(key, db); @@ -151,7 +151,7 @@ public class RepositoryCache { * @param db * repository to unregister. */ - public static void close(@NonNull final Repository db) { + public static void close(@NonNull Repository db) { if (db.getDirectory() != null) { FileKey key = FileKey.exact(db.getDirectory(), db.getFS()); cache.unregisterAndCloseRepository(key); @@ -170,7 +170,7 @@ public class RepositoryCache { * repository to unregister. * @since 4.3 */ - public static void unregister(final Repository db) { + public static void unregister(Repository db) { if (db.getDirectory() != null) { unregister(FileKey.exact(db.getDirectory(), db.getFS())); } @@ -287,13 +287,13 @@ public class RepositoryCache { return db; } - private void registerRepository(final Key location, final Repository db) { - Repository oldDb = cacheMap.put(location, db); - if (oldDb != null) - oldDb.close(); + private void registerRepository(Key location, Repository db) { + try (Repository oldDb = cacheMap.put(location, db)) { + // oldDb is auto-closed + } } - private Repository unregisterRepository(final Key location) { + private Repository unregisterRepository(Key location) { return cacheMap.remove(location); } @@ -302,7 +302,7 @@ public class RepositoryCache { && (System.currentTimeMillis() - db.closedAt.get() > expireAfter); } - private void unregisterAndCloseRepository(final Key location) { + private void unregisterAndCloseRepository(Key location) { synchronized (lockFor(location)) { Repository oldDb = unregisterRepository(location); if (oldDb != null) { @@ -329,7 +329,7 @@ public class RepositoryCache { } } - private Lock lockFor(final Key location) { + private Lock lockFor(Key location) { return openLocks[(location.hashCode() >>> 1) % openLocks.length]; } @@ -383,7 +383,7 @@ public class RepositoryCache { * @return a key for the given directory. * @see #lenient(File, FS) */ - public static FileKey exact(final File directory, FS fs) { + public static FileKey exact(File directory, FS fs) { return new FileKey(directory, fs); } @@ -406,7 +406,7 @@ public class RepositoryCache { * @return a key for the given directory. * @see #exact(File, FS) */ - public static FileKey lenient(final File directory, FS fs) { + public static FileKey lenient(File directory, FS fs) { final File gitdir = resolve(directory, fs); return new FileKey(gitdir != null ? gitdir : directory, fs); } @@ -421,12 +421,12 @@ public class RepositoryCache { * the file system abstraction which will be necessary to * perform certain file system operations. */ - protected FileKey(final File directory, FS fs) { + protected FileKey(File directory, FS fs) { path = canonical(directory); this.fs = fs; } - private static File canonical(final File path) { + private static File canonical(File path) { try { return path.getCanonicalFile(); } catch (IOException e) { @@ -440,7 +440,7 @@ public class RepositoryCache { } @Override - public Repository open(final boolean mustExist) throws IOException { + public Repository open(boolean mustExist) throws IOException { if (mustExist && !isGitRepository(path, fs)) throw new RepositoryNotFoundException(path); return new FileRepository(path); @@ -452,7 +452,7 @@ public class RepositoryCache { } @Override - public boolean equals(final Object o) { + public boolean equals(Object o) { return o instanceof FileKey && path.equals(((FileKey) o).path); } @@ -476,19 +476,19 @@ public class RepositoryCache { * it doesn't look enough like a Git directory to really be a * Git directory. */ - public static boolean isGitRepository(final File dir, FS fs) { + public static boolean isGitRepository(File dir, FS fs) { return fs.resolve(dir, "objects").exists() //$NON-NLS-1$ && fs.resolve(dir, "refs").exists() //$NON-NLS-1$ && isValidHead(new File(dir, Constants.HEAD)); } - private static boolean isValidHead(final File head) { + private static boolean isValidHead(File head) { final String ref = readFirstLine(head); return ref != null && (ref.startsWith("ref: refs/") || ObjectId.isId(ref)); //$NON-NLS-1$ } - private static String readFirstLine(final File head) { + private static String readFirstLine(File head) { try { final byte[] buf = IO.readFully(head, 4096); int n = buf.length; @@ -521,7 +521,7 @@ public class RepositoryCache { * @return the actual directory location if a better match is found; * null if there is no suitable match. */ - public static File resolve(final File directory, FS fs) { + public static File resolve(File directory, FS fs) { if (isGitRepository(directory, fs)) return directory; if (isGitRepository(new File(directory, Constants.DOT_GIT), fs)) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java index 32ef504802..bd03165805 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java @@ -168,7 +168,7 @@ public class TagBuilder { * @param newMessage * the tag's message. */ - public void setMessage(final String newMessage) { + public void setMessage(String newMessage) { message = newMessage; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java index 936ce3dcc8..2f759e53ca 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.lib; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.io.OutputStreamWriter; @@ -63,7 +63,7 @@ public class TextProgressMonitor extends BatchingProgressMonitor { * Initialize a new progress monitor. */ public TextProgressMonitor() { - this(new PrintWriter(new OutputStreamWriter(System.err, UTF_8))); + this(new PrintWriter(new OutputStreamWriter(System.err, CHARSET))); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java index 1a3c6f6bd5..bfb5e2fc12 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/UserConfig.java @@ -71,7 +71,7 @@ public class UserConfig { private boolean isCommitterEmailImplicit; - private UserConfig(final Config rc) { + private UserConfig(Config rc) { authorName = getNameInternal(rc, Constants.GIT_AUTHOR_NAME_KEY); if (authorName == null) { authorName = getDefaultUserName(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeStrategy.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeStrategy.java index 520ea6e74a..98a706c6ad 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeStrategy.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeStrategy.java @@ -100,7 +100,7 @@ public abstract class MergeStrategy { * @throws java.lang.IllegalArgumentException * a strategy by the same name has already been registered. */ - public static void register(final MergeStrategy imp) { + public static void register(MergeStrategy imp) { register(imp.getName(), imp); } @@ -129,7 +129,7 @@ public abstract class MergeStrategy { * name of the strategy to locate. * @return the strategy instance; null if no strategy matches the name. */ - public static synchronized MergeStrategy get(final String name) { + public static synchronized MergeStrategy get(String name) { return STRATEGIES.get(name); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java index cd19d696a8..25eb1af127 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java @@ -113,7 +113,7 @@ public abstract class Merger { * @param local * the repository this merger will read and write data on. */ - protected Merger(final Repository local) { + protected Merger(Repository local) { if (local == null) { throw new NullPointerException(JGitText.get().repositoryIsRequired); } @@ -215,7 +215,7 @@ public abstract class Merger { * one or more sources could not be read, or outputs could not * be written to the Repository. */ - public boolean merge(final AnyObjectId... tips) throws IOException { + public boolean merge(AnyObjectId... tips) throws IOException { return merge(true, tips); } @@ -243,7 +243,7 @@ public abstract class Merger { * one or more sources could not be read, or outputs could not * be written to the Repository. */ - public boolean merge(final boolean flush, final AnyObjectId... tips) + public boolean merge(boolean flush, AnyObjectId... tips) throws IOException { sourceObjects = new RevObject[tips.length]; for (int i = 0; i < tips.length; i++) @@ -328,7 +328,7 @@ public abstract class Merger { * @throws java.io.IOException * the tree object is not found or cannot be read. */ - protected AbstractTreeIterator openTree(final AnyObjectId treeId) + protected AbstractTreeIterator openTree(AnyObjectId treeId) throws IncorrectObjectTypeException, IOException { return new CanonicalTreeParser(null, reader, treeId); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java index 6f7a702470..da6a3da67d 100755..100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java @@ -516,61 +516,6 @@ public class ResolveMerger extends ThreeWayMerger { * @param ignoreConflicts * see * {@link org.eclipse.jgit.merge.ResolveMerger#mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)} - * @return <code>false</code> if the merge will fail because the index entry - * didn't match ours or the working-dir file was dirty and a - * conflict occurred - * @throws org.eclipse.jgit.errors.MissingObjectException - * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException - * @throws org.eclipse.jgit.errors.CorruptObjectException - * @throws java.io.IOException - * @since 3.5 - */ - @Deprecated - protected boolean processEntry(CanonicalTreeParser base, - CanonicalTreeParser ours, CanonicalTreeParser theirs, - DirCacheBuildIterator index, WorkingTreeIterator work, - boolean ignoreConflicts) throws MissingObjectException, - IncorrectObjectTypeException, CorruptObjectException, IOException { - return processEntry(base, ours, theirs, index, work, ignoreConflicts, - null); - } - - /** - * Processes one path and tries to merge taking git attributes in account. - * This method will do all trivial (not content) merges and will also detect - * if a merge will fail. The merge will fail when one of the following is - * true - * <ul> - * <li>the index entry does not match the entry in ours. When merging one - * branch into the current HEAD, ours will point to HEAD and theirs will - * point to the other branch. It is assumed that the index matches the HEAD - * because it will only not match HEAD if it was populated before the merge - * operation. But the merge commit should not accidentally contain - * modifications done before the merge. Check the <a href= - * "http://www.kernel.org/pub/software/scm/git/docs/git-read-tree.html#_3_way_merge" - * >git read-tree</a> documentation for further explanations.</li> - * <li>A conflict was detected and the working-tree file is dirty. When a - * conflict is detected the content-merge algorithm will try to write a - * merged version into the working-tree. If the file is dirty we would - * override unsaved data.</li> - * </ul> - * - * @param base - * the common base for ours and theirs - * @param ours - * the ours side of the merge. When merging a branch into the - * HEAD ours will point to HEAD - * @param theirs - * the theirs side of the merge. When merging a branch into the - * current HEAD theirs will point to the branch which is merged - * into HEAD. - * @param index - * the index entry - * @param work - * the file in the working tree - * @param ignoreConflicts - * see - * {@link org.eclipse.jgit.merge.ResolveMerger#mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)} * @param attributes * the attributes defined for this entry * @return <code>false</code> if the merge will fail because the index entry @@ -1050,11 +995,11 @@ public class ResolveMerger extends ThreeWayMerger { return RawText.load(loader, threshold); } - private static boolean nonTree(final int mode) { + private static boolean nonTree(int mode) { return mode != 0 && !FileMode.TREE.equals(mode); } - private static boolean isGitLink(final int mode) { + private static boolean isGitLink(int mode) { return FileMode.GITLINK.equals(mode); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategyOneSided.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategyOneSided.java index 979685c409..6e2e2aad0d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategyOneSided.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategyOneSided.java @@ -71,7 +71,7 @@ public class StrategyOneSided extends MergeStrategy { * @param index * the position of the input tree to accept as the result. */ - protected StrategyOneSided(final String name, final int index) { + protected StrategyOneSided(String name, int index) { strategyName = name; treeIndex = index; } @@ -84,31 +84,31 @@ public class StrategyOneSided extends MergeStrategy { /** {@inheritDoc} */ @Override - public Merger newMerger(final Repository db) { + public Merger newMerger(Repository db) { return new OneSide(db, treeIndex); } /** {@inheritDoc} */ @Override - public Merger newMerger(final Repository db, boolean inCore) { + public Merger newMerger(Repository db, boolean inCore) { return new OneSide(db, treeIndex); } /** {@inheritDoc} */ @Override - public Merger newMerger(final ObjectInserter inserter, final Config config) { + public Merger newMerger(ObjectInserter inserter, Config config) { return new OneSide(inserter, treeIndex); } static class OneSide extends Merger { private final int treeIndex; - protected OneSide(final Repository local, final int index) { + protected OneSide(Repository local, int index) { super(local); treeIndex = index; } - protected OneSide(final ObjectInserter inserter, final int index) { + protected OneSide(ObjectInserter inserter, int index) { super(inserter); treeIndex = index; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java index 5739d58b39..4aeacf5082 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java @@ -84,7 +84,7 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy { /** {@inheritDoc} */ @Override - public ThreeWayMerger newMerger(final Repository db) { + public ThreeWayMerger newMerger(Repository db) { return new InCoreMerger(db); } @@ -116,13 +116,13 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy { private ObjectId resultTree; - InCoreMerger(final Repository local) { + InCoreMerger(Repository local) { super(local); tw = new NameConflictTreeWalk(local, reader); cache = DirCache.newInCore(); } - InCoreMerger(final ObjectInserter inserter) { + InCoreMerger(ObjectInserter inserter) { super(inserter); tw = new NameConflictTreeWalk(null, reader); cache = DirCache.newInCore(); @@ -182,11 +182,11 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy { } } - private static boolean nonTree(final int mode) { + private static boolean nonTree(int mode) { return mode != 0 && !FileMode.TREE.equals(mode); } - private void add(final int tree, final int stage) throws IOException { + private void add(int tree, int stage) throws IOException { final AbstractTreeIterator i = getTree(tree); if (i != null) { if (FileMode.TREE.equals(tw.getRawMode(tree))) { @@ -203,7 +203,7 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy { } } - private AbstractTreeIterator getTree(final int tree) { + private AbstractTreeIterator getTree(int tree) { return tw.getTree(tree, AbstractTreeIterator.class); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java index 3f28820092..2fc0f4f073 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ThreeWayMerger.java @@ -71,7 +71,7 @@ public abstract class ThreeWayMerger extends Merger { * @param local * the repository this merger will read and write data on. */ - protected ThreeWayMerger(final Repository local) { + protected ThreeWayMerger(Repository local) { super(local); } @@ -83,7 +83,7 @@ public abstract class ThreeWayMerger extends Merger { * @param inCore * perform the merge in core with no working folder involved */ - protected ThreeWayMerger(final Repository local, boolean inCore) { + protected ThreeWayMerger(Repository local, boolean inCore) { this(local); } @@ -112,7 +112,7 @@ public abstract class ThreeWayMerger extends Merger { * @throws java.io.IOException * the object could not be read. */ - public void setBase(final AnyObjectId id) throws MissingObjectException, + public void setBase(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (id != null) { baseTree = walk.parseTree(id); @@ -123,7 +123,7 @@ public abstract class ThreeWayMerger extends Merger { /** {@inheritDoc} */ @Override - public boolean merge(final AnyObjectId... tips) throws IOException { + public boolean merge(AnyObjectId... tips) throws IOException { if (tips.length != 2) return false; return super.merge(tips); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java b/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java index 1be5251622..6723b6309c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/notes/LeafBucket.java @@ -218,7 +218,7 @@ class LeafBucket extends InMemoryNoteBucket { return fmt; } - private int treeSize(final int nameLen) { + private int treeSize(int nameLen) { int sz = cnt * TreeFormatter.entrySize(REGULAR_FILE, nameLen); for (NonNoteEntry e = nonNotes; e != null; e = e.next) sz += e.treeEntrySize(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/BinaryHunk.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/BinaryHunk.java index 079d6f6d67..95391ec565 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/BinaryHunk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/BinaryHunk.java @@ -80,7 +80,7 @@ public class BinaryHunk { /** Inflated length of the data. */ private int length; - BinaryHunk(final FileHeader fh, final int offset) { + BinaryHunk(FileHeader fh, int offset) { file = fh; startOffset = offset; } @@ -139,7 +139,7 @@ public class BinaryHunk { return length; } - int parseHunk(int ptr, final int end) { + int parseHunk(int ptr, int end) { final byte[] buf = file.buf; if (match(buf, ptr, LITERAL) >= 0) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedFileHeader.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedFileHeader.java index 1afb53da8e..34075787fb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedFileHeader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedFileHeader.java @@ -69,7 +69,7 @@ public class CombinedFileHeader extends FileHeader { private FileMode[] oldModes; - CombinedFileHeader(final byte[] b, final int offset) { + CombinedFileHeader(byte[] b, int offset) { super(b, offset); } @@ -108,7 +108,7 @@ public class CombinedFileHeader extends FileHeader { * the ancestor to get the mode of * @return the mode of the requested ancestor. */ - public FileMode getOldMode(final int nthParent) { + public FileMode getOldMode(int nthParent) { return oldModes[nthParent]; } @@ -130,13 +130,13 @@ public class CombinedFileHeader extends FileHeader { * the ancestor to get the object id of * @return the id of the requested ancestor. */ - public AbbreviatedObjectId getOldId(final int nthParent) { + public AbbreviatedObjectId getOldId(int nthParent) { return oldIds[nthParent]; } /** {@inheritDoc} */ @Override - public String getScriptText(final Charset ocs, final Charset ncs) { + public String getScriptText(Charset ocs, Charset ncs) { final Charset[] cs = new Charset[getParentCount() + 1]; Arrays.fill(cs, ocs); cs[getParentCount()] = ncs; @@ -149,12 +149,12 @@ public class CombinedFileHeader extends FileHeader { * Convert the patch script for this file into a string. */ @Override - public String getScriptText(final Charset[] charsetGuess) { + public String getScriptText(Charset[] charsetGuess) { return super.getScriptText(charsetGuess); } @Override - int parseGitHeaders(int ptr, final int end) { + int parseGitHeaders(int ptr, int end) { while (ptr < end) { final int eol = nextLF(buf, ptr); if (isHunkHdr(buf, ptr, end) >= 1) { @@ -191,7 +191,7 @@ public class CombinedFileHeader extends FileHeader { /** {@inheritDoc} */ @Override - protected void parseIndexLine(int ptr, final int eol) { + protected void parseIndexLine(int ptr, int eol) { // "index $asha1,$bsha1..$csha1" // final List<AbbreviatedObjectId> ids = new ArrayList<>(); @@ -213,18 +213,18 @@ public class CombinedFileHeader extends FileHeader { /** {@inheritDoc} */ @Override - protected void parseNewFileMode(final int ptr, final int eol) { + protected void parseNewFileMode(int ptr, int eol) { for (int i = 0; i < oldModes.length; i++) oldModes[i] = FileMode.MISSING; super.parseNewFileMode(ptr, eol); } @Override - HunkHeader newHunkHeader(final int offset) { + HunkHeader newHunkHeader(int offset) { return new CombinedHunkHeader(this, offset); } - private void parseModeLine(int ptr, final int eol) { + private void parseModeLine(int ptr, int eol) { // "mode $amode,$bmode..$cmode" // int n = 0; @@ -240,7 +240,7 @@ public class CombinedFileHeader extends FileHeader { newMode = parseFileMode(dot2 + 1, eol); } - private void parseDeletedFileMode(int ptr, final int eol) { + private void parseDeletedFileMode(int ptr, int eol) { // "deleted file mode $amode,$bmode" // changeType = ChangeType.DELETE; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedHunkHeader.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedHunkHeader.java index bbf802317d..d278132c61 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedHunkHeader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/CombinedHunkHeader.java @@ -64,7 +64,7 @@ public class CombinedHunkHeader extends HunkHeader { private CombinedOldImage[] old; - CombinedHunkHeader(final CombinedFileHeader fh, final int offset) { + CombinedHunkHeader(CombinedFileHeader fh, int offset) { super(fh, offset, null); old = new CombinedOldImage[fh.getParentCount()]; for (int i = 0; i < old.length; i++) { @@ -97,7 +97,7 @@ public class CombinedHunkHeader extends HunkHeader { * the ancestor to get the old image data of * @return image data of the requested ancestor. */ - public OldImage getOldImage(final int nthParent) { + public OldImage getOldImage(int nthParent) { return old[nthParent]; } @@ -125,11 +125,11 @@ public class CombinedHunkHeader extends HunkHeader { } @Override - int parseBody(final Patch script, final int end) { + int parseBody(Patch script, int end) { final byte[] buf = file.buf; int c = nextLF(buf, startOffset); - for (final CombinedOldImage o : old) { + for (CombinedOldImage o : old) { o.nDeleted = 0; o.nAdded = 0; o.nContext = 0; @@ -207,7 +207,7 @@ public class CombinedHunkHeader extends HunkHeader { } @Override - void extractFileLines(final OutputStream[] out) throws IOException { + void extractFileLines(OutputStream[] out) throws IOException { final byte[] buf = file.buf; int ptr = startOffset; int eol = nextLF(buf, ptr); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java index 5cfbbb2d88..d0a5216e1e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java @@ -146,7 +146,7 @@ public class FileHeader extends DiffEntry { * @param type * the type of patch used to modify this file */ - public FileHeader(final byte[] headerLines, EditList edits, PatchType type) { + public FileHeader(byte[] headerLines, EditList edits, PatchType type) { this(headerLines, 0); endOffset = headerLines.length; int ptr = parseGitFileName(Patch.DIFF_GIT.length, headerLines.length); @@ -155,7 +155,7 @@ public class FileHeader extends DiffEntry { addHunk(new HunkHeader(this, edits)); } - FileHeader(final byte[] b, final int offset) { + FileHeader(byte[] b, int offset) { buf = b; startOffset = offset; changeType = ChangeType.MODIFY; // unless otherwise designated @@ -264,12 +264,12 @@ public class FileHeader extends DiffEntry { final String[] files = extractFileLines(charsetGuess); final int[] offsets = new int[files.length]; - for (final HunkHeader h : getHunks()) + for (HunkHeader h : getHunks()) h.extractFileLines(r, files, offsets); return r.toString(); } - private static boolean trySimpleConversion(final Charset[] charsetGuess) { + private static boolean trySimpleConversion(Charset[] charsetGuess) { if (charsetGuess == null) return true; for (int i = 1; i < charsetGuess.length; i++) { @@ -279,12 +279,12 @@ public class FileHeader extends DiffEntry { return true; } - private String[] extractFileLines(final Charset[] csGuess) { + private String[] extractFileLines(Charset[] csGuess) { final TemporaryBuffer[] tmp = new TemporaryBuffer[getParentCount() + 1]; try { for (int i = 0; i < tmp.length; i++) tmp[i] = new TemporaryBuffer.Heap(Integer.MAX_VALUE); - for (final HunkHeader h : getHunks()) + for (HunkHeader h : getHunks()) h.extractFileLines(tmp); final String[] r = new String[tmp.length]; @@ -329,7 +329,7 @@ public class FileHeader extends DiffEntry { return hunks; } - void addHunk(final HunkHeader h) { + void addHunk(HunkHeader h) { if (h.getFileHeader() != this) throw new IllegalArgumentException(JGitText.get().hunkBelongsToAnotherFile); if (hunks == null) @@ -337,7 +337,7 @@ public class FileHeader extends DiffEntry { hunks.add(h); } - HunkHeader newHunkHeader(final int offset) { + HunkHeader newHunkHeader(int offset) { return new HunkHeader(this, offset); } @@ -370,7 +370,7 @@ public class FileHeader extends DiffEntry { */ public EditList toEditList() { final EditList r = new EditList(); - for (final HunkHeader hunk : hunks) + for (HunkHeader hunk : hunks) r.addAll(hunk.toEditList()); return r; } @@ -384,7 +384,7 @@ public class FileHeader extends DiffEntry { * one past the last position to parse. * @return first character after the LF at the end of the line; -1 on error. */ - int parseGitFileName(int ptr, final int end) { + int parseGitFileName(int ptr, int end) { final int eol = nextLF(buf, ptr); final int bol = ptr; if (eol >= end) { @@ -444,7 +444,7 @@ public class FileHeader extends DiffEntry { return eol; } - int parseGitHeaders(int ptr, final int end) { + int parseGitHeaders(int ptr, int end) { while (ptr < end) { final int eol = nextLF(buf, ptr); if (isHunkHdr(buf, ptr, eol) >= 1) { @@ -514,25 +514,25 @@ public class FileHeader extends DiffEntry { return ptr; } - void parseOldName(int ptr, final int eol) { + void parseOldName(int ptr, int eol) { oldPath = p1(parseName(oldPath, ptr + OLD_NAME.length, eol)); if (oldPath == DEV_NULL) changeType = ChangeType.ADD; } - void parseNewName(int ptr, final int eol) { + void parseNewName(int ptr, int eol) { newPath = p1(parseName(newPath, ptr + NEW_NAME.length, eol)); if (newPath == DEV_NULL) changeType = ChangeType.DELETE; } - void parseNewFileMode(int ptr, final int eol) { + void parseNewFileMode(int ptr, int eol) { oldMode = FileMode.MISSING; newMode = parseFileMode(ptr + NEW_FILE_MODE.length, eol); changeType = ChangeType.ADD; } - int parseTraditionalHeaders(int ptr, final int end) { + int parseTraditionalHeaders(int ptr, int end) { while (ptr < end) { final int eol = nextLF(buf, ptr); if (isHunkHdr(buf, ptr, eol) >= 1) { @@ -555,7 +555,7 @@ public class FileHeader extends DiffEntry { return ptr; } - private String parseName(final String expect, int ptr, final int end) { + private String parseName(String expect, int ptr, int end) { if (ptr == end) return expect; @@ -585,7 +585,7 @@ public class FileHeader extends DiffEntry { return s > 0 ? r.substring(s + 1) : r; } - FileMode parseFileMode(int ptr, final int end) { + FileMode parseFileMode(int ptr, int end) { int tmp = 0; while (ptr < end - 1) { tmp <<= 3; @@ -594,7 +594,7 @@ public class FileHeader extends DiffEntry { return FileMode.fromBits(tmp); } - void parseIndexLine(int ptr, final int end) { + void parseIndexLine(int ptr, int end) { // "index $asha1..$bsha1[ $mode]" where $asha1 and $bsha1 // can be unique abbreviations // @@ -636,7 +636,7 @@ public class FileHeader extends DiffEntry { * for a 3 way-merge returns 3. If this is not a hunk header, 0 is * returned instead. */ - static int isHunkHdr(final byte[] buf, final int start, final int end) { + static int isHunkHdr(byte[] buf, int start, int end) { int ptr = start; while (ptr < end && buf[ptr] == '@') ptr++; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java index d022d47833..1458945c31 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/HunkHeader.java @@ -120,7 +120,7 @@ public class HunkHeader { private EditList editList; - HunkHeader(final FileHeader fh, final int offset) { + HunkHeader(FileHeader fh, int offset) { this(fh, offset, new OldImage() { @Override public AbbreviatedObjectId getId() { @@ -129,13 +129,13 @@ public class HunkHeader { }); } - HunkHeader(final FileHeader fh, final int offset, final OldImage oi) { + HunkHeader(FileHeader fh, int offset, OldImage oi) { file = fh; startOffset = offset; old = oi; } - HunkHeader(final FileHeader fh, final EditList editList) { + HunkHeader(FileHeader fh, EditList editList) { this(fh, fh.buf.length); this.editList = editList; endOffset = startOffset; @@ -293,7 +293,7 @@ public class HunkHeader { newLineCount = 1; } - int parseBody(final Patch script, final int end) { + int parseBody(Patch script, int end) { final byte[] buf = file.buf; int c = nextLF(buf, startOffset), last = c; @@ -359,7 +359,7 @@ public class HunkHeader { return c; } - void extractFileLines(final OutputStream[] out) throws IOException { + void extractFileLines(OutputStream[] out) throws IOException { final byte[] buf = file.buf; int ptr = startOffset; int eol = nextLF(buf, ptr); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/Patch.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/Patch.java index da123a7c2d..052f2a7906 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/Patch.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/Patch.java @@ -101,7 +101,7 @@ public class Patch { * @param fh * the header of the file. */ - public void addFile(final FileHeader fh) { + public void addFile(FileHeader fh) { files.add(fh); } @@ -120,7 +120,7 @@ public class Patch { * @param err * the error description. */ - public void addError(final FormatError err) { + public void addError(FormatError err) { errors.add(err); } @@ -146,12 +146,12 @@ public class Patch { * @throws java.io.IOException * there was an error reading from the input stream. */ - public void parse(final InputStream is) throws IOException { + public void parse(InputStream is) throws IOException { final byte[] buf = readFully(is); parse(buf, 0, buf.length); } - private static byte[] readFully(final InputStream is) throws IOException { + private static byte[] readFully(InputStream is) throws IOException { try (TemporaryBuffer b = new TemporaryBuffer.Heap(Integer.MAX_VALUE)) { b.copy(is); return b.toByteArray(); @@ -173,12 +173,12 @@ public class Patch { * 1 past the last position to end parsing. The total length to * be parsed is <code>end - ptr</code>. */ - public void parse(final byte[] buf, int ptr, final int end) { + public void parse(byte[] buf, int ptr, int end) { while (ptr < end) ptr = parseFile(buf, ptr, end); } - private int parseFile(final byte[] buf, int c, final int end) { + private int parseFile(byte[] buf, int c, int end) { while (c < end) { if (isHunkHdr(buf, c, end) >= 1) { // If we find a disconnected hunk header we might @@ -234,7 +234,7 @@ public class Patch { return c; } - private int parseDiffGit(final byte[] buf, final int start, final int end) { + private int parseDiffGit(byte[] buf, int start, int end) { final FileHeader fh = new FileHeader(buf, start); int ptr = fh.parseGitFileName(start + DIFF_GIT.length, end); if (ptr < 0) @@ -271,14 +271,14 @@ public class Patch { return ptr; } - private static int skipFile(final byte[] buf, int ptr) { + private static int skipFile(byte[] buf, int ptr) { ptr = nextLF(buf, ptr); if (match(buf, ptr, OLD_NAME) >= 0) ptr = nextLF(buf, ptr); return ptr; } - private int parseHunks(final FileHeader fh, int c, final int end) { + private int parseHunks(FileHeader fh, int c, int end) { final byte[] buf = fh.buf; while (c < end) { // If we see a file header at this point, we have all of the @@ -349,7 +349,7 @@ public class Patch { return c; } - private int parseGitBinary(final FileHeader fh, int c, final int end) { + private int parseGitBinary(FileHeader fh, int c, int end) { final BinaryHunk postImage = new BinaryHunk(fh, c); final int nEnd = postImage.parseHunk(c, end); if (nEnd < 0) { @@ -373,17 +373,17 @@ public class Patch { return c; } - void warn(final byte[] buf, final int ptr, final String msg) { + void warn(byte[] buf, int ptr, String msg) { addError(new FormatError(buf, ptr, FormatError.Severity.WARNING, msg)); } - void error(final byte[] buf, final int ptr, final String msg) { + void error(byte[] buf, int ptr, String msg) { addError(new FormatError(buf, ptr, FormatError.Severity.ERROR, msg)); } private static boolean matchAny(final byte[] buf, final int c, final byte[][] srcs) { - for (final byte[] s : srcs) { + for (byte[] s : srcs) { if (match(buf, c, s) >= 0) return true; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java index f88b819d4d..58e2106fe2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/AbstractPlotRenderer.java @@ -92,14 +92,14 @@ public abstract class AbstractPlotRenderer<TLane extends PlotLane, TColor> { * total height (in pixels) of this cell. */ @SuppressWarnings("unchecked") - protected void paintCommit(final PlotCommit<TLane> commit, final int h) { + protected void paintCommit(PlotCommit<TLane> commit, int h) { final int dotSize = computeDotSize(h); final TLane myLane = commit.getLane(); final int myLaneX = laneC(myLane); final TColor myColor = laneColor(myLane); int maxCenter = myLaneX; - for (final TLane passingLane : (TLane[]) commit.passingLanes) { + for (TLane passingLane : (TLane[]) commit.passingLanes) { final int cx = laneC(passingLane); final TColor c = laneColor(passingLane); drawLine(c, cx, 0, cx, h, LINE_WIDTH); @@ -190,7 +190,7 @@ public abstract class AbstractPlotRenderer<TLane extends PlotLane, TColor> { */ protected abstract int drawLabel(int x, int y, Ref ref); - private static int computeDotSize(final int h) { + private static int computeDotSize(int h) { int d = (int) (Math.min(h, LANE_WIDTH) * 0.50f); d += (d & 1); return d; @@ -282,12 +282,12 @@ public abstract class AbstractPlotRenderer<TLane extends PlotLane, TColor> { */ protected abstract void drawText(String msg, int x, int y); - private static int laneX(final PlotLane myLane) { + private static int laneX(PlotLane myLane) { final int p = myLane != null ? myLane.getPosition() : 0; return LEFT_PAD + LANE_WIDTH * p; } - private static int laneC(final PlotLane myLane) { + private static int laneC(PlotLane myLane) { return laneX(myLane) + LANE_WIDTH / 2; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java index 091bf683ac..9914b0c991 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java @@ -79,7 +79,7 @@ public class PlotCommit<L extends PlotLane> extends RevCommit { * @param id * the identity of this commit. */ - protected PlotCommit(final AnyObjectId id) { + protected PlotCommit(AnyObjectId id) { super(id); forkingOffLanes = NO_LANES; passingLanes = NO_LANES; @@ -88,19 +88,19 @@ public class PlotCommit<L extends PlotLane> extends RevCommit { refs = NO_REFS; } - void addForkingOffLane(final PlotLane f) { + void addForkingOffLane(PlotLane f) { forkingOffLanes = addLane(f, forkingOffLanes); } - void addPassingLane(final PlotLane c) { + void addPassingLane(PlotLane c) { passingLanes = addLane(c, passingLanes); } - void addMergingLane(final PlotLane m) { + void addMergingLane(PlotLane m) { mergingLanes = addLane(m, mergingLanes); } - private static PlotLane[] addLane(final PlotLane l, PlotLane[] lanes) { + private static PlotLane[] addLane(PlotLane l, PlotLane[] lanes) { final int cnt = lanes.length; if (cnt == 0) lanes = new PlotLane[] { l }; @@ -115,7 +115,7 @@ public class PlotCommit<L extends PlotLane> extends RevCommit { return lanes; } - void addChild(final PlotCommit c) { + void addChild(PlotCommit c) { final int cnt = children.length; if (cnt == 0) children = new PlotCommit[] { c }; @@ -152,7 +152,7 @@ public class PlotCommit<L extends PlotLane> extends RevCommit { * @throws java.lang.ArrayIndexOutOfBoundsException * an invalid child index was specified. */ - public final PlotCommit getChild(final int nth) { + public final PlotCommit getChild(int nth) { return children[nth]; } @@ -163,8 +163,8 @@ public class PlotCommit<L extends PlotLane> extends RevCommit { * the commit to test. * @return true if the given commit built on top of this commit. */ - public final boolean isChild(final PlotCommit c) { - for (final PlotCommit a : children) + public final boolean isChild(PlotCommit c) { + for (PlotCommit a : children) if (a == c) return true; return false; @@ -189,7 +189,7 @@ public class PlotCommit<L extends PlotLane> extends RevCommit { * @throws java.lang.ArrayIndexOutOfBoundsException * an invalid ref index was specified. */ - public final Ref getRef(final int nth) { + public final Ref getRef(int nth) { return refs[nth]; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java index 6a0ba66ba1..5e153164ad 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommitList.java @@ -94,7 +94,7 @@ public class PlotCommitList<L extends PlotLane> extends /** {@inheritDoc} */ @Override - public void source(final RevWalk w) { + public void source(RevWalk w) { if (!(w instanceof PlotWalk)) throw new ClassCastException(MessageFormat.format(JGitText.get().classCastNotA, PlotWalk.class.getName())); super.source(w); @@ -120,13 +120,13 @@ public class PlotCommitList<L extends PlotLane> extends @SuppressWarnings("unchecked") public void findPassingThrough(final PlotCommit<L> currCommit, final Collection<L> result) { - for (final PlotLane p : currCommit.passingLanes) + for (PlotLane p : currCommit.passingLanes) result.add((L) p); } /** {@inheritDoc} */ @Override - protected void enter(final int index, final PlotCommit<L> currCommit) { + protected void enter(int index, PlotCommit<L> currCommit) { setupChildren(currCommit); final int nChildren = currCommit.getChildCount(); @@ -202,7 +202,7 @@ public class PlotCommitList<L extends PlotLane> extends closeLane(currCommit.lane); } - private void continueActiveLanes(final PlotCommit currCommit) { + private void continueActiveLanes(PlotCommit currCommit) { for (PlotLane lane : activeLanes) if (lane != currCommit.lane) currCommit.addPassingLane(lane); @@ -356,7 +356,7 @@ public class PlotCommitList<L extends PlotLane> extends } } - private void setupChildren(final PlotCommit<L> currCommit) { + private void setupChildren(PlotCommit<L> currCommit) { final int nParents = currCommit.getParentCount(); for (int i = 0; i < nParents; i++) ((PlotCommit) currCommit.getParent(i)).addChild(currCommit); @@ -416,7 +416,7 @@ public class PlotCommitList<L extends PlotLane> extends * @param lane * a lane */ - protected void recycleLane(final L lane) { + protected void recycleLane(L lane) { // Nothing. } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java index 8ba8d6e4ca..f27f356c6b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotWalk.java @@ -90,7 +90,7 @@ public class PlotWalk extends RevWalk { * @param repo * the repository the walker will obtain data from. */ - public PlotWalk(final Repository repo) { + public PlotWalk(Repository repo) { super(repo); super.sort(RevSort.TOPO, true); reverseRefMap = repo.getAllRefsByPeeledObjectId(); @@ -118,7 +118,7 @@ public class PlotWalk extends RevWalk { /** {@inheritDoc} */ @Override - public void sort(final RevSort s, final boolean use) { + public void sort(RevSort s, boolean use) { if (s == RevSort.TOPO && !use) throw new IllegalArgumentException(JGitText.get().topologicalSortRequired); super.sort(s, use); @@ -126,7 +126,7 @@ public class PlotWalk extends RevWalk { /** {@inheritDoc} */ @Override - protected RevCommit createCommit(final AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id) { return new PlotCommit(id); } @@ -140,7 +140,7 @@ public class PlotWalk extends RevWalk { return pc; } - private Ref[] getRefs(final AnyObjectId commitId) { + private Ref[] getRefs(AnyObjectId commitId) { Collection<Ref> list = reverseRefMap.get(commitId); if (list == null) return PlotCommit.NO_REFS; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java index b948adb42e..247a3bdb28 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/AbstractRevQueue.java @@ -74,7 +74,7 @@ abstract class AbstractRevQueue extends Generator { * @param queueControl * flag that controls admission to the queue. */ - public final void add(final RevCommit c, final RevFlag queueControl) { + public final void add(RevCommit c, RevFlag queueControl) { if (!c.has(queueControl)) { c.add(queueControl); add(c); @@ -94,7 +94,7 @@ abstract class AbstractRevQueue extends Generator { * @param queueControl * flag that controls admission to the queue. */ - public final void addParents(final RevCommit c, final RevFlag queueControl) { + public final void addParents(RevCommit c, RevFlag queueControl) { final RevCommit[] pList = c.parents; if (pList == null) return; @@ -132,7 +132,7 @@ abstract class AbstractRevQueue extends Generator { * @param c * a {@link org.eclipse.jgit.revwalk.RevCommit} */ - protected static void describe(final StringBuilder s, final RevCommit c) { + protected static void describe(StringBuilder s, RevCommit c) { s.append(c.toString()); s.append('\n'); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockObjQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockObjQueue.java index 371cd06dda..fcdf79520a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockObjQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockObjQueue.java @@ -55,7 +55,7 @@ class BlockObjQueue { free = new BlockFreeList(); } - void add(final RevObject c) { + void add(RevObject c) { Block b = tail; if (b == null) { b = free.newBlock(); @@ -98,7 +98,7 @@ class BlockObjQueue { return b; } - void freeBlock(final Block b) { + void freeBlock(Block b) { b.next = next; next = b; } @@ -127,7 +127,7 @@ class BlockObjQueue { return headIndex == tailIndex; } - void add(final RevObject c) { + void add(RevObject c) { objects[tailIndex++] = c; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockRevQueue.java index 74a3511088..79307b5b7c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockRevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BlockRevQueue.java @@ -58,7 +58,7 @@ abstract class BlockRevQueue extends AbstractRevQueue { free = new BlockFreeList(); } - BlockRevQueue(final Generator s) throws MissingObjectException, + BlockRevQueue(Generator s) throws MissingObjectException, IncorrectObjectTypeException, IOException { free = new BlockFreeList(); outputType = s.outputType(); @@ -85,7 +85,7 @@ abstract class BlockRevQueue extends AbstractRevQueue { * sharing the same free list are doing so from only a single thread. */ @Override - public void shareFreeList(final BlockRevQueue q) { + public void shareFreeList(BlockRevQueue q) { free = q.free; } @@ -101,7 +101,7 @@ abstract class BlockRevQueue extends AbstractRevQueue { return b; } - void freeBlock(final Block b) { + void freeBlock(Block b) { b.next = next; next = b; } @@ -138,11 +138,11 @@ abstract class BlockRevQueue extends AbstractRevQueue { return headIndex > 0; } - void add(final RevCommit c) { + void add(RevCommit c) { commits[tailIndex++] = c; } - void unpop(final RevCommit c) { + void unpop(RevCommit c) { commits[--headIndex] = c; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java index 6be0c8584e..0fd6621e62 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/BoundaryGenerator.java @@ -54,7 +54,7 @@ class BoundaryGenerator extends Generator { Generator g; - BoundaryGenerator(final RevWalk w, final Generator s) { + BoundaryGenerator(RevWalk w, Generator s) { g = new InitialGenerator(w, s); } @@ -64,7 +64,7 @@ class BoundaryGenerator extends Generator { } @Override - void shareFreeList(final BlockRevQueue q) { + void shareFreeList(BlockRevQueue q) { g.shareFreeList(q); } @@ -85,7 +85,7 @@ class BoundaryGenerator extends Generator { private final Generator source; - InitialGenerator(final RevWalk w, final Generator s) { + InitialGenerator(RevWalk w, Generator s) { walk = w; held = new FIFORevQueue(); source = s; @@ -98,7 +98,7 @@ class BoundaryGenerator extends Generator { } @Override - void shareFreeList(final BlockRevQueue q) { + void shareFreeList(BlockRevQueue q) { q.shareFreeList(held); } @@ -107,7 +107,7 @@ class BoundaryGenerator extends Generator { IncorrectObjectTypeException, IOException { RevCommit c = source.next(); if (c != null) { - for (final RevCommit p : c.parents) + for (RevCommit p : c.parents) if ((p.flags & UNINTERESTING) != 0) held.add(p); return c; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java index c993fe50a9..b86e876201 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DateRevQueue.java @@ -76,7 +76,7 @@ public class DateRevQueue extends AbstractRevQueue { super(); } - DateRevQueue(final Generator s) throws MissingObjectException, + DateRevQueue(Generator s) throws MissingObjectException, IncorrectObjectTypeException, IOException { for (;;) { final RevCommit c = s.next(); @@ -88,7 +88,7 @@ public class DateRevQueue extends AbstractRevQueue { /** {@inheritDoc} */ @Override - public void add(final RevCommit c) { + public void add(RevCommit c) { sinceLastIndex++; if (++inQueue > REBUILD_INDEX_COUNT && sinceLastIndex > REBUILD_INDEX_COUNT) @@ -181,7 +181,7 @@ public class DateRevQueue extends AbstractRevQueue { } @Override - boolean everbodyHasFlag(final int f) { + boolean everbodyHasFlag(int f) { for (Entry q = head; q != null; q = q.next) { if ((q.commit.flags & f) == 0) return false; @@ -190,7 +190,7 @@ public class DateRevQueue extends AbstractRevQueue { } @Override - boolean anybodyHasFlag(final int f) { + boolean anybodyHasFlag(int f) { for (Entry q = head; q != null; q = q.next) { if ((q.commit.flags & f) != 0) return true; @@ -212,7 +212,7 @@ public class DateRevQueue extends AbstractRevQueue { return s.toString(); } - private Entry newEntry(final RevCommit c) { + private Entry newEntry(RevCommit c) { Entry r = free; if (r == null) r = new Entry(); @@ -222,7 +222,7 @@ public class DateRevQueue extends AbstractRevQueue { return r; } - private void freeEntry(final Entry e) { + private void freeEntry(Entry e) { e.next = free; free = e; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DelayRevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DelayRevQueue.java index 4a0d19d60d..c397a01317 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DelayRevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DelayRevQueue.java @@ -69,7 +69,7 @@ final class DelayRevQueue extends Generator { private int size; - DelayRevQueue(final Generator g) { + DelayRevQueue(Generator g) { pending = g; delay = new FIFORevQueue(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java index ad05186354..eaec305b47 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/DepthGenerator.java @@ -113,7 +113,7 @@ class DepthGenerator extends Generator { } @Override - void shareFreeList(final BlockRevQueue q) { + void shareFreeList(BlockRevQueue q) { pending.shareFreeList(q); } @@ -134,7 +134,7 @@ class DepthGenerator extends Generator { int newDepth = c.depth + 1; - for (final RevCommit p : c.parents) { + for (RevCommit p : c.parents) { DepthWalk.Commit dp = (DepthWalk.Commit) p; // If no depth has been assigned to this commit, assign diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FIFORevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FIFORevQueue.java index 63b7990600..cdb084c15e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FIFORevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FIFORevQueue.java @@ -63,14 +63,14 @@ public class FIFORevQueue extends BlockRevQueue { super(); } - FIFORevQueue(final Generator s) throws MissingObjectException, + FIFORevQueue(Generator s) throws MissingObjectException, IncorrectObjectTypeException, IOException { super(s); } /** {@inheritDoc} */ @Override - public void add(final RevCommit c) { + public void add(RevCommit c) { Block b = tail; if (b == null) { b = free.newBlock(); @@ -92,7 +92,7 @@ public class FIFORevQueue extends BlockRevQueue { * @param c * the commit to insert into the queue. */ - public void unpop(final RevCommit c) { + public void unpop(RevCommit c) { Block b = head; if (b == null) { b = free.newBlock(); @@ -139,7 +139,7 @@ public class FIFORevQueue extends BlockRevQueue { } @Override - boolean everbodyHasFlag(final int f) { + boolean everbodyHasFlag(int f) { for (Block b = head; b != null; b = b.next) { for (int i = b.headIndex; i < b.tailIndex; i++) if ((b.commits[i].flags & f) == 0) @@ -149,7 +149,7 @@ public class FIFORevQueue extends BlockRevQueue { } @Override - boolean anybodyHasFlag(final int f) { + boolean anybodyHasFlag(int f) { for (Block b = head; b != null; b = b.next) { for (int i = b.headIndex; i < b.tailIndex; i++) if ((b.commits[i].flags & f) != 0) @@ -158,7 +158,7 @@ public class FIFORevQueue extends BlockRevQueue { return false; } - void removeFlag(final int f) { + void removeFlag(int f) { final int not_f = ~f; for (Block b = head; b != null; b = b.next) { for (int i = b.headIndex; i < b.tailIndex; i++) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FixUninterestingGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FixUninterestingGenerator.java index 9d734a7296..4e6d7e681d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FixUninterestingGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FixUninterestingGenerator.java @@ -61,7 +61,7 @@ import org.eclipse.jgit.errors.MissingObjectException; final class FixUninterestingGenerator extends Generator { private final Generator pending; - FixUninterestingGenerator(final Generator g) { + FixUninterestingGenerator(Generator g) { pending = g; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java index 2da97c891b..dae3aacb83 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FollowFilter.java @@ -95,7 +95,7 @@ public class FollowFilter extends TreeFilter { private RenameCallback renameCallback; - FollowFilter(final PathFilter path, final DiffConfig cfg) { + FollowFilter(PathFilter path, DiffConfig cfg) { this.path = path; this.cfg = cfg; } @@ -112,7 +112,7 @@ public class FollowFilter extends TreeFilter { /** {@inheritDoc} */ @Override - public boolean include(final TreeWalk walker) + public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { return path.include(walker) && ANY_DIFF.include(walker); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterKey.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterKey.java index 360be298e3..45d5f809bb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterKey.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterKey.java @@ -70,7 +70,7 @@ public final class FooterKey { * @param keyName * name of the footer line. */ - public FooterKey(final String keyName) { + public FooterKey(String keyName) { name = keyName; raw = Constants.encode(keyName.toLowerCase(Locale.ROOT)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java index 074ce8275c..d6fed66702 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/FooterLine.java @@ -86,7 +86,7 @@ public final class FooterLine { * key to test this line's key name against. * @return true if {@code key.getName().equalsIgnorecase(getKey())}. */ - public boolean matches(final FooterKey key) { + public boolean matches(FooterKey key) { final byte[] kRaw = key.raw; final int len = kRaw.length; int bPtr = keyStart; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/Generator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/Generator.java index a95303b641..b2c92ea249 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/Generator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/Generator.java @@ -81,7 +81,7 @@ abstract class Generator { * @param q * another FIFO queue that wants to share our queue's free list. */ - void shareFreeList(final BlockRevQueue q) { + void shareFreeList(BlockRevQueue q) { // Do nothing by default. } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/LIFORevQueue.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/LIFORevQueue.java index f734b693ef..846b8d92fa 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/LIFORevQueue.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/LIFORevQueue.java @@ -62,14 +62,14 @@ public class LIFORevQueue extends BlockRevQueue { super(); } - LIFORevQueue(final Generator s) throws MissingObjectException, + LIFORevQueue(Generator s) throws MissingObjectException, IncorrectObjectTypeException, IOException { super(s); } /** {@inheritDoc} */ @Override - public void add(final RevCommit c) { + public void add(RevCommit c) { Block b = head; if (b == null || !b.canUnpop()) { b = free.newBlock(); @@ -103,7 +103,7 @@ public class LIFORevQueue extends BlockRevQueue { } @Override - boolean everbodyHasFlag(final int f) { + boolean everbodyHasFlag(int f) { for (Block b = head; b != null; b = b.next) { for (int i = b.headIndex; i < b.tailIndex; i++) if ((b.commits[i].flags & f) == 0) @@ -113,7 +113,7 @@ public class LIFORevQueue extends BlockRevQueue { } @Override - boolean anybodyHasFlag(final int f) { + boolean anybodyHasFlag(int f) { for (Block b = head; b != null; b = b.next) { for (int i = b.headIndex; i < b.tailIndex; i++) if ((b.commits[i].flags & f) != 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java index 73ce9854e0..2fe95318b2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/MergeBaseGenerator.java @@ -84,12 +84,12 @@ class MergeBaseGenerator extends Generator { private CarryStack stack; - MergeBaseGenerator(final RevWalk w) { + MergeBaseGenerator(RevWalk w) { walker = w; pending = new DateRevQueue(); } - void init(final AbstractRevQueue p) throws IOException { + void init(AbstractRevQueue p) throws IOException { try { for (;;) { final RevCommit c = p.next(); @@ -119,7 +119,7 @@ class MergeBaseGenerator extends Generator { } } - private void add(final RevCommit c) { + private void add(RevCommit c) { final int flag = walker.allocFlag(); branchMask |= flag; if ((c.flags & branchMask) != 0) { @@ -146,7 +146,7 @@ class MergeBaseGenerator extends Generator { return null; } - for (final RevCommit p : c.parents) { + for (RevCommit p : c.parents) { if ((p.flags & IN_PENDING) != 0) continue; if ((p.flags & PARSED) == 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java index 25c3e1224e..e5903c9117 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/ObjectWalk.java @@ -119,7 +119,7 @@ public class ObjectWalk extends RevWalk { * @param repo * the repository the walker will obtain data from. */ - public ObjectWalk(final Repository repo) { + public ObjectWalk(Repository repo) { this(repo.newObjectReader()); } @@ -699,7 +699,7 @@ public class ObjectWalk extends RevWalk { /** {@inheritDoc} */ @Override - protected void reset(final int retainFlags) { + protected void reset(int retainFlags) { super.reset(retainFlags); for (RevObject obj : rootObjects) @@ -711,7 +711,7 @@ public class ObjectWalk extends RevWalk { freeVisit = null; } - private void addObject(final RevObject o) { + private void addObject(RevObject o) { if ((o.flags & IN_PENDING) == 0) { o.flags |= IN_PENDING; rootObjects.add(o); @@ -719,7 +719,7 @@ public class ObjectWalk extends RevWalk { } } - private void markTreeUninteresting(final RevTree tree) + private void markTreeUninteresting(RevTree tree) throws MissingObjectException, IncorrectObjectTypeException, IOException { if ((tree.flags & UNINTERESTING) != 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java index 94ae2c993c..e607b7daa0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/PendingGenerator.java @@ -140,7 +140,7 @@ class PendingGenerator extends Generator { produce = filter.include(walker, c); } - for (final RevCommit p : c.parents) { + for (RevCommit p : c.parents) { if ((p.flags & SEEN) != 0) continue; if ((p.flags & PARSED) == 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevBlob.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevBlob.java index d3529292e6..cc5e3e40db 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevBlob.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevBlob.java @@ -62,7 +62,7 @@ public class RevBlob extends RevObject { * @param id * object name for the blob. */ - protected RevBlob(final AnyObjectId id) { + protected RevBlob(AnyObjectId id) { super(id); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java index 9db146706f..b67f934f6e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java @@ -44,7 +44,7 @@ package org.eclipse.jgit.revwalk; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.nio.charset.Charset; @@ -148,18 +148,18 @@ public class RevCommit extends RevObject { * @param id * object name for the commit. */ - protected RevCommit(final AnyObjectId id) { + protected RevCommit(AnyObjectId id) { super(id); } @Override - void parseHeaders(final RevWalk walk) throws MissingObjectException, + void parseHeaders(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { parseCanonical(walk, walk.getCachedBytes(this)); } @Override - void parseBody(final RevWalk walk) throws MissingObjectException, + void parseBody(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (buffer == null) { buffer = walk.getCachedBytes(this); @@ -168,7 +168,7 @@ public class RevCommit extends RevObject { } } - void parseCanonical(final RevWalk walk, final byte[] raw) + void parseCanonical(RevWalk walk, byte[] raw) throws IOException { if (!walk.shallowCommitsInitialized) walk.initializeShallowCommits(); @@ -310,7 +310,7 @@ public class RevCommit extends RevObject { * @param flag * the single flag value to carry back onto parents. */ - public void carry(final RevFlag flag) { + public void carry(RevFlag flag) { final int carry = flags & flag.mask; if (carry != 0) carryFlags(this, carry); @@ -353,7 +353,7 @@ public class RevCommit extends RevObject { * @throws java.lang.ArrayIndexOutOfBoundsException * an invalid parent index was specified. */ - public final RevCommit getParent(final int nth) { + public final RevCommit getParent(int nth) { return parents[nth]; } @@ -490,7 +490,7 @@ public class RevCommit extends RevObject { return str; } - static boolean hasLF(final byte[] r, int b, final int e) { + static boolean hasLF(byte[] r, int b, int e) { while (b < e) if (r[b++] == '\n') return true; @@ -539,7 +539,7 @@ public class RevCommit extends RevObject { try { return getEncoding(); } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { - return UTF_8; + return CHARSET; } } @@ -615,7 +615,7 @@ public class RevCommit extends RevObject { * with the specified key, or there are no footers at all. * @see #getFooterLines() */ - public final List<String> getFooterLines(final String keyName) { + public final List<String> getFooterLines(String keyName) { return getFooterLines(new FooterKey(keyName)); } @@ -630,12 +630,12 @@ public class RevCommit extends RevObject { * with the specified key, or there are no footers at all. * @see #getFooterLines() */ - public final List<String> getFooterLines(final FooterKey keyName) { + public final List<String> getFooterLines(FooterKey keyName) { final List<FooterLine> src = getFooterLines(); if (src.isEmpty()) return Collections.emptyList(); final ArrayList<String> r = new ArrayList<>(src.size()); - for (final FooterLine f : src) { + for (FooterLine f : src) { if (f.matches(keyName)) r.add(f.getValue()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java index 38cf3f510a..d2fda2f91e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommitList.java @@ -91,7 +91,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * object that should be present was not found. Repository * corruption may have occurred. */ - public void applyFlag(final RevFilter matching, final RevFlag flag) + public void applyFlag(RevFilter matching, RevFlag flag) throws MissingObjectException, IncorrectObjectTypeException, IOException { applyFlag(matching, flag, 0, size()); @@ -165,7 +165,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * the flag to remove. Applications are responsible for * allocating this flag from the source RevWalk. */ - public void clearFlag(final RevFlag flag) { + public void clearFlag(RevFlag flag) { clearFlag(flag, 0, size()); } @@ -207,7 +207,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * @return index of the first commit at or after index <code>begin</code> * that has the specified flag set on it; -1 if no match is found. */ - public int indexOf(final RevFlag flag, int begin) { + public int indexOf(RevFlag flag, int begin) { while (begin < size()) { int index = begin; Block s = contents; @@ -238,7 +238,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * @return index of the first commit at or before index <code>begin</code> * that has the specified flag set on it; -1 if no match is found. */ - public int lastIndexOf(final RevFlag flag, int begin) { + public int lastIndexOf(RevFlag flag, int begin) { begin = Math.min(begin, size() - 1); while (begin >= 0) { int index = begin; @@ -265,7 +265,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * the walker to populate from. * @see #fillTo(int) */ - public void source(final RevWalk w) { + public void source(RevWalk w) { walker = w; } @@ -299,7 +299,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * see {@link org.eclipse.jgit.revwalk.RevWalk#next()} */ @SuppressWarnings("unchecked") - public void fillTo(final int highMark) throws MissingObjectException, + public void fillTo(int highMark) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (walker == null || size > highMark) return; @@ -364,7 +364,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * see {@link org.eclipse.jgit.revwalk.RevWalk#next()} */ @SuppressWarnings("unchecked") - public void fillTo(final RevCommit commitToLoad, int highMark) + public void fillTo(RevCommit commitToLoad, int highMark) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (walker == null || commitToLoad == null @@ -419,7 +419,7 @@ public class RevCommitList<E extends RevCommit> extends RevObjectList<E> { * @param e * the object being added (or set) into the list. */ - protected void enter(final int index, final E e) { + protected void enter(int index, E e) { // Do nothing by default. } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlag.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlag.java index 1e79867425..413a552962 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlag.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlag.java @@ -85,7 +85,7 @@ public class RevFlag { final int mask; - RevFlag(final RevWalk w, final String n, final int m) { + RevFlag(RevWalk w, String n, int m) { walker = w; name = n; mask = m; @@ -107,7 +107,7 @@ public class RevFlag { } static class StaticRevFlag extends RevFlag { - StaticRevFlag(final String n, final int m) { + StaticRevFlag(String n, int m) { super(null, n, m); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlagSet.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlagSet.java index 9740d1417d..45a730cfd2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlagSet.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevFlagSet.java @@ -73,7 +73,7 @@ public class RevFlagSet extends AbstractSet<RevFlag> { * @param s * the set to copy flags from. */ - public RevFlagSet(final RevFlagSet s) { + public RevFlagSet(RevFlagSet s) { mask = s.mask; active = new ArrayList<>(s.active); } @@ -84,14 +84,14 @@ public class RevFlagSet extends AbstractSet<RevFlag> { * @param s * the collection to copy flags from. */ - public RevFlagSet(final Collection<RevFlag> s) { + public RevFlagSet(Collection<RevFlag> s) { this(); addAll(s); } /** {@inheritDoc} */ @Override - public boolean contains(final Object o) { + public boolean contains(Object o) { if (o instanceof RevFlag) return (mask & ((RevFlag) o).mask) != 0; return false; @@ -99,7 +99,7 @@ public class RevFlagSet extends AbstractSet<RevFlag> { /** {@inheritDoc} */ @Override - public boolean containsAll(final Collection<?> c) { + public boolean containsAll(Collection<?> c) { if (c instanceof RevFlagSet) { final int cMask = ((RevFlagSet) c).mask; return (mask & cMask) == cMask; @@ -109,7 +109,7 @@ public class RevFlagSet extends AbstractSet<RevFlag> { /** {@inheritDoc} */ @Override - public boolean add(final RevFlag flag) { + public boolean add(RevFlag flag) { if ((mask & flag.mask) != 0) return false; mask |= flag.mask; @@ -122,7 +122,7 @@ public class RevFlagSet extends AbstractSet<RevFlag> { /** {@inheritDoc} */ @Override - public boolean remove(final Object o) { + public boolean remove(Object o) { final RevFlag flag = (RevFlag) o; if ((mask & flag.mask) == 0) return false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java index 4a88105d10..eef9bf33e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObject.java @@ -60,7 +60,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { int flags; - RevObject(final AnyObjectId name) { + RevObject(AnyObjectId name) { super(name); } @@ -93,7 +93,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * the flag to test. * @return true if the flag has been added to this object; false if not. */ - public final boolean has(final RevFlag flag) { + public final boolean has(RevFlag flag) { return (flags & flag.mask) != 0; } @@ -105,7 +105,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @return true if any flag in the set has been added to this object; false * if not. */ - public final boolean hasAny(final RevFlagSet set) { + public final boolean hasAny(RevFlagSet set) { return (flags & set.mask) != 0; } @@ -117,7 +117,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @return true if all flags of the set have been added to this object; * false if some or none have been added. */ - public final boolean hasAll(final RevFlagSet set) { + public final boolean hasAll(RevFlagSet set) { return (flags & set.mask) == set.mask; } @@ -129,7 +129,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @param flag * the flag to mark on this object, for later testing. */ - public final void add(final RevFlag flag) { + public final void add(RevFlag flag) { flags |= flag.mask; } @@ -139,7 +139,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @param set * the set of flags to mark on this object, for later testing. */ - public final void add(final RevFlagSet set) { + public final void add(RevFlagSet set) { flags |= set.mask; } @@ -151,7 +151,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @param flag * the flag to remove from this object. */ - public final void remove(final RevFlag flag) { + public final void remove(RevFlag flag) { flags &= ~flag.mask; } @@ -161,7 +161,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @param set * the flag to remove from this object. */ - public final void remove(final RevFlagSet set) { + public final void remove(RevFlagSet set) { flags &= ~set.mask; } @@ -183,7 +183,7 @@ public abstract class RevObject extends ObjectIdOwnerMap.Entry { * @param s * buffer to append a debug description of core RevFlags onto. */ - protected void appendCoreFlags(final StringBuilder s) { + protected void appendCoreFlags(StringBuilder s) { s.append((flags & RevWalk.TOPO_DELAY) != 0 ? 'o' : '-'); s.append((flags & RevWalk.TEMP_MARK) != 0 ? 't' : '-'); s.append((flags & RevWalk.REWRITE) != 0 ? 'r' : '-'); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObjectList.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObjectList.java index 2bb4427181..2f21e17455 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObjectList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevObjectList.java @@ -82,7 +82,7 @@ public class RevObjectList<E extends RevObject> extends AbstractList<E> { /** {@inheritDoc} */ @Override - public void add(final int index, final E element) { + public void add(int index, E element) { if (index != size) throw new UnsupportedOperationException(MessageFormat.format( JGitText.get().unsupportedOperationNotAddAtEnd, @@ -147,7 +147,7 @@ public class RevObjectList<E extends RevObject> extends AbstractList<E> { final int shift; - Block(final int s) { + Block(int s) { shift = s; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java index d74837e860..0050bac0ae 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.revwalk; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.nio.charset.Charset; @@ -137,18 +137,18 @@ public class RevTag extends RevObject { * @param id * object name for the tag. */ - protected RevTag(final AnyObjectId id) { + protected RevTag(AnyObjectId id) { super(id); } @Override - void parseHeaders(final RevWalk walk) throws MissingObjectException, + void parseHeaders(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { parseCanonical(walk, walk.getCachedBytes(this)); } @Override - void parseBody(final RevWalk walk) throws MissingObjectException, + void parseBody(RevWalk walk) throws MissingObjectException, IncorrectObjectTypeException, IOException { if (buffer == null) { buffer = walk.getCachedBytes(this); @@ -157,7 +157,7 @@ public class RevTag extends RevObject { } } - void parseCanonical(final RevWalk walk, final byte[] rawTag) + void parseCanonical(RevWalk walk, byte[] rawTag) throws CorruptObjectException { final MutableInteger pos = new MutableInteger(); final int oType; @@ -169,7 +169,7 @@ public class RevTag extends RevObject { int p = pos.value += 4; // "tag " final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1; - tagName = RawParseUtils.decode(UTF_8, rawTag, p, nameEnd); + tagName = RawParseUtils.decode(CHARSET, rawTag, p, nameEnd); if (walk.isRetainBody()) buffer = rawTag; @@ -257,7 +257,7 @@ public class RevTag extends RevObject { try { return RawParseUtils.parseEncoding(buffer); } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { - return UTF_8; + return CHARSET; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTree.java index 92b81a17d6..e7de270f65 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTree.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTree.java @@ -62,7 +62,7 @@ public class RevTree extends RevObject { * @param id * object name for the tree. */ - protected RevTree(final AnyObjectId id) { + protected RevTree(AnyObjectId id) { super(id); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java index 91c15a1e70..a986cfd8ff 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java @@ -209,7 +209,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * ObjectReader will be created by the walker, and will be closed * when the walker is closed. */ - public RevWalk(final Repository repo) { + public RevWalk(Repository repo) { this(repo.newObjectReader(), true); } @@ -294,7 +294,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public void markStart(final RevCommit c) throws MissingObjectException, + public void markStart(RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { if ((c.flags & SEEN) != 0) return; @@ -324,10 +324,10 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public void markStart(final Collection<RevCommit> list) + public void markStart(Collection<RevCommit> list) throws MissingObjectException, IncorrectObjectTypeException, IOException { - for (final RevCommit c : list) + for (RevCommit c : list) markStart(c); } @@ -364,7 +364,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public void markUninteresting(final RevCommit c) + public void markUninteresting(RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { c.flags |= UNINTERESTING; @@ -402,7 +402,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public boolean isMergedInto(final RevCommit base, final RevCommit tip) + public boolean isMergedInto(RevCommit base, RevCommit tip) throws MissingObjectException, IncorrectObjectTypeException, IOException { final RevFilter oldRF = filter; @@ -475,7 +475,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @param s * a sorting strategy to enable. */ - public void sort(final RevSort s) { + public void sort(RevSort s) { assertNotStarted(); sorting.clear(); sorting.add(s); @@ -496,7 +496,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * true if this strategy should be used, false if it should be * removed. */ - public void sort(final RevSort s, final boolean use) { + public void sort(RevSort s, boolean use) { assertNotStarted(); if (use) sorting.add(s); @@ -541,7 +541,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @see org.eclipse.jgit.revwalk.filter.AndRevFilter * @see org.eclipse.jgit.revwalk.filter.OrRevFilter */ - public void setRevFilter(final RevFilter newFilter) { + public void setRevFilter(RevFilter newFilter) { assertNotStarted(); filter = newFilter != null ? newFilter : RevFilter.ALL; } @@ -582,7 +582,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * will be used instead, as it matches everything. * @see org.eclipse.jgit.treewalk.filter.PathFilter */ - public void setTreeFilter(final TreeFilter newFilter) { + public void setTreeFilter(TreeFilter newFilter) { assertNotStarted(); treeFilter = newFilter != null ? newFilter : TreeFilter.ALL; } @@ -638,7 +638,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @param retain * true to retain bodies; false to discard them early. */ - public void setRetainBody(final boolean retain) { + public void setRetainBody(boolean retain) { retainBody = retain; } @@ -653,7 +653,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @return reference to the blob object. Never null. */ @NonNull - public RevBlob lookupBlob(final AnyObjectId id) { + public RevBlob lookupBlob(AnyObjectId id) { RevBlob c = (RevBlob) objects.get(id); if (c == null) { c = new RevBlob(id); @@ -673,7 +673,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @return reference to the tree object. Never null. */ @NonNull - public RevTree lookupTree(final AnyObjectId id) { + public RevTree lookupTree(AnyObjectId id) { RevTree c = (RevTree) objects.get(id); if (c == null) { c = new RevTree(id); @@ -696,7 +696,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @return reference to the commit object. Never null. */ @NonNull - public RevCommit lookupCommit(final AnyObjectId id) { + public RevCommit lookupCommit(AnyObjectId id) { RevCommit c = (RevCommit) objects.get(id); if (c == null) { c = createCommit(id); @@ -716,7 +716,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @return reference to the tag object. Never null. */ @NonNull - public RevTag lookupTag(final AnyObjectId id) { + public RevTag lookupTag(AnyObjectId id) { RevTag c = (RevTag) objects.get(id); if (c == null) { c = new RevTag(id); @@ -738,7 +738,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @return reference to the object. Never null. */ @NonNull - public RevObject lookupAny(final AnyObjectId id, final int type) { + public RevObject lookupAny(AnyObjectId id, int type) { RevObject r = objects.get(id); if (r == null) { switch (type) { @@ -793,7 +793,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * a pack file or loose object could not be read. */ @NonNull - public RevCommit parseCommit(final AnyObjectId id) + public RevCommit parseCommit(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevObject c = peel(parseAny(id)); @@ -821,7 +821,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * a pack file or loose object could not be read. */ @NonNull - public RevTree parseTree(final AnyObjectId id) + public RevTree parseTree(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevObject c = peel(parseAny(id)); @@ -856,7 +856,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * a pack file or loose object could not be read. */ @NonNull - public RevTag parseTag(final AnyObjectId id) throws MissingObjectException, + public RevTag parseTag(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevObject c = parseAny(id); if (!(c instanceof RevTag)) @@ -882,7 +882,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * a pack file or loose object could not be read. */ @NonNull - public RevObject parseAny(final AnyObjectId id) + public RevObject parseAny(AnyObjectId id) throws MissingObjectException, IOException { RevObject r = objects.get(id); if (r == null) @@ -1040,7 +1040,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public void parseHeaders(final RevObject obj) + public void parseHeaders(RevObject obj) throws MissingObjectException, IOException { if ((obj.flags & PARSED) == 0) obj.parseHeaders(this); @@ -1059,7 +1059,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.io.IOException * a pack file or loose object could not be read. */ - public void parseBody(final RevObject obj) + public void parseBody(RevObject obj) throws MissingObjectException, IOException { obj.parseBody(this); } @@ -1100,7 +1100,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @throws java.lang.IllegalArgumentException * too many flags have been reserved on this revision walker. */ - public RevFlag newFlag(final String name) { + public RevFlag newFlag(String name) { final int m = allocFlag(); return new RevFlag(this, name, m); } @@ -1124,7 +1124,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @param flag * the flag to carry onto parents, if set on a descendant. */ - public void carry(final RevFlag flag) { + public void carry(RevFlag flag) { if ((freeFlags & flag.mask) != 0) throw new IllegalArgumentException(MessageFormat.format(JGitText.get().flagIsDisposed, flag.name)); if (flag.walker != this) @@ -1141,8 +1141,8 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @param set * the flags to carry onto parents, if set on a descendant. */ - public void carry(final Collection<RevFlag> set) { - for (final RevFlag flag : set) + public void carry(Collection<RevFlag> set) { + for (RevFlag flag : set) carry(flag); } @@ -1200,11 +1200,11 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * @param flag * the to recycle. */ - public void disposeFlag(final RevFlag flag) { + public void disposeFlag(RevFlag flag) { freeFlag(flag.mask); } - void freeFlag(final int mask) { + void freeFlag(int mask) { retainOnReset &= ~mask; if (isNotStarted()) { freeFlags |= mask; @@ -1244,7 +1244,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * application flags that should <b>not</b> be cleared from * existing commit objects. */ - public final void resetRetain(final RevFlagSet retainFlags) { + public final void resetRetain(RevFlagSet retainFlags) { reset(retainFlags.mask); } @@ -1262,9 +1262,9 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * application flags that should <b>not</b> be cleared from * existing commit objects. */ - public final void resetRetain(final RevFlag... retainFlags) { + public final void resetRetain(RevFlag... retainFlags) { int mask = 0; - for (final RevFlag flag : retainFlags) + for (RevFlag flag : retainFlags) mask |= flag.mask; reset(mask); } @@ -1286,7 +1286,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { final int clearFlags = ~retainFlags; final FIFORevQueue q = new FIFORevQueue(); - for (final RevCommit c : roots) { + for (RevCommit c : roots) { if ((c.flags & clearFlags) == 0) continue; c.flags &= retainFlags; @@ -1300,7 +1300,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { break; if (c.parents == null) continue; - for (final RevCommit p : c.parents) { + for (RevCommit p : c.parents) { if ((p.flags & clearFlags) == 0) continue; p.flags &= retainFlags; @@ -1435,11 +1435,11 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable { * the object this walker requires a commit reference for. * @return a new unparsed reference for the object. */ - protected RevCommit createCommit(final AnyObjectId id) { + protected RevCommit createCommit(AnyObjectId id) { return new RevCommit(id); } - void carryFlagsImpl(final RevCommit c) { + void carryFlagsImpl(RevCommit c) { final int carry = c.flags & carryFlags; if (carry != 0) RevCommit.carryFlags(c, carry); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java index f82301a82d..1c868ffe08 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RewriteGenerator.java @@ -76,12 +76,12 @@ class RewriteGenerator extends Generator { private final Generator source; - RewriteGenerator(final Generator s) { + RewriteGenerator(Generator s) { source = s; } @Override - void shareFreeList(final BlockRevQueue q) { + void shareFreeList(BlockRevQueue q) { source.shareFreeList(q); } @@ -148,7 +148,7 @@ class RewriteGenerator extends Generator { } } - private RevCommit[] cleanup(final RevCommit[] oldList) { + private RevCommit[] cleanup(RevCommit[] oldList) { // Remove any duplicate parents caused due to rewrites (e.g. a merge // with two sides that both simplified back into the merge base). // We also may have deleted a parent by marking it null. @@ -167,14 +167,14 @@ class RewriteGenerator extends Generator { } if (newCnt == oldList.length) { - for (final RevCommit p : oldList) + for (RevCommit p : oldList) p.flags &= ~DUPLICATE; return oldList; } final RevCommit[] newList = new RevCommit[newCnt]; newCnt = 0; - for (final RevCommit p : oldList) { + for (RevCommit p : oldList) { if (p != null) { newList[newCnt++] = p; p.flags &= ~DUPLICATE; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java index 1ec6290317..eb129a2631 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/StartGenerator.java @@ -66,7 +66,7 @@ import org.eclipse.jgit.treewalk.filter.TreeFilter; class StartGenerator extends Generator { private final RevWalk walker; - StartGenerator(final RevWalk w) { + StartGenerator(RevWalk w) { walker = w; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java index 7b11d04901..645034351f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TopoSortGenerator.java @@ -69,7 +69,7 @@ class TopoSortGenerator extends Generator { * @throws IncorrectObjectTypeException * @throws IOException */ - TopoSortGenerator(final Generator s) throws MissingObjectException, + TopoSortGenerator(Generator s) throws MissingObjectException, IncorrectObjectTypeException, IOException { pending = new FIFORevQueue(); outputType = s.outputType() | SORT_TOPO; @@ -78,7 +78,7 @@ class TopoSortGenerator extends Generator { final RevCommit c = s.next(); if (c == null) break; - for (final RevCommit p : c.parents) + for (RevCommit p : c.parents) p.inDegree++; pending.add(c); } @@ -90,7 +90,7 @@ class TopoSortGenerator extends Generator { } @Override - void shareFreeList(final BlockRevQueue q) { + void shareFreeList(BlockRevQueue q) { q.shareFreeList(pending); } @@ -113,7 +113,7 @@ class TopoSortGenerator extends Generator { // All of our children have already produced, // so it is OK for us to produce now as well. // - for (final RevCommit p : c.parents) { + for (RevCommit p : c.parents) { if (--p.inDegree == 0 && (p.flags & TOPO_DELAY) != 0) { // This parent tried to come before us, but we are // his last child. unpop the parent so it goes right diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java index 99c5d59a11..11301538e6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/TreeRevFilter.java @@ -89,7 +89,7 @@ public class TreeRevFilter extends RevFilter { * replaced with a new filter following new paths after a rename. * @since 3.5 */ - public TreeRevFilter(final RevWalk walker, final TreeFilter t) { + public TreeRevFilter(RevWalk walker, TreeFilter t) { this(walker, t, 0); } @@ -132,7 +132,7 @@ public class TreeRevFilter extends RevFilter { /** {@inheritDoc} */ @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { // Reset the tree filter to scan this commit and parents. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AndRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AndRevFilter.java index 0019e0c283..dfb83b491a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AndRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AndRevFilter.java @@ -72,7 +72,7 @@ public abstract class AndRevFilter extends RevFilter { * second filter to test. * @return a filter that must match both input filters. */ - public static RevFilter create(final RevFilter a, final RevFilter b) { + public static RevFilter create(RevFilter a, RevFilter b) { if (a == ALL) return b; if (b == ALL) @@ -88,7 +88,7 @@ public abstract class AndRevFilter extends RevFilter { * filters. * @return a filter that must match all input filters. */ - public static RevFilter create(final RevFilter[] list) { + public static RevFilter create(RevFilter[] list) { if (list.length == 2) return create(list[0], list[1]); if (list.length < 2) @@ -106,7 +106,7 @@ public abstract class AndRevFilter extends RevFilter { * filters. * @return a filter that must match all input filters. */ - public static RevFilter create(final Collection<RevFilter> list) { + public static RevFilter create(Collection<RevFilter> list) { if (list.size() < 2) throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded); final RevFilter[] subfilters = new RevFilter[list.size()]; @@ -123,7 +123,7 @@ public abstract class AndRevFilter extends RevFilter { private final boolean requiresCommitBody; - Binary(final RevFilter one, final RevFilter two) { + Binary(RevFilter one, RevFilter two) { a = one; b = two; requiresCommitBody = a.requiresCommitBody() @@ -131,7 +131,7 @@ public abstract class AndRevFilter extends RevFilter { } @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { return a.include(walker, c) && b.include(walker, c); @@ -159,7 +159,7 @@ public abstract class AndRevFilter extends RevFilter { private final boolean requiresCommitBody; - List(final RevFilter[] list) { + List(RevFilter[] list) { subfilters = list; boolean rcb = false; @@ -169,10 +169,10 @@ public abstract class AndRevFilter extends RevFilter { } @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { - for (final RevFilter f : subfilters) { + for (RevFilter f : subfilters) { if (!f.include(walker, c)) return false; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java index e00feaf9a0..334d4f0144 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/AuthorRevFilter.java @@ -81,7 +81,7 @@ public class AuthorRevFilter { // Don't permit us to be created. } - static RawCharSequence textFor(final RevCommit cmit) { + static RawCharSequence textFor(RevCommit cmit) { final byte[] raw = cmit.getRawBuffer(); final int b = RawParseUtils.author(raw, 0); if (b < 0) @@ -91,12 +91,12 @@ public class AuthorRevFilter { } private static class PatternSearch extends PatternMatchRevFilter { - PatternSearch(final String patternText) { + PatternSearch(String patternText) { super(patternText, true, true, Pattern.CASE_INSENSITIVE); } @Override - protected CharSequence text(final RevCommit cmit) { + protected CharSequence text(RevCommit cmit) { return textFor(cmit); } @@ -107,12 +107,12 @@ public class AuthorRevFilter { } private static class SubStringSearch extends SubStringRevFilter { - SubStringSearch(final String patternText) { + SubStringSearch(String patternText) { super(patternText); } @Override - protected RawCharSequence text(final RevCommit cmit) { + protected RawCharSequence text(RevCommit cmit) { return textFor(cmit); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitTimeRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitTimeRevFilter.java index 9f4f10f3ae..38805153ef 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitTimeRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitTimeRevFilter.java @@ -64,7 +64,7 @@ public abstract class CommitTimeRevFilter extends RevFilter { * the point in time to cut on. * @return a new filter to select commits on or before <code>ts</code>. */ - public static final RevFilter before(final Date ts) { + public static final RevFilter before(Date ts) { return before(ts.getTime()); } @@ -75,7 +75,7 @@ public abstract class CommitTimeRevFilter extends RevFilter { * the point in time to cut on, in milliseconds * @return a new filter to select commits on or before <code>ts</code>. */ - public static final RevFilter before(final long ts) { + public static final RevFilter before(long ts) { return new Before(ts); } @@ -86,7 +86,7 @@ public abstract class CommitTimeRevFilter extends RevFilter { * the point in time to cut on. * @return a new filter to select commits on or after <code>ts</code>. */ - public static final RevFilter after(final Date ts) { + public static final RevFilter after(Date ts) { return after(ts.getTime()); } @@ -97,7 +97,7 @@ public abstract class CommitTimeRevFilter extends RevFilter { * the point in time to cut on, in milliseconds. * @return a new filter to select commits on or after <code>ts</code>. */ - public static final RevFilter after(final long ts) { + public static final RevFilter after(long ts) { return new After(ts); } @@ -109,7 +109,7 @@ public abstract class CommitTimeRevFilter extends RevFilter { * @param until the point in time to cut off. * @return a new filter to select commits between the given date/times. */ - public static final RevFilter between(final Date since, final Date until) { + public static final RevFilter between(Date since, Date until) { return between(since.getTime(), until.getTime()); } @@ -121,13 +121,13 @@ public abstract class CommitTimeRevFilter extends RevFilter { * @param until the point in time to cut off, in millisconds. * @return a new filter to select commits between the given date/times. */ - public static final RevFilter between(final long since, final long until) { + public static final RevFilter between(long since, long until) { return new Between(since, until); } final int when; - CommitTimeRevFilter(final long ts) { + CommitTimeRevFilter(long ts) { when = (int) (ts / 1000); } @@ -144,12 +144,12 @@ public abstract class CommitTimeRevFilter extends RevFilter { } private static class Before extends CommitTimeRevFilter { - Before(final long ts) { + Before(long ts) { super(ts); } @Override - public boolean include(final RevWalk walker, final RevCommit cmit) + public boolean include(RevWalk walker, RevCommit cmit) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { return cmit.getCommitTime() <= when; @@ -163,12 +163,12 @@ public abstract class CommitTimeRevFilter extends RevFilter { } private static class After extends CommitTimeRevFilter { - After(final long ts) { + After(long ts) { super(ts); } @Override - public boolean include(final RevWalk walker, final RevCommit cmit) + public boolean include(RevWalk walker, RevCommit cmit) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { // Since the walker sorts commits by commit time we can be @@ -190,13 +190,13 @@ public abstract class CommitTimeRevFilter extends RevFilter { private static class Between extends CommitTimeRevFilter { private final int until; - Between(final long since, final long until) { + Between(long since, long until) { super(since); this.until = (int) (until / 1000); } @Override - public boolean include(final RevWalk walker, final RevCommit cmit) + public boolean include(RevWalk walker, RevCommit cmit) throws StopWalkException, MissingObjectException, IncorrectObjectTypeException, IOException { return cmit.getCommitTime() <= until && cmit.getCommitTime() >= when; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitterRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitterRevFilter.java index 4a1b3a6c7f..37c840e379 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitterRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/CommitterRevFilter.java @@ -81,7 +81,7 @@ public class CommitterRevFilter { // Don't permit us to be created. } - static RawCharSequence textFor(final RevCommit cmit) { + static RawCharSequence textFor(RevCommit cmit) { final byte[] raw = cmit.getRawBuffer(); final int b = RawParseUtils.committer(raw, 0); if (b < 0) @@ -91,12 +91,12 @@ public class CommitterRevFilter { } private static class PatternSearch extends PatternMatchRevFilter { - PatternSearch(final String patternText) { + PatternSearch(String patternText) { super(patternText, true, true, Pattern.CASE_INSENSITIVE); } @Override - protected CharSequence text(final RevCommit cmit) { + protected CharSequence text(RevCommit cmit) { return textFor(cmit); } @@ -107,12 +107,12 @@ public class CommitterRevFilter { } private static class SubStringSearch extends SubStringRevFilter { - SubStringSearch(final String patternText) { + SubStringSearch(String patternText) { super(patternText); } @Override - protected RawCharSequence text(final RevCommit cmit) { + protected RawCharSequence text(RevCommit cmit) { return textFor(cmit); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/MessageRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/MessageRevFilter.java index f1f4065480..480aaa38eb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/MessageRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/MessageRevFilter.java @@ -81,7 +81,7 @@ public class MessageRevFilter { // Don't permit us to be created. } - static RawCharSequence textFor(final RevCommit cmit) { + static RawCharSequence textFor(RevCommit cmit) { final byte[] raw = cmit.getRawBuffer(); final int b = RawParseUtils.commitMessage(raw, 0); if (b < 0) @@ -90,13 +90,13 @@ public class MessageRevFilter { } private static class PatternSearch extends PatternMatchRevFilter { - PatternSearch(final String patternText) { + PatternSearch(String patternText) { super(patternText, true, true, Pattern.CASE_INSENSITIVE | Pattern.DOTALL); } @Override - protected CharSequence text(final RevCommit cmit) { + protected CharSequence text(RevCommit cmit) { return textFor(cmit); } @@ -107,12 +107,12 @@ public class MessageRevFilter { } private static class SubStringSearch extends SubStringRevFilter { - SubStringSearch(final String patternText) { + SubStringSearch(String patternText) { super(patternText); } @Override - protected RawCharSequence text(final RevCommit cmit) { + protected RawCharSequence text(RevCommit cmit) { return textFor(cmit); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/NotRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/NotRevFilter.java index 84b7f6b7b6..69dec567b8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/NotRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/NotRevFilter.java @@ -61,13 +61,13 @@ public class NotRevFilter extends RevFilter { * filter to negate. * @return a filter that does the reverse of <code>a</code>. */ - public static RevFilter create(final RevFilter a) { + public static RevFilter create(RevFilter a) { return new NotRevFilter(a); } private final RevFilter a; - private NotRevFilter(final RevFilter one) { + private NotRevFilter(RevFilter one) { a = one; } @@ -79,7 +79,7 @@ public class NotRevFilter extends RevFilter { /** {@inheritDoc} */ @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { return !a.include(walker, c); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/OrRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/OrRevFilter.java index a14764a82d..1cef12f79c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/OrRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/OrRevFilter.java @@ -72,7 +72,7 @@ public abstract class OrRevFilter extends RevFilter { * second filter to test. * @return a filter that must match at least one input filter. */ - public static RevFilter create(final RevFilter a, final RevFilter b) { + public static RevFilter create(RevFilter a, RevFilter b) { if (a == ALL || b == ALL) return ALL; return new Binary(a, b); @@ -86,7 +86,7 @@ public abstract class OrRevFilter extends RevFilter { * filters. * @return a filter that must match at least one input filter. */ - public static RevFilter create(final RevFilter[] list) { + public static RevFilter create(RevFilter[] list) { if (list.length == 2) return create(list[0], list[1]); if (list.length < 2) @@ -104,7 +104,7 @@ public abstract class OrRevFilter extends RevFilter { * filters. * @return a filter that must match at least one input filter. */ - public static RevFilter create(final Collection<RevFilter> list) { + public static RevFilter create(Collection<RevFilter> list) { if (list.size() < 2) throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded); final RevFilter[] subfilters = new RevFilter[list.size()]; @@ -121,7 +121,7 @@ public abstract class OrRevFilter extends RevFilter { private final boolean requiresCommitBody; - Binary(final RevFilter one, final RevFilter two) { + Binary(RevFilter one, RevFilter two) { a = one; b = two; requiresCommitBody = a.requiresCommitBody() @@ -129,7 +129,7 @@ public abstract class OrRevFilter extends RevFilter { } @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { return a.include(walker, c) || b.include(walker, c); @@ -157,7 +157,7 @@ public abstract class OrRevFilter extends RevFilter { private final boolean requiresCommitBody; - List(final RevFilter[] list) { + List(RevFilter[] list) { subfilters = list; boolean rcb = false; @@ -167,10 +167,10 @@ public abstract class OrRevFilter extends RevFilter { } @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { - for (final RevFilter f : subfilters) { + for (RevFilter f : subfilters) { if (f.include(walker, c)) return true; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java index edce224a6e..4f41edf54d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/PatternMatchRevFilter.java @@ -72,7 +72,7 @@ public abstract class PatternMatchRevFilter extends RevFilter { * @return same pattern, but re-encoded to match our funny raw UTF-8 * character sequence {@link org.eclipse.jgit.util.RawCharSequence}. */ - protected static final String forceToRaw(final String patternText) { + protected static final String forceToRaw(String patternText) { final byte[] b = Constants.encode(patternText); final StringBuilder needle = new StringBuilder(b.length); for (int i = 0; i < b.length; i++) @@ -128,7 +128,7 @@ public abstract class PatternMatchRevFilter extends RevFilter { /** {@inheritDoc} */ @Override - public boolean include(final RevWalk walker, final RevCommit cmit) + public boolean include(RevWalk walker, RevCommit cmit) throws MissingObjectException, IncorrectObjectTypeException, IOException { return compiledPattern.reset(text(cmit)).matches(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFilter.java index 9068c57517..39f0d60166 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFilter.java @@ -103,7 +103,7 @@ public abstract class RevFilter { private static final class AllFilter extends RevFilter { @Override - public boolean include(final RevWalk walker, final RevCommit c) { + public boolean include(RevWalk walker, RevCommit c) { return true; } @@ -128,7 +128,7 @@ public abstract class RevFilter { private static final class NoneFilter extends RevFilter { @Override - public boolean include(final RevWalk walker, final RevCommit c) { + public boolean include(RevWalk walker, RevCommit c) { return false; } @@ -184,7 +184,7 @@ public abstract class RevFilter { private static final class NoMergesFilter extends RevFilter { @Override - public boolean include(final RevWalk walker, final RevCommit c) { + public boolean include(RevWalk walker, RevCommit c) { return c.getParentCount() < 2; } @@ -216,7 +216,7 @@ public abstract class RevFilter { private static final class MergeBaseFilter extends RevFilter { @Override - public boolean include(final RevWalk walker, final RevCommit c) { + public boolean include(RevWalk walker, RevCommit c) { throw new UnsupportedOperationException(JGitText.get().cannotBeCombined); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFlagFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFlagFilter.java index 8225e4d3e7..c67c44b216 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFlagFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/RevFlagFilter.java @@ -63,7 +63,7 @@ public abstract class RevFlagFilter extends RevFilter { * the flag to test. * @return filter that selects only commits with flag <code>a</code>. */ - public static RevFilter has(final RevFlag a) { + public static RevFilter has(RevFlag a) { final RevFlagSet s = new RevFlagSet(); s.add(a); return new HasAll(s); @@ -76,9 +76,9 @@ public abstract class RevFlagFilter extends RevFilter { * set of flags to test. * @return filter that selects only commits with all flags in <code>a</code>. */ - public static RevFilter hasAll(final RevFlag... a) { + public static RevFilter hasAll(RevFlag... a) { final RevFlagSet set = new RevFlagSet(); - for (final RevFlag flag : a) + for (RevFlag flag : a) set.add(flag); return new HasAll(set); } @@ -90,7 +90,7 @@ public abstract class RevFlagFilter extends RevFilter { * set of flags to test. * @return filter that selects only commits with all flags in <code>a</code>. */ - public static RevFilter hasAll(final RevFlagSet a) { + public static RevFilter hasAll(RevFlagSet a) { return new HasAll(new RevFlagSet(a)); } @@ -101,9 +101,9 @@ public abstract class RevFlagFilter extends RevFilter { * set of flags to test. * @return filter that selects only commits with any flag in <code>a</code>. */ - public static RevFilter hasAny(final RevFlag... a) { + public static RevFilter hasAny(RevFlag... a) { final RevFlagSet set = new RevFlagSet(); - for (final RevFlag flag : a) + for (RevFlag flag : a) set.add(flag); return new HasAny(set); } @@ -115,13 +115,13 @@ public abstract class RevFlagFilter extends RevFilter { * set of flags to test. * @return filter that selects only commits with any flag in <code>a</code>. */ - public static RevFilter hasAny(final RevFlagSet a) { + public static RevFilter hasAny(RevFlagSet a) { return new HasAny(new RevFlagSet(a)); } final RevFlagSet flags; - RevFlagFilter(final RevFlagSet m) { + RevFlagFilter(RevFlagSet m) { flags = m; } @@ -138,12 +138,12 @@ public abstract class RevFlagFilter extends RevFilter { } private static class HasAll extends RevFlagFilter { - HasAll(final RevFlagSet m) { + HasAll(RevFlagSet m) { super(m); } @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { return c.hasAll(flags); @@ -156,12 +156,12 @@ public abstract class RevFlagFilter extends RevFilter { } private static class HasAny extends RevFlagFilter { - HasAny(final RevFlagSet m) { + HasAny(RevFlagSet m) { super(m); } @Override - public boolean include(final RevWalk walker, final RevCommit c) + public boolean include(RevWalk walker, RevCommit c) throws MissingObjectException, IncorrectObjectTypeException, IOException { return c.hasAny(flags); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/SubStringRevFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/SubStringRevFilter.java index 3e6b1480e2..54650da0e0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/SubStringRevFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/filter/SubStringRevFilter.java @@ -65,7 +65,7 @@ public abstract class SubStringRevFilter extends RevFilter { * if {@link org.eclipse.jgit.revwalk.filter.PatternMatchRevFilter} * must be used instead. */ - public static boolean safe(final String pattern) { + public static boolean safe(String pattern) { for (int i = 0; i < pattern.length(); i++) { final char c = pattern.charAt(i); switch (c) { @@ -96,13 +96,13 @@ public abstract class SubStringRevFilter extends RevFilter { * the {@link #safe(String)} as regular expression meta * characters are treated as literals. */ - protected SubStringRevFilter(final String patternText) { + protected SubStringRevFilter(String patternText) { pattern = new RawSubStringPattern(patternText); } /** {@inheritDoc} */ @Override - public boolean include(final RevWalk walker, final RevCommit cmit) + public boolean include(RevWalk walker, RevCommit cmit) throws MissingObjectException, IncorrectObjectTypeException, IOException { return pattern.match(text(cmit)) >= 0; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java index 3f064e3341..4b272ba7a4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java @@ -49,6 +49,8 @@ package org.eclipse.jgit.storage.file; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; @@ -164,8 +166,8 @@ public class FileBasedConfig extends StoredConfig { } else { final String decoded; if (isUtf8(in)) { - decoded = RawParseUtils.decode( - RawParseUtils.UTF8_CHARSET, in, 3, in.length); + decoded = RawParseUtils.decode(CHARSET, + in, 3, in.length); utf8Bom = true; } else { decoded = RawParseUtils.decode(in); @@ -222,7 +224,7 @@ public class FileBasedConfig extends StoredConfig { bos.write(0xEF); bos.write(0xBB); bos.write(0xBF); - bos.write(text.getBytes(RawParseUtils.UTF8_CHARSET.name())); + bos.write(text.getBytes(CHARSET)); out = bos.toByteArray(); } else { out = Constants.encode(text); @@ -252,7 +254,7 @@ public class FileBasedConfig extends StoredConfig { super.clear(); } - private static ObjectId hash(final byte[] rawText) { + private static ObjectId hash(byte[] rawText) { return ObjectId.fromRaw(Constants.newMessageDigest().digest(rawText)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java index 19fc63e00b..c2e6a42001 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java @@ -98,7 +98,7 @@ public class WindowCacheConfig { * maximum number of streams to open at a time. Open packs count * against the process limits */ - public void setPackedGitOpenFiles(final int fdLimit) { + public void setPackedGitOpenFiles(int fdLimit) { packedGitOpenFiles = fdLimit; } @@ -121,7 +121,7 @@ public class WindowCacheConfig { * maximum number bytes of heap memory to dedicate to caching * pack file data. */ - public void setPackedGitLimit(final long newLimit) { + public void setPackedGitLimit(long newLimit) { packedGitLimit = newLimit; } @@ -142,7 +142,7 @@ public class WindowCacheConfig { * @param newSize * size in bytes of a single window read in from the pack file. */ - public void setPackedGitWindowSize(final int newSize) { + public void setPackedGitWindowSize(int newSize) { packedGitWindowSize = newSize; } @@ -165,7 +165,7 @@ public class WindowCacheConfig { * for windows; false reads entire window into a byte[] with * standard read calls. */ - public void setPackedGitMMAP(final boolean usemmap) { + public void setPackedGitMMAP(boolean usemmap) { packedGitMMAP = usemmap; } @@ -189,7 +189,7 @@ public class WindowCacheConfig { * maximum number of bytes to cache in delta base cache for * inflated, recently accessed objects, without delta chains. */ - public void setDeltaBaseCacheLimit(final int newLimit) { + public void setDeltaBaseCacheLimit(int newLimit) { deltaBaseCacheLimit = newLimit; } @@ -211,7 +211,7 @@ public class WindowCacheConfig { * array, while objects bigger than this size require using an * {@link org.eclipse.jgit.lib.ObjectStream}. */ - public void setStreamFileThreshold(final int newLimit) { + public void setStreamFileThreshold(int newLimit) { streamFileThreshold = newLimit; } @@ -226,7 +226,7 @@ public class WindowCacheConfig { * @return {@code this}. * @since 3.0 */ - public WindowCacheConfig fromConfig(final Config rc) { + public WindowCacheConfig fromConfig(Config rc) { setPackedGitOpenFiles(rc.getInt( "core", null, "packedgitopenfiles", getPackedGitOpenFiles())); //$NON-NLS-1$ //$NON-NLS-2$ setPackedGitLimit(rc.getLong( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java index 484cde29ee..256e41d22b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/pack/PackConfig.java @@ -1039,7 +1039,7 @@ public class PackConfig { * @param rc * configuration to read properties from. */ - public void fromConfig(final Config rc) { + public void fromConfig(Config rc) { setMaxDeltaDepth(rc.getInt("pack", "depth", getMaxDeltaDepth())); //$NON-NLS-1$ //$NON-NLS-2$ setDeltaSearchWindowSize(rc.getInt( "pack", "window", getDeltaSearchWindowSize())); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java index 2314cf10df..ce8995ad8f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -115,11 +115,13 @@ public class SubmoduleWalk implements AutoCloseable { * * @param repository * a {@link org.eclipse.jgit.lib.Repository} object. - * @return generator over submodule index entries + * @return generator over submodule index entries. The caller is responsible + * for calling {@link #close()}. * @throws java.io.IOException */ public static SubmoduleWalk forIndex(Repository repository) throws IOException { + @SuppressWarnings("resource") // The caller closes it SubmoduleWalk generator = new SubmoduleWalk(repository); try { DirCache index = repository.readDirCache(); @@ -369,7 +371,7 @@ public class SubmoduleWalk implements AutoCloseable { * the {@link org.eclipse.jgit.lib.Repository}. * @throws java.io.IOException */ - public SubmoduleWalk(final Repository repository) throws IOException { + public SubmoduleWalk(Repository repository) throws IOException { this.repository = repository; repoConfig = repository.getConfig(); walk = new TreeWalk(repository); @@ -386,7 +388,7 @@ public class SubmoduleWalk implements AutoCloseable { * .gitmodules config object * @return this generator */ - public SubmoduleWalk setModulesConfig(final Config config) { + public SubmoduleWalk setModulesConfig(Config config) { modulesConfig = config; loadPathNames(); return this; @@ -405,7 +407,7 @@ public class SubmoduleWalk implements AutoCloseable { * tree containing .gitmodules * @return this generator */ - public SubmoduleWalk setRootTree(final AbstractTreeIterator tree) { + public SubmoduleWalk setRootTree(AbstractTreeIterator tree) { rootTree = tree; modulesConfig = null; pathToName = null; @@ -426,7 +428,7 @@ public class SubmoduleWalk implements AutoCloseable { * @return this generator * @throws java.io.IOException */ - public SubmoduleWalk setRootTree(final AnyObjectId id) throws IOException { + public SubmoduleWalk setRootTree(AnyObjectId id) throws IOException { final CanonicalTreeParser p = new CanonicalTreeParser(); p.reset(walk.getObjectReader(), id); rootTree = p; @@ -560,7 +562,7 @@ public class SubmoduleWalk implements AutoCloseable { * @return this generator * @throws org.eclipse.jgit.errors.CorruptObjectException */ - public SubmoduleWalk setTree(final AbstractTreeIterator iterator) + public SubmoduleWalk setTree(AbstractTreeIterator iterator) throws CorruptObjectException { walk.addTree(iterator); return this; @@ -578,7 +580,7 @@ public class SubmoduleWalk implements AutoCloseable { * @throws MissingObjectException * if any. */ - public SubmoduleWalk setTree(final AnyObjectId treeId) throws IOException { + public SubmoduleWalk setTree(AnyObjectId treeId) throws IOException { walk.addTree(treeId); return this; } @@ -754,13 +756,11 @@ public class SubmoduleWalk implements AutoCloseable { * @throws java.io.IOException */ public ObjectId getHead() throws IOException { - Repository subRepo = getRepository(); - if (subRepo == null) - return null; - try { + try (Repository subRepo = getRepository()) { + if (subRepo == null) { + return null; + } return subRepo.resolve(Constants.HEAD); - } finally { - subRepo.close(); } } @@ -771,14 +771,12 @@ public class SubmoduleWalk implements AutoCloseable { * @throws java.io.IOException */ public String getHeadRef() throws IOException { - Repository subRepo = getRepository(); - if (subRepo == null) - return null; - try { + try (Repository subRepo = getRepository()) { + if (subRepo == null) { + return null; + } Ref head = subRepo.exactRef(Constants.HEAD); return head != null ? head.getLeaf().getName() : null; - } finally { - subRepo.close(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index d7c5b9d7f9..a0fc57ca1f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.ByteArrayOutputStream; import java.io.File; @@ -128,14 +128,14 @@ public class AmazonS3 { SIGNED_HEADERS.add("date"); //$NON-NLS-1$ } - private static boolean isSignedHeader(final String name) { + private static boolean isSignedHeader(String name) { final String nameLC = StringUtils.toLowerCase(name); return SIGNED_HEADERS.contains(nameLC) || nameLC.startsWith("x-amz-"); //$NON-NLS-1$ } - private static String toCleanString(final List<String> list) { + private static String toCleanString(List<String> list) { final StringBuilder s = new StringBuilder(); - for (final String v : list) { + for (String v : list) { if (s.length() > 0) s.append(','); s.append(v.replaceAll("\n", "").trim()); //$NON-NLS-1$ //$NON-NLS-2$ @@ -143,7 +143,7 @@ public class AmazonS3 { return s.toString(); } - private static String remove(final Map<String, String> m, final String k) { + private static String remove(Map<String, String> m, String k) { final String r = m.remove(k); return r != null ? r : ""; //$NON-NLS-1$ } @@ -283,7 +283,7 @@ public class AmazonS3 { * @throws java.io.IOException * sending the request was not possible. */ - public URLConnection get(final String bucket, final String key) + public URLConnection get(String bucket, String key) throws IOException { for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) { final HttpURLConnection c = open("GET", bucket, key); //$NON-NLS-1$ @@ -312,7 +312,7 @@ public class AmazonS3 { * @throws java.io.IOException * decryption could not be configured. */ - public InputStream decrypt(final URLConnection u) throws IOException { + public InputStream decrypt(URLConnection u) throws IOException { return encryption.decrypt(u.getInputStream()); } @@ -336,7 +336,7 @@ public class AmazonS3 { * sending the request was not possible, or the response XML * document could not be parsed properly. */ - public List<String> list(final String bucket, String prefix) + public List<String> list(String bucket, String prefix) throws IOException { if (prefix.length() > 0 && !prefix.endsWith("/")) //$NON-NLS-1$ prefix += "/"; //$NON-NLS-1$ @@ -359,7 +359,7 @@ public class AmazonS3 { * @throws java.io.IOException * deletion failed due to communications error. */ - public void delete(final String bucket, final String key) + public void delete(String bucket, String key) throws IOException { for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) { final HttpURLConnection c = open("DELETE", bucket, key); //$NON-NLS-1$ @@ -396,7 +396,7 @@ public class AmazonS3 { * @throws java.io.IOException * creation/updating failed due to communications error. */ - public void put(final String bucket, final String key, final byte[] data) + public void put(String bucket, String key, byte[] data) throws IOException { if (encryption != WalkEncryption.NONE) { // We have to copy to produce the cipher text anyway so use @@ -524,12 +524,11 @@ public class AmazonS3 { JGitText.get().amazonS3ActionFailed, action, key, Integer.valueOf(HttpSupport.response(c)), c.getResponseMessage())); - final InputStream errorStream = c.getErrorStream(); - if (errorStream == null) { + if (c.getErrorStream() == null) { return err; } - try { + try (InputStream errorStream = c.getErrorStream()) { final ByteArrayOutputStream b = new ByteArrayOutputStream(); byte[] buf = new byte[2048]; for (;;) { @@ -545,13 +544,11 @@ public class AmazonS3 { if (buf.length > 0) { err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$ } - } finally { - errorStream.close(); } return err; } - IOException maxAttempts(final String action, final String key) { + IOException maxAttempts(String action, String key) { return new IOException(MessageFormat.format( JGitText.get().amazonS3ActionFailedGivingUp, action, key, Integer.valueOf(maxAttempts))); @@ -600,10 +597,10 @@ public class AmazonS3 { return c; } - void authorize(final HttpURLConnection c) throws IOException { + void authorize(HttpURLConnection c) throws IOException { final Map<String, List<String>> reqHdr = c.getRequestProperties(); final SortedMap<String, String> sigHdr = new TreeMap<>(); - for (final Map.Entry<String, List<String>> entry : reqHdr.entrySet()) { + for (Map.Entry<String, List<String>> entry : reqHdr.entrySet()) { final String hdr = entry.getKey(); if (isSignedHeader(hdr)) sigHdr.put(StringUtils.toLowerCase(hdr), toCleanString(entry.getValue())); @@ -622,7 +619,7 @@ public class AmazonS3 { s.append(remove(sigHdr, "date")); //$NON-NLS-1$ s.append('\n'); - for (final Map.Entry<String, String> e : sigHdr.entrySet()) { + for (Map.Entry<String, String> e : sigHdr.entrySet()) { s.append(e.getKey()); s.append(':'); s.append(e.getValue()); @@ -638,7 +635,7 @@ public class AmazonS3 { try { final Mac m = Mac.getInstance(HMAC); m.init(privateKey); - sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8))); + sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(CHARSET))); } catch (NoSuchAlgorithmException e) { throw new IOException(MessageFormat.format(JGitText.get().noHMACsupport, HMAC, e.getMessage())); } catch (InvalidKeyException e) { @@ -647,7 +644,7 @@ public class AmazonS3 { c.setRequestProperty("Authorization", "AWS " + publicKey + ":" + sec); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - static Properties properties(final File authFile) + static Properties properties(File authFile) throws FileNotFoundException, IOException { final Properties p = new Properties(); try (FileInputStream in = new FileInputStream(authFile)) { @@ -667,7 +664,7 @@ public class AmazonS3 { private StringBuilder data; - ListParser(final String bn, final String p) { + ListParser(String bn, String p) { bucket = bn; prefix = p; } @@ -730,7 +727,7 @@ public class AmazonS3 { } @Override - public void characters(final char[] ch, final int s, final int n) + public void characters(char[] ch, int s, int n) throws SAXException { if (data != null) data.append(ch, s, n); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java index c8d1d229b5..f6045f6fe6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseConnection.java @@ -85,7 +85,7 @@ public abstract class BaseConnection implements Connection { /** {@inheritDoc} */ @Override - public final Ref getRef(final String name) { + public final Ref getRef(String name) { return advertisedRefs.get(name); } @@ -132,7 +132,7 @@ public abstract class BaseConnection implements Connection { * will be wrapped in an unmodifiable way to protect it, but it * does not get copied. */ - protected void available(final Map<String, Ref> all) { + protected void available(Map<String, Ref> all) { advertisedRefs = Collections.unmodifiableMap(all); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java index e9227e33a3..38eae1cd48 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackConnection.java @@ -122,7 +122,7 @@ abstract class BasePackConnection extends BaseConnection { /** Extra objects the remote has, but which aren't offered as refs. */ protected final Set<ObjectId> additionalHaves = new HashSet<>(); - BasePackConnection(final PackTransport packTransport) { + BasePackConnection(PackTransport packTransport) { transport = (Transport) packTransport; local = transport.local; uri = transport.uri; @@ -274,7 +274,7 @@ abstract class BasePackConnection extends BaseConnection { * option string * @return whether this option is supported */ - protected boolean isCapableOf(final String option) { + protected boolean isCapableOf(String option) { return remoteCapablities.contains(option); } @@ -287,7 +287,7 @@ abstract class BasePackConnection extends BaseConnection { * option we want * @return {@code true} if the requested option is supported */ - protected boolean wantCapability(final StringBuilder b, final String option) { + protected boolean wantCapability(StringBuilder b, String option) { if (!isCapableOf(option)) return false; b.append(' '); @@ -314,7 +314,7 @@ abstract class BasePackConnection extends BaseConnection { return UserAgent.getAgent(remoteCapablities, super.getPeerUserAgent()); } - private PackProtocolException duplicateAdvertisement(final String name) { + private PackProtocolException duplicateAdvertisement(String name) { return new PackProtocolException(uri, MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, name)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java index 1383045031..0dfcd8716e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java @@ -45,8 +45,6 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.RefDatabase.ALL; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -55,7 +53,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashSet; -import java.util.Map; import java.util.Set; import org.eclipse.jgit.errors.PackProtocolException; @@ -200,6 +197,13 @@ public abstract class BasePackFetchConnection extends BasePackConnection */ public static final String OPTION_ALLOW_REACHABLE_SHA1_IN_WANT = GitProtocolConstants.OPTION_ALLOW_REACHABLE_SHA1_IN_WANT; + /** + * The client specified a filter expression. + * + * @since 5.0 + */ + public static final String OPTION_FILTER = GitProtocolConstants.OPTION_FILTER; + private final RevWalk walk; /** All commits that are immediately reachable by a local ref. */ @@ -242,13 +246,16 @@ public abstract class BasePackFetchConnection extends BasePackConnection private PacketLineOut pckState; + /** If not -1, the maximum blob size to be sent to the server. */ + private final long filterBlobLimit; + /** * Create a new connection to fetch using the native git transport. * * @param packTransport * the transport. */ - public BasePackFetchConnection(final PackTransport packTransport) { + public BasePackFetchConnection(PackTransport packTransport) { super(packTransport); if (local != null) { @@ -262,6 +269,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection } includeTags = transport.getTagOpt() != TagOpt.NO_TAGS; thinPack = transport.isFetchThin(); + filterBlobLimit = transport.getFilterBlobLimit(); if (local != null) { walk = new RevWalk(local); @@ -288,7 +296,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection final boolean minimalNegotiation; - FetchConfig(final Config c) { + FetchConfig(Config c) { allowOfsDelta = c.getBoolean("repack", "usedeltabaseoffset", true); //$NON-NLS-1$ //$NON-NLS-2$ minimalNegotiation = c.getBoolean("fetch", "useminimalnegotiation", //$NON-NLS-1$ //$NON-NLS-2$ false); @@ -331,7 +339,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection /** {@inheritDoc} */ @Override - public void setPackLockMessage(final String message) { + public void setPackLockMessage(String message) { lockMessage = message; } @@ -410,9 +418,9 @@ public abstract class BasePackFetchConnection extends BasePackConnection return local.getConfig().get(FetchConfig::new); } - private int maxTimeWanted(final Collection<Ref> wants) { + private int maxTimeWanted(Collection<Ref> wants) { int maxTime = 0; - for (final Ref r : wants) { + for (Ref r : wants) { try { final RevObject obj = walk.parseAny(r.getObjectId()); if (obj instanceof RevCommit) { @@ -427,10 +435,9 @@ public abstract class BasePackFetchConnection extends BasePackConnection return maxTime; } - private void markReachable(final Set<ObjectId> have, final int maxTime) + private void markReachable(Set<ObjectId> have, int maxTime) throws IOException { - Map<String, Ref> refs = local.getRefDatabase().getRefs(ALL); - for (final Ref r : refs.values()) { + for (Ref r : local.getRefDatabase().getRefs()) { ObjectId id = r.getPeeledObjectId(); if (id == null) id = r.getObjectId(); @@ -482,10 +489,10 @@ public abstract class BasePackFetchConnection extends BasePackConnection } } - private boolean sendWants(final Collection<Ref> want) throws IOException { + private boolean sendWants(Collection<Ref> want) throws IOException { final PacketLineOut p = statelessRPC ? pckState : pckOut; boolean first = true; - for (final Ref r : want) { + for (Ref r : want) { ObjectId objectId = r.getObjectId(); if (objectId == null) { continue; @@ -524,6 +531,11 @@ public abstract class BasePackFetchConnection extends BasePackConnection if (first) { return false; } + if (filterBlobLimit == 0) { + p.writeString(OPTION_FILTER + " blob:none"); //$NON-NLS-1$ + } else if (filterBlobLimit > 0) { + p.writeString(OPTION_FILTER + " blob:limit=" + filterBlobLimit); //$NON-NLS-1$ + } p.end(); outNeedsEnd = false; return true; @@ -564,11 +576,16 @@ public abstract class BasePackFetchConnection extends BasePackConnection OPTION_MULTI_ACK_DETAILED)); } + if (filterBlobLimit >= 0 && !wantCapability(line, OPTION_FILTER)) { + throw new PackProtocolException(uri, + JGitText.get().filterRequiresCapability); + } + addUserAgentCapability(line); return line.toString(); } - private void negotiate(final ProgressMonitor monitor) throws IOException, + private void negotiate(ProgressMonitor monitor) throws IOException, CancelledException { final MutableObjectId ackId = new MutableObjectId(); int resultsPending = 0; @@ -768,7 +785,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection } @Override - public boolean include(final RevWalk walker, final RevCommit c) { + public boolean include(RevWalk walker, RevCommit c) { final boolean remoteKnowsIsCommon = c.has(COMMON); if (c.has(ADVERTISED)) { // Remote advertised this, and we have it, hence common. @@ -789,14 +806,14 @@ public abstract class BasePackFetchConnection extends BasePackConnection } private void markRefsAdvertised() { - for (final Ref r : getRefs()) { + for (Ref r : getRefs()) { markAdvertised(r.getObjectId()); if (r.getPeeledObjectId() != null) markAdvertised(r.getPeeledObjectId()); } } - private void markAdvertised(final AnyObjectId id) { + private void markAdvertised(AnyObjectId id) { try { walk.parseAny(id).add(ADVERTISED); } catch (IOException readError) { @@ -804,7 +821,7 @@ public abstract class BasePackFetchConnection extends BasePackConnection } } - private void markCommon(final RevObject obj, final AckNackResult anr) + private void markCommon(RevObject obj, AckNackResult anr) throws IOException { if (statelessRPC && anr == AckNackResult.ACK_COMMON && !obj.has(STATE)) { StringBuilder s; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java index ee6f29ed0a..69624ff7a3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java @@ -146,7 +146,7 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen * @param packTransport * the transport. */ - public BasePackPushConnection(final PackTransport packTransport) { + public BasePackPushConnection(PackTransport packTransport) { super(packTransport); thinPack = transport.isPushThin(); atomic = transport.isPushAtomic(); @@ -256,7 +256,7 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen pushOptions.toString())); } - for (final RemoteRefUpdate rru : refUpdates) { + for (RemoteRefUpdate rru : refUpdates) { if (!capableDeleteRefs && rru.isDelete()) { rru.setStatus(Status.REJECTED_NODELETE); continue; @@ -294,7 +294,7 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen } private void transmitOptions() throws IOException { - for (final String pushOption : pushOptions) { + for (String pushOption : pushOptions) { pckOut.writeString(pushOption); } @@ -332,17 +332,17 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen Set<ObjectId> remoteObjects = new HashSet<>(); Set<ObjectId> newObjects = new HashSet<>(); - try (final PackWriter writer = new PackWriter(transport.getPackConfig(), + try (PackWriter writer = new PackWriter(transport.getPackConfig(), local.newObjectReader())) { - for (final Ref r : getRefs()) { + for (Ref r : getRefs()) { // only add objects that we actually have ObjectId oid = r.getObjectId(); if (local.hasObject(oid)) remoteObjects.add(oid); } remoteObjects.addAll(additionalHaves); - for (final RemoteRefUpdate r : refUpdates.values()) { + for (RemoteRefUpdate r : refUpdates.values()) { if (!ObjectId.zeroId().equals(r.getNewObjectId())) newObjects.add(r.getNewObjectId()); } @@ -365,7 +365,7 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen } } - private void readStatusReport(final Map<String, RemoteRefUpdate> refUpdates) + private void readStatusReport(Map<String, RemoteRefUpdate> refUpdates) throws IOException { final String unpackLine = readStringLongTimeout(); if (!unpackLine.startsWith("unpack ")) //$NON-NLS-1$ @@ -411,7 +411,7 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen rru.setMessage(message); } } - for (final RemoteRefUpdate rru : refUpdates.values()) { + for (RemoteRefUpdate rru : refUpdates.values()) { if (rru.getStatus() == Status.AWAITING_REPORT) throw new PackProtocolException(MessageFormat.format( JGitText.get().expectedReportForRefNotReceived , uri, rru.getRemoteName())); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java index e97f71a488..c426e3c05d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java @@ -306,7 +306,7 @@ public abstract class BaseReceivePack { * @param into * the destination repository. */ - protected BaseReceivePack(final Repository into) { + protected BaseReceivePack(Repository into) { db = into; walk = new RevWalk(db); @@ -340,7 +340,7 @@ public abstract class BaseReceivePack { final long maxDiscardBytes; final SignedPushConfig signedPush; - ReceiveConfig(final Config config) { + ReceiveConfig(Config config) { allowCreates = true; allowDeletes = !config.getBoolean("receive", "denydeletes", false); //$NON-NLS-1$ //$NON-NLS-2$ allowNonFastForwards = !config.getBoolean("receive", //$NON-NLS-1$ @@ -548,7 +548,7 @@ public abstract class BaseReceivePack { * commands before writing output and does not perform the * initial advertising. */ - public void setBiDirectionalPipe(final boolean twoWay) { + public void setBiDirectionalPipe(boolean twoWay) { biDirectionalPipe = twoWay; } @@ -592,7 +592,7 @@ public abstract class BaseReceivePack { * assume all received objects are valid. * @see #setObjectChecker(ObjectChecker) */ - public void setCheckReceivedObjects(final boolean check) { + public void setCheckReceivedObjects(boolean check) { if (check && objectChecker == null) setObjectChecker(new ObjectChecker()); else if (!check && objectChecker != null) @@ -626,7 +626,7 @@ public abstract class BaseReceivePack { * @param canCreate * {@code true} to permit create ref commands to be processed. */ - public void setAllowCreates(final boolean canCreate) { + public void setAllowCreates(boolean canCreate) { allowCreates = canCreate; } @@ -645,7 +645,7 @@ public abstract class BaseReceivePack { * @param canDelete * {@code true} to permit delete ref commands to be processed. */ - public void setAllowDeletes(final boolean canDelete) { + public void setAllowDeletes(boolean canDelete) { allowAnyDeletes = canDelete; } @@ -691,7 +691,7 @@ public abstract class BaseReceivePack { * {@code true} to permit the client to ask for non-fast-forward * updates of an existing ref. */ - public void setAllowNonFastForwards(final boolean canRewind) { + public void setAllowNonFastForwards(boolean canRewind) { allowNonFastForwards = canRewind; } @@ -741,7 +741,7 @@ public abstract class BaseReceivePack { * automatically determined based on the repository * configuration. */ - public void setRefLogIdent(final PersonIdent pi) { + public void setRefLogIdent(PersonIdent pi) { refLogIdent = pi; } @@ -778,7 +778,7 @@ public abstract class BaseReceivePack { * @param advertiseRefsHook * the hook; may be null to show all refs. */ - public void setAdvertiseRefsHook(final AdvertiseRefsHook advertiseRefsHook) { + public void setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook) { if (advertiseRefsHook != null) this.advertiseRefsHook = advertiseRefsHook; else @@ -795,7 +795,7 @@ public abstract class BaseReceivePack { * @param refFilter * the filter; may be null to show all refs. */ - public void setRefFilter(final RefFilter refFilter) { + public void setRefFilter(RefFilter refFilter) { this.refFilter = refFilter != null ? refFilter : RefFilter.DEFAULT; } @@ -816,7 +816,7 @@ public abstract class BaseReceivePack { * before aborting an IO read or write operation with the * connected client. */ - public void setTimeout(final int seconds) { + public void setTimeout(int seconds) { timeout = seconds; } @@ -861,7 +861,7 @@ public abstract class BaseReceivePack { * @param limit * the Git object size limit. If zero then there is not limit. */ - public void setMaxObjectSizeLimit(final long limit) { + public void setMaxObjectSizeLimit(long limit) { maxObjectSizeLimit = limit; } @@ -874,7 +874,7 @@ public abstract class BaseReceivePack { * the pack size limit, in bytes * @since 3.3 */ - public void setMaxPackSizeLimit(final long limit) { + public void setMaxPackSizeLimit(long limit) { if (limit < 0) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().receivePackInvalidLimit, Long.valueOf(limit))); @@ -1031,7 +1031,7 @@ public abstract class BaseReceivePack { * string describing the problem identified by the hook. The * string must not end with an LF, and must not contain an LF. */ - public void sendError(final String what) { + public void sendError(String what) { if (refs == null) { if (advertiseError == null) advertiseError = new StringBuilder(); @@ -1064,7 +1064,7 @@ public abstract class BaseReceivePack { * string describing the problem identified by the hook. The * string must not end with an LF, and must not contain an LF. */ - public void sendMessage(final String what) { + public void sendMessage(String what) { msgOutWrapper.write(Constants.encode(what + "\n")); //$NON-NLS-1$ } @@ -1213,7 +1213,7 @@ public abstract class BaseReceivePack { * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException * the hook denied advertisement. */ - public void sendAdvertisedRefs(final RefAdvertiser adv) + public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException { if (advertiseError != null) { adv.writeOne("ERR " + advertiseError); //$NON-NLS-1$ @@ -1440,7 +1440,7 @@ public abstract class BaseReceivePack { * @return {@code true} if a pack is expected based on the list of commands. */ protected boolean needPack() { - for (final ReceiveCommand cmd : commands) { + for (ReceiveCommand cmd : commands) { if (cmd.getType() != ReceiveCommand.Type.DELETE) return true; } @@ -1526,21 +1526,21 @@ public abstract class BaseReceivePack { } parser = null; - try (final ObjectWalk ow = new ObjectWalk(db)) { + try (ObjectWalk ow = new ObjectWalk(db)) { if (baseObjects != null) { ow.sort(RevSort.TOPO); if (!baseObjects.isEmpty()) ow.sort(RevSort.BOUNDARY, true); } - for (final ReceiveCommand cmd : commands) { + for (ReceiveCommand cmd : commands) { if (cmd.getResult() != Result.NOT_ATTEMPTED) continue; if (cmd.getType() == ReceiveCommand.Type.DELETE) continue; ow.markStart(ow.parseAny(cmd.getNewId())); } - for (final ObjectId have : advertisedHaves) { + for (ObjectId have : advertisedHaves) { RevObject o = ow.parseAny(have); ow.markUninteresting(o); @@ -1596,7 +1596,7 @@ public abstract class BaseReceivePack { * Validate the command list. */ protected void validateCommands() { - for (final ReceiveCommand cmd : commands) { + for (ReceiveCommand cmd : commands) { final Ref ref = cmd.getRef(); if (cmd.getResult() != Result.NOT_ATTEMPTED) continue; @@ -1761,7 +1761,7 @@ public abstract class BaseReceivePack { * @return a copy of the command list containing only those commands with the * desired status. */ - protected List<ReceiveCommand> filterCommands(final Result want) { + protected List<ReceiveCommand> filterCommands(Result want) { return ReceiveCommand.filter(commands, want); } @@ -1815,7 +1815,7 @@ public abstract class BaseReceivePack { if (unpackError != null) { out.sendString("unpack error " + unpackError.getMessage()); //$NON-NLS-1$ if (forClient) { - for (final ReceiveCommand cmd : commands) { + for (ReceiveCommand cmd : commands) { out.sendString("ng " + cmd.getRefName() //$NON-NLS-1$ + " n/a (unpacker error)"); //$NON-NLS-1$ } @@ -1825,7 +1825,7 @@ public abstract class BaseReceivePack { if (forClient) out.sendString("unpack ok"); //$NON-NLS-1$ - for (final ReceiveCommand cmd : commands) { + for (ReceiveCommand cmd : commands) { if (cmd.getResult() == Result.OK) { if (forClient) out.sendString("ok " + cmd.getRefName()); //$NON-NLS-1$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java index 39efabf5d8..449f529447 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java @@ -47,8 +47,6 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.RefDatabase.ALL; - import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; @@ -98,7 +96,7 @@ class BundleFetchConnection extends BaseFetchConnection { private PackLock packLock; - BundleFetchConnection(Transport transportBundle, final InputStream src) throws TransportException { + BundleFetchConnection(Transport transportBundle, InputStream src) throws TransportException { transport = transportBundle; bin = new BufferedInputStream(src); try { @@ -155,12 +153,12 @@ class BundleFetchConnection extends BaseFetchConnection { available(avail); } - private PackProtocolException duplicateAdvertisement(final String name) { + private PackProtocolException duplicateAdvertisement(String name) { return new PackProtocolException(transport.uri, MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, name)); } - private String readLine(final byte[] hdrbuf) throws IOException { + private String readLine(byte[] hdrbuf) throws IOException { StringBuilder line = new StringBuilder(); boolean done = false; while (!done) { @@ -212,7 +210,7 @@ class BundleFetchConnection extends BaseFetchConnection { /** {@inheritDoc} */ @Override - public void setPackLockMessage(final String message) { + public void setPackLockMessage(String message) { lockMessage = message; } @@ -228,13 +226,13 @@ class BundleFetchConnection extends BaseFetchConnection { if (prereqs.isEmpty()) return; - try (final RevWalk rw = new RevWalk(transport.local)) { + try (RevWalk rw = new RevWalk(transport.local)) { final RevFlag PREREQ = rw.newFlag("PREREQ"); //$NON-NLS-1$ final RevFlag SEEN = rw.newFlag("SEEN"); //$NON-NLS-1$ final Map<ObjectId, String> missing = new HashMap<>(); final List<RevObject> commits = new ArrayList<>(); - for (final Map.Entry<ObjectId, String> e : prereqs.entrySet()) { + for (Map.Entry<ObjectId, String> e : prereqs.entrySet()) { ObjectId p = e.getKey(); try { final RevCommit c = rw.parseCommit(p); @@ -254,13 +252,13 @@ class BundleFetchConnection extends BaseFetchConnection { throw new MissingBundlePrerequisiteException(transport.uri, missing); - Map<String, Ref> localRefs; + List<Ref> localRefs; try { - localRefs = transport.local.getRefDatabase().getRefs(ALL); + localRefs = transport.local.getRefDatabase().getRefs(); } catch (IOException e) { throw new TransportException(transport.uri, e.getMessage(), e); } - for (final Ref r : localRefs.values()) { + for (Ref r : localRefs) { try { rw.markStart(rw.parseCommit(r.getObjectId())); } catch (IOException readError) { @@ -284,7 +282,7 @@ class BundleFetchConnection extends BaseFetchConnection { } if (remaining > 0) { - for (final RevObject o : commits) { + for (RevObject o : commits) { if (!o.has(SEEN)) missing.put(o, prereqs.get(o)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java index 35ac7792e6..f2a261bbe6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java @@ -151,7 +151,7 @@ public class BundleWriter { * @param id * object to pack. Multiple refs may point to the same object. */ - public void include(final String name, final AnyObjectId id) { + public void include(String name, AnyObjectId id) { boolean validRefName = Repository.isValidRefName(name) || Constants.HEAD.equals(name); if (!validRefName) throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidRefName, name)); @@ -169,7 +169,7 @@ public class BundleWriter { * @param r * the ref to include. */ - public void include(final Ref r) { + public void include(Ref r) { include(r.getName(), r.getObjectId()); if (r.getPeeledObjectId() != null) @@ -192,7 +192,7 @@ public class BundleWriter { * parsed and not disposed in order to maximize the amount of * debugging information available in the bundle stream. */ - public void assume(final RevCommit c) { + public void assume(RevCommit c) { if (c != null) assume.add(c); } @@ -221,7 +221,7 @@ public class BundleWriter { final HashSet<ObjectId> inc = new HashSet<>(); final HashSet<ObjectId> exc = new HashSet<>(); inc.addAll(include.values()); - for (final RevCommit r : assume) + for (RevCommit r : assume) exc.add(r.getId()); packWriter.setIndexDisabled(true); packWriter.setDeltaBaseAsOffset(true); @@ -236,7 +236,7 @@ public class BundleWriter { w.write('\n'); final char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH]; - for (final RevCommit a : assume) { + for (RevCommit a : assume) { w.write('-'); a.copyTo(tmp, w); if (a.getRawBuffer() != null) { @@ -245,7 +245,7 @@ public class BundleWriter { } w.write('\n'); } - for (final Map.Entry<String, ObjectId> e : include.entrySet()) { + for (Map.Entry<String, ObjectId> e : include.entrySet()) { e.getValue().copyTo(tmp, w); w.write(' '); w.write(e.getKey()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Connection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Connection.java index bcc5110e73..d4c514e636 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Connection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Connection.java @@ -95,7 +95,7 @@ public interface Connection extends AutoCloseable { * name of the ref to obtain. * @return the requested ref; null if the remote did not advertise this ref. */ - public Ref getRef(final String name); + public Ref getRef(String name); /** * {@inheritDoc} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java index 2fc5eb2b51..7289ce7b6c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Daemon.java @@ -53,7 +53,9 @@ import java.net.Socket; import java.net.SocketAddress; import java.net.SocketException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.Collection; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.PersonIdent; @@ -107,7 +109,7 @@ public class Daemon { * port will be chosen on all network interfaces. */ @SuppressWarnings("unchecked") - public Daemon(final InetSocketAddress addr) { + public Daemon(InetSocketAddress addr) { myAddress = addr; processors = new ThreadGroup("Git-Daemon"); //$NON-NLS-1$ @@ -153,12 +155,17 @@ public class Daemon { @Override protected void execute(final DaemonClient dc, - final Repository db) throws IOException, + final Repository db, + @Nullable Collection<String> extraParameters) + throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { UploadPack up = uploadPackFactory.create(dc, db); InputStream in = dc.getInputStream(); OutputStream out = dc.getOutputStream(); + if (extraParameters != null) { + up.setExtraParameters(extraParameters); + } up.upload(in, out, null); } }, new DaemonService("receive-pack", "receivepack") { //$NON-NLS-1$ //$NON-NLS-2$ @@ -168,7 +175,9 @@ public class Daemon { @Override protected void execute(final DaemonClient dc, - final Repository db) throws IOException, + final Repository db, + @Nullable Collection<String> extraParameters) + throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { ReceivePack rp = receivePackFactory.create(dc, db); @@ -200,7 +209,7 @@ public class Daemon { public synchronized DaemonService getService(String name) { if (!name.startsWith("git-")) //$NON-NLS-1$ name = "git-" + name; //$NON-NLS-1$ - for (final DaemonService s : services) { + for (DaemonService s : services) { if (s.getCommandName().equals(name)) return s; } @@ -224,7 +233,7 @@ public class Daemon { * before aborting an IO read or write operation with the * connected client. */ - public void setTimeout(final int seconds) { + public void setTimeout(int seconds) { timeout = seconds; } @@ -411,7 +420,7 @@ public class Daemon { } } - void startClient(final Socket s) { + void startClient(Socket s) { final DaemonClient dc = new DaemonClient(this); final SocketAddress peer = s.getRemoteSocketAddress(); @@ -445,8 +454,8 @@ public class Daemon { }.start(); } - synchronized DaemonService matchService(final String cmd) { - for (final DaemonService d : services) { + synchronized DaemonService matchService(String cmd) { + for (DaemonService d : services) { if (d.handles(cmd)) return d; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java index a9731ac3a4..51c4918f56 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonClient.java @@ -50,6 +50,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.InetAddress; import java.net.Socket; +import java.util.Arrays; +import java.util.Collection; import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; @@ -66,11 +68,11 @@ public class DaemonClient { private OutputStream rawOut; - DaemonClient(final Daemon d) { + DaemonClient(Daemon d) { daemon = d; } - void setRemoteAddress(final InetAddress ia) { + void setRemoteAddress(InetAddress ia) { peer = ia; } @@ -110,7 +112,7 @@ public class DaemonClient { return rawOut; } - void execute(final Socket sock) throws IOException, + void execute(Socket sock) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { rawIn = new BufferedInputStream(sock.getInputStream()); rawOut = new BufferedOutputStream(sock.getOutputStream()); @@ -118,6 +120,14 @@ public class DaemonClient { if (0 < daemon.getTimeout()) sock.setSoTimeout(daemon.getTimeout() * 1000); String cmd = new PacketLineIn(rawIn).readStringRaw(); + + Collection<String> extraParameters = null; + + int nulnul = cmd.indexOf("\0\0"); //$NON-NLS-1$ + if (nulnul != -1) { + extraParameters = Arrays.asList(cmd.substring(nulnul + 2).split("\0")); //$NON-NLS-1$ + } + final int nul = cmd.indexOf('\0'); if (nul >= 0) { // Newer clients hide a "host" header behind this byte. @@ -131,6 +141,6 @@ public class DaemonClient { if (srv == null) return; sock.setSoTimeout(0); - srv.execute(this, cmd); + srv.execute(this, cmd, extraParameters); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java index 712eb22152..6d2bee8dc3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DaemonService.java @@ -45,7 +45,9 @@ package org.eclipse.jgit.transport; import java.io.IOException; +import java.util.Collection; +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config.SectionParser; import org.eclipse.jgit.lib.Repository; @@ -65,7 +67,7 @@ public abstract class DaemonService { private boolean overridable; - DaemonService(final String cmdName, final String cfgName) { + DaemonService(String cmdName, String cfgName) { command = cmdName.startsWith("git-") ? cmdName : "git-" + cmdName; //$NON-NLS-1$ //$NON-NLS-2$ configKey = cfg -> new ServiceConfig(DaemonService.this, cfg, cfgName); overridable = true; @@ -96,7 +98,7 @@ public abstract class DaemonService { * {@code true} to allow this service to be used; {@code false} * to deny it. */ - public void setEnabled(final boolean on) { + public void setEnabled(boolean on) { enabled = on; } @@ -120,7 +122,7 @@ public abstract class DaemonService { * enabled state with the <code>daemon.servicename</code> config * setting. */ - public void setOverridable(final boolean on) { + public void setOverridable(boolean on) { overridable = on; } @@ -140,19 +142,20 @@ public abstract class DaemonService { * input line from the client. * @return true if this command can accept the given command line. */ - public boolean handles(final String commandLine) { + public boolean handles(String commandLine) { return command.length() + 1 < commandLine.length() && commandLine.charAt(command.length()) == ' ' && commandLine.startsWith(command); } - void execute(final DaemonClient client, final String commandLine) + void execute(DaemonClient client, String commandLine, + @Nullable Collection<String> extraParameters) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException { final String name = commandLine.substring(command.length() + 1); try (Repository db = client.getDaemon().openRepository(client, name)) { if (isEnabledFor(db)) { - execute(client, db); + execute(client, db, extraParameters); } } catch (ServiceMayNotContinueException e) { // An error when opening the repo means the client is expecting a ref @@ -162,13 +165,14 @@ public abstract class DaemonService { } } - private boolean isEnabledFor(final Repository db) { + private boolean isEnabledFor(Repository db) { if (isOverridable()) return db.getConfig().get(configKey).enabled; return isEnabled(); } - abstract void execute(DaemonClient client, Repository db) + abstract void execute(DaemonClient client, Repository db, + @Nullable Collection<String> extraParameters) throws IOException, ServiceNotEnabledException, ServiceNotAuthorizedException; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java index a749fbcaf0..5f74e72eaf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/DefaultSshSessionFactory.java @@ -61,7 +61,7 @@ import com.jcraft.jsch.Session; class DefaultSshSessionFactory extends JschConfigSessionFactory { /** {@inheritDoc} */ @Override - protected void configure(final OpenSshConfig.Host hc, final Session session) { + protected void configure(OpenSshConfig.Host hc, Session session) { // No additional configuration required. } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchHeadRecord.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchHeadRecord.java index 421ef21073..34ab361c74 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchHeadRecord.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchHeadRecord.java @@ -63,7 +63,7 @@ class FetchHeadRecord { URIish sourceURI; - void write(final Writer pw) throws IOException { + void write(Writer pw) throws IOException { final String type; final String name; if (sourceName.startsWith(R_HEADS)) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index fdb5adf94e..ff183c8974 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -106,12 +106,12 @@ class FetchProcess { private Map<String, Ref> localRefs; - FetchProcess(final Transport t, final Collection<RefSpec> f) { + FetchProcess(Transport t, Collection<RefSpec> f) { transport = t; toFetch = f; } - void execute(final ProgressMonitor monitor, final FetchResult result) + void execute(ProgressMonitor monitor, FetchResult result) throws NotSupportedException, TransportException { askFor.clear(); localUpdates.clear(); @@ -123,7 +123,7 @@ class FetchProcess { executeImp(monitor, result); } finally { try { - for (final PackLock lock : packLocks) + for (PackLock lock : packLocks) lock.unlock(); } catch (IOException e) { throw new TransportException(e.getMessage(), e); @@ -139,7 +139,7 @@ class FetchProcess { result.setAdvertisedRefs(transport.getURI(), conn.getRefsMap()); result.peerUserAgent = conn.getPeerUserAgent(); final Set<Ref> matched = new HashSet<>(); - for (final RefSpec spec : toFetch) { + for (RefSpec spec : toFetch) { if (spec.getSource() == null) throw new TransportException(MessageFormat.format( JGitText.get().sourceRefNotSpecifiedForRefspec, spec)); @@ -176,7 +176,7 @@ class FetchProcess { // have.addAll(askFor.keySet()); askFor.clear(); - for (final Ref r : additionalTags) { + for (Ref r : additionalTags) { ObjectId id = r.getPeeledObjectId(); if (id == null) id = r.getObjectId(); @@ -198,7 +198,7 @@ class FetchProcess { .newBatchUpdate() .setAllowNonFastForwards(true) .setRefLogMessage("fetch", true); //$NON-NLS-1$ - try (final RevWalk walk = new RevWalk(transport.local)) { + try (RevWalk walk = new RevWalk(transport.local)) { if (monitor instanceof BatchingProgressMonitor) { ((BatchingProgressMonitor) monitor).setDelayStart( 250, TimeUnit.MILLISECONDS); @@ -239,7 +239,7 @@ class FetchProcess { } } - private void fetchObjects(final ProgressMonitor monitor) + private void fetchObjects(ProgressMonitor monitor) throws TransportException { try { conn.setPackLockMessage("jgit fetch " + transport.uri); //$NON-NLS-1$ @@ -253,7 +253,7 @@ class FetchProcess { JGitText.get().peerDidNotSupplyACompleteObjectGraph); } - private void closeConnection(final FetchResult result) { + private void closeConnection(FetchResult result) { if (conn != null) { conn.close(); result.addMessages(conn.getMessages()); @@ -277,12 +277,12 @@ class FetchProcess { // new connection has offered to us. // final HashMap<ObjectId, Ref> avail = new HashMap<>(); - for (final Ref r : conn.getRefs()) + for (Ref r : conn.getRefs()) avail.put(r.getObjectId(), r); final Collection<Ref> wants = new ArrayList<>(askFor.values()); askFor.clear(); - for (final Ref want : wants) { + for (Ref want : wants) { final Ref newRef = avail.get(want.getObjectId()); if (newRef != null) { askFor.put(newRef.getObjectId(), newRef); @@ -293,7 +293,7 @@ class FetchProcess { } } - private void removeTrackingRefUpdate(final ObjectId want) { + private void removeTrackingRefUpdate(ObjectId want) { final Iterator<TrackingRefUpdate> i = localUpdates.iterator(); while (i.hasNext()) { final TrackingRefUpdate u = i.next(); @@ -302,7 +302,7 @@ class FetchProcess { } } - private void removeFetchHeadRecord(final ObjectId want) { + private void removeFetchHeadRecord(ObjectId want) { final Iterator<FetchHeadRecord> i = fetchHeadUpdates.iterator(); while (i.hasNext()) { final FetchHeadRecord fh = i.next(); @@ -311,7 +311,7 @@ class FetchProcess { } } - private void updateFETCH_HEAD(final FetchResult result) throws IOException { + private void updateFETCH_HEAD(FetchResult result) throws IOException { File meta = transport.local.getDirectory(); if (meta == null) return; @@ -320,7 +320,7 @@ class FetchProcess { if (lock.lock()) { try (Writer w = new OutputStreamWriter( lock.getOutputStream())) { - for (final FetchHeadRecord h : fetchHeadUpdates) { + for (FetchHeadRecord h : fetchHeadUpdates) { h.write(w); result.add(h); } @@ -334,10 +334,10 @@ class FetchProcess { private boolean askForIsComplete() throws TransportException { try { - try (final ObjectWalk ow = new ObjectWalk(transport.local)) { - for (final ObjectId want : askFor.keySet()) + try (ObjectWalk ow = new ObjectWalk(transport.local)) { + for (ObjectId want : askFor.keySet()) ow.markStart(ow.parseAny(want)); - for (final Ref ref : localRefs().values()) + for (Ref ref : localRefs().values()) ow.markUninteresting(ow.parseAny(ref.getObjectId())); ow.checkConnectivity(); } @@ -349,15 +349,15 @@ class FetchProcess { } } - private void expandWildcard(final RefSpec spec, final Set<Ref> matched) + private void expandWildcard(RefSpec spec, Set<Ref> matched) throws TransportException { - for (final Ref src : conn.getRefs()) { + for (Ref src : conn.getRefs()) { if (spec.matchSource(src) && matched.add(src)) want(src, spec.expandFromSource(src)); } } - private void expandSingle(final RefSpec spec, final Set<Ref> matched) + private void expandSingle(RefSpec spec, Set<Ref> matched) throws TransportException { String want = spec.getSource(); if (ObjectId.isId(want)) { @@ -377,7 +377,7 @@ class FetchProcess { private Collection<Ref> expandAutoFollowTags() throws TransportException { final Collection<Ref> additionalTags = new ArrayList<>(); final Map<String, Ref> haveRefs = localRefs(); - for (final Ref r : conn.getRefs()) { + for (Ref r : conn.getRefs()) { if (!isTag(r)) continue; @@ -401,7 +401,7 @@ class FetchProcess { private void expandFetchTags() throws TransportException { final Map<String, Ref> haveRefs = localRefs(); - for (final Ref r : conn.getRefs()) { + for (Ref r : conn.getRefs()) { if (!isTag(r)) { continue; } @@ -416,12 +416,12 @@ class FetchProcess { } } - private void wantTag(final Ref r) throws TransportException { + private void wantTag(Ref r) throws TransportException { want(r, new RefSpec().setSource(r.getName()) .setDestination(r.getName()).setForceUpdate(true)); } - private void want(final Ref src, final RefSpec spec) + private void want(Ref src, RefSpec spec) throws TransportException { final ObjectId newId = src.getObjectId(); if (newId == null) { @@ -479,9 +479,12 @@ class FetchProcess { private void deleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch) throws IOException { - for (final Ref ref : localRefs().values()) { + for (Ref ref : localRefs().values()) { + if (ref.isSymbolic()) { + continue; + } final String refname = ref.getName(); - for (final RefSpec spec : toFetch) { + for (RefSpec spec : toFetch) { if (spec.matchDestination(refname)) { final RefSpec s = spec.expandFromDestination(refname); if (result.getAdvertisedRef(s.getSource()) == null) { @@ -506,11 +509,11 @@ class FetchProcess { batch.addCommand(update.asReceiveCommand()); } - private static boolean isTag(final Ref r) { + private static boolean isTag(Ref r) { return isTag(r.getName()); } - private static boolean isTag(final String name) { + private static boolean isTag(String name) { return name.startsWith(Constants.R_TAGS); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchResult.java index 2667ec37ca..ad4c5e9354 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchResult.java @@ -68,7 +68,7 @@ public class FetchResult extends OperationResult { submodules = new HashMap<>(); } - void add(final FetchHeadRecord r) { + void add(FetchHeadRecord r) { if (!r.notForMerge) forMerge.add(r); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java index 2031147820..10cd775304 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java @@ -108,6 +108,14 @@ public class GitProtocolConstants { public static final String OPTION_SHALLOW = "shallow"; //$NON-NLS-1$ /** + * The client wants the "deepen" command to be interpreted as relative to + * the client's shallow commits. + * + * @since 5.0 + */ + public static final String OPTION_DEEPEN_RELATIVE = "deepen-relative"; //$NON-NLS-1$ + + /** * The client does not want progress messages and will ignore them. * * @since 3.2 @@ -152,6 +160,13 @@ public class GitProtocolConstants { public static final String OPTION_PUSH_CERT = "push-cert"; //$NON-NLS-1$ /** + * The client specified a filter expression. + * + * @since 5.0 + */ + public static final String OPTION_FILTER = "filter"; //$NON-NLS-1$ + + /** * The client supports atomic pushes. If this option is used, the server * will update all refs within one atomic transaction. * @@ -215,6 +230,20 @@ public class GitProtocolConstants { */ public static final String CAPABILITY_PUSH_OPTIONS = "push-options"; //$NON-NLS-1$ + /** + * The server supports listing refs using protocol v2. + * + * @since 5.0 + */ + public static final String COMMAND_LS_REFS = "ls-refs"; //$NON-NLS-1$ + + /** + * The server supports fetch using protocol v2. + * + * @since 5.0 + */ + public static final String COMMAND_FETCH = "fetch"; //$NON-NLS-1$ + static enum MultiAck { OFF, CONTINUE, DETAILED; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java index 6c26b7026a..1415334c63 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; import static java.nio.charset.StandardCharsets.ISO_8859_1; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.File; import java.security.InvalidKeyException; @@ -102,7 +102,7 @@ public class HMACSHA1NonceGenerator implements NonceGenerator { } String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ - byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8)); + byte[] rawHmac = mac.doFinal(input.getBytes(CHARSET)); return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$ } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java index c40d9635de..fb03190b02 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.util.HttpSupport.HDR_AUTHORIZATION; import static org.eclipse.jgit.util.HttpSupport.HDR_WWW_AUTHENTICATE; @@ -51,6 +51,7 @@ import java.io.IOException; import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -59,7 +60,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Map.Entry; -import java.util.Random; import org.eclipse.jgit.transport.http.HttpConnection; import org.eclipse.jgit.util.Base64; @@ -160,10 +160,10 @@ abstract class HttpAuthMethod { final Map<String, List<String>> headers = conn.getHeaderFields(); HttpAuthMethod authentication = Type.NONE.method(EMPTY_STRING); - for (final Entry<String, List<String>> entry : headers.entrySet()) { + for (Entry<String, List<String>> entry : headers.entrySet()) { if (HDR_WWW_AUTHENTICATE.equalsIgnoreCase(entry.getKey())) { if (entry.getValue() != null) { - for (final String value : entry.getValue()) { + for (String value : entry.getValue()) { if (value != null && value.length() != 0) { final String[] valuePart = value.split( SCHEMA_NAME_SEPARATOR, 2); @@ -307,15 +307,15 @@ abstract class HttpAuthMethod { } @Override - void authorize(final String username, final String password) { + void authorize(String username, String password) { this.user = username; this.pass = password; } @Override - void configureRequest(final HttpConnection conn) throws IOException { + void configureRequest(HttpConnection conn) throws IOException { String ident = user + ":" + pass; //$NON-NLS-1$ - String enc = Base64.encodeBytes(ident.getBytes(UTF_8)); + String enc = Base64.encodeBytes(ident.getBytes(CHARSET)); conn.setRequestProperty(HDR_AUTHORIZATION, type.getSchemeName() + " " + enc); //$NON-NLS-1$ } @@ -323,7 +323,7 @@ abstract class HttpAuthMethod { /** Performs HTTP digest authentication. */ private static class Digest extends HttpAuthMethod { - private static final Random PRNG = new Random(); + private static final SecureRandom PRNG = new SecureRandom(); private final Map<String, String> params; @@ -346,14 +346,14 @@ abstract class HttpAuthMethod { } @Override - void authorize(final String username, final String password) { + void authorize(String username, String password) { this.user = username; this.pass = password; } @SuppressWarnings("boxing") @Override - void configureRequest(final HttpConnection conn) throws IOException { + void configureRequest(HttpConnection conn) throws IOException { final Map<String, String> r = new LinkedHashMap<>(); final String realm = params.get("realm"); //$NON-NLS-1$ @@ -430,15 +430,15 @@ abstract class HttpAuthMethod { private static String H(String data) { MessageDigest md = newMD5(); - md.update(data.getBytes(UTF_8)); + md.update(data.getBytes(CHARSET)); return LHEX(md.digest()); } private static String KD(String secret, String data) { MessageDigest md = newMD5(); - md.update(secret.getBytes(UTF_8)); + md.update(secret.getBytes(CHARSET)); md.update((byte) ':'); - md.update(data.getBytes(UTF_8)); + md.update(data.getBytes(CHARSET)); return LHEX(md.digest()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/InsecureCipherFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/InsecureCipherFactory.java index 73384a1162..d494273f29 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/InsecureCipherFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/InsecureCipherFactory.java @@ -54,7 +54,7 @@ import javax.crypto.NoSuchPaddingException; * This is a hack for {@link WalkEncryption} to create any cipher configured by * the end-user. Using this class allows JGit to violate ErrorProne's security * recommendations (<a - * href="http://errorprone.info/bugpattern/InsecureCryptoUsage" + * href="https://errorprone.info/bugpattern/InsecureCryptoUsage" * >InsecureCryptoUsage</a>), which is not secure. */ class InsecureCipherFactory { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java index 2a222fbc7b..eab3b3c0cc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschConfigSessionFactory.java @@ -70,6 +70,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jcraft.jsch.ConfigRepository; +import com.jcraft.jsch.ConfigRepository.Config; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; @@ -222,10 +223,30 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory { session.setUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider)); } + safeConfig(session, hc.getConfig()); configure(hc, session); return session; } + private void safeConfig(Session session, Config cfg) { + // Ensure that Jsch checks all configured algorithms, not just its + // built-in ones. Otherwise it may propose an algorithm for which it + // doesn't have an implementation, and then run into an NPE if that + // algorithm ends up being chosen. + copyConfigValueToSession(session, cfg, "Ciphers", "CheckCiphers"); //$NON-NLS-1$ //$NON-NLS-2$ + copyConfigValueToSession(session, cfg, "KexAlgorithms", "CheckKexes"); //$NON-NLS-1$ //$NON-NLS-2$ + copyConfigValueToSession(session, cfg, "HostKeyAlgorithms", //$NON-NLS-1$ + "CheckSignatures"); //$NON-NLS-1$ + } + + private void copyConfigValueToSession(Session session, Config cfg, + String from, String to) { + String value = cfg.getValue(from); + if (value != null) { + session.setConfig(to, value); + } + } + private void setUserName(Session session, String userName) { // Jsch 0.1.54 picks up the user name from the ssh config, even if an // explicit user name was given! We must correct that if ~/.ssh/config @@ -309,7 +330,7 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory { * @throws com.jcraft.jsch.JSchException * the user configuration could not be created. */ - protected JSch getJSch(final OpenSshConfig.Host hc, FS fs) throws JSchException { + protected JSch getJSch(OpenSshConfig.Host hc, FS fs) throws JSchException { if (defaultJSch == null) { defaultJSch = createDefaultJSch(fs); if (defaultJSch.getConfigRepository() == null) { @@ -351,13 +372,15 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory { */ protected JSch createDefaultJSch(FS fs) throws JSchException { final JSch jsch = new JSch(); + JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa")); //$NON-NLS-1$ //$NON-NLS-2$ + JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss")); //$NON-NLS-1$ //$NON-NLS-2$ configureJSch(jsch); knownHosts(jsch, fs); identities(jsch, fs); return jsch; } - private static void knownHosts(final JSch sch, FS fs) throws JSchException { + private static void knownHosts(JSch sch, FS fs) throws JSchException { final File home = fs.userHome(); if (home == null) return; @@ -371,7 +394,7 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory { } } - private static void identities(final JSch sch, FS fs) { + private static void identities(JSch sch, FS fs) { final File home = fs.userHome(); if (home == null) return; @@ -383,7 +406,7 @@ public abstract class JschConfigSessionFactory extends SshSessionFactory { } } - private static void loadIdentity(final JSch sch, final File priv) { + private static void loadIdentity(JSch sch, File priv) { if (priv.isFile()) { try { sch.addIdentity(priv.getAbsolutePath()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java index 081d05748c..e3ef832343 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/JschSession.java @@ -82,7 +82,7 @@ public class JschSession implements RemoteSession { * @param uri * the URI information for the remote connection */ - public JschSession(final Session session, URIish uri) { + public JschSession(Session session, URIish uri) { sock = session; this.uri = uri; } @@ -145,7 +145,7 @@ public class JschSession implements RemoteSession { * @throws IOException * on problems opening streams */ - JschProcess(final String commandName, int tms) + JschProcess(String commandName, int tms) throws TransportException, IOException { timeout = tms; try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java index e3f287bef8..e688f6340d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java @@ -211,9 +211,7 @@ public class NetRC { this.hosts.clear(); this.lastModified = this.netrc.lastModified(); - BufferedReader r = null; - try { - r = new BufferedReader(new FileReader(netrc)); + try (BufferedReader r = new BufferedReader(new FileReader(netrc))) { String line = null; NetRCEntry entry = new NetRCEntry(); @@ -315,13 +313,6 @@ public class NetRC { hosts.put(entry.machine, entry); } catch (IOException e) { throw new RuntimeException(e); - } finally { - try { - if (r != null) - r.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java index 4660c40d98..f5ccdc8f13 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OpenSshConfig.java @@ -186,7 +186,7 @@ public class OpenSshConfig implements ConfigRepository { /** State read from the config file, plus {@link Host}s created from it. */ private State state; - OpenSshConfig(final File h, final File cfg) { + OpenSshConfig(File h, File cfg) { home = h; configFile = cfg; state = new State(); @@ -201,7 +201,7 @@ public class OpenSshConfig implements ConfigRepository { * configuration file. * @return r configuration for the requested name. Never null. */ - public Host lookup(final String hostName) { + public Host lookup(String hostName) { final State cache = refresh(); Host h = cache.hosts.get(hostName); if (h != null) { @@ -211,7 +211,7 @@ public class OpenSshConfig implements ConfigRepository { // Initialize with default entries at the top of the file, before the // first Host block. fullConfig.merge(cache.entries.get(HostEntry.DEFAULT_NAME)); - for (final Map.Entry<String, HostEntry> e : cache.entries.entrySet()) { + for (Map.Entry<String, HostEntry> e : cache.entries.entrySet()) { String key = e.getKey(); if (isHostMatch(key, hostName)) { fullConfig.merge(e.getValue()); @@ -238,7 +238,7 @@ public class OpenSshConfig implements ConfigRepository { return state; } - private Map<String, HostEntry> parse(final InputStream in) + private Map<String, HostEntry> parse(InputStream in) throws IOException { final Map<String, HostEntry> m = new LinkedHashMap<>(); final BufferedReader br = new BufferedReader(new InputStreamReader(in)); @@ -332,14 +332,14 @@ public class OpenSshConfig implements ConfigRepository { } } - private static String dequote(final String value) { + private static String dequote(String value) { if (value.startsWith("\"") && value.endsWith("\"") //$NON-NLS-1$ //$NON-NLS-2$ && value.length() > 1) return value.substring(1, value.length() - 1); return value; } - private static String nows(final String value) { + private static String nows(String value) { final StringBuilder b = new StringBuilder(); for (int i = 0; i < value.length(); i++) { if (!Character.isSpaceChar(value.charAt(i))) @@ -348,7 +348,7 @@ public class OpenSshConfig implements ConfigRepository { return b.toString(); } - private static Boolean yesno(final String value) { + private static Boolean yesno(String value) { if (StringUtils.equalsIgnoreCase("yes", value)) //$NON-NLS-1$ return Boolean.TRUE; return Boolean.FALSE; @@ -365,7 +365,7 @@ public class OpenSshConfig implements ConfigRepository { return new File(home, path); } - private static int positive(final String value) { + private static int positive(String value) { if (value != null) { try { return Integer.parseUnsignedInt(value); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OperationResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OperationResult.java index 42317984fe..08f7f0d1af 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/OperationResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/OperationResult.java @@ -107,7 +107,7 @@ public abstract class OperationResult { * name of the ref to obtain. * @return the requested ref; null if the remote did not advertise this ref. */ - public final Ref getAdvertisedRef(final String name) { + public final Ref getAdvertisedRef(String name) { return advertisedRefs.get(name); } @@ -129,16 +129,16 @@ public abstract class OperationResult { * @return status of the local ref; null if this local ref was not touched * during this operation. */ - public TrackingRefUpdate getTrackingRefUpdate(final String localName) { + public TrackingRefUpdate getTrackingRefUpdate(String localName) { return updates.get(localName); } - void setAdvertisedRefs(final URIish u, final Map<String, Ref> ar) { + void setAdvertisedRefs(URIish u, Map<String, Ref> ar) { uri = u; advertisedRefs = ar; } - void add(final TrackingRefUpdate u) { + void add(TrackingRefUpdate u) { updates.put(u.getLocalName(), u); } @@ -158,7 +158,7 @@ public abstract class OperationResult { return messageBuffer != null ? messageBuffer.toString() : ""; //$NON-NLS-1$ } - void addMessages(final String msg) { + void addMessages(String msg) { if (msg != null && msg.length() > 0) { if (messageBuffer == null) messageBuffer = new StringBuilder(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java index af5a0b7c98..49acb4d9d8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java @@ -200,7 +200,7 @@ public abstract class PackParser { * @param src * the stream the parser will read. */ - protected PackParser(final ObjectDatabase odb, final InputStream src) { + protected PackParser(ObjectDatabase odb, InputStream src) { objectDatabase = odb.newCachedDatabase(); in = src; @@ -232,7 +232,7 @@ public abstract class PackParser { * @param allow * true to enable a thin pack. */ - public void setAllowThin(final boolean allow) { + public void setAllowThin(boolean allow) { allowThin = allow; } @@ -379,7 +379,7 @@ public abstract class PackParser { * @param oc * the checker instance; null to disable object checking. */ - public void setObjectChecker(final ObjectChecker oc) { + public void setObjectChecker(ObjectChecker oc) { objCheck = oc; } @@ -399,7 +399,7 @@ public abstract class PackParser { * @param on * true to enable the default checker; false to disable it. */ - public void setObjectChecking(final boolean on) { + public void setObjectChecking(boolean on) { setObjectChecker(on ? new ObjectChecker() : null); } @@ -629,7 +629,7 @@ public abstract class PackParser { resolving.endTask(); } - private void resolveDeltas(final ProgressMonitor progress) + private void resolveDeltas(ProgressMonitor progress) throws IOException { final int last = entryCount; for (int i = 0; i < last; i++) { @@ -819,7 +819,7 @@ public abstract class PackParser { return info; } - private UnresolvedDelta removeBaseById(final AnyObjectId id) { + private UnresolvedDelta removeBaseById(AnyObjectId id) { final DeltaChain d = baseById.get(id); return d != null ? d.remove() : null; } @@ -865,7 +865,7 @@ public abstract class PackParser { return first; } - private void resolveDeltasWithExternalBases(final ProgressMonitor progress) + private void resolveDeltasWithExternalBases(ProgressMonitor progress) throws IOException { growEntries(baseById.size()); @@ -873,7 +873,7 @@ public abstract class PackParser { baseObjectIds = new ObjectIdSubclassMap<>(); final List<DeltaChain> missing = new ArrayList<>(64); - for (final DeltaChain baseId : baseById) { + for (DeltaChain baseId : baseById) { if (baseId.head == null) continue; @@ -905,7 +905,7 @@ public abstract class PackParser { JGitText.get().downloadCancelledDuringIndexing); } - for (final DeltaChain base : missing) { + for (DeltaChain base : missing) { if (base.head != null) throw new MissingObjectException(base, "delta base"); //$NON-NLS-1$ } @@ -1065,7 +1065,7 @@ public abstract class PackParser { } } - private void whole(final long pos, final int type, final long sz) + private void whole(long pos, int type, long sz) throws IOException { SHA1 objectDigest = objectHasher.reset(); objectDigest.update(Constants.encodedTypeString(type)); @@ -1076,7 +1076,6 @@ public abstract class PackParser { final byte[] data; if (type == Constants.OBJ_BLOB) { byte[] readBuffer = buffer(); - InputStream inf = inflate(Source.INPUT, sz); BlobObjectChecker checker = null; if (objCheck != null) { checker = objCheck.newBlobObjectChecker(); @@ -1085,15 +1084,16 @@ public abstract class PackParser { checker = BlobObjectChecker.NULL_CHECKER; } long cnt = 0; - while (cnt < sz) { - int r = inf.read(readBuffer); - if (r <= 0) - break; - objectDigest.update(readBuffer, 0, r); - checker.update(readBuffer, 0, r); - cnt += r; + try (InputStream inf = inflate(Source.INPUT, sz)) { + while (cnt < sz) { + int r = inf.read(readBuffer); + if (r <= 0) + break; + objectDigest.update(readBuffer, 0, r); + checker.update(readBuffer, 0, r); + cnt += r; + } } - inf.close(); objectDigest.digest(tempObjectId); checker.endBlob(tempObjectId); data = null; @@ -1162,33 +1162,29 @@ public abstract class PackParser { final byte[] readBuffer = buffer(); final byte[] curBuffer = new byte[readBuffer.length]; long sz = info.size; - InputStream pck = null; try (ObjectStream cur = readCurs.open(obj, info.type).openStream()) { if (cur.getSize() != sz) { throw new IOException(MessageFormat.format( JGitText.get().collisionOn, obj.name())); } - pck = inflate(Source.DATABASE, sz); - while (0 < sz) { - int n = (int) Math.min(readBuffer.length, sz); - IO.readFully(cur, curBuffer, 0, n); - IO.readFully(pck, readBuffer, 0, n); - for (int i = 0; i < n; i++) { - if (curBuffer[i] != readBuffer[i]) { - throw new IOException(MessageFormat.format(JGitText - .get().collisionOn, obj.name())); + try (InputStream pck = inflate(Source.DATABASE, sz)) { + while (0 < sz) { + int n = (int) Math.min(readBuffer.length, sz); + IO.readFully(cur, curBuffer, 0, n); + IO.readFully(pck, readBuffer, 0, n); + for (int i = 0; i < n; i++) { + if (curBuffer[i] != readBuffer[i]) { + throw new IOException(MessageFormat.format( + JGitText.get().collisionOn, obj.name())); + } } + sz -= n; } - sz -= n; } } catch (MissingObjectException notLocal) { // This is OK, we don't have a copy of the object locally - // but the API throws when we try to read it as usually its + // but the API throws when we try to read it as usually it's // an error to read something that doesn't exist. - } finally { - if (pck != null) { - pck.close(); - } } } @@ -1228,7 +1224,7 @@ public abstract class PackParser { } // Consume exactly one byte from the buffer and return it. - private int readFrom(final Source src) throws IOException { + private int readFrom(Source src) throws IOException { if (bAvail == 0) fill(src, 1); bAvail--; @@ -1236,13 +1232,13 @@ public abstract class PackParser { } // Consume cnt bytes from the buffer. - void use(final int cnt) { + void use(int cnt) { bOffset += cnt; bAvail -= cnt; } // Ensure at least need bytes are available in in {@link #buf}. - int fill(final Source src, final int need) throws IOException { + int fill(Source src, int need) throws IOException { while (bAvail < need) { int next = bOffset + bAvail; int free = buf.length - next; @@ -1640,23 +1636,23 @@ public abstract class PackParser { public long size; } - private void inflateAndSkip(final Source src, final long inflatedSize) + private void inflateAndSkip(Source src, long inflatedSize) throws IOException { - final InputStream inf = inflate(src, inflatedSize); - IO.skipFully(inf, inflatedSize); - inf.close(); + try (InputStream inf = inflate(src, inflatedSize)) { + IO.skipFully(inf, inflatedSize); + } } - private byte[] inflateAndReturn(final Source src, final long inflatedSize) + private byte[] inflateAndReturn(Source src, long inflatedSize) throws IOException { final byte[] dst = new byte[(int) inflatedSize]; - final InputStream inf = inflate(src, inflatedSize); - IO.readFully(inf, dst, 0, dst.length); - inf.close(); + try (InputStream inf = inflate(src, inflatedSize)) { + IO.readFully(inf, dst, 0, dst.length); + } return dst; } - private InputStream inflate(final Source src, final long inflatedSize) + private InputStream inflate(Source src, long inflatedSize) throws IOException { inflater.open(src, inflatedSize); return inflater; @@ -1665,7 +1661,7 @@ public abstract class PackParser { private static class DeltaChain extends ObjectIdOwnerMap.Entry { UnresolvedDelta head; - DeltaChain(final AnyObjectId id) { + DeltaChain(AnyObjectId id) { super(id); } @@ -1676,7 +1672,7 @@ public abstract class PackParser { return r; } - void add(final UnresolvedDelta d) { + void add(UnresolvedDelta d) { d.next = head; head = d; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java index 80fc0b42ad..59d1b7885b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackedObjectInfo.java @@ -75,7 +75,7 @@ public class PackedObjectInfo extends ObjectIdOwnerMap.Entry { * @param id * the identity of the object the new instance tracks. */ - public PackedObjectInfo(final AnyObjectId id) { + public PackedObjectInfo(AnyObjectId id) { super(id); } @@ -95,7 +95,7 @@ public class PackedObjectInfo extends ObjectIdOwnerMap.Entry { * @param offset * offset where written object starts */ - public void setOffset(final long offset) { + public void setOffset(long offset) { this.offset = offset; } @@ -116,7 +116,7 @@ public class PackedObjectInfo extends ObjectIdOwnerMap.Entry { * inflated length and delta base reference) as computed by * {@link java.util.zip.CRC32}. */ - public void setCRC(final int crc) { + public void setCRC(int crc) { this.crc = crc; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index 87064e122b..cc556f8af6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -74,6 +74,13 @@ public class PacketLineIn { /** Magic return from {@link #readString()} when a flush packet is found. */ public static final String END = new StringBuilder(0).toString(); /* must not string pool */ + /** + * Magic return from {@link #readString()} when a delim packet is found. + * + * @since 5.0 + */ + public static final String DELIM = new StringBuilder(0).toString(); /* must not string pool */ + static enum AckNackResult { /** NAK */ NAK, @@ -115,7 +122,7 @@ public class PacketLineIn { this.limit = limit; } - AckNackResult readACK(final MutableObjectId returnedId) throws IOException { + AckNackResult readACK(MutableObjectId returnedId) throws IOException { final String line = readString(); if (line.length() == 0) throw new PackProtocolException(JGitText.get().expectedACKNAKFoundEOF); @@ -147,6 +154,7 @@ public class PacketLineIn { * use {@link #readStringRaw()} instead. * * @return the string. {@link #END} if the string was the magic flush + * packet, {@link #DELIM} if the string was the magic DELIM * packet. * @throws java.io.IOException * the stream cannot be read. @@ -157,6 +165,10 @@ public class PacketLineIn { log.debug("git< 0000"); //$NON-NLS-1$ return END; } + if (len == 1) { + log.debug("git< 0001"); //$NON-NLS-1$ + return DELIM; + } len -= 4; // length header (4 bytes) if (len == 0) { @@ -232,6 +244,8 @@ public class PacketLineIn { if (len == 0) { return 0; + } else if (len == 1) { + return 1; } else if (len < 4) { throw invalidHeader(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java index 48bdd01f55..a26d1d77d6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java @@ -78,7 +78,7 @@ public class PacketLineOut { * @param outputStream * stream. */ - public PacketLineOut(final OutputStream outputStream) { + public PacketLineOut(OutputStream outputStream) { out = outputStream; lenbuffer = new byte[5]; flushOnEnd = true; @@ -104,7 +104,7 @@ public class PacketLineOut { * the packet could not be written, the stream is corrupted as * the packet may have been only partially written. */ - public void writeString(final String s) throws IOException { + public void writeString(String s) throws IOException { writePacket(Constants.encode(s)); } @@ -147,6 +147,20 @@ public class PacketLineOut { } /** + * Write a packet delim marker (0001). + * + * @throws java.io.IOException + * the marker could not be written, the stream is corrupted + * as the marker may have been only partially written. + * @since 5.0 + */ + public void writeDelim() throws IOException { + formatLength(1); + out.write(lenbuffer, 0, 4); + log.debug("git> 0001"); //$NON-NLS-1$ + } + + /** * Write a packet end marker, sometimes referred to as a flush command. * <p> * Technically this is a magical packet type which can be detected diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java index 41af8078c8..2364434b0f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.IOException; import java.io.OutputStream; @@ -141,7 +141,7 @@ public class ProgressSpinner { private void write(String s) { if (write) { try { - out.write(s.getBytes(UTF_8)); + out.write(s.getBytes(CHARSET)); out.flush(); } catch (IOException e) { write = false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java index f9fddbe889..178c80d22e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.util.RawParseUtils.lastIndexOfTrim; import java.text.SimpleDateFormat; @@ -95,7 +95,7 @@ public class PushCertificateIdent { */ public static PushCertificateIdent parse(String str) { MutableInteger p = new MutableInteger(); - byte[] raw = str.getBytes(UTF_8); + byte[] raw = str.getBytes(CHARSET); int tzBegin = raw.length - 1; tzBegin = lastIndexOfTrim(raw, ' ', tzBegin); if (tzBegin < 0 || raw[tzBegin] != ' ') { @@ -129,7 +129,7 @@ public class PushCertificateIdent { idEnd = raw.length; } } - String id = new String(raw, 0, idEnd, UTF_8); + String id = new String(raw, 0, idEnd, CHARSET); return new PushCertificateIdent(str, id, when * 1000L, tz); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java index ab58a3317a..7f5a3408e3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT; import static org.eclipse.jgit.lib.FileMode.TYPE_FILE; @@ -192,7 +192,7 @@ public class PushCertificateStore implements AutoCloseable { * @return iterable over certificates; must be fully iterated in order to * close resources. */ - public Iterable<PushCertificate> getAll(final String refName) { + public Iterable<PushCertificate> getAll(String refName) { return new Iterable<PushCertificate>() { @Override public Iterator<PushCertificate> iterator() { @@ -292,7 +292,7 @@ public class PushCertificateStore implements AutoCloseable { ObjectLoader loader = tw.getObjectReader().open(tw.getObjectId(0), OBJ_BLOB); try (InputStream in = loader.openStream(); - Reader r = new BufferedReader(new InputStreamReader(in, UTF_8))) { + Reader r = new BufferedReader(new InputStreamReader(in, CHARSET))) { return PushCertificateParser.fromReader(r); } } @@ -473,7 +473,7 @@ public class PushCertificateStore implements AutoCloseable { DirCacheEditor editor = dc.editor(); String certText = pc.cert.toText() + pc.cert.getSignature(); - final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(UTF_8)); + final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(CHARSET)); boolean any = false; for (ReceiveCommand cmd : pc.cert.getCommands()) { if (byRef != null && !commandsEqual(cmd, byRef.get(cmd.getRefName()))) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java index 3201732a98..470a3c046f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java @@ -48,7 +48,7 @@ import java.io.OutputStream; import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -124,10 +124,10 @@ class PushProcess { throws TransportException { this.walker = new RevWalk(transport.local); this.transport = transport; - this.toPush = new HashMap<>(); + this.toPush = new LinkedHashMap<>(); this.out = out; this.pushOptions = transport.getPushOptions(); - for (final RemoteRefUpdate rru : toPush) { + for (RemoteRefUpdate rru : toPush) { if (this.toPush.put(rru.getRemoteName(), rru) != null) throw new TransportException(MessageFormat.format( JGitText.get().duplicateRemoteRefUpdateIsIllegal, rru.getRemoteName())); @@ -150,7 +150,7 @@ class PushProcess { * when some error occurred during operation, like I/O, protocol * error, or local database consistency error. */ - PushResult execute(final ProgressMonitor monitor) + PushResult execute(ProgressMonitor monitor) throws NotSupportedException, TransportException { try { monitor.beginTask(PROGRESS_OPENING_CONNECTION, @@ -176,7 +176,7 @@ class PushProcess { } if (!transport.isDryRun()) updateTrackingRefs(); - for (final RemoteRefUpdate rru : toPush.values()) { + for (RemoteRefUpdate rru : toPush.values()) { final TrackingRefUpdate tru = rru.getTrackingRefUpdate(); if (tru != null) res.add(tru); @@ -190,8 +190,8 @@ class PushProcess { private Map<String, RemoteRefUpdate> prepareRemoteUpdates() throws TransportException { boolean atomic = transport.isPushAtomic(); - final Map<String, RemoteRefUpdate> result = new HashMap<>(); - for (final RemoteRefUpdate rru : toPush.values()) { + final Map<String, RemoteRefUpdate> result = new LinkedHashMap<>(); + for (RemoteRefUpdate rru : toPush.values()) { final Ref advertisedRef = connection.getRef(rru.getRemoteName()); ObjectId advertisedOld = null; if (advertisedRef != null) { @@ -277,13 +277,13 @@ class PushProcess { } private void modifyUpdatesForDryRun() { - for (final RemoteRefUpdate rru : toPush.values()) + for (RemoteRefUpdate rru : toPush.values()) if (rru.getStatus() == Status.NOT_ATTEMPTED) rru.setStatus(Status.OK); } private void updateTrackingRefs() { - for (final RemoteRefUpdate rru : toPush.values()) { + for (RemoteRefUpdate rru : toPush.values()) { final Status status = rru.getStatus(); if (rru.hasTrackingRefUpdate() && (status == Status.UP_TO_DATE || status == Status.OK)) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushResult.java index 8bae5a5e09..54527048f8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushResult.java @@ -82,7 +82,7 @@ public class PushResult extends OperationResult { * remote ref name * @return status of remote ref update */ - public RemoteRefUpdate getRemoteUpdate(final String refName) { + public RemoteRefUpdate getRemoteUpdate(String refName) { return remoteUpdates.get(refName); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java index e14d18f3a6..d61aeb04d2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java @@ -713,7 +713,7 @@ public class ReceiveCommand { * @param s * the new status code for this command. */ - public void setResult(final Result s) { + public void setResult(Result s) { setResult(s, null); } @@ -725,7 +725,7 @@ public class ReceiveCommand { * @param m * optional message explaining the new status. */ - public void setResult(final Result s, final String m) { + public void setResult(Result s, String m) { status = s; message = m; } @@ -770,7 +770,7 @@ public class ReceiveCommand { * receive-pack session. * @since 2.0 */ - public void execute(final BaseReceivePack rp) { + public void execute(BaseReceivePack rp) { try { String expTarget = getOldSymref(); boolean detach = getNewSymref() != null @@ -818,11 +818,11 @@ public class ReceiveCommand { } } - void setRef(final Ref r) { + void setRef(Ref r) { ref = r; } - void setType(final Type t) { + void setType(Type t) { type = t; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java index 7c5f32ac0d..35fb0b17a7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceivePack.java @@ -88,7 +88,7 @@ public class ReceivePack extends BaseReceivePack { * @param into * the destination repository. */ - public ReceivePack(final Repository into) { + public ReceivePack(Repository into) { super(into); preReceive = PreReceiveHook.NULL; postReceive = PostReceiveHook.NULL; @@ -154,7 +154,7 @@ public class ReceivePack extends BaseReceivePack { * @param h * the hook instance; may be null to disable the hook. */ - public void setPreReceiveHook(final PreReceiveHook h) { + public void setPreReceiveHook(PreReceiveHook h) { preReceive = h != null ? h : PreReceiveHook.NULL; } @@ -178,7 +178,7 @@ public class ReceivePack extends BaseReceivePack { * @param h * the hook instance; may be null to disable the hook. */ - public void setPostReceiveHook(final PostReceiveHook h) { + public void setPostReceiveHook(PostReceiveHook h) { postReceive = h != null ? h : PostReceiveHook.NULL; } @@ -288,7 +288,7 @@ public class ReceivePack extends BaseReceivePack { if (echoCommandFailures && msgOut != null) { sendStatusReport(false, unpackError, new Reporter() { @Override - void sendString(final String s) throws IOException { + void sendString(String s) throws IOException { msgOut.write(Constants.encode(s + "\n")); //$NON-NLS-1$ } }); @@ -301,7 +301,7 @@ public class ReceivePack extends BaseReceivePack { } sendStatusReport(true, unpackError, new Reporter() { @Override - void sendString(final String s) throws IOException { + void sendString(String s) throws IOException { pckOut.writeString(s + "\n"); //$NON-NLS-1$ } }); @@ -309,7 +309,7 @@ public class ReceivePack extends BaseReceivePack { } else if (msgOut != null) { sendStatusReport(false, unpackError, new Reporter() { @Override - void sendString(final String s) throws IOException { + void sendString(String s) throws IOException { msgOut.write(Constants.encode(s + "\n")); //$NON-NLS-1$ } }); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java index 5eb1661738..dc1871b729 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java @@ -43,7 +43,7 @@ package org.eclipse.jgit.transport; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SYMREF; @@ -53,11 +53,12 @@ import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.CharsetEncoder; import java.nio.charset.CoderResult; +import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import java.util.SortedMap; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; @@ -65,7 +66,6 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefComparator; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.util.RefMap; /** * Support for the start of {@link org.eclipse.jgit.transport.UploadPack} and @@ -74,7 +74,7 @@ import org.eclipse.jgit.util.RefMap; public abstract class RefAdvertiser { /** Advertiser which frames lines in a {@link PacketLineOut} format. */ public static class PacketLineOutRefAdvertiser extends RefAdvertiser { - private final CharsetEncoder utf8 = UTF_8.newEncoder(); + private final CharsetEncoder utf8 = CHARSET.newEncoder(); private final PacketLineOut pckOut; private byte[] binArr = new byte[256]; @@ -152,7 +152,7 @@ public abstract class RefAdvertiser { } @Override - protected void writeOne(final CharSequence line) throws IOException { + protected void writeOne(CharSequence line) throws IOException { pckOut.writeString(line.toString()); } @@ -176,6 +176,11 @@ public abstract class RefAdvertiser { boolean first = true; + private boolean useProtocolV2; + + /* only used in protocol v2 */ + private final Map<String, String> symrefs = new HashMap<>(); + /** * Initialize this advertiser with a repository for peeling tags. * @@ -187,6 +192,16 @@ public abstract class RefAdvertiser { } /** + * @param b + * true if this advertiser should advertise using the protocol + * v2 format, false otherwise + * @since 5.0 + */ + public void setUseProtocolV2(boolean b) { + useProtocolV2 = b; + } + + /** * Toggle tag peeling. * <p> * <p> @@ -199,7 +214,7 @@ public abstract class RefAdvertiser { * true to show the dereferenced value of a tag as the special * ref <code>$tag^{}</code> ; false to omit it from the output. */ - public void setDerefTags(final boolean deref) { + public void setDerefTags(boolean deref) { derefTags = deref; } @@ -253,7 +268,11 @@ public abstract class RefAdvertiser { * @since 3.6 */ public void addSymref(String from, String to) { - advertiseCapability(OPTION_SYMREF, from + ':' + to); + if (useProtocolV2) { + symrefs.put(from, to); + } else { + advertiseCapability(OPTION_SYMREF, from + ':' + to); + } } /** @@ -267,13 +286,55 @@ public abstract class RefAdvertiser { * @throws java.io.IOException * the underlying output stream failed to write out an * advertisement record. + * @deprecated use {@link #send(Collection)} instead. */ + @Deprecated public Set<ObjectId> send(Map<String, Ref> refs) throws IOException { - for (Ref ref : getSortedRefs(refs)) { - if (ref.getObjectId() == null) + return send(refs.values()); + } + + /** + * Format an advertisement for the supplied refs. + * + * @param refs + * zero or more refs to format for the client. The collection is + * sorted before display if necessary, and therefore may appear + * in any order. + * @return set of ObjectIds that were advertised to the client. + * @throws java.io.IOException + * the underlying output stream failed to write out an + * advertisement record. + * @since 5.0 + */ + public Set<ObjectId> send(Collection<Ref> refs) throws IOException { + for (Ref ref : RefComparator.sort(refs)) { + // TODO(jrn) revive the SortedMap optimization e.g. by introducing + // SortedList + ObjectId objectId = ref.getObjectId(); + if (objectId == null) { continue; + } - advertiseAny(ref.getObjectId(), ref.getName()); + if (useProtocolV2) { + String symrefPart = symrefs.containsKey(ref.getName()) + ? (" symref-target:" + symrefs.get(ref.getName())) //$NON-NLS-1$ + : ""; //$NON-NLS-1$ + String peelPart = ""; //$NON-NLS-1$ + if (derefTags) { + if (!ref.isPeeled() && repository != null) { + ref = repository.getRefDatabase().peel(ref); + } + ObjectId peeledObjectId = ref.getPeeledObjectId(); + if (peeledObjectId != null) { + peelPart = " peeled:" + peeledObjectId.getName(); //$NON-NLS-1$ + } + } + writeOne(objectId.getName() + " " + ref.getName() + symrefPart //$NON-NLS-1$ + + peelPart + "\n"); //$NON-NLS-1$ + continue; + } + + advertiseAny(objectId, ref.getName()); if (!derefTags) continue; @@ -281,7 +342,7 @@ public abstract class RefAdvertiser { if (!ref.isPeeled()) { if (repository == null) continue; - ref = repository.peel(ref); + ref = repository.getRefDatabase().peel(ref); } if (ref.getPeeledObjectId() != null) @@ -290,13 +351,6 @@ public abstract class RefAdvertiser { return sent; } - private Iterable<Ref> getSortedRefs(Map<String, Ref> all) { - if (all instanceof RefMap - || (all instanceof SortedMap && ((SortedMap) all).comparator() == null)) - return all.values(); - return RefComparator.sort(all.values()); - } - /** * Advertise one object is available using the magic {@code .have}. * <p> @@ -324,13 +378,13 @@ public abstract class RefAdvertiser { return first; } - private void advertiseAnyOnce(AnyObjectId obj, final String refName) + private void advertiseAnyOnce(AnyObjectId obj, String refName) throws IOException { if (!sent.contains(obj)) advertiseAny(obj, refName); } - private void advertiseAny(AnyObjectId obj, final String refName) + private void advertiseAny(AnyObjectId obj, String refName) throws IOException { sent.add(obj.toObjectId()); advertiseId(obj, refName); @@ -351,7 +405,7 @@ public abstract class RefAdvertiser { * the underlying output stream failed to write out an * advertisement record. */ - public void advertiseId(final AnyObjectId id, final String refName) + public void advertiseId(AnyObjectId id, String refName) throws IOException { tmpLine.setLength(0); id.copyTo(tmpId, tmpLine); @@ -361,7 +415,7 @@ public abstract class RefAdvertiser { first = false; if (!capablities.isEmpty()) { tmpLine.append('\0'); - for (final String capName : capablities) { + for (String capName : capablities) { tmpLine.append(' '); tmpLine.append(capName); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefFilter.java index bbe4f84bc8..992ddc6e53 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefFilter.java @@ -63,7 +63,7 @@ public interface RefFilter { */ public static final RefFilter DEFAULT = new RefFilter() { @Override - public Map<String, Ref> filter (final Map<String, Ref> refs) { + public Map<String, Ref> filter (Map<String, Ref> refs) { return refs; } }; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java index e1b306ea90..afd3adaacc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java @@ -72,7 +72,7 @@ public class RefSpec implements Serializable { * ref spec component - string to test. Can be null. * @return true if provided string is a wildcard ref spec component. */ - public static boolean isWildcard(final String s) { + public static boolean isWildcard(String s) { return s != null && s.contains("*"); //$NON-NLS-1$ } @@ -222,11 +222,11 @@ public class RefSpec implements Serializable { * @throws java.lang.IllegalArgumentException * the specification is invalid. */ - public RefSpec(final String spec) { + public RefSpec(String spec) { this(spec, WildcardMode.REQUIRE_MATCH); } - private RefSpec(final RefSpec p) { + private RefSpec(RefSpec p) { force = p.isForceUpdate(); wildcard = p.isWildcard(); srcName = p.getSource(); @@ -250,7 +250,7 @@ public class RefSpec implements Serializable { * new value for force update in the returned instance. * @return a new RefSpec with force update as specified. */ - public RefSpec setForceUpdate(final boolean forceUpdate) { + public RefSpec setForceUpdate(boolean forceUpdate) { final RefSpec r = new RefSpec(this); r.force = forceUpdate; return r; @@ -293,7 +293,7 @@ public class RefSpec implements Serializable { * status of the existing destination disagrees with the * wildcard status of the new source. */ - public RefSpec setSource(final String source) { + public RefSpec setSource(String source) { final RefSpec r = new RefSpec(this); r.srcName = checkValid(source); if (isWildcard(r.srcName) && r.dstName == null) @@ -332,7 +332,7 @@ public class RefSpec implements Serializable { * of the existing source disagrees with the wildcard status of * the new destination. */ - public RefSpec setDestination(final String destination) { + public RefSpec setDestination(String destination) { final RefSpec r = new RefSpec(this); r.dstName = checkValid(destination); if (isWildcard(r.dstName) && r.srcName == null) @@ -372,7 +372,7 @@ public class RefSpec implements Serializable { * ref name that should be tested. * @return true if the names match; false otherwise. */ - public boolean matchSource(final String r) { + public boolean matchSource(String r) { return match(r, getSource()); } @@ -383,7 +383,7 @@ public class RefSpec implements Serializable { * ref whose name should be tested. * @return true if the names match; false otherwise. */ - public boolean matchSource(final Ref r) { + public boolean matchSource(Ref r) { return match(r.getName(), getSource()); } @@ -394,7 +394,7 @@ public class RefSpec implements Serializable { * ref name that should be tested. * @return true if the names match; false otherwise. */ - public boolean matchDestination(final String r) { + public boolean matchDestination(String r) { return match(r, getDestination()); } @@ -405,7 +405,7 @@ public class RefSpec implements Serializable { * ref whose name should be tested. * @return true if the names match; false otherwise. */ - public boolean matchDestination(final Ref r) { + public boolean matchDestination(Ref r) { return match(r.getName(), getDestination()); } @@ -425,7 +425,7 @@ public class RefSpec implements Serializable { * when the RefSpec was constructed with wildcard mode that * doesn't require matching wildcards. */ - public RefSpec expandFromSource(final String r) { + public RefSpec expandFromSource(String r) { if (allowMismatchedWildcards != WildcardMode.REQUIRE_MATCH) { throw new IllegalStateException( JGitText.get().invalidExpandWildcard); @@ -433,7 +433,7 @@ public class RefSpec implements Serializable { return isWildcard() ? new RefSpec(this).expandFromSourceImp(r) : this; } - private RefSpec expandFromSourceImp(final String name) { + private RefSpec expandFromSourceImp(String name) { final String psrc = srcName, pdst = dstName; wildcard = false; srcName = name; @@ -457,7 +457,7 @@ public class RefSpec implements Serializable { * when the RefSpec was constructed with wildcard mode that * doesn't require matching wildcards. */ - public RefSpec expandFromSource(final Ref r) { + public RefSpec expandFromSource(Ref r) { return expandFromSource(r.getName()); } @@ -477,7 +477,7 @@ public class RefSpec implements Serializable { * when the RefSpec was constructed with wildcard mode that * doesn't require matching wildcards. */ - public RefSpec expandFromDestination(final String r) { + public RefSpec expandFromDestination(String r) { if (allowMismatchedWildcards != WildcardMode.REQUIRE_MATCH) { throw new IllegalStateException( JGitText.get().invalidExpandWildcard); @@ -485,7 +485,7 @@ public class RefSpec implements Serializable { return isWildcard() ? new RefSpec(this).expandFromDstImp(r) : this; } - private RefSpec expandFromDstImp(final String name) { + private RefSpec expandFromDstImp(String name) { final String psrc = srcName, pdst = dstName; wildcard = false; srcName = expandWildcard(name, pdst, psrc); @@ -508,11 +508,11 @@ public class RefSpec implements Serializable { * when the RefSpec was constructed with wildcard mode that * doesn't require matching wildcards. */ - public RefSpec expandFromDestination(final Ref r) { + public RefSpec expandFromDestination(Ref r) { return expandFromDestination(r.getName()); } - private boolean match(final String name, final String s) { + private boolean match(String name, String s) { if (s == null) return false; if (isWildcard(s)) { @@ -541,7 +541,7 @@ public class RefSpec implements Serializable { return spec; } - private static boolean isValid(final String s) { + private static boolean isValid(String s) { if (s.startsWith("/")) //$NON-NLS-1$ return false; if (s.contains("//")) //$NON-NLS-1$ @@ -569,7 +569,7 @@ public class RefSpec implements Serializable { /** {@inheritDoc} */ @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (!(obj instanceof RefSpec)) return false; final RefSpec b = (RefSpec) obj; @@ -584,7 +584,7 @@ public class RefSpec implements Serializable { return true; } - private static boolean eq(final String a, final String b) { + private static boolean eq(String a, String b) { if (a == b) return true; if (a == null || b == null) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java index 7b882ec8d5..0a621f19e1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java @@ -112,7 +112,7 @@ public class RemoteConfig implements Serializable { * @throws java.net.URISyntaxException * one of the URIs within the remote's configuration is invalid. */ - public static List<RemoteConfig> getAllRemoteConfigs(final Config rc) + public static List<RemoteConfig> getAllRemoteConfigs(Config rc) throws URISyntaxException { final List<String> names = new ArrayList<>(rc .getSubsections(SECTION)); @@ -120,7 +120,7 @@ public class RemoteConfig implements Serializable { final List<RemoteConfig> result = new ArrayList<>(names .size()); - for (final String name : names) + for (String name : names) result.add(new RemoteConfig(rc, name)); return result; } @@ -160,7 +160,7 @@ public class RemoteConfig implements Serializable { * @throws java.net.URISyntaxException * one of the URIs within the remote's configuration is invalid. */ - public RemoteConfig(final Config rc, final String remoteName) + public RemoteConfig(Config rc, String remoteName) throws URISyntaxException { name = remoteName; @@ -170,12 +170,12 @@ public class RemoteConfig implements Serializable { vlst = rc.getStringList(SECTION, name, KEY_URL); Map<String, String> insteadOf = getReplacements(rc, KEY_INSTEADOF); uris = new ArrayList<>(vlst.length); - for (final String s : vlst) { + for (String s : vlst) { uris.add(new URIish(replaceUri(s, insteadOf))); } String[] plst = rc.getStringList(SECTION, name, KEY_PUSHURL); pushURIs = new ArrayList<>(plst.length); - for (final String s : plst) { + for (String s : plst) { pushURIs.add(new URIish(s)); } if (pushURIs.isEmpty()) { @@ -223,26 +223,26 @@ public class RemoteConfig implements Serializable { * @param rc * the configuration file to store ourselves into. */ - public void update(final Config rc) { + public void update(Config rc) { final List<String> vlst = new ArrayList<>(); vlst.clear(); - for (final URIish u : getURIs()) + for (URIish u : getURIs()) vlst.add(u.toPrivateString()); rc.setStringList(SECTION, getName(), KEY_URL, vlst); vlst.clear(); - for (final URIish u : getPushURIs()) + for (URIish u : getPushURIs()) vlst.add(u.toPrivateString()); rc.setStringList(SECTION, getName(), KEY_PUSHURL, vlst); vlst.clear(); - for (final RefSpec u : getFetchRefSpecs()) + for (RefSpec u : getFetchRefSpecs()) vlst.add(u.toString()); rc.setStringList(SECTION, getName(), KEY_FETCH, vlst); vlst.clear(); - for (final RefSpec u : getPushRefSpecs()) + for (RefSpec u : getPushRefSpecs()) vlst.add(u.toString()); rc.setStringList(SECTION, getName(), KEY_PUSH, vlst); @@ -277,7 +277,7 @@ public class RemoteConfig implements Serializable { rc.setInt(SECTION, getName(), key, currentValue); } - private void unset(final Config rc, final String key) { + private void unset(Config rc, String key) { rc.unset(SECTION, getName(), key); } @@ -335,7 +335,7 @@ public class RemoteConfig implements Serializable { * the new URI to add to this remote. * @return true if the URI was added; false if it already exists. */ - public boolean addURI(final URIish toAdd) { + public boolean addURI(URIish toAdd) { if (uris.contains(toAdd)) return false; return uris.add(toAdd); @@ -348,7 +348,7 @@ public class RemoteConfig implements Serializable { * the URI to remove from this remote. * @return true if the URI was added; false if it already exists. */ - public boolean removeURI(final URIish toRemove) { + public boolean removeURI(URIish toRemove) { return uris.remove(toRemove); } @@ -368,7 +368,7 @@ public class RemoteConfig implements Serializable { * the new URI to add to this remote. * @return true if the URI was added; false if it already exists. */ - public boolean addPushURI(final URIish toAdd) { + public boolean addPushURI(URIish toAdd) { if (pushURIs.contains(toAdd)) return false; return pushURIs.add(toAdd); @@ -381,7 +381,7 @@ public class RemoteConfig implements Serializable { * the URI to remove from this remote. * @return true if the URI was added; false if it already exists. */ - public boolean removePushURI(final URIish toRemove) { + public boolean removePushURI(URIish toRemove) { return pushURIs.remove(toRemove); } @@ -401,7 +401,7 @@ public class RemoteConfig implements Serializable { * the new specification to add. * @return true if the specification was added; false if it already exists. */ - public boolean addFetchRefSpec(final RefSpec s) { + public boolean addFetchRefSpec(RefSpec s) { if (fetch.contains(s)) return false; return fetch.add(s); @@ -414,7 +414,7 @@ public class RemoteConfig implements Serializable { * list of fetch specifications to set. List is copied, it can be * modified after this call. */ - public void setFetchRefSpecs(final List<RefSpec> specs) { + public void setFetchRefSpecs(List<RefSpec> specs) { fetch.clear(); fetch.addAll(specs); } @@ -426,7 +426,7 @@ public class RemoteConfig implements Serializable { * list of push specifications to set. List is copied, it can be * modified after this call. */ - public void setPushRefSpecs(final List<RefSpec> specs) { + public void setPushRefSpecs(List<RefSpec> specs) { push.clear(); push.addAll(specs); } @@ -438,7 +438,7 @@ public class RemoteConfig implements Serializable { * the specification to remove. * @return true if the specification existed and was removed. */ - public boolean removeFetchRefSpec(final RefSpec s) { + public boolean removeFetchRefSpec(RefSpec s) { return fetch.remove(s); } @@ -458,7 +458,7 @@ public class RemoteConfig implements Serializable { * the new specification to add. * @return true if the specification was added; false if it already exists. */ - public boolean addPushRefSpec(final RefSpec s) { + public boolean addPushRefSpec(RefSpec s) { if (push.contains(s)) return false; return push.add(s); @@ -471,7 +471,7 @@ public class RemoteConfig implements Serializable { * the specification to remove. * @return true if the specification existed and was removed. */ - public boolean removePushRefSpec(final RefSpec s) { + public boolean removePushRefSpec(RefSpec s) { return push.remove(s); } @@ -520,7 +520,7 @@ public class RemoteConfig implements Serializable { * @param option * method to use when handling annotated tags. */ - public void setTagOpt(final TagOpt option) { + public void setTagOpt(TagOpt option) { tagopt = option != null ? option : TagOpt.AUTO_FOLLOW; } @@ -541,7 +541,7 @@ public class RemoteConfig implements Serializable { * @param m * true to automatically delete remote refs during push. */ - public void setMirror(final boolean m) { + public void setMirror(boolean m) { mirror = m; } @@ -562,7 +562,7 @@ public class RemoteConfig implements Serializable { * before aborting an IO read or write operation with this * remote. A timeout of 0 will block indefinitely. */ - public void setTimeout(final int seconds) { + public void setTimeout(int seconds) { timeout = seconds; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java index 3e9b16ee49..931653fa90 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java @@ -481,7 +481,7 @@ public class RemoteRefUpdate { expectedOldObjectId = id; } - void setStatus(final Status status) { + void setStatus(Status status) { this.status = status; } @@ -489,7 +489,7 @@ public class RemoteRefUpdate { this.fastForward = fastForward; } - void setMessage(final String message) { + void setMessage(String message) { this.message = message; } @@ -501,7 +501,7 @@ public class RemoteRefUpdate { * @throws java.io.IOException * when I/O error occurred during update */ - protected void updateTrackingRef(final RevWalk walk) throws IOException { + protected void updateTrackingRef(RevWalk walk) throws IOException { if (isDelete()) trackingRefUpdate.setResult(localUpdate.delete(walk)); else diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java index 15338a3a3a..3100cb444a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java @@ -133,7 +133,7 @@ public class SideBandInputStream extends InputStream { /** {@inheritDoc} */ @Override - public int read(final byte[] b, int off, int len) throws IOException { + public int read(byte[] b, int off, int len) throws IOException { int r = 0; while (len > 0) { needDataPacket(); @@ -203,7 +203,7 @@ public class SideBandInputStream extends InputStream { progressBuffer = pkt; } - private void doProgressLine(final String msg) throws IOException { + private void doProgressLine(String msg) throws IOException { Matcher matcher; matcher = P_BOUNDED.matcher(msg); @@ -239,7 +239,7 @@ public class SideBandInputStream extends InputStream { out.write(msg.getBytes()); } - private void beginTask(final int totalWorkUnits) { + private void beginTask(int totalWorkUnits) { monitor.beginTask(remote(currentTask), totalWorkUnits); } @@ -254,7 +254,7 @@ public class SideBandInputStream extends InputStream { return r.toString(); } - private String readString(final int len) throws IOException { + private String readString(int len) throws IOException { final byte[] raw = new byte[len]; IO.readFully(rawIn, raw, 0, len); return RawParseUtils.decode(Constants.CHARSET, raw, 0, len); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java index af65827ca6..b2cc1b6d9e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandOutputStream.java @@ -102,7 +102,7 @@ public class SideBandOutputStream extends OutputStream { * stream that the packets are written onto. This stream should * be attached to a SideBandInputStream on the remote side. */ - public SideBandOutputStream(final int chan, final int sz, final OutputStream os) { + public SideBandOutputStream(int chan, int sz, OutputStream os) { if (chan <= 0 || chan > 255) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().channelMustBeInRange1_255, @@ -136,7 +136,7 @@ public class SideBandOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public void write(final byte[] b, int off, int len) throws IOException { + public void write(byte[] b, int off, int len) throws IOException { while (0 < len) { int capacity = buffer.length - cnt; if (cnt == HDR_SIZE && capacity < len) { @@ -163,7 +163,7 @@ public class SideBandOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public void write(final int b) throws IOException { + public void write(int b) throws IOException { if (cnt == buffer.length) writeBuffer(); buffer[cnt++] = (byte) b; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandProgressMonitor.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandProgressMonitor.java index 365545a092..8a3e4efc93 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandProgressMonitor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandProgressMonitor.java @@ -55,7 +55,7 @@ class SideBandProgressMonitor extends BatchingProgressMonitor { private boolean write; - SideBandProgressMonitor(final OutputStream os) { + SideBandProgressMonitor(OutputStream os) { out = os; write = true; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java index e0022333ef..ae357dfb75 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SshSessionFactory.java @@ -80,7 +80,7 @@ public abstract class SshSessionFactory { * factory for future sessions to be created through. If null the * default factory will be restored.s */ - public static void setInstance(final SshSessionFactory newFactory) { + public static void setInstance(SshSessionFactory newFactory) { if (newFactory != null) INSTANCE = newFactory; else @@ -121,7 +121,7 @@ public abstract class SshSessionFactory { * {@link #getSession(URIish, CredentialsProvider, FS, int)} * method. */ - public void releaseSession(final RemoteSession session) { + public void releaseSession(RemoteSession session) { session.disconnect(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java index e1134e8fa8..cd17913514 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TagOpt.java @@ -84,7 +84,7 @@ public enum TagOpt { private final String option; - private TagOpt(final String o) { + private TagOpt(String o) { option = o; } @@ -104,10 +104,10 @@ public enum TagOpt { * the configuration file text value. * @return the option that matches the passed parameter. */ - public static TagOpt fromOption(final String o) { + public static TagOpt fromOption(String o) { if (o == null || o.length() == 0) return AUTO_FOLLOW; - for (final TagOpt tagopt : values()) { + for (TagOpt tagopt : values()) { if (tagopt.option().equals(o)) return tagopt; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java index 4c70725e42..4ae1ccb420 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java @@ -62,8 +62,8 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.util.SystemReader; /** - * The standard "transfer", "fetch", "receive", and "uploadpack" configuration - * parameters. + * The standard "transfer", "fetch", "protocol", "receive", and "uploadpack" + * configuration parameters. */ public class TransferConfig { private static final String FSCK = "fsck"; //$NON-NLS-1$ @@ -92,6 +92,33 @@ public class TransferConfig { IGNORE; } + /** + * A git configuration variable for which versions of the Git protocol to prefer. + * Used in protocol.version. + */ + enum ProtocolVersion { + V0("0"), //$NON-NLS-1$ + V2("2"); //$NON-NLS-1$ + + final String name; + + ProtocolVersion(String name) { + this.name = name; + } + + static @Nullable ProtocolVersion parse(@Nullable String name) { + if (name == null) { + return null; + } + for (ProtocolVersion v : ProtocolVersion.values()) { + if (v.name.equals(name)) { + return v; + } + } + return null; + } + } + private final boolean fetchFsck; private final boolean receiveFsck; private final String fsckSkipList; @@ -101,32 +128,36 @@ public class TransferConfig { private final boolean safeForMacOS; private final boolean allowTipSha1InWant; private final boolean allowReachableSha1InWant; + private final boolean allowFilter; + final @Nullable ProtocolVersion protocolVersion; final String[] hideRefs; - TransferConfig(final Repository db) { + TransferConfig(Repository db) { this(db.getConfig()); } - TransferConfig(final Config rc) { - boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); //$NON-NLS-1$ //$NON-NLS-2$ - fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); //$NON-NLS-1$ //$NON-NLS-2$ - receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); //$NON-NLS-1$ //$NON-NLS-2$ - fsckSkipList = rc.getString(FSCK, null, "skipList"); //$NON-NLS-1$ - allowInvalidPersonIdent = rc.getBoolean(FSCK, "allowInvalidPersonIdent", false); //$NON-NLS-1$ - safeForWindows = rc.getBoolean(FSCK, "safeForWindows", //$NON-NLS-1$ + @SuppressWarnings("nls") + TransferConfig(Config rc) { + boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); + fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); + receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); + fsckSkipList = rc.getString(FSCK, null, "skipList"); + allowInvalidPersonIdent = rc.getBoolean(FSCK, "allowInvalidPersonIdent", + false); + safeForWindows = rc.getBoolean(FSCK, "safeForWindows", SystemReader.getInstance().isWindows()); - safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", //$NON-NLS-1$ + safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", SystemReader.getInstance().isMacOS()); ignore = EnumSet.noneOf(ObjectChecker.ErrorType.class); EnumSet<ObjectChecker.ErrorType> set = EnumSet .noneOf(ObjectChecker.ErrorType.class); for (String key : rc.getNames(FSCK)) { - if (equalsIgnoreCase(key, "skipList") //$NON-NLS-1$ - || equalsIgnoreCase(key, "allowLeadingZeroFileMode") //$NON-NLS-1$ - || equalsIgnoreCase(key, "allowInvalidPersonIdent") //$NON-NLS-1$ - || equalsIgnoreCase(key, "safeForWindows") //$NON-NLS-1$ - || equalsIgnoreCase(key, "safeForMacOS")) { //$NON-NLS-1$ + if (equalsIgnoreCase(key, "skipList") + || equalsIgnoreCase(key, "allowLeadingZeroFileMode") + || equalsIgnoreCase(key, "allowInvalidPersonIdent") + || equalsIgnoreCase(key, "safeForWindows") + || equalsIgnoreCase(key, "safeForMacOS")) { continue; } @@ -145,15 +176,18 @@ public class TransferConfig { } } if (!set.contains(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE) - && rc.getBoolean(FSCK, "allowLeadingZeroFileMode", false)) { //$NON-NLS-1$ + && rc.getBoolean(FSCK, "allowLeadingZeroFileMode", false)) { ignore.add(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE); } allowTipSha1InWant = rc.getBoolean( - "uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$ + "uploadpack", "allowtipsha1inwant", false); allowReachableSha1InWant = rc.getBoolean( - "uploadpack", "allowreachablesha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$ - hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); //$NON-NLS-1$ //$NON-NLS-2$ + "uploadpack", "allowreachablesha1inwant", false); + allowFilter = rc.getBoolean( + "uploadpack", "allowfilter", false); + protocolVersion = ProtocolVersion.parse(rc.getString("protocol", null, "version")); + hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); } /** @@ -220,6 +254,14 @@ public class TransferConfig { } /** + * @return true if clients are allowed to specify a "filter" line + * @since 5.0 + */ + public boolean isAllowFilter() { + return allowFilter; + } + + /** * Get {@link org.eclipse.jgit.transport.RefFilter} respecting configured * hidden refs. * diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java index 8db796a83f..d342ef46df 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -46,11 +46,10 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.RefDatabase.ALL; +import static org.eclipse.jgit.lib.Constants.CHARSET; import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintStream; @@ -64,7 +63,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Enumeration; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -144,17 +143,8 @@ public abstract class Transport implements AutoCloseable { } private static void scan(ClassLoader ldr, URL url) { - BufferedReader br; - try { - InputStream urlIn = url.openStream(); - br = new BufferedReader(new InputStreamReader(urlIn, "UTF-8")); //$NON-NLS-1$ - } catch (IOException err) { - // If we cannot read from the service list, go to the next. - // - return; - } - - try { + try (BufferedReader br = new BufferedReader( + new InputStreamReader(url.openStream(), CHARSET))) { String line; while ((line = br.readLine()) != null) { line = line.trim(); @@ -167,15 +157,8 @@ public abstract class Transport implements AutoCloseable { line = line.substring(0, comment).trim(); load(ldr, line); } - } catch (IOException err) { - // If we failed during a read, ignore the error. - // - } finally { - try { - br.close(); - } catch (IOException e) { - // Ignore the close error; we are only reading. - } + } catch (IOException e) { + // Ignore errors } } @@ -288,7 +271,7 @@ public abstract class Transport implements AutoCloseable { * @throws org.eclipse.jgit.errors.TransportException * the transport cannot open this URI. */ - public static Transport open(final Repository local, final String remote) + public static Transport open(Repository local, String remote) throws NotSupportedException, URISyntaxException, TransportException { return open(local, remote, Operation.FETCH); @@ -410,7 +393,7 @@ public abstract class Transport implements AutoCloseable { * if provided remote configuration doesn't have any URI * associated. */ - public static Transport open(final Repository local, final RemoteConfig cfg) + public static Transport open(Repository local, RemoteConfig cfg) throws NotSupportedException, TransportException { return open(local, cfg, Operation.FETCH); } @@ -495,7 +478,7 @@ public abstract class Transport implements AutoCloseable { throws NotSupportedException, TransportException { final List<URIish> uris = getURIs(cfg, op); final List<Transport> transports = new ArrayList<>(uris.size()); - for (final URIish uri : uris) { + for (URIish uri : uris) { final Transport tn = open(local, uri, cfg.getName()); tn.applyConfig(cfg); transports.add(tn); @@ -519,7 +502,7 @@ public abstract class Transport implements AutoCloseable { } } - private static boolean doesNotExist(final RemoteConfig cfg) { + private static boolean doesNotExist(RemoteConfig cfg) { return cfg.getURIs().isEmpty() && cfg.getPushURIs().isEmpty(); } @@ -536,7 +519,7 @@ public abstract class Transport implements AutoCloseable { * @throws org.eclipse.jgit.errors.TransportException * the transport cannot open this URI. */ - public static Transport open(final Repository local, final URIish uri) + public static Transport open(Repository local, URIish uri) throws NotSupportedException, TransportException { return open(local, uri, null); } @@ -638,7 +621,7 @@ public abstract class Transport implements AutoCloseable { final List<RemoteRefUpdate> result = new LinkedList<>(); final Collection<RefSpec> procRefs = expandPushWildcardsFor(db, specs); - for (final RefSpec spec : procRefs) { + for (RefSpec spec : procRefs) { String srcSpec = spec.getSource(); final Ref srcRef = db.findRef(srcSpec); if (srcRef != null) @@ -705,12 +688,12 @@ public abstract class Transport implements AutoCloseable { private static Collection<RefSpec> expandPushWildcardsFor( final Repository db, final Collection<RefSpec> specs) throws IOException { - final Map<String, Ref> localRefs = db.getRefDatabase().getRefs(ALL); - final Collection<RefSpec> procRefs = new HashSet<>(); + final List<Ref> localRefs = db.getRefDatabase().getRefs(); + final Collection<RefSpec> procRefs = new LinkedHashSet<>(); - for (final RefSpec spec : specs) { + for (RefSpec spec : specs) { if (spec.isWildcard()) { - for (final Ref localRef : localRefs.values()) { + for (Ref localRef : localRefs) { if (spec.matchSource(localRef)) procRefs.add(spec.expandFromSource(localRef)); } @@ -724,7 +707,7 @@ public abstract class Transport implements AutoCloseable { private static String findTrackingRefName(final String remoteName, final Collection<RefSpec> fetchSpecs) { // try to find matching tracking refs - for (final RefSpec fetchSpec : fetchSpecs) { + for (RefSpec fetchSpec : fetchSpecs) { if (fetchSpec.matchSource(remoteName)) { if (fetchSpec.isWildcard()) return fetchSpec.expandFromSource(remoteName) @@ -807,6 +790,8 @@ public abstract class Transport implements AutoCloseable { /** Should refs no longer on the source be pruned from the destination? */ private boolean removeDeletedRefs; + private long filterBlobLimit = -1; + /** Timeout in seconds to wait before aborting an IO read or write. */ private int timeout; @@ -833,7 +818,7 @@ public abstract class Transport implements AutoCloseable { * the URI used to access the remote repository. This must be the * URI passed to {@link #open(Repository, URIish)}. */ - protected Transport(final Repository local, final URIish uri) { + protected Transport(Repository local, URIish uri) { final TransferConfig tc = local.getConfig().get(TransferConfig.KEY); this.local = local; this.uri = uri; @@ -848,7 +833,7 @@ public abstract class Transport implements AutoCloseable { * @param uri * a {@link org.eclipse.jgit.transport.URIish} object. */ - protected Transport(final URIish uri) { + protected Transport(URIish uri) { this.uri = uri; this.local = null; this.objectChecker = new ObjectChecker(); @@ -881,7 +866,7 @@ public abstract class Transport implements AutoCloseable { * @param where * name of the executable. */ - public void setOptionUploadPack(final String where) { + public void setOptionUploadPack(String where) { if (where != null && where.length() > 0) optionUploadPack = where; else @@ -903,7 +888,7 @@ public abstract class Transport implements AutoCloseable { * @param option * method to use when handling annotated tags. */ - public void setTagOpt(final TagOpt option) { + public void setTagOpt(TagOpt option) { tagopt = option != null ? option : TagOpt.AUTO_FOLLOW; } @@ -927,7 +912,7 @@ public abstract class Transport implements AutoCloseable { * when it shouldn't * @see PackTransport */ - public void setFetchThin(final boolean fetchThin) { + public void setFetchThin(boolean fetchThin) { this.fetchThin = fetchThin; } @@ -950,7 +935,7 @@ public abstract class Transport implements AutoCloseable { * received objects are valid. * @see #setObjectChecker(ObjectChecker) */ - public void setCheckFetchedObjects(final boolean check) { + public void setCheckFetchedObjects(boolean check) { if (check && objectChecker == null) setObjectChecker(new ObjectChecker()); else if (!check && objectChecker != null) @@ -1025,7 +1010,7 @@ public abstract class Transport implements AutoCloseable { * false when it shouldn't * @see PackTransport */ - public void setPushThin(final boolean pushThin) { + public void setPushThin(boolean pushThin) { this.pushThin = pushThin; } @@ -1050,7 +1035,7 @@ public abstract class Transport implements AutoCloseable { * @see PackTransport * @since 4.2 */ - public void setPushAtomic(final boolean atomic) { + public void setPushAtomic(boolean atomic) { this.pushAtomic = atomic; } @@ -1077,17 +1062,34 @@ public abstract class Transport implements AutoCloseable { * * @param remove true to remove refs that no longer exist. */ - public void setRemoveDeletedRefs(final boolean remove) { + public void setRemoveDeletedRefs(boolean remove) { removeDeletedRefs = remove; } /** + * @return the last value passed to {@link #setFilterBlobLimit}, or -1 if + * it was never invoked. + * @since 5.0 + */ + public long getFilterBlobLimit() { + return filterBlobLimit; + } + + /** + * @param bytes exclude blobs of size greater than this + * @since 5.0 + */ + public void setFilterBlobLimit(long bytes) { + filterBlobLimit = bytes; + } + + /** * Apply provided remote configuration on this transport. * * @param cfg * configuration to apply on this transport. */ - public void applyConfig(final RemoteConfig cfg) { + public void applyConfig(RemoteConfig cfg) { setOptionUploadPack(cfg.getUploadPack()); setOptionReceivePack(cfg.getReceivePack()); setTagOpt(cfg.getTagOpt()); @@ -1116,7 +1118,7 @@ public abstract class Transport implements AutoCloseable { * and not really update remote refs, false otherwise - when push * should act normally. */ - public void setDryRun(final boolean dryRun) { + public void setDryRun(boolean dryRun) { this.dryRun = dryRun; } @@ -1137,7 +1139,7 @@ public abstract class Transport implements AutoCloseable { * before aborting an IO read or write operation with this * remote. */ - public void setTimeout(final int seconds) { + public void setTimeout(int seconds) { timeout = seconds; } @@ -1204,7 +1206,7 @@ public abstract class Transport implements AutoCloseable { * null if push options are unsupported * @since 4.5 */ - public void setPushOptions(final List<String> pushOptions) { + public void setPushOptions(List<String> pushOptions) { this.pushOptions = pushOptions; } @@ -1251,9 +1253,9 @@ public abstract class Transport implements AutoCloseable { // object transfer overheads. // final Collection<RefSpec> tmp = new ArrayList<>(toFetch); - for (final RefSpec requested : toFetch) { + for (RefSpec requested : toFetch) { final String reqSrc = requested.getSource(); - for (final RefSpec configured : fetch) { + for (RefSpec configured : fetch) { final String cfgSrc = configured.getSource(); final String cfgDst = configured.getDestination(); if (cfgSrc.equals(reqSrc) && cfgDst != null) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java index c6191eceb0..6118cb8770 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java @@ -267,7 +267,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { } @Override - WalkRemoteObjectDatabase openAlternate(final String location) + WalkRemoteObjectDatabase openAlternate(String location) throws IOException { return new DatabaseS3(bucketName, resolveKey(location)); } @@ -278,7 +278,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { have.addAll(s3.list(bucket, resolveKey("pack"))); //$NON-NLS-1$ final Collection<String> packs = new ArrayList<>(); - for (final String n : have) { + for (String n : have) { if (!n.startsWith("pack-") || !n.endsWith(".pack")) //$NON-NLS-1$ //$NON-NLS-2$ continue; @@ -290,7 +290,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { } @Override - FileStream open(final String path) throws IOException { + FileStream open(String path) throws IOException { final URLConnection c = s3.get(bucket, resolveKey(path)); final InputStream raw = c.getInputStream(); final InputStream in = s3.decrypt(c); @@ -299,7 +299,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { } @Override - void deleteFile(final String path) throws IOException { + void deleteFile(String path) throws IOException { s3.delete(bucket, resolveKey(path)); } @@ -311,7 +311,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { } @Override - void writeFile(final String path, final byte[] data) throws IOException { + void writeFile(String path, byte[] data) throws IOException { s3.put(bucket, resolveKey(path), data); } @@ -323,7 +323,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { return avail; } - private void readLooseRefs(final TreeMap<String, Ref> avail) + private void readLooseRefs(TreeMap<String, Ref> avail) throws TransportException { try { for (final String n : s3.list(bucket, resolveKey(ROOT_DIR @@ -334,16 +334,13 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { } } - private Ref readRef(final TreeMap<String, Ref> avail, final String rn) + private Ref readRef(TreeMap<String, Ref> avail, String rn) throws TransportException { final String s; String ref = ROOT_DIR + rn; try { - final BufferedReader br = openReader(ref); - try { + try (BufferedReader br = openReader(ref)) { s = br.readLine(); - } finally { - br.close(); } } catch (FileNotFoundException noRef) { return null; @@ -377,7 +374,7 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport { throw new TransportException(getURI(), MessageFormat.format(JGitText.get().transportExceptionBadRef, rn, s)); } - private Storage loose(final Ref r) { + private Storage loose(Ref r) { if (r != null && r.getStorage() == Storage.PACKED) return Storage.LOOSE_PACKED; return Storage.LOOSE; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java index 816187ee0c..1132503643 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java @@ -113,11 +113,11 @@ class TransportGitAnon extends TcpTransport implements PackTransport { } }; - TransportGitAnon(final Repository local, final URIish uri) { + TransportGitAnon(Repository local, URIish uri) { super(local, uri); } - TransportGitAnon(final URIish uri) { + TransportGitAnon(URIish uri) { super(uri); } @@ -142,6 +142,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport { Socket openConnection() throws TransportException { final int tms = getTimeout() > 0 ? getTimeout() * 1000 : 0; final int port = uri.getPort() > 0 ? uri.getPort() : GIT_PORT; + @SuppressWarnings("resource") // Closed by the caller final Socket s = new Socket(); try { final InetAddress host = InetAddress.getByName(uri.getHost()); @@ -162,7 +163,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport { return s; } - void service(final String name, final PacketLineOut pckOut) + void service(String name, PacketLineOut pckOut) throws IOException { final StringBuilder cmd = new StringBuilder(); cmd.append(name); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java index bc85e6f60f..d59fe33df6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitSsh.java @@ -141,12 +141,12 @@ public class TransportGitSsh extends SshTransport implements PackTransport { } }; - TransportGitSsh(final Repository local, final URIish uri) { + TransportGitSsh(Repository local, URIish uri) { super(local, uri); initSshSessionFactory(); } - TransportGitSsh(final URIish uri) { + TransportGitSsh(URIish uri) { super(uri); initSshSessionFactory(); } @@ -176,7 +176,7 @@ public class TransportGitSsh extends SshTransport implements PackTransport { return new SshPushConnection(); } - String commandFor(final String exe) { + String commandFor(String exe) { String path = uri.getPath(); if (uri.getScheme() != null && uri.getPath().startsWith("/~")) //$NON-NLS-1$ path = (uri.getPath().substring(1)); @@ -311,6 +311,9 @@ public class TransportGitSsh extends SshTransport implements PackTransport { public void close() { endOut(); + if (process != null) { + process.destroy(); + } if (errorThread != null) { try { errorThread.halt(); @@ -322,8 +325,6 @@ public class TransportGitSsh extends SshTransport implements PackTransport { } super.close(); - if (process != null) - process.destroy(); } } @@ -377,6 +378,9 @@ public class TransportGitSsh extends SshTransport implements PackTransport { public void close() { endOut(); + if (process != null) { + process.destroy(); + } if (errorThread != null) { try { errorThread.halt(); @@ -388,8 +392,6 @@ public class TransportGitSsh extends SshTransport implements PackTransport { } super.close(); - if (process != null) - process.destroy(); } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java index a1826231ab..c08f400307 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -273,7 +273,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, private boolean sslFailure = false; - TransportHttp(final Repository local, final URIish uri) + TransportHttp(Repository local, URIish uri) throws NotSupportedException { super(local, uri); setURI(uri); @@ -298,7 +298,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, * @throws org.eclipse.jgit.errors.NotSupportedException * @since 4.9 */ - protected void setURI(final URIish uri) throws NotSupportedException { + protected void setURI(URIish uri) throws NotSupportedException { try { currentUri = uri; baseUrl = toURL(uri); @@ -314,7 +314,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, * @param uri * @throws NotSupportedException */ - TransportHttp(final URIish uri) throws NotSupportedException { + TransportHttp(URIish uri) throws NotSupportedException { super(uri); setURI(uri); http = new HttpConfig(uri); @@ -332,10 +332,26 @@ public class TransportHttp extends HttpTransport implements WalkTransport, * @param on * if {@code true} (default), smart HTTP is enabled. */ - public void setUseSmartHttp(final boolean on) { + public void setUseSmartHttp(boolean on) { useSmartHttp = on; } + @SuppressWarnings("resource") // Closed by caller + private FetchConnection getConnection(HttpConnection c, InputStream in, + String service) throws IOException { + BaseConnection f; + if (isSmartHttp(c, service)) { + readSmartHeaders(in, service); + f = new SmartHttpFetchConnection(in); + } else { + // Assume this server doesn't support smart HTTP fetch + // and fall back on dumb object walking. + f = newDumbConnection(in); + } + f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER)); + return (FetchConnection) f; + } + /** {@inheritDoc} */ @Override public FetchConnection openFetch() throws TransportException, @@ -343,21 +359,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport, final String service = SVC_UPLOAD_PACK; try { final HttpConnection c = connect(service); - final InputStream in = openInputStream(c); - try { - BaseConnection f; - if (isSmartHttp(c, service)) { - readSmartHeaders(in, service); - f = new SmartHttpFetchConnection(in); - } else { - // Assume this server doesn't support smart HTTP fetch - // and fall back on dumb object walking. - f = newDumbConnection(in); - } - f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER)); - return (FetchConnection) f; - } finally { - in.close(); + try (InputStream in = openInputStream(c)) { + return getConnection(c, in, service); } } catch (NotSupportedException err) { throw err; @@ -480,7 +483,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, this.headers = headers; } - private HttpConnection connect(final String service) + private HttpConnection connect(String service) throws TransportException, NotSupportedException { URL u = getServiceURL(service); int authAttempts = 1; @@ -772,7 +775,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return true; } - private URL getServiceURL(final String service) + private URL getServiceURL(String service) throws NotSupportedException { try { final StringBuilder b = new StringBuilder(); @@ -796,21 +799,6 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } /** - * Open an HTTP connection, setting the accept-encoding request header to gzip. - * - * @param method HTTP request method - * @param u url of the HTTP connection - * @return the HTTP connection - * @throws java.io.IOException - * @since 3.3 - * @deprecated use {@link #httpOpen(String, URL, AcceptEncoding)} instead. - */ - @Deprecated - protected HttpConnection httpOpen(String method, URL u) throws IOException { - return httpOpen(method, u, AcceptEncoding.GZIP); - } - - /** * Open an HTTP connection. * * @param method HTTP request method @@ -873,18 +861,18 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return new TransportException(uri, why); } - private boolean isSmartHttp(final HttpConnection c, final String service) { + private boolean isSmartHttp(HttpConnection c, String service) { final String expType = "application/x-" + service + "-advertisement"; //$NON-NLS-1$ //$NON-NLS-2$ final String actType = c.getContentType(); return expType.equals(actType); } - private boolean isGzipContent(final HttpConnection c) { + private boolean isGzipContent(HttpConnection c) { return ENCODING_GZIP.equals(c.getHeaderField(HDR_CONTENT_ENCODING)) || ENCODING_X_GZIP.equals(c.getHeaderField(HDR_CONTENT_ENCODING)); } - private void readSmartHeaders(final InputStream in, final String service) + private void readSmartHeaders(InputStream in, String service) throws IOException { // A smart reply will have a '#' after the first 4 bytes, but // a dumb reply cannot contain a '#' until after byte 41. Do a @@ -915,7 +903,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, class HttpObjectDB extends WalkRemoteObjectDatabase { private final URL httpObjectsUrl; - HttpObjectDB(final URL b) { + HttpObjectDB(URL b) { httpObjectsUrl = b; } @@ -942,7 +930,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } @Override - WalkRemoteObjectDatabase openAlternate(final String location) + WalkRemoteObjectDatabase openAlternate(String location) throws IOException { return new HttpObjectDB(new URL(httpObjectsUrl, location)); } @@ -974,7 +962,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } @Override - FileStream open(final String path) throws IOException { + FileStream open(String path) throws IOException { return open(path, AcceptEncoding.UNSPECIFIED); } @@ -1042,15 +1030,15 @@ public class TransportHttp extends HttpTransport implements WalkTransport, return avail; } - private PackProtocolException outOfOrderAdvertisement(final String n) { + private PackProtocolException outOfOrderAdvertisement(String n) { return new PackProtocolException(MessageFormat.format(JGitText.get().advertisementOfCameBefore, n, n)); } - private PackProtocolException invalidAdvertisement(final String n) { + private PackProtocolException invalidAdvertisement(String n) { return new PackProtocolException(MessageFormat.format(JGitText.get().invalidAdvertisementOf, n)); } - private PackProtocolException duplicateAdvertisement(final String n) { + private PackProtocolException duplicateAdvertisement(String n) { return new PackProtocolException(MessageFormat.format(JGitText.get().duplicateAdvertisementsOf, n)); } @@ -1063,7 +1051,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, class SmartHttpFetchConnection extends BasePackFetchConnection { private MultiRequestService svc; - SmartHttpFetchConnection(final InputStream advertisement) + SmartHttpFetchConnection(InputStream advertisement) throws TransportException { super(TransportHttp.this); statelessRPC = true; @@ -1093,7 +1081,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } class SmartHttpPushConnection extends BasePackPushConnection { - SmartHttpPushConnection(final InputStream advertisement) + SmartHttpPushConnection(InputStream advertisement) throws TransportException { super(TransportHttp.this); statelessRPC = true; @@ -1396,7 +1384,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, class MultiRequestService extends Service { boolean finalRequest; - MultiRequestService(final String serviceName) { + MultiRequestService(String serviceName) { super(serviceName); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java index 4f1880b7ef..fbb2c44100 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportLocal.java @@ -162,11 +162,11 @@ class TransportLocal extends Transport implements PackTransport { remoteGitDir = gitDir; } - UploadPack createUploadPack(final Repository dst) { + UploadPack createUploadPack(Repository dst) { return new UploadPack(dst); } - ReceivePack createReceivePack(final Repository dst) { + ReceivePack createReceivePack(Repository dst) { return new ReceivePack(dst); } @@ -229,7 +229,7 @@ class TransportLocal extends Transport implements PackTransport { * @throws org.eclipse.jgit.errors.TransportException * if any. */ - protected Process spawn(final String cmd) + protected Process spawn(String cmd) throws TransportException { try { String[] args = { "." }; //$NON-NLS-1$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java index 09cd67b515..f129ba34da 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportSftp.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; + import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; @@ -134,7 +136,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { } }; - TransportSftp(final Repository local, final URIish uri) { + TransportSftp(Repository local, URIish uri) { super(local, uri); } @@ -195,7 +197,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { } } - SftpObjectDB(final SftpObjectDB parent, final String p) + SftpObjectDB(SftpObjectDB parent, String p) throws TransportException { try { ftp = newSftp(); @@ -227,7 +229,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { } @Override - WalkRemoteObjectDatabase openAlternate(final String location) + WalkRemoteObjectDatabase openAlternate(String location) throws IOException { return new SftpObjectDB(this, location); } @@ -244,9 +246,9 @@ public class TransportSftp extends SshTransport implements WalkTransport { files = new HashMap<>(); mtimes = new HashMap<>(); - for (final ChannelSftp.LsEntry ent : list) + for (ChannelSftp.LsEntry ent : list) files.put(ent.getFilename(), ent); - for (final ChannelSftp.LsEntry ent : list) { + for (ChannelSftp.LsEntry ent : list) { final String n = ent.getFilename(); if (!n.startsWith("pack-") || !n.endsWith(".pack")) //$NON-NLS-1$ //$NON-NLS-2$ continue; @@ -261,7 +263,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { Collections.sort(packs, new Comparator<String>() { @Override - public int compare(final String o1, final String o2) { + public int compare(String o1, String o2) { return mtimes.get(o2).intValue() - mtimes.get(o1).intValue(); } @@ -276,7 +278,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { } @Override - FileStream open(final String path) throws IOException { + FileStream open(String path) throws IOException { try { final SftpATTRS a = ftp.lstat(path); return new FileStream(ftp.get(path), a.getSize()); @@ -290,7 +292,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { } @Override - void deleteFile(final String path) throws IOException { + void deleteFile(String path) throws IOException { try { ftp.rm(path); } catch (SftpException je) { @@ -343,8 +345,8 @@ public class TransportSftp extends SshTransport implements WalkTransport { } @Override - void writeFile(final String path, final byte[] data) throws IOException { - final String lock = path + ".lock"; //$NON-NLS-1$ + void writeFile(String path, byte[] data) throws IOException { + final String lock = path + LOCK_SUFFIX; try { super.writeFile(lock, data); try { @@ -411,7 +413,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { je.getMessage()), je); } - for (final ChannelSftp.LsEntry ent : list) { + for (ChannelSftp.LsEntry ent : list) { final String n = ent.getFilename(); if (".".equals(n) || "..".equals(n)) //$NON-NLS-1$ //$NON-NLS-2$ continue; @@ -464,7 +466,7 @@ public class TransportSftp extends SshTransport implements WalkTransport { MessageFormat.format(JGitText.get().badRef, name, line)); } - private Storage loose(final Ref r) { + private Storage loose(Ref r) { if (r != null && r.getStorage() == Storage.PACKED) return Storage.LOOSE_PACKED; return Storage.LOOSE; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java index a048fe30f2..026fd819c4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/URIish.java @@ -387,7 +387,7 @@ public class URIish implements Serializable { * @param u * the source URL to convert from. */ - public URIish(final URL u) { + public URIish(URL u) { scheme = u.getProtocol(); path = u.getPath(); path = cleanLeadingSlashes(path, scheme); @@ -416,7 +416,7 @@ public class URIish implements Serializable { // Configure nothing. } - private URIish(final URIish u) { + private URIish(URIish u) { this.scheme = u.scheme; this.rawPath = u.rawPath; this.path = u.path; @@ -451,7 +451,7 @@ public class URIish implements Serializable { * the new value for host. * @return a new URI with the updated value. */ - public URIish setHost(final String n) { + public URIish setHost(String n) { final URIish r = new URIish(this); r.host = n; return r; @@ -473,7 +473,7 @@ public class URIish implements Serializable { * the new value for scheme. * @return a new URI with the updated value. */ - public URIish setScheme(final String n) { + public URIish setScheme(String n) { final URIish r = new URIish(this); r.scheme = n; return r; @@ -504,7 +504,7 @@ public class URIish implements Serializable { * the new value for path. * @return a new URI with the updated value. */ - public URIish setPath(final String n) { + public URIish setPath(String n) { final URIish r = new URIish(this); r.path = n; r.rawPath = n; @@ -519,7 +519,7 @@ public class URIish implements Serializable { * @return a new URI with the updated value. * @throws java.net.URISyntaxException */ - public URIish setRawPath(final String n) throws URISyntaxException { + public URIish setRawPath(String n) throws URISyntaxException { final URIish r = new URIish(this); r.path = unescape(n); r.rawPath = n; @@ -542,7 +542,7 @@ public class URIish implements Serializable { * the new value for user. * @return a new URI with the updated value. */ - public URIish setUser(final String n) { + public URIish setUser(String n) { final URIish r = new URIish(this); r.user = n; return r; @@ -564,7 +564,7 @@ public class URIish implements Serializable { * the new value for password. * @return a new URI with the updated value. */ - public URIish setPass(final String n) { + public URIish setPass(String n) { final URIish r = new URIish(this); r.pass = n; return r; @@ -586,7 +586,7 @@ public class URIish implements Serializable { * the new value for port. * @return a new URI with the updated value. */ - public URIish setPort(final int n) { + public URIish setPort(int n) { final URIish r = new URIish(this); r.port = n > 0 ? n : -1; return r; @@ -613,7 +613,7 @@ public class URIish implements Serializable { /** {@inheritDoc} */ @Override - public boolean equals(final Object obj) { + public boolean equals(Object obj) { if (!(obj instanceof URIish)) return false; final URIish b = (URIish) obj; @@ -632,7 +632,7 @@ public class URIish implements Serializable { return true; } - private static boolean eq(final String a, final String b) { + private static boolean eq(String a, String b) { if (a == b) return true; if (StringUtils.isEmptyOrNull(a) && StringUtils.isEmptyOrNull(b)) @@ -657,7 +657,7 @@ public class URIish implements Serializable { return format(false, false); } - private String format(final boolean includePassword, boolean escapeNonAscii) { + private String format(boolean includePassword, boolean escapeNonAscii) { final StringBuilder r = new StringBuilder(); if (getScheme() != null) { r.append(getScheme()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 0209be1f73..7de0506bb3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -43,10 +43,15 @@ package org.eclipse.jgit.transport; +import static org.eclipse.jgit.lib.Constants.R_TAGS; import static org.eclipse.jgit.lib.RefDatabase.ALL; +import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_FETCH; +import static org.eclipse.jgit.transport.GitProtocolConstants.COMMAND_LS_REFS; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_AGENT; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_ALLOW_REACHABLE_SHA1_IN_WANT; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_ALLOW_TIP_SHA1_IN_WANT; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_DEEPEN_RELATIVE; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_FILTER; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_INCLUDE_TAG; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_MULTI_ACK; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_MULTI_ACK_DETAILED; @@ -67,10 +72,13 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; + +import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.MissingObjectException; @@ -85,7 +93,6 @@ import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.RefDatabase; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.revwalk.AsyncRevObjectQueue; import org.eclipse.jgit.revwalk.BitmapWalker; @@ -102,6 +109,7 @@ import org.eclipse.jgit.storage.pack.PackConfig; import org.eclipse.jgit.storage.pack.PackStatistics; import org.eclipse.jgit.transport.GitProtocolConstants.MultiAck; import org.eclipse.jgit.transport.RefAdvertiser.PacketLineOutRefAdvertiser; +import org.eclipse.jgit.transport.TransferConfig.ProtocolVersion; import org.eclipse.jgit.util.io.InterruptTimer; import org.eclipse.jgit.util.io.NullOutputStream; import org.eclipse.jgit.util.io.TimeoutInputStream; @@ -237,6 +245,12 @@ public class UploadPack { /** Timer to manage {@link #timeout}. */ private InterruptTimer timer; + /** + * Whether the client requested to use protocol V2 through a side + * channel (such as the Git-Protocol HTTP header). + */ + private boolean clientRequestedV2; + private InputStream rawIn; private ResponseBufferedOutputStream rawOut; @@ -278,12 +292,22 @@ public class UploadPack { /** Shallow commits the client already has. */ private final Set<ObjectId> clientShallowCommits = new HashSet<>(); - /** Shallow commits on the client which are now becoming unshallow */ - private final List<ObjectId> unshallowCommits = new ArrayList<>(); - /** Desired depth from the client on a shallow request. */ private int depth; + /** + * Commit time of the newest objects the client has asked us using + * --shallow-since not to send. Cannot be nonzero if depth is nonzero. + */ + private int shallowSince; + + /** + * (Possibly short) ref names, ancestors of which the client has asked us + * not to send using --shallow-exclude. Cannot be non-null if depth is + * nonzero. + */ + private @Nullable List<String> shallowExcludeRefs; + /** Commit time of the oldest common commit, in seconds. */ private int oldestTime; @@ -317,8 +341,7 @@ public class UploadPack { private PackStatistics statistics; - @SuppressWarnings("deprecation") - private UploadPackLogger logger = UploadPackLogger.NULL; + private long filterBlobLimit = -1; /** * Create a new pack upload for an open repository. @@ -326,7 +349,7 @@ public class UploadPack { * @param copyFrom * the source repository. */ - public UploadPack(final Repository copyFrom) { + public UploadPack(Repository copyFrom) { db = copyFrom; walk = new RevWalk(db); walk.setRetainBody(false); @@ -415,7 +438,7 @@ public class UploadPack { * before aborting an IO read or write operation with the * connected client. */ - public void setTimeout(final int seconds) { + public void setTimeout(int seconds) { timeout = seconds; } @@ -442,7 +465,7 @@ public class UploadPack { * commands before writing output and does not perform the * initial advertising. */ - public void setBiDirectionalPipe(final boolean twoWay) { + public void setBiDirectionalPipe(boolean twoWay) { biDirectionalPipe = twoWay; } @@ -545,7 +568,7 @@ public class UploadPack { * @param advertiseRefsHook * the hook; may be null to show all refs. */ - public void setAdvertiseRefsHook(final AdvertiseRefsHook advertiseRefsHook) { + public void setAdvertiseRefsHook(AdvertiseRefsHook advertiseRefsHook) { if (advertiseRefsHook != null) this.advertiseRefsHook = advertiseRefsHook; else @@ -564,7 +587,7 @@ public class UploadPack { * @param refFilter * the filter; may be null to show all refs. */ - public void setRefFilter(final RefFilter refFilter) { + public void setRefFilter(RefFilter refFilter) { this.refFilter = refFilter != null ? refFilter : RefFilter.DEFAULT; } @@ -639,29 +662,6 @@ public class UploadPack { } /** - * Get the configured logger. - * - * @return the configured logger. - * @deprecated Use {@link #getPreUploadHook()}. - */ - @Deprecated - public UploadPackLogger getLogger() { - return logger; - } - - /** - * Set the logger. - * - * @param logger - * the logger instance. If null, no logging occurs. - * @deprecated Use {@link #setPreUploadHook(PreUploadHook)}. - */ - @Deprecated - public void setLogger(UploadPackLogger logger) { - this.logger = logger; - } - - /** * Check whether the client expects a side-band stream. * * @return true if the client has advertised a side-band capability, false @@ -680,8 +680,34 @@ public class UploadPack { } /** + * Set the Extra Parameters provided by the client. + * + * <p>These are parameters passed by the client through a side channel + * such as the Git-Protocol HTTP header, to allow a client to request + * a newer response format while remaining compatible with older servers + * that do not understand different request formats. + * + * @param params + * parameters supplied by the client, split at colons or NUL + * bytes. + * @since 5.0 + */ + public void setExtraParameters(Collection<String> params) { + this.clientRequestedV2 = params.contains("version=2"); //$NON-NLS-1$ + } + + private boolean useProtocolV2() { + return ProtocolVersion.V2.equals(transferConfig.protocolVersion) + && clientRequestedV2; + } + + /** * Execute the upload task on the socket. * + * <p>If the client passed extra parameters (e.g., "version=2") through a + * side channel, the caller must call setExtraParameters first to supply + * them. + * * @param input * raw input to read client commands from. Caller must ensure the * input is buffered, otherwise read performance may suffer. @@ -722,7 +748,11 @@ public class UploadPack { pckIn = new PacketLineIn(rawIn); pckOut = new PacketLineOut(rawOut); - service(); + if (useProtocolV2()) { + serviceV2(); + } else { + service(); + } } finally { msgOut = NullOutputStream.INSTANCE; walk.close(); @@ -742,21 +772,6 @@ public class UploadPack { * @return statistics about pack output, if a pack was sent. Null if no pack * was sent, such as during the negotiation phase of a smart HTTP * connection, or if the client was already up-to-date. - * @since 3.0 - * @deprecated Use {@link #getStatistics()}. - */ - @Deprecated - public PackWriter.Statistics getPackStatistics() { - return statistics == null ? null - : new PackWriter.Statistics(statistics); - } - - /** - * Get the PackWriter's statistics if a pack was sent to the client. - * - * @return statistics about pack output, if a pack was sent. Null if no pack - * was sent, such as during the negotiation phase of a smart HTTP - * connection, or if the client was already up-to-date. * @since 4.1 */ public PackStatistics getStatistics() { @@ -765,7 +780,7 @@ public class UploadPack { private Map<String, Ref> getAdvertisedOrDefaultRefs() throws IOException { if (refs == null) - setAdvertisedRefs(db.getRefDatabase().getRefs(RefDatabase.ALL)); + setAdvertisedRefs(db.getRefDatabase().getRefs(ALL)); return refs; } @@ -774,6 +789,7 @@ public class UploadPack { // If it's a non-bidi request, we need to read the entire request before // writing a response. Buffer the response until then. PackStatistics.Accumulator accumulator = new PackStatistics.Accumulator(); + List<ObjectId> unshallowCommits = new ArrayList<>(); try { if (biDirectionalPipe) sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut)); @@ -803,7 +819,7 @@ public class UploadPack { if (!clientShallowCommits.isEmpty()) verifyClientShallow(); if (depth != 0) - processShallow(); + processShallow(null, unshallowCommits, true); if (!clientShallowCommits.isEmpty()) walk.assumeShallow(clientShallowCommits); sendPack = negotiate(accumulator); @@ -855,8 +871,288 @@ public class UploadPack { rawOut.stopBuffering(); } - if (sendPack) - sendPack(accumulator); + if (sendPack) { + sendPack(accumulator, refs == null ? null : refs.values(), unshallowCommits); + } + } + + private void lsRefsV2() throws IOException { + PacketLineOutRefAdvertiser adv = new PacketLineOutRefAdvertiser(pckOut); + String line; + ArrayList<String> refPrefixes = new ArrayList<>(); + boolean needToFindSymrefs = false; + + adv.setUseProtocolV2(true); + + line = pckIn.readString(); + + // Currently, we do not support any capabilities, so the next + // line is DELIM if there are arguments or END if not. + if (line == PacketLineIn.DELIM) { + while ((line = pckIn.readString()) != PacketLineIn.END) { + if (line.equals("peel")) { //$NON-NLS-1$ + adv.setDerefTags(true); + } else if (line.equals("symrefs")) { //$NON-NLS-1$ + needToFindSymrefs = true; + } else if (line.startsWith("ref-prefix ")) { //$NON-NLS-1$ + refPrefixes.add(line.substring("ref-prefix ".length())); //$NON-NLS-1$ + } else { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + } + } else if (line != PacketLineIn.END) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + rawOut.stopBuffering(); + + Map<String, Ref> refsToSend; + if (refPrefixes.isEmpty()) { + refsToSend = getAdvertisedOrDefaultRefs(); + } else { + refsToSend = new HashMap<>(); + for (String refPrefix : refPrefixes) { + for (Ref ref : db.getRefDatabase().getRefsByPrefix(refPrefix)) { + refsToSend.put(ref.getName(), ref); + } + } + } + + if (needToFindSymrefs) { + findSymrefs(adv, refsToSend); + } + + adv.send(refsToSend); + adv.end(); + } + + private void fetchV2() throws IOException { + options = new HashSet<>(); + + // Packs are always sent multiplexed and using full 64K + // lengths. + options.add(OPTION_SIDE_BAND_64K); + + // Depending on the requestValidator, #processHaveLines may + // require that advertised be set. Set it only in the required + // circumstances (to avoid a full ref lookup in the case that + // we don't need it). + if (requestValidator instanceof TipRequestValidator || + requestValidator instanceof ReachableCommitTipRequestValidator || + requestValidator instanceof AnyRequestValidator) { + advertised = Collections.emptySet(); + } else { + advertised = refIdSet(getAdvertisedOrDefaultRefs().values()); + } + + String line; + List<ObjectId> peerHas = new ArrayList<>(); + boolean doneReceived = false; + + // Currently, we do not support any capabilities, so the next + // line is DELIM. + if ((line = pckIn.readString()) != PacketLineIn.DELIM) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + + boolean includeTag = false; + boolean filterReceived = false; + while ((line = pckIn.readString()) != PacketLineIn.END) { + if (line.startsWith("want ")) { //$NON-NLS-1$ + wantIds.add(ObjectId.fromString(line.substring(5))); + } else if (line.startsWith("have ")) { //$NON-NLS-1$ + peerHas.add(ObjectId.fromString(line.substring(5))); + } else if (line.equals("done")) { //$NON-NLS-1$ + doneReceived = true; + } else if (line.equals(OPTION_THIN_PACK)) { + options.add(OPTION_THIN_PACK); + } else if (line.equals(OPTION_NO_PROGRESS)) { + options.add(OPTION_NO_PROGRESS); + } else if (line.equals(OPTION_INCLUDE_TAG)) { + options.add(OPTION_INCLUDE_TAG); + includeTag = true; + } else if (line.equals(OPTION_OFS_DELTA)) { + options.add(OPTION_OFS_DELTA); + } else if (line.startsWith("shallow ")) { //$NON-NLS-1$ + clientShallowCommits.add(ObjectId.fromString(line.substring(8))); + } else if (line.startsWith("deepen ")) { //$NON-NLS-1$ + depth = Integer.parseInt(line.substring(7)); + if (depth <= 0) { + throw new PackProtocolException( + MessageFormat.format(JGitText.get().invalidDepth, + Integer.valueOf(depth))); + } + if (shallowSince != 0) { + throw new PackProtocolException( + JGitText.get().deepenSinceWithDeepen); + } + if (shallowExcludeRefs != null) { + throw new PackProtocolException( + JGitText.get().deepenNotWithDeepen); + } + } else if (line.startsWith("deepen-not ")) { //$NON-NLS-1$ + List<String> exclude = shallowExcludeRefs; + if (exclude == null) { + exclude = shallowExcludeRefs = new ArrayList<>(); + } + exclude.add(line.substring(11)); + if (depth != 0) { + throw new PackProtocolException( + JGitText.get().deepenNotWithDeepen); + } + } else if (line.equals(OPTION_DEEPEN_RELATIVE)) { + options.add(OPTION_DEEPEN_RELATIVE); + } else if (line.startsWith("deepen-since ")) { //$NON-NLS-1$ + shallowSince = Integer.parseInt(line.substring(13)); + if (shallowSince <= 0) { + throw new PackProtocolException( + MessageFormat.format( + JGitText.get().invalidTimestamp, line)); + } + if (depth != 0) { + throw new PackProtocolException( + JGitText.get().deepenSinceWithDeepen); + } + } else if (transferConfig.isAllowFilter() + && line.startsWith(OPTION_FILTER + ' ')) { + if (filterReceived) { + throw new PackProtocolException(JGitText.get().tooManyFilters); + } + filterReceived = true; + parseFilter(line.substring(OPTION_FILTER.length() + 1)); + } else { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + } + rawOut.stopBuffering(); + + boolean sectionSent = false; + @Nullable List<ObjectId> shallowCommits = null; + List<ObjectId> unshallowCommits = new ArrayList<>(); + + if (!clientShallowCommits.isEmpty()) { + verifyClientShallow(); + } + if (depth != 0 || shallowSince != 0 || shallowExcludeRefs != null) { + shallowCommits = new ArrayList<ObjectId>(); + processShallow(shallowCommits, unshallowCommits, false); + } + if (!clientShallowCommits.isEmpty()) + walk.assumeShallow(clientShallowCommits); + + if (doneReceived) { + processHaveLines(peerHas, ObjectId.zeroId(), new PacketLineOut(NullOutputStream.INSTANCE)); + } else { + pckOut.writeString("acknowledgments\n"); //$NON-NLS-1$ + for (ObjectId id : peerHas) { + if (walk.getObjectReader().has(id)) { + pckOut.writeString("ACK " + id.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + processHaveLines(peerHas, ObjectId.zeroId(), new PacketLineOut(NullOutputStream.INSTANCE)); + if (okToGiveUp()) { + pckOut.writeString("ready\n"); //$NON-NLS-1$ + } else if (commonBase.isEmpty()) { + pckOut.writeString("NAK\n"); //$NON-NLS-1$ + } + sectionSent = true; + } + + if (doneReceived || okToGiveUp()) { + if (shallowCommits != null) { + if (sectionSent) + pckOut.writeDelim(); + pckOut.writeString("shallow-info\n"); //$NON-NLS-1$ + for (ObjectId o : shallowCommits) { + pckOut.writeString("shallow " + o.getName() + '\n'); //$NON-NLS-1$ + } + for (ObjectId o : unshallowCommits) { + pckOut.writeString("unshallow " + o.getName() + '\n'); //$NON-NLS-1$ + } + sectionSent = true; + } + + if (sectionSent) + pckOut.writeDelim(); + pckOut.writeString("packfile\n"); //$NON-NLS-1$ + sendPack(new PackStatistics.Accumulator(), + includeTag + ? db.getRefDatabase().getRefsByPrefix(R_TAGS) + : null, + unshallowCommits); + } + pckOut.end(); + } + + /* + * Returns true if this is the last command and we should tear down the + * connection. + */ + private boolean serveOneCommandV2() throws IOException { + String command; + try { + command = pckIn.readString(); + } catch (EOFException eof) { + /* EOF when awaiting command is fine */ + return true; + } + if (command == PacketLineIn.END) { + // A blank request is valid according + // to the protocol; do nothing in this + // case. + return true; + } + if (command.equals("command=" + COMMAND_LS_REFS)) { //$NON-NLS-1$ + lsRefsV2(); + return false; + } + if (command.equals("command=" + COMMAND_FETCH)) { //$NON-NLS-1$ + fetchV2(); + return false; + } + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unknownTransportCommand, command)); + } + + private List<String> getV2CapabilityAdvertisement() { + ArrayList<String> caps = new ArrayList<>(); + caps.add("version 2"); //$NON-NLS-1$ + caps.add(COMMAND_LS_REFS); + caps.add( + COMMAND_FETCH + '=' + + (transferConfig.isAllowFilter() ? OPTION_FILTER + ' ' : "") + //$NON-NLS-1$ + OPTION_SHALLOW); + return caps; + } + + private void serviceV2() throws IOException { + if (biDirectionalPipe) { + // Just like in service(), the capability advertisement + // is sent only if this is a bidirectional pipe. (If + // not, the client is expected to call + // sendAdvertisedRefs() on its own.) + for (String s : getV2CapabilityAdvertisement()) { + pckOut.writeString(s + "\n"); //$NON-NLS-1$ + } + pckOut.end(); + + while (!serveOneCommandV2()) { + // Repeat until an empty command or EOF. + } + return; + } + + try { + serveOneCommandV2(); + } finally { + while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) { + // Discard until EOF. + } + rawOut.stopBuffering(); + } } private static Set<ObjectId> refIdSet(Collection<Ref> refs) { @@ -874,7 +1170,23 @@ public class UploadPack { return ids; } - private void processShallow() throws IOException { + /* + * Determines what "shallow" and "unshallow" lines to send to the user. + * The information is written to shallowCommits (if not null) and + * unshallowCommits, and also written to #pckOut (if writeToPckOut is + * true). + */ + private void processShallow(@Nullable List<ObjectId> shallowCommits, + List<ObjectId> unshallowCommits, + boolean writeToPckOut) throws IOException { + if (options.contains(OPTION_DEEPEN_RELATIVE) || + shallowSince != 0 || + shallowExcludeRefs != null) { + // TODO(jonathantanmy): Implement deepen-relative, deepen-since, + // and deepen-not. + throw new UnsupportedOperationException(); + } + int walkDepth = depth - 1; try (DepthWalk.RevWalk depthWalk = new DepthWalk.RevWalk( walk.getObjectReader(), walkDepth)) { @@ -895,19 +1207,29 @@ public class UploadPack { // Commits at the boundary which aren't already shallow in // the client need to be marked as such if (c.getDepth() == walkDepth - && !clientShallowCommits.contains(c)) - pckOut.writeString("shallow " + o.name()); //$NON-NLS-1$ + && !clientShallowCommits.contains(c)) { + if (shallowCommits != null) { + shallowCommits.add(c.copy()); + } + if (writeToPckOut) { + pckOut.writeString("shallow " + o.name()); //$NON-NLS-1$ + } + } // Commits not on the boundary which are shallow in the client // need to become unshallowed if (c.getDepth() < walkDepth && clientShallowCommits.remove(c)) { unshallowCommits.add(c.copy()); - pckOut.writeString("unshallow " + c.name()); //$NON-NLS-1$ + if (writeToPckOut) { + pckOut.writeString("unshallow " + c.name()); //$NON-NLS-1$ + } } } } - pckOut.end(); + if (writeToPckOut) { + pckOut.end(); + } } private void verifyClientShallow() @@ -945,12 +1267,44 @@ public class UploadPack { * @param adv * the advertisement formatter. * @throws java.io.IOException - * the formatter failed to write an advertisement. + * the formatter failed to write an advertisement. * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException - * the hook denied advertisement. + * the hook denied advertisement. */ - public void sendAdvertisedRefs(final RefAdvertiser adv) throws IOException, + public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException { + sendAdvertisedRefs(adv, null); + } + + /** + * Generate an advertisement of available refs and capabilities. + * + * @param adv + * the advertisement formatter. + * @param serviceName + * if not null, also output "# service=serviceName" followed by a + * flush packet before the advertisement. This is required + * in v0 of the HTTP protocol, described in Git's + * Documentation/technical/http-protocol.txt. + * @throws java.io.IOException + * the formatter failed to write an advertisement. + * @throws org.eclipse.jgit.transport.ServiceMayNotContinueException + * the hook denied advertisement. + * @since 5.0 + */ + public void sendAdvertisedRefs(RefAdvertiser adv, + @Nullable String serviceName) throws IOException, + ServiceMayNotContinueException { + if (useProtocolV2()) { + // The equivalent in v2 is only the capabilities + // advertisement. + for (String s : getV2CapabilityAdvertisement()) { + adv.writeOne(s); + } + adv.end(); + return; + } + try { advertiseRefsHook.advertiseRefs(this); } catch (ServiceMayNotContinueException fail) { @@ -961,6 +1315,10 @@ public class UploadPack { throw fail; } + if (serviceName != null) { + adv.writeOne("# service=" + serviceName + '\n'); //$NON-NLS-1$ + adv.end(); + } adv.init(db); adv.advertiseCapability(OPTION_INCLUDE_TAG); adv.advertiseCapability(OPTION_MULTI_ACK_DETAILED); @@ -983,6 +1341,9 @@ public class UploadPack { || policy == null) adv.advertiseCapability(OPTION_ALLOW_REACHABLE_SHA1_IN_WANT); adv.advertiseCapability(OPTION_AGENT, UserAgent.get()); + if (transferConfig.isAllowFilter()) { + adv.advertiseCapability(OPTION_FILTER); + } adv.setDerefTags(true); Map<String, Ref> advertisedOrDefaultRefs = getAdvertisedOrDefaultRefs(); findSymrefs(adv, advertisedOrDefaultRefs); @@ -1021,8 +1382,36 @@ public class UploadPack { return msgOut; } + private void parseFilter(String arg) throws PackProtocolException { + if (arg.equals("blob:none")) { //$NON-NLS-1$ + filterBlobLimit = 0; + } else if (arg.startsWith("blob:limit=")) { //$NON-NLS-1$ + try { + filterBlobLimit = Long.parseLong( + arg.substring("blob:limit=".length())); //$NON-NLS-1$ + } catch (NumberFormatException e) { + throw new PackProtocolException( + MessageFormat.format(JGitText.get().invalidFilter, + arg)); + } + } + /* + * We must have (1) either "blob:none" or + * "blob:limit=" set (because we only support + * blob size limits for now), and (2) if the + * latter, then it must be nonnegative. Throw + * if (1) or (2) is not met. + */ + if (filterBlobLimit < 0) { + throw new PackProtocolException( + MessageFormat.format(JGitText.get().invalidFilter, + arg)); + } + } + private void recvWants() throws IOException { boolean isFirst = true; + boolean filterReceived = false; for (;;) { String line; try { @@ -1051,6 +1440,19 @@ public class UploadPack { continue; } + if (transferConfig.isAllowFilter() + && line.startsWith(OPTION_FILTER + " ")) { //$NON-NLS-1$ + String arg = line.substring(OPTION_FILTER.length() + 1); + + if (filterReceived) { + throw new PackProtocolException(JGitText.get().tooManyFilters); + } + filterReceived = true; + + parseFilter(arg); + continue; + } + if (!line.startsWith("want ") || line.length() < 45) //$NON-NLS-1$ throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedGot, "want", line)); //$NON-NLS-1$ @@ -1122,7 +1524,7 @@ public class UploadPack { } if (line == PacketLineIn.END) { - last = processHaveLines(peerHas, last); + last = processHaveLines(peerHas, last, pckOut); if (commonBase.isEmpty() || multiAck != MultiAck.OFF) pckOut.writeString("NAK\n"); //$NON-NLS-1$ if (noDone && sentReady) { @@ -1137,7 +1539,7 @@ public class UploadPack { peerHas.add(ObjectId.fromString(line.substring(5))); accumulator.haves++; } else if (line.equals("done")) { //$NON-NLS-1$ - last = processHaveLines(peerHas, last); + last = processHaveLines(peerHas, last, pckOut); if (commonBase.isEmpty()) pckOut.writeString("NAK\n"); //$NON-NLS-1$ @@ -1153,7 +1555,7 @@ public class UploadPack { } } - private ObjectId processHaveLines(List<ObjectId> peerHas, ObjectId last) + private ObjectId processHaveLines(List<ObjectId> peerHas, ObjectId last, PacketLineOut out) throws IOException { preUploadHook.onBeginNegotiateRound(this, wantIds, peerHas.size()); if (wantAll.isEmpty() && !wantIds.isEmpty()) @@ -1198,13 +1600,13 @@ public class UploadPack { switch (multiAck) { case OFF: if (commonBase.size() == 1) - pckOut.writeString("ACK " + obj.name() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ + out.writeString("ACK " + obj.name() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ break; case CONTINUE: - pckOut.writeString("ACK " + obj.name() + " continue\n"); //$NON-NLS-1$ //$NON-NLS-2$ + out.writeString("ACK " + obj.name() + " continue\n"); //$NON-NLS-1$ //$NON-NLS-2$ break; case DETAILED: - pckOut.writeString("ACK " + obj.name() + " common\n"); //$NON-NLS-1$ //$NON-NLS-2$ + out.writeString("ACK " + obj.name() + " common\n"); //$NON-NLS-1$ //$NON-NLS-2$ break; } } @@ -1230,10 +1632,10 @@ public class UploadPack { case OFF: break; case CONTINUE: - pckOut.writeString("ACK " + id.name() + " continue\n"); //$NON-NLS-1$ //$NON-NLS-2$ + out.writeString("ACK " + id.name() + " continue\n"); //$NON-NLS-1$ //$NON-NLS-2$ break; case DETAILED: - pckOut.writeString("ACK " + id.name() + " ready\n"); //$NON-NLS-1$ //$NON-NLS-2$ + out.writeString("ACK " + id.name() + " ready\n"); //$NON-NLS-1$ //$NON-NLS-2$ sentReady = true; break; } @@ -1245,7 +1647,7 @@ public class UploadPack { if (multiAck == MultiAck.DETAILED && !didOkToGiveUp && okToGiveUp()) { ObjectId id = peerHas.get(peerHas.size() - 1); - pckOut.writeString("ACK " + id.name() + " ready\n"); //$NON-NLS-1$ //$NON-NLS-2$ + out.writeString("ACK " + id.name() + " ready\n"); //$NON-NLS-1$ //$NON-NLS-2$ sentReady = true; } @@ -1340,7 +1742,7 @@ public class UploadPack { new ReachableCommitTipRequestValidator().checkWants(up, wants); else if (!wants.isEmpty()) { Set<ObjectId> refIds = - refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values()); + refIdSet(up.getRepository().getRefDatabase().getRefs()); for (ObjectId obj : wants) { if (!refIds.contains(obj)) throw new WantNotValidException(obj); @@ -1360,7 +1762,7 @@ public class UploadPack { public void checkWants(UploadPack up, List<ObjectId> wants) throws PackProtocolException, IOException { checkNotAdvertisedWants(up, wants, - refIdSet(up.getRepository().getRefDatabase().getRefs(ALL).values())); + refIdSet(up.getRepository().getRefDatabase().getRefs())); } } @@ -1443,7 +1845,7 @@ public class UploadPack { } } - private void addCommonBase(final RevObject o) { + private void addCommonBase(RevObject o) { if (!o.has(COMMON)) { o.add(COMMON); commonBase.add(o); @@ -1472,7 +1874,7 @@ public class UploadPack { } } - private boolean wantSatisfied(final RevObject want) throws IOException { + private boolean wantSatisfied(RevObject want) throws IOException { if (want.has(SATISFIED)) return true; @@ -1493,13 +1895,29 @@ public class UploadPack { return false; } - private void sendPack(PackStatistics.Accumulator accumulator) - throws IOException { + /** + * Send the requested objects to the client. + * + * @param accumulator + * where to write statistics about the content of the pack. + * @param allTags + * refs to search for annotated tags to include in the pack + * if the {@link #OPTION_INCLUDE_TAG} capability was + * requested. + * @param unshallowCommits + * shallow commits on the client that are now becoming + * unshallow + * @throws IOException + * if an error occured while generating or writing the pack. + */ + private void sendPack(PackStatistics.Accumulator accumulator, + @Nullable Collection<Ref> allTags, + List<ObjectId> unshallowCommits) throws IOException { final boolean sideband = options.contains(OPTION_SIDE_BAND) || options.contains(OPTION_SIDE_BAND_64K); if (sideband) { try { - sendPack(true, accumulator); + sendPack(true, accumulator, allTags, unshallowCommits); } catch (ServiceMayNotContinueException noPack) { // This was already reported on (below). throw noPack; @@ -1520,7 +1938,7 @@ public class UploadPack { throw err; } } else { - sendPack(false, accumulator); + sendPack(false, accumulator, allTags, unshallowCommits); } } @@ -1540,9 +1958,28 @@ public class UploadPack { } } - @SuppressWarnings("deprecation") + /** + * Send the requested objects to the client. + * + * @param sideband + * whether to wrap the pack in side-band pkt-lines, + * interleaved with progress messages and errors. + * @param accumulator + * where to write statistics about the content of the pack. + * @param allTags + * refs to search for annotated tags to include in the pack + * if the {@link #OPTION_INCLUDE_TAG} capability was + * requested. + * @param unshallowCommits + * shallow commits on the client that are now becoming + * unshallow + * @throws IOException + * if an error occured while generating or writing the pack. + */ private void sendPack(final boolean sideband, - PackStatistics.Accumulator accumulator) throws IOException { + PackStatistics.Accumulator accumulator, + @Nullable Collection<Ref> allTags, + List<ObjectId> unshallowCommits) throws IOException { ProgressMonitor pm = NullProgressMonitor.INSTANCE; OutputStream packOut = rawOut; @@ -1583,11 +2020,18 @@ public class UploadPack { PackConfig cfg = packConfig; if (cfg == null) cfg = new PackConfig(db); + @SuppressWarnings("resource") // PackWriter is referenced in the finally + // block, and is closed there final PackWriter pw = new PackWriter(cfg, walk.getObjectReader(), accumulator); try { pw.setIndexDisabled(true); - pw.setUseCachedPacks(true); + if (filterBlobLimit >= 0) { + pw.setFilterBlobLimit(filterBlobLimit); + pw.setUseCachedPacks(false); + } else { + pw.setUseCachedPacks(true); + } pw.setUseBitmaps(depth == 0 && clientShallowCommits.isEmpty()); pw.setClientShallowCommits(clientShallowCommits); pw.setReuseDeltaCommits(true); @@ -1595,6 +2039,8 @@ public class UploadPack { pw.setThin(options.contains(OPTION_THIN_PACK)); pw.setReuseValidatingObjects(false); + // Objects named directly by references go at the beginning + // of the pack. if (commonBase.isEmpty() && refs != null) { Set<ObjectId> tagTargets = new HashSet<>(); for (Ref ref : refs.values()) { @@ -1625,8 +2071,8 @@ public class UploadPack { rw = ow; } - if (options.contains(OPTION_INCLUDE_TAG) && refs != null) { - for (Ref ref : refs.values()) { + if (options.contains(OPTION_INCLUDE_TAG) && allTags != null) { + for (Ref ref : allTags) { ObjectId objectId = ref.getObjectId(); if (objectId == null) { // skip unborn branch @@ -1644,7 +2090,7 @@ public class UploadPack { } if (!ref.isPeeled()) - ref = db.peel(ref); + ref = db.getRefDatabase().peel(ref); ObjectId peeledId = ref.getPeeledObjectId(); objectId = ref.getObjectId(); @@ -1669,7 +2115,6 @@ public class UploadPack { statistics = pw.getStatistics(); if (statistics != null) { postUploadHook.onPostUpload(statistics); - logger.onPackStatistics(new PackWriter.Statistics(statistics)); } pw.close(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java deleted file mode 100644 index 611418d22c..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2011, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.transport; - -import org.eclipse.jgit.internal.storage.pack.PackWriter; - -/** - * Logs activity that occurred within - * {@link org.eclipse.jgit.transport.UploadPack}. - * <p> - * Implementors of the interface are responsible for associating the current - * thread to a particular connection, if they need to also include connection - * information. One method is to use a {@link java.lang.ThreadLocal} to remember - * the connection information before invoking UploadPack. - * - * @deprecated use {@link org.eclipse.jgit.transport.PostUploadHook} instead - */ -@Deprecated -public interface UploadPackLogger { // TODO remove in JGit 5.0 - /** A simple no-op logger. */ - public static final UploadPackLogger NULL = new UploadPackLogger() { - @Override - public void onPackStatistics(PackWriter.Statistics stats) { - // Do nothing. - } - }; - - /** - * Notice to the logger after a pack has been sent. - * - * @param stats - * the statistics after sending a pack to the client. - * @since 3.0 - */ - public void onPackStatistics(PackWriter.Statistics stats); -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLoggerChain.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLoggerChain.java deleted file mode 100644 index 9e14672dc5..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLoggerChain.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (C) 2011, Google Inc. - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.transport; - -import java.util.List; - -import org.eclipse.jgit.internal.storage.pack.PackWriter; - -/** - * UploadPackLogger that delegates to a list of other loggers. - * <p> - * loggers are run in the order passed to the constructor. - * - * @deprecated Use {@link org.eclipse.jgit.transport.PostUploadHookChain} - * instead. - */ -@Deprecated -public class UploadPackLoggerChain implements UploadPackLogger { - private final UploadPackLogger[] loggers; - private final int count; - - /** - * Create a new logger chaining the given loggers together. - * - * @param loggers - * loggers to execute, in order. - * @return a new logger chain of the given loggers. - */ - public static UploadPackLogger newChain( - List<? extends UploadPackLogger> loggers) { - UploadPackLogger[] newLoggers = new UploadPackLogger[loggers.size()]; - int i = 0; - for (UploadPackLogger logger : loggers) - if (logger != UploadPackLogger.NULL) - newLoggers[i++] = logger; - if (i == 0) - return UploadPackLogger.NULL; - else if (i == 1) - return newLoggers[0]; - else - return new UploadPackLoggerChain(newLoggers, i); - } - - /** {@inheritDoc} */ - @Override - public void onPackStatistics(PackWriter.Statistics stats) { - for (int i = 0; i < count; i++) - loggers[i].onPackStatistics(stats); - } - - private UploadPackLoggerChain(UploadPackLogger[] loggers, int count) { - this.loggers = loggers; - this.count = count; - } -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java index 615e46b982..b4248ee3fc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkEncryption.java @@ -128,7 +128,7 @@ abstract class WalkEncryption { throw new IOException(MessageFormat.format(JGitText.get().unsupportedEncryptionAlgorithm, v)); } - IOException error(final Throwable why) { + IOException error(Throwable why) { return new IOException(MessageFormat .format(JGitText.get().encryptionError, why.getMessage()), why); @@ -141,7 +141,7 @@ abstract class WalkEncryption { } @Override - void validate(final HttpURLConnection u, final String prefix) + void validate(HttpURLConnection u, String prefix) throws IOException { validateImpl(u, prefix, "", ""); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -240,19 +240,19 @@ abstract class WalkEncryption { } @Override - void request(final HttpURLConnection u, final String prefix) { + void request(HttpURLConnection u, String prefix) { u.setRequestProperty(prefix + JETS3T_CRYPTO_VER, CRYPTO_VER); u.setRequestProperty(prefix + JETS3T_CRYPTO_ALG, cryptoAlg); } @Override - void validate(final HttpURLConnection u, final String prefix) + void validate(HttpURLConnection u, String prefix) throws IOException { validateImpl(u, prefix, CRYPTO_VER, cryptoAlg); } @Override - OutputStream encrypt(final OutputStream os) throws IOException { + OutputStream encrypt(OutputStream os) throws IOException { try { final Cipher cipher = InsecureCipherFactory.create(cryptoAlg); cipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec); @@ -263,7 +263,7 @@ abstract class WalkEncryption { } @Override - InputStream decrypt(final InputStream in) throws IOException { + InputStream decrypt(InputStream in) throws IOException { try { final Cipher cipher = InsecureCipherFactory.create(cryptoAlg); cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java index 6708964d5e..9307914444 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java @@ -44,8 +44,6 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.RefDatabase.ALL; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -58,7 +56,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; -import java.util.Map; import java.util.Set; import org.eclipse.jgit.errors.CompoundException; @@ -190,7 +187,7 @@ class WalkFetchConnection extends BaseFetchConnection { /** Inserter to read objects from {@link #local}. */ private final ObjectReader reader; - WalkFetchConnection(final WalkTransport t, final WalkRemoteObjectDatabase w) { + WalkFetchConnection(WalkTransport t, WalkRemoteObjectDatabase w) { Transport wt = (Transport)t; local = wt.local; objCheck = wt.getObjectChecker(); @@ -259,7 +256,7 @@ class WalkFetchConnection extends BaseFetchConnection { /** {@inheritDoc} */ @Override - public void setPackLockMessage(final String message) { + public void setPackLockMessage(String message) { lockMessage = message; } @@ -268,18 +265,18 @@ class WalkFetchConnection extends BaseFetchConnection { public void close() { inserter.close(); reader.close(); - for (final RemotePack p : unfetchedPacks) { + for (RemotePack p : unfetchedPacks) { if (p.tmpIdx != null) p.tmpIdx.delete(); } - for (final WalkRemoteObjectDatabase r : remotes) + for (WalkRemoteObjectDatabase r : remotes) r.close(); } - private void queueWants(final Collection<Ref> want) + private void queueWants(Collection<Ref> want) throws TransportException { final HashSet<ObjectId> inWorkQueue = new HashSet<>(); - for (final Ref r : want) { + for (Ref r : want) { final ObjectId id = r.getObjectId(); if (id == null) { throw new NullPointerException(MessageFormat.format( @@ -302,7 +299,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private void process(final ObjectId id) throws TransportException { + private void process(ObjectId id) throws TransportException { final RevObject obj; try { if (id instanceof RevObject) { @@ -342,7 +339,7 @@ class WalkFetchConnection extends BaseFetchConnection { fetchErrors.remove(id); } - private void processBlob(final RevObject obj) throws TransportException { + private void processBlob(RevObject obj) throws TransportException { try { if (reader.has(obj, Constants.OBJ_BLOB)) obj.add(COMPLETE); @@ -356,7 +353,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private void processTree(final RevObject obj) throws TransportException { + private void processTree(RevObject obj) throws TransportException { try { treeWalk.reset(obj); while (treeWalk.next()) { @@ -384,22 +381,22 @@ class WalkFetchConnection extends BaseFetchConnection { obj.add(COMPLETE); } - private void processCommit(final RevObject obj) throws TransportException { + private void processCommit(RevObject obj) throws TransportException { final RevCommit commit = (RevCommit) obj; markLocalCommitsComplete(commit.getCommitTime()); needs(commit.getTree()); - for (final RevCommit p : commit.getParents()) + for (RevCommit p : commit.getParents()) needs(p); obj.add(COMPLETE); } - private void processTag(final RevObject obj) { + private void processTag(RevObject obj) { final RevTag tag = (RevTag) obj; needs(tag.getObject()); obj.add(COMPLETE); } - private void needs(final RevObject obj) { + private void needs(RevObject obj) { if (obj.has(COMPLETE)) return; if (!obj.has(IN_WORK_QUEUE)) { @@ -408,7 +405,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private void downloadObject(final ProgressMonitor pm, final AnyObjectId id) + private void downloadObject(ProgressMonitor pm, AnyObjectId id) throws TransportException { if (alreadyHave(id)) return; @@ -462,7 +459,7 @@ class WalkFetchConnection extends BaseFetchConnection { if (packNameList == null || packNameList.isEmpty()) continue; - for (final String packName : packNameList) { + for (String packName : packNameList) { if (packsConsidered.add(packName)) unfetchedPacks.add(new RemotePack(wrr, packName)); } @@ -474,7 +471,7 @@ class WalkFetchConnection extends BaseFetchConnection { // Collection<WalkRemoteObjectDatabase> al = expandOneAlternate(id, pm); if (al != null && !al.isEmpty()) { - for (final WalkRemoteObjectDatabase alt : al) { + for (WalkRemoteObjectDatabase alt : al) { remotes.add(alt); noPacksYet.add(alt); noAlternatesYet.add(alt); @@ -498,7 +495,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private boolean alreadyHave(final AnyObjectId id) throws TransportException { + private boolean alreadyHave(AnyObjectId id) throws TransportException { try { return reader.has(id); } catch (IOException error) { @@ -689,21 +686,21 @@ class WalkFetchConnection extends BaseFetchConnection { return null; } - private void markLocalRefsComplete(final Set<ObjectId> have) throws TransportException { - Map<String, Ref> refs; + private void markLocalRefsComplete(Set<ObjectId> have) throws TransportException { + List<Ref> refs; try { - refs = local.getRefDatabase().getRefs(ALL); + refs = local.getRefDatabase().getRefs(); } catch (IOException e) { throw new TransportException(e.getMessage(), e); } - for (final Ref r : refs.values()) { + for (Ref r : refs) { try { markLocalObjComplete(revWalk.parseAny(r.getObjectId())); } catch (IOException readError) { throw new TransportException(MessageFormat.format(JGitText.get().localRefIsMissingObjects, r.getName()), readError); } } - for (final ObjectId id : have) { + for (ObjectId id : have) { try { markLocalObjComplete(revWalk.parseAny(id)); } catch (IOException readError) { @@ -732,7 +729,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private void markLocalCommitsComplete(final int until) + private void markLocalCommitsComplete(int until) throws TransportException { try { for (;;) { @@ -742,7 +739,7 @@ class WalkFetchConnection extends BaseFetchConnection { localCommitQueue.next(); markTreeComplete(c.getTree()); - for (final RevCommit p : c.getParents()) + for (RevCommit p : c.getParents()) pushLocalCommit(p); } } catch (IOException err) { @@ -750,7 +747,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private void pushLocalCommit(final RevCommit p) + private void pushLocalCommit(RevCommit p) throws MissingObjectException, IOException { if (p.has(LOCALLY_SEEN)) return; @@ -761,7 +758,7 @@ class WalkFetchConnection extends BaseFetchConnection { localCommitQueue.add(p); } - private void markTreeComplete(final RevTree tree) throws IOException { + private void markTreeComplete(RevTree tree) throws IOException { if (tree.has(COMPLETE)) return; tree.add(COMPLETE); @@ -795,7 +792,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - private void recordError(final AnyObjectId id, final Throwable what) { + private void recordError(AnyObjectId id, Throwable what) { final ObjectId objId = id.copy(); List<Throwable> errors = fetchErrors.get(objId); if (errors == null) { @@ -816,7 +813,7 @@ class WalkFetchConnection extends BaseFetchConnection { PackIndex index; - RemotePack(final WalkRemoteObjectDatabase c, final String pn) { + RemotePack(WalkRemoteObjectDatabase c, String pn) { connection = c; packName = pn; idxName = packName.substring(0, packName.length() - 5) + ".idx"; //$NON-NLS-1$ @@ -834,7 +831,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - void openIndex(final ProgressMonitor pm) throws IOException { + void openIndex(ProgressMonitor pm) throws IOException { if (index != null) return; if (tmpIdx == null) @@ -853,17 +850,12 @@ class WalkFetchConnection extends BaseFetchConnection { pm.beginTask("Get " + idxName.substring(0, 12) + "..idx", //$NON-NLS-1$ //$NON-NLS-2$ s.length < 0 ? ProgressMonitor.UNKNOWN : (int) (s.length / 1024)); - try { - final FileOutputStream fos = new FileOutputStream(tmpIdx); - try { - final byte[] buf = new byte[2048]; - int cnt; - while (!pm.isCancelled() && (cnt = s.in.read(buf)) >= 0) { - fos.write(buf, 0, cnt); - pm.update(cnt / 1024); - } - } finally { - fos.close(); + try (FileOutputStream fos = new FileOutputStream(tmpIdx)) { + final byte[] buf = new byte[2048]; + int cnt; + while (!pm.isCancelled() && (cnt = s.in.read(buf)) >= 0) { + fos.write(buf, 0, cnt); + pm.update(cnt / 1024); } } catch (IOException err) { FileUtils.delete(tmpIdx); @@ -886,7 +878,7 @@ class WalkFetchConnection extends BaseFetchConnection { } } - void downloadPack(final ProgressMonitor monitor) throws IOException { + void downloadPack(ProgressMonitor monitor) throws IOException { String name = "pack/" + packName; //$NON-NLS-1$ WalkRemoteObjectDatabase.FileStream s = connection.open(name); try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java index cf50c51d5d..4c754252a3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java @@ -157,7 +157,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { // ref using the directory name being created. // final List<RemoteRefUpdate> updates = new ArrayList<>(); - for (final RemoteRefUpdate u : refUpdates.values()) { + for (RemoteRefUpdate u : refUpdates.values()) { final String n = u.getRemoteName(); if (!n.startsWith("refs/") || !Repository.isValidRefName(n)) { //$NON-NLS-1$ u.setStatus(Status.REJECTED_OTHER_REASON); @@ -177,7 +177,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { // if (!updates.isEmpty()) sendpack(updates, monitor); - for (final RemoteRefUpdate u : updates) + for (RemoteRefUpdate u : updates) updateCommand(u); // Is this a new repository? If so we should create additional @@ -196,10 +196,10 @@ class WalkPushConnection extends BaseConnection implements PushConnection { if (!packedRefUpdates.isEmpty()) { try { refWriter.writePackedRefs(); - for (final RemoteRefUpdate u : packedRefUpdates) + for (RemoteRefUpdate u : packedRefUpdates) u.setStatus(Status.OK); } catch (IOException err) { - for (final RemoteRefUpdate u : packedRefUpdates) { + for (RemoteRefUpdate u : packedRefUpdates) { u.setStatus(Status.REJECTED_OTHER_REASON); u.setMessage(err.getMessage()); } @@ -225,14 +225,14 @@ class WalkPushConnection extends BaseConnection implements PushConnection { String pathPack = null; String pathIdx = null; - try (final PackWriter writer = new PackWriter(transport.getPackConfig(), + try (PackWriter writer = new PackWriter(transport.getPackConfig(), local.newObjectReader())) { final Set<ObjectId> need = new HashSet<>(); final Set<ObjectId> have = new HashSet<>(); - for (final RemoteRefUpdate r : updates) + for (RemoteRefUpdate r : updates) need.add(r.getNewObjectId()); - for (final Ref r : getRefs()) { + for (Ref r : getRefs()) { have.add(r.getObjectId()); if (r.getPeeledObjectId() != null) have.add(r.getPeeledObjectId()); @@ -247,7 +247,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { return; packNames = new LinkedHashMap<>(); - for (final String n : dest.getPackNames()) + for (String n : dest.getPackNames()) packNames.put(n, n); final String base = "pack-" + writer.computeName().name(); //$NON-NLS-1$ @@ -295,7 +295,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { } } - private void safeDelete(final String path) { + private void safeDelete(String path) { if (path != null) { try { dest.deleteFile(path); @@ -307,7 +307,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { } } - private void deleteCommand(final RemoteRefUpdate u) { + private void deleteCommand(RemoteRefUpdate u) { final Ref r = newRefs.remove(u.getRemoteName()); if (r == null) { // Already gone. @@ -337,7 +337,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { } } - private void updateCommand(final RemoteRefUpdate u) { + private void updateCommand(RemoteRefUpdate u) { try { dest.writeRef(u.getRemoteName(), u.getNewObjectId()); newRefs.put(u.getRemoteName(), new ObjectIdRef.Unpeeled( @@ -354,7 +354,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { && packNames.isEmpty(); } - private void createNewRepository(final List<RemoteRefUpdate> updates) + private void createNewRepository(List<RemoteRefUpdate> updates) throws TransportException { try { final String ref = "ref: " + pickHEAD(updates) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ @@ -374,12 +374,12 @@ class WalkPushConnection extends BaseConnection implements PushConnection { } } - private static String pickHEAD(final List<RemoteRefUpdate> updates) { + private static String pickHEAD(List<RemoteRefUpdate> updates) { // Try to use master if the user is pushing that, it is the // default branch and is likely what they want to remain as // the default on the new remote. // - for (final RemoteRefUpdate u : updates) { + for (RemoteRefUpdate u : updates) { final String n = u.getRemoteName(); if (n.equals(Constants.R_HEADS + Constants.MASTER)) return n; @@ -388,7 +388,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { // Pick any branch, under the assumption the user pushed only // one to the remote side. // - for (final RemoteRefUpdate u : updates) { + for (RemoteRefUpdate u : updates) { final String n = u.getRemoteName(); if (n.startsWith(Constants.R_HEADS)) return n; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java index 965be509cd..aa71c9445a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java @@ -202,7 +202,7 @@ abstract class WalkRemoteObjectDatabase { * @throws IOException * deletion is not supported, or deletion failed. */ - void deleteFile(final String path) throws IOException { + void deleteFile(String path) throws IOException { throw new IOException(MessageFormat.format(JGitText.get().deletingNotSupported, path)); } @@ -263,7 +263,7 @@ abstract class WalkRemoteObjectDatabase { * writing is not supported, or attempting to write the file * failed, possibly due to permissions or remote disk full, etc. */ - void writeFile(final String path, final byte[] data) throws IOException { + void writeFile(String path, byte[] data) throws IOException { try (OutputStream os = writeFile(path, null, null)) { os.write(data); } @@ -278,7 +278,7 @@ abstract class WalkRemoteObjectDatabase { * @throws IOException * deletion is not supported, or deletion failed. */ - void deleteRef(final String name) throws IOException { + void deleteRef(String name) throws IOException { deleteFile(ROOT_DIR + name); } @@ -291,7 +291,7 @@ abstract class WalkRemoteObjectDatabase { * @throws IOException * deletion is not supported, or deletion failed. */ - void deleteRefLog(final String name) throws IOException { + void deleteRefLog(String name) throws IOException { deleteFile(ROOT_DIR + Constants.LOGS + "/" + name); //$NON-NLS-1$ } @@ -309,7 +309,7 @@ abstract class WalkRemoteObjectDatabase { * writing is not supported, or attempting to write the file * failed, possibly due to permissions or remote disk full, etc. */ - void writeRef(final String name, final ObjectId value) throws IOException { + void writeRef(String name, ObjectId value) throws IOException { final ByteArrayOutputStream b; b = new ByteArrayOutputStream(Constants.OBJECT_ID_STRING_LENGTH + 1); @@ -333,9 +333,9 @@ abstract class WalkRemoteObjectDatabase { * writing is not supported, or attempting to write the file * failed, possibly due to permissions or remote disk full, etc. */ - void writeInfoPacks(final Collection<String> packNames) throws IOException { + void writeInfoPacks(Collection<String> packNames) throws IOException { final StringBuilder w = new StringBuilder(); - for (final String n : packNames) { + for (String n : packNames) { w.append("P "); //$NON-NLS-1$ w.append(n); w.append('\n'); @@ -361,7 +361,7 @@ abstract class WalkRemoteObjectDatabase { * exists, or after it was determined to exist but before the * stream could be created. */ - BufferedReader openReader(final String path) throws IOException { + BufferedReader openReader(String path) throws IOException { final InputStream is = open(path).in; return new BufferedReader(new InputStreamReader(is, Constants.CHARSET)); } @@ -414,7 +414,7 @@ abstract class WalkRemoteObjectDatabase { * @throws org.eclipse.jgit.errors.TransportException * an error occurred reading from the packed refs file. */ - protected void readPackedRefs(final Map<String, Ref> avail) + protected void readPackedRefs(Map<String, Ref> avail) throws TransportException { try (BufferedReader br = openReader(ROOT_DIR + Constants.PACKED_REFS)) { readPackedRefsImpl(avail, br); @@ -475,7 +475,7 @@ abstract class WalkRemoteObjectDatabase { * stream containing the file data. This stream will be * closed by the caller when reading is complete. */ - FileStream(final InputStream i) { + FileStream(InputStream i) { in = i; length = -1; } @@ -490,7 +490,7 @@ abstract class WalkRemoteObjectDatabase { * total number of bytes available for reading through * <code>i</code>. */ - FileStream(final InputStream i, final long n) { + FileStream(InputStream i, long n) { in = i; length = n; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java index 16a6f4ab73..60acd2f8ae 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/resolver/FileResolver.java @@ -87,7 +87,7 @@ public class FileResolver<C> implements RepositoryResolver<C> { * if true, exports all repositories, ignoring the check for the * {@code git-daemon-export-ok} files. */ - public FileResolver(final File basePath, final boolean exportAll) { + public FileResolver(File basePath, boolean exportAll) { this(); exportDirectory(basePath); setExportAll(exportAll); @@ -95,7 +95,7 @@ public class FileResolver<C> implements RepositoryResolver<C> { /** {@inheritDoc} */ @Override - public Repository open(final C req, final String name) + public Repository open(C req, String name) throws RepositoryNotFoundException, ServiceNotEnabledException { if (isUnreasonableName(name)) throw new RepositoryNotFoundException(name); @@ -175,7 +175,7 @@ public class FileResolver<C> implements RepositoryResolver<C> { * * @param export a boolean. */ - public void setExportAll(final boolean export) { + public void setExportAll(boolean export) { exportAll = export; } @@ -202,7 +202,7 @@ public class FileResolver<C> implements RepositoryResolver<C> { * git repository, but any directory below it which has a file * named <code>git-daemon-export-ok</code> will be published. */ - public void exportDirectory(final File dir) { + public void exportDirectory(File dir) { exportBase.add(dir); } @@ -240,7 +240,7 @@ public class FileResolver<C> implements RepositoryResolver<C> { return name + Constants.DOT_GIT_EXT; } - private static boolean isUnreasonableName(final String name) { + private static boolean isUnreasonableName(String name) { if (name.length() == 0) return true; // no empty paths diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java index a7900f0b67..470ed02841 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java @@ -176,7 +176,7 @@ public abstract class AbstractTreeIterator { * root of the repository. A trailing slash ('/') is * automatically appended if the prefix does not end in '/'. */ - protected AbstractTreeIterator(final String prefix) { + protected AbstractTreeIterator(String prefix) { parent = null; if (prefix != null && prefix.length() > 0) { @@ -210,7 +210,7 @@ public abstract class AbstractTreeIterator { * root of the repository. A trailing slash ('/') is * automatically appended if the prefix does not end in '/'. */ - protected AbstractTreeIterator(final byte[] prefix) { + protected AbstractTreeIterator(byte[] prefix) { parent = null; if (prefix != null && prefix.length > 0) { @@ -232,7 +232,7 @@ public abstract class AbstractTreeIterator { * @param p * parent tree iterator. */ - protected AbstractTreeIterator(final AbstractTreeIterator p) { + protected AbstractTreeIterator(AbstractTreeIterator p) { parent = p; path = p.path; pathOffset = p.pathLen + 1; @@ -275,7 +275,7 @@ public abstract class AbstractTreeIterator { * number of live bytes in the path buffer. This many bytes will * be moved into the larger buffer. */ - protected void growPath(final int len) { + protected void growPath(int len) { setPathCapacity(path.length << 1, len); } @@ -287,7 +287,7 @@ public abstract class AbstractTreeIterator { * @param len * the amount of live bytes in path buffer */ - protected void ensurePathCapacity(final int capacity, final int len) { + protected void ensurePathCapacity(int capacity, int len) { if (path.length >= capacity) return; final byte[] o = path; @@ -322,11 +322,11 @@ public abstract class AbstractTreeIterator { * @return -1 if this entry sorts first; 0 if the entries are equal; 1 if * p's entry sorts first. */ - public int pathCompare(final AbstractTreeIterator p) { + public int pathCompare(AbstractTreeIterator p) { return pathCompare(p, p.mode); } - int pathCompare(final AbstractTreeIterator p, final int pMode) { + int pathCompare(AbstractTreeIterator p, int pMode) { // Its common when we are a subtree for both parents to match; // when this happens everything in path[0..cPos] is known to // be equal and does not require evaluation again. @@ -420,7 +420,7 @@ public abstract class AbstractTreeIterator { * the other iterator to test against. * @return true if both iterators have the same object id; false otherwise. */ - public boolean idEqual(final AbstractTreeIterator otherIterator) { + public boolean idEqual(AbstractTreeIterator otherIterator) { return ObjectId.equals(idBuffer(), idOffset(), otherIterator.idBuffer(), otherIterator.idOffset()); } @@ -447,7 +447,7 @@ public abstract class AbstractTreeIterator { * @param out * buffer to copy the object id into. */ - public void getEntryObjectId(final MutableObjectId out) { + public void getEntryObjectId(MutableObjectId out) { out.fromRaw(idBuffer(), idOffset()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java index 71113a661a..019968875d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java @@ -119,7 +119,7 @@ public class CanonicalTreeParser extends AbstractTreeIterator { reset(reader, treeId); } - private CanonicalTreeParser(final CanonicalTreeParser p) { + private CanonicalTreeParser(CanonicalTreeParser p) { super(p); } @@ -140,7 +140,7 @@ public class CanonicalTreeParser extends AbstractTreeIterator { * @param treeData * the raw tree content. */ - public void reset(final byte[] treeData) { + public void reset(byte[] treeData) { attributesNode = null; raw = treeData; prevPtr = -1; @@ -219,7 +219,7 @@ public class CanonicalTreeParser extends AbstractTreeIterator { * @throws java.io.IOException * a loose object or pack file could not be read. */ - public void reset(final ObjectReader reader, final AnyObjectId id) + public void reset(ObjectReader reader, AnyObjectId id) throws IncorrectObjectTypeException, IOException { reset(reader.open(id, OBJ_TREE).getCachedBytes()); } @@ -262,7 +262,7 @@ public class CanonicalTreeParser extends AbstractTreeIterator { /** {@inheritDoc} */ @Override - public CanonicalTreeParser createSubtreeIterator(final ObjectReader reader) + public CanonicalTreeParser createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException { return createSubtreeIterator(reader, new MutableObjectId()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java index 596d3d0835..f5d45c7687 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java @@ -63,7 +63,7 @@ public class EmptyTreeIterator extends AbstractTreeIterator { // Create a root empty tree. } - EmptyTreeIterator(final AbstractTreeIterator p) { + EmptyTreeIterator(AbstractTreeIterator p) { super(p); pathLen = pathOffset; } @@ -92,7 +92,7 @@ public class EmptyTreeIterator extends AbstractTreeIterator { /** {@inheritDoc} */ @Override - public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) + public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException { return new EmptyTreeIterator(this); } @@ -141,13 +141,13 @@ public class EmptyTreeIterator extends AbstractTreeIterator { /** {@inheritDoc} */ @Override - public void next(final int delta) throws CorruptObjectException { + public void next(int delta) throws CorruptObjectException { // Do nothing. } /** {@inheritDoc} */ @Override - public void back(final int delta) throws CorruptObjectException { + public void back(int delta) throws CorruptObjectException { // Do nothing. } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java index 8df764d293..24b9ac086e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java @@ -52,6 +52,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; @@ -67,6 +68,7 @@ import org.eclipse.jgit.util.FS; * {@link org.eclipse.jgit.treewalk.TreeWalk}. */ public class FileTreeIterator extends WorkingTreeIterator { + /** * the starting directory of this Iterator. All entries are located directly * in this directory. @@ -130,7 +132,7 @@ public class FileTreeIterator extends WorkingTreeIterator { * @param options * working tree options to be used */ - public FileTreeIterator(final File root, FS fs, WorkingTreeOptions options) { + public FileTreeIterator(File root, FS fs, WorkingTreeOptions options) { this(root, fs, options, DefaultFileModeStrategy.INSTANCE); } @@ -171,27 +173,6 @@ public class FileTreeIterator extends WorkingTreeIterator { * the file system abstraction which will be necessary to perform * certain file system operations. * @since 4.3 - * @deprecated use {@link #FileTreeIterator(FileTreeIterator, File, FS)} - * instead. - */ - @Deprecated - protected FileTreeIterator(final WorkingTreeIterator p, final File root, - FS fs) { - this(p, root, fs, DefaultFileModeStrategy.INSTANCE); - } - - /** - * Create a new iterator to traverse a subdirectory. - * - * @param p - * the parent iterator we were created from. - * @param root - * the subdirectory. This should be a directory contained within - * the parent directory. - * @param fs - * the file system abstraction which will be necessary to perform - * certain file system operations. - * @since 4.3 */ protected FileTreeIterator(final FileTreeIterator p, final File root, FS fs) { @@ -226,19 +207,39 @@ public class FileTreeIterator extends WorkingTreeIterator { /** {@inheritDoc} */ @Override - public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) + public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException { - return new FileTreeIterator(this, ((FileEntry) current()).getFile(), fs, fileModeStrategy); + if (!walksIgnoredDirectories() && isEntryIgnored()) { + DirCacheIterator iterator = getDirCacheIterator(); + if (iterator == null) { + return new EmptyTreeIterator(this); + } + // Only enter if we have an associated DirCacheIterator that is + // at the same entry (which indicates there is some already + // tracked file underneath this directory). Otherwise the + // directory is indeed ignored and can be skipped entirely. + } + return enterSubtree(); + } + + + /** + * Create a new iterator for the current entry's subtree. + * <p> + * The parent reference of the iterator must be <code>this</code>, otherwise + * the caller would not be able to exit out of the subtree iterator + * correctly and return to continue walking <code>this</code>. + * + * @return a new iterator that walks over the current subtree. + * @since 5.0 + */ + protected AbstractTreeIterator enterSubtree() { + return new FileTreeIterator(this, ((FileEntry) current()).getFile(), fs, + fileModeStrategy); } private Entry[] entries() { - final File[] all = directory.listFiles(); - if (all == null) - return EOF; - final Entry[] r = new Entry[all.length]; - for (int i = 0; i < r.length; i++) - r[i] = new FileEntry(all[i], fs, fileModeStrategy); - return r; + return fs.list(directory, fileModeStrategy); } /** @@ -267,7 +268,7 @@ public class FileTreeIterator extends WorkingTreeIterator { * * @since 4.3 */ - static public class DefaultFileModeStrategy implements FileModeStrategy { + public static class DefaultFileModeStrategy implements FileModeStrategy { /** * a singleton instance of the default FileModeStrategy */ @@ -300,7 +301,7 @@ public class FileTreeIterator extends WorkingTreeIterator { * * @since 4.3 */ - static public class NoGitlinksStrategy implements FileModeStrategy { + public static class NoGitlinksStrategy implements FileModeStrategy { /** * a singleton instance of the default FileModeStrategy @@ -325,7 +326,7 @@ public class FileTreeIterator extends WorkingTreeIterator { /** * Wrapper for a standard Java IO file */ - static public class FileEntry extends Entry { + public static class FileEntry extends Entry { private final FileMode mode; private FS.Attributes attributes; @@ -364,6 +365,29 @@ public class FileTreeIterator extends WorkingTreeIterator { mode = fileModeStrategy.getMode(f, attributes); } + /** + * Create a new file entry given the specified FileModeStrategy + * + * @param f + * file + * @param fs + * file system + * @param attributes + * of the file + * @param fileModeStrategy + * the strategy to use when determining the FileMode of a + * file; controls gitlinks etc. + * + * @since 5.0 + */ + public FileEntry(File f, FS fs, FS.Attributes attributes, + FileModeStrategy fileModeStrategy) { + this.fs = fs; + this.attributes = attributes; + f = fs.normalize(f); + mode = fileModeStrategy.getMode(f, attributes); + } + @Override public FileMode getMode() { return mode; @@ -386,12 +410,12 @@ public class FileTreeIterator extends WorkingTreeIterator { @Override public InputStream openInputStream() throws IOException { - if (fs.isSymLink(getFile())) + if (attributes.isSymbolicLink()) { return new ByteArrayInputStream(fs.readSymLink(getFile()) - .getBytes( - Constants.CHARACTER_ENCODING)); - else + .getBytes(Constants.CHARACTER_ENCODING)); + } else { return new FileInputStream(getFile()); + } } /** @@ -426,7 +450,7 @@ public class FileTreeIterator extends WorkingTreeIterator { /** {@inheritDoc} */ @Override - protected byte[] idSubmodule(final Entry e) { + protected byte[] idSubmodule(Entry e) { return idSubmodule(getDirectory(), e); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java index 5560f7750c..61b130f93f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java @@ -99,7 +99,7 @@ public class NameConflictTreeWalk extends TreeWalk { * @param repo * the repository the walker will obtain data from. */ - public NameConflictTreeWalk(final Repository repo) { + public NameConflictTreeWalk(Repository repo) { super(repo); } @@ -112,7 +112,7 @@ public class NameConflictTreeWalk extends TreeWalk { * the reader the walker will obtain tree data from. * @since 4.3 */ - public NameConflictTreeWalk(@Nullable Repository repo, final ObjectReader or) { + public NameConflictTreeWalk(@Nullable Repository repo, ObjectReader or) { super(repo, or); } @@ -122,7 +122,7 @@ public class NameConflictTreeWalk extends TreeWalk { * @param or * the reader the walker will obtain tree data from. */ - public NameConflictTreeWalk(final ObjectReader or) { + public NameConflictTreeWalk(ObjectReader or) { super(or); } @@ -135,7 +135,7 @@ public class NameConflictTreeWalk extends TreeWalk { if (isTree(minRef)) { if (skipEntry(minRef)) { - for (final AbstractTreeIterator t : trees) { + for (AbstractTreeIterator t : trees) { if (t.matches == minRef) { t.next(1); t.matches = null; @@ -222,16 +222,16 @@ public class NameConflictTreeWalk extends TreeWalk { return FileMode.GITLINK.equals(p.mode); } - private static boolean isTree(final AbstractTreeIterator p) { + private static boolean isTree(AbstractTreeIterator p) { return FileMode.TREE.equals(p.mode); } - private boolean skipEntry(final AbstractTreeIterator minRef) + private boolean skipEntry(AbstractTreeIterator minRef) throws CorruptObjectException { // A tree D/F may have been handled earlier. We need to // not report this path if it has already been reported. // - for (final AbstractTreeIterator t : trees) { + for (AbstractTreeIterator t : trees) { if (t.matches == minRef || t.first()) continue; @@ -260,14 +260,14 @@ public class NameConflictTreeWalk extends TreeWalk { return false; } - private AbstractTreeIterator combineDF(final AbstractTreeIterator minRef) + private AbstractTreeIterator combineDF(AbstractTreeIterator minRef) throws CorruptObjectException { // Look for a possible D/F conflict forward in the tree(s) // as there may be a "$path/" which matches "$path". Make // such entries match this entry. // AbstractTreeIterator treeMatch = null; - for (final AbstractTreeIterator t : trees) { + for (AbstractTreeIterator t : trees) { if (t.matches == minRef || t.eof()) continue; @@ -306,7 +306,7 @@ public class NameConflictTreeWalk extends TreeWalk { // matching iterators instead of the file iterator. // This way isSubtree is true and isRecursive works. // - for (final AbstractTreeIterator t : trees) + for (AbstractTreeIterator t : trees) if (t.matches == minRef) t.matches = treeMatch; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java index 8872689d36..d500aae681 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java @@ -332,7 +332,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * ObjectReader will be created by the walker, and will be closed * when the walker is closed. */ - public TreeWalk(final Repository repo) { + public TreeWalk(Repository repo) { this(repo, repo.newObjectReader(), true); } @@ -348,7 +348,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * is not closed when the walker is closed. * @since 4.3 */ - public TreeWalk(final @Nullable Repository repo, final ObjectReader or) { + public TreeWalk(@Nullable Repository repo, ObjectReader or) { this(repo, or, false); } @@ -359,7 +359,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * the reader the walker will obtain tree data from. The reader * is not closed when the walker is closed. */ - public TreeWalk(final ObjectReader or) { + public TreeWalk(ObjectReader or) { this(null, or, false); } @@ -447,7 +447,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @see org.eclipse.jgit.treewalk.filter.AndTreeFilter * @see org.eclipse.jgit.treewalk.filter.OrTreeFilter */ - public void setFilter(final TreeFilter newFilter) { + public void setFilter(TreeFilter newFilter) { filter = newFilter != null ? newFilter : TreeFilter.ALL; } @@ -475,7 +475,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @param b * true to skip subtree nodes and only obtain files nodes. */ - public void setRecursive(final boolean b) { + public void setRecursive(boolean b) { recursive = b; } @@ -505,7 +505,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * true to get trees after their children. * @see #isPostOrderTraversal() */ - public void setPostOrderTraversal(final boolean b) { + public void setPostOrderTraversal(boolean b) { postOrderTraversal = b; } @@ -633,22 +633,6 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { } /** - * Get the EOL stream type of the current entry using the config and - * {@link #getAttributes()}. - * - * @return the EOL stream type of the current entry using the config and - * {@link #getAttributes()}. Note that this method may return null - * if the {@link org.eclipse.jgit.treewalk.TreeWalk} is not based on - * a working tree - * @since 4.3 - * @deprecated use {@link #getEolStreamType(OperationType)} instead. - */ - @Deprecated - public @Nullable EolStreamType getEolStreamType() { - return (getEolStreamType(operationType)); - } - - /** * Reset this walker so new tree iterators can be added to it. */ public void reset() { @@ -677,7 +661,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @throws java.io.IOException * a loose object or pack file could not be read. */ - public void reset(final AnyObjectId id) throws MissingObjectException, + public void reset(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { if (trees.length == 1) { AbstractTreeIterator o = trees[0]; @@ -718,7 +702,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @throws java.io.IOException * a loose object or pack file could not be read. */ - public void reset(final AnyObjectId... ids) throws MissingObjectException, + public void reset(AnyObjectId... ids) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { final int oldLen = trees.length; final int newLen = ids.length; @@ -773,7 +757,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @throws java.io.IOException * a loose object or pack file could not be read. */ - public int addTree(final AnyObjectId id) throws MissingObjectException, + public int addTree(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException, IOException { return addTree(parserFor(id)); } @@ -936,7 +920,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @return mode bits for the current entry of the nth tree. * @see FileMode#fromBits(int) */ - public int getRawMode(final int nth) { + public int getRawMode(int nth) { final AbstractTreeIterator t = trees[nth]; return t.matches == currentHead ? t.mode : 0; } @@ -952,7 +936,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * tree to obtain the mode from. * @return mode for the current entry of the nth tree. */ - public FileMode getFileMode(final int nth) { + public FileMode getFileMode(int nth) { return FileMode.fromBits(getRawMode(nth)); } @@ -987,7 +971,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @see #getObjectId(MutableObjectId, int) * @see #idEqual(int, int) */ - public ObjectId getObjectId(final int nth) { + public ObjectId getObjectId(int nth) { final AbstractTreeIterator t = trees[nth]; return t.matches == currentHead ? t.getEntryObjectId() : ObjectId .zeroId(); @@ -1009,7 +993,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * tree to obtain the object identifier from. * @see #idEqual(int, int) */ - public void getObjectId(final MutableObjectId out, final int nth) { + public void getObjectId(MutableObjectId out, int nth) { final AbstractTreeIterator t = trees[nth]; if (t.matches == currentHead) t.getEntryObjectId(out); @@ -1028,7 +1012,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * <code>getObjectId(nthA).equals(getObjectId(nthB))</code>. * @see #getObjectId(int) */ - public boolean idEqual(final int nthA, final int nthB) { + public boolean idEqual(int nthA, int nthB) { final AbstractTreeIterator ch = currentHead; final AbstractTreeIterator a = trees[nthA]; final AbstractTreeIterator b = trees[nthB]; @@ -1126,7 +1110,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * again on this tree walk. * @since 4.7 */ - public int isPathMatch(final byte[] p, final int pLen) { + public int isPathMatch(byte[] p, int pLen) { final AbstractTreeIterator t = currentHead; final byte[] c = t.path; final int cLen = t.pathLen; @@ -1179,7 +1163,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * path; 1 if the current path is past p and p will never match * again on this tree walk. */ - public int isPathPrefix(final byte[] p, final int pLen) { + public int isPathPrefix(byte[] p, int pLen) { final AbstractTreeIterator t = currentHead; final byte[] c = t.path; final int cLen = t.pathLen; @@ -1229,7 +1213,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { * @return true if p is suffix of the current path; * false if otherwise */ - public boolean isPathSuffix(final byte[] p, final int pLen) { + public boolean isPathSuffix(byte[] p, int pLen) { final AbstractTreeIterator t = currentHead; final byte[] c = t.path; final int cLen = t.pathLen; @@ -1377,7 +1361,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { trees[i] = trees[i].parent; AbstractTreeIterator minRef = null; - for (final AbstractTreeIterator t : trees) { + for (AbstractTreeIterator t : trees) { if (t.matches != t) continue; if (minRef == null || t.pathCompare(minRef) < 0) @@ -1386,18 +1370,18 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { currentHead = minRef; } - private CanonicalTreeParser parserFor(final AnyObjectId id) + private CanonicalTreeParser parserFor(AnyObjectId id) throws IncorrectObjectTypeException, IOException { final CanonicalTreeParser p = new CanonicalTreeParser(); p.reset(reader, id); return p; } - static String pathOf(final AbstractTreeIterator t) { + static String pathOf(AbstractTreeIterator t) { return RawParseUtils.decode(Constants.CHARSET, t.path, 0, t.pathLen); } - static String pathOf(final byte[] buf, int pos, int end) { + static String pathOf(byte[] buf, int pos, int end) { return RawParseUtils.decode(Constants.CHARSET, buf, pos, end); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 68cc7cb580..179fd46791 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -211,7 +211,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * @param p * parent tree iterator. */ - protected WorkingTreeIterator(final WorkingTreeIterator p) { + protected WorkingTreeIterator(WorkingTreeIterator p) { super(p); state = p.state; repository = p.repository; @@ -256,6 +256,45 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { state.dirCacheTree = treeId; } + /** + * Retrieves the {@link DirCacheIterator} at the current entry if + * {@link #setDirCacheIterator(TreeWalk, int)} was called. + * + * @return the DirCacheIterator, or {@code null} if not set or not at the + * current entry + * @since 5.0 + */ + protected DirCacheIterator getDirCacheIterator() { + if (state.dirCacheTree >= 0 && state.walk != null) { + return state.walk.getTree(state.dirCacheTree, + DirCacheIterator.class); + } + return null; + } + + /** + * Defines whether this {@link WorkingTreeIterator} walks ignored + * directories. + * + * @param includeIgnored + * {@code false} to skip ignored directories, if possible; + * {@code true} to always include them in the walk + * @since 5.0 + */ + public void setWalkIgnoredDirectories(boolean includeIgnored) { + state.walkIgnored = includeIgnored; + } + + /** + * Tells whether this {@link WorkingTreeIterator} walks ignored directories. + * + * @return {@code true} if it does, {@code false} otherwise + * @since 5.0 + */ + public boolean walksIgnoredDirectories() { + return state.walkIgnored; + } + /** {@inheritDoc} */ @Override public boolean hasId() { @@ -340,30 +379,22 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * @return non-null submodule id */ protected byte[] idSubmodule(File directory, Entry e) { - final Repository submoduleRepo; - try { - submoduleRepo = SubmoduleWalk.getSubmoduleRepository(directory, - e.getName(), - repository != null ? repository.getFS() : FS.DETECTED); - } catch (IOException exception) { - return zeroid; - } - if (submoduleRepo == null) - return zeroid; - - final ObjectId head; - try { - head = submoduleRepo.resolve(Constants.HEAD); + try (Repository submoduleRepo = SubmoduleWalk.getSubmoduleRepository( + directory, e.getName(), + repository != null ? repository.getFS() : FS.DETECTED)) { + if (submoduleRepo == null) { + return zeroid; + } + ObjectId head = submoduleRepo.resolve(Constants.HEAD); + if (head == null) { + return zeroid; + } + byte[] id = new byte[Constants.OBJECT_ID_LENGTH]; + head.copyRawTo(id, 0); + return id; } catch (IOException exception) { return zeroid; - } finally { - submoduleRepo.close(); } - if (head == null) - return zeroid; - final byte[] id = new byte[Constants.OBJECT_ID_LENGTH]; - head.copyRawTo(id, 0); - return id; } private static final byte[] digits = { '0', '1', '2', '3', '4', '5', '6', @@ -372,7 +403,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { private static final byte[] hblob = Constants .encodedTypeString(Constants.OBJ_BLOB); - private byte[] idBufferBlob(final Entry e) { + private byte[] idBufferBlob(Entry e) { try { final InputStream is = e.openInputStream(); if (is == null) @@ -430,7 +461,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { return filterClean(is, opType); } - private static void safeClose(final InputStream in) { + private static void safeClose(InputStream in) { try { in.close(); } catch (IOException err2) { @@ -548,7 +579,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { /** {@inheritDoc} */ @Override - public void next(final int delta) throws CorruptObjectException { + public void next(int delta) throws CorruptObjectException { ptr += delta; if (!eof()) { parseEntry(); @@ -557,7 +588,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { /** {@inheritDoc} */ @Override - public void back(final int delta) throws CorruptObjectException { + public void back(int delta) throws CorruptObjectException { ptr -= delta; parseEntry(); } @@ -662,7 +693,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * @throws java.io.IOException * a relevant ignore rule file exists but cannot be read. */ - protected boolean isEntryIgnored(final int pLen) throws IOException { + protected boolean isEntryIgnored(int pLen) throws IOException { return isEntryIgnored(pLen, mode); } @@ -677,7 +708,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * @throws IOException * a relevant ignore rule file exists but cannot be read. */ - private boolean isEntryIgnored(final int pLen, int fileMode) + private boolean isEntryIgnored(int pLen, int fileMode) throws IOException { // The ignore code wants path to start with a '/' if possible. // If we have the '/' in our path buffer because we are inside @@ -756,7 +787,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * files in the subtree of the work tree this iterator operates * on */ - protected void init(final Entry[] list) { + protected void init(Entry[] list) { // Filter out nulls, . and .. as these are not valid tree entries, // also cache the encoded forms of the path names for efficient use // later on during sorting and iteration. @@ -838,7 +869,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * an int. * @return true if different, false otherwise */ - public boolean isModeDifferent(final int rawMode) { + public boolean isModeDifferent(int rawMode) { // Determine difference in mode-bits of file and index-entry. In the // bitwise presentation of modeDiff we'll have a '1' when the two modes // differ at this position. @@ -992,7 +1023,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { * available at this iterator's current entry * @return index file mode */ - public FileMode getIndexFileMode(final DirCacheIterator indexIter) { + public FileMode getIndexFileMode(DirCacheIterator indexIter) { final FileMode wtMode = getEntryFileMode(); if (indexIter == null) { return wtMode; @@ -1173,13 +1204,17 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { return contentDigest.digest(); } - /** A single entry within a working directory tree. */ - protected static abstract class Entry { + /** + * A single entry within a working directory tree. + * + * @since 5.0 + */ + public static abstract class Entry { byte[] encodedName; int encodedNameLen; - void encodeName(final CharsetEncoder enc) { + void encodeName(CharsetEncoder enc) { final ByteBuffer b; try { b = enc.encode(CharBuffer.wrap(getName())); @@ -1280,11 +1315,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { IgnoreNode load() throws IOException { IgnoreNode r = new IgnoreNode(); - InputStream in = entry.openInputStream(); - try { + try (InputStream in = entry.openInputStream()) { r.parse(in); - } finally { - in.close(); } return r.getRules().isEmpty() ? null : r; } @@ -1332,11 +1364,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { private static void loadRulesFromFile(IgnoreNode r, File exclude) throws FileNotFoundException, IOException { if (FS.DETECTED.exists(exclude)) { - FileInputStream in = new FileInputStream(exclude); - try { + try (FileInputStream in = new FileInputStream(exclude)) { r.parse(in); - } finally { - in.close(); } } } @@ -1353,11 +1382,8 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { AttributesNode load() throws IOException { AttributesNode r = new AttributesNode(); - InputStream in = entry.openInputStream(); - try { + try (InputStream in = entry.openInputStream()) { r.parse(in); - } finally { - in.close(); } return r.getRules().isEmpty() ? null : r; } @@ -1378,7 +1404,10 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { TreeWalk walk; /** Position of the matching {@link DirCacheIterator}. */ - int dirCacheTree; + int dirCacheTree = -1; + + /** Whether the iterator shall walk ignored directories. */ + boolean walkIgnored = false; final Map<String, Boolean> directoryToIgnored = new HashMap<>(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java index 2dfb2033d0..846fb6e342 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java @@ -74,7 +74,7 @@ public class WorkingTreeOptions { private final boolean dirNoGitLinks; - private WorkingTreeOptions(final Config rc) { + private WorkingTreeOptions(Config rc) { fileMode = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_FILEMODE, true); autoCRLF = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java index 6d40a4eb51..a960bd7a8e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java @@ -71,7 +71,7 @@ public abstract class AndTreeFilter extends TreeFilter { * second filter to test. * @return a filter that must match both input filters. */ - public static TreeFilter create(final TreeFilter a, final TreeFilter b) { + public static TreeFilter create(TreeFilter a, TreeFilter b) { if (a == ALL) return b; if (b == ALL) @@ -87,7 +87,7 @@ public abstract class AndTreeFilter extends TreeFilter { * filters. * @return a filter that must match all input filters. */ - public static TreeFilter create(final TreeFilter[] list) { + public static TreeFilter create(TreeFilter[] list) { if (list.length == 2) return create(list[0], list[1]); if (list.length < 2) @@ -105,7 +105,7 @@ public abstract class AndTreeFilter extends TreeFilter { * filters. * @return a filter that must match all input filters. */ - public static TreeFilter create(final Collection<TreeFilter> list) { + public static TreeFilter create(Collection<TreeFilter> list) { if (list.size() < 2) throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded); final TreeFilter[] subfilters = new TreeFilter[list.size()]; @@ -120,13 +120,13 @@ public abstract class AndTreeFilter extends TreeFilter { private final TreeFilter b; - Binary(final TreeFilter one, final TreeFilter two) { + Binary(TreeFilter one, TreeFilter two) { a = one; b = two; } @Override - public boolean include(final TreeWalk walker) + public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { return matchFilter(walker) <= 0; @@ -170,12 +170,12 @@ public abstract class AndTreeFilter extends TreeFilter { private static class List extends AndTreeFilter { private final TreeFilter[] subfilters; - List(final TreeFilter[] list) { + List(TreeFilter[] list) { subfilters = list; } @Override - public boolean include(final TreeWalk walker) + public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { return matchFilter(walker) <= 0; @@ -186,7 +186,7 @@ public abstract class AndTreeFilter extends TreeFilter { throws MissingObjectException, IncorrectObjectTypeException, IOException { int m = 0; - for (final TreeFilter f : subfilters) { + for (TreeFilter f : subfilters) { int r = f.matchFilter(walker); if (r == 1) { return 1; @@ -200,7 +200,7 @@ public abstract class AndTreeFilter extends TreeFilter { @Override public boolean shouldBeRecursive() { - for (final TreeFilter f : subfilters) + for (TreeFilter f : subfilters) if (f.shouldBeRecursive()) return true; return false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java index 653786b7ae..995561e59e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java @@ -77,7 +77,7 @@ class ByteArraySet { initTable(1 << Integer.highestOneBit((capacity * 2) - 1)); } - private byte[] get(final byte[] toFind, int length, int hash) { + private byte[] get(byte[] toFind, int length, int hash) { final int msk = mask; int i = hash & msk; final byte[][] tbl = table; @@ -112,7 +112,7 @@ class ByteArraySet { * pre-computed hash of toFind * @return true if the mapping exists for this byte array; false otherwise. */ - boolean contains(final byte[] toFind, int length, int hash) { + boolean contains(byte[] toFind, int length, int hash) { return get(toFind, length, hash) != null; } @@ -180,7 +180,7 @@ class ByteArraySet { return size == 0; } - private void insert(final byte[] newValue, int hash) { + private void insert(byte[] newValue, int hash) { final int msk = mask; int j = hash & msk; final byte[][] tbl = table; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilter.java index 81b8e6d148..338ee2b27a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilter.java @@ -63,7 +63,7 @@ public final class InterIndexDiffFilter extends TreeFilter { /** {@inheritDoc} */ @Override - public boolean include(final TreeWalk walker) { + public boolean include(TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java index 3403c78578..6090508a44 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java @@ -62,7 +62,7 @@ public class NotIgnoredFilter extends TreeFilter { * @param workdirTreeIndex * index of the workdir tree in the tree walk */ - public NotIgnoredFilter(final int workdirTreeIndex) { + public NotIgnoredFilter(int workdirTreeIndex) { this.index = workdirTreeIndex; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java index 2e023d0698..d315526e08 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java @@ -61,13 +61,13 @@ public class NotTreeFilter extends TreeFilter { * filter to negate. * @return a filter that does the reverse of <code>a</code>. */ - public static TreeFilter create(final TreeFilter a) { + public static TreeFilter create(TreeFilter a) { return new NotTreeFilter(a); } private final TreeFilter a; - private NotTreeFilter(final TreeFilter one) { + private NotTreeFilter(TreeFilter one) { a = one; } @@ -79,7 +79,7 @@ public class NotTreeFilter extends TreeFilter { /** {@inheritDoc} */ @Override - public boolean include(final TreeWalk walker) + public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { return matchFilter(walker) == 0; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java index dbb062b973..308ff0c962 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java @@ -71,7 +71,7 @@ public abstract class OrTreeFilter extends TreeFilter { * second filter to test. * @return a filter that must match at least one input filter. */ - public static TreeFilter create(final TreeFilter a, final TreeFilter b) { + public static TreeFilter create(TreeFilter a, TreeFilter b) { if (a == ALL || b == ALL) return ALL; return new Binary(a, b); @@ -85,7 +85,7 @@ public abstract class OrTreeFilter extends TreeFilter { * filters. * @return a filter that must match at least one input filter. */ - public static TreeFilter create(final TreeFilter[] list) { + public static TreeFilter create(TreeFilter[] list) { if (list.length == 2) return create(list[0], list[1]); if (list.length < 2) @@ -103,7 +103,7 @@ public abstract class OrTreeFilter extends TreeFilter { * filters. * @return a filter that must match at least one input filter. */ - public static TreeFilter create(final Collection<TreeFilter> list) { + public static TreeFilter create(Collection<TreeFilter> list) { if (list.size() < 2) throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded); final TreeFilter[] subfilters = new TreeFilter[list.size()]; @@ -118,13 +118,13 @@ public abstract class OrTreeFilter extends TreeFilter { private final TreeFilter b; - Binary(final TreeFilter one, final TreeFilter two) { + Binary(TreeFilter one, TreeFilter two) { a = one; b = two; } @Override - public boolean include(final TreeWalk walker) + public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { return matchFilter(walker) <= 0; @@ -168,12 +168,12 @@ public abstract class OrTreeFilter extends TreeFilter { private static class List extends OrTreeFilter { private final TreeFilter[] subfilters; - List(final TreeFilter[] list) { + List(TreeFilter[] list) { subfilters = list; } @Override - public boolean include(final TreeWalk walker) + public boolean include(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { return matchFilter(walker) <= 0; @@ -184,7 +184,7 @@ public abstract class OrTreeFilter extends TreeFilter { throws MissingObjectException, IncorrectObjectTypeException, IOException { int m = 1; - for (final TreeFilter f : subfilters) { + for (TreeFilter f : subfilters) { int r = f.matchFilter(walker); if (r == 0) { return 0; @@ -198,7 +198,7 @@ public abstract class OrTreeFilter extends TreeFilter { @Override public boolean shouldBeRecursive() { - for (final TreeFilter f : subfilters) + for (TreeFilter f : subfilters) if (f.shouldBeRecursive()) return true; return false; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java index 2f7f5cdc57..9267fb64f5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java @@ -86,7 +86,7 @@ public class PathFilter extends TreeFilter { final byte[] pathRaw; - private PathFilter(final String s) { + private PathFilter(String s) { pathStr = s; pathRaw = Constants.encode(pathStr); } @@ -102,20 +102,20 @@ public class PathFilter extends TreeFilter { /** {@inheritDoc} */ @Override - public boolean include(final TreeWalk walker) { + public boolean include(TreeWalk walker) { return matchFilter(walker) <= 0; } /** {@inheritDoc} */ @Override - public int matchFilter(final TreeWalk walker) { + public int matchFilter(TreeWalk walker) { return walker.isPathMatch(pathRaw, pathRaw.length); } /** {@inheritDoc} */ @Override public boolean shouldBeRecursive() { - for (final byte b : pathRaw) + for (byte b : pathRaw) if (b == '/') return true; return false; @@ -143,7 +143,7 @@ public class PathFilter extends TreeFilter { * @return {@code true} if the path length of this filter matches the length * of the current path of the supplied TreeWalk. */ - public boolean isDone(final TreeWalk walker) { + public boolean isDone(TreeWalk walker) { return pathRaw.length == walker.getPathLength(); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java index 0652288b63..5cf5750808 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java @@ -82,13 +82,13 @@ public class PathFilterGroup { * the paths to test against. Must have at least one entry. * @return a new filter for the list of paths supplied. */ - public static TreeFilter createFromStrings(final Collection<String> paths) { + public static TreeFilter createFromStrings(Collection<String> paths) { if (paths.isEmpty()) throw new IllegalArgumentException( JGitText.get().atLeastOnePathIsRequired); final PathFilter[] p = new PathFilter[paths.size()]; int i = 0; - for (final String s : paths) + for (String s : paths) p[i++] = PathFilter.create(s); return create(p); } @@ -109,7 +109,7 @@ public class PathFilterGroup { * the paths to test against. Must have at least one entry. * @return a new filter for the paths supplied. */ - public static TreeFilter createFromStrings(final String... paths) { + public static TreeFilter createFromStrings(String... paths) { if (paths.length == 0) throw new IllegalArgumentException( JGitText.get().atLeastOnePathIsRequired); @@ -131,7 +131,7 @@ public class PathFilterGroup { * the paths to test against. Must have at least one entry. * @return a new filter for the list of paths supplied. */ - public static TreeFilter create(final Collection<PathFilter> paths) { + public static TreeFilter create(Collection<PathFilter> paths) { if (paths.isEmpty()) throw new IllegalArgumentException( JGitText.get().atLeastOnePathIsRequired); @@ -140,7 +140,7 @@ public class PathFilterGroup { return create(p); } - private static TreeFilter create(final PathFilter[] p) { + private static TreeFilter create(PathFilter[] p) { if (p.length == 1) return new Single(p[0]); return new Group(p); @@ -151,13 +151,13 @@ public class PathFilterGroup { private final byte[] raw; - private Single(final PathFilter p) { + private Single(PathFilter p) { path = p; raw = path.pathRaw; } @Override - public boolean include(final TreeWalk walker) { + public boolean include(TreeWalk walker) { final int cmp = walker.isPathPrefix(raw, raw.length); if (cmp > 0) throw StopWalkException.INSTANCE; @@ -188,7 +188,7 @@ public class PathFilterGroup { private byte[] max; - private Group(final PathFilter[] pathFilters) { + private Group(PathFilter[] pathFilters) { fullpaths = new ByteArraySet(pathFilters.length); prefixes = new ByteArraySet(pathFilters.length / 5); // 5 is an empirically derived ratio of #paths/#prefixes from: @@ -239,7 +239,7 @@ public class PathFilterGroup { } @Override - public boolean include(final TreeWalk walker) { + public boolean include(TreeWalk walker) { byte[] rp = walker.getRawPath(); Hasher hasher = new Hasher(rp, walker.getPathLength()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathSuffixFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathSuffixFilter.java index 553e6bdd63..3d9f875e99 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathSuffixFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathSuffixFilter.java @@ -84,7 +84,7 @@ public class PathSuffixFilter extends TreeFilter { final String pathStr; final byte[] pathRaw; - private PathSuffixFilter(final String s) { + private PathSuffixFilter(String s) { pathStr = s; pathRaw = Constants.encode(pathStr); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java index f0a76324b2..11ad465538 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java @@ -91,7 +91,7 @@ public abstract class TreeFilter { private static final class AllFilter extends TreeFilter { @Override - public boolean include(final TreeWalk walker) { + public boolean include(TreeWalk walker) { return true; } @@ -133,7 +133,7 @@ public abstract class TreeFilter { private static final int baseTree = 0; @Override - public boolean include(final TreeWalk walker) { + public boolean include(TreeWalk walker) { final int n = walker.getTreeCount(); if (n == 1) // Assume they meant difference to empty tree. return true; @@ -221,7 +221,7 @@ public abstract class TreeFilter { * as thrown by {@link #include(TreeWalk)} * @since 4.7 */ - public int matchFilter(final TreeWalk walker) + public int matchFilter(TreeWalk walker) throws MissingObjectException, IncorrectObjectTypeException, IOException { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java index 0c27ced76b..442f0793fb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java @@ -6,9 +6,8 @@ package org.eclipse.jgit.util; -import static java.nio.charset.StandardCharsets.UTF_8; +import static org.eclipse.jgit.lib.Constants.CHARSET; -import java.nio.charset.StandardCharsets; import java.text.MessageFormat; import java.util.Arrays; @@ -55,7 +54,7 @@ public class Base64 { + "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$ + "0123456789" // //$NON-NLS-1$ + "+/" // //$NON-NLS-1$ - ).getBytes(UTF_8); + ).getBytes(CHARSET); DEC = new byte[128]; Arrays.fill(DEC, INVALID_DEC); @@ -178,7 +177,7 @@ public class Base64 { e += 4; } - return new String(outBuff, 0, e, StandardCharsets.UTF_8); + return new String(outBuff, 0, e, CHARSET); } /** @@ -294,7 +293,7 @@ public class Base64 { * @return the decoded data */ public static byte[] decode(String s) { - byte[] bytes = s.getBytes(UTF_8); + byte[] bytes = s.getBytes(CHARSET); return decode(bytes, 0, bytes.length); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java index 9915bdf49b..6b58790b23 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/CachedAuthenticator.java @@ -61,7 +61,7 @@ public abstract class CachedAuthenticator extends Authenticator { * @param ca * the information we should remember. */ - public static void add(final CachedAuthentication ca) { + public static void add(CachedAuthentication ca) { cached.add(ca); } @@ -70,7 +70,7 @@ public abstract class CachedAuthenticator extends Authenticator { protected final PasswordAuthentication getPasswordAuthentication() { final String host = getRequestingHost(); final int port = getRequestingPort(); - for (final CachedAuthentication ca : cached) { + for (CachedAuthentication ca : cached) { if (ca.host.equals(host) && ca.port == port) return ca.toPasswordAuthentication(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index edcb9d7a6a..3372bbe6a4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -71,6 +71,9 @@ import org.eclipse.jgit.errors.CommandFailedException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry; +import org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy; +import org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry; import org.eclipse.jgit.util.ProcessResult.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,6 +85,14 @@ public abstract class FS { private static final Logger LOG = LoggerFactory.getLogger(FS.class); /** + * An empty array of entries, suitable as a return value for + * {@link #list(File, FileModeStrategy)}. + * + * @since 5.0 + */ + protected static final Entry[] NO_ENTRIES = {}; + + /** * This class creates FS instances. It will be overridden by a Java7 variant * if such can be detected in {@link #detect(Boolean)}. * @@ -379,7 +390,7 @@ public abstract class FS { * @return the translated path. <code>new File(dir,name)</code> if this * platform does not require path name translation. */ - public File resolve(final File dir, final String name) { + public File resolve(File dir, String name) { final File abspn = new File(name); if (abspn.isAbsolute()) return abspn; @@ -455,11 +466,11 @@ public abstract class FS { * @return the first match found, or null * @since 3.0 */ - protected static File searchPath(final String path, final String... lookFor) { + protected static File searchPath(String path, String... lookFor) { if (path == null) return null; - for (final String p : path.split(File.pathSeparator)) { + for (String p : path.split(File.pathSeparator)) { for (String command : lookFor) { final File e = new File(p, command); if (e.isFile()) @@ -887,6 +898,29 @@ public abstract class FS { } /** + * Enumerates children of a directory. + * + * @param directory + * to get the children of + * @param fileModeStrategy + * to use to calculate the git mode of a child + * @return an array of entries for the children + * + * @since 5.0 + */ + public Entry[] list(File directory, FileModeStrategy fileModeStrategy) { + final File[] all = directory.listFiles(); + if (all == null) { + return NO_ENTRIES; + } + final Entry[] result = new Entry[all.length]; + for (int i = 0; i < result.length; i++) { + result[i] = new FileEntry(all[i], this, fileModeStrategy); + } + return result; + } + + /** * Checks whether the given hook is defined for the given repository, then * runs it with the given arguments. * <p> @@ -1023,7 +1057,7 @@ public abstract class FS { * exists in the given repository, <code>null</code> otherwise. * @since 4.0 */ - public File findHook(Repository repository, final String hookName) { + public File findHook(Repository repository, String hookName) { File gitDir = repository.getDirectory(); if (gitDir == null) return null; @@ -1108,19 +1142,23 @@ public abstract class FS { new StreamGobbler(process.getErrorStream(), errRedirect)); executor.execute( new StreamGobbler(process.getInputStream(), outRedirect)); + @SuppressWarnings("resource") // Closed in the finally block OutputStream outputStream = process.getOutputStream(); - if (inRedirect != null) { - new StreamGobbler(inRedirect, outputStream).copy(); - } try { - outputStream.close(); - } catch (IOException e) { - // When the process exits before consuming the input, the OutputStream - // is replaced with the null output stream. This null output stream - // throws IOException for all write calls. When StreamGobbler fails to - // flush the buffer because of this, this close call tries to flush it - // again. This causes another IOException. Since we ignore the - // IOException in StreamGobbler, we also ignore the exception here. + if (inRedirect != null) { + new StreamGobbler(inRedirect, outputStream).copy(); + } + } finally { + try { + outputStream.close(); + } catch (IOException e) { + // When the process exits before consuming the input, the OutputStream + // is replaced with the null output stream. This null output stream + // throws IOException for all write calls. When StreamGobbler fails to + // flush the buffer because of this, this close call tries to flush it + // again. This causes another IOException. Since we ignore the + // IOException in StreamGobbler, we also ignore the exception here. + } } return process.waitFor(); } catch (IOException e) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java index a2923db9dd..3abf4dc5e5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java @@ -389,7 +389,7 @@ public class FS_POSIX extends FS { Integer nlink = (Integer) (Files.getAttribute(lockPath, "unix:nlink")); //$NON-NLS-1$ if (nlink != 2) { - LOG.warn("nlink of link to lock file {0} was not 2 but {1}", //$NON-NLS-1$ + LOG.warn("nlink of link to lock file {} was not 2 but {}", //$NON-NLS-1$ lock.getPath(), nlink); return false; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java index 29fe5dc829..9f99e28557 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java @@ -47,11 +47,21 @@ package org.eclipse.jgit.util; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.FileVisitOption; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.Arrays; +import java.util.EnumSet; import java.util.List; import org.eclipse.jgit.errors.CommandFailedException; +import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry; +import org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy; +import org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -97,13 +107,13 @@ public class FS_Win32 extends FS { /** {@inheritDoc} */ @Override - public boolean canExecute(final File f) { + public boolean canExecute(File f) { return false; } /** {@inheritDoc} */ @Override - public boolean setExecute(final File f, final boolean canExec) { + public boolean setExecute(File f, boolean canExec) { return false; } @@ -121,6 +131,49 @@ public class FS_Win32 extends FS { /** {@inheritDoc} */ @Override + public Entry[] list(File directory, FileModeStrategy fileModeStrategy) { + List<Entry> result = new ArrayList<>(); + FS fs = this; + boolean checkExecutable = fs.supportsExecute(); + try { + Files.walkFileTree(directory.toPath(), + EnumSet.noneOf(FileVisitOption.class), 1, + new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult visitFile(Path file, + BasicFileAttributes attrs) throws IOException { + File f = file.toFile(); + FS.Attributes attributes = new FS.Attributes(fs, f, + true, attrs.isDirectory(), + checkExecutable && f.canExecute(), + attrs.isSymbolicLink(), + attrs.isRegularFile(), + attrs.creationTime().toMillis(), + attrs.lastModifiedTime().toMillis(), + attrs.size()); + result.add(new FileEntry(f, fs, attributes, + fileModeStrategy)); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, + IOException exc) throws IOException { + // Just ignore it + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + // Ignore + } + if (result.isEmpty()) { + return NO_ENTRIES; + } + return result.toArray(new Entry[result.size()]); + } + + /** {@inheritDoc} */ + @Override protected File discoverGitExe() { String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$ File gitExe = searchPath(path, "git.exe", "git.cmd"); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java index 64cdcc300d..3393fbfd1d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.util; +import static org.eclipse.jgit.lib.Constants.CHARSET; + import java.io.File; import java.io.PrintStream; import java.nio.file.Files; @@ -117,14 +119,14 @@ public class FS_Win32_Cygwin extends FS_Win32 { /** {@inheritDoc} */ @Override - public File resolve(final File dir, final String pn) { + public File resolve(File dir, String pn) { String useCygPath = System.getProperty("jgit.usecygpath"); //$NON-NLS-1$ if (useCygPath != null && useCygPath.equals("true")) { //$NON-NLS-1$ String w; try { w = readPipe(dir, // new String[] { cygpath, "--windows", "--absolute", pn }, // //$NON-NLS-1$ //$NON-NLS-2$ - "UTF-8"); //$NON-NLS-1$ + CHARSET.name()); } catch (CommandFailedException e) { LOG.warn(e.getMessage()); return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtil.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtil.java deleted file mode 100644 index 96f21756d5..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtil.java +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (C) 2012, Robin Rosenberg <robin.rosenberg@dewire.com> - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.util; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.jgit.util.FS.Attributes; - -/** - * File utilities using Java 7 NIO2 - */ -@Deprecated -public class FileUtil { - - /** - * Read target path of a symlink. - * - * @param path - * a {@link java.io.File}. - * @return target path of the symlink. - * @throws java.io.IOException - * @deprecated use {@link org.eclipse.jgit.util.FileUtils#readSymLink(File)} - * instead - */ - @Deprecated - public static String readSymlink(File path) throws IOException { - return FileUtils.readSymLink(path); - } - - /** - * Create a symlink - * - * @param path - * path of the symlink to be created - * @param target - * target of the symlink to be created - * @throws java.io.IOException - * @deprecated use - * {@link org.eclipse.jgit.util.FileUtils#createSymLink(File, String)} - * instead - */ - @Deprecated - public static void createSymLink(File path, String target) - throws IOException { - FileUtils.createSymLink(path, target); - } - - /** - * Whether the passed file is a symlink - * - * @param path - * a {@link java.io.File} object. - * @return {@code true} if the passed path is a symlink - * @deprecated Use - * {@link java.nio.file.Files#isSymbolicLink(java.nio.file.Path)} - * instead - */ - @Deprecated - public static boolean isSymlink(File path) { - return FileUtils.isSymlink(path); - } - - /** - * Get lastModified attribute for given path - * - * @param path - * a {@link java.io.File}. - * @return lastModified attribute for given path - * @throws java.io.IOException - * @deprecated Use - * {@link java.nio.file.Files#getLastModifiedTime(java.nio.file.Path, java.nio.file.LinkOption...)} - * instead - */ - @Deprecated - public static long lastModified(File path) throws IOException { - return FileUtils.lastModified(path); - } - - /** - * Set lastModified attribute for given path - * - * @param path - * a {@link java.io.File}. - * @param time - * a long. - * @throws java.io.IOException - * @deprecated Use - * {@link java.nio.file.Files#setLastModifiedTime(java.nio.file.Path, java.nio.file.attribute.FileTime)} - * instead - */ - @Deprecated - public static void setLastModified(File path, long time) throws IOException { - FileUtils.setLastModified(path, time); - } - - /** - * Whether this file exists - * - * @param path - * a {@link java.io.File}. - * @return {@code true} if the given path exists - * @deprecated Use - * {@link java.nio.file.Files#exists(java.nio.file.Path, java.nio.file.LinkOption...)} - * instead - */ - @Deprecated - public static boolean exists(File path) { - return FileUtils.exists(path); - } - - /** - * Whether this file is hidden - * - * @param path - * a {@link java.io.File}. - * @return {@code true} if the given path is hidden - * @throws java.io.IOException - * @deprecated Use {@link java.nio.file.Files#isHidden(java.nio.file.Path)} - * instead - */ - @Deprecated - public static boolean isHidden(File path) throws IOException { - return FileUtils.isHidden(path); - } - - /** - * Set this file hidden - * - * @param path - * a {@link java.io.File}. - * @param hidden - * a boolean. - * @throws java.io.IOException - * @deprecated Use - * {@link org.eclipse.jgit.util.FileUtils#setHidden(File,boolean)} - * instead - */ - @Deprecated - public static void setHidden(File path, boolean hidden) throws IOException { - FileUtils.setHidden(path, hidden); - } - - /** - * Get file length - * - * @param path - * a {@link java.io.File}. - * @return length of the given file - * @throws java.io.IOException - * @deprecated Use {@link org.eclipse.jgit.util.FileUtils#getLength(File)} - * instead - */ - @Deprecated - public static long getLength(File path) throws IOException { - return FileUtils.getLength(path); - } - - /** - * Whether the given File is a directory - * - * @param path - * a {@link java.io.File} object. - * @return {@code true} if the given file is a directory - * @deprecated Use - * {@link java.nio.file.Files#isDirectory(java.nio.file.Path, java.nio.file.LinkOption...)} - * instead - */ - @Deprecated - public static boolean isDirectory(File path) { - return FileUtils.isDirectory(path); - } - - /** - * Whether the given File is a file - * - * @param path - * a {@link java.io.File} object. - * @return {@code true} if the given file is a file - * @deprecated Use - * {@link java.nio.file.Files#isRegularFile(java.nio.file.Path, java.nio.file.LinkOption...)} - * instead - */ - @Deprecated - public static boolean isFile(File path) { - return FileUtils.isFile(path); - } - - /** - * Whether the given file can be executed - * - * @param path - * a {@link java.io.File} object. - * @return {@code true} if the given file can be executed - * @deprecated Use {@link org.eclipse.jgit.util.FileUtils#canExecute(File)} - * instead - */ - @Deprecated - public static boolean canExecute(File path) { - return FileUtils.canExecute(path); - } - - /** - * Delete the given file - * - * @param path - * a {@link java.io.File} object. - * @throws java.io.IOException - * @deprecated use {@link org.eclipse.jgit.util.FileUtils#delete(File)} - */ - @Deprecated - public static void delete(File path) throws IOException { - FileUtils.delete(path); - } - - /** - * Get file system attributes for the given file - * - * @param fs - * a {@link org.eclipse.jgit.util.FS} object. - * @param path - * a {@link java.io.File} object. - * @return file system attributes for the given file - * @deprecated Use - * {@link org.eclipse.jgit.util.FileUtils#getFileAttributesPosix(FS,File)} - * instead - */ - @Deprecated - public static Attributes getFileAttributesPosix(FS fs, File path) { - return FileUtils.getFileAttributesPosix(fs, path); - } - - /** - * NFC normalize File (on Mac), otherwise do nothing - * - * @param file - * a {@link java.io.File}. - * @return on Mac: NFC normalized {@link java.io.File}, otherwise the passed - * file - * @deprecated Use {@link org.eclipse.jgit.util.FileUtils#normalize(File)} - * instead - */ - @Deprecated - public static File normalize(File file) { - return FileUtils.normalize(file); - } - - /** - * NFC normalize file name (on Mac), otherwise do nothing - * - * @param name - * a {@link java.lang.String} object. - * @return on Mac: NFC normalized form of given name - * @deprecated Use {@link org.eclipse.jgit.util.FileUtils#normalize(String)} - * instead - */ - @Deprecated - public static String normalize(String name) { - return FileUtils.normalize(name); - } - -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java index 08c278e38a..2f547c15b0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java @@ -122,7 +122,7 @@ public class FileUtils { * {@link java.nio.file.InvalidPathException}) * @since 4.10 */ - public static Path toPath(final File f) throws IOException { + public static Path toPath(File f) throws IOException { try { return f.toPath(); } catch (InvalidPathException ex) { @@ -141,7 +141,7 @@ public class FileUtils { * cause java.io.IOExceptions during race conditions when * multiple concurrent threads all try to delete the same file. */ - public static void delete(final File f) throws IOException { + public static void delete(File f) throws IOException { delete(f, NONE); } @@ -162,7 +162,7 @@ public class FileUtils { * multiple concurrent threads all try to delete the same file. * This exception is not thrown when IGNORE_ERRORS is set. */ - public static void delete(final File f, int options) throws IOException { + public static void delete(File f, int options) throws IOException { FS fs = FS.DETECTED; if ((options & SKIP_MISSING) != 0 && !fs.exists(f)) return; @@ -241,7 +241,7 @@ public class FileUtils { * if the rename has failed * @since 3.0 */ - public static void rename(final File src, final File dst) + public static void rename(File src, File dst) throws IOException { rename(src, dst, StandardCopyOption.REPLACE_EXISTING); } @@ -321,7 +321,7 @@ public class FileUtils { * multiple concurrent threads all try to create the same * directory. */ - public static void mkdir(final File d) + public static void mkdir(File d) throws IOException { mkdir(d, false); } @@ -341,7 +341,7 @@ public class FileUtils { * multiple concurrent threads all try to create the same * directory. */ - public static void mkdir(final File d, boolean skipExisting) + public static void mkdir(File d, boolean skipExisting) throws IOException { if (!d.mkdir()) { if (skipExisting && d.isDirectory()) @@ -366,7 +366,7 @@ public class FileUtils { * multiple concurrent threads all try to create the same * directory. */ - public static void mkdirs(final File d) throws IOException { + public static void mkdirs(File d) throws IOException { mkdirs(d, false); } @@ -388,7 +388,7 @@ public class FileUtils { * multiple concurrent threads all try to create the same * directory. */ - public static void mkdirs(final File d, boolean skipExisting) + public static void mkdirs(File d, boolean skipExisting) throws IOException { if (!d.mkdirs()) { if (skipExisting && d.isDirectory()) @@ -498,33 +498,6 @@ public class FileUtils { throw new IOException(JGitText.get().cannotCreateTempDir); } - - /** - * Relativize a path - * - * @deprecated Use the more-clearly-named - * {@link org.eclipse.jgit.util.FileUtils#relativizeNativePath(String, String)} - * instead, or directly call - * {@link org.eclipse.jgit.util.FileUtils#relativizePath(String, String, String, boolean)} - * - * Expresses <code>other</code> as a relative file path from - * <code>base</code>. File-separator and case sensitivity are - * based on the current file system. - * - * See also - * {@link org.eclipse.jgit.util.FileUtils#relativizePath(String, String, String, boolean)}. - * @param base - * Base path - * @param other - * Destination path - * @return Relative path from <code>base</code> to <code>other</code> - * @since 3.7 - */ - @Deprecated - public static String relativize(String base, String other) { - return relativizeNativePath(base, other); - } - /** * Expresses <code>other</code> as a relative file path from * <code>base</code>. File-separator and case sensitivity are based on the diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java index a5a858f85e..6f92b37853 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.util; +import static org.eclipse.jgit.lib.Constants.CHARACTER_ENCODING; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.ConnectException; @@ -175,11 +177,11 @@ public class HttpSupport { * @param key * value which must be encoded to protected special characters. */ - public static void encode(final StringBuilder urlstr, final String key) { + public static void encode(StringBuilder urlstr, String key) { if (key == null || key.length() == 0) return; try { - urlstr.append(URLEncoder.encode(key, "UTF-8")); //$NON-NLS-1$ + urlstr.append(URLEncoder.encode(key, CHARACTER_ENCODING)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(JGitText.get().couldNotURLEncodeToUTF8, e); } @@ -200,7 +202,7 @@ public class HttpSupport { * communications error prevented obtaining the response code. * @since 3.3 */ - public static int response(final HttpConnection c) throws IOException { + public static int response(HttpConnection c) throws IOException { try { return c.getResponseCode(); } catch (ConnectException ce) { @@ -228,7 +230,7 @@ public class HttpSupport { * @throws java.io.IOException * communications error prevented obtaining the response code. */ - public static int response(final java.net.HttpURLConnection c) + public static int response(java.net.HttpURLConnection c) throws IOException { try { return c.getResponseCode(); @@ -273,7 +275,7 @@ public class HttpSupport { * the proxy could not be computed as the supplied URL could not * be read. This failure should never occur. */ - public static Proxy proxyFor(final ProxySelector proxySelector, final URL u) + public static Proxy proxyFor(ProxySelector proxySelector, URL u) throws ConnectException { try { return proxySelector.select(u.toURI()).get(0); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java index f39d217863..e88e7a38c6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java @@ -47,7 +47,6 @@ package org.eclipse.jgit.util; import java.io.EOFException; import java.io.File; -import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -59,6 +58,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.util.io.SilentFileInputStream; /** * Input/Output utilities @@ -76,7 +76,7 @@ public class IO { * @throws java.io.IOException * the file exists, but its contents cannot be read. */ - public static final byte[] readFully(final File path) + public static final byte[] readFully(File path) throws FileNotFoundException, IOException { return IO.readFully(path, Integer.MAX_VALUE); } @@ -96,10 +96,9 @@ public class IO { * @throws java.io.IOException * the file exists, but its contents cannot be read. */ - public static final byte[] readSome(final File path, final int limit) + public static final byte[] readSome(File path, int limit) throws FileNotFoundException, IOException { - FileInputStream in = new FileInputStream(path); - try { + try (SilentFileInputStream in = new SilentFileInputStream(path)) { byte[] buf = new byte[limit]; int cnt = 0; for (;;) { @@ -113,12 +112,6 @@ public class IO { byte[] res = new byte[cnt]; System.arraycopy(buf, 0, res, 0, cnt); return res; - } finally { - try { - in.close(); - } catch (IOException ignored) { - // do nothing - } } } @@ -136,10 +129,9 @@ public class IO { * @throws java.io.IOException * the file exists, but its contents cannot be read. */ - public static final byte[] readFully(final File path, final int max) + public static final byte[] readFully(File path, int max) throws FileNotFoundException, IOException { - final FileInputStream in = new FileInputStream(path); - try { + try (SilentFileInputStream in = new SilentFileInputStream(path)) { long sz = Math.max(path.length(), 1); if (sz > max) throw new IOException(MessageFormat.format( @@ -173,12 +165,6 @@ public class IO { buf = nb; } return buf; - } finally { - try { - in.close(); - } catch (IOException ignored) { - // ignore any close errors, this was a read only stream - } } } @@ -325,7 +311,7 @@ public class IO { * @throws java.io.IOException * there was an error reading from the stream. */ - public static void skipFully(final InputStream fd, long toSkip) + public static void skipFully(InputStream fd, long toSkip) throws IOException { while (toSkip > 0) { final long r = fd.skip(toSkip); @@ -343,7 +329,7 @@ public class IO { * @return the string divided into lines * @since 2.0 */ - public static List<String> readLines(final String s) { + public static List<String> readLines(String s) { List<String> l = new ArrayList<>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java index 24038f0976..7441d50686 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java @@ -65,7 +65,7 @@ public class IntList { * @param capacity * number of entries the list can initially hold. */ - public IntList(final int capacity) { + public IntList(int capacity) { entries = new int[capacity]; } @@ -102,7 +102,7 @@ public class IntList { * @throws java.lang.ArrayIndexOutOfBoundsException * the index outside the valid range */ - public int get(final int i) { + public int get(int i) { if (count <= i) throw new ArrayIndexOutOfBoundsException(i); return entries[i]; @@ -121,7 +121,7 @@ public class IntList { * @param n * the number to add. */ - public void add(final int n) { + public void add(int n) { if (count == entries.length) grow(); entries[count++] = n; @@ -135,7 +135,7 @@ public class IntList { * @param n * value to store at the position. */ - public void set(final int index, final int n) { + public void set(int index, int n) { if (count < index) throw new ArrayIndexOutOfBoundsException(index); else if (count == index) @@ -154,7 +154,7 @@ public class IntList { * @param val * value to insert into padded positions. */ - public void fillTo(int toIndex, final int val) { + public void fillTo(int toIndex, int val) { while (count < toIndex) add(val); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/LongList.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/LongList.java index 404594cf79..3bd6e18264 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/LongList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/LongList.java @@ -67,7 +67,7 @@ public class LongList { * @param capacity * number of entries the list can initially hold. */ - public LongList(final int capacity) { + public LongList(int capacity) { entries = new long[capacity]; } @@ -89,7 +89,7 @@ public class LongList { * @throws java.lang.ArrayIndexOutOfBoundsException * the index outside the valid range */ - public long get(final int i) { + public long get(int i) { if (count <= i) throw new ArrayIndexOutOfBoundsException(i); return entries[i]; @@ -102,7 +102,7 @@ public class LongList { * the value to search for. * @return true of {@code value} appears in this list. */ - public boolean contains(final long value) { + public boolean contains(long value) { for (int i = 0; i < count; i++) if (entries[i] == value) return true; @@ -122,7 +122,7 @@ public class LongList { * @param n * the number to add. */ - public void add(final long n) { + public void add(long n) { if (count == entries.length) grow(); entries[count++] = n; @@ -136,7 +136,7 @@ public class LongList { * @param n * value to store at the position. */ - public void set(final int index, final long n) { + public void set(int index, long n) { if (count < index) throw new ArrayIndexOutOfBoundsException(index); else if (count == index) @@ -155,7 +155,7 @@ public class LongList { * @param val * value to insert into padded positions. */ - public void fillTo(int toIndex, final long val) { + public void fillTo(int toIndex, long val) { while (count < toIndex) add(val); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java index 09eee42024..8c7f672848 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/LongMap.java @@ -144,7 +144,7 @@ public class LongMap<V> { return null; } - private void insert(final Node<V> n) { + private void insert(Node<V> n) { final int idx = index(n.key); n.next = table[idx]; table[idx] = n; @@ -166,14 +166,14 @@ public class LongMap<V> { } } - private final int index(final long key) { + private final int index(long key) { int h = ((int) key) >>> 1; h ^= (h >>> 20) ^ (h >>> 12); return h & (table.length - 1); } @SuppressWarnings("unchecked") - private static final <V> Node<V>[] createArray(final int sz) { + private static final <V> Node<V>[] createArray(int sz) { return new Node[sz]; } @@ -182,7 +182,7 @@ public class LongMap<V> { V value; Node<V> next; - Node(final long k, final V v) { + Node(long k, V v) { key = k; value = v; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java index 77bc2495fb..4d58d0614a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java @@ -99,7 +99,7 @@ public abstract class QuotedString { * @return the cleaned string. * @see #dequote(byte[], int, int) */ - public String dequote(final String in) { + public String dequote(String in) { final byte[] b = Constants.encode(in); return dequote(b, 0, b.length); } @@ -137,7 +137,7 @@ public abstract class QuotedString { */ public static class BourneStyle extends QuotedString { @Override - public String quote(final String in) { + public String quote(String in) { final StringBuilder r = new StringBuilder(); r.append('\''); int start = 0, i = 0; @@ -160,7 +160,7 @@ public abstract class QuotedString { } @Override - public String dequote(final byte[] in, int ip, final int ie) { + public String dequote(byte[] in, int ip, int ie) { boolean inquote = false; final byte[] r = new byte[ie - ip]; int rPtr = 0; @@ -188,7 +188,7 @@ public abstract class QuotedString { /** Bourne style, but permits <code>~user</code> at the start of the string. */ public static class BourneUserPathStyle extends BourneStyle { @Override - public String quote(final String in) { + public String quote(String in) { if (in.matches("^~[A-Za-z0-9_-]+$")) { //$NON-NLS-1$ // If the string is just "~user" we can assume they // mean "~user/". @@ -255,7 +255,7 @@ public abstract class QuotedString { } @Override - public String quote(final String instr) { + public String quote(String instr) { if (instr.length() == 0) return "\"\""; //$NON-NLS-1$ boolean reuse = true; @@ -291,13 +291,13 @@ public abstract class QuotedString { } @Override - public String dequote(final byte[] in, final int inPtr, final int inEnd) { + public String dequote(byte[] in, int inPtr, int inEnd) { if (2 <= inEnd - inPtr && in[inPtr] == '"' && in[inEnd - 1] == '"') return dq(in, inPtr + 1, inEnd - 1); return RawParseUtils.decode(Constants.CHARSET, in, inPtr, inEnd); } - private static String dq(final byte[] in, int inPtr, final int inEnd) { + private static String dq(byte[] in, int inPtr, int inEnd) { final byte[] r = new byte[inEnd - inPtr]; int rPtr = 0; while (inPtr < inEnd) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawCharSequence.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawCharSequence.java index 23ee9d0d64..42060c659e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawCharSequence.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawCharSequence.java @@ -68,7 +68,7 @@ public final class RawCharSequence implements CharSequence { * @param end * ending position for the sequence. */ - public RawCharSequence(final byte[] buf, final int start, final int end) { + public RawCharSequence(byte[] buf, int start, int end) { buffer = buf; startPtr = start; endPtr = end; @@ -76,7 +76,7 @@ public final class RawCharSequence implements CharSequence { /** {@inheritDoc} */ @Override - public char charAt(final int index) { + public char charAt(int index) { return (char) (buffer[startPtr + index] & 0xff); } @@ -88,7 +88,7 @@ public final class RawCharSequence implements CharSequence { /** {@inheritDoc} */ @Override - public CharSequence subSequence(final int start, final int end) { + public CharSequence subSequence(int start, int end) { return new RawCharSequence(buffer, startPtr + start, startPtr + end); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java index 014c7727a8..c22c8de5d1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -63,6 +63,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.jgit.annotations.Nullable; +import org.eclipse.jgit.errors.BinaryBlobException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.PersonIdent; @@ -125,7 +126,7 @@ public final class RawParseUtils { * the buffer to test for equality with b. * @return ptr + src.length if b[ptr..src.length] == src; else -1. */ - public static final int match(final byte[] b, int ptr, final byte[] src) { + public static final int match(byte[] b, int ptr, byte[] src) { if (ptr + src.length > b.length) return -1; for (int i = 0; i < src.length; i++, ptr++) @@ -461,7 +462,7 @@ public final class RawParseUtils { * position within buffer to start parsing digits at. * @return the timezone at this location, expressed in minutes. */ - public static final int parseTimeZoneOffset(final byte[] b, int ptr) { + public static final int parseTimeZoneOffset(byte[] b, int ptr) { return parseTimeZoneOffset(b, ptr, null); } @@ -500,7 +501,7 @@ public final class RawParseUtils { * character to find. * @return new position just after chrA. */ - public static final int next(final byte[] b, int ptr, final char chrA) { + public static final int next(byte[] b, int ptr, char chrA) { final int sz = b.length; while (ptr < sz) { if (b[ptr++] == chrA) @@ -520,7 +521,7 @@ public final class RawParseUtils { * position within buffer to start looking for LF at. * @return new position just after the first LF found. */ - public static final int nextLF(final byte[] b, int ptr) { + public static final int nextLF(byte[] b, int ptr) { return next(b, ptr, '\n'); } @@ -537,7 +538,7 @@ public final class RawParseUtils { * character to find. * @return new position just after the first chrA or LF to be found. */ - public static final int nextLF(final byte[] b, int ptr, final char chrA) { + public static final int nextLF(byte[] b, int ptr, char chrA) { final int sz = b.length; while (ptr < sz) { final byte c = b[ptr++]; @@ -558,7 +559,7 @@ public final class RawParseUtils { * character to find. * @return new position just before chrA, -1 for not found */ - public static final int prev(final byte[] b, int ptr, final char chrA) { + public static final int prev(byte[] b, int ptr, char chrA) { if (ptr == b.length) --ptr; while (ptr >= 0) { @@ -579,7 +580,7 @@ public final class RawParseUtils { * position within buffer to start looking for LF at. * @return new position just before the first LF found, -1 for not found */ - public static final int prevLF(final byte[] b, int ptr) { + public static final int prevLF(byte[] b, int ptr) { return prev(b, ptr, '\n'); } @@ -597,7 +598,7 @@ public final class RawParseUtils { * @return new position just before the first chrA or LF to be found, -1 for * not found */ - public static final int prevLF(final byte[] b, int ptr, final char chrA) { + public static final int prevLF(byte[] b, int ptr, char chrA) { if (ptr == b.length) --ptr; while (ptr >= 0) { @@ -632,11 +633,47 @@ public final class RawParseUtils { * line 1. * @param end * 1 past the end of the content within <code>buf</code>. - * @return a line map indexing the start position of each line. + * @return a line map indicating the starting position of each line, or a + * map representing the entire buffer as a single line if + * <code>buf</code> contains a NUL byte. */ - public static final IntList lineMap(final byte[] buf, int ptr, int end) { - int start = ptr; + public static final IntList lineMap(byte[] buf, int ptr, int end) { + IntList map = lineMapOrNull(buf, ptr, end); + if (map == null) { + map = new IntList(3); + map.add(Integer.MIN_VALUE); + map.add(ptr); + map.add(end); + } + return map; + } + + /** + * Like {@link #lineMap(byte[], int, int)} but throw + * {@link BinaryBlobException} if a NUL byte is encountered. + * + * @param buf + * buffer to scan. + * @param ptr + * position within the buffer corresponding to the first byte of + * line 1. + * @param end + * 1 past the end of the content within <code>buf</code>. + * @return a line map indicating the starting position of each line. + * @throws BinaryBlobException + * if a NUL byte is found. + * @since 5.0 + */ + public static final IntList lineMapOrBinary(byte[] buf, int ptr, int end) + throws BinaryBlobException { + IntList map = lineMapOrNull(buf, ptr, end); + if (map == null) { + throw new BinaryBlobException(); + } + return map; + } + private static @Nullable IntList lineMapOrNull(byte[] buf, int ptr, int end) { // Experimentally derived from multiple source repositories // the average number of bytes/line is 36. Its a rough guess // to initially size our map close to the target. @@ -649,11 +686,7 @@ public final class RawParseUtils { } if (buf[ptr] == '\0') { - // binary data. - map = new IntList(3); - map.add(Integer.MIN_VALUE); - map.add(start); - break; + return null; } foundLF = (buf[ptr] == '\n'); @@ -675,7 +708,7 @@ public final class RawParseUtils { * character of the author's name. If no author header can be * located -1 is returned. */ - public static final int author(final byte[] b, int ptr) { + public static final int author(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 46; // skip the "tree ..." line. @@ -697,7 +730,7 @@ public final class RawParseUtils { * character of the committer's name. If no committer header can be * located -1 is returned. */ - public static final int committer(final byte[] b, int ptr) { + public static final int committer(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 46; // skip the "tree ..." line. @@ -721,7 +754,7 @@ public final class RawParseUtils { * character of the tagger's name. If no tagger header can be * located -1 is returned. */ - public static final int tagger(final byte[] b, int ptr) { + public static final int tagger(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 48; // skip the "object ..." line. @@ -749,7 +782,7 @@ public final class RawParseUtils { * character of the encoding's name. If no encoding header can be * located -1 is returned (and UTF-8 should be assumed). */ - public static final int encoding(final byte[] b, int ptr) { + public static final int encoding(byte[] b, int ptr) { final int sz = b.length; while (ptr < sz) { if (b[ptr] == '\n') @@ -773,7 +806,7 @@ public final class RawParseUtils { * @since 4.2 */ @Nullable - public static String parseEncodingName(final byte[] b) { + public static String parseEncodingName(byte[] b) { int enc = encoding(b, 0); if (enc < 0) { return null; @@ -801,7 +834,7 @@ public final class RawParseUtils { * if the JRE does not support the character set requested by * the encoding header. */ - public static Charset parseEncoding(final byte[] b) { + public static Charset parseEncoding(byte[] b) { String enc = parseEncodingName(b); if (enc == null) { return UTF_8; @@ -831,7 +864,7 @@ public final class RawParseUtils { * @return the parsed identity or null in case the identity could not be * parsed. */ - public static PersonIdent parsePersonIdent(final String in) { + public static PersonIdent parsePersonIdent(String in) { return parsePersonIdent(Constants.encode(in), 0); } @@ -853,7 +886,7 @@ public final class RawParseUtils { * @return the parsed identity or null in case the identity could not be * parsed. */ - public static PersonIdent parsePersonIdent(final byte[] raw, final int nameB) { + public static PersonIdent parsePersonIdent(byte[] raw, int nameB) { Charset cs; try { cs = parseEncoding(raw); @@ -961,7 +994,7 @@ public final class RawParseUtils { * @return position of the ':' which terminates the footer line key if this * is otherwise a valid footer line key; otherwise -1. */ - public static int endOfFooterLineKey(final byte[] raw, int ptr) { + public static int endOfFooterLineKey(byte[] raw, int ptr) { try { for (;;) { final byte c = raw[ptr]; @@ -988,7 +1021,7 @@ public final class RawParseUtils { * @return a string representation of the range <code>[start,end)</code>, * after decoding the region through the specified character set. */ - public static String decode(final byte[] buffer) { + public static String decode(byte[] buffer) { return decode(buffer, 0, buffer.length); } @@ -1026,7 +1059,7 @@ public final class RawParseUtils { * @return a string representation of the range <code>[start,end)</code>, * after decoding the region through the specified character set. */ - public static String decode(final Charset cs, final byte[] buffer) { + public static String decode(Charset cs, byte[] buffer) { return decode(cs, buffer, 0, buffer.length); } @@ -1143,7 +1176,7 @@ public final class RawParseUtils { return r.toString(); } - private static String decode(final ByteBuffer b, final Charset charset) + private static String decode(ByteBuffer b, Charset charset) throws CharacterCodingException { final CharsetDecoder d = charset.newDecoder(); d.onMalformedInput(CodingErrorAction.REPORT); @@ -1162,7 +1195,7 @@ public final class RawParseUtils { * commit buffer. * @return position of the user's message buffer. */ - public static final int commitMessage(final byte[] b, int ptr) { + public static final int commitMessage(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 46; // skip the "tree ..." line. @@ -1186,7 +1219,7 @@ public final class RawParseUtils { * buffer. * @return position of the user's message buffer. */ - public static final int tagMessage(final byte[] b, int ptr) { + public static final int tagMessage(byte[] b, int ptr) { final int sz = b.length; if (ptr == 0) ptr += 48; // skip the "object ..." line. @@ -1211,7 +1244,7 @@ public final class RawParseUtils { * @return position of the LF at the end of the paragraph; * <code>b.length</code> if no paragraph end could be located. */ - public static final int endOfParagraph(final byte[] b, final int start) { + public static final int endOfParagraph(byte[] b, int start) { int ptr = start; final int sz = b.length; while (ptr < sz && (b[ptr] != '\n' && b[ptr] != '\r')) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawSubStringPattern.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawSubStringPattern.java index a8f9bc72eb..040b5cbc37 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawSubStringPattern.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawSubStringPattern.java @@ -66,7 +66,7 @@ public class RawSubStringPattern { * meta-characters are supported by this implementation. The * string may not be the empty string. */ - public RawSubStringPattern(final String patternText) { + public RawSubStringPattern(String patternText) { if (patternText.length() == 0) throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString); needleString = patternText; @@ -87,7 +87,7 @@ public class RawSubStringPattern { * pattern; -1 if this pattern does not appear at any position of * <code>rcs</code>. */ - public int match(final RawCharSequence rcs) { + public int match(RawCharSequence rcs) { final int needleLen = needle.length; final byte first = needle[0]; @@ -114,11 +114,11 @@ public class RawSubStringPattern { return -1; } - private static final boolean neq(final byte a, final byte b) { + private static final boolean neq(byte a, byte b) { return a != b && a != lc(b); } - private static final byte lc(final byte q) { + private static final byte lc(byte q) { return (byte) StringUtils.toLowerCase((char) (q & 0xff)); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RefMap.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RefMap.java index c1aaecfd91..a3f9730f13 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RefMap.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RefMap.java @@ -169,7 +169,7 @@ public class RefMap extends AbstractMap<String, Ref> { /** {@inheritDoc} */ @Override - public Ref put(final String keyName, Ref value) { + public Ref put(String keyName, Ref value) { String name = toRefName(keyName); if (!name.equals(value.getName())) @@ -355,7 +355,7 @@ public class RefMap extends AbstractMap<String, Ref> { return null; } - private Ref resolveLoose(final Ref l) { + private Ref resolveLoose(Ref l) { if (resolvedIdx < resolved.size()) { Ref r = resolved.get(resolvedIdx); int cmp = RefComparator.compareTo(l, r); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java new file mode 100644 index 0000000000..913aa72867 --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2018, Markus Duft <markus.duft@ssi-schaefer.com> + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.util; + +import java.io.IOException; +import java.text.MessageFormat; + +import org.eclipse.jgit.annotations.Nullable; +import org.eclipse.jgit.errors.CommandFailedException; +import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.eclipse.jgit.transport.RemoteSession; +import org.eclipse.jgit.transport.SshSessionFactory; +import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.util.io.MessageWriter; +import org.eclipse.jgit.util.io.StreamCopyThread; + +/** + * Extra utilities to support usage of SSH. + * + * @since 5.0 + */ +public class SshSupport { + + /** + * Utility to execute a remote SSH command and read the first line of + * output. + * + * @param sshUri + * the SSH remote URI + * @param provider + * the {@link CredentialsProvider} or <code>null</code>. + * @param fs + * the {@link FS} implementation passed to + * {@link SshSessionFactory} + * @param command + * the remote command to execute. + * @param timeout + * a timeout in seconds. The timeout may be exceeded in corner + * cases. + * @return The entire output read from stdout. + * @throws IOException + * @throws CommandFailedException + * if the ssh command execution failed, error message contains + * the content of stderr. + */ + public static String runSshCommand(URIish sshUri, + @Nullable CredentialsProvider provider, FS fs, String command, + int timeout) throws IOException, CommandFailedException { + RemoteSession session = null; + Process process = null; + StreamCopyThread errorThread = null; + StreamCopyThread outThread = null; + CommandFailedException failure = null; + @SuppressWarnings("resource") + MessageWriter stderr = new MessageWriter(); + try (MessageWriter stdout = new MessageWriter()) { + session = SshSessionFactory.getInstance().getSession(sshUri, + provider, fs, 1000 * timeout); + process = session.exec(command, 0); + errorThread = new StreamCopyThread(process.getErrorStream(), + stderr.getRawStream()); + errorThread.start(); + outThread = new StreamCopyThread(process.getInputStream(), + stdout.getRawStream()); + outThread.start(); + try { + // waitFor with timeout has a bug - JSch' exitValue() throws the + // wrong exception type :( + if (process.waitFor() == 0) { + return stdout.toString(); + } else { + return null; // still running after timeout + } + } catch (InterruptedException e) { + return null; // error + } + } finally { + if (errorThread != null) { + try { + errorThread.halt(); + } catch (InterruptedException e) { + // Stop waiting and return anyway. + } finally { + errorThread = null; + } + } + if (outThread != null) { + try { + outThread.halt(); + } catch (InterruptedException e) { + // Stop waiting and return anyway. + } finally { + outThread = null; + } + } + if (process != null) { + if (process.exitValue() != 0) { + failure = new CommandFailedException(process.exitValue(), + MessageFormat.format( + JGitText.get().sshCommandFailed, command, + stderr.toString())); + } + process.destroy(); + } + stderr.close(); + if (session != null) { + SshSessionFactory.getInstance().releaseSession(session); + } + if (failure != null) { + throw failure; + } + } + } + +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java index b4736d3e40..3868e56f50 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java @@ -74,7 +74,7 @@ public final class StringUtils { * the input character. * @return lowercase version of the input. */ - public static char toLowerCase(final char c) { + public static char toLowerCase(char c) { return c <= 'Z' ? LC[c] : c; } @@ -91,7 +91,7 @@ public final class StringUtils { * @return a copy of the input string, after converting characters in the * range 'A'..'Z' to 'a'..'z'. */ - public static String toLowerCase(final String in) { + public static String toLowerCase(String in) { final StringBuilder r = new StringBuilder(in.length()); for (int i = 0; i < in.length(); i++) r.append(toLowerCase(in.charAt(i))); @@ -138,7 +138,7 @@ public final class StringUtils { * second string to compare. * @return true if a equals b */ - public static boolean equalsIgnoreCase(final String a, final String b) { + public static boolean equalsIgnoreCase(String a, String b) { if (a == b) return true; if (a.length() != b.length()) @@ -205,7 +205,7 @@ public final class StringUtils { * if {@code value} is not recognized as one of the standard * boolean names. */ - public static boolean toBoolean(final String stringValue) { + public static boolean toBoolean(String stringValue) { if (stringValue == null) throw new NullPointerException(JGitText.get().expectedBooleanStringValue); @@ -232,7 +232,7 @@ public final class StringUtils { * @return the boolean interpretation of {@code value} or null in case the * string does not represent a boolean value */ - public static Boolean toBooleanOrNull(final String stringValue) { + public static Boolean toBooleanOrNull(String stringValue) { if (stringValue == null) return null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java index 96a796cbdc..953c9768f9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java @@ -237,7 +237,7 @@ public abstract class SystemReader { public abstract FileBasedConfig openUserConfig(Config parent, FS fs); /** - * Open the gitonfig configuration found in the system-wide "etc" directory + * Open the gitconfig configuration found in the system-wide "etc" directory * * @param parent * a config with values not found directly in the returned @@ -245,7 +245,7 @@ public abstract class SystemReader { * @param fs * the file system abstraction which will be necessary to perform * certain file system operations. - * @return the gitonfig configuration found in the system-wide "etc" + * @return the gitconfig configuration found in the system-wide "etc" * directory */ public abstract FileBasedConfig openSystemConfig(Config parent, FS fs); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java index dd933a0294..3ed7aeb954 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java @@ -91,7 +91,7 @@ public abstract class TemporaryBuffer extends OutputStream { * maximum number of bytes to store in memory before entering the * overflow output path; also used as the estimated size. */ - protected TemporaryBuffer(final int limit) { + protected TemporaryBuffer(int limit) { this(limit, limit); } @@ -106,7 +106,7 @@ public abstract class TemporaryBuffer extends OutputStream { * overflow output path. * @since 4.0 */ - protected TemporaryBuffer(final int estimatedSize, final int limit) { + protected TemporaryBuffer(int estimatedSize, int limit) { if (estimatedSize > limit) throw new IllegalArgumentException(); this.inCoreLimit = limit; @@ -116,7 +116,7 @@ public abstract class TemporaryBuffer extends OutputStream { /** {@inheritDoc} */ @Override - public void write(final int b) throws IOException { + public void write(int b) throws IOException { if (overflow != null) { overflow.write(b); return; @@ -137,7 +137,7 @@ public abstract class TemporaryBuffer extends OutputStream { /** {@inheritDoc} */ @Override - public void write(final byte[] b, int off, int len) throws IOException { + public void write(byte[] b, int off, int len) throws IOException { if (overflow == null) { while (len > 0) { Block s = last(); @@ -183,7 +183,7 @@ public abstract class TemporaryBuffer extends OutputStream { * an error occurred reading from the input stream, or while * writing to a local temporary file. */ - public void copy(final InputStream in) throws IOException { + public void copy(InputStream in) throws IOException { if (blocks != null) { for (;;) { Block s = last(); @@ -238,7 +238,7 @@ public abstract class TemporaryBuffer extends OutputStream { throw new OutOfMemoryError(JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; - for (final Block b : blocks) { + for (Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } @@ -265,7 +265,7 @@ public abstract class TemporaryBuffer extends OutputStream { JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; - for (final Block b : blocks) { + for (Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } @@ -288,11 +288,11 @@ public abstract class TemporaryBuffer extends OutputStream { * an error occurred reading from a temporary file on the local * system, or writing to the output stream. */ - public void writeTo(final OutputStream os, ProgressMonitor pm) + public void writeTo(OutputStream os, ProgressMonitor pm) throws IOException { if (pm == null) pm = NullProgressMonitor.INSTANCE; - for (final Block b : blocks) { + for (Block b : blocks) { os.write(b.buffer, 0, b.count); pm.update(b.count / 1024); } @@ -373,7 +373,7 @@ public abstract class TemporaryBuffer extends OutputStream { overflow = overflow(); final Block last = blocks.remove(blocks.size() - 1); - for (final Block b : blocks) + for (Block b : blocks) overflow.write(b.buffer, 0, b.count); blocks = null; @@ -442,7 +442,7 @@ public abstract class TemporaryBuffer extends OutputStream { * system default temporary directory (for example /tmp) will * be used instead. */ - public LocalFile(final File directory) { + public LocalFile(File directory) { this(directory, DEFAULT_IN_CORE_LIMIT); } @@ -458,7 +458,7 @@ public abstract class TemporaryBuffer extends OutputStream { * maximum number of bytes to store in memory. Storage beyond * this limit will use the local file. */ - public LocalFile(final File directory, final int inCoreLimit) { + public LocalFile(File directory, int inCoreLimit) { super(inCoreLimit); this.directory = directory; } @@ -487,17 +487,14 @@ public abstract class TemporaryBuffer extends OutputStream { if (Integer.MAX_VALUE < len) throw new OutOfMemoryError(JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; - final FileInputStream in = new FileInputStream(onDiskFile); - try { + try (FileInputStream in = new FileInputStream(onDiskFile)) { IO.readFully(in, out, 0, (int) len); - } finally { - in.close(); } return out; } @Override - public void writeTo(final OutputStream os, ProgressMonitor pm) + public void writeTo(OutputStream os, ProgressMonitor pm) throws IOException { if (onDiskFile == null) { super.writeTo(os, pm); @@ -505,16 +502,13 @@ public abstract class TemporaryBuffer extends OutputStream { } if (pm == null) pm = NullProgressMonitor.INSTANCE; - final FileInputStream in = new FileInputStream(onDiskFile); - try { + try (FileInputStream in = new FileInputStream(onDiskFile)) { int cnt; final byte[] buf = new byte[Block.SZ]; while ((cnt = in.read(buf)) >= 0) { os.write(buf, 0, cnt); pm.update(cnt / 1024); } - } finally { - in.close(); } } @@ -569,7 +563,7 @@ public abstract class TemporaryBuffer extends OutputStream { * also used as the estimated size. Storing beyond this many * will cause an IOException to be thrown during write. */ - public Heap(final int limit) { + public Heap(int limit) { super(limit); } @@ -585,7 +579,7 @@ public abstract class TemporaryBuffer extends OutputStream { * thrown during write. * @since 4.0 */ - public Heap(final int estimatedSize, final int limit) { + public Heap(int estimatedSize, int limit) { super(estimatedSize, limit); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java index 45668255e5..08377e6be0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java @@ -100,7 +100,7 @@ public class AutoCRLFInputStream extends InputStream { /** {@inheritDoc} */ @Override - public int read(byte[] bs, final int off, final int len) throws IOException { + public int read(byte[] bs, int off, int len) throws IOException { if (len == 0) return 0; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java index e764389ac8..d8cfee7c46 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java @@ -113,7 +113,7 @@ public class AutoCRLFOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public void write(byte[] b, final int startOff, final int startLen) + public void write(byte[] b, int startOff, int startLen) throws IOException { final int overflow = buffer(b, startOff, startLen); if (overflow < 0) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java index 06f83f3ed9..ff28161a52 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFInputStream.java @@ -134,7 +134,7 @@ public class AutoLFInputStream extends InputStream { /** {@inheritDoc} */ @Override - public int read(byte[] bs, final int off, final int len) + public int read(byte[] bs, int off, int len) throws IOException { if (len == 0) return 0; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java index 32226c4af4..908d0a0b44 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java @@ -120,7 +120,7 @@ public class AutoLFOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public void write(byte[] b, final int startOff, final int startLen) + public void write(byte[] b, int startOff, int startLen) throws IOException { final int overflow = buffer(b, startOff, startLen); if (overflow < 0) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java deleted file mode 100644 index dd9a95306f..0000000000 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2010, 2013 Marc Strapetz <marc.strapetz@syntevo.com> - * and other copyright owners as documented in the project's IP log. - * - * This program and the accompanying materials are made available - * under the terms of the Eclipse Distribution License v1.0 which - * accompanies this distribution, is reproduced below, and is - * available at http://www.eclipse.org/org/documents/edl-v10.php - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Eclipse Foundation, Inc. nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.eclipse.jgit.util.io; - -import java.io.IOException; -import java.io.InputStream; - -/** - * An input stream which canonicalizes EOLs bytes on the fly to '\n'. - * - * Optionally, a binary check on the first 8000 bytes is performed and in case - * of binary files, canonicalization is turned off (for the complete file). - * - * @deprecated use {@link org.eclipse.jgit.util.io.AutoLFInputStream} instead - */ -@Deprecated -public class EolCanonicalizingInputStream extends AutoLFInputStream { - - /** - * Creates a new InputStream, wrapping the specified stream - * - * @param in - * raw input stream - * @param detectBinary - * whether binaries should be detected - */ - public EolCanonicalizingInputStream(InputStream in, boolean detectBinary) { - super(in, detectBinary); - } - - /** - * Creates a new InputStream, wrapping the specified stream - * - * @param in - * raw input stream - * @param detectBinary - * whether binaries should be detected - * @param abortIfBinary - * throw an IOException if the file is binary - */ - public EolCanonicalizingInputStream(InputStream in, boolean detectBinary, - boolean abortIfBinary) { - super(in, detectBinary, abortIfBinary); - } - - /** - * A special exception thrown when {@link AutoLFInputStream} is told to - * throw an exception when attempting to read a binary file. The exception - * may be thrown at any stage during reading. - * - * @since 3.3 - */ - public static class IsBinaryException extends IOException { - private static final long serialVersionUID = 1L; - - IsBinaryException() { - super(); - } - } - -} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java index f400e50cd3..b7feddda57 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/InterruptTimer.java @@ -103,7 +103,7 @@ public final class InterruptTimer { * @param threadName * name of the timer thread. */ - public InterruptTimer(final String threadName) { + public InterruptTimer(String threadName) { state = new AlarmState(); autoKiller = new AutoKiller(state); thread = new AlarmThread(threadName, state); @@ -117,7 +117,7 @@ public final class InterruptTimer { * number of milliseconds before the interrupt should trigger. * Must be > 0. */ - public void begin(final int timeout) { + public void begin(int timeout) { if (timeout <= 0) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidTimeout, Integer.valueOf(timeout))); @@ -145,7 +145,7 @@ public final class InterruptTimer { } static final class AlarmThread extends Thread { - AlarmThread(final String name, final AlarmState q) { + AlarmThread(String name, AlarmState q) { super(q); setName(name); setDaemon(true); @@ -161,7 +161,7 @@ public final class InterruptTimer { private static final class AutoKiller { private final AlarmState state; - AutoKiller(final AlarmState s) { + AutoKiller(AlarmState s) { state = s; } @@ -203,7 +203,7 @@ public final class InterruptTimer { } } - synchronized void begin(final int timeout) { + synchronized void begin(int timeout) { if (terminated) throw new IllegalStateException(JGitText.get().timerAlreadyTerminated); callingThread = Thread.currentThread(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java index 5e50995a2a..65470d4ef1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/IsolatedOutputStream.java @@ -99,7 +99,7 @@ public class IsolatedOutputStream extends OutputStream { /** {@inheritDoc} */ @Override - public void write(final byte[] buf, final int pos, final int cnt) + public void write(byte[] buf, int pos, int cnt) throws IOException { checkClosed(); execute(new Callable<Void>() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentFileInputStream.java index 68b417e5d1..e58803bb9b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentFileInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011, Robin Rosenberg + * Copyright (C) 2018, David Pursehouse <david.pursehouse@gmail.com> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -40,39 +40,36 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + package org.eclipse.jgit.util.io; -import java.io.BufferedOutputStream; -import java.io.OutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; /** - * <p>SafeBufferedOutputStream class.</p> + * An implementation of FileInputStream that ignores any exceptions on close(). * - * @deprecated use BufferedOutputStream in Java 8 and later. + * @since 5.0 */ -@Deprecated -public class SafeBufferedOutputStream extends BufferedOutputStream { +public class SilentFileInputStream extends FileInputStream { /** - * <p>Constructor for SafeBufferedOutputStream.</p> - * - * @see BufferedOutputStream#BufferedOutputStream(OutputStream) - * @param out - * underlying output stream + * @param file + * the file + * @throws FileNotFoundException + * the file was not found */ - public SafeBufferedOutputStream(OutputStream out) { - super(out); + public SilentFileInputStream(File file) throws FileNotFoundException { + super(file); } - /** - * <p>Constructor for SafeBufferedOutputStream.</p> - * - * @see BufferedOutputStream#BufferedOutputStream(OutputStream, int) - * @param out - * underlying output stream - * @param size - * buffer size - */ - public SafeBufferedOutputStream(OutputStream out, int size) { - super(out, size); + @Override + public void close() { + try { + super.close(); + } catch (IOException e) { + // Ignore + } } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java index 5c1af9efad..a9989a1c28 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java @@ -73,7 +73,7 @@ public class StreamCopyThread extends Thread { * stream to copy into. The destination stream is automatically * closed when the thread terminates. */ - public StreamCopyThread(final InputStream i, final OutputStream o) { + public StreamCopyThread(InputStream i, OutputStream o) { setName(Thread.currentThread().getName() + "-StreamCopy"); //$NON-NLS-1$ src = i; dst = o; @@ -81,20 +81,6 @@ public class StreamCopyThread extends Thread { } /** - * Request the thread to flush the output stream as soon as possible. - * <p> - * This is an asynchronous request to the thread. The actual flush will - * happen at some future point in time, when the thread wakes up to process - * the request. - */ - @Deprecated - public void flush() { - synchronized (writeLock) { - interrupt(); - } - } - - /** * Request that the thread terminate, and wait for it. * <p> * This method signals to the copy thread that it should stop as soon as diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java index dee4fe9e91..e40a5a4cee 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java @@ -89,7 +89,7 @@ public class TeeInputStream extends InputStream { /** {@inheritDoc} */ @Override - public long skip(final long count) throws IOException { + public long skip(long count) throws IOException { long skipped = 0; long cnt = count; final byte[] b = skipBuffer(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java index 01b25195ff..2392b8ae23 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutInputStream.java @@ -89,7 +89,7 @@ public class TimeoutInputStream extends FilterInputStream { * @param millis * number of milliseconds before aborting a read. Must be > 0. */ - public void setTimeout(final int millis) { + public void setTimeout(int millis) { if (millis < 0) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidTimeout, Integer.valueOf(millis))); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java index ea40133383..27f18740f4 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/TimeoutOutputStream.java @@ -91,7 +91,7 @@ public class TimeoutOutputStream extends OutputStream { * number of milliseconds before aborting a write. Must be > * 0. */ - public void setTimeout(final int millis) { + public void setTimeout(int millis) { if (millis < 0) throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidTimeout, Integer.valueOf(millis))); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java index 51d3106aa5..e14eb2b600 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java @@ -107,7 +107,7 @@ public class UnionInputStream extends InputStream { * @param in * the stream to add; must not be null. */ - public void add(final InputStream in) { + public void add(InputStream in) { streams.add(in); } @@ -164,7 +164,7 @@ public class UnionInputStream extends InputStream { /** {@inheritDoc} */ @Override - public long skip(final long count) throws IOException { + public long skip(long count) throws IOException { long skipped = 0; long cnt = count; while (0 < cnt) { |