aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/META-INF/MANIFEST.MF92
-rw-r--r--org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF4
-rw-r--r--org.eclipse.jgit/pom.xml2
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ArchiveCommand.java24
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/FetchCommand.java43
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java14
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/errors/EmptyCommitException.java (renamed from org.eclipse.jgit/src/org/eclipse/jgit/api/errors/EmtpyCommitException.java)12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/errors/StoredObjectRepresentationNotAvailableException.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java29
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsInserter.java33
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackCompactor.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsPackFile.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsStreamKey.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/BitmapIndexImpl.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LazyObjectIdSetFile.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java18
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ObjectDirectoryPackParser.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackBitmapIndex.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java18
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java318
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BitmapIndex.java13
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectLoader.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoFile.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java31
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/TextProgressMonitor.java4
-rwxr-xr-xorg.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java55
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevTag.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java24
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/HMACSHA1NonceGenerator.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpAuthMethod.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/NetRC.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java58
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/ProgressSpinner.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateIdent.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificateStore.java6
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java45
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java5
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java92
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java77
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLoggerChain.java96
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java17
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java49
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtil.java303
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java27
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/HttpSupport.java4
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java120
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java102
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/SilentFileInputStream.java (renamed from org.eclipse.jgit/src/org/eclipse/jgit/util/io/SafeBufferedOutputStream.java)47
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/StreamCopyThread.java14
83 files changed, 613 insertions, 1639 deletions
diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF
index 6528e059c0..3e49a0462d 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.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
-Export-Package: org.eclipse.jgit.annotations;version="4.11.1",
- org.eclipse.jgit.api;version="4.11.1";
+Export-Package: org.eclipse.jgit.annotations;version="5.0.0",
+ org.eclipse.jgit.api;version="5.0.0";
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.1",
org.eclipse.jgit.submodule,
org.eclipse.jgit.transport,
org.eclipse.jgit.merge",
- org.eclipse.jgit.api.errors;version="4.11.1";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.errors",
- org.eclipse.jgit.attributes;version="4.11.1",
- org.eclipse.jgit.blame;version="4.11.1";
+ org.eclipse.jgit.api.errors;version="5.0.0";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.errors",
+ org.eclipse.jgit.attributes;version="5.0.0",
+ org.eclipse.jgit.blame;version="5.0.0";
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.1";
+ org.eclipse.jgit.diff;version="5.0.0";
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.1";
+ org.eclipse.jgit.dircache;version="5.0.0";
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.1";
+ org.eclipse.jgit.errors;version="5.0.0";
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.1";uses:="org.eclipse.jgit.lib",
- org.eclipse.jgit.fnmatch;version="4.11.1",
- org.eclipse.jgit.gitrepo;version="4.11.1";
+ org.eclipse.jgit.events;version="5.0.0";uses:="org.eclipse.jgit.lib",
+ org.eclipse.jgit.fnmatch;version="5.0.0",
+ org.eclipse.jgit.gitrepo;version="5.0.0";
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.1";x-internal:=true,
- org.eclipse.jgit.hooks;version="4.11.1";uses:="org.eclipse.jgit.lib",
- org.eclipse.jgit.ignore;version="4.11.1",
- org.eclipse.jgit.ignore.internal;version="4.11.1";x-friends:="org.eclipse.jgit.test",
- org.eclipse.jgit.internal;version="4.11.1";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.test",
- org.eclipse.jgit.internal.fsck;version="4.11.1";x-friends:="org.eclipse.jgit.test",
- org.eclipse.jgit.internal.ketch;version="4.11.1";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
- org.eclipse.jgit.internal.storage.dfs;version="4.11.1";
+ org.eclipse.jgit.gitrepo.internal;version="5.0.0";x-internal:=true,
+ org.eclipse.jgit.hooks;version="5.0.0";uses:="org.eclipse.jgit.lib",
+ org.eclipse.jgit.ignore;version="5.0.0",
+ org.eclipse.jgit.ignore.internal;version="5.0.0";x-friends:="org.eclipse.jgit.test",
+ org.eclipse.jgit.internal;version="5.0.0";x-friends:="org.eclipse.jgit.test,org.eclipse.jgit.http.test",
+ org.eclipse.jgit.internal.fsck;version="5.0.0";x-friends:="org.eclipse.jgit.test",
+ org.eclipse.jgit.internal.ketch;version="5.0.0";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
+ org.eclipse.jgit.internal.storage.dfs;version="5.0.0";
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.1";
+ org.eclipse.jgit.internal.storage.file;version="5.0.0";
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.1",
org.eclipse.jgit.lfs,
org.eclipse.jgit.pgm,
org.eclipse.jgit.pgm.test",
- org.eclipse.jgit.internal.storage.io;version="4.11.1";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
- org.eclipse.jgit.internal.storage.pack;version="4.11.1";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
- org.eclipse.jgit.internal.storage.reftable;version="4.11.1";
+ org.eclipse.jgit.internal.storage.io;version="5.0.0";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
+ org.eclipse.jgit.internal.storage.pack;version="5.0.0";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
+ org.eclipse.jgit.internal.storage.reftable;version="5.0.0";
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.1";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
- org.eclipse.jgit.lib;version="4.11.1";
+ org.eclipse.jgit.internal.storage.reftree;version="5.0.0";x-friends:="org.eclipse.jgit.junit,org.eclipse.jgit.test,org.eclipse.jgit.pgm",
+ org.eclipse.jgit.lib;version="5.0.0";
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.1",
org.eclipse.jgit.treewalk,
org.eclipse.jgit.transport,
org.eclipse.jgit.submodule",
- org.eclipse.jgit.lib.internal;version="4.11.1";x-internal:=true,
- org.eclipse.jgit.merge;version="4.11.1";
+ org.eclipse.jgit.lib.internal;version="5.0.0";x-internal:=true,
+ org.eclipse.jgit.merge;version="5.0.0";
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.1",
- org.eclipse.jgit.notes;version="4.11.1";
+ org.eclipse.jgit.nls;version="5.0.0",
+ org.eclipse.jgit.notes;version="5.0.0";
uses:="org.eclipse.jgit.lib,
org.eclipse.jgit.treewalk,
org.eclipse.jgit.revwalk,
org.eclipse.jgit.merge",
- org.eclipse.jgit.patch;version="4.11.1";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.diff",
- org.eclipse.jgit.revplot;version="4.11.1";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.revwalk",
- org.eclipse.jgit.revwalk;version="4.11.1";
+ org.eclipse.jgit.patch;version="5.0.0";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.diff",
+ org.eclipse.jgit.revplot;version="5.0.0";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.revwalk",
+ org.eclipse.jgit.revwalk;version="5.0.0";
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.1";uses:="org.eclipse.jgit.revwalk,org.eclipse.jgit.lib,org.eclipse.jgit.util",
- org.eclipse.jgit.storage.file;version="4.11.1";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.util",
- org.eclipse.jgit.storage.pack;version="4.11.1";uses:="org.eclipse.jgit.lib",
- org.eclipse.jgit.submodule;version="4.11.1";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.treewalk.filter,org.eclipse.jgit.treewalk",
- org.eclipse.jgit.transport;version="4.11.1";
+ org.eclipse.jgit.revwalk.filter;version="5.0.0";uses:="org.eclipse.jgit.revwalk,org.eclipse.jgit.lib,org.eclipse.jgit.util",
+ org.eclipse.jgit.storage.file;version="5.0.0";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.util",
+ org.eclipse.jgit.storage.pack;version="5.0.0";uses:="org.eclipse.jgit.lib",
+ org.eclipse.jgit.submodule;version="5.0.0";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.treewalk.filter,org.eclipse.jgit.treewalk",
+ org.eclipse.jgit.transport;version="5.0.0";
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.1",
org.eclipse.jgit.transport.http,
org.eclipse.jgit.errors,
org.eclipse.jgit.storage.pack",
- org.eclipse.jgit.transport.http;version="4.11.1";uses:="javax.net.ssl",
- org.eclipse.jgit.transport.resolver;version="4.11.1";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.transport",
- org.eclipse.jgit.treewalk;version="4.11.1";
+ org.eclipse.jgit.transport.http;version="5.0.0";uses:="javax.net.ssl",
+ org.eclipse.jgit.transport.resolver;version="5.0.0";uses:="org.eclipse.jgit.lib,org.eclipse.jgit.transport",
+ org.eclipse.jgit.treewalk;version="5.0.0";
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.1";uses:="org.eclipse.jgit.treewalk",
- org.eclipse.jgit.util;version="4.11.1";
+ org.eclipse.jgit.treewalk.filter;version="5.0.0";uses:="org.eclipse.jgit.treewalk",
+ org.eclipse.jgit.util;version="5.0.0";
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.1",
- org.eclipse.jgit.util.sha1;version="4.11.1",
- org.eclipse.jgit.util.time;version="4.11.1"
+ org.eclipse.jgit.util.io;version="5.0.0",
+ org.eclipse.jgit.util.sha1;version="5.0.0",
+ org.eclipse.jgit.util.time;version="5.0.0"
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 c356bb6649..89926f409a 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.1.qualifier
-Eclipse-SourceBundle: org.eclipse.jgit;version="4.11.1.qualifier";roots="."
+Bundle-Version: 5.0.0.qualifier
+Eclipse-SourceBundle: org.eclipse.jgit;version="5.0.0.qualifier";roots="."
diff --git a/org.eclipse.jgit/pom.xml b/org.eclipse.jgit/pom.xml
index c71743bab7..d94667f304 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.1-SNAPSHOT</version>
+ <version>5.0.0-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 10139f9b89..28c414dcb2 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -307,6 +307,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.
@@ -358,6 +359,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}
@@ -664,6 +666,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
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/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
index 79b0efbe6d..f368e836ae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -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();
}
}
}
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/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/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/StashCreateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
index 3495ff8a9d..82c7a4b6c7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
@@ -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/SubmoduleStatusCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java
index 97ae668078..5c21864202 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleStatusCommand.java
@@ -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/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/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
index 8b4d2ec8fc..09c0351b80 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java
@@ -147,19 +147,13 @@ 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();
}
}
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..84bb340d24 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -49,7 +49,6 @@ 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;
@@ -87,6 +86,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).
@@ -429,18 +429,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
@@ -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);
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/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/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 753a7f9a8e..3c02302d22 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -368,6 +368,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;
@@ -419,6 +420,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;
@@ -726,6 +728,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;
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..2723fd1923 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;
}
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/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/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/GcLog.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GcLog.java
index bca7076aca..c159a94705 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.BufferedReader;
import java.io.File;
@@ -187,6 +187,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/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
index bc23dcce27..80d67cf6af 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
@@ -136,24 +136,6 @@ 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) {
ref = f;
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..b5a4d5c3fd 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
@@ -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,8 +437,6 @@ public class ObjectDirectoryPackParser extends PackParser {
iw = PackIndexWriter.createVersion(os, indexVersion);
iw.write(list, packHash);
os.getChannel().force(true);
- } finally {
- os.close();
}
}
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/PackIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackIndex.java
index acfd9c4719..e324c1f52b 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
@@ -95,20 +95,14 @@ public abstract class PackIndex
* 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);
+ 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
- }
}
}
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..8b16a2ecd7 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>
@@ -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.
@@ -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)
@@ -2062,6 +2072,24 @@ 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.
+ *
+ * @see #setFilterBlobLimit
+ */
+ 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 +2251,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/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..f44aeceb52 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;
@@ -81,8 +83,7 @@ public class BlobBasedConfig extends Config {
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/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
index 4d558c9fc2..285a56c87a 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;
@@ -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);
}
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..5c7cee6ca5 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";
@@ -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 */
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..fbdffbc48e 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();
}
}
}
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..64f2a6fc6d 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,8 +265,6 @@ public abstract class ObjectLoader {
}
if (0 <= in.read())
throw new EOFException();
- } finally {
- in.close();
}
} else {
out.write(getCachedBytes());
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/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
index 4c0bde1376..c43037ea0e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
@@ -486,7 +486,7 @@ public abstract class Repository implements AutoCloseable {
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;
@@ -709,7 +709,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 +762,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 +813,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);
}
@@ -1057,24 +1057,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".
@@ -1964,11 +1946,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..5e902c9883 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java
@@ -288,9 +288,9 @@ public class RepositoryCache {
}
private void registerRepository(final Key location, final Repository db) {
- Repository oldDb = cacheMap.put(location, db);
- if (oldDb != null)
- oldDb.close();
+ try (Repository oldDb = cacheMap.put(location, db)) {
+ // oldDb is auto-closed
+ }
}
private Repository unregisterRepository(final Key location) {
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/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index 6462608f57..17a3d6194e 100755
--- 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
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..5c8371f918 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;
@@ -539,7 +539,7 @@ public class RevCommit extends RevObject {
try {
return getEncoding();
} catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
- return UTF_8;
+ return CHARSET;
}
}
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..cbeda71a87 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;
@@ -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/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
index 9927daf3d5..93ffb944c8 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;
@@ -154,7 +156,7 @@ public class FileBasedConfig extends StoredConfig {
} else {
final String decoded;
if (isUtf8(in)) {
- decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET,
+ decoded = RawParseUtils.decode(CHARSET,
in, 3, in.length);
utf8Bom = true;
} else {
@@ -198,7 +200,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);
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..211bbe8e54 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();
@@ -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..740a284302 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;
@@ -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,8 +544,6 @@ public class AmazonS3 {
if (buf.length > 0) {
err.initCause(new IOException("\n" + new String(buf))); //$NON-NLS-1$
}
- } finally {
- errorStream.close();
}
return err;
}
@@ -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) {
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..0de9dfd7e2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java
@@ -200,6 +200,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,6 +249,9 @@ 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.
*
@@ -262,6 +272,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);
@@ -524,6 +535,11 @@ public abstract class BasePackFetchConnection extends BasePackConnection
if (first) {
return false;
}
+ if (filterBlobLimit == 0) {
+ p.writeString(OPTION_FILTER + " blob:none");
+ } else if (filterBlobLimit > 0) {
+ p.writeString(OPTION_FILTER + " blob:limit=" + filterBlobLimit);
+ }
p.end();
outNeedsEnd = false;
return true;
@@ -564,6 +580,11 @@ 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();
}
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..6d39dcd8a7 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/GitProtocolConstants.java
@@ -152,6 +152,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.
*
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..de7a7dc1c7 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;
@@ -315,7 +315,7 @@ abstract class HttpAuthMethod {
@Override
void configureRequest(final 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$
}
@@ -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/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/PackParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
index af5a0b7c98..8972955412 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PackParser.java
@@ -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();
- }
}
}
@@ -1642,17 +1638,17 @@ public abstract class PackParser {
private void inflateAndSkip(final Source src, final 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)
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;
}
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..36d660234d 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;
@@ -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/RefAdvertiser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefAdvertiser.java
index 5eb1661738..6ad39e3ddd 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;
@@ -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];
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..3b4181d6de 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransferConfig.java
@@ -101,6 +101,7 @@ public class TransferConfig {
private final boolean safeForMacOS;
private final boolean allowTipSha1InWant;
private final boolean allowReachableSha1InWant;
+ private final boolean allowFilter;
final String[] hideRefs;
TransferConfig(final Repository db) {
@@ -153,6 +154,8 @@ public class TransferConfig {
"uploadpack", "allowtipsha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
allowReachableSha1InWant = rc.getBoolean(
"uploadpack", "allowreachablesha1inwant", false); //$NON-NLS-1$ //$NON-NLS-2$
+ allowFilter = rc.getBoolean(
+ "uploadpack", "allowfilter", false); //$NON-NLS-1$ //$NON-NLS-2$
hideRefs = rc.getStringList("uploadpack", null, "hiderefs"); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -220,6 +223,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..afefbff5d8 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,11 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.RefDatabase.ALL;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
@@ -144,17 +144,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 +158,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
}
}
@@ -807,6 +791,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;
@@ -1082,6 +1068,23 @@ public abstract class Transport implements AutoCloseable {
}
/**
+ * @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(final long bytes) {
+ filterBlobLimit = bytes;
+ }
+
+ /**
* Apply provided remote configuration on this transport.
*
* @param cfg
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..ac68ba2fdd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportAmazonS3.java
@@ -339,11 +339,8 @@ public class TransportAmazonS3 extends HttpTransport implements WalkTransport {
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;
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..b300d55477 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
@@ -796,21 +796,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
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..7f36ab98d2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -47,6 +47,7 @@ import static org.eclipse.jgit.lib.RefDatabase.ALL;
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_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;
@@ -317,8 +318,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.
@@ -639,29 +639,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
@@ -742,21 +719,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() {
@@ -983,6 +945,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);
@@ -1023,6 +988,7 @@ public class UploadPack {
private void recvWants() throws IOException {
boolean isFirst = true;
+ boolean filterReceived = false;
for (;;) {
String line;
try {
@@ -1051,6 +1017,41 @@ 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;
+
+ if (arg.equals("blob:none")) {
+ filterBlobLimit = 0;
+ } else if (arg.startsWith("blob:limit=")) {
+ try {
+ filterBlobLimit = Long.parseLong(arg.substring("blob:limit=".length()));
+ } 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));
+ }
+ continue;
+ }
+
if (!line.startsWith("want ") || line.length() < 45) //$NON-NLS-1$
throw new PackProtocolException(MessageFormat.format(JGitText.get().expectedGot, "want", line)); //$NON-NLS-1$
@@ -1540,7 +1541,6 @@ public class UploadPack {
}
}
- @SuppressWarnings("deprecation")
private void sendPack(final boolean sideband,
PackStatistics.Accumulator accumulator) throws IOException {
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
@@ -1583,11 +1583,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);
@@ -1669,7 +1676,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/WalkFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
index 6708964d5e..46fd5cf1d6 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
@@ -853,17 +853,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 (final 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);
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..0130cf97ec 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java
@@ -171,27 +171,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) {
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..41c016cff8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
@@ -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() {
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..e6566939f8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
@@ -340,30 +340,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',
@@ -1280,11 +1272,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 +1321,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 +1339,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;
}
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/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
index 64cdcc300d..0b0a5057ce 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;
@@ -124,7 +126,7 @@ public class FS_Win32_Cygwin extends FS_Win32 {
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..933af469d0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java
@@ -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..d070ed39d0 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;
@@ -179,7 +181,7 @@ public class HttpSupport {
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);
}
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..fa19e89f2e 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
@@ -98,8 +98,7 @@ public class IO {
*/
public static final byte[] readSome(final File path, final 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
- }
}
}
@@ -138,8 +131,7 @@ public class IO {
*/
public static final byte[] readFully(final File path, final 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
- }
}
}
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..96123ea670
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/SshSupport.java
@@ -0,0 +1,120 @@
+/*
+ * 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.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.eclipse.jgit.annotations.Nullable;
+import org.eclipse.jgit.lib.Constants;
+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.
+ * @return The first line of output read from stdout. Stderr is discarded.
+ * @throws IOException
+ */
+ public static String runSshCommand(URIish sshUri,
+ @Nullable CredentialsProvider provider, FS fs, String command,
+ int timeout) throws IOException {
+ RemoteSession session = null;
+ Process process = null;
+ StreamCopyThread errorThread = null;
+ try (MessageWriter stderr = 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();
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(process.getInputStream(),
+ Constants.CHARSET))) {
+ return reader.readLine();
+ }
+ } finally {
+ if (errorThread != null) {
+ try {
+ errorThread.halt();
+ } catch (InterruptedException e) {
+ // Stop waiting and return anyway.
+ } finally {
+ errorThread = null;
+ }
+ }
+ if (process != null) {
+ process.destroy();
+ }
+ if (session != null) {
+ SshSessionFactory.getInstance().releaseSession(session);
+ }
+ }
+ }
+
+}
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..887f69b87c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/TemporaryBuffer.java
@@ -487,11 +487,8 @@ 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;
}
@@ -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();
}
}
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/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..efdddeee95 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
@@ -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