summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF10
-rw-r--r--org.eclipse.jgit.ant.test/pom.xml2
-rw-r--r--org.eclipse.jgit.ant/META-INF/MANIFEST.MF6
-rw-r--r--org.eclipse.jgit.ant/pom.xml2
-rw-r--r--org.eclipse.jgit.archive/META-INF/MANIFEST.MF14
-rw-r--r--org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF4
-rw-r--r--org.eclipse.jgit.archive/pom.xml2
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java16
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java9
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java9
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java9
-rw-r--r--org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java9
-rw-r--r--org.eclipse.jgit.http.apache/.settings/.api_filters11
-rw-r--r--org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF10
-rw-r--r--org.eclipse.jgit.http.apache/pom.xml2
-rw-r--r--org.eclipse.jgit.http.server/META-INF/MANIFEST.MF26
-rw-r--r--org.eclipse.jgit.http.server/pom.xml2
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java11
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java5
-rw-r--r--org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java10
-rw-r--r--org.eclipse.jgit.http.test/META-INF/MANIFEST.MF40
-rw-r--r--org.eclipse.jgit.http.test/pom.xml2
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ProtocolErrorTest.java10
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SetAdditionalHeadersTest.java5
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java15
-rw-r--r--org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF20
-rw-r--r--org.eclipse.jgit.junit.http/pom.xml2
-rw-r--r--org.eclipse.jgit.junit/META-INF/MANIFEST.MF36
-rw-r--r--org.eclipse.jgit.junit/pom.xml2
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java6
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java4
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java37
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java4
-rw-r--r--org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF38
-rw-r--r--org.eclipse.jgit.lfs.server.test/pom.xml2
-rw-r--r--org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java12
-rw-r--r--org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF31
-rw-r--r--org.eclipse.jgit.lfs.server/pom.xml2
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java48
-rw-r--r--org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java8
-rw-r--r--org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF24
-rw-r--r--org.eclipse.jgit.lfs.test/pom.xml2
-rw-r--r--org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java4
-rw-r--r--org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java4
-rw-r--r--org.eclipse.jgit.lfs/.settings/.api_filters27
-rw-r--r--org.eclipse.jgit.lfs/META-INF/MANIFEST.MF46
-rw-r--r--org.eclipse.jgit.lfs/pom.xml2
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java13
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java8
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java4
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java5
-rw-r--r--org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java52
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/feature.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml6
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml2
-rw-r--r--org.eclipse.jgit.packaging/pom.xml2
-rw-r--r--org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF36
-rw-r--r--org.eclipse.jgit.pgm.test/pom.xml2
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java6
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java13
-rw-r--r--org.eclipse.jgit.pgm/.settings/.api_filters11
-rw-r--r--org.eclipse.jgit.pgm/META-INF/MANIFEST.MF86
-rw-r--r--org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF4
-rw-r--r--org.eclipse.jgit.pgm/pom.xml2
-rw-r--r--org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties1
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java27
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java6
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java4
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java11
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java4
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java15
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java5
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java6
-rw-r--r--org.eclipse.jgit.test/META-INF/MANIFEST.MF92
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java6
-rw-r--r--org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java (renamed from org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java)74
-rw-r--r--org.eclipse.jgit.test/pom.xml2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java19
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java54
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java24
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java70
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java770
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java79
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java19
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java91
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java130
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java5
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java7
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java)2
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java (renamed from org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java)52
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java6
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java102
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java102
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java35
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java28
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java3
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java36
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java146
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java67
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java13
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java4
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java68
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java47
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java57
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java48
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java14
-rw-r--r--org.eclipse.jgit.ui/.settings/.api_filters11
-rw-r--r--org.eclipse.jgit.ui/META-INF/MANIFEST.MF18
-rw-r--r--org.eclipse.jgit.ui/pom.xml2
-rw-r--r--org.eclipse.jgit/.settings/.api_filters65
-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.java11
-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/PushCommand.java3
-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/SubmoduleSyncCommand.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java64
-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.java34
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java2
-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/file/ReflogWriter.java38
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java315
-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/TransportGitAnon.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java48
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java93
-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.java66
-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.java57
-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.java60
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java53
-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
-rw-r--r--pom.xml2
243 files changed, 2561 insertions, 3530 deletions
diff --git a/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF
index 00cd1a241d..ae9496cff5 100644
--- a/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF
@@ -4,13 +4,13 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.ant.test
Bundle-SymbolicName: org.eclipse.jgit.ant.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.apache.tools.ant,
- org.eclipse.jgit.ant.tasks;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.ant.tasks;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
org.junit;version="[4.12,5.0.0)"
diff --git a/org.eclipse.jgit.ant.test/pom.xml b/org.eclipse.jgit.ant.test/pom.xml
index 05b050b012..f8b83c2972 100644
--- a/org.eclipse.jgit.ant.test/pom.xml
+++ b/org.eclipse.jgit.ant.test/pom.xml
@@ -50,7 +50,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.ant.test</artifactId>
diff --git a/org.eclipse.jgit.ant/META-INF/MANIFEST.MF b/org.eclipse.jgit.ant/META-INF/MANIFEST.MF
index 01555ce3b9..f917ba3f68 100644
--- a/org.eclipse.jgit.ant/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.ant/META-INF/MANIFEST.MF
@@ -3,11 +3,11 @@ Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Automatic-Module-Name: org.eclipse.jgit.ant
Bundle-SymbolicName: org.eclipse.jgit.ant
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.apache.tools.ant,
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)"
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)"
Bundle-Localization: plugin
Bundle-Vendor: %Provider-Name
-Export-Package: org.eclipse.jgit.ant.tasks;version="4.11.1";
+Export-Package: org.eclipse.jgit.ant.tasks;version="5.0.0";
uses:="org.apache.tools.ant.types,org.apache.tools.ant"
diff --git a/org.eclipse.jgit.ant/pom.xml b/org.eclipse.jgit.ant/pom.xml
index 103e2e5f07..7767c6996f 100644
--- a/org.eclipse.jgit.ant/pom.xml
+++ b/org.eclipse.jgit.ant/pom.xml
@@ -48,7 +48,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.ant</artifactId>
diff --git a/org.eclipse.jgit.archive/META-INF/MANIFEST.MF b/org.eclipse.jgit.archive/META-INF/MANIFEST.MF
index 3917129706..7fa8576fcd 100644
--- a/org.eclipse.jgit.archive/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.archive/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.archive
Bundle-SymbolicName: org.eclipse.jgit.archive
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -13,15 +13,15 @@ Import-Package: org.apache.commons.compress.archivers;version="[1.4,2.0)",
org.apache.commons.compress.compressors.bzip2;version="[1.4,2.0)",
org.apache.commons.compress.compressors.gzip;version="[1.4,2.0)",
org.apache.commons.compress.compressors.xz;version="[1.4,2.0)",
- org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.api;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
org.osgi.framework;version="[1.3.0,2.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.jgit.archive.FormatActivator
-Export-Package: org.eclipse.jgit.archive;version="4.11.1";
+Export-Package: org.eclipse.jgit.archive;version="5.0.0";
uses:="org.eclipse.jgit.lib,
org.eclipse.jgit.api,
org.apache.commons.compress.archivers,
diff --git a/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF
index de7fbdb4ce..ef53d07eed 100644
--- a/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF
+++ b/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF
@@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.jgit.archive - Sources
Bundle-SymbolicName: org.eclipse.jgit.archive.source
Bundle-Vendor: Eclipse.org - JGit
-Bundle-Version: 4.11.1.qualifier
-Eclipse-SourceBundle: org.eclipse.jgit.archive;version="4.11.1.qualifier";roots="."
+Bundle-Version: 5.0.0.qualifier
+Eclipse-SourceBundle: org.eclipse.jgit.archive;version="5.0.0.qualifier";roots="."
diff --git a/org.eclipse.jgit.archive/pom.xml b/org.eclipse.jgit.archive/pom.xml
index 1ac1643c88..2a3500c173 100644
--- a/org.eclipse.jgit.archive/pom.xml
+++ b/org.eclipse.jgit.archive/pom.xml
@@ -50,7 +50,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.archive</artifactId>
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
index 7559ada864..9ed60d941a 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TarFormat.java
@@ -42,6 +42,8 @@
*/
package org.eclipse.jgit.archive;
+import static org.eclipse.jgit.lib.Constants.CHARACTER_ENCODING;
+
import java.io.IOException;
import java.io.OutputStream;
import java.text.MessageFormat;
@@ -82,22 +84,14 @@ public final class TarFormat extends BaseFormat implements
@Override
public ArchiveOutputStream createArchiveOutputStream(OutputStream s,
Map<String, Object> o) throws IOException {
- TarArchiveOutputStream out = new TarArchiveOutputStream(s, "UTF-8"); //$NON-NLS-1$
+ TarArchiveOutputStream out = new TarArchiveOutputStream(s,
+ CHARACTER_ENCODING);
out.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);
out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
return applyFormatOptions(out, o);
}
/** {@inheritDoc} */
- @Deprecated
- @Override
- public void putEntry(ArchiveOutputStream out,
- String path, FileMode mode, ObjectLoader loader)
- throws IOException {
- putEntry(out, null, path, mode,loader);
- }
-
- /** {@inheritDoc} */
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
@@ -106,7 +100,7 @@ public final class TarFormat extends BaseFormat implements
final TarArchiveEntry entry = new TarArchiveEntry(
path, TarConstants.LF_SYMLINK);
entry.setLinkName(new String(
- loader.getCachedBytes(100), "UTF-8")); //$NON-NLS-1$
+ loader.getCachedBytes(100), CHARACTER_ENCODING));
out.putArchiveEntry(entry);
out.closeArchiveEntry();
return;
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
index 2f95f6d74f..fa6a7b0555 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/Tbz2Format.java
@@ -83,15 +83,6 @@ public final class Tbz2Format extends BaseFormat implements
}
/** {@inheritDoc} */
- @Deprecated
- @Override
- public void putEntry(ArchiveOutputStream out,
- String path, FileMode mode, ObjectLoader loader)
- throws IOException {
- putEntry(out, null, path, mode,loader);
- }
-
- /** {@inheritDoc} */
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
index b22a62d07e..368b4f2467 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TgzFormat.java
@@ -83,15 +83,6 @@ public final class TgzFormat extends BaseFormat implements
}
/** {@inheritDoc} */
- @Deprecated
- @Override
- public void putEntry(ArchiveOutputStream out,
- String path, FileMode mode, ObjectLoader loader)
- throws IOException {
- putEntry(out, null, path, mode,loader);
- }
-
- /** {@inheritDoc} */
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
index d23d2b657e..36616eda8d 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/TxzFormat.java
@@ -83,15 +83,6 @@ public final class TxzFormat extends BaseFormat implements
}
/** {@inheritDoc} */
- @Deprecated
- @Override
- public void putEntry(ArchiveOutputStream out,
- String path, FileMode mode, ObjectLoader loader)
- throws IOException {
- putEntry(out, null, path, mode,loader);
- }
-
- /** {@inheritDoc} */
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
diff --git a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
index dc8fb44572..8483801c90 100644
--- a/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
+++ b/org.eclipse.jgit.archive/src/org/eclipse/jgit/archive/ZipFormat.java
@@ -84,15 +84,6 @@ public final class ZipFormat extends BaseFormat implements
}
/** {@inheritDoc} */
- @Deprecated
- @Override
- public void putEntry(ArchiveOutputStream out,
- String path, FileMode mode, ObjectLoader loader)
- throws IOException {
- putEntry(out, null, path, mode,loader);
- }
-
- /** {@inheritDoc} */
@Override
public void putEntry(ArchiveOutputStream out,
ObjectId tree, String path, FileMode mode, ObjectLoader loader)
diff --git a/org.eclipse.jgit.http.apache/.settings/.api_filters b/org.eclipse.jgit.http.apache/.settings/.api_filters
new file mode 100644
index 0000000000..d1a066418c
--- /dev/null
+++ b/org.eclipse.jgit.http.apache/.settings/.api_filters
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jgit.http.apache" version="2">
+ <resource path="META-INF/MANIFEST.MF">
+ <filter id="925892614">
+ <message_arguments>
+ <message_argument value="5.0.0"/>
+ <message_argument value="4.11.0"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF
index 6973aa86bf..ced2532c00 100644
--- a/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Automatic-Module-Name: org.eclipse.jgit.http.apache
Bundle-SymbolicName: org.eclipse.jgit.http.apache
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Localization: plugin
Bundle-Vendor: %Provider-Name
@@ -23,10 +23,10 @@ Import-Package: org.apache.http;version="[4.3.0,5.0.0)",
org.apache.http.impl.client;version="[4.3.0,5.0.0)",
org.apache.http.impl.conn;version="[4.3.0,5.0.0)",
org.apache.http.params;version="[4.3.0,5.0.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)"
-Export-Package: org.eclipse.jgit.transport.http.apache;version="4.11.1";
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)"
+Export-Package: org.eclipse.jgit.transport.http.apache;version="5.0.0";
uses:="org.apache.http.client,
org.eclipse.jgit.transport.http,
org.apache.http.entity,
diff --git a/org.eclipse.jgit.http.apache/pom.xml b/org.eclipse.jgit.http.apache/pom.xml
index 3e30cf471d..8d3e365ff6 100644
--- a/org.eclipse.jgit.http.apache/pom.xml
+++ b/org.eclipse.jgit.http.apache/pom.xml
@@ -48,7 +48,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.http.apache</artifactId>
diff --git a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
index e55830ad2d..d7ed5f04d0 100644
--- a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF
@@ -3,13 +3,13 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.http.server
Bundle-SymbolicName: org.eclipse.jgit.http.server
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
-Export-Package: org.eclipse.jgit.http.server;version="4.11.1",
- org.eclipse.jgit.http.server.glue;version="4.11.1";
+Export-Package: org.eclipse.jgit.http.server;version="5.0.0",
+ org.eclipse.jgit.http.server.glue;version="5.0.0";
uses:="javax.servlet,javax.servlet.http",
- org.eclipse.jgit.http.server.resolver;version="4.11.1";
+ org.eclipse.jgit.http.server.resolver;version="5.0.0";
uses:="org.eclipse.jgit.transport.resolver,
org.eclipse.jgit.lib,
org.eclipse.jgit.transport,
@@ -18,12 +18,12 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.servlet;version="[2.5.0,3.2.0)",
javax.servlet.http;version="[2.5.0,3.2.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.resolver;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)"
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)"
diff --git a/org.eclipse.jgit.http.server/pom.xml b/org.eclipse.jgit.http.server/pom.xml
index c132932501..6aaffcf3b3 100644
--- a/org.eclipse.jgit.http.server/pom.xml
+++ b/org.eclipse.jgit.http.server/pom.xml
@@ -52,7 +52,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.http.server</artifactId>
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
index c89a5d762c..b9e82c27f6 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
@@ -140,9 +140,9 @@ public class RepositoryFilter implements Filter {
return;
}
- final Repository db;
- try {
- db = resolver.open(req, name);
+ try (Repository db = resolver.open(req, name)) {
+ request.setAttribute(ATTRIBUTE_REPOSITORY, db);
+ chain.doFilter(request, response);
} catch (RepositoryNotFoundException e) {
sendError(req, res, SC_NOT_FOUND);
return;
@@ -155,13 +155,8 @@ public class RepositoryFilter implements Filter {
} catch (ServiceMayNotContinueException e) {
sendError(req, res, e.getStatusCode(), e.getMessage());
return;
- }
- try {
- request.setAttribute(ATTRIBUTE_REPOSITORY, db);
- chain.doFilter(request, response);
} finally {
request.removeAttribute(ATTRIBUTE_REPOSITORY);
- db.close();
}
}
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
index f1ff547ea7..272edc6879 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ServletUtils.java
@@ -220,12 +220,9 @@ public final class ServletUtils {
public static void send(byte[] content, final HttpServletRequest req,
final HttpServletResponse rsp) throws IOException {
content = sendInit(content, req, rsp);
- final OutputStream out = rsp.getOutputStream();
- try {
+ try (OutputStream out = rsp.getOutputStream()) {
out.write(content);
out.flush();
- } finally {
- out.close();
}
}
diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
index 4eb94a3a22..ad5e8d479e 100644
--- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
+++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java
@@ -110,11 +110,8 @@ class SmartOutputStream extends TemporaryBuffer {
if (256 < out.length() && acceptsGzipEncoding(req)) {
TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);
try {
- GZIPOutputStream gzip = new GZIPOutputStream(gzbuf);
- try {
+ try (GZIPOutputStream gzip = new GZIPOutputStream(gzbuf)) {
out.writeTo(gzip, null);
- } finally {
- gzip.close();
}
if (gzbuf.length() < out.length()) {
out = gzbuf;
@@ -131,12 +128,9 @@ class SmartOutputStream extends TemporaryBuffer {
// hardcoded LIMIT constant above assures us we wouldn't store
// more than 2 GiB of content in memory.
rsp.setContentLength((int) out.length());
- final OutputStream os = rsp.getOutputStream();
- try {
+ try (OutputStream os = rsp.getOutputStream()) {
out.writeTo(os, null);
os.flush();
- } finally {
- os.close();
}
}
}
diff --git a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
index 4244cfb533..d83402bded 100644
--- a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.http.test
Bundle-SymbolicName: org.eclipse.jgit.http.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -25,25 +25,25 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)",
org.eclipse.jetty.util.log;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.http.server;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.http.server.glue;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.http.server.resolver;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http.apache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.resolver;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.http.server;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.http.server.glue;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.http.server.resolver;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http.apache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.runner;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.http.test/pom.xml b/org.eclipse.jgit.http.test/pom.xml
index f352164e7e..6eef6cea56 100644
--- a/org.eclipse.jgit.http.test/pom.xml
+++ b/org.eclipse.jgit.http.test/pom.xml
@@ -51,7 +51,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.http.test</artifactId>
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ProtocolErrorTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ProtocolErrorTest.java
index 87d0bad85c..a1baae3b26 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ProtocolErrorTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/ProtocolErrorTest.java
@@ -149,19 +149,15 @@ public class ProtocolErrorTest extends HttpTestCase {
c.setRequestProperty("Content-Type",
GitSmartHttpTools.RECEIVE_PACK_REQUEST_TYPE);
c.setFixedLengthStreamingMode(reqbin.length);
- OutputStream out = c.getOutputStream();
- try {
+ try (OutputStream out = c.getOutputStream()) {
out.write(reqbin);
- } finally {
- out.close();
}
assertEquals(200, c.getResponseCode());
assertEquals(GitSmartHttpTools.RECEIVE_PACK_RESULT_TYPE,
c.getContentType());
- InputStream rawin = c.getInputStream();
- try {
+ try (InputStream rawin = c.getInputStream()) {
PacketLineIn pckin = new PacketLineIn(rawin);
assertEquals("unpack error "
+ JGitText.get().packfileIsTruncatedNoParam,
@@ -169,8 +165,6 @@ public class ProtocolErrorTest extends HttpTestCase {
assertEquals("ng refs/objects/A n/a (unpacker error)",
pckin.readString());
assertSame(PacketLineIn.END, pckin.readString());
- } finally {
- rawin.close();
}
} finally {
c.disconnect();
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SetAdditionalHeadersTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SetAdditionalHeadersTest.java
index ef8daec31f..fbc54f3872 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SetAdditionalHeadersTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SetAdditionalHeadersTest.java
@@ -107,8 +107,7 @@ public class SetAdditionalHeadersTest extends HttpTestCase {
assertEquals("http", remoteURI.getScheme());
- Transport t = Transport.open(dst, remoteURI);
- try {
+ try (Transport t = Transport.open(dst, remoteURI)) {
assertTrue("isa TransportHttp", t instanceof TransportHttp);
assertTrue("isa HttpTransport", t instanceof HttpTransport);
@@ -117,8 +116,6 @@ public class SetAdditionalHeadersTest extends HttpTestCase {
headers.put("AnotherKey", "someValue");
((TransportHttp) t).setAdditionalHeaders(headers);
t.openFetch();
- } finally {
- t.close();
}
List<AccessEvent> requests = getRequests();
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
index 5f40be4e05..d8541aa13d 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.http.test;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_ENCODING;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_LENGTH;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
@@ -267,9 +267,9 @@ public class SmartClientSmartServerTest extends HttpTestCase {
final HttpServletResponse r = (HttpServletResponse) response;
r.setContentType("text/plain");
r.setCharacterEncoding("UTF-8");
- PrintWriter w = r.getWriter();
- w.print("OK");
- w.close();
+ try (PrintWriter w = r.getWriter()) {
+ w.print("OK");
+ }
}
@Override
@@ -397,11 +397,8 @@ public class SmartClientSmartServerTest extends HttpTestCase {
assertTrue("isa TransportHttp", t instanceof TransportHttp);
assertTrue("isa HttpTransport", t instanceof HttpTransport);
- FetchConnection c = t.openFetch();
- try {
+ try (FetchConnection c = t.openFetch()) {
map = c.getRefsMap();
- } finally {
- c.close();
}
}
@@ -1084,7 +1081,7 @@ public class SmartClientSmartServerTest extends HttpTestCase {
public void testInvalidWant() throws Exception {
@SuppressWarnings("resource")
ObjectId id = new ObjectInserter.Formatter().idFor(Constants.OBJ_BLOB,
- "testInvalidWant".getBytes(UTF_8));
+ "testInvalidWant".getBytes(CHARSET));
Repository dst = createBareRepository();
try (Transport t = Transport.open(dst, remoteURI);
diff --git a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
index ace791dedc..f3d587a414 100644
--- a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.junit.http
Bundle-SymbolicName: org.eclipse.jgit.junit.http
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
@@ -22,16 +22,16 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)",
org.eclipse.jetty.util.log;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.ssl;version="[9.4.5,10.0.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.http.server;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.resolver;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.http.server;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.0.0,5.1.0)",
org.junit;version="[4.12,5.0.0)"
-Export-Package: org.eclipse.jgit.junit.http;version="4.11.1";
+Export-Package: org.eclipse.jgit.junit.http;version="5.0.0";
uses:="org.eclipse.jgit.transport,
org.eclipse.jgit.junit,
javax.servlet.http,
diff --git a/org.eclipse.jgit.junit.http/pom.xml b/org.eclipse.jgit.junit.http/pom.xml
index 7dfccc95fb..59b2c25a0c 100644
--- a/org.eclipse.jgit.junit.http/pom.xml
+++ b/org.eclipse.jgit.junit.http/pom.xml
@@ -50,7 +50,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.junit.http</artifactId>
diff --git a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF
index 7214dab2ea..81e90e005d 100644
--- a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF
@@ -3,31 +3,31 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.junit
Bundle-SymbolicName: org.eclipse.jgit.junit
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Import-Package: org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.dircache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.merge;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.io;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.time;version="[4.11.1,4.12.0)",
+Import-Package: org.eclipse.jgit.api;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.api.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.dircache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.merge;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.io;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.time;version="[5.0.0,5.1.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
org.junit.runner;version="[4.12,5.0.0)",
org.junit.runners.model;version="[4.12,5.0.0)"
-Export-Package: org.eclipse.jgit.junit;version="4.11.1";
+Export-Package: org.eclipse.jgit.junit;version="5.0.0";
uses:="org.eclipse.jgit.dircache,
org.eclipse.jgit.lib,
org.eclipse.jgit.revwalk,
@@ -36,4 +36,4 @@ Export-Package: org.eclipse.jgit.junit;version="4.11.1";
org.eclipse.jgit.util,
org.eclipse.jgit.storage.file,
org.eclipse.jgit.api",
- org.eclipse.jgit.junit.time;version="4.11.1"
+ org.eclipse.jgit.junit.time;version="5.0.0"
diff --git a/org.eclipse.jgit.junit/pom.xml b/org.eclipse.jgit.junit/pom.xml
index d53eb274d3..1c1fa0497b 100644
--- a/org.eclipse.jgit.junit/pom.xml
+++ b/org.eclipse.jgit.junit/pom.xml
@@ -52,7 +52,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.junit</artifactId>
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
index cef81a062d..27f745e4e9 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/JGitTestUtil.java
@@ -45,7 +45,7 @@
package org.eclipse.jgit.junit;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.File;
import java.io.FileNotFoundException;
@@ -246,7 +246,7 @@ public abstract class JGitTestUtil {
throws IOException {
FileUtils.mkdirs(f.getParentFile(), true);
try (Writer w = new OutputStreamWriter(new FileOutputStream(f),
- UTF_8)) {
+ CHARSET)) {
w.write(body);
}
}
@@ -263,7 +263,7 @@ public abstract class JGitTestUtil {
*/
public static String read(final File file) throws IOException {
final byte[] body = IO.readFully(file);
- return new String(body, 0, body.length, UTF_8);
+ return new String(body, 0, body.length, CHARSET);
}
/**
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
index 568bc3b0e1..3c00bd3df1 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
@@ -45,7 +45,7 @@
package org.eclipse.jgit.junit;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
@@ -352,7 +352,7 @@ public abstract class LocalDiskRepositoryTestCase {
if (0 != (includedOptions & CONTENT)) {
sb.append(", content:"
+ new String(repo.open(entry.getObjectId(),
- Constants.OBJ_BLOB).getCachedBytes(), UTF_8));
+ Constants.OBJ_BLOB).getCachedBytes(), CHARSET));
}
if (0 != (includedOptions & ASSUME_UNCHANGED))
sb.append(", assume-unchanged:"
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
index afc2c445cf..93fc771cb3 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
@@ -46,7 +46,7 @@
package org.eclipse.jgit.junit;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import java.io.File;
@@ -94,20 +94,13 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
*/
protected static void copyFile(final File src, final File dst)
throws IOException {
- final FileInputStream fis = new FileInputStream(src);
- try {
- final FileOutputStream fos = new FileOutputStream(dst);
- try {
- final byte[] buf = new byte[4096];
- int r;
- while ((r = fis.read(buf)) > 0) {
- fos.write(buf, 0, r);
- }
- } finally {
- fos.close();
+ try (FileInputStream fis = new FileInputStream(src);
+ FileOutputStream fos = new FileOutputStream(dst)) {
+ final byte[] buf = new byte[4096];
+ int r;
+ while ((r = fis.read(buf)) > 0) {
+ fos.write(buf, 0, r);
}
- } finally {
- fis.close();
}
}
@@ -199,7 +192,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected static void checkFile(File f, final String checkData)
throws IOException {
try (Reader r = new InputStreamReader(new FileInputStream(f),
- UTF_8)) {
+ CHARSET)) {
if (checkData.length() > 0) {
char[] data = new char[checkData.length()];
assertEquals(data.length, r.read(data));
@@ -293,10 +286,11 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
dce.setFileMode(treeItr.getEntryFileMode());
dce.setLastModified(treeItr.getEntryLastModified());
dce.setLength((int) len);
- FileInputStream in = new FileInputStream(
- treeItr.getEntryFile());
- dce.setObjectId(inserter.insert(Constants.OBJ_BLOB, len, in));
- in.close();
+ try (FileInputStream in = new FileInputStream(
+ treeItr.getEntryFile())) {
+ dce.setObjectId(
+ inserter.insert(Constants.OBJ_BLOB, len, in));
+ }
builder.add(dce);
treeItr.next(1);
}
@@ -380,8 +374,9 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
while (actTime <= startTime) {
Thread.sleep(sleepTime);
sleepTime *= 2;
- FileOutputStream fos = new FileOutputStream(tmp);
- fos.close();
+ try (FileOutputStream fos = new FileOutputStream(tmp)) {
+ // Do nothing
+ }
actTime = fs.lastModified(tmp);
}
return actTime;
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index 41634e7cda..89a86d8eea 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.junit;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -268,7 +268,7 @@ public class TestRepository<R extends Repository> {
* @throws Exception
*/
public RevBlob blob(final String content) throws Exception {
- return blob(content.getBytes(UTF_8));
+ return blob(content.getBytes(CHARSET));
}
/**
diff --git a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
index a80cd3afe3..e272e3d47b 100644
--- a/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.lfs.server.test/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.lfs.server.test
Bundle-SymbolicName: org.eclipse.jgit.lfs.server.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -28,24 +28,24 @@ Import-Package: javax.servlet;version="[3.1.0,4.0.0)",
org.eclipse.jetty.util.log;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)",
- org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.server;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.server.fs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.test;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.api;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.api.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.server;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.server.fs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.test;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.lfs.server.test/pom.xml b/org.eclipse.jgit.lfs.server.test/pom.xml
index 2343b6c3e9..fbf4d4b3b5 100644
--- a/org.eclipse.jgit.lfs.server.test/pom.xml
+++ b/org.eclipse.jgit.lfs.server.test/pom.xml
@@ -50,7 +50,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.lfs.server.test</artifactId>
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
index 90fe116804..50a06f94d6 100644
--- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
+++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/LfsServerTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.lfs.server.fs;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import java.io.BufferedInputStream;
@@ -131,12 +131,6 @@ public abstract class LfsServerTest {
@Override
protected LargeFileRepository getLargeFileRepository(
- LfsRequest request, String path) {
- return repository;
- }
-
- @Override
- protected LargeFileRepository getLargeFileRepository(
LfsRequest request, String path, String auth)
throws LfsException {
return repository;
@@ -217,11 +211,11 @@ public abstract class LfsServerTest {
if (buf.hasArray()) {
error = new String(buf.array(),
buf.arrayOffset() + buf.position(), buf.remaining(),
- UTF_8);
+ CHARSET);
} else {
final byte[] b = new byte[buf.remaining()];
buf.duplicate().get(b);
- error = new String(b, UTF_8);
+ error = new String(b, CHARSET);
}
} catch (IOException e) {
error = statusLine.getReasonPhrase();
diff --git a/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF
index d9e2ee54f9..28b123165e 100644
--- a/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.lfs.server/META-INF/MANIFEST.MF
@@ -3,19 +3,19 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.lfs.server
Bundle-SymbolicName: org.eclipse.jgit.lfs.server
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
-Export-Package: org.eclipse.jgit.lfs.server;version="4.11.1";
+Export-Package: org.eclipse.jgit.lfs.server;version="5.0.0";
uses:="javax.servlet.http,
org.eclipse.jgit.lfs.lib",
- org.eclipse.jgit.lfs.server.fs;version="4.11.1";
+ org.eclipse.jgit.lfs.server.fs;version="5.0.0";
uses:="javax.servlet,
javax.servlet.http,
org.eclipse.jgit.lfs.server,
org.eclipse.jgit.lfs.lib",
- org.eclipse.jgit.lfs.server.internal;version="4.11.1";x-internal:=true,
- org.eclipse.jgit.lfs.server.s3;version="4.11.1";
+ org.eclipse.jgit.lfs.server.internal;version="5.0.0";x-internal:=true,
+ org.eclipse.jgit.lfs.server.s3;version="5.0.0";
uses:="org.eclipse.jgit.lfs.server,
org.eclipse.jgit.lfs.lib"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
@@ -25,14 +25,15 @@ Import-Package: com.google.gson;version="[2.8.0,3.0.0)",
javax.servlet.http;version="[3.1.0,4.0.0)",
org.apache.http;version="[4.3.0,5.0.0)",
org.apache.http.client;version="[4.3.0,5.0.0)",
- org.eclipse.jgit.annotations;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http.apache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.annotations;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http.apache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
org.slf4j;version="[1.7.0,2.0.0)"
diff --git a/org.eclipse.jgit.lfs.server/pom.xml b/org.eclipse.jgit.lfs.server/pom.xml
index ac75170d2e..3bb09baba9 100644
--- a/org.eclipse.jgit.lfs.server/pom.xml
+++ b/org.eclipse.jgit.lfs.server/pom.xml
@@ -50,7 +50,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.lfs.server</artifactId>
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
index 6968d75636..d22d45967e 100644
--- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
+++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/LfsProtocolServlet.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.lfs.server;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.apache.http.HttpStatus.SC_FORBIDDEN;
import static org.apache.http.HttpStatus.SC_INSUFFICIENT_STORAGE;
import static org.apache.http.HttpStatus.SC_INTERNAL_SERVER_ERROR;
@@ -112,48 +112,6 @@ public abstract class LfsProtocolServlet extends HttpServlet {
* the request
* @param path
* the path
- * @return the large file repository storing large files.
- * @throws org.eclipse.jgit.lfs.errors.LfsException
- * implementations should throw more specific exceptions to
- * signal which type of error occurred:
- * <dl>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsValidationError}</dt>
- * <dd>when there is a validation error with one or more of the
- * objects in the request</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsRepositoryNotFound}</dt>
- * <dd>when the repository does not exist for the user</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsRepositoryReadOnly}</dt>
- * <dd>when the user has read, but not write access. Only
- * applicable when the operation in the request is "upload"</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsRateLimitExceeded}</dt>
- * <dd>when the user has hit a rate limit with the server</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsBandwidthLimitExceeded}</dt>
- * <dd>when the bandwidth limit for the user or repository has
- * been exceeded</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsInsufficientStorage}</dt>
- * <dd>when there is insufficient storage on the server</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsUnavailable}</dt>
- * <dd>when LFS is not available</dd>
- * <dt>{@link org.eclipse.jgit.lfs.errors.LfsException}</dt>
- * <dd>when an unexpected internal server error occurred</dd>
- * </dl>
- * @since 4.5
- * @deprecated use
- * {@link #getLargeFileRepository(LfsRequest, String, String)}
- */
- @Deprecated
- protected LargeFileRepository getLargeFileRepository(LfsRequest request,
- String path) throws LfsException {
- return getLargeFileRepository(request, path, null);
- }
-
- /**
- * Get the large file repository for the given request and path.
- *
- * @param request
- * the request
- * @param path
- * the path
* @param auth
* the Authorization HTTP header
* @return the large file repository storing large files.
@@ -244,10 +202,10 @@ public abstract class LfsProtocolServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Writer w = new BufferedWriter(
- new OutputStreamWriter(res.getOutputStream(), UTF_8));
+ new OutputStreamWriter(res.getOutputStream(), CHARSET));
Reader r = new BufferedReader(
- new InputStreamReader(req.getInputStream(), UTF_8));
+ new InputStreamReader(req.getInputStream(), CHARSET));
LfsRequest request = LfsGson.fromJson(r, LfsRequest.class);
String path = req.getPathInfo();
diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
index b21c94e4e6..374a560581 100644
--- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
+++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/s3/SignerV4.java
@@ -43,7 +43,7 @@
*/
package org.eclipse.jgit.lfs.server.s3;
-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 java.io.UnsupportedEncodingException;
@@ -359,13 +359,13 @@ class SignerV4 {
private static byte[] hash(String s) {
MessageDigest md = Constants.newMessageDigest();
- md.update(s.getBytes(UTF_8));
+ md.update(s.getBytes(CHARSET));
return md.digest();
}
private static byte[] sign(String stringData, byte[] key) {
try {
- byte[] data = stringData.getBytes(UTF_8);
+ byte[] data = stringData.getBytes(CHARSET);
Mac mac = Mac.getInstance(HMACSHA256);
mac.init(new SecretKeySpec(key, HMACSHA256));
return mac.doFinal(data);
@@ -395,7 +395,7 @@ class SignerV4 {
private static String urlEncode(String url, boolean keepPathSlash) {
String encoded;
try {
- encoded = URLEncoder.encode(url, UTF_8.name());
+ encoded = URLEncoder.encode(url, CHARSET.name());
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e);
}
diff --git a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF
index b91859771e..eda0867b25 100644
--- a/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.lfs.test/META-INF/MANIFEST.MF
@@ -3,23 +3,23 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.lfs.test
Bundle-SymbolicName: org.eclipse.jgit.lfs.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Import-Package: org.eclipse.jgit.internal.storage.dfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
+Import-Package: org.eclipse.jgit.internal.storage.dfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
org.hamcrest.core;version="[1.1.0,2.0.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.runner;version="[4.12,5.0.0)",
org.junit.runners;version="[4.12,5.0.0)"
-Export-Package: org.eclipse.jgit.lfs.test;version="4.11.1";x-friends:="org.eclipse.jgit.lfs.server.test"
+Export-Package: org.eclipse.jgit.lfs.test;version="5.0.0";x-friends:="org.eclipse.jgit.lfs.server.test"
diff --git a/org.eclipse.jgit.lfs.test/pom.xml b/org.eclipse.jgit.lfs.test/pom.xml
index 318e5a7101..7c6aa7283f 100644
--- a/org.eclipse.jgit.lfs.test/pom.xml
+++ b/org.eclipse.jgit.lfs.test/pom.xml
@@ -50,7 +50,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.lfs.test</artifactId>
diff --git a/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java b/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java
index c3c3859467..e3c6ef80bc 100644
--- a/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java
+++ b/org.eclipse.jgit.lfs.test/src/org/eclipse/jgit/lfs/test/LongObjectIdTestUtils.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.lfs.test;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
@@ -66,7 +66,7 @@ public class LongObjectIdTestUtils {
*/
public static LongObjectId hash(String s) {
MessageDigest md = Constants.newMessageDigest();
- md.update(s.getBytes(UTF_8));
+ md.update(s.getBytes(CHARSET));
return LongObjectId.fromRaw(md.digest());
}
diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
index 146a25ed3d..a1283ddf41 100644
--- a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
+++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LFSPointerTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.lfs.lib;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARACTER_ENCODING;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
@@ -66,7 +66,7 @@ public class LFSPointerTest {
assertEquals(
"version https://git-lfs.github.com/spec/v1\noid sha256:"
+ s + "\nsize 4\n",
- baos.toString(UTF_8.name()));
+ baos.toString(CHARACTER_ENCODING));
}
}
}
diff --git a/org.eclipse.jgit.lfs/.settings/.api_filters b/org.eclipse.jgit.lfs/.settings/.api_filters
deleted file mode 100644
index f4887e272b..0000000000
--- a/org.eclipse.jgit.lfs/.settings/.api_filters
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<component id="org.eclipse.jgit.lfs" version="2">
- <resource path="src/org/eclipse/jgit/lfs/CleanFilter.java" type="org.eclipse.jgit.lfs.CleanFilter">
- <filter id="421572723">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.lfs.CleanFilter"/>
- <message_argument value="register()"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/lfs/LfsPointer.java" type="org.eclipse.jgit.lfs.LfsPointer">
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.lfs.LfsPointer"/>
- <message_argument value="SIZE_THRESHOLD"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/lfs/SmudgeFilter.java" type="org.eclipse.jgit.lfs.SmudgeFilter">
- <filter id="421572723">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.lfs.SmudgeFilter"/>
- <message_argument value="register()"/>
- </message_arguments>
- </filter>
- </resource>
-</component>
diff --git a/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF b/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF
index 0056904809..acc3532595 100644
--- a/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.lfs/META-INF/MANIFEST.MF
@@ -3,33 +3,33 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.lfs
Bundle-SymbolicName: org.eclipse.jgit.lfs
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
-Export-Package: org.eclipse.jgit.lfs;version="4.11.1",
- org.eclipse.jgit.lfs.errors;version="4.11.1",
- org.eclipse.jgit.lfs.internal;version="4.11.1";x-friends:="org.eclipse.jgit.lfs.test,org.eclipse.jgit.lfs.server.fs,org.eclipse.jgit.lfs.server",
- org.eclipse.jgit.lfs.lib;version="4.11.1"
+Export-Package: org.eclipse.jgit.lfs;version="5.0.0",
+ org.eclipse.jgit.lfs.errors;version="5.0.0",
+ org.eclipse.jgit.lfs.internal;version="5.0.0";x-friends:="org.eclipse.jgit.lfs.test,org.eclipse.jgit.lfs.server.fs,org.eclipse.jgit.lfs.server",
+ org.eclipse.jgit.lfs.lib;version="5.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.google.gson;version="[2.8.2,3.0.0)",
com.google.gson.stream;version="[2.8.2,3.0.0)",
org.apache.http.impl.client;version="[4.2.6,5.0.0)",
org.apache.http.impl.conn;version="[4.2.6,5.0.0)",
- org.eclipse.jgit.annotations;version="[4.11.1,4.12.0)";resolution:=optional,
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.attributes;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.diff;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.hooks;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.io;version="[4.11.1,4.12.0)"
+ org.eclipse.jgit.annotations;version="[5.0.0,5.1.0)";resolution:=optional,
+ org.eclipse.jgit.api.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.attributes;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.diff;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.hooks;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.pack;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.io;version="[5.0.0,5.1.0)"
diff --git a/org.eclipse.jgit.lfs/pom.xml b/org.eclipse.jgit.lfs/pom.xml
index 15e8c005fe..b1539e517b 100644
--- a/org.eclipse.jgit.lfs/pom.xml
+++ b/org.eclipse.jgit.lfs/pom.xml
@@ -50,7 +50,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.lfs</artifactId>
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java
index 40d83420ec..4c46bbd23a 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/Lfs.java
@@ -65,19 +65,6 @@ public class Lfs {
/**
* Constructor for Lfs.
*
- * @param root
- * the path to the LFS media directory. Will be
- * {@code "<repo>/.git/lfs"}
- * @deprecated use {@link #Lfs(Repository)} instead.
- */
- @Deprecated
- public Lfs(Path root) {
- this.root = root;
- }
-
- /**
- * Constructor for Lfs.
- *
* @param db
* the associated repo
*
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
index 0e3830c098..4f959409fc 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPointer.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.lfs;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.BufferedReader;
import java.io.IOException;
@@ -134,7 +134,7 @@ public class LfsPointer implements Comparable<LfsPointer> {
*/
public void encode(OutputStream out) {
try (PrintStream ps = new PrintStream(out, false,
- UTF_8.name())) {
+ CHARSET.name())) {
ps.print("version "); //$NON-NLS-1$
ps.print(VERSION + "\n"); //$NON-NLS-1$
ps.print("oid " + HASH_FUNCTION_NAME + ":"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -143,7 +143,7 @@ public class LfsPointer implements Comparable<LfsPointer> {
ps.print(size + "\n"); //$NON-NLS-1$
} catch (UnsupportedEncodingException e) {
// should not happen, we are using a standard charset
- throw new UnsupportedCharsetException(UTF_8.name());
+ throw new UnsupportedCharsetException(CHARSET.name());
}
}
@@ -165,7 +165,7 @@ public class LfsPointer implements Comparable<LfsPointer> {
long sz = -1;
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(in, UTF_8))) {
+ new InputStreamReader(in, CHARSET))) {
for (String s = br.readLine(); s != null; s = br.readLine()) {
if (s.startsWith("#") || s.length() == 0) { //$NON-NLS-1$
continue;
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java
index c522572ee3..7fd7c216ac 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/LfsPrePushHook.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.lfs;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lfs.Protocol.OPERATION_UPLOAD;
import static org.eclipse.jgit.lfs.internal.LfsConnectionFactory.toRequest;
import static org.eclipse.jgit.transport.http.HttpConnection.HTTP_OK;
@@ -204,7 +204,7 @@ public class LfsPrePushHook extends PrePushHook {
}
Gson gson = Protocol.gson();
api.getOutputStream().write(
- gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(UTF_8));
+ gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(CHARSET));
int responseCode = api.getResponseCode();
if (responseCode != HTTP_OK) {
throw new IOException(
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java
index e2ab309230..6bff12f9cc 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java
@@ -42,11 +42,12 @@
*/
package org.eclipse.jgit.lfs;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.MessageFormat;
@@ -169,7 +170,7 @@ public class SmudgeFilter extends FilterCommand {
.write(gson
.toJson(LfsConnectionFactory
.toRequest(Protocol.OPERATION_DOWNLOAD, res))
- .getBytes(StandardCharsets.UTF_8));
+ .getBytes(CHARSET));
int responseCode = lfsServerConn.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK) {
throw new IOException(
diff --git a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java
index 5d8268b73e..25a70c745a 100644
--- a/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java
+++ b/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/internal/LfsConnectionFactory.java
@@ -47,9 +47,7 @@ import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT;
import static org.eclipse.jgit.util.HttpSupport.HDR_ACCEPT_ENCODING;
import static org.eclipse.jgit.util.HttpSupport.HDR_CONTENT_TYPE;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.ProxySelector;
import java.net.URL;
import java.text.SimpleDateFormat;
@@ -66,20 +64,17 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.HttpConfig;
import org.eclipse.jgit.transport.HttpTransport;
-import org.eclipse.jgit.transport.RemoteSession;
-import org.eclipse.jgit.transport.SshSessionFactory;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.http.HttpConnection;
-import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.HttpSupport;
-import org.eclipse.jgit.util.io.MessageWriter;
-import org.eclipse.jgit.util.io.StreamCopyThread;
+import org.eclipse.jgit.util.SshSupport;
/**
* Provides means to get a valid LFS connection for a given repository.
*/
public class LfsConnectionFactory {
+ private static final int SSH_AUTH_TIMEOUT_SECONDS = 5;
private static final String SCHEME_HTTPS = "https"; //$NON-NLS-1$
private static final String SCHEME_SSH = "ssh"; //$NON-NLS-1$
private static final Map<String, AuthCache> sshAuthCache = new TreeMap<>();
@@ -193,10 +188,11 @@ public class LfsConnectionFactory {
// discover and authenticate; git-lfs does "ssh
// -p <port> -- <host> git-lfs-authenticate
// <project> <upload/download>"
- String json = runSshCommand(u.setPath(""), //$NON-NLS-1$
- db.getFS(),
+ String json = SshSupport.runSshCommand(u.setPath(""), //$NON-NLS-1$
+ null, db.getFS(),
"git-lfs-authenticate " + extractProjectName(u) + " " //$NON-NLS-1$//$NON-NLS-2$
- + purpose);
+ + purpose,
+ SSH_AUTH_TIMEOUT_SECONDS);
action = Protocol.gson().fromJson(json,
Protocol.ExpiringAction.class);
@@ -253,42 +249,6 @@ public class LfsConnectionFactory {
}
}
- private static String runSshCommand(URIish sshUri, FS fs, String command)
- throws IOException {
- RemoteSession session = null;
- Process process = null;
- StreamCopyThread errorThread = null;
- try (MessageWriter stderr = new MessageWriter()) {
- session = SshSessionFactory.getInstance().getSession(sshUri, null,
- fs, 5_000);
- process = session.exec(command, 0);
- errorThread = new StreamCopyThread(process.getErrorStream(),
- stderr.getRawStream());
- errorThread.start();
- try (BufferedReader reader = new BufferedReader(
- new InputStreamReader(process.getInputStream(),
- org.eclipse.jgit.lib.Constants.CHARSET))) {
- return reader.readLine();
- }
- } finally {
- if (process != null) {
- process.destroy();
- }
- if (errorThread != null) {
- try {
- errorThread.halt();
- } catch (InterruptedException e) {
- // Stop waiting and return anyway.
- } finally {
- errorThread = null;
- }
- }
- if (session != null) {
- SshSessionFactory.getInstance().releaseSession(session);
- }
- }
- }
-
/**
* @param operation
* the operation to perform, e.g. Protocol.OPERATION_DOWNLOAD
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml
index 81211fcdcd..ab047c968a 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml
index db69cab4d5..d6f38ac160 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml
index 11f8ed0889..6c046b454c 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit.http.apache"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml
index 992e4c4f0b..7dcc484ebc 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml
index 6f5958defe..7ad4b1a6c1 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit.junit"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml
index 885dba02c8..8b0b3eee03 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/feature.xml
index ec9d2e3ad3..b3770f5435 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit.lfs"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/pom.xml
index c29d7ec188..8c49ebfb57 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.lfs.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml
index 6a29a01df3..f1a81011eb 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit.pgm"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
@@ -31,8 +31,8 @@
version="0.0.0"/>
<requires>
- <import feature="org.eclipse.jgit" version="4.11.1" match="equivalent"/>
- <import feature="org.eclipse.jgit.lfs" version="4.11.1" match="equivalent"/>
+ <import feature="org.eclipse.jgit" version="5.0.0" match="equivalent"/>
+ <import feature="org.eclipse.jgit.lfs" version="5.0.0" match="equivalent"/>
</requires>
<plugin
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml
index f5768c1597..c81ed79697 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml
index 5d9d073a0f..a93d865aed 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit.pgm.source"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml
index bbf0f25956..13d58fbe1c 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml
index f5002a7f2f..92d669217b 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.repository</artifactId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml
index ec448c5b58..b8244a852f 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.jgit.source"
label="%featureName"
- version="4.11.1.qualifier"
+ version="5.0.0.qualifier"
provider-name="%providerName">
<description url="http://www.eclipse.org/jgit/">
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml
index c093cc9a57..aba2cb6e24 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml
@@ -50,7 +50,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.jgit.feature</groupId>
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF
index 62dfe917e4..3fb306bb68 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF
@@ -2,4 +2,4 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JGit Target Platform Bundle
Bundle-SymbolicName: org.eclipse.jgit.target
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml
index 90b660eca0..63b87af725 100644
--- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml
+++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml
@@ -49,7 +49,7 @@
<parent>
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.jgit.target</artifactId>
diff --git a/org.eclipse.jgit.packaging/pom.xml b/org.eclipse.jgit.packaging/pom.xml
index 7e6b8f1bd2..5afdae5c19 100644
--- a/org.eclipse.jgit.packaging/pom.xml
+++ b/org.eclipse.jgit.packaging/pom.xml
@@ -53,7 +53,7 @@
<groupId>org.eclipse.jgit</groupId>
<artifactId>jgit.tycho.parent</artifactId>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>JGit Tycho Parent</name>
diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
index 68f7f38195..bee6c49389 100644
--- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF
@@ -3,28 +3,28 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.pgm.test
Bundle-SymbolicName: org.eclipse.jgit.pgm.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Import-Package: org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.diff;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.dircache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="4.11.1",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.merge;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm.opt;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.io;version="[4.11.1,4.12.0)",
+Import-Package: org.eclipse.jgit.api;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.api.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.diff;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.dircache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="5.0.0",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.merge;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.pgm;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.pgm.opt;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.io;version="[5.0.0,5.1.0)",
org.hamcrest.core;bundle-version="[1.1.0,2.0.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.pgm.test/pom.xml b/org.eclipse.jgit.pgm.test/pom.xml
index 02dd076685..2c36e46079 100644
--- a/org.eclipse.jgit.pgm.test/pom.xml
+++ b/org.eclipse.jgit.pgm.test/pom.xml
@@ -50,7 +50,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.pgm.test</artifactId>
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
index e5c85ebfc7..e992ddfb5b 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ArchiveTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.pgm;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -612,7 +612,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
private BufferedReader readFromProcess(Process proc) throws Exception {
return new BufferedReader(
- new InputStreamReader(proc.getInputStream(), UTF_8));
+ new InputStreamReader(proc.getInputStream(), CHARSET));
}
private void grepForEntry(String name, String mode, String... cmdline)
@@ -750,7 +750,7 @@ public class ArchiveTest extends CLIRepositoryTestCase {
// found!
List<String> l = new ArrayList<>();
BufferedReader reader = new BufferedReader(
- new InputStreamReader(in, UTF_8));
+ new InputStreamReader(in, CHARSET));
String line;
while ((line = reader.readLine()) != null)
l.add(line);
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java
index 9685d4517a..dde1a332db 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/FetchTest.java
@@ -92,6 +92,19 @@ public class FetchTest extends CLIRepositoryTestCase {
}
@Test
+ public void testFetchForceUpdate() throws Exception {
+ String[] result = execute(
+ "git fetch test refs/heads/master:refs/remotes/origin/master");
+ assertEquals(" * [new branch] master -> origin/master",
+ result[1]);
+ assertEquals(" * [new tag] tag -> tag", result[2]);
+ remoteGit.commit().setAmend(true).setMessage("amended").call();
+ result = execute(
+ "git fetch -f test refs/heads/master:refs/remotes/origin/master");
+ assertEquals("", result[0]);
+ }
+
+ @Test
public void testFetchNoTags() throws Exception {
String[] result = execute("git fetch --no-tags test refs/heads/master:refs/remotes/origin/master");
assertEquals(" * [new branch] master -> origin/master",
diff --git a/org.eclipse.jgit.pgm/.settings/.api_filters b/org.eclipse.jgit.pgm/.settings/.api_filters
new file mode 100644
index 0000000000..facef2df6b
--- /dev/null
+++ b/org.eclipse.jgit.pgm/.settings/.api_filters
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jgit.pgm" version="2">
+ <resource path="META-INF/MANIFEST.MF">
+ <filter id="925892614">
+ <message_arguments>
+ <message_argument value="5.0.0"/>
+ <message_argument value="4.11.0"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
index 8c35976aa0..0e47968344 100644
--- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.pgm
Bundle-SymbolicName: org.eclipse.jgit.pgm
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
@@ -28,49 +28,49 @@ Import-Package: javax.servlet;version="[3.1.0,4.0.0)",
org.eclipse.jetty.util.log;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)",
- org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.archive;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.awtui;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.blame;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.diff;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.dircache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.gitrepo;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.ketch;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.io;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftree;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.server;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.server.fs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs.server.s3;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.merge;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.notes;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revplot;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http.apache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.resolver;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.io;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.api;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.api.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.archive;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.awtui;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.blame;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.diff;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.dircache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.gitrepo;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.ketch;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftree;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.server;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.server.fs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs.server.s3;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.merge;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.notes;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revplot;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.pack;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http.apache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.io;version="[5.0.0,5.1.0)",
org.kohsuke.args4j;version="[2.33.0,3.0.0)",
org.kohsuke.args4j.spi;version="[2.33.0,3.0.0)"
-Export-Package: org.eclipse.jgit.console;version="4.11.1";
+Export-Package: org.eclipse.jgit.console;version="5.0.0";
uses:="org.eclipse.jgit.transport,
org.eclipse.jgit.util",
- org.eclipse.jgit.pgm;version="4.11.1";
+ org.eclipse.jgit.pgm;version="5.0.0";
uses:="org.eclipse.jgit.revwalk,
org.eclipse.jgit.treewalk.filter,
org.eclipse.jgit.pgm.opt,
@@ -81,11 +81,11 @@ Export-Package: org.eclipse.jgit.console;version="4.11.1";
org.eclipse.jgit.treewalk,
javax.swing,
org.eclipse.jgit.transport",
- org.eclipse.jgit.pgm.debug;version="4.11.1";
+ org.eclipse.jgit.pgm.debug;version="5.0.0";
uses:="org.eclipse.jgit.util.io,
org.eclipse.jgit.pgm",
- org.eclipse.jgit.pgm.internal;version="4.11.1";x-friends:="org.eclipse.jgit.pgm.test,org.eclipse.jgit.test",
- org.eclipse.jgit.pgm.opt;version="4.11.1";
+ org.eclipse.jgit.pgm.internal;version="5.0.0";x-friends:="org.eclipse.jgit.pgm.test,org.eclipse.jgit.test",
+ org.eclipse.jgit.pgm.opt;version="5.0.0";
uses:="org.eclipse.jgit.lib,
org.eclipse.jgit.revwalk,
org.kohsuke.args4j.spi,
diff --git a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF
index 5804094405..e14f1c73a4 100644
--- a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF
+++ b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF
@@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2
Bundle-Name: org.eclipse.jgit.pgm - Sources
Bundle-SymbolicName: org.eclipse.jgit.pgm.source
Bundle-Vendor: Eclipse.org - JGit
-Bundle-Version: 4.11.1.qualifier
-Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="4.11.1.qualifier";roots="."
+Bundle-Version: 5.0.0.qualifier
+Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="5.0.0.qualifier";roots="."
diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml
index 285c31abe8..b4a3b11608 100644
--- a/org.eclipse.jgit.pgm/pom.xml
+++ b/org.eclipse.jgit.pgm/pom.xml
@@ -50,7 +50,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.pgm</artifactId>
diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
index cb0ea1bc48..e9370930d1 100644
--- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
+++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties
@@ -343,6 +343,7 @@ usage_forEachRefOutput=for-each-ref output
usage_forceCheckout=when switching branches, proceed even if the index or the working tree differs from HEAD
usage_forceClean=required to delete files or directories
usage_forceCreateBranchEvenExists=force create branch even exists
+usage_forcedFetch=force ref update fetch option
usage_forceReplacingAnExistingTag=force replacing an existing tag
usage_getAndSetOptions=Get and set repository or global options
usage_groups=Restrict manifest projects to ones with specified group(s), use "-" for excluding [default|all|G1,G2,G3|G4,-G5,-G6]
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java
index 81aeef8cdd..510daecd3d 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/CommandCatalog.java
@@ -43,11 +43,10 @@
package org.eclipse.jgit.pgm;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
@@ -148,31 +147,15 @@ public class CommandCatalog {
}
private void scan(final URL cUrl) {
- final BufferedReader cIn;
- try {
- final InputStream in = cUrl.openStream();
- cIn = new BufferedReader(new InputStreamReader(in, UTF_8));
- } catch (IOException err) {
- // If we cannot read from the service list, go to the next.
- //
- return;
- }
-
- try {
+ try (BufferedReader cIn = new BufferedReader(
+ new InputStreamReader(cUrl.openStream(), CHARSET))) {
String line;
while ((line = cIn.readLine()) != null) {
if (line.length() > 0 && !line.startsWith("#")) //$NON-NLS-1$
load(line);
}
- } catch (IOException err) {
- // If we failed during a read, ignore the error.
- //
- } finally {
- try {
- cIn.close();
- } catch (IOException e) {
- // Ignore the close error; we are only reading.
- }
+ } catch (IOException e) {
+ // Ignore errors
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
index bc76372862..61fd521b80 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Fetch.java
@@ -100,6 +100,9 @@ class Fetch extends AbstractFetchCommand implements FetchCommand.Callback {
tags = Boolean.FALSE;
}
+ @Option(name = "--force", usage = "usage_forcedFetch", aliases = { "-f" })
+ private Boolean force;
+
private FetchRecurseSubmodulesMode recurseSubmodules;
@Option(name = "--recurse-submodules", usage = "usage_recurseSubmodules")
@@ -155,6 +158,9 @@ class Fetch extends AbstractFetchCommand implements FetchCommand.Callback {
if (quiet == null || !quiet.booleanValue())
fetch.setProgressMonitor(new TextProgressMonitor(errw));
fetch.setRecurseSubmodules(recurseSubmodules).setCallback(this);
+ if (force != null) {
+ fetch.setForceUpdate(force.booleanValue());
+ }
FetchResult result = fetch.call();
if (result.getTrackingRefUpdates().isEmpty()
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
index a376bc098d..75612be753 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.pgm;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.File;
import java.io.IOException;
@@ -217,7 +217,7 @@ public class Main {
}
PrintWriter createErrorWriter() {
- return new PrintWriter(new OutputStreamWriter(System.err, UTF_8));
+ return new PrintWriter(new OutputStreamWriter(System.err, CHARSET));
}
private void execute(final String[] argv) throws Exception {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java
index 5efc03b287..58acc5cafd 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Version.java
@@ -96,14 +96,9 @@ class Version extends TextBuiltin {
}
private static String getBundleVersion(URL url) {
- try {
- InputStream is = url.openStream();
- try {
- Manifest manifest = new Manifest(is);
- return manifest.getMainAttributes().getValue("Bundle-Version"); //$NON-NLS-1$
- } finally {
- is.close();
- }
+ try (InputStream is = url.openStream()) {
+ Manifest manifest = new Manifest(is);
+ return manifest.getMainAttributes().getValue("Bundle-Version"); //$NON-NLS-1$
} catch (IOException e) {
// do nothing - will return null
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java
index 248eaac8ad..575a122158 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/BenchmarkReftable.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.pgm.debug;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.lib.Constants.MASTER;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
@@ -154,7 +154,7 @@ class BenchmarkReftable extends TextBuiltin {
throws IOException, FileNotFoundException {
RefList.Builder<Ref> list = new RefList.Builder<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(lsRemotePath), UTF_8))) {
+ new FileInputStream(lsRemotePath), CHARSET))) {
Ref last = null;
String line;
while ((line = br.readLine()) != null) {
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
index bbc1b0f330..f39ecbecf2 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/ShowPackDelta.java
@@ -125,12 +125,13 @@ class ShowPackDelta extends TextBuiltin {
ptr++;
ptr++;
- @SuppressWarnings("resource" /* java 7 */)
- TemporaryBuffer.Heap raw = new TemporaryBuffer.Heap(bufArray.length);
- InflaterInputStream inf = new InflaterInputStream(
- new ByteArrayInputStream(bufArray, ptr, bufArray.length));
- raw.copy(inf);
- inf.close();
- return raw.toByteArray();
+ try (TemporaryBuffer.Heap raw = new TemporaryBuffer.Heap(
+ bufArray.length);
+ InflaterInputStream inf = new InflaterInputStream(
+ new ByteArrayInputStream(bufArray, ptr,
+ bufArray.length))) {
+ raw.copy(inf);
+ return raw.toByteArray();
+ }
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
index 83b7bcea26..6378e8d220 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
@@ -288,11 +288,8 @@ class TextHashFunctions extends TextBuiltin {
else
rb.findGitDir(dir);
- Repository repo = rb.build();
- try {
+ try (Repository repo = rb.build()) {
run(repo);
- } finally {
- repo.close();
}
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java
index 6cbc1b082b..c5ea028be8 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/WriteReftable.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.pgm.debug;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.lib.Constants.MASTER;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
@@ -192,7 +192,7 @@ class WriteReftable extends TextBuiltin {
static List<Ref> readRefs(String inputFile) throws IOException {
List<Ref> refs = new ArrayList<>();
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(new FileInputStream(inputFile), UTF_8))) {
+ new InputStreamReader(new FileInputStream(inputFile), CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
ObjectId id = ObjectId.fromString(line.substring(0, 40));
@@ -227,7 +227,7 @@ class WriteReftable extends TextBuiltin {
List<LogEntry> log = new ArrayList<>();
try (BufferedReader br = new BufferedReader(
- new InputStreamReader(new FileInputStream(logPath), UTF_8))) {
+ new InputStreamReader(new FileInputStream(logPath), CHARSET))) {
@SuppressWarnings("nls")
Pattern pattern = Pattern.compile("([^,]+)" // 1: ref
+ ",([0-9]+(?:[.][0-9]+)?)" // 2: time
diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
index 49f5cc0008..06bac92953 100644
--- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF
@@ -3,58 +3,58 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.test
Bundle-SymbolicName: org.eclipse.jgit.test
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Localization: plugin
Bundle-Vendor: %provider_name
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)",
com.jcraft.jsch;version="[0.1.54,0.2.0)",
- org.eclipse.jgit.api;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.api.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.attributes;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.awtui;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.blame;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.diff;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.dircache;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.events;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.fnmatch;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.gitrepo;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.hooks;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.ignore;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.ignore.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.fsck;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.dfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.io;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftable;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.internal.storage.reftree;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.junit;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lfs;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.merge;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.notes;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.patch;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.pgm.internal;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revplot;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.file;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.storage.pack;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.submodule;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.http;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport.resolver;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.treewalk.filter;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.io;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util.sha1;version="[4.11.1,4.12.0)",
+ org.eclipse.jgit.api;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.api.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.attributes;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.awtui;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.blame;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.diff;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.dircache;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.events;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.fnmatch;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.gitrepo;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.hooks;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.ignore;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.ignore.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.fsck;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.dfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.io;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.pack;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftable;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.internal.storage.reftree;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.junit;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lfs;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.merge;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.notes;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.patch;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.pgm;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.pgm.internal;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revplot;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.file;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.storage.pack;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.submodule;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.http;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport.resolver;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.treewalk.filter;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.io;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util.sha1;version="[5.0.0,5.1.0)",
org.junit;version="[4.12,5.0.0)",
org.junit.experimental.theories;version="[4.12,5.0.0)",
org.junit.rules;version="[4.12,5.0.0)",
diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
index 438d2d625b..4d9e864227 100644
--- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/ignore/CGitVsJGitRandomIgnorePatternTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.ignore;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import java.io.BufferedReader;
import java.io.File;
@@ -158,7 +158,7 @@ public class CGitVsJGitRandomIgnorePatternTest {
this.gitDir = gitDir;
this.pattern = pattern;
Files.write(FileUtils.toPath(new File(gitDir, ".gitignore")),
- (pattern + "\n").getBytes(UTF_8), StandardOpenOption.CREATE,
+ (pattern + "\n").getBytes(CHARSET), StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE);
}
@@ -188,7 +188,7 @@ public class CGitVsJGitRandomIgnorePatternTest {
Process proc = Runtime.getRuntime().exec(command, new String[0],
gitDir);
try (OutputStream out = proc.getOutputStream()) {
- out.write((path + "\n").getBytes(UTF_8));
+ out.write((path + "\n").getBytes(CHARSET));
out.flush();
}
return proc;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java
index 611418d22c..b238389847 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPackLogger.java
+++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/treewalk/FileTreeIteratorPerformanceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Google Inc.
+ * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -40,38 +40,54 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+package org.eclipse.jgit.treewalk;
-package org.eclipse.jgit.transport;
+import static org.junit.Assert.fail;
-import org.eclipse.jgit.internal.storage.pack.PackWriter;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.treewalk.filter.PathFilter;
+import org.junit.Test;
/**
- * 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
+ * Simple performance test for git add / FileTreeIterator.
*/
-@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.
- }
- };
+public class FileTreeIteratorPerformanceTest extends RepositoryTestCase {
- /**
- * 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);
+ private static int N_OF_FILES = 501;
+
+ @Test
+ public void testPerformance() throws Exception {
+ try (Git git = new Git(db)) {
+ long times[] = new long[N_OF_FILES];
+ long sum = 0;
+ String lastName = null;
+ for (int i = 0; i < N_OF_FILES; i++) {
+ lastName = "a" + (i + 100000) + ".txt";
+ writeTrashFile(lastName, "");
+ long start = System.nanoTime();
+ git.add().addFilepattern(lastName).call();
+ long elapsed = System.nanoTime() - start;
+ times[i] = elapsed;
+ sum += elapsed;
+ }
+ System.out.println("Total (µs) " + sum / 1000.0);
+ for (int i = 0; i < times.length; i++) {
+ System.out
+ .println("Time " + i + " (µs) = " + times[i] / 1000.0);
+ }
+ FileTreeIterator iter = new FileTreeIterator(db);
+ try (TreeWalk walk = new TreeWalk(db)) {
+ walk.setFilter(PathFilter.create(lastName));
+ walk.addTree(iter);
+ long start = System.nanoTime();
+ if (walk.next()) {
+ System.out.println("Walk time (µs) = "
+ + (System.nanoTime() - start) / 1000.0);
+ } else {
+ fail("File not found");
+ }
+ }
+ }
+ }
}
diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml
index af4056c36f..e53aaabc4e 100644
--- a/org.eclipse.jgit.test/pom.xml
+++ b/org.eclipse.jgit.test/pom.xml
@@ -52,7 +52,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.test</artifactId>
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
index edab96b971..1300f98d8a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ArchiveCommandTest.java
@@ -229,11 +229,6 @@ public class ArchiveCommandTest extends RepositoryTestCase {
}
@Override
- public void putEntry(MockOutputStream out, String path, FileMode mode, ObjectLoader loader) {
- putEntry(out, null, path, mode, loader);
- }
-
- @Override
public void putEntry(MockOutputStream out, ObjectId tree, String path, FileMode mode, ObjectLoader loader) {
String content = mode != FileMode.TREE ? new String(loader.getBytes()) : null;
entries.put(path, content);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
index 0dd3749337..3a13aa5a41 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
@@ -54,7 +54,7 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
-import org.eclipse.jgit.api.errors.EmtpyCommitException;
+import org.eclipse.jgit.api.errors.EmptyCommitException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.dircache.DirCache;
@@ -553,8 +553,8 @@ public class CommitCommandTest extends RepositoryTestCase {
git.commit().setAuthor("New Author", "newauthor@example.org")
.setMessage("again no change").setAllowEmpty(false)
.call();
- fail("Didn't get the expected EmtpyCommitException");
- } catch (EmtpyCommitException e) {
+ fail("Didn't get the expected EmptyCommitException");
+ } catch (EmptyCommitException e) {
// expect this exception
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
index 1e3a39aad8..bb303cc411 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java
@@ -42,7 +42,7 @@
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_CRLF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.AUTO_LF;
import static org.eclipse.jgit.lib.CoreConfig.EolStreamType.DIRECT;
@@ -150,8 +150,8 @@ public class EolStreamTypeUtilTest {
EolStreamType streamTypeWithBinaryCheck, String output,
String expectedConversion) throws Exception {
ByteArrayOutputStream b;
- byte[] outputBytes = output.getBytes(UTF_8);
- byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
+ byte[] outputBytes = output.getBytes(CHARSET);
+ byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET);
// test using output text and assuming it was declared TEXT
b = new ByteArrayOutputStream();
@@ -277,8 +277,8 @@ public class EolStreamTypeUtilTest {
private void testCheckin(EolStreamType streamTypeText,
EolStreamType streamTypeWithBinaryCheck, String input,
String expectedConversion) throws Exception {
- byte[] inputBytes = input.getBytes(UTF_8);
- byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8);
+ byte[] inputBytes = input.getBytes(CHARSET);
+ byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET);
// test using input text and assuming it was declared TEXT
try (InputStream in = EolStreamTypeUtil.wrapInputStream(
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
index 83a0564c77..cf1afceae6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/FetchCommandTest.java
@@ -102,6 +102,25 @@ public class FetchCommandTest extends RepositoryTestCase {
}
@Test
+ public void testForcedFetch() throws Exception {
+ remoteGit.commit().setMessage("commit").call();
+ remoteGit.commit().setMessage("commit2").call();
+ git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/master").call();
+
+ remoteGit.commit().setAmend(true).setMessage("amended").call();
+ FetchResult res = git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/master").call();
+ assertEquals(RefUpdate.Result.REJECTED,
+ res.getTrackingRefUpdate("refs/heads/master").getResult());
+ res = git.fetch().setRemote("test")
+ .setRefSpecs("refs/heads/master:refs/heads/master")
+ .setForceUpdate(true).call();
+ assertEquals(RefUpdate.Result.FORCED,
+ res.getTrackingRefUpdate("refs/heads/master").getResult());
+ }
+
+ @Test
public void fetchShouldAutoFollowTag() throws Exception {
remoteGit.commit().setMessage("commit").call();
Ref tagRef = remoteGit.tag().setName("foo").call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
index 6e06e9545a..e234aa339c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import java.util.List;
@@ -88,7 +88,7 @@ public class NotesCommandTest extends RepositoryTestCase {
git.notesAdd().setObjectId(commit2).setMessage("data").call();
Note note = git.notesShow().setObjectId(commit2).call();
String content = new String(db.open(note.getData()).getCachedBytes(),
- UTF_8);
+ CHARSET);
assertEquals(content, "data");
git.notesRemove().setObjectId(commit2).call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index 9461c42500..0b0e3bf3ea 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -592,7 +592,7 @@ public class PullCommandTest extends RepositoryTestCase {
private static void writeToFile(File actFile, String string)
throws IOException {
try (FileOutputStream fos = new FileOutputStream(actFile)) {
- fos.write(string.getBytes(UTF_8));
+ fos.write(string.getBytes(CHARSET));
}
}
@@ -606,7 +606,7 @@ public class PullCommandTest extends RepositoryTestCase {
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
- String content = new String(bos.toByteArray(), UTF_8);
+ String content = new String(bos.toByteArray(), CHARSET);
assertEquals(string, content);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
index 913b4ac434..b349c66cab 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -396,7 +396,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
private static void writeToFile(File actFile, String string)
throws IOException {
try (FileOutputStream fos = new FileOutputStream(actFile)) {
- fos.write(string.getBytes(UTF_8));
+ fos.write(string.getBytes(CHARSET));
}
}
@@ -410,7 +410,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
bos.write(buffer, 0, read);
read = fis.read(buffer);
}
- String content = new String(bos.toByteArray(), UTF_8);
+ String content = new String(bos.toByteArray(), CHARSET);
assertEquals(string, content);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index 2bf91aeed8..96e7091ae1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.api;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -1464,7 +1464,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]);
PersonIdent parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes(UTF_8));
+ convertedAuthor.getBytes(CHARSET));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
// this is rounded to the last second
@@ -1481,7 +1481,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]);
parsedIdent = git.rebase().parseAuthor(
- convertedAuthor.getBytes(UTF_8));
+ convertedAuthor.getBytes(CHARSET));
assertEquals(ident.getName(), parsedIdent.getName());
assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress());
assertEquals(123456789000L, parsedIdent.getWhen().getTime());
@@ -2104,7 +2104,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
int count = 0;
File todoFile = getTodoFile();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(todoFile), UTF_8))) {
+ new FileInputStream(todoFile), CHARSET))) {
String line = br.readLine();
while (line != null) {
int firstBlank = line.indexOf(' ');
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index ba51881ffd..8f56a9270e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
@@ -100,39 +100,39 @@ public class ResetCommandTest extends RepositoryTestCase {
File nestedFile = new File(dir, "b.txt");
FileUtils.createNewFile(nestedFile);
- PrintWriter nesterFileWriter = new PrintWriter(nestedFile);
- nesterFileWriter.print("content");
- nesterFileWriter.flush();
-
- // create file
- indexFile = new File(db.getWorkTree(), "a.txt");
- FileUtils.createNewFile(indexFile);
- PrintWriter writer = new PrintWriter(indexFile);
- writer.print("content");
- writer.flush();
-
- // add file and commit it
- git.add().addFilepattern("dir").addFilepattern("a.txt").call();
- secondCommit = git.commit().setMessage("adding a.txt and dir/b.txt")
- .call();
-
- prestage = DirCache.read(db.getIndexFile(), db.getFS()).getEntry(
- indexFile.getName());
-
- // modify file and add to index
- writer.print("new content");
- writer.close();
- nesterFileWriter.print("new content");
- nesterFileWriter.close();
+ try (PrintWriter nestedFileWriter = new PrintWriter(nestedFile)) {
+ nestedFileWriter.print("content");
+ nestedFileWriter.flush();
+
+ // create file
+ indexFile = new File(db.getWorkTree(), "a.txt");
+ FileUtils.createNewFile(indexFile);
+ try (PrintWriter writer = new PrintWriter(indexFile)) {
+ writer.print("content");
+ writer.flush();
+
+ // add file and commit it
+ git.add().addFilepattern("dir").addFilepattern("a.txt").call();
+ secondCommit = git.commit()
+ .setMessage("adding a.txt and dir/b.txt").call();
+
+ prestage = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+
+ // modify file and add to index
+ writer.print("new content");
+ }
+ nestedFileWriter.print("new content");
+ }
git.add().addFilepattern("a.txt").addFilepattern("dir").call();
// create a file not added to the index
untrackedFile = new File(db.getWorkTree(),
"notAddedToIndex.txt");
FileUtils.createNewFile(untrackedFile);
- PrintWriter writer2 = new PrintWriter(untrackedFile);
- writer2.print("content");
- writer2.close();
+ try (PrintWriter writer2 = new PrintWriter(untrackedFile)) {
+ writer2.print("content");
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
index 0f13a68b25..32f34213ec 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/AbstractDiffTestCase.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.diff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -240,6 +240,6 @@ public abstract class AbstractDiffTestCase {
r.append(text.charAt(i));
r.append('\n');
}
- return new RawText(r.toString().getBytes(UTF_8));
+ return new RawText(r.toString().getBytes(CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
index 6ad59b9e56..69e40777cc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RawTextTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.diff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -136,8 +136,8 @@ public class RawTextTest {
e = c.reduceCommonStartEnd(t("abQxy"), t("abRxy"), e);
assertEquals(new Edit(2, 3, 2, 3), e);
- RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(UTF_8));
- RawText b = new RawText("p\na b \nR\n c d \n".getBytes(UTF_8));
+ RawText a = new RawText("p\na b\nQ\nc d\n".getBytes(CHARSET));
+ RawText b = new RawText("p\na b \nR\n c d \n".getBytes(CHARSET));
e = new Edit(0, 4, 0, 4);
e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(2, 3, 2, 3), e);
@@ -149,14 +149,14 @@ public class RawTextTest {
RawText b;
Edit e;
- a = new RawText("R\n y\n".getBytes(UTF_8));
- b = new RawText("S\n\n y\n".getBytes(UTF_8));
+ a = new RawText("R\n y\n".getBytes(CHARSET));
+ b = new RawText("S\n\n y\n".getBytes(CHARSET));
e = new Edit(0, 2, 0, 3);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e);
- a = new RawText("S\n\n y\n".getBytes(UTF_8));
- b = new RawText("R\n y\n".getBytes(UTF_8));
+ a = new RawText("S\n\n y\n".getBytes(CHARSET));
+ b = new RawText("R\n y\n".getBytes(CHARSET));
e = new Edit(0, 3, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 2, 0, 1), e);
@@ -167,8 +167,8 @@ public class RawTextTest {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes(UTF_8));
- b = new RawText("start of line".getBytes(UTF_8));
+ a = new RawText("start".getBytes(CHARSET));
+ b = new RawText("start of line".getBytes(CHARSET));
e = new Edit(0, 1, 0, 1);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 1), e);
@@ -179,8 +179,8 @@ public class RawTextTest {
RawText a;
RawText b;
Edit e;
- a = new RawText("start".getBytes(UTF_8));
- b = new RawText("start of\nlastline".getBytes(UTF_8));
+ a = new RawText("start".getBytes(CHARSET));
+ b = new RawText("start of\nlastline".getBytes(CHARSET));
e = new Edit(0, 1, 0, 2);
e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e);
assertEquals(new Edit(0, 1, 0, 2), e);
@@ -239,6 +239,6 @@ public class RawTextTest {
r.append(text.charAt(i));
r.append('\n');
}
- return new RawText(r.toString().getBytes(UTF_8));
+ return new RawText(r.toString().getBytes(CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
index f168e83284..51a6f8121c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/SimilarityIndexTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.diff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -82,7 +82,7 @@ public class SimilarityIndexTest {
+ "A\n" //
+ "B\n" //
+ "B\n" //
- + "B\n").getBytes(UTF_8);
+ + "B\n").getBytes(CHARSET);
SimilarityIndex si = new SimilarityIndex();
si.hash(new ByteArrayInputStream(in), in.length, false);
assertEquals(2, si.size());
@@ -130,12 +130,12 @@ public class SimilarityIndexTest {
+ "D\r\n" //
+ "B\r\n";
SimilarityIndex src = new SimilarityIndex();
- byte[] bytes1 = text.getBytes(UTF_8);
+ byte[] bytes1 = text.getBytes(CHARSET);
src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true);
src.sort();
SimilarityIndex dst = new SimilarityIndex();
- byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8);
+ byte[] bytes2 = text.replace("\r", "").getBytes(CHARSET);
dst.hash(new ByteArrayInputStream(bytes2), bytes2.length, true);
dst.sort();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
index dec17623fc..80d4329858 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.dircache;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -236,7 +236,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
private static Map<String, CGitIndexRecord> readLsFiles() throws Exception {
final LinkedHashMap<String, CGitIndexRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) {
+ new FileInputStream(pathOf("gitgit.lsfiles")), CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final CGitIndexRecord cr = new CGitIndexRecord(line);
@@ -249,7 +249,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
private static Map<String, CGitLsTreeRecord> readLsTree() throws Exception {
final LinkedHashMap<String, CGitLsTreeRecord> r = new LinkedHashMap<>();
try (BufferedReader br = new BufferedReader(new InputStreamReader(
- new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) {
+ new FileInputStream(pathOf("gitgit.lstree")), CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final CGitLsTreeRecord cr = new CGitLsTreeRecord(line);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
index c9673a6882..69a48cc4b5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.gitrepo;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -82,7 +82,7 @@ public class ManifestParserTest {
ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null);
- parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
+ parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET)));
// Unfiltered projects should have them all.
results.clear();
results.add("foo");
@@ -136,7 +136,7 @@ public class ManifestParserTest {
baseUrl, null, null);
try {
parser.read(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)));
+ xmlContent.toString().getBytes(CHARSET)));
fail("ManifestParser did not throw exception for missing fetch");
} catch (IOException e) {
assertTrue(e.getCause() instanceof SAXException);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java
index 341cc4f215..548b9033bc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandSymlinkTest.java
@@ -119,45 +119,47 @@ public class RepoCommandSymlinkTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testCopyFileBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository()
+ .setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
+ .getRepository()) {
- // The LinkedHello symlink should exist.
- File linkedhello = new File(localDb.getWorkTree(), "LinkedHello");
- assertTrue("The LinkedHello file should exist",
- localDb.getFS().exists(linkedhello));
- assertTrue("The LinkedHello file should be a symlink",
- localDb.getFS().isSymLink(linkedhello));
- assertEquals("foo/hello.txt",
- localDb.getFS().readSymLink(linkedhello));
+ // The LinkedHello symlink should exist.
+ File linkedhello = new File(localDb.getWorkTree(),
+ "LinkedHello");
+ assertTrue("The LinkedHello file should exist",
+ localDb.getFS().exists(linkedhello));
+ assertTrue("The LinkedHello file should be a symlink",
+ localDb.getFS().isSymLink(linkedhello));
+ assertEquals("foo/hello.txt",
+ localDb.getFS().readSymLink(linkedhello));
- // The foo/LinkedHello file should be skipped.
- File linkedfoohello = new File(localDb.getWorkTree(), "foo/LinkedHello");
- assertFalse("The foo/LinkedHello file should be skipped",
- localDb.getFS().exists(linkedfoohello));
+ // The foo/LinkedHello file should be skipped.
+ File linkedfoohello = new File(localDb.getWorkTree(),
+ "foo/LinkedHello");
+ assertFalse("The foo/LinkedHello file should be skipped",
+ localDb.getFS().exists(linkedfoohello));
- // The subdir/LinkedHello file should use a relative ../
- File linkedsubdirhello = new File(localDb.getWorkTree(),
- "subdir/LinkedHello");
- assertTrue("The subdir/LinkedHello file should exist",
- localDb.getFS().exists(linkedsubdirhello));
- assertTrue("The subdir/LinkedHello file should be a symlink",
- localDb.getFS().isSymLink(linkedsubdirhello));
- assertEquals("../foo/hello.txt",
- localDb.getFS().readSymLink(linkedsubdirhello));
+ // The subdir/LinkedHello file should use a relative ../
+ File linkedsubdirhello = new File(localDb.getWorkTree(),
+ "subdir/LinkedHello");
+ assertTrue("The subdir/LinkedHello file should exist",
+ localDb.getFS().exists(linkedsubdirhello));
+ assertTrue("The subdir/LinkedHello file should be a symlink",
+ localDb.getFS().isSymLink(linkedsubdirhello));
+ assertEquals("../foo/hello.txt",
+ localDb.getFS().readSymLink(linkedsubdirhello));
- // The bar/foo/LinkedHello file should use a single relative ../
- File linkedbarfoohello = new File(localDb.getWorkTree(),
- "bar/foo/LinkedHello");
- assertTrue("The bar/foo/LinkedHello file should exist",
- localDb.getFS().exists(linkedbarfoohello));
- assertTrue("The bar/foo/LinkedHello file should be a symlink",
- localDb.getFS().isSymLink(linkedbarfoohello));
- assertEquals("../baz/hello.txt",
- localDb.getFS().readSymLink(linkedbarfoohello));
-
- localDb.close();
+ // The bar/foo/LinkedHello file should use a single relative ../
+ File linkedbarfoohello = new File(localDb.getWorkTree(),
+ "bar/foo/LinkedHello");
+ assertTrue("The bar/foo/LinkedHello file should exist",
+ localDb.getFS().exists(linkedbarfoohello));
+ assertTrue("The bar/foo/LinkedHello file should be a symlink",
+ localDb.getFS().isSymLink(linkedbarfoohello));
+ assertEquals("../baz/hello.txt",
+ localDb.getFS().readSymLink(linkedbarfoohello));
+ }
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
index 2253a0421f..fa45214f0c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.gitrepo;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -185,108 +185,93 @@ public class RepoCommandTest extends RepositoryTestCase {
}
}
+ private Repository cloneRepository(Repository repo, boolean bare)
+ throws Exception {
+ Repository r = Git.cloneRepository()
+ .setURI(repo.getDirectory().toURI().toString())
+ .setDirectory(createUniqueTestGitDir(true)).setBare(bare).call()
+ .getRepository();
+ if (bare) {
+ assertTrue(r.isBare());
+ } else {
+ assertFalse(r.isBare());
+ }
+ return r;
+ }
+
@Test
public void runTwiceIsNOP() throws Exception {
- Repository child = Git.cloneRepository()
- .setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
-
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\"..\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"base\" name=\"platform/base\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
- assertTrue(dest.isBare());
- assertTrue(child.isBare());
+ IndexedRepos repos = new IndexedRepos();
+ repos.put("platform/base", child);
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"remote1\" fetch=\"..\" />")
- .append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"base\" name=\"platform/base\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put("platform/base", child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
- String firstIdStr = commit.getId().name() + ":" + ".gitmodules";
- commit = new RepoCommand(dest)
- .setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- assertEquals(firstIdStr, idStr);
- child.close();
- dest.close();
+ String firstIdStr = commit.getId().name() + ":" + ".gitmodules";
+ commit = new RepoCommand(dest)
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ assertEquals(firstIdStr, idStr);
+ }
}
@Test
public void androidSetup() throws Exception {
- Repository child = Git.cloneRepository()
- .setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
-
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\"..\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"base\" name=\"platform/base\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
- assertTrue(dest.isBare());
- assertTrue(child.isBare());
+ IndexedRepos repos = new IndexedRepos();
+ repos.put("platform/base", child);
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"remote1\" fetch=\"..\" />")
- .append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"base\" name=\"platform/base\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put("platform/base", child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "base", "url");
- assertEquals(subUrl, "../base");
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "base", "url");
+ assertEquals(subUrl, "../base");
+ }
}
-
- child.close();
- dest.close();
}
@Test
@@ -299,200 +284,174 @@ public class RepoCommandTest extends RepositoryTestCase {
.append("<project path=\"base\" name=\"platform/base\" />")
.append("</manifest>");
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true)).setBare(true).call()
- .getRepository();
-
- assertTrue(dest.isBare());
-
- RevCommit commit = new RepoCommand(dest)
- .setInputStream(new ByteArrayInputStream(
- xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(new IndexedRepos())
- .setURI("platform/")
- .setTargetURI("platform/superproject")
- .setRecordRemoteBranch(true)
- .setIgnoreRemoteFailures(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
-
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "base", "url");
- assertEquals(subUrl, "https://host.com/platform/base");
+ try (Repository dest = cloneRepository(db, true)) {
+ RevCommit commit = new RepoCommand(dest)
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(new IndexedRepos()).setURI("platform/")
+ .setTargetURI("platform/superproject")
+ .setRecordRemoteBranch(true).setIgnoreRemoteFailures(true)
+ .setRecordSubmoduleLabels(true).call();
+
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "base", "url");
+ assertEquals(subUrl, "https://host.com/platform/base");
+ }
}
-
- dest.close();
}
@Test
public void gerritSetup() throws Exception {
- Repository child =
- Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
-
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"remote1\" fetch=\".\" />")
+ .append("<default revision=\"master\" remote=\"remote1\" />")
+ .append("<project path=\"plugins/cookbook\" name=\"plugins/cookbook\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
- assertTrue(dest.isBare());
- assertTrue(child.isBare());
+ IndexedRepos repos = new IndexedRepos();
+ repos.put("plugins/cookbook", child);
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"remote1\" fetch=\".\" />")
- .append("<default revision=\"master\" remote=\"remote1\" />")
- .append("<project path=\"plugins/cookbook\" name=\"plugins/cookbook\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put("plugins/cookbook", child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI("")
- .setTargetURI("gerrit")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI("").setTargetURI("gerrit")
+ .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true)
+ .call();
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "plugins/cookbook", "url");
- assertEquals(subUrl, "../plugins/cookbook");
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "plugins/cookbook",
+ "url");
+ assertEquals(subUrl, "../plugins/cookbook");
+ }
}
-
- child.close();
- dest.close();
}
@Test
public void absoluteRemoteURL() throws Exception {
- Repository child =
- Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- String abs = "https://chromium.googlesource.com";
- String repoUrl = "https://chromium.googlesource.com/chromium/src";
- boolean fetchSlash = false;
- boolean baseSlash = false;
- do {
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ String abs = "https://chromium.googlesource.com";
+ String repoUrl = "https://chromium.googlesource.com/chromium/src";
+ boolean fetchSlash = false;
+ boolean baseSlash = false;
do {
- String fetchUrl = fetchSlash ? abs + "/" : abs;
- String baseUrl = baseSlash ? abs + "/" : abs;
-
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"origin\" fetch=\"" + fetchUrl + "\" />")
- .append("<default revision=\"master\" remote=\"origin\" />")
- .append("<project path=\"src\" name=\"chromium/src\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put(repoUrl, child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI(baseUrl)
- .setTargetURI("gerrit")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
-
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "src", "url");
- assertEquals("https://chromium.googlesource.com/chromium/src", subUrl);
- }
- fetchSlash = !fetchSlash;
- } while (fetchSlash);
- baseSlash = !baseSlash;
- } while (baseSlash);
- child.close();
- dest.close();
+ do {
+ String fetchUrl = fetchSlash ? abs + "/" : abs;
+ String baseUrl = baseSlash ? abs + "/" : abs;
+
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"origin\" fetch=\""
+ + fetchUrl + "\" />")
+ .append("<default revision=\"master\" remote=\"origin\" />")
+ .append("<project path=\"src\" name=\"chromium/src\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
+
+ IndexedRepos repos = new IndexedRepos();
+ repos.put(repoUrl, child);
+
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI(baseUrl)
+ .setTargetURI("gerrit").setRecordRemoteBranch(true)
+ .setRecordSubmoduleLabels(true).call();
+
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "src",
+ "url");
+ assertEquals(
+ "https://chromium.googlesource.com/chromium/src",
+ subUrl);
+ }
+ fetchSlash = !fetchSlash;
+ } while (fetchSlash);
+ baseSlash = !baseSlash;
+ } while (baseSlash);
+ }
}
@Test
public void absoluteRemoteURLAbsoluteTargetURL() throws Exception {
- Repository child =
- Git.cloneRepository().setURI(groupADb.getDirectory().toURI().toString())
- .setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- Repository dest = Git.cloneRepository()
- .setURI(db.getDirectory().toURI().toString()).setDirectory(createUniqueTestGitDir(true))
- .setBare(true).call().getRepository();
- String abs = "https://chromium.googlesource.com";
- String repoUrl = "https://chromium.googlesource.com/chromium/src";
- boolean fetchSlash = false;
- boolean baseSlash = false;
- do {
+ try (Repository child = cloneRepository(groupADb, true);
+ Repository dest = cloneRepository(db, true)) {
+ String abs = "https://chromium.googlesource.com";
+ String repoUrl = "https://chromium.googlesource.com/chromium/src";
+ boolean fetchSlash = false;
+ boolean baseSlash = false;
do {
- String fetchUrl = fetchSlash ? abs + "/" : abs;
- String baseUrl = baseSlash ? abs + "/" : abs;
-
- StringBuilder xmlContent = new StringBuilder();
- xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
- .append("<manifest>")
- .append("<remote name=\"origin\" fetch=\"" + fetchUrl + "\" />")
- .append("<default revision=\"master\" remote=\"origin\" />")
- .append("<project path=\"src\" name=\"chromium/src\" />")
- .append("</manifest>");
- RepoCommand cmd = new RepoCommand(dest);
-
- IndexedRepos repos = new IndexedRepos();
- repos.put(repoUrl, child);
-
- RevCommit commit = cmd
- .setInputStream(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)))
- .setRemoteReader(repos)
- .setURI(baseUrl)
- .setTargetURI(abs + "/superproject")
- .setRecordRemoteBranch(true)
- .setRecordSubmoduleLabels(true)
- .call();
-
- String idStr = commit.getId().name() + ":" + ".gitmodules";
- ObjectId modId = dest.resolve(idStr);
-
- try (ObjectReader reader = dest.newObjectReader()) {
- byte[] bytes = reader.open(modId).getCachedBytes(Integer.MAX_VALUE);
- Config base = new Config();
- BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
- String subUrl = cfg.getString("submodule", "src", "url");
- assertEquals("../chromium/src", subUrl);
- }
- fetchSlash = !fetchSlash;
- } while (fetchSlash);
- baseSlash = !baseSlash;
- } while (baseSlash);
- child.close();
- dest.close();
+ do {
+ String fetchUrl = fetchSlash ? abs + "/" : abs;
+ String baseUrl = baseSlash ? abs + "/" : abs;
+
+ StringBuilder xmlContent = new StringBuilder();
+ xmlContent.append(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+ .append("<manifest>")
+ .append("<remote name=\"origin\" fetch=\""
+ + fetchUrl + "\" />")
+ .append("<default revision=\"master\" remote=\"origin\" />")
+ .append("<project path=\"src\" name=\"chromium/src\" />")
+ .append("</manifest>");
+ RepoCommand cmd = new RepoCommand(dest);
+
+ IndexedRepos repos = new IndexedRepos();
+ repos.put(repoUrl, child);
+
+ RevCommit commit = cmd
+ .setInputStream(new ByteArrayInputStream(
+ xmlContent.toString().getBytes(CHARSET)))
+ .setRemoteReader(repos).setURI(baseUrl)
+ .setTargetURI(abs + "/superproject")
+ .setRecordRemoteBranch(true)
+ .setRecordSubmoduleLabels(true).call();
+
+ String idStr = commit.getId().name() + ":" + ".gitmodules";
+ ObjectId modId = dest.resolve(idStr);
+
+ try (ObjectReader reader = dest.newObjectReader()) {
+ byte[] bytes = reader.open(modId)
+ .getCachedBytes(Integer.MAX_VALUE);
+ Config base = new Config();
+ BlobBasedConfig cfg = new BlobBasedConfig(base, bytes);
+ String subUrl = cfg.getString("submodule", "src",
+ "url");
+ assertEquals("../chromium/src", subUrl);
+ }
+ fetchSlash = !fetchSlash;
+ } while (fetchSlash);
+ baseSlash = !baseSlash;
+ } while (baseSlash);
+ }
}
@Test
@@ -513,11 +472,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
assertTrue("submodule should be checked out", hello.exists());
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "master world", content);
+ }
}
@Test
@@ -603,19 +563,21 @@ public class RepoCommandTest extends RepositoryTestCase {
// The original file should exist
File hello = new File(localDb.getWorkTree(), "foo/hello.txt");
assertTrue("The original file should exist", hello.exists());
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("The original file should have expected content",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("The original file should have expected content",
+ "master world", content);
+ }
// The dest file should also exist
hello = new File(localDb.getWorkTree(), "Hello");
assertTrue("The destination file should exist", hello.exists());
- reader = new BufferedReader(new FileReader(hello));
- content = reader.readLine();
- reader.close();
- assertEquals("The destination file should have expected content",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("The destination file should have expected content",
+ "master world", content);
+ }
}
@Test
@@ -638,24 +600,27 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testBareRepo");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The .gitmodules file should exist
- File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
- assertTrue("The .gitmodules file should exist", gitmodules.exists());
- // The first line of .gitmodules file should be expected
- BufferedReader reader = new BufferedReader(new FileReader(gitmodules));
- String content = reader.readLine();
- reader.close();
- assertEquals("The first line of .gitmodules file should be as expected",
- "[submodule \"foo\"]", content);
- // The gitlink should be the same as remote head sha1
- String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
- localDb.close();
- String remote = defaultDb.resolve(Constants.HEAD).name();
- assertEquals("The gitlink should be the same as remote head", remote,
- gitlink);
+ .getRepository()) {
+ // The .gitmodules file should exist
+ File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
+ assertTrue("The .gitmodules file should exist",
+ gitmodules.exists());
+ // The first line of .gitmodules file should be expected
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(gitmodules))) {
+ String content = reader.readLine();
+ assertEquals(
+ "The first line of .gitmodules file should be as expected",
+ "[submodule \"foo\"]", content);
+ }
+ // The gitlink should be the same as remote head sha1
+ String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
+ String remote = defaultDb.resolve(Constants.HEAD).name();
+ assertEquals("The gitlink should be the same as remote head",
+ remote, gitlink);
+ }
}
@Test
@@ -677,11 +642,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -703,11 +669,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -729,11 +696,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -757,14 +725,14 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testRevisionBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The gitlink should be the same as oldCommitId
- String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
- localDb.close();
- assertEquals("The gitlink is same as remote head", oldCommitId.name(),
- gitlink);
+ .getRepository()) {
+ // The gitlink should be the same as oldCommitId
+ String gitlink = localDb.resolve(Constants.HEAD + ":foo").name();
+ assertEquals("The gitlink is same as remote head",
+ oldCommitId.name(), gitlink);
+ }
}
@Test
@@ -790,22 +758,24 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testCopyFileBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The Hello file should exist
- File hello = new File(localDb.getWorkTree(), "Hello");
- assertTrue("The Hello file should exist", hello.exists());
- // The foo/Hello file should be skipped.
- File foohello = new File(localDb.getWorkTree(), "foo/Hello");
- assertFalse("The foo/Hello file should be skipped", foohello.exists());
- localDb.close();
- // The content of Hello file should be expected
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("The Hello file should have expected content",
- "branch world", content);
+ .getRepository()) {
+ // The Hello file should exist
+ File hello = new File(localDb.getWorkTree(), "Hello");
+ assertTrue("The Hello file should exist", hello.exists());
+ // The foo/Hello file should be skipped.
+ File foohello = new File(localDb.getWorkTree(), "foo/Hello");
+ assertFalse("The foo/Hello file should be skipped",
+ foohello.exists());
+ // The content of Hello file should be expected
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("The Hello file should have expected content",
+ "branch world", content);
+ }
+ }
}
@Test
@@ -841,36 +811,38 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testReplaceManifestBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ File dotmodules;
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
- // The Hello file should not exist
- File hello = new File(localDb.getWorkTree(), "Hello");
- assertFalse("The Hello file shouldn't exist", hello.exists());
- // The Hello.txt file should exist
- File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
- assertTrue("The Hello.txt file should exist", hellotxt.exists());
+ .getRepository()) {
+ // The Hello file should not exist
+ File hello = new File(localDb.getWorkTree(), "Hello");
+ assertFalse("The Hello file shouldn't exist", hello.exists());
+ // The Hello.txt file should exist
+ File hellotxt = new File(localDb.getWorkTree(), "Hello.txt");
+ assertTrue("The Hello.txt file should exist", hellotxt.exists());
+ dotmodules = new File(localDb.getWorkTree(),
+ Constants.DOT_GIT_MODULES);
+ }
// The .gitmodules file should have 'submodule "bar"' and shouldn't
// have
// 'submodule "foo"' lines.
- File dotmodules = new File(localDb.getWorkTree(),
- Constants.DOT_GIT_MODULES);
- localDb.close();
- BufferedReader reader = new BufferedReader(new FileReader(dotmodules));
- boolean foo = false;
- boolean bar = false;
- while (true) {
- String line = reader.readLine();
- if (line == null)
- break;
- if (line.contains("submodule \"foo\""))
- foo = true;
- if (line.contains("submodule \"bar\""))
- bar = true;
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(dotmodules))) {
+ boolean foo = false;
+ boolean bar = false;
+ while (true) {
+ String line = reader.readLine();
+ if (line == null)
+ break;
+ if (line.contains("submodule \"foo\""))
+ foo = true;
+ if (line.contains("submodule \"bar\""))
+ bar = true;
+ }
+ assertTrue("The bar submodule should exist", bar);
+ assertFalse("The foo submodule shouldn't exist", foo);
}
- reader.close();
- assertTrue("The bar submodule should exist", bar);
- assertFalse("The foo submodule shouldn't exist", foo);
}
@Test
@@ -896,34 +868,37 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri).call();
// Clone it
File directory = createTempDirectory("testRemoveOverlappingBare");
- Repository localDb = Git.cloneRepository().setDirectory(directory)
+ File dotmodules;
+ try (Repository localDb = Git.cloneRepository().setDirectory(directory)
.setURI(remoteDb.getDirectory().toURI().toString()).call()
- .getRepository();
+ .getRepository()) {
+ dotmodules = new File(localDb.getWorkTree(),
+ Constants.DOT_GIT_MODULES);
+ }
+
// The .gitmodules file should have 'submodule "foo"' and shouldn't
// have
// 'submodule "foo/bar"' lines.
- File dotmodules = new File(localDb.getWorkTree(),
- Constants.DOT_GIT_MODULES);
- localDb.close();
- BufferedReader reader = new BufferedReader(new FileReader(dotmodules));
- boolean foo = false;
- boolean foobar = false;
- boolean a = false;
- while (true) {
- String line = reader.readLine();
- if (line == null)
- break;
- if (line.contains("submodule \"foo\""))
- foo = true;
- if (line.contains("submodule \"foo/bar\""))
- foobar = true;
- if (line.contains("submodule \"a\""))
- a = true;
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(dotmodules))) {
+ boolean foo = false;
+ boolean foobar = false;
+ boolean a = false;
+ while (true) {
+ String line = reader.readLine();
+ if (line == null)
+ break;
+ if (line.contains("submodule \"foo\""))
+ foo = true;
+ if (line.contains("submodule \"foo/bar\""))
+ foobar = true;
+ if (line.contains("submodule \"a\""))
+ a = true;
+ }
+ assertTrue("The foo submodule should exist", foo);
+ assertFalse("The foo/bar submodule shouldn't exist", foobar);
+ assertTrue("The a submodule should exist", a);
}
- reader.close();
- assertTrue("The foo submodule should exist", foo);
- assertFalse("The foo/bar submodule shouldn't exist", foobar);
- assertTrue("The a submodule should exist", a);
}
@Test
@@ -959,11 +934,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.call();
File hello = new File(localDb.getWorkTree(), "foo/hello.txt");
assertTrue("submodule should be checked out", hello.exists());
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "master world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "master world", content);
+ }
}
@Test
public void testRemoteAlias() throws Exception {
@@ -1165,11 +1141,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
@Test
@@ -1191,11 +1168,12 @@ public class RepoCommandTest extends RepositoryTestCase {
.setURI(rootUri)
.call();
File hello = new File(db.getWorkTree(), "foo/hello.txt");
- BufferedReader reader = new BufferedReader(new FileReader(hello));
- String content = reader.readLine();
- reader.close();
- assertEquals("submodule content should be as expected",
- "branch world", content);
+ try (BufferedReader reader = new BufferedReader(
+ new FileReader(hello))) {
+ String content = reader.readLine();
+ assertEquals("submodule content should be as expected",
+ "branch world", content);
+ }
}
private void resolveRelativeUris() {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
index ccc64fb468..80595feff5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.ignore;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -56,7 +56,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
-import org.eclipse.jgit.ignore.IgnoreNode.MatchResult;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.treewalk.FileTreeIterator;
@@ -546,19 +545,6 @@ public class IgnoreNodeTest extends RepositoryTestCase {
endWalk();
}
- @SuppressWarnings("deprecation")
- @Test
- public void testEmptyIgnoreNode() {
- // Rules are never empty: WorkingTreeIterator optimizes empty files away
- // So we have to test it manually in case third party clients use
- // IgnoreNode directly.
- IgnoreNode node = new IgnoreNode();
- assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false));
- assertEquals(MatchResult.CHECK_PARENT, node.isIgnored("", false, false));
- assertEquals(MatchResult.CHECK_PARENT_NEGATE_FIRST_MATCH,
- node.isIgnored("", false, true));
- }
-
@Test
public void testEmptyIgnoreRules() throws IOException {
IgnoreNode node = new IgnoreNode();
@@ -779,6 +765,6 @@ public class IgnoreNodeTest extends RepositoryTestCase {
for (String line : rules) {
data.append(line + "\n");
}
- return new ByteArrayInputStream(data.toString().getBytes(UTF_8));
+ return new ByteArrayInputStream(data.toString().getBytes(CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
index d5d3857ca4..26c11c7eb7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java
@@ -41,7 +41,7 @@
*/
package org.eclipse.jgit.indexdiff;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -128,7 +128,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
File restoreScript = new File(testDir, name + ".sh");
try (OutputStream out = new BufferedOutputStream(
new FileOutputStream(restoreScript));
- Writer writer = new OutputStreamWriter(out, UTF_8)) {
+ Writer writer = new OutputStreamWriter(out, CHARSET)) {
writer.write("echo `which git` 1>&2\n");
writer.write("echo `git --version` 1>&2\n");
writer.write("git init " + name + " && \\\n");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
index 91bd523975..128c1edde1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileTest.java
@@ -146,15 +146,15 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -180,15 +180,15 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
.getMessage());
}
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -239,15 +239,15 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertNotNull(ol.getCachedBytes());
assertArrayEquals(data3, ol.getCachedBytes());
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(Constants.OBJ_BLOB, in.getType());
- assertEquals(data3.length, in.getSize());
- byte[] act = new byte[data3.length];
- IO.readFully(in, act, 0, data3.length);
- assertTrue("same content", Arrays.equals(act, data3));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(Constants.OBJ_BLOB, in.getType());
+ assertEquals(data3.length, in.getSize());
+ byte[] act = new byte[data3.length];
+ IO.readFully(in, act, 0, data3.length);
+ assertTrue("same content", Arrays.equals(act, data3));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
}
@@ -282,22 +282,16 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
File packName = new File(dir, idA.name() + ".pack");
File idxName = new File(dir, idA.name() + ".idx");
- FileOutputStream f = new FileOutputStream(packName);
- try {
+ try (FileOutputStream f = new FileOutputStream(packName)) {
f.write(pack.toByteArray());
- } finally {
- f.close();
}
- f = new FileOutputStream(idxName);
- try {
+ try (FileOutputStream f = new FileOutputStream(idxName)) {
List<PackedObjectInfo> list = new ArrayList<>();
list.add(a);
list.add(b);
Collections.sort(list);
new PackIndexWriterV1(f).write(list, footer);
- } finally {
- f.close();
}
PackFile packFile = new PackFile(packName, PackExt.INDEX.getBit());
@@ -321,16 +315,17 @@ public class PackFileTest extends LocalDiskRepositoryTestCase {
assertTrue("has blob", wc.has(id));
ObjectLoader ol = wc.open(id);
- ObjectStream in = ol.openStream();
- assertTrue(in instanceof ObjectStream.SmallStream);
- assertEquals(300, in.available());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertTrue(in instanceof ObjectStream.SmallStream);
+ assertEquals(300, in.available());
+ }
wc.setStreamFileThreshold(299);
ol = wc.open(id);
- in = ol.openStream();
- assertTrue(in instanceof ObjectStream.Filter);
- assertEquals(1, in.available());
+ try (ObjectStream in = ol.openStream()) {
+ assertTrue(in instanceof ObjectStream.Filter);
+ assertEquals(1, in.available());
+ }
}
private static byte[] clone(int first, byte[] base) {
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
index 379432ddbb..3711f83656 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
@@ -515,11 +515,8 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
// Validate that an index written by PackWriter is the same.
final File idx2File = new File(indexFile.getAbsolutePath() + ".2");
- final FileOutputStream is = new FileOutputStream(idx2File);
- try {
+ try (FileOutputStream is = new FileOutputStream(idx2File)) {
writer.writeIndex(is);
- } finally {
- is.close();
}
final PackIndex idx2 = PackIndex.open(idx2File);
assertTrue(idx2 instanceof PackIndexV2);
@@ -715,14 +712,14 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
String id = pw.computeName().getName();
File packdir = repo.getObjectDatabase().getPackDirectory();
File packFile = new File(packdir, "pack-" + id + ".pack");
- FileOutputStream packOS = new FileOutputStream(packFile);
- pw.writePack(NullProgressMonitor.INSTANCE,
- NullProgressMonitor.INSTANCE, packOS);
- packOS.close();
+ try (FileOutputStream packOS = new FileOutputStream(packFile)) {
+ pw.writePack(NullProgressMonitor.INSTANCE,
+ NullProgressMonitor.INSTANCE, packOS);
+ }
File idxFile = new File(packdir, "pack-" + id + ".idx");
- FileOutputStream idxOS = new FileOutputStream(idxFile);
- pw.writeIndex(idxOS);
- idxOS.close();
+ try (FileOutputStream idxOS = new FileOutputStream(idxFile)) {
+ pw.writeIndex(idxOS);
+ }
return PackIndex.open(idxFile);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
index 52861ecd53..592d0c8671 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
@@ -45,7 +45,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 static org.eclipse.jgit.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -252,7 +252,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
ObjectId blobId;
try (ObjectInserter ins = bareRepo.newObjectInserter()) {
- blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(UTF_8));
+ blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(CHARSET));
ins.flush();
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
index d7505af4cf..91255007ef 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
@@ -47,7 +47,7 @@
package org.eclipse.jgit.internal.storage.file;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -137,10 +137,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test000_openrepo_default_gitDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -162,10 +162,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
public void test000_openrepo_default_gitDirAndWorkTreeSet()
throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -187,10 +187,10 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test000_openrepo_default_workDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1");
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -213,13 +213,13 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw");
FileUtils.mkdir(workdir);
- FileRepository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- final FileBasedConfig cfg = repo1initial.getConfig();
- cfg.setString("core", null, "worktree", workdir.getAbsolutePath());
- cfg.save();
- repo1initial.close();
+ try (FileRepository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ final FileBasedConfig cfg = repo1initial.getConfig();
+ cfg.setString("core", null, "worktree", workdir.getAbsolutePath());
+ cfg.save();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -242,13 +242,13 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw");
FileUtils.mkdir(workdir);
- FileRepository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- final FileBasedConfig cfg = repo1initial.getConfig();
- cfg.setString("core", null, "worktree", "../../rw");
- cfg.save();
- repo1initial.close();
+ try (FileRepository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ final FileBasedConfig cfg = repo1initial.getConfig();
+ cfg.setString("core", null, "worktree", "../../rw");
+ cfg.save();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = (FileRepository) new FileRepositoryBuilder()
@@ -273,26 +273,24 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
File indexFile = new File(trash, "idx");
File objDir = new File(trash, "../obj");
File altObjDir = db.getObjectDatabase().getDirectory();
- Repository repo1initial = new FileRepository(new File(repo1Parent,
- Constants.DOT_GIT));
- repo1initial.create();
- repo1initial.close();
+ try (Repository repo1initial = new FileRepository(
+ new File(repo1Parent, Constants.DOT_GIT))) {
+ repo1initial.create();
+ }
File theDir = new File(repo1Parent, Constants.DOT_GIT);
- FileRepository r = (FileRepository) new FileRepositoryBuilder() //
+ try (FileRepository r = (FileRepository) new FileRepositoryBuilder() //
.setGitDir(theDir).setObjectDirectory(objDir) //
.addAlternateObjectDirectory(altObjDir) //
.setIndexFile(indexFile) //
- .build();
- assertEqualsPath(theDir, r.getDirectory());
- assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
- assertEqualsPath(indexFile, r.getIndexFile());
- assertEqualsPath(objDir, r.getObjectDatabase().getDirectory());
- assertNotNull(r.open(ObjectId
- .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4")));
- // Must close or the default repo pack files created by this test gets
- // locked via the alternate object directories on Windows.
- r.close();
+ .build()) {
+ assertEqualsPath(theDir, r.getDirectory());
+ assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
+ assertEqualsPath(indexFile, r.getIndexFile());
+ assertEqualsPath(objDir, r.getObjectDatabase().getDirectory());
+ assertNotNull(r.open(ObjectId
+ .fromString("6db9c2ebf75590eef973081736730a9ea169a0c4")));
+ }
}
protected void assertEqualsPath(File expected, File actual)
@@ -417,14 +415,11 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
// Verify the commit we just wrote is in the correct format.
ObjectDatabase odb = db.getObjectDatabase();
assertTrue("is ObjectDirectory", odb instanceof ObjectDirectory);
- final XInputStream xis = new XInputStream(new FileInputStream(
- ((ObjectDirectory) odb).fileFor(cmtid)));
- try {
+ try (XInputStream xis = new XInputStream(
+ new FileInputStream(((ObjectDirectory) odb).fileFor(cmtid)))) {
assertEquals(0x78, xis.readUInt8());
assertEquals(0x9c, xis.readUInt8());
assertEquals(0, 0x789c % 31);
- } finally {
- xis.close();
}
// Verify we can read it.
@@ -522,7 +517,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
4294967295000L, 60));
commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
4294967295000L, 60));
- commit.setEncoding(UTF_8);
+ commit.setEncoding(CHARSET);
commit.setMessage("\u00dcbergeeks");
ObjectId cid = insertCommit(commit);
assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
index c5ab766838..98ff04e15e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/UnpackedObjectTest.java
@@ -130,15 +130,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -150,11 +150,8 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
ObjectLoader ol;
{
- FileInputStream fs = new FileInputStream(path(id));
- try {
+ try (FileInputStream fs = new FileInputStream(path(id))) {
ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
}
}
@@ -171,15 +168,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
.getMessage());
}
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -316,23 +313,13 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, gz);
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
- try {
- byte[] tmp = new byte[data.length];
- InputStream in = ol.openStream();
- try {
- IO.readFully(in, tmp, 0, tmp.length);
- } finally {
- in.close();
- }
+ byte[] tmp = new byte[data.length];
+ try (InputStream in = ol.openStream()) {
+ IO.readFully(in, tmp, 0, tmp.length);
fail("Did not throw CorruptObjectException");
} catch (CorruptObjectException coe) {
assertEquals(MessageFormat.format(JGitText.get().objectIsCorrupt,
@@ -354,16 +341,12 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, tr);
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
byte[] tmp = new byte[data.length];
+ @SuppressWarnings("resource") // We are testing that the close() method throws
InputStream in = ol.openStream();
IO.readFully(in, tmp, 0, tmp.length);
try {
@@ -389,16 +372,12 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, tr);
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
byte[] tmp = new byte[data.length];
+ @SuppressWarnings("resource") // We are testing that the close() method throws
InputStream in = ol.openStream();
IO.readFully(in, tmp, 0, tmp.length);
try {
@@ -426,14 +405,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
assertFalse("is not large", ol.isLarge());
assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data, ol.getCachedBytes()));
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content",
+ Arrays.equals(data, ol.getCachedBytes()));
+ }
}
@Test
@@ -444,13 +424,8 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
write(id, compressPackFormat(type, data));
ObjectLoader ol;
- {
- FileInputStream fs = new FileInputStream(path(id));
- try {
- ol = UnpackedObject.open(fs, path(id), id, wc);
- } finally {
- fs.close();
- }
+ try (FileInputStream fs = new FileInputStream(path(id))) {
+ ol = UnpackedObject.open(fs, path(id), id, wc);
}
assertNotNull("created loader", ol);
@@ -466,15 +441,15 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
.getMessage());
}
- ObjectStream in = ol.openStream();
- assertNotNull("have stream", in);
- assertEquals(type, in.getType());
- assertEquals(data.length, in.getSize());
- byte[] data2 = new byte[data.length];
- IO.readFully(in, data2, 0, data.length);
- assertTrue("same content", Arrays.equals(data2, data));
- assertEquals("stream at EOF", -1, in.read());
- in.close();
+ try (ObjectStream in = ol.openStream()) {
+ assertNotNull("have stream", in);
+ assertEquals(type, in.getType());
+ assertEquals(data.length, in.getSize());
+ byte[] data2 = new byte[data.length];
+ IO.readFully(in, data2, 0, data.length);
+ assertTrue("same content", Arrays.equals(data2, data));
+ assertEquals("stream at EOF", -1, in.read());
+ }
}
@Test
@@ -573,11 +548,8 @@ public class UnpackedObjectTest extends LocalDiskRepositoryTestCase {
private void write(ObjectId id, byte[] data) throws IOException {
File path = path(id);
FileUtils.mkdirs(path.getParentFile());
- FileOutputStream out = new FileOutputStream(path);
- try {
+ try (FileOutputStream out = new FileOutputStream(path)) {
out.write(data);
- } finally {
- out.close();
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
index cc348388cf..9ac794ed8e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/WindowCacheGetTest.java
@@ -74,11 +74,10 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
super.setUp();
toLoad = new ArrayList<>();
- final BufferedReader br = new BufferedReader(new InputStreamReader(
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(JGitTestUtil
.getTestResourceFile("all_packed_objects.txt")),
- Constants.CHARSET));
- try {
+ Constants.CHARSET))) {
String line;
while ((line = br.readLine()) != null) {
final String[] parts = line.split(" {1,}");
@@ -90,8 +89,6 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase {
// parts[4] is the offset in the pack
toLoad.add(o);
}
- } finally {
- br.close();
}
assertEquals(96, toLoad.size());
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
index b7027f3272..965899e7a0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/junit/TestRepositoryTest.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.junit;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -418,6 +418,6 @@ public class TestRepositoryTest {
RevObject obj = tr.get(rw.parseTree(treeish), path);
assertSame(RevBlob.class, obj.getClass());
ObjectLoader loader = rw.getObjectReader().open(obj);
- return new String(loader.getCachedBytes(), UTF_8);
+ return new String(loader.getCachedBytes(), CHARSET);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
index f1c62d4be2..22c66cec16 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
@@ -45,7 +45,7 @@
package org.eclipse.jgit.lib;
import static java.lang.Integer.valueOf;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.junit.JGitTestUtil.concat;
import static org.eclipse.jgit.lib.Constants.OBJECT_ID_LENGTH;
import static org.eclipse.jgit.lib.Constants.OBJ_BAD;
@@ -1454,7 +1454,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes(UTF_8);
+ byte[] data = b.toString().getBytes(CHARSET);
checker.setSafeForWindows(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1468,7 +1468,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
entry(b, "100644 a");
- byte[] data = b.toString().getBytes(UTF_8);
+ byte[] data = b.toString().getBytes(CHARSET);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1482,7 +1482,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 \u0065\u0301");
entry(b, "100644 \u00e9");
- byte[] data = b.toString().getBytes(UTF_8);
+ byte[] data = b.toString().getBytes(CHARSET);
checker.setSafeForMacOS(true);
assertCorrupt("duplicate entry names", OBJ_TREE, data);
assertSkipListAccepts(OBJ_TREE, data);
@@ -1496,7 +1496,7 @@ public class ObjectCheckerTest {
StringBuilder b = new StringBuilder();
entry(b, "100644 A");
checker.setSafeForMacOS(true);
- checker.checkTree(b.toString().getBytes(UTF_8));
+ checker.checkTree(b.toString().getBytes(CHARSET));
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
index 9236b4e821..8d9ccab1bd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
@@ -176,12 +176,9 @@ public class RacyGitTests extends RepositoryTestCase {
private File addToWorkDir(String path, String content) throws IOException {
File f = new File(db.getWorkTree(), path);
- FileOutputStream fos = new FileOutputStream(f);
- try {
+ try (FileOutputStream fos = new FileOutputStream(f)) {
fos.write(content.getBytes(Constants.CHARACTER_ENCODING));
return f;
- } finally {
- fos.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
index 7fb3309982..e93867829a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RefTest.java
@@ -253,11 +253,11 @@ public class RefTest extends SampleDataRepositoryTestCase {
InterruptedException {
Ref ref = db.exactRef("refs/heads/master");
assertEquals(Storage.PACKED, ref.getStorage());
- FileOutputStream os = new FileOutputStream(new File(db.getDirectory(),
- "refs/heads/master"));
- os.write(ref.getObjectId().name().getBytes());
- os.write('\n');
- os.close();
+ try (FileOutputStream os = new FileOutputStream(
+ new File(db.getDirectory(), "refs/heads/master"))) {
+ os.write(ref.getObjectId().name().getBytes());
+ os.write('\n');
+ }
ref = db.exactRef("refs/heads/master");
assertEquals(Storage.LOOSE, ref.getStorage());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
index 1107c2c69b..58b005c282 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java
@@ -94,24 +94,25 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testFileKeyOpenExisting() throws IOException {
- Repository r;
-
- r = new FileKey(db.getDirectory(), db.getFS()).open(true);
- assertNotNull(r);
- assertEqualsFile(db.getDirectory(), r.getDirectory());
- r.close();
+ try (Repository r = new FileKey(db.getDirectory(), db.getFS())
+ .open(true)) {
+ assertNotNull(r);
+ assertEqualsFile(db.getDirectory(), r.getDirectory());
+ }
- r = new FileKey(db.getDirectory(), db.getFS()).open(false);
- assertNotNull(r);
- assertEqualsFile(db.getDirectory(), r.getDirectory());
- r.close();
+ try (Repository r = new FileKey(db.getDirectory(), db.getFS())
+ .open(false)) {
+ assertNotNull(r);
+ assertEqualsFile(db.getDirectory(), r.getDirectory());
+ }
}
@Test
public void testFileKeyOpenNew() throws IOException {
- final Repository n = createRepository(true, false);
- final File gitdir = n.getDirectory();
- n.close();
+ File gitdir;
+ try (Repository n = createRepository(true, false)) {
+ gitdir = n.getDirectory();
+ }
recursiveDelete(gitdir);
assertFalse(gitdir.exists());
@@ -143,6 +144,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testCacheOpen() throws Exception {
final FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ @SuppressWarnings("resource") // We are testing the close() method
final Repository d2 = RepositoryCache.open(loc);
assertNotSame(db, d2);
assertSame(d2, RepositoryCache.open(FileKey.exact(loc.getFile(), db.getFS())));
@@ -176,6 +178,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUsageCount() throws Exception {
FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ @SuppressWarnings("resource") // We are testing the close() method
Repository d2 = RepositoryCache.open(loc);
assertEquals(1, d2.useCnt.get());
RepositoryCache.open(FileKey.exact(loc.getFile(), db.getFS()));
@@ -189,6 +192,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUsageCountWithRegisteredRepository()
throws IOException {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repo = createRepository(false, false);
assertEquals(1, repo.useCnt.get());
RepositoryCache.register(repo);
@@ -200,6 +204,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryNotUnregisteringWhenClosing() throws Exception {
FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ @SuppressWarnings("resource") // We are testing the close() method
Repository d2 = RepositoryCache.open(loc);
assertEquals(1, d2.useCnt.get());
assertThat(RepositoryCache.getRegisteredKeys(),
@@ -214,6 +219,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUnregisteringWhenExpiredAndUsageCountNegative()
throws Exception {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repoA = createBareRepository();
RepositoryCache.register(repoA);
@@ -234,7 +240,9 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testRepositoryUnregisteringWhenExpired() throws Exception {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repoA = createRepository(true, false);
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repoB = createRepository(true, false);
Repository repoC = createBareRepository();
RepositoryCache.register(repoA);
@@ -268,6 +276,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
@Test
public void testReconfigure() throws InterruptedException, IOException {
+ @SuppressWarnings("resource") // We are testing the close() method
Repository repo = createRepository(false, false);
RepositoryCache.register(repo);
assertTrue(RepositoryCache.isCached(repo));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
index 3bcd787f81..203c00e28a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/SquashCommitMsgTest.java
@@ -66,12 +66,9 @@ public class SquashCommitMsgTest extends RepositoryTestCase {
db.writeSquashCommitMsg(null);
assertEquals(db.readSquashCommitMsg(), null);
assertFalse(new File(db.getDirectory(), Constants.SQUASH_MSG).exists());
- FileOutputStream fos = new FileOutputStream(new File(db.getDirectory(),
- Constants.SQUASH_MSG));
- try {
+ try (FileOutputStream fos = new FileOutputStream(
+ new File(db.getDirectory(), Constants.SQUASH_MSG))) {
fos.write(squashMsg.getBytes(Constants.CHARACTER_ENCODING));
- } finally {
- fos.close();
}
assertEquals(db.readSquashCommitMsg(), squashMsg);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
index 190224a855..ee99aa1379 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java
@@ -83,7 +83,7 @@ import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
-public class RecursiveMergerTest extends RepositoryTestCase {
+public class CrissCrossMergeTest extends RepositoryTestCase {
static int counter = 0;
@DataPoints
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
index 9322a4734e..58093a3729 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.merge;
-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.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -91,19 +91,17 @@ import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Assert;
-import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
@RunWith(Theories.class)
-public class ResolveMergerTest extends RepositoryTestCase {
+public class MergerTest extends RepositoryTestCase {
- @DataPoint
- public static MergeStrategy resolve = MergeStrategy.RESOLVE;
-
- @DataPoint
- public static MergeStrategy recursive = MergeStrategy.RECURSIVE;
+ @DataPoints
+ public static MergeStrategy[] strategiesUnderTest = new MergeStrategy[] {
+ MergeStrategy.RECURSIVE, MergeStrategy.RESOLVE };
@Theory
public void failingDeleteOfDirectoryWithUntrackedContent(
@@ -756,7 +754,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
}
binary[50] = '\0';
- writeTrashFile("file", new String(binary, UTF_8));
+ writeTrashFile("file", new String(binary, CHARSET));
git.add().addFilepattern("file").call();
RevCommit first = git.commit().setMessage("added file").call();
@@ -764,7 +762,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
int idx = LINELEN * 1200 + 1;
byte save = binary[idx];
binary[idx] = '@';
- writeTrashFile("file", new String(binary, UTF_8));
+ writeTrashFile("file", new String(binary, CHARSET));
binary[idx] = save;
git.add().addFilepattern("file").call();
@@ -773,7 +771,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call();
binary[LINELEN * 1500 + 1] = '!';
- writeTrashFile("file", new String(binary, UTF_8));
+ writeTrashFile("file", new String(binary, CHARSET));
git.add().addFilepattern("file").call();
RevCommit sideCommit = git.commit().setAll(true)
.setMessage("modified file l 1500").call();
@@ -935,7 +933,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
merger.getMergeResults().get("file");
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
fmt.formatMerge(out, merger.getMergeResults().get("file"),
- "BASE", "OURS", "THEIRS", UTF_8.name());
+ "BASE", "OURS", "THEIRS", CHARSET.name());
String expected = "<<<<<<< OURS\n"
+ "1master\n"
+ "=======\n"
@@ -943,7 +941,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
+ ">>>>>>> THEIRS\n"
+ "2\n"
+ "3";
- assertEquals(expected, new String(out.toByteArray(), UTF_8));
+ assertEquals(expected, new String(out.toByteArray(), CHARSET));
}
}
}
@@ -1033,19 +1031,21 @@ public class ResolveMergerTest extends RepositoryTestCase {
git.commit().setMessage("added c.txt").call();
// Get a handle to the the file so on windows it can't be deleted.
- FileInputStream fis = new FileInputStream(new File(db.getWorkTree(),
- "b.txt"));
- MergeResult mergeRes = git.merge().setStrategy(strategy)
- .include(masterCommit).call();
- if (mergeRes.getMergeStatus().equals(MergeStatus.FAILED)) {
- // probably windows
- assertEquals(1, mergeRes.getFailingPaths().size());
- assertEquals(MergeFailureReason.COULD_NOT_DELETE, mergeRes
- .getFailingPaths().get("b.txt"));
+ try (FileInputStream fis = new FileInputStream(
+ new File(db.getWorkTree(), "b.txt"))) {
+ MergeResult mergeRes = git.merge().setStrategy(strategy)
+ .include(masterCommit).call();
+ if (mergeRes.getMergeStatus().equals(MergeStatus.FAILED)) {
+ // probably windows
+ assertEquals(1, mergeRes.getFailingPaths().size());
+ assertEquals(MergeFailureReason.COULD_NOT_DELETE,
+ mergeRes.getFailingPaths().get("b.txt"));
+ }
+ assertEquals(
+ "[a.txt, mode:100644, content:master]"
+ + "[c.txt, mode:100644, content:side]",
+ indexState(CONTENT));
}
- assertEquals("[a.txt, mode:100644, content:master]"
- + "[c.txt, mode:100644, content:side]", indexState(CONTENT));
- fis.close();
}
@Theory
@@ -1328,6 +1328,6 @@ public class ResolveMergerTest extends RepositoryTestCase {
if (obj == null) {
return null;
}
- return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), UTF_8);
+ return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), CHARSET);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
index 65375c7ae0..8da199f7c6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/GetTextTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.patch;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -83,7 +83,7 @@ public class GetTextTest {
@Test
public void testGetText_Convert() throws IOException {
final Charset csOld = ISO_8859_1;
- final Charset csNew = UTF_8;
+ final Charset csNew = CHARSET;
final Patch p = parseTestPatchFile();
assertTrue(p.getErrors().isEmpty());
assertEquals(1, p.getFiles().size());
@@ -103,7 +103,7 @@ public class GetTextTest {
@Test
public void testGetText_DiffCc() throws IOException {
final Charset csOld = ISO_8859_1;
- final Charset csNew = UTF_8;
+ final Charset csNew = CHARSET;
final Patch p = parseTestPatchFile();
assertTrue(p.getErrors().isEmpty());
assertEquals(1, p.getFiles().size());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java
index e4b43172d6..6989343362 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcErrorTest.java
@@ -96,17 +96,14 @@ public class PatchCcErrorTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java
index 837414b054..4a26d50e49 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchCcTest.java
@@ -199,17 +199,14 @@ public class PatchCcTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java
index 52e3874b6c..3bdf852167 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchErrorTest.java
@@ -177,17 +177,14 @@ public class PatchErrorTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java
index 9f57ab98c0..6a09a4919e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchTest.java
@@ -357,17 +357,14 @@ public class PatchTest {
private Patch parseTestPatchFile() throws IOException {
final String patchFile = JGitTestUtil.getName() + ".patch";
- final InputStream in = getClass().getResourceAsStream(patchFile);
- if (in == null) {
- fail("No " + patchFile + " test vector");
- return null; // Never happens
- }
- try {
+ try (InputStream in = getClass().getResourceAsStream(patchFile)) {
+ if (in == null) {
+ fail("No " + patchFile + " test vector");
+ return null; // Never happens
+ }
final Patch p = new Patch();
p.parse(in);
return p;
- } finally {
- in.close();
}
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
index 88f240bb1f..9fc96212c7 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.revwalk;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -114,7 +114,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
assertNull(c.getTree());
assertNull(c.parents);
- c.parseCanonical(rw, body.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, body.toString().getBytes(CHARSET));
assertNotNull(c.getTree());
assertEquals(treeId, c.getTree().getId());
assertSame(rw.lookupTree(treeId), c.getTree());
@@ -148,7 +148,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
return c;
}
@@ -161,7 +161,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
assertEquals("", c.getFullMessage());
assertEquals("", c.getShortMessage());
@@ -176,7 +176,7 @@ public class RevCommitParseTest extends RepositoryTestCase {
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent());
assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent());
@@ -185,13 +185,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -205,13 +205,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -260,14 +260,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(ISO_8859_1));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding EUC-JP\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding EUC-JP\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -291,14 +291,14 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer C O. Miter <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding ISO-8859-1\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevCommit c;
c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -313,13 +313,13 @@ public class RevCommitParseTest extends RepositoryTestCase {
public void testParse_incorrectUtf8Name() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
b.write("committer co <c@example.com> 1218123390 -0500\n"
- .getBytes(UTF_8));
- b.write("encoding 'utf8'\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("encoding 'utf8'\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -338,12 +338,12 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
@@ -365,12 +365,12 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(UTF_8));
- b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("author au <a@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("committer co <c@example.com> 1218123390 -0500\n".getBytes(CHARSET));
+ b.write("encoding it_IT.UTF8\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevCommit c = new RevCommit(
id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
index 38bd371b90..8e9507961b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.revwalk;
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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -98,7 +98,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, b.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, b.toString().getBytes(CHARSET));
assertNotNull(c.getObject());
assertEquals(id, c.getObject().getId());
assertSame(rw.lookupAny(id, typeCode), c.getObject());
@@ -141,7 +141,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, body.toString().getBytes(CHARSET));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -189,7 +189,7 @@ public class RevTagParseTest extends RepositoryTestCase {
assertNull(c.getObject());
assertNull(c.getTagName());
- c.parseCanonical(rw, body.toString().getBytes(UTF_8));
+ c.parseCanonical(rw, body.toString().getBytes(CHARSET));
assertNotNull(c.getObject());
assertEquals(treeId, c.getObject().getId());
assertSame(rw.lookupTree(treeId), c.getObject());
@@ -213,7 +213,7 @@ public class RevTagParseTest extends RepositoryTestCase {
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
- c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8));
+ c.parseCanonical(new RevWalk(db), b.toString().getBytes(CHARSET));
return c;
}
@@ -221,17 +221,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_implicit_UTF8_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -246,15 +246,15 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_implicit_mixed_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
- b.write("\n".getBytes(UTF_8));
- b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -307,17 +307,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_explicit_bad_encoded() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
.getBytes(ISO_8859_1));
- b.write("encoding EUC-JP\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ b.write("encoding EUC-JP\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -342,17 +342,17 @@ public class RevTagParseTest extends RepositoryTestCase {
public void testParse_explicit_bad_encoded2() throws Exception {
final ByteArrayOutputStream b = new ByteArrayOutputStream();
b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
- .getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.2.3.4.5\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.2.3.4.5\n".getBytes(CHARSET));
b
.write("tagger F\u00f6r fattare <a_u_thor@example.com> 1218123387 +0700\n"
- .getBytes(UTF_8));
- b.write("encoding ISO-8859-1\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("\u304d\u308c\u3044\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("Hi\n".getBytes(UTF_8));
+ .getBytes(CHARSET));
+ b.write("encoding ISO-8859-1\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("\u304d\u308c\u3044\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("Hi\n".getBytes(CHARSET));
final RevTag c;
c = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
c.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -365,13 +365,13 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_illegalEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.0\n".getBytes(UTF_8));
- b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.0\n".getBytes(CHARSET));
+ b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("encoding utf-8logoutputencoding=gbk\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
t.parseCanonical(new RevWalk(db), b.toByteArray());
@@ -384,13 +384,13 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_unsupportedEncoding() throws Exception {
ByteArrayOutputStream b = new ByteArrayOutputStream();
- b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8));
- b.write("type tree\n".getBytes(UTF_8));
- b.write("tag v1.0\n".getBytes(UTF_8));
- b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(UTF_8));
- b.write("encoding it_IT.UTF8\n".getBytes(UTF_8));
- b.write("\n".getBytes(UTF_8));
- b.write("message\n".getBytes(UTF_8));
+ b.write("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(CHARSET));
+ b.write("type tree\n".getBytes(CHARSET));
+ b.write("tag v1.0\n".getBytes(CHARSET));
+ b.write("tagger t <t@example.com> 1218123387 +0700\n".getBytes(CHARSET));
+ b.write("encoding it_IT.UTF8\n".getBytes(CHARSET));
+ b.write("\n".getBytes(CHARSET));
+ b.write("message\n".getBytes(CHARSET));
RevTag t = new RevTag(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
t.parseCanonical(new RevWalk(db), b.toByteArray());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
index 7f0d60295c..0dea5ce97b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.storage.file;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.util.FileUtils.pathToString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -105,7 +105,7 @@ public class FileBasedConfigTest {
@Test
public void testUTF8withoutBOM() throws IOException, ConfigInvalidException {
- final File file = createFile(CONTENT1.getBytes(UTF_8));
+ final File file = createFile(CONTENT1.getBytes(CHARSET));
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
config.load();
assertEquals(ALICE, config.getString(USER, null, NAME));
@@ -121,7 +121,7 @@ public class FileBasedConfigTest {
bos1.write(0xEF);
bos1.write(0xBB);
bos1.write(0xBF);
- bos1.write(CONTENT1.getBytes(UTF_8));
+ bos1.write(CONTENT1.getBytes(CHARSET));
final File file = createFile(bos1.toByteArray());
final FileBasedConfig config = new FileBasedConfig(file, FS.DETECTED);
@@ -135,7 +135,7 @@ public class FileBasedConfigTest {
bos2.write(0xEF);
bos2.write(0xBB);
bos2.write(0xBF);
- bos2.write(CONTENT2.getBytes(UTF_8));
+ bos2.write(CONTENT2.getBytes(CHARSET));
assertArrayEquals(bos2.toByteArray(), IO.readFully(file));
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
index f42dd02814..1a67e41976 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
@@ -129,10 +129,11 @@ public class SubmoduleAddTest extends RepositoryTestCase {
command.setPath(path);
String uri = db.getDirectory().toURI().toString();
command.setURI(uri);
- Repository repo = command.call();
- assertNotNull(repo);
- ObjectId subCommit = repo.resolve(Constants.HEAD);
- repo.close();
+ ObjectId subCommit;
+ try (Repository repo = command.call()) {
+ assertNotNull(repo);
+ subCommit = repo.resolve(Constants.HEAD);
+ }
SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
@@ -141,10 +142,10 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath());
assertEquals(uri, generator.getConfigUrl());
- Repository subModRepo = generator.getRepository();
- assertNotNull(subModRepo);
- assertEquals(subCommit, commit);
- subModRepo.close();
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(subCommit, commit);
+ }
Status status = Git.wrap(db).status().call();
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
@@ -209,16 +210,14 @@ public class SubmoduleAddTest extends RepositoryTestCase {
fullUri = fullUri.replace('\\', '/');
}
assertEquals(fullUri, generator.getConfigUrl());
- Repository subModRepo = generator.getRepository();
- assertNotNull(subModRepo);
- assertEquals(
- fullUri,
- subModRepo
- .getConfig()
- .getString(ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME,
- ConfigConstants.CONFIG_KEY_URL));
- subModRepo.close();
+ try (Repository subModRepo = generator.getRepository()) {
+ assertNotNull(subModRepo);
+ assertEquals(fullUri,
+ subModRepo.getConfig().getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
assertEquals(commit, repo.resolve(Constants.HEAD));
Status status = Git.wrap(db).status().call();
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
index 13db44a9c5..6f3b52f7bb 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleSyncTest.java
@@ -135,12 +135,14 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
assertEquals(url, generator.getConfigUrl());
- Repository subModRepository = generator.getRepository();
- StoredConfig submoduleConfig = subModRepository.getConfig();
- subModRepository.close();
- assertEquals(url, submoduleConfig.getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
+ try (Repository subModRepository = generator.getRepository()) {
+ StoredConfig submoduleConfig = subModRepository.getConfig();
+ assertEquals(url,
+ submoduleConfig.getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
@Test
@@ -208,11 +210,13 @@ public class SubmoduleSyncTest extends RepositoryTestCase {
generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
assertEquals("git://server/sub.git", generator.getConfigUrl());
- Repository subModRepository1 = generator.getRepository();
- StoredConfig submoduleConfig = subModRepository1.getConfig();
- subModRepository1.close();
- assertEquals("git://server/sub.git", submoduleConfig.getString(
- ConfigConstants.CONFIG_REMOTE_SECTION,
- Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
+ try (Repository subModRepository1 = generator.getRepository()) {
+ StoredConfig submoduleConfig = subModRepository1.getConfig();
+ assertEquals("git://server/sub.git",
+ submoduleConfig.getString(
+ ConfigConstants.CONFIG_REMOTE_SECTION,
+ Constants.DEFAULT_REMOTE_NAME,
+ ConfigConstants.CONFIG_KEY_URL));
+ }
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
index 7064f6097b..bbce413ef3 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleUpdateTest.java
@@ -121,10 +121,10 @@ public class SubmoduleUpdateTest extends RepositoryTestCase {
SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
assertTrue(generator.next());
- Repository subRepo = generator.getRepository();
- assertNotNull(subRepo);
- assertEquals(commit, subRepo.resolve(Constants.HEAD));
- subRepo.close();
+ try (Repository subRepo = generator.getRepository()) {
+ assertNotNull(subRepo);
+ assertEquals(commit, subRepo.resolve(Constants.HEAD));
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
index 658b971acb..d30ac840a6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
@@ -45,7 +45,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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -199,7 +199,7 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase {
Ref ref = repo.exactRef(refName);
assertNotNull(ref);
assertEquals(id, ref.getObjectId());
- assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8));
+ assertEquals(data, new String(repo.open(id, OBJ_BLOB).getBytes(), CHARSET));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
index 2fea8a92ac..76404aba91 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/NetRCTest.java
@@ -42,6 +42,7 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -74,10 +75,10 @@ public class NetRCTest extends RepositoryTestCase {
}
private void config(final String data) throws IOException {
- final OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(configFile), "UTF-8");
- fw.write(data);
- fw.close();
+ try (OutputStreamWriter fw = new OutputStreamWriter(
+ new FileOutputStream(configFile), CHARSET)) {
+ fw.write(data);
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
index d604751fef..886f577d98 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/OpenSshConfigTest.java
@@ -43,6 +43,7 @@
package org.eclipse.jgit.transport;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -93,7 +94,7 @@ public class OpenSshConfigTest extends RepositoryTestCase {
long lastMtime = configFile.lastModified();
do {
try (final OutputStreamWriter fw = new OutputStreamWriter(
- new FileOutputStream(configFile), "UTF-8")) {
+ new FileOutputStream(configFile), CHARSET)) {
fw.write(data);
}
} while (lastMtime == configFile.lastModified());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
index 5d9bdbdbad..b6d0611437 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
@@ -93,8 +93,7 @@ public class PackParserTest extends RepositoryTestCase {
@Test
public void test1() throws IOException {
File packFile = JGitTestUtil.getTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack");
- final InputStream is = new FileInputStream(packFile);
- try {
+ try (InputStream is = new FileInputStream(packFile)) {
ObjectDirectoryPackParser p = (ObjectDirectoryPackParser) index(is);
p.parse(NullProgressMonitor.INSTANCE);
PackFile file = p.getPackFile();
@@ -107,8 +106,6 @@ public class PackParserTest extends RepositoryTestCase {
assertTrue(file.hasObject(ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327")));
assertTrue(file.hasObject(ObjectId.fromString("aabf2ffaec9b497f0950352b3e582d73035c2035")));
assertTrue(file.hasObject(ObjectId.fromString("c59759f143fb1fe21c197981df75a7ee00290799")));
- } finally {
- is.close();
}
}
@@ -121,8 +118,7 @@ public class PackParserTest extends RepositoryTestCase {
@Test
public void test2() throws IOException {
File packFile = JGitTestUtil.getTestResourceFile("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack");
- final InputStream is = new FileInputStream(packFile);
- try {
+ try (InputStream is = new FileInputStream(packFile)) {
ObjectDirectoryPackParser p = (ObjectDirectoryPackParser) index(is);
p.parse(NullProgressMonitor.INSTANCE);
PackFile file = p.getPackFile();
@@ -140,8 +136,6 @@ public class PackParserTest extends RepositoryTestCase {
assertTrue(file.hasObject(ObjectId.fromString("20a8ade77639491ea0bd667bf95de8abf3a434c8")));
assertTrue(file.hasObject(ObjectId.fromString("2675188fd86978d5bc4d7211698b2118ae3bf658")));
// and lots more...
- } finally {
- is.close();
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
index 8ef87cb3c1..7aae7b0c32 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java
@@ -199,6 +199,23 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
assertFalse(haves.get().contains(P));
}
+ private TransportLocal newTransportLocalWithStrictValidation()
+ throws Exception {
+ return new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
+ @Override
+ ReceivePack createReceivePack(final Repository db) {
+ db.close();
+ dst.incrementOpen();
+
+ final ReceivePack rp = super.createReceivePack(dst);
+ rp.setCheckReceivedObjects(true);
+ rp.setCheckReferencedObjectsAreReachable(true);
+ rp.setAdvertiseRefsHook(new HidePrivateHook());
+ return rp;
+ }
+ };
+ }
+
@Test
public void testSuccess() throws Exception {
// Manually force a delta of an object so we reuse it later.
@@ -230,19 +247,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
// Push this new content to the remote, doing strict validation.
//
- TransportLocal t = new TransportLocal(src, uriOf(dst), dst.getDirectory()) {
- @Override
- ReceivePack createReceivePack(final Repository db) {
- db.close();
- dst.incrementOpen();
-
- final ReceivePack rp = super.createReceivePack(dst);
- rp.setCheckReceivedObjects(true);
- rp.setCheckReferencedObjectsAreReachable(true);
- rp.setAdvertiseRefsHook(new HidePrivateHook());
- return rp;
- }
- };
+ PushResult r;
RemoteRefUpdate u = new RemoteRefUpdate( //
src, //
R_MASTER, // src name
@@ -251,12 +256,9 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas
null, // local tracking branch
null // expected id
);
- PushResult r;
- try {
+ try (TransportLocal t = newTransportLocalWithStrictValidation()) {
t.setPushThin(true);
r = t.push(PM, Collections.singleton(u));
- } finally {
- t.close();
}
assertNotNull("have result", r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index a8127abd36..5246b56bdc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -13,6 +13,7 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTree;
import org.eclipse.jgit.transport.UploadPack.RequestPolicy;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
@@ -170,4 +171,149 @@ public class UploadPackTest {
Collections.singletonList(new RefSpec(blob.name())));
}
}
+
+ @Test
+ public void testFetchWithBlobNoneFilter() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob blob1 = remote2.blob("foobar");
+ RevBlob blob2 = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", blob1),
+ remote2.file("2", blob2));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(0);
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ assertTrue(client.hasObject(tree.toObjectId()));
+ assertFalse(client.hasObject(blob1.toObjectId()));
+ assertFalse(client.hasObject(blob2.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchWithBlobLimitFilter() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob longBlob = remote2.blob("foobar");
+ RevBlob shortBlob = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", longBlob),
+ remote2.file("2", shortBlob));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(5);
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ assertFalse(client.hasObject(longBlob.toObjectId()));
+ assertTrue(client.hasObject(shortBlob.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchWithBlobLimitFilterAndBitmaps() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob longBlob = remote2.blob("foobar");
+ RevBlob shortBlob = remote2.blob("fooba");
+ RevTree tree = remote2.tree(remote2.file("1", longBlob),
+ remote2.file("2", shortBlob));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true);
+
+ // generate bitmaps
+ new DfsGarbageCollector(server2).pack(null);
+ server2.scanForRepoChanges();
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(5);
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ assertFalse(client.hasObject(longBlob.toObjectId()));
+ assertTrue(client.hasObject(shortBlob.toObjectId()));
+ }
+ }
+
+ @Test
+ public void testFetchWithNonSupportingServer() throws Exception {
+ InMemoryRepository server2 = newRepo("server2");
+ TestRepository<InMemoryRepository> remote2 =
+ new TestRepository<>(server2);
+ RevBlob blob = remote2.blob("foo");
+ RevTree tree = remote2.tree(remote2.file("1", blob));
+ RevCommit commit = remote2.commit(tree);
+ remote2.update("master", commit);
+
+ server2.getConfig().setBoolean("uploadpack", null, "allowfilter", false);
+
+ testProtocol = new TestProtocol<>(
+ new UploadPackFactory<Object>() {
+ @Override
+ public UploadPack create(Object req, Repository db)
+ throws ServiceNotEnabledException,
+ ServiceNotAuthorizedException {
+ UploadPack up = new UploadPack(db);
+ return up;
+ }
+ }, null);
+ uri = testProtocol.register(ctx, server2);
+
+ try (Transport tn = testProtocol.open(uri, client, "server2")) {
+ tn.setFilterBlobLimit(0);
+
+ thrown.expect(TransportException.class);
+ thrown.expectMessage("filter requires server to advertise that capability");
+
+ tn.fetch(NullProgressMonitor.INSTANCE,
+ Collections.singletonList(new RefSpec(commit.name())));
+ }
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
index cb04f83fb5..33e2529731 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/WalkEncryptionTest.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.transport.WalkEncryptionTest.Util.cryptoCipherListPBE;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.cryptoCipherListTrans;
import static org.eclipse.jgit.transport.WalkEncryptionTest.Util.folderDelete;
@@ -360,7 +360,7 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static String textRead(File file) throws Exception {
- return new String(Files.readAllBytes(file.toPath()), UTF_8);
+ return new String(Files.readAllBytes(file.toPath()), CHARSET);
}
/**
@@ -371,7 +371,7 @@ public class WalkEncryptionTest {
* @throws Exception
*/
static void textWrite(File file, String text) throws Exception {
- Files.write(file.toPath(), text.getBytes(UTF_8));
+ Files.write(file.toPath(), text.getBytes(CHARSET));
}
static void verifyFileContent(File fileOne, File fileTwo)
@@ -419,12 +419,9 @@ public class WalkEncryptionTest {
URLConnection c = url.openConnection();
c.setConnectTimeout(500);
c.setReadTimeout(500);
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(c.getInputStream()));
- try {
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(c.getInputStream()))) {
return reader.readLine();
- } finally {
- reader.close();
}
} catch (UnknownHostException | SocketTimeoutException e) {
return "Can't reach http://checkip.amazonaws.com to"
@@ -654,9 +651,9 @@ public class WalkEncryptionTest {
Properties props = Props.discover();
props.put(AmazonS3.Keys.PASSWORD, JGIT_PASS);
props.put(AmazonS3.Keys.CRYPTO_ALG, algorithm);
- PrintWriter writer = new PrintWriter(JGIT_CONF_FILE);
- props.store(writer, "JGIT S3 connection configuration file.");
- writer.close();
+ try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE)) {
+ props.store(writer, "JGIT S3 connection configuration file.");
+ }
}
/**
@@ -668,9 +665,9 @@ public class WalkEncryptionTest {
static void configCreate(Properties source) throws Exception {
Properties target = Props.discover();
target.putAll(source);
- PrintWriter writer = new PrintWriter(JGIT_CONF_FILE);
- target.store(writer, "JGIT S3 connection configuration file.");
- writer.close();
+ try (PrintWriter writer = new PrintWriter(JGIT_CONF_FILE)) {
+ target.store(writer, "JGIT S3 connection configuration file.");
+ }
}
/**
@@ -741,7 +738,7 @@ public class WalkEncryptionTest {
AmazonS3 s3 = new AmazonS3(props);
String file = JGIT_USER + "-" + UUID.randomUUID().toString();
String path = JGIT_REMOTE_DIR + "/" + file;
- s3.put(bucket, path, file.getBytes(UTF_8));
+ s3.put(bucket, path, file.getBytes(CHARSET));
s3.delete(bucket, path);
}
@@ -836,10 +833,10 @@ public class WalkEncryptionTest {
{
byte[] origin = sourceText.getBytes(charset);
ByteArrayOutputStream target = new ByteArrayOutputStream();
- OutputStream source = crypto.encrypt(target);
- source.write(origin);
- source.flush();
- source.close();
+ try (OutputStream source = crypto.encrypt(target)) {
+ source.write(origin);
+ source.flush();
+ }
cipherText = target.toByteArray();
}
{
@@ -1074,10 +1071,10 @@ public class WalkEncryptionTest {
remoteConfig.update(config);
config.save();
- Git git = Git.open(dirOne);
- git.checkout().setName("master").call();
- git.push().setRemote(remote).setRefSpecs(specs).call();
- git.close();
+ try (Git git = Git.open(dirOne)) {
+ git.checkout().setName("master").call();
+ git.push().setRemote(remote).setRefSpecs(specs).call();
+ }
File fileStatic = new File(dirOne, nameStatic);
assertTrue("Provided by setup", fileStatic.exists());
@@ -1089,11 +1086,11 @@ public class WalkEncryptionTest {
File fileStatic = new File(dirTwo, nameStatic);
assertFalse("Not Provided by setup", fileStatic.exists());
- Git git = Git.cloneRepository().setURI(uri).setDirectory(dirTwo)
- .call();
- git.close();
+ try (Git git = Git.cloneRepository().setURI(uri)
+ .setDirectory(dirTwo).call()) {
+ assertTrue("Provided by clone", fileStatic.exists());
+ }
- assertTrue("Provided by clone", fileStatic.exists());
}
{ // Verify static file content.
@@ -1111,11 +1108,11 @@ public class WalkEncryptionTest {
assertTrue("Provided by create", fileDynamic.exists());
assertTrue("Need content to encrypt", fileDynamic.length() > 0);
- Git git = Git.open(dirOne);
- git.add().addFilepattern(nameDynamic).call();
- git.commit().setMessage(nameDynamic).call();
- git.push().setRemote(remote).setRefSpecs(specs).call();
- git.close();
+ try (Git git = Git.open(dirOne)) {
+ git.add().addFilepattern(nameDynamic).call();
+ git.commit().setMessage(nameDynamic).call();
+ git.push().setRemote(remote).setRefSpecs(specs).call();
+ }
}
@@ -1124,9 +1121,9 @@ public class WalkEncryptionTest {
File fileDynamic = new File(dirTwo, nameDynamic);
assertFalse("Not Provided by setup", fileDynamic.exists());
- Git git = Git.open(dirTwo);
- git.pull().call();
- git.close();
+ try (Git git = Git.open(dirTwo)) {
+ git.pull().call();
+ }
assertTrue("Provided by pull", fileDynamic.exists());
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java
index f7a7fb8a97..c6389fb1ae 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/NotTreeFilterTest.java
@@ -57,12 +57,13 @@ import org.junit.Test;
public class NotTreeFilterTest extends RepositoryTestCase {
@Test
public void testWrap() throws Exception {
- final TreeWalk tw = new TreeWalk(db);
- final TreeFilter a = TreeFilter.ALL;
- final TreeFilter n = NotTreeFilter.create(a);
- assertNotNull(n);
- assertTrue(a.include(tw));
- assertFalse(n.include(tw));
+ try (TreeWalk tw = new TreeWalk(db)) {
+ final TreeFilter a = TreeFilter.ALL;
+ final TreeFilter n = NotTreeFilter.create(a);
+ assertNotNull(n);
+ assertTrue(a.include(tw));
+ assertFalse(n.include(tw));
+ }
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
index e8566d2438..a748b52215 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/RawSubStringPatternTest.java
@@ -42,7 +42,7 @@
*/
package org.eclipse.jgit.util;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -93,7 +93,7 @@ public class RawSubStringPatternTest extends RepositoryTestCase {
}
private static RawCharSequence raw(String text) {
- byte[] bytes = text.getBytes(UTF_8);
+ byte[] bytes = text.getBytes(CHARSET);
return new RawCharSequence(bytes, 0, bytes.length);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
index d978804d57..e73dab2ce6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/TemporaryBufferTest.java
@@ -61,6 +61,7 @@ import org.junit.Test;
public class TemporaryBufferTest {
@Test
public void testEmpty() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try {
b.close();
@@ -75,6 +76,7 @@ public class TemporaryBufferTest {
@Test
public void testOneByte() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte test = (byte) new TestRng(getName()).nextInt();
try {
@@ -87,10 +89,8 @@ public class TemporaryBufferTest {
assertEquals(1, r.length);
assertEquals(test, r[0]);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(1, r.length);
assertEquals(test, r[0]);
@@ -102,6 +102,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlock_BulkWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ);
@@ -118,10 +119,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -133,6 +132,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_BulkWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@@ -149,10 +149,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -164,6 +162,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_SingleWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@@ -178,10 +177,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -193,6 +190,7 @@ public class TemporaryBufferTest {
@Test
public void testOneBlockAndHalf_Copy() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.Block.SZ * 3 / 2);
@@ -208,10 +206,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -223,6 +219,7 @@ public class TemporaryBufferTest {
@Test
public void testLarge_SingleWrite() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
@@ -236,10 +233,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -253,18 +248,18 @@ public class TemporaryBufferTest {
public void testInCoreInputStream() throws IOException {
final int cnt = 256;
final byte[] test = new TestRng(getName()).nextBytes(cnt);
- final TemporaryBuffer.Heap b = new TemporaryBuffer.Heap(cnt + 4);
- b.write(test);
- b.close();
-
- InputStream in = b.openInputStream();
- byte[] act = new byte[cnt];
- IO.readFully(in, act, 0, cnt);
- assertArrayEquals(test, act);
+ try (final TemporaryBuffer.Heap b = new TemporaryBuffer.Heap(cnt + 4)) {
+ b.write(test);
+ InputStream in = b.openInputStream();
+ byte[] act = new byte[cnt];
+ IO.readFully(in, act, 0, cnt);
+ assertArrayEquals(test, act);
+ }
}
@Test
public void testInCoreLimit_SwitchOnAppendByte() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT + 1);
@@ -279,10 +274,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -294,6 +287,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchBeforeAppendByte() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 3);
@@ -308,10 +302,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -323,6 +315,7 @@ public class TemporaryBufferTest {
@Test
public void testInCoreLimit_SwitchOnCopy() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final byte[] test = new TestRng(getName())
.nextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2);
@@ -340,10 +333,8 @@ public class TemporaryBufferTest {
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(test.length, r.length);
assertArrayEquals(test, r);
@@ -355,7 +346,7 @@ public class TemporaryBufferTest {
@Test
public void testDestroyWhileOpen() throws IOException {
- @SuppressWarnings("resource" /* java 7 */)
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
try {
b.write(new TestRng(getName())
@@ -367,6 +358,7 @@ public class TemporaryBufferTest {
@Test
public void testRandomWrites() throws IOException {
+ @SuppressWarnings("resource") // Buffer is explicitly destroyed in finally block
final TemporaryBuffer b = new TemporaryBuffer.LocalFile(null);
final TestRng rng = new TestRng(getName());
final int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;
@@ -399,10 +391,8 @@ public class TemporaryBufferTest {
assertEquals(expect.length, r.length);
assertArrayEquals(expect, r);
}
- {
- final ByteArrayOutputStream o = new ByteArrayOutputStream();
+ try (ByteArrayOutputStream o = new ByteArrayOutputStream()) {
b.writeTo(o, null);
- o.close();
final byte[] r = o.toByteArray();
assertEquals(expect.length, r.length);
assertArrayEquals(expect, r);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
index a72d33cd51..0655827310 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java
@@ -96,32 +96,31 @@ public class AutoCRLFOutputStreamTest {
for (int i = -4; i < 5; ++i) {
int size = Math.abs(i);
byte[] buf = new byte[size];
- InputStream in = new ByteArrayInputStream(inbytes);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- OutputStream out = new AutoCRLFOutputStream(bos);
- if (i > 0) {
- int n;
- while ((n = in.read(buf)) >= 0) {
- out.write(buf, 0, n);
+ try (InputStream in = new ByteArrayInputStream(inbytes);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OutputStream out = new AutoCRLFOutputStream(bos)) {
+ if (i > 0) {
+ int n;
+ while ((n = in.read(buf)) >= 0) {
+ out.write(buf, 0, n);
+ }
+ } else if (i < 0) {
+ int n;
+ while ((n = in.read(buf)) >= 0) {
+ byte[] b = new byte[n];
+ System.arraycopy(buf, 0, b, 0, n);
+ out.write(b);
+ }
+ } else {
+ int c;
+ while ((c = in.read()) != -1)
+ out.write(c);
}
- } else if (i < 0) {
- int n;
- while ((n = in.read(buf)) >= 0) {
- byte[] b = new byte[n];
- System.arraycopy(buf, 0, b, 0, n);
- out.write(b);
- }
- } else {
- int c;
- while ((c = in.read()) != -1)
- out.write(c);
+ out.flush();
+ byte[] actualBytes = bos.toByteArray();
+ Assert.assertEquals("bufsize=" + size, encode(expectBytes),
+ encode(actualBytes));
}
- out.flush();
- in.close();
- out.close();
- byte[] actualBytes = bos.toByteArray();
- Assert.assertEquals("bufsize=" + size, encode(expectBytes),
- encode(actualBytes));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
index 38199d8aaf..5058165802 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoLFInputStreamTest.java
@@ -44,7 +44,7 @@
package org.eclipse.jgit.util.io;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayInputStream;
@@ -97,38 +97,41 @@ public class AutoLFInputStreamTest {
private static void test(byte[] input, byte[] expected,
boolean detectBinary) throws IOException {
- final InputStream bis1 = new ByteArrayInputStream(input);
- final InputStream cis1 = new AutoLFInputStream(bis1, detectBinary);
- int index1 = 0;
- for (int b = cis1.read(); b != -1; b = cis1.read()) {
- assertEquals(expected[index1], (byte) b);
- index1++;
- }
-
- assertEquals(expected.length, index1);
-
- for (int bufferSize = 1; bufferSize < 10; bufferSize++) {
- final byte[] buffer = new byte[bufferSize];
- final InputStream bis2 = new ByteArrayInputStream(input);
- final InputStream cis2 = new AutoLFInputStream(bis2, detectBinary);
+ try (InputStream bis1 = new ByteArrayInputStream(input);
+ InputStream cis1 = new AutoLFInputStream(bis1, detectBinary)) {
+ int index1 = 0;
+ for (int b = cis1.read(); b != -1; b = cis1.read()) {
+ assertEquals(expected[index1], (byte) b);
+ index1++;
+ }
- int read = 0;
- for (int readNow = cis2.read(buffer, 0, buffer.length); readNow != -1
- && read < expected.length; readNow = cis2.read(buffer, 0,
- buffer.length)) {
- for (int index2 = 0; index2 < readNow; index2++) {
- assertEquals(expected[read + index2], buffer[index2]);
+ assertEquals(expected.length, index1);
+
+ for (int bufferSize = 1; bufferSize < 10; bufferSize++) {
+ final byte[] buffer = new byte[bufferSize];
+ try (InputStream bis2 = new ByteArrayInputStream(input);
+ InputStream cis2 = new AutoLFInputStream(bis2,
+ detectBinary)) {
+
+ int read = 0;
+ for (int readNow = cis2.read(buffer, 0,
+ buffer.length); readNow != -1
+ && read < expected.length; readNow = cis2
+ .read(buffer, 0, buffer.length)) {
+ for (int index2 = 0; index2 < readNow; index2++) {
+ assertEquals(expected[read + index2],
+ buffer[index2]);
+ }
+ read += readNow;
+ }
+
+ assertEquals(expected.length, read);
}
- read += readNow;
}
-
- assertEquals(expected.length, read);
- cis2.close();
}
- cis1.close();
}
private static byte[] asBytes(String in) {
- return in.getBytes(UTF_8);
+ return in.getBytes(CHARSET);
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java
index 6b5ef7ec64..b824fae9fd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/UnionInputStreamTest.java
@@ -58,13 +58,13 @@ import org.junit.Test;
public class UnionInputStreamTest {
@Test
public void testEmptyStream() throws IOException {
- final UnionInputStream u = new UnionInputStream();
- assertTrue(u.isEmpty());
- assertEquals(-1, u.read());
- assertEquals(-1, u.read(new byte[1], 0, 1));
- assertEquals(0, u.available());
- assertEquals(0, u.skip(1));
- u.close();
+ try (UnionInputStream u = new UnionInputStream()) {
+ assertTrue(u.isEmpty());
+ assertEquals(-1, u.read());
+ assertEquals(-1, u.read(new byte[1], 0, 1));
+ assertEquals(0, u.available());
+ assertEquals(0, u.skip(1));
+ }
}
@Test
@@ -211,25 +211,24 @@ public class UnionInputStreamTest {
@Test
public void testCloseDuringClose() throws IOException {
- final UnionInputStream u = new UnionInputStream();
final boolean closed[] = new boolean[2];
- u.add(new ByteArrayInputStream(new byte[] { 1 }) {
- @Override
- public void close() {
- closed[0] = true;
- }
- });
- u.add(new ByteArrayInputStream(new byte[] { 2 }) {
- @Override
- public void close() {
- closed[1] = true;
- }
- });
+ try (UnionInputStream u = new UnionInputStream()) {
+ u.add(new ByteArrayInputStream(new byte[] { 1 }) {
+ @Override
+ public void close() {
+ closed[0] = true;
+ }
+ });
+ u.add(new ByteArrayInputStream(new byte[] { 2 }) {
+ @Override
+ public void close() {
+ closed[1] = true;
+ }
+ });
- assertFalse(closed[0]);
- assertFalse(closed[1]);
-
- u.close();
+ assertFalse(closed[0]);
+ assertFalse(closed[1]);
+ }
assertTrue(closed[0]);
assertTrue(closed[1]);
@@ -237,6 +236,7 @@ public class UnionInputStreamTest {
@Test
public void testExceptionDuringClose() {
+ @SuppressWarnings("resource") // We are testing the close() method
final UnionInputStream u = new UnionInputStream();
u.add(new ByteArrayInputStream(new byte[] { 1 }) {
@Override
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
index e6045a91bd..3c612e1bdd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/sha1/SHA1Test.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.util.sha1;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -95,15 +95,15 @@ public class SHA1Test {
.fromString("a9993e364706816aba3e25717850c26c9cd0d89d");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST1.getBytes(UTF_8));
+ m.update(TEST1.getBytes(CHARSET));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST1.getBytes(UTF_8));
+ s.update(TEST1.getBytes(CHARSET));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST1.getBytes(UTF_8));
+ s.update(TEST1.getBytes(CHARSET));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);
@@ -117,15 +117,15 @@ public class SHA1Test {
.fromString("84983e441c3bd26ebaae4aa1f95129e5e54670f1");
MessageDigest m = MessageDigest.getInstance("SHA-1");
- m.update(TEST2.getBytes(UTF_8));
+ m.update(TEST2.getBytes(CHARSET));
ObjectId m1 = ObjectId.fromRaw(m.digest());
SHA1 s = SHA1.newInstance();
- s.update(TEST2.getBytes(UTF_8));
+ s.update(TEST2.getBytes(CHARSET));
ObjectId s1 = ObjectId.fromRaw(s.digest());
s.reset();
- s.update(TEST2.getBytes(UTF_8));
+ s.update(TEST2.getBytes(CHARSET));
ObjectId s2 = s.toObjectId();
assertEquals(m1, s1);
diff --git a/org.eclipse.jgit.ui/.settings/.api_filters b/org.eclipse.jgit.ui/.settings/.api_filters
new file mode 100644
index 0000000000..aed9c7a352
--- /dev/null
+++ b/org.eclipse.jgit.ui/.settings/.api_filters
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jgit.ui" version="2">
+ <resource path="META-INF/MANIFEST.MF">
+ <filter id="925892614">
+ <message_arguments>
+ <message_argument value="5.0.0"/>
+ <message_argument value="4.11.0"/>
+ </message_arguments>
+ </filter>
+ </resource>
+</component>
diff --git a/org.eclipse.jgit.ui/META-INF/MANIFEST.MF b/org.eclipse.jgit.ui/META-INF/MANIFEST.MF
index adfa32cc80..221ea599d7 100644
--- a/org.eclipse.jgit.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.ui/META-INF/MANIFEST.MF
@@ -4,14 +4,14 @@ Bundle-ManifestVersion: 2
Bundle-Name: %plugin_name
Automatic-Module-Name: org.eclipse.jgit.ui
Bundle-SymbolicName: org.eclipse.jgit.ui
-Bundle-Version: 4.11.1.qualifier
+Bundle-Version: 5.0.0.qualifier
Bundle-Vendor: %provider_name
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Export-Package: org.eclipse.jgit.awtui;version="4.11.1"
-Import-Package: org.eclipse.jgit.errors;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.lib;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.nls;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revplot;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.revwalk;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.transport;version="[4.11.1,4.12.0)",
- org.eclipse.jgit.util;version="[4.11.1,4.12.0)"
+Export-Package: org.eclipse.jgit.awtui;version="5.0.0"
+Import-Package: org.eclipse.jgit.errors;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.lib;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.nls;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revplot;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.revwalk;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.transport;version="[5.0.0,5.1.0)",
+ org.eclipse.jgit.util;version="[5.0.0,5.1.0)"
diff --git a/org.eclipse.jgit.ui/pom.xml b/org.eclipse.jgit.ui/pom.xml
index cf1dbd09fe..c30f4b17d4 100644
--- a/org.eclipse.jgit.ui/pom.xml
+++ b/org.eclipse.jgit.ui/pom.xml
@@ -52,7 +52,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.ui</artifactId>
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index d4a059110b..3d36b880ea 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -1,66 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.jgit" version="2">
- <resource path="META-INF/MANIFEST.MF">
- <filter id="924844039">
+ <resource path="src/org/eclipse/jgit/lib/ObjectIdSerializer.java" type="org.eclipse.jgit.lib.ObjectIdSerializer">
+ <filter id="1141899266">
<message_arguments>
- <message_argument value="4.11.1"/>
- <message_argument value="4.11.0"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/diff/DiffEntry.java" type="org.eclipse.jgit.diff.DiffEntry">
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.diff.DiffEntry"/>
- <message_argument value="diffAttribute"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants">
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.lib.ConfigConstants"/>
- <message_argument value="CONFIG_KEY_REQUIRED"/>
- </message_arguments>
- </filter>
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.lib.ConfigConstants"/>
- <message_argument value="CONFIG_SECTION_LFS"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/merge/ResolveMerger.java" type="org.eclipse.jgit.merge.ResolveMerger">
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.merge.ResolveMerger"/>
- <message_argument value="workingTreeOptions"/>
- </message_arguments>
- </filter>
- </resource>
- <resource path="src/org/eclipse/jgit/storage/pack/PackStatistics.java" type="org.eclipse.jgit.storage.pack.PackStatistics$Accumulator">
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/>
- <message_argument value="advertised"/>
- </message_arguments>
- </filter>
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/>
- <message_argument value="haves"/>
- </message_arguments>
- </filter>
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/>
- <message_argument value="timeNegotiating"/>
- </message_arguments>
- </filter>
- <filter id="336658481">
- <message_arguments>
- <message_argument value="org.eclipse.jgit.storage.pack.PackStatistics.Accumulator"/>
- <message_argument value="wants"/>
+ <message_argument value="4.11"/>
+ <message_argument value="5.0"/>
+ <message_argument value="writeWithoutMarker(OutputStream, AnyObjectId)"/>
</message_arguments>
</filter>
</resource>
diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF
index 0201aa89ac..31c0bcba96 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..6084375e37 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java
@@ -191,12 +191,12 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
throw new InvalidRemoteException(
MessageFormat.format(JGitText.get().invalidURL, uri));
}
- Repository repository = null;
+ @SuppressWarnings("resource") // Closed by caller
+ Repository repository = init();
FetchResult fetchResult = null;
Thread cleanupHook = new Thread(() -> cleanup());
Runtime.getRuntime().addShutdownHook(cleanupHook);
try {
- repository = init();
fetchResult = fetch(repository, u);
} catch (IOException ioe) {
if (repository != null) {
@@ -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/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
index 19bdd35778..459451feae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
@@ -153,7 +153,8 @@ public class PushCommand extends
final List<Transport> transports;
transports = Transport.openAll(repo, remote, Transport.Operation.PUSH);
- for (final Transport transport : transports) {
+ for (@SuppressWarnings("resource") // Explicitly closed in finally
+ final Transport transport : transports) {
transport.setPushThin(thin);
transport.setPushAtomic(atomic);
if (receivePack != null)
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
index da1ff06ae5..98c16b8931 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -1734,23 +1734,17 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
String content)
throws IOException {
File file = new File(parentDir, name);
- FileOutputStream fos = new FileOutputStream(file);
- try {
+ try (FileOutputStream fos = new FileOutputStream(file)) {
fos.write(content.getBytes(Constants.CHARACTER_ENCODING));
fos.write('\n');
- } finally {
- fos.close();
}
}
private static void appendToFile(File file, String content)
throws IOException {
- FileOutputStream fos = new FileOutputStream(file, true);
- try {
+ try (FileOutputStream fos = new FileOutputStream(file, true)) {
fos.write(content.getBytes(Constants.CHARACTER_ENCODING));
fos.write('\n');
- } finally {
- fos.close();
}
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/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/SubmoduleSyncCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java
index d22d820c32..462543d3bb 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleSyncCommand.java
@@ -132,30 +132,31 @@ public class SubmoduleSyncCommand extends GitCommand<Map<String, String>> {
path, ConfigConstants.CONFIG_KEY_URL, remoteUrl);
synced.put(path, remoteUrl);
- Repository subRepo = generator.getRepository();
- if (subRepo == null)
- continue;
+ try (Repository subRepo = generator.getRepository()) {
+ if (subRepo == null) {
+ continue;
+ }
+
+ StoredConfig subConfig;
+ String branch;
- StoredConfig subConfig;
- String branch;
- try {
subConfig = subRepo.getConfig();
// Get name of remote associated with current branch and
// fall back to default remote name as last resort
branch = getHeadBranch(subRepo);
String remote = null;
- if (branch != null)
+ if (branch != null) {
remote = subConfig.getString(
ConfigConstants.CONFIG_BRANCH_SECTION, branch,
ConfigConstants.CONFIG_KEY_REMOTE);
- if (remote == null)
+ }
+ if (remote == null) {
remote = Constants.DEFAULT_REMOTE_NAME;
+ }
subConfig.setString(ConfigConstants.CONFIG_REMOTE_SECTION,
remote, ConfigConstants.CONFIG_KEY_URL, remoteUrl);
subConfig.save();
- } finally {
- subRepo.close();
}
}
if (!synced.isEmpty())
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
index 3362d46f10..289ef4a8f5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java
@@ -149,6 +149,38 @@ public class SubmoduleUpdateCommand extends
return this;
}
+ private Repository getOrCloneSubmodule(SubmoduleWalk generator, String url)
+ throws IOException, GitAPIException {
+ Repository repository = generator.getRepository();
+ if (repository == null) {
+ if (callback != null) {
+ callback.cloningSubmodule(generator.getPath());
+ }
+ CloneCommand clone = Git.cloneRepository();
+ configure(clone);
+ clone.setURI(url);
+ clone.setDirectory(generator.getDirectory());
+ clone.setGitDir(
+ new File(new File(repo.getDirectory(), Constants.MODULES),
+ generator.getPath()));
+ if (monitor != null) {
+ clone.setProgressMonitor(monitor);
+ }
+ repository = clone.call().getRepository();
+ } else if (this.fetch) {
+ if (fetchCallback != null) {
+ fetchCallback.fetchingSubmodule(generator.getPath());
+ }
+ FetchCommand fetchCommand = Git.wrap(repository).fetch();
+ if (monitor != null) {
+ fetchCommand.setProgressMonitor(monitor);
+ }
+ configure(fetchCommand);
+ fetchCommand.call();
+ }
+ return repository;
+ }
+
/**
* {@inheritDoc}
*
@@ -175,34 +207,8 @@ public class SubmoduleUpdateCommand extends
if (url == null)
continue;
- Repository submoduleRepo = generator.getRepository();
- // Clone repository if not present
- if (submoduleRepo == null) {
- if (callback != null) {
- callback.cloningSubmodule(generator.getPath());
- }
- CloneCommand clone = Git.cloneRepository();
- configure(clone);
- clone.setURI(url);
- clone.setDirectory(generator.getDirectory());
- clone.setGitDir(new File(new File(repo.getDirectory(),
- Constants.MODULES), generator.getPath()));
- if (monitor != null)
- clone.setProgressMonitor(monitor);
- submoduleRepo = clone.call().getRepository();
- } else if (this.fetch) {
- if (fetchCallback != null) {
- fetchCallback.fetchingSubmodule(generator.getPath());
- }
- FetchCommand fetchCommand = Git.wrap(submoduleRepo).fetch();
- if (monitor != null) {
- fetchCommand.setProgressMonitor(monitor);
- }
- configure(fetchCommand);
- fetchCommand.call();
- }
-
- try (RevWalk walk = new RevWalk(submoduleRepo)) {
+ try (Repository submoduleRepo = getOrCloneSubmodule(generator,
+ url); RevWalk walk = new RevWalk(submoduleRepo)) {
RevCommit commit = walk
.parseCommit(generator.getObjectId());
@@ -237,8 +243,6 @@ public class SubmoduleUpdateCommand extends
generator.getPath());
}
}
- } finally {
- submoduleRepo.close();
}
updated.add(generator.getPath());
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/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..1220b122b8 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;
}
@@ -666,6 +669,7 @@ public class DfsInserter extends ObjectInserter {
@Override
public ObjectStream openStream() throws IOException {
+ @SuppressWarnings("resource") // Explicitly closed below
final DfsReader ctx = db.newReader();
if (srcPack != packKey) {
try {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java
index 42b1a479d8..8e9ed5d0d8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsObjDatabase.java
@@ -546,7 +546,7 @@ public abstract class DfsObjDatabase extends ObjectDatabase {
}
}
- if (newPacks.isEmpty())
+ if (newPacks.isEmpty() && newReftables.isEmpty())
return new PackListImpl(NO_PACKS.packs, NO_PACKS.reftables);
if (!foundNew) {
old.clearDirty();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/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/file/ReflogWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java
index d99c266144..b366eafe2f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java
@@ -219,6 +219,22 @@ public class ReflogWriter {
return Constants.encode(r.toString());
}
+ private FileOutputStream getFileOutputStream(File log) throws IOException {
+ try {
+ return new FileOutputStream(log, true);
+ } catch (FileNotFoundException err) {
+ File dir = log.getParentFile();
+ if (dir.exists()) {
+ throw err;
+ }
+ if (!dir.mkdirs() && !dir.isDirectory()) {
+ throw new IOException(MessageFormat
+ .format(JGitText.get().cannotCreateDirectory, dir));
+ }
+ return new FileOutputStream(log, true);
+ }
+ }
+
private ReflogWriter log(String refName, byte[] rec) throws IOException {
File log = refdb.logFor(refName);
boolean write = forceWrite
@@ -228,29 +244,17 @@ public class ReflogWriter {
return this;
WriteConfig wc = refdb.getRepository().getConfig().get(WriteConfig.KEY);
- FileOutputStream out;
- try {
- out = new FileOutputStream(log, true);
- } catch (FileNotFoundException err) {
- File dir = log.getParentFile();
- if (dir.exists())
- throw err;
- if (!dir.mkdirs() && !dir.isDirectory())
- throw new IOException(MessageFormat.format(
- JGitText.get().cannotCreateDirectory, dir));
- out = new FileOutputStream(log, true);
- }
- try {
+ try (FileOutputStream out = getFileOutputStream(log)) {
if (wc.getFSyncRefFiles()) {
FileChannel fc = out.getChannel();
ByteBuffer buf = ByteBuffer.wrap(rec);
- while (0 < buf.remaining())
+ while (0 < buf.remaining()) {
fc.write(buf);
+ }
fc.force(true);
- } else
+ } else {
out.write(rec);
- } finally {
- out.close();
+ }
}
return this;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/PackWriter.java
index 42df1a6588..490766b8f7 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,21 @@ public class PackWriter implements AutoCloseable {
objectsMap.add(otp);
}
+ // Adds the given object as an object to be packed, first performing
+ // filtering on blobs at or exceeding a given size.
+ private void filterAndAddObject(@NonNull AnyObjectId src, int type,
+ int pathHashCode) throws IOException {
+
+ // Check if this object needs to be rejected, doing the cheaper
+ // checks first.
+ boolean reject = filterBlobLimit >= 0 &&
+ type == OBJ_BLOB &&
+ reader.getObjectSize(src, OBJ_BLOB) > filterBlobLimit;
+ if (!reject) {
+ addObject(src, type, pathHashCode);
+ }
+ }
+
private boolean exclude(AnyObjectId objectId) {
if (excludeInPacks == null)
return false;
@@ -2223,290 +2248,6 @@ public class PackWriter implements AutoCloseable {
return true;
}
- /**
- * Summary of how PackWriter created the pack.
- *
- * @deprecated Use {@link PackStatistics} instead.
- */
- @Deprecated
- public static class Statistics {
- /** Statistics about a single class of object. */
- public static class ObjectType {
- // All requests are forwarded to this object.
- private PackStatistics.ObjectType objectType;
-
- /**
- * Wraps an
- * {@link org.eclipse.jgit.storage.pack.PackStatistics.ObjectType}
- * instance to maintain backwards compatibility with existing API.
- *
- * @param type
- * the wrapped instance
- */
- public ObjectType(PackStatistics.ObjectType type) {
- objectType = type;
- }
-
- /**
- * @return total number of objects output. This total includes the
- * value of {@link #getDeltas()}.
- */
- public long getObjects() {
- return objectType.getObjects();
- }
-
- /**
- * @return total number of deltas output. This may be lower than the
- * actual number of deltas if a cached pack was reused.
- */
- public long getDeltas() {
- return objectType.getDeltas();
- }
-
- /**
- * @return number of objects whose existing representation was
- * reused in the output. This count includes
- * {@link #getReusedDeltas()}.
- */
- public long getReusedObjects() {
- return objectType.getReusedObjects();
- }
-
- /**
- * @return number of deltas whose existing representation was reused
- * in the output, as their base object was also output or
- * was assumed present for a thin pack. This may be lower
- * than the actual number of reused deltas if a cached pack
- * was reused.
- */
- public long getReusedDeltas() {
- return objectType.getReusedDeltas();
- }
-
- /**
- * @return total number of bytes written. This size includes the
- * object headers as well as the compressed data. This size
- * also includes all of {@link #getDeltaBytes()}.
- */
- public long getBytes() {
- return objectType.getBytes();
- }
-
- /**
- * @return number of delta bytes written. This size includes the
- * object headers for the delta objects.
- */
- public long getDeltaBytes() {
- return objectType.getDeltaBytes();
- }
- }
-
- // All requests are forwarded to this object.
- private PackStatistics statistics;
-
- /**
- * Wraps a {@link PackStatistics} object to maintain backwards
- * compatibility with existing API.
- *
- * @param stats
- * the wrapped PackStatitics object
- */
- public Statistics(PackStatistics stats) {
- statistics = stats;
- }
-
- /**
- * @return unmodifiable collection of objects to be included in the
- * pack. May be null if the pack was hand-crafted in a unit
- * test.
- */
- public Set<ObjectId> getInterestingObjects() {
- return statistics.getInterestingObjects();
- }
-
- /**
- * @return unmodifiable collection of objects that should be excluded
- * from the pack, as the peer that will receive the pack already
- * has these objects.
- */
- public Set<ObjectId> getUninterestingObjects() {
- return statistics.getUninterestingObjects();
- }
-
- /**
- * @return unmodifiable collection of the cached packs that were reused
- * in the output, if any were selected for reuse.
- */
- public Collection<CachedPack> getReusedPacks() {
- return statistics.getReusedPacks();
- }
-
- /**
- * @return number of objects in the output pack that went through the
- * delta search process in order to find a potential delta base.
- */
- public int getDeltaSearchNonEdgeObjects() {
- return statistics.getDeltaSearchNonEdgeObjects();
- }
-
- /**
- * @return number of objects in the output pack that went through delta
- * base search and found a suitable base. This is a subset of
- * {@link #getDeltaSearchNonEdgeObjects()}.
- */
- public int getDeltasFound() {
- return statistics.getDeltasFound();
- }
-
- /**
- * @return total number of objects output. This total includes the value
- * of {@link #getTotalDeltas()}.
- */
- public long getTotalObjects() {
- return statistics.getTotalObjects();
- }
-
- /**
- * @return the count of objects that needed to be discovered through an
- * object walk because they were not found in bitmap indices.
- * Returns -1 if no bitmap indices were found.
- */
- public long getBitmapIndexMisses() {
- return statistics.getBitmapIndexMisses();
- }
-
- /**
- * @return total number of deltas output. This may be lower than the
- * actual number of deltas if a cached pack was reused.
- */
- public long getTotalDeltas() {
- return statistics.getTotalDeltas();
- }
-
- /**
- * @return number of objects whose existing representation was reused in
- * the output. This count includes {@link #getReusedDeltas()}.
- */
- public long getReusedObjects() {
- return statistics.getReusedObjects();
- }
-
- /**
- * @return number of deltas whose existing representation was reused in
- * the output, as their base object was also output or was
- * assumed present for a thin pack. This may be lower than the
- * actual number of reused deltas if a cached pack was reused.
- */
- public long getReusedDeltas() {
- return statistics.getReusedDeltas();
- }
-
- /**
- * @return total number of bytes written. This size includes the pack
- * header, trailer, thin pack, and reused cached pack(s).
- */
- public long getTotalBytes() {
- return statistics.getTotalBytes();
- }
-
- /**
- * @return size of the thin pack in bytes, if a thin pack was generated.
- * A thin pack is created when the client already has objects
- * and some deltas are created against those objects, or if a
- * cached pack is being used and some deltas will reference
- * objects in the cached pack. This size does not include the
- * pack header or trailer.
- */
- public long getThinPackBytes() {
- return statistics.getThinPackBytes();
- }
-
- /**
- * @param typeCode
- * object type code, e.g. OBJ_COMMIT or OBJ_TREE.
- * @return information about this type of object in the pack.
- */
- public ObjectType byObjectType(int typeCode) {
- return new ObjectType(statistics.byObjectType(typeCode));
- }
-
- /** @return true if the resulting pack file was a shallow pack. */
- public boolean isShallow() {
- return statistics.isShallow();
- }
-
- /** @return depth (in commits) the pack includes if shallow. */
- public int getDepth() {
- return statistics.getDepth();
- }
-
- /**
- * @return time in milliseconds spent enumerating the objects that need
- * to be included in the output. This time includes any restarts
- * that occur when a cached pack is selected for reuse.
- */
- public long getTimeCounting() {
- return statistics.getTimeCounting();
- }
-
- /**
- * @return time in milliseconds spent matching existing representations
- * against objects that will be transmitted, or that the client
- * can be assumed to already have.
- */
- public long getTimeSearchingForReuse() {
- return statistics.getTimeSearchingForReuse();
- }
-
- /**
- * @return time in milliseconds spent finding the sizes of all objects
- * that will enter the delta compression search window. The
- * sizes need to be known to better match similar objects
- * together and improve delta compression ratios.
- */
- public long getTimeSearchingForSizes() {
- return statistics.getTimeSearchingForSizes();
- }
-
- /**
- * @return time in milliseconds spent on delta compression. This is
- * observed wall-clock time and does not accurately track CPU
- * time used when multiple threads were used to perform the
- * delta compression.
- */
- public long getTimeCompressing() {
- return statistics.getTimeCompressing();
- }
-
- /**
- * @return time in milliseconds spent writing the pack output, from
- * start of header until end of trailer. The transfer speed can
- * be approximated by dividing {@link #getTotalBytes()} by this
- * value.
- */
- public long getTimeWriting() {
- return statistics.getTimeWriting();
- }
-
- /** @return total time spent processing this pack. */
- public long getTimeTotal() {
- return statistics.getTimeTotal();
- }
-
- /**
- * @return get the average output speed in terms of bytes-per-second.
- * {@code getTotalBytes() / (getTimeWriting() / 1000.0)}.
- */
- public double getTransferRate() {
- return statistics.getTransferRate();
- }
-
- /** @return formatted message string for display to clients. */
- public String getMessage() {
- return statistics.getMessage();
- }
- }
-
private class MutableState {
/** Estimated size of a single ObjectToPack instance. */
// Assume 64-bit pointers, since this is just an estimate.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java
index ce2ba4a2e1..942d72fe23 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockReader.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.internal.storage.reftable;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.internal.storage.reftable.BlockWriter.compare;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN;
@@ -138,7 +138,7 @@ class BlockReader {
if (blockType == LOG_BLOCK_TYPE) {
len -= 9;
}
- return RawParseUtils.decode(UTF_8, nameBuf, 0, len);
+ return RawParseUtils.decode(CHARSET, nameBuf, 0, len);
}
boolean match(byte[] match, boolean matchIsPrefix) {
@@ -171,7 +171,7 @@ class BlockReader {
}
Ref readRef() throws IOException {
- String name = RawParseUtils.decode(UTF_8, nameBuf, 0, nameLen);
+ String name = RawParseUtils.decode(CHARSET, nameBuf, 0, nameLen);
switch (valueType & VALUE_TYPE_MASK) {
case VALUE_NONE: // delete
return newRef(name);
@@ -266,7 +266,7 @@ class BlockReader {
private String readValueString() {
int len = readVarint32();
int end = ptr + len;
- String s = RawParseUtils.decode(UTF_8, buf, ptr, end);
+ String s = RawParseUtils.decode(CHARSET, buf, ptr, end);
ptr = end;
return s;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java
index b3173e838c..3d8fbf4996 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/BlockWriter.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.internal.storage.reftable;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE;
@@ -440,7 +440,7 @@ class BlockWriter {
}
private static byte[] nameUtf8(Ref ref) {
- return ref.getName().getBytes(UTF_8);
+ return ref.getName().getBytes(CHARSET);
}
}
@@ -559,13 +559,13 @@ class BlockWriter {
this.newId = newId;
this.timeSecs = who.getWhen().getTime() / 1000L;
this.tz = (short) who.getTimeZoneOffset();
- this.name = who.getName().getBytes(UTF_8);
- this.email = who.getEmailAddress().getBytes(UTF_8);
- this.msg = message.getBytes(UTF_8);
+ this.name = who.getName().getBytes(CHARSET);
+ this.email = who.getEmailAddress().getBytes(CHARSET);
+ this.msg = message.getBytes(CHARSET);
}
static byte[] key(String ref, long index) {
- byte[] name = ref.getBytes(UTF_8);
+ byte[] name = ref.getBytes(CHARSET);
byte[] key = Arrays.copyOf(name, name.length + 1 + 8);
NB.encodeInt64(key, key.length - 8, reverseUpdateIndex(index));
return key;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java
index 1fc43c9fac..44bbb16219 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableOutputStream.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.internal.storage.reftable;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_HEADER_LEN;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.INDEX_BLOCK_TYPE;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.LOG_BLOCK_TYPE;
@@ -160,7 +160,7 @@ class ReftableOutputStream extends OutputStream {
}
void writeVarintString(String s) {
- writeVarintString(s.getBytes(UTF_8));
+ writeVarintString(s.getBytes(CHARSET));
}
void writeVarintString(byte[] msg) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java
index 74877192f6..5356952b5d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftable/ReftableReader.java
@@ -43,7 +43,7 @@
package org.eclipse.jgit.internal.storage.reftable;
-import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.eclipse.jgit.lib.Constants.CHARSET;
import static org.eclipse.jgit.internal.storage.reftable.BlockReader.decodeBlockLen;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_BLOCK_TYPE;
import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.FILE_FOOTER_LEN;
@@ -182,7 +182,7 @@ public class ReftableReader extends Reftable {
public RefCursor seekRef(String refName) throws IOException {
initRefIndex();
- byte[] key = refName.getBytes(UTF_8);
+ byte[] key = refName.getBytes(CHARSET);
boolean prefix = key[key.length - 1] == '/';
RefCursorImpl i = new RefCursorImpl(refEnd, key, prefix);
@@ -223,7 +223,7 @@ public class ReftableReader extends Reftable {
initLogIndex();
if (logPosition > 0) {
byte[] key = LogEntry.key(refName, updateIndex);
- byte[] match = refName.getBytes(UTF_8);
+ byte[] match = refName.getBytes(CHARSET);
LogCursorImpl i = new LogCursorImpl(logEnd, match);
i.block = seek(LOG_BLOCK_TYPE, key, logIndex, logPosition, logEnd);
return i;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/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..c49013a8a1 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"); //$NON-NLS-1$
+ } else if (filterBlobLimit > 0) {
+ p.writeString(OPTION_FILTER + " blob:limit=" + filterBlobLimit); //$NON-NLS-1$
+ }
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/TransportGitAnon.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
index 816187ee0c..cbf77bb0b2 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportGitAnon.java
@@ -142,6 +142,7 @@ class TransportGitAnon extends TcpTransport implements PackTransport {
Socket openConnection() throws TransportException {
final int tms = getTimeout() > 0 ? getTimeout() * 1000 : 0;
final int port = uri.getPort() > 0 ? uri.getPort() : GIT_PORT;
+ @SuppressWarnings("resource") // Closed by the caller
final Socket s = new Socket();
try {
final InetAddress host = InetAddress.getByName(uri.getHost());
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..87c328f452 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java
@@ -336,6 +336,22 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
useSmartHttp = on;
}
+ @SuppressWarnings("resource") // Closed by caller
+ private FetchConnection getConnection(HttpConnection c, InputStream in,
+ String service) throws IOException {
+ BaseConnection f;
+ if (isSmartHttp(c, service)) {
+ readSmartHeaders(in, service);
+ f = new SmartHttpFetchConnection(in);
+ } else {
+ // Assume this server doesn't support smart HTTP fetch
+ // and fall back on dumb object walking.
+ f = newDumbConnection(in);
+ }
+ f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
+ return (FetchConnection) f;
+ }
+
/** {@inheritDoc} */
@Override
public FetchConnection openFetch() throws TransportException,
@@ -343,21 +359,8 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
final String service = SVC_UPLOAD_PACK;
try {
final HttpConnection c = connect(service);
- final InputStream in = openInputStream(c);
- try {
- BaseConnection f;
- if (isSmartHttp(c, service)) {
- readSmartHeaders(in, service);
- f = new SmartHttpFetchConnection(in);
- } else {
- // Assume this server doesn't support smart HTTP fetch
- // and fall back on dumb object walking.
- f = newDumbConnection(in);
- }
- f.setPeerUserAgent(c.getHeaderField(HttpSupport.HDR_SERVER));
- return (FetchConnection) f;
- } finally {
- in.close();
+ try (InputStream in = openInputStream(c)) {
+ return getConnection(c, in, service);
}
} catch (NotSupportedException err) {
throw err;
@@ -796,21 +799,6 @@ public class TransportHttp extends HttpTransport implements WalkTransport,
}
/**
- * Open an HTTP connection, setting the accept-encoding request header to gzip.
- *
- * @param method HTTP request method
- * @param u url of the HTTP connection
- * @return the HTTP connection
- * @throws java.io.IOException
- * @since 3.3
- * @deprecated use {@link #httpOpen(String, URL, AcceptEncoding)} instead.
- */
- @Deprecated
- protected HttpConnection httpOpen(String method, URL u) throws IOException {
- return httpOpen(method, u, AcceptEncoding.GZIP);
- }
-
- /**
* Open an HTTP connection.
*
* @param method HTTP request method
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..6ae7b96d43 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,42 @@ 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")) { //$NON-NLS-1$
+ filterBlobLimit = 0;
+ } else if (arg.startsWith("blob:limit=")) { //$NON-NLS-1$
+ try {
+ filterBlobLimit = Long.parseLong(
+ arg.substring("blob:limit=".length())); //$NON-NLS-1$
+ } catch (NumberFormatException e) {
+ throw new PackProtocolException(
+ MessageFormat.format(JGitText.get().invalidFilter,
+ arg));
+ }
+ }
+ /*
+ * We must have (1) either "blob:none" or
+ * "blob:limit=" set (because we only support
+ * blob size limits for now), and (2) if the
+ * latter, then it must be nonnegative. Throw
+ * if (1) or (2) is not met.
+ */
+ if (filterBlobLimit < 0) {
+ throw new PackProtocolException(
+ MessageFormat.format(JGitText.get().invalidFilter,
+ arg));
+ }
+ 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 +1542,6 @@ public class UploadPack {
}
}
- @SuppressWarnings("deprecation")
private void sendPack(final boolean sideband,
PackStatistics.Accumulator accumulator) throws IOException {
ProgressMonitor pm = NullProgressMonitor.INSTANCE;
@@ -1583,11 +1584,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 +1677,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/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..06f53c2f3b 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) {
@@ -232,13 +211,7 @@ public class FileTreeIterator extends WorkingTreeIterator {
}
private Entry[] entries() {
- final File[] all = directory.listFiles();
- if (all == null)
- return EOF;
- final Entry[] r = new Entry[all.length];
- for (int i = 0; i < r.length; i++)
- r[i] = new FileEntry(all[i], fs, fileModeStrategy);
- return r;
+ return fs.list(directory, fileModeStrategy);
}
/**
@@ -267,7 +240,7 @@ public class FileTreeIterator extends WorkingTreeIterator {
*
* @since 4.3
*/
- static public class DefaultFileModeStrategy implements FileModeStrategy {
+ public static class DefaultFileModeStrategy implements FileModeStrategy {
/**
* a singleton instance of the default FileModeStrategy
*/
@@ -300,7 +273,7 @@ public class FileTreeIterator extends WorkingTreeIterator {
*
* @since 4.3
*/
- static public class NoGitlinksStrategy implements FileModeStrategy {
+ public static class NoGitlinksStrategy implements FileModeStrategy {
/**
* a singleton instance of the default FileModeStrategy
@@ -325,7 +298,7 @@ public class FileTreeIterator extends WorkingTreeIterator {
/**
* Wrapper for a standard Java IO file
*/
- static public class FileEntry extends Entry {
+ public static class FileEntry extends Entry {
private final FileMode mode;
private FS.Attributes attributes;
@@ -364,6 +337,29 @@ public class FileTreeIterator extends WorkingTreeIterator {
mode = fileModeStrategy.getMode(f, attributes);
}
+ /**
+ * Create a new file entry given the specified FileModeStrategy
+ *
+ * @param f
+ * file
+ * @param fs
+ * file system
+ * @param attributes
+ * of the file
+ * @param fileModeStrategy
+ * the strategy to use when determining the FileMode of a
+ * file; controls gitlinks etc.
+ *
+ * @since 5.0
+ */
+ public FileEntry(File f, FS fs, FS.Attributes attributes,
+ FileModeStrategy fileModeStrategy) {
+ this.fs = fs;
+ this.attributes = attributes;
+ f = fs.normalize(f);
+ mode = fileModeStrategy.getMode(f, attributes);
+ }
+
@Override
public FileMode getMode() {
return mode;
@@ -386,12 +382,12 @@ public class FileTreeIterator extends WorkingTreeIterator {
@Override
public InputStream openInputStream() throws IOException {
- if (fs.isSymLink(getFile()))
+ if (attributes.isSymbolicLink()) {
return new ByteArrayInputStream(fs.readSymLink(getFile())
- .getBytes(
- Constants.CHARACTER_ENCODING));
- else
+ .getBytes(Constants.CHARACTER_ENCODING));
+ } else {
return new FileInputStream(getFile());
+ }
}
/**
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..cb68cee7bd 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);
+ 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;
}
- if (submoduleRepo == null)
- return zeroid;
-
- final ObjectId head;
- try {
- head = submoduleRepo.resolve(Constants.HEAD);
- } 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',
@@ -1173,8 +1165,12 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator {
return contentDigest.digest();
}
- /** A single entry within a working directory tree. */
- protected static abstract class Entry {
+ /**
+ * A single entry within a working directory tree.
+ *
+ * @since 5.0
+ */
+ public static abstract class Entry {
byte[] encodedName;
int encodedNameLen;
@@ -1280,11 +1276,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 +1325,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 +1343,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.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
index edcb9d7a6a..27a437f4f5 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
@@ -71,6 +71,9 @@ import org.eclipse.jgit.errors.CommandFailedException;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry;
+import org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy;
+import org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry;
import org.eclipse.jgit.util.ProcessResult.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,6 +85,14 @@ public abstract class FS {
private static final Logger LOG = LoggerFactory.getLogger(FS.class);
/**
+ * An empty array of entries, suitable as a return value for
+ * {@link #list(File, FileModeStrategy)}.
+ *
+ * @since 5.0
+ */
+ protected static final Entry[] NO_ENTRIES = {};
+
+ /**
* This class creates FS instances. It will be overridden by a Java7 variant
* if such can be detected in {@link #detect(Boolean)}.
*
@@ -887,6 +898,29 @@ public abstract class FS {
}
/**
+ * Enumerates children of a directory.
+ *
+ * @param directory
+ * to get the children of
+ * @param fileModeStrategy
+ * to use to calculate the git mode of a child
+ * @return an array of entries for the children
+ *
+ * @since 5.0
+ */
+ public Entry[] list(File directory, FileModeStrategy fileModeStrategy) {
+ final File[] all = directory.listFiles();
+ if (all == null) {
+ return NO_ENTRIES;
+ }
+ final Entry[] result = new Entry[all.length];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = new FileEntry(all[i], this, fileModeStrategy);
+ }
+ return result;
+ }
+
+ /**
* Checks whether the given hook is defined for the given repository, then
* runs it with the given arguments.
* <p>
@@ -1108,19 +1142,23 @@ public abstract class FS {
new StreamGobbler(process.getErrorStream(), errRedirect));
executor.execute(
new StreamGobbler(process.getInputStream(), outRedirect));
+ @SuppressWarnings("resource") // Closed in the finally block
OutputStream outputStream = process.getOutputStream();
- if (inRedirect != null) {
- new StreamGobbler(inRedirect, outputStream).copy();
- }
try {
- outputStream.close();
- } catch (IOException e) {
- // When the process exits before consuming the input, the OutputStream
- // is replaced with the null output stream. This null output stream
- // throws IOException for all write calls. When StreamGobbler fails to
- // flush the buffer because of this, this close call tries to flush it
- // again. This causes another IOException. Since we ignore the
- // IOException in StreamGobbler, we also ignore the exception here.
+ if (inRedirect != null) {
+ new StreamGobbler(inRedirect, outputStream).copy();
+ }
+ } finally {
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ // When the process exits before consuming the input, the OutputStream
+ // is replaced with the null output stream. This null output stream
+ // throws IOException for all write calls. When StreamGobbler fails to
+ // flush the buffer because of this, this close call tries to flush it
+ // again. This causes another IOException. Since we ignore the
+ // IOException in StreamGobbler, we also ignore the exception here.
+ }
}
return process.waitFor();
} catch (IOException e) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
index 29fe5dc829..a0ed04fe66 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32.java
@@ -47,11 +47,21 @@ package org.eclipse.jgit.util;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.file.FileVisitOption;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.EnumSet;
import java.util.List;
import org.eclipse.jgit.errors.CommandFailedException;
+import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry;
+import org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy;
+import org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -121,6 +131,49 @@ public class FS_Win32 extends FS {
/** {@inheritDoc} */
@Override
+ public Entry[] list(File directory, FileModeStrategy fileModeStrategy) {
+ List<Entry> result = new ArrayList<>();
+ FS fs = this;
+ boolean checkExecutable = fs.supportsExecute();
+ try {
+ Files.walkFileTree(directory.toPath(),
+ EnumSet.noneOf(FileVisitOption.class), 1,
+ new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file,
+ BasicFileAttributes attrs) throws IOException {
+ File f = file.toFile();
+ FS.Attributes attributes = new FS.Attributes(fs, f,
+ true, attrs.isDirectory(),
+ checkExecutable && f.canExecute(),
+ attrs.isSymbolicLink(),
+ attrs.isRegularFile(),
+ attrs.creationTime().toMillis(),
+ attrs.lastModifiedTime().toMillis(),
+ attrs.size());
+ result.add(new FileEntry(f, fs, attributes,
+ fileModeStrategy));
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult visitFileFailed(Path file,
+ IOException exc) throws IOException {
+ // Just ignore it
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ } catch (IOException e) {
+ // Ignore
+ }
+ if (result.isEmpty()) {
+ return NO_ENTRIES;
+ }
+ return result.toArray(new Entry[result.size()]);
+ }
+
+ /** {@inheritDoc} */
+ @Override
protected File discoverGitExe() {
String path = SystemReader.getInstance().getenv("PATH"); //$NON-NLS-1$
File gitExe = searchPath(path, "git.exe", "git.cmd"); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
index 64cdcc300d..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
diff --git a/pom.xml b/pom.xml
index aba1582be7..794654a3e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,7 @@
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit-parent</artifactId>
<packaging>pom</packaging>
- <version>4.11.1-SNAPSHOT</version>
+ <version>5.0.0-SNAPSHOT</version>
<name>JGit - Parent</name>
<url>${jgit-url}</url>