From c70c51fdd1d4be8b2033b22cf7f0f4a7492462e3 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 29 Aug 2018 13:02:52 +0900 Subject: [PATCH 01/16] Upgrade maven-compiler-plugin to 3.8.0 Change-Id: I545095f9ee7481c73765d029f9a32edf01625893 Signed-off-by: David Pursehouse --- pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 904abd239..0fbd1c708 100644 --- a/pom.xml +++ b/pom.xml @@ -218,6 +218,7 @@ 2.8.2 3.1.6 2.21.0 + 3.8.0 jacoco @@ -744,7 +745,7 @@ maven-compiler-plugin - 3.7.0 + ${maven-compiler-plugin-version} UTF-8 1.8 @@ -813,7 +814,7 @@ maven-compiler-plugin - 3.7.0 + ${maven-compiler-plugin-version} eclipse UTF-8 From afbc55aa229535a53a75b9641849c54d76f41eee Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 30 Aug 2018 08:50:37 +0900 Subject: [PATCH 02/16] Format BUILD files with buildifier 0.15.0 Change-Id: I6200b0040d24da86968c688f45a2056343e182be Signed-off-by: David Pursehouse --- org.eclipse.jgit.pgm/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit.pgm/BUILD b/org.eclipse.jgit.pgm/BUILD index bbf4b1c43..ddc84bea0 100644 --- a/org.eclipse.jgit.pgm/BUILD +++ b/org.eclipse.jgit.pgm/BUILD @@ -27,8 +27,8 @@ java_library( java_binary( name = "jgit", - runtime_deps = [":pgm"], main_class = "org.eclipse.jgit.pgm.Main", + runtime_deps = [":pgm"], ) java_import( From 19222ce7c455a25dacd1867d207081d604cfb066 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 30 Aug 2018 08:48:41 +0900 Subject: [PATCH 03/16] Bazel: Use hyphen instead of underscore in external repository names Recent Bazel versions support the hyphen character in external repository names. On the Gerrit project, the repository names were harmonized to consistently use hyphen. As a side effect, it is no longer possible to build jgit from source in the gerrit tree, due to the different repository names. Rename the dependencies to use hyphens, consistent with gerrit. Change-Id: Ideebd858ddd3f0e6f765643001642dfb6c12441f Signed-off-by: David Pursehouse --- WORKSPACE | 30 +++++++++++++++--------------- lib/BUILD | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 3f36b3472..9d723d28e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -40,43 +40,43 @@ maven_jar( ) maven_jar( - name = "commons_codec", + name = "commons-codec", artifact = "commons-codec:commons-codec:1.10", sha1 = "4b95f4897fa13f2cd904aee711aeafc0c5295cd8", ) maven_jar( - name = "commons_logging", + name = "commons-logging", artifact = "commons-logging:commons-logging:1.2", sha1 = "4bfc12adfe4842bf07b657f0369c4cb522955686", ) maven_jar( - name = "log_api", + name = "log-api", artifact = "org.slf4j:slf4j-api:1.7.2", sha1 = "0081d61b7f33ebeab314e07de0cc596f8e858d97", ) maven_jar( - name = "slf4j_simple", + name = "slf4j-simple", artifact = "org.slf4j:slf4j-simple:1.7.2", sha1 = "760055906d7353ba4f7ce1b8908bc6b2e91f39fa", ) maven_jar( - name = "servlet_api_3_1", + name = "servlet-api-3_1", artifact = "javax.servlet:javax.servlet-api:3.1.0", sha1 = "3cd63d075497751784b2fa84be59432f4905bf7c", ) maven_jar( - name = "commons_compress", + name = "commons-compress", artifact = "org.apache.commons:commons-compress:1.15", sha1 = "b686cd04abaef1ea7bc5e143c080563668eec17e", ) maven_jar( - name = "tukaani_xz", + name = "tukaani-xz", artifact = "org.tukaani:xz:1.6", sha1 = "05b6f921f1810bdf90e25471968f741f87168b64", ) @@ -94,13 +94,13 @@ maven_jar( ) maven_jar( - name = "hamcrest_library", + name = "hamcrest-library", artifact = "org.hamcrest:hamcrest-library:1.3", sha1 = "4785a3c21320980282f9f33d0d1264a69040538f", ) maven_jar( - name = "hamcrest_core", + name = "hamcrest-core", artifact = "org.hamcrest:hamcrest-core:1.3", sha1 = "42a25dc3219429f0e5d060061f71acb49bf010a0", ) @@ -114,42 +114,42 @@ maven_jar( JETTY_VER = "9.4.11.v20180605" maven_jar( - name = "jetty_servlet", + name = "jetty-servlet", artifact = "org.eclipse.jetty:jetty-servlet:" + JETTY_VER, sha1 = "66d31900fcfc70e3666f0b3335b6660635154f98", src_sha1 = "930c50de49b9c258d5f0329426cbcac4d3143497", ) maven_jar( - name = "jetty_security", + name = "jetty-security", artifact = "org.eclipse.jetty:jetty-security:" + JETTY_VER, sha1 = "926def86d31ee07ca4b4658833dc6ee6918b8e86", src_sha1 = "019bc7c2a366cbb201950f24dd64d9d9a49b6840", ) maven_jar( - name = "jetty_server", + name = "jetty-server", artifact = "org.eclipse.jetty:jetty-server:" + JETTY_VER, sha1 = "58353c2f27515b007fc83ae22002feb34fc24714", src_sha1 = "e7d832d74df616137755996b41bc28bb82b3bc42", ) maven_jar( - name = "jetty_http", + name = "jetty-http", artifact = "org.eclipse.jetty:jetty-http:" + JETTY_VER, sha1 = "20c35f5336befe35b0bd5c4a63e07170fe7872d7", src_sha1 = "5bc30d1f7e8c4456c22cc85999b8cafd3741bdff", ) maven_jar( - name = "jetty_io", + name = "jetty-io", artifact = "org.eclipse.jetty:jetty-io:" + JETTY_VER, sha1 = "d164de1dac18c4ca80a1b783d879c97449909c3b", src_sha1 = "02c0caba292b1cb74cec1d36c6f91dc863c89b5a", ) maven_jar( - name = "jetty_util", + name = "jetty-util", artifact = "org.eclipse.jetty:jetty-util:" + JETTY_VER, sha1 = "f0f25aa2f27d618a04bc7356fa247ae4a05245b3", src_sha1 = "4e5c4c483cfd9804c2fc5d5751866243bbb9d740", diff --git a/lib/BUILD b/lib/BUILD index 53eb19188..ebba0daf4 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -13,19 +13,19 @@ java_library( "//org.eclipse.jgit.archive:__pkg__", "//org.eclipse.jgit.pgm.test:__pkg__", ], - exports = ["@commons_compress//jar"], + exports = ["@commons-compress//jar"], ) java_library( name = "commons-codec", - exports = ["@commons_codec//jar"], + exports = ["@commons-codec//jar"], ) java_library( name = "commons-logging", testonly = 1, visibility = ["//visibility:public"], - exports = ["@commons_logging//jar"], + exports = ["@commons-logging//jar"], ) java_library( @@ -69,7 +69,7 @@ java_library( name = "jetty-http", # TODO: This should be testonly but org.eclipse.jgit.pgm depends on it. visibility = ["//visibility:public"], - exports = ["@jetty_http//jar"], + exports = ["@jetty-http//jar"], runtime_deps = [":commons-codec"], ) @@ -77,35 +77,35 @@ java_library( name = "jetty-io", # TODO: This should be testonly but org.eclipse.jgit.pgm depends on it. visibility = ["//visibility:public"], - exports = ["@jetty_io//jar"], + exports = ["@jetty-io//jar"], ) java_library( name = "jetty-security", # TODO: This should be testonly but org.eclipse.jgit.pgm depends on it. visibility = ["//visibility:public"], - exports = ["@jetty_security//jar"], + exports = ["@jetty-security//jar"], ) java_library( name = "jetty-server", # TODO: This should be testonly but org.eclipse.jgit.pgm depends on it. visibility = ["//visibility:public"], - exports = ["@jetty_server//jar"], + exports = ["@jetty-server//jar"], ) java_library( name = "jetty-servlet", # TODO: This should be testonly but org.eclipse.jgit.pgm depends on it. visibility = ["//visibility:public"], - exports = ["@jetty_servlet//jar"], + exports = ["@jetty-servlet//jar"], ) java_library( name = "jetty-util", # TODO: This should be testonly but org.eclipse.jgit.pgm depends on it. visibility = ["//visibility:public"], - exports = ["@jetty_util//jar"], + exports = ["@jetty-util//jar"], ) java_library( @@ -131,8 +131,8 @@ java_library( testonly = 1, visibility = ["//visibility:public"], exports = [ - "@hamcrest_core//jar", - "@hamcrest_library//jar", + "@hamcrest-core//jar", + "@hamcrest-library//jar", "@junit//jar", ], ) @@ -148,25 +148,25 @@ java_library( "//org.eclipse.jgit.lfs.server.test:__pkg__", "//org.eclipse.jgit.pgm:__pkg__", ], - exports = ["@servlet_api_3_1//jar"], + exports = ["@servlet-api-3_1//jar"], ) java_library( name = "slf4j-api", visibility = ["//visibility:public"], - exports = ["@log_api//jar"], + exports = ["@log-api//jar"], ) java_library( name = "slf4j-simple", testonly = 1, visibility = ["//visibility:public"], - exports = ["@slf4j_simple//jar"], + exports = ["@slf4j-simple//jar"], ) java_library( name = "xz", testonly = 1, visibility = ["//visibility:public"], - exports = ["@tukaani_xz//jar"], + exports = ["@tukaani-xz//jar"], ) From e665e3fcd4fdb5097332c0e048c80ccc0dd05caf Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Wed, 29 Aug 2018 16:36:42 -0700 Subject: [PATCH 04/16] UploadPack: avoid conflating shallow commit lists in protocol v2 At the moment there are two copies of the client shallow commit list: one in the request and another in the clientShallowCommits member of the class. The verifyShallowCommit function was removing missing object ids from the member but not the request list, and code afterwards was using the request's version. In practice, this didn't cause trouble because these shallow commits are used as endpoint for a walk, and missing ids are just never reached. Change-Id: I70a8f1fd46de135da09f16e5d954693c8438ffcb Signed-off-by: Ivan Frade --- .../jgit/transport/UploadPackTest.java | 38 +++++++++++++++++++ .../eclipse/jgit/transport/UploadPack.java | 19 ++++++---- 2 files changed, 50 insertions(+), 7 deletions(-) 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 79d3d87e2..4c6076a20 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 @@ -1417,6 +1417,44 @@ public class UploadPackTest { assertFalse(client.hasObject(parent.toObjectId())); } + @Test + public void testV2FetchMissingShallow() throws Exception { + RevCommit one = remote.commit().message("1").create(); + RevCommit two = remote.commit().message("2").parent(one).create(); + RevCommit three = remote.commit().message("3").parent(two).create(); + remote.update("three", three); + + server.getConfig().setBoolean("uploadpack", null, "allowrefinwant", + true); + + ByteArrayInputStream recvStream = uploadPackV2("command=fetch\n", + PacketLineIn.DELIM, + "want-ref refs/heads/three\n", + "deepen 3", + "shallow 0123012301230123012301230123012301230123", + "shallow " + two.getName() + '\n', + "done\n", + PacketLineIn.END); + PacketLineIn pckIn = new PacketLineIn(recvStream); + + assertThat(pckIn.readString(), is("shallow-info")); + assertThat(pckIn.readString(), + is("shallow " + one.toObjectId().getName())); + assertThat(pckIn.readString(), + is("unshallow " + two.toObjectId().getName())); + assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertThat(pckIn.readString(), is("wanted-refs")); + assertThat(pckIn.readString(), + is(three.toObjectId().getName() + " refs/heads/three")); + assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertThat(pckIn.readString(), is("packfile")); + parsePack(recvStream); + + assertTrue(client.hasObject(one.toObjectId())); + assertTrue(client.hasObject(two.toObjectId())); + assertTrue(client.hasObject(three.toObjectId())); + } + private static class RejectAllRefFilter implements RefFilter { @Override public Map filter(Map refs) { 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 60938facb..a88057089 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -295,7 +295,7 @@ public class UploadPack { private final Set commonBase = new HashSet<>(); /** Shallow commits the client already has. */ - private final Set clientShallowCommits = new HashSet<>(); + private Set clientShallowCommits = new HashSet<>(); /** Desired depth from the client on a shallow request. */ private int depth; @@ -832,7 +832,7 @@ public class UploadPack { multiAck = MultiAck.OFF; if (!clientShallowCommits.isEmpty()) - verifyClientShallow(); + verifyClientShallow(clientShallowCommits); if (depth != 0) processShallow(null, unshallowCommits, true); if (!clientShallowCommits.isEmpty()) @@ -1068,7 +1068,7 @@ public class UploadPack { // copying data back to class fields options = req.getOptions(); wantIds.addAll(req.getWantsIds()); - clientShallowCommits.addAll(req.getClientShallowCommits()); + clientShallowCommits = req.getClientShallowCommits(); depth = req.getDepth(); shallowSince = req.getShallowSince(); filterBlobLimit = req.getFilterBlobLimit(); @@ -1079,7 +1079,7 @@ public class UploadPack { List unshallowCommits = new ArrayList<>(); if (!req.getClientShallowCommits().isEmpty()) { - verifyClientShallow(); + verifyClientShallow(req.getClientShallowCommits()); } if (req.getDepth() != 0 || req.getShallowSince() != 0 || !req.getShallowExcludeRefs().isEmpty()) { @@ -1303,9 +1303,14 @@ public class UploadPack { } } - private void verifyClientShallow() + /* + * Verify all shallow lines refer to commits + * + * It can mutate the input set (removing missing object ids from it) + */ + private void verifyClientShallow(Set shallowCommits) throws IOException, PackProtocolException { - AsyncRevObjectQueue q = walk.parseAny(clientShallowCommits, true); + AsyncRevObjectQueue q = walk.parseAny(shallowCommits, true); try { for (;;) { try { @@ -1323,7 +1328,7 @@ public class UploadPack { } catch (MissingObjectException notCommit) { // shallow objects not known at the server are ignored // by git-core upload-pack, match that behavior. - clientShallowCommits.remove(notCommit.getObjectId()); + shallowCommits.remove(notCommit.getObjectId()); continue; } } From 74d41be0d14c4b0234b76e3147beaeedab6537c1 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Thu, 30 Aug 2018 12:44:51 -0700 Subject: [PATCH 05/16] Use right variable in error message about depth When this exception is thrown, the `depth` member variable isn't set yet, resulting in a confusing error message: "Invalid depth: 0". Change-Id: I8a2bd5e1d9bec00acb0b8857bbf6821e95bf1369 Signed-off-by: Ivan Frade --- org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a88057089..03fc57cba 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1015,7 +1015,7 @@ public class UploadPack { if (parsedDepth <= 0) { throw new PackProtocolException( MessageFormat.format(JGitText.get().invalidDepth, - Integer.valueOf(depth))); + Integer.valueOf(parsedDepth))); } if (reqBuilder.getShallowSince() != 0) { throw new PackProtocolException( From 04d27cf70fb51ba6ffb1ca353fe81160fbef6883 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Mon, 27 Aug 2018 10:14:27 -0700 Subject: [PATCH 06/16] FetchV2Request round up (doneReceived, renamings) Make "doneReceived" a member of the fetch request. It indicates if the "done" line has been received (so it makes sense there) and makes all the code after the parsing depend only on the request. Rename "shallowExcludeRefs" to "deepenNot". Those refs come in "deepen-not" lines in the protocol, and this name makes clearer the intention. Change-Id: I7bec65de04930277266491d278de7c3af7d8cbe6 Signed-off-by: Ivan Frade --- .../jgit/transport/FetchV2Request.java | 53 +++++++++++++------ .../eclipse/jgit/transport/UploadPack.java | 19 ++++--- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java index 188c0e057..e633ca420 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java @@ -71,7 +71,7 @@ public final class FetchV2Request { private final int shallowSince; - private final List shallowExcludeRefs; + private final List deepenNotRefs; private final int depth; @@ -79,19 +79,22 @@ public final class FetchV2Request { private final Set options; + private final boolean doneReceived; + private FetchV2Request(List peerHas, TreeMap wantedRefs, Set wantsIds, Set clientShallowCommits, int shallowSince, - List shallowExcludeRefs, int depth, long filterBlobLimit, - Set options) { + List deependNotRefs, int depth, long filterBlobLimit, + boolean doneReceived, Set options) { this.peerHas = peerHas; this.wantedRefs = wantedRefs; this.wantsIds = wantsIds; this.clientShallowCommits = clientShallowCommits; this.shallowSince = shallowSince; - this.shallowExcludeRefs = shallowExcludeRefs; + this.deepenNotRefs = deependNotRefs; this.depth = depth; this.filterBlobLimit = filterBlobLimit; + this.doneReceived = doneReceived; this.options = options; } @@ -135,8 +138,8 @@ public final class FetchV2Request { * The value in a "deepen-since" line in the request, indicating the * timestamp where to stop fetching/cloning. * - * @return timestamp where to stop the shallow fetch/clone. Defaults to 0 if - * not set in the request + * @return timestamp in seconds since the epoch, where to stop the shallow + * fetch/clone. Defaults to 0 if not set in the request. */ int getShallowSince() { return shallowSince; @@ -146,8 +149,8 @@ public final class FetchV2Request { * @return the refs in "deepen-not" lines in the request. */ @NonNull - List getShallowExcludeRefs() { - return shallowExcludeRefs; + List getDeepenNotRefs() { + return deepenNotRefs; } /** @@ -164,6 +167,13 @@ public final class FetchV2Request { return filterBlobLimit; } + /** + * @return true if the request had a "done" line + */ + boolean wasDoneReceived() { + return doneReceived; + } + /** * Options that tune the expected response from the server, like * "thin-pack", "no-progress" or "ofs-delta" @@ -194,7 +204,7 @@ public final class FetchV2Request { Set clientShallowCommits = new HashSet<>(); - List shallowExcludeRefs = new ArrayList<>(); + List deepenNotRefs = new ArrayList<>(); Set options = new HashSet<>(); @@ -204,6 +214,8 @@ public final class FetchV2Request { long filterBlobLimit = -1; + boolean doneReceived; + private Builder() { } @@ -282,16 +294,16 @@ public final class FetchV2Request { /** * @return if there has been any "deepen not" line in the request */ - boolean hasShallowExcludeRefs() { - return shallowExcludeRefs.size() > 0; + boolean hasDeepenNotRefs() { + return !deepenNotRefs.isEmpty(); } /** - * @param shallowExcludeRef reference in a "deepen not" line + * @param deepenNotRef reference in a "deepen not" line * @return the builder */ - Builder addShallowExcludeRefs(String shallowExcludeRef) { - this.shallowExcludeRefs.add(shallowExcludeRef); + Builder addDeepenNotRef(String deepenNotRef) { + this.deepenNotRefs.add(deepenNotRef); return this; } @@ -323,13 +335,22 @@ public final class FetchV2Request { return this; } + /** + * Mark that the "done" line has been received. + * + * @return the builder + */ + Builder setDoneReceived() { + this.doneReceived = true; + return this; + } /** * @return Initialized fetch request */ FetchV2Request build() { return new FetchV2Request(peerHas, wantedRefs, wantsIds, - clientShallowCommits, shallowSince, shallowExcludeRefs, - depth, filterBlobLimit, options); + clientShallowCommits, shallowSince, deepenNotRefs, + depth, filterBlobLimit, doneReceived, options); } } } 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 03fc57cba..41883c98a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -311,7 +311,7 @@ public class UploadPack { * not to send using --shallow-exclude. Cannot be non-empty if depth is * nonzero. */ - private List shallowExcludeRefs = new ArrayList<>(); + private List deepenNotRefs = new ArrayList<>(); /** Commit time of the oldest common commit, in seconds. */ private int oldestTime; @@ -963,7 +963,6 @@ public class UploadPack { } String line; - boolean doneReceived = false; // Currently, we do not support any capabilities, so the next // line is DELIM. @@ -997,7 +996,7 @@ public class UploadPack { } else if (line.startsWith("have ")) { //$NON-NLS-1$ reqBuilder.addPeerHas(ObjectId.fromString(line.substring(5))); } else if (line.equals("done")) { //$NON-NLS-1$ - doneReceived = true; + reqBuilder.setDoneReceived(); } else if (line.equals(OPTION_THIN_PACK)) { reqBuilder.addOption(OPTION_THIN_PACK); } else if (line.equals(OPTION_NO_PROGRESS)) { @@ -1021,13 +1020,13 @@ public class UploadPack { throw new PackProtocolException( JGitText.get().deepenSinceWithDeepen); } - if (reqBuilder.hasShallowExcludeRefs()) { + if (reqBuilder.hasDeepenNotRefs()) { throw new PackProtocolException( JGitText.get().deepenNotWithDeepen); } reqBuilder.setDepth(parsedDepth); } else if (line.startsWith("deepen-not ")) { //$NON-NLS-1$ - reqBuilder.addShallowExcludeRefs(line.substring(11)); + reqBuilder.addDeepenNotRef(line.substring(11)); if (reqBuilder.getDepth() != 0) { throw new PackProtocolException( JGitText.get().deepenNotWithDeepen); @@ -1072,7 +1071,7 @@ public class UploadPack { depth = req.getDepth(); shallowSince = req.getShallowSince(); filterBlobLimit = req.getFilterBlobLimit(); - shallowExcludeRefs = req.getShallowExcludeRefs(); + deepenNotRefs = req.getDeepenNotRefs(); boolean sectionSent = false; @Nullable List shallowCommits = null; @@ -1082,14 +1081,14 @@ public class UploadPack { verifyClientShallow(req.getClientShallowCommits()); } if (req.getDepth() != 0 || req.getShallowSince() != 0 - || !req.getShallowExcludeRefs().isEmpty()) { + || !req.getDeepenNotRefs().isEmpty()) { shallowCommits = new ArrayList<>(); processShallow(shallowCommits, unshallowCommits, false); } if (!req.getClientShallowCommits().isEmpty()) walk.assumeShallow(req.getClientShallowCommits()); - if (doneReceived) { + if (req.wasDoneReceived()) { processHaveLines(req.getPeerHas(), ObjectId.zeroId(), new PacketLineOut(NullOutputStream.INSTANCE)); } else { @@ -1109,7 +1108,7 @@ public class UploadPack { sectionSent = true; } - if (doneReceived || okToGiveUp()) { + if (req.wasDoneReceived() || okToGiveUp()) { if (shallowCommits != null) { if (sectionSent) pckOut.writeDelim(); @@ -1252,7 +1251,7 @@ public class UploadPack { boolean writeToPckOut) throws IOException { if (options.contains(OPTION_DEEPEN_RELATIVE) || shallowSince != 0 || - !shallowExcludeRefs.isEmpty()) { + !deepenNotRefs.isEmpty()) { // TODO(jonathantanmy): Implement deepen-relative, deepen-since, // and deepen-not. throw new UnsupportedOperationException(); From 4e8feb96a3fdffdd64360ddf3632420a42470737 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 31 Aug 2018 13:03:29 -0700 Subject: [PATCH 07/16] FetchV2Request: Correct typo in parameter name There is an extra 'd' in deependNotRefs. Noticed during code review. Change-Id: I93d8d7951fe5c351b62e23bdf5bad0ebd631017d Signed-off-by: Jonathan Nieder --- .../src/org/eclipse/jgit/transport/FetchV2Request.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java index e633ca420..92e21bce2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java @@ -84,14 +84,14 @@ public final class FetchV2Request { private FetchV2Request(List peerHas, TreeMap wantedRefs, Set wantsIds, Set clientShallowCommits, int shallowSince, - List deependNotRefs, int depth, long filterBlobLimit, + List deepenNotRefs, int depth, long filterBlobLimit, boolean doneReceived, Set options) { this.peerHas = peerHas; this.wantedRefs = wantedRefs; this.wantsIds = wantsIds; this.clientShallowCommits = clientShallowCommits; this.shallowSince = shallowSince; - this.deepenNotRefs = deependNotRefs; + this.deepenNotRefs = deepenNotRefs; this.depth = depth; this.filterBlobLimit = filterBlobLimit; this.doneReceived = doneReceived; From 346bc34169e86121b71206374653891dc5bc4512 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Fri, 31 Aug 2018 13:07:45 -0700 Subject: [PATCH 08/16] FetchV2Request: Rename shallowSince to deepenSince This fetch parameter is called deepen-since in the protocol. Call it the same thing in the request object to make the code easier to reason about. This doesn't touch UploadPack#shallowSince, which is likely to be eliminated altogether in a later patch anyway. Change-Id: I8ef34bc7ad12fae3a9057ae951367cc024e1a1cb Suggested-by: Ivan Frade Signed-off-by: Jonathan Nieder --- .../jgit/transport/FetchV2Request.java | 24 +++++++++---------- .../eclipse/jgit/transport/UploadPack.java | 12 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java index 92e21bce2..853d96905 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchV2Request.java @@ -69,7 +69,7 @@ public final class FetchV2Request { private final Set clientShallowCommits; - private final int shallowSince; + private final int deepenSince; private final List deepenNotRefs; @@ -83,14 +83,14 @@ public final class FetchV2Request { private FetchV2Request(List peerHas, TreeMap wantedRefs, Set wantsIds, - Set clientShallowCommits, int shallowSince, + Set clientShallowCommits, int deepenSince, List deepenNotRefs, int depth, long filterBlobLimit, boolean doneReceived, Set options) { this.peerHas = peerHas; this.wantedRefs = wantedRefs; this.wantsIds = wantsIds; this.clientShallowCommits = clientShallowCommits; - this.shallowSince = shallowSince; + this.deepenSince = deepenSince; this.deepenNotRefs = deepenNotRefs; this.depth = depth; this.filterBlobLimit = filterBlobLimit; @@ -141,8 +141,8 @@ public final class FetchV2Request { * @return timestamp in seconds since the epoch, where to stop the shallow * fetch/clone. Defaults to 0 if not set in the request. */ - int getShallowSince() { - return shallowSince; + int getDeepenSince() { + return deepenSince; } /** @@ -210,7 +210,7 @@ public final class FetchV2Request { int depth; - int shallowSince; + int deepenSince; long filterBlobLimit = -1; @@ -309,11 +309,11 @@ public final class FetchV2Request { /** * @param value - * shallow since value received in a "deepen since" line + * Unix timestamp received in a "deepen since" line * @return the builder */ - Builder setShallowSince(int value) { - this.shallowSince = value; + Builder setDeepenSince(int value) { + this.deepenSince = value; return this; } @@ -321,8 +321,8 @@ public final class FetchV2Request { * @return shallow since value, sent before in a "deepen since" line. 0 * by default. */ - int getShallowSince() { - return this.shallowSince; + int getDeepenSince() { + return this.deepenSince; } /** @@ -349,7 +349,7 @@ public final class FetchV2Request { */ FetchV2Request build() { return new FetchV2Request(peerHas, wantedRefs, wantsIds, - clientShallowCommits, shallowSince, deepenNotRefs, + clientShallowCommits, deepenSince, deepenNotRefs, depth, filterBlobLimit, doneReceived, options); } } 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 41883c98a..b1d7e5447 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -1016,7 +1016,7 @@ public class UploadPack { MessageFormat.format(JGitText.get().invalidDepth, Integer.valueOf(parsedDepth))); } - if (reqBuilder.getShallowSince() != 0) { + if (reqBuilder.getDeepenSince() != 0) { throw new PackProtocolException( JGitText.get().deepenSinceWithDeepen); } @@ -1034,8 +1034,8 @@ public class UploadPack { } else if (line.equals(OPTION_DEEPEN_RELATIVE)) { reqBuilder.addOption(OPTION_DEEPEN_RELATIVE); } else if (line.startsWith("deepen-since ")) { //$NON-NLS-1$ - int parsedShallowSince = Integer.parseInt(line.substring(13)); - if (parsedShallowSince <= 0) { + int ts = Integer.parseInt(line.substring(13)); + if (ts <= 0) { throw new PackProtocolException( MessageFormat.format( JGitText.get().invalidTimestamp, line)); @@ -1044,7 +1044,7 @@ public class UploadPack { throw new PackProtocolException( JGitText.get().deepenSinceWithDeepen); } - reqBuilder.setShallowSince(parsedShallowSince); + reqBuilder.setDeepenSince(ts); } else if (transferConfig.isAllowFilter() && line.startsWith(OPTION_FILTER + ' ')) { if (filterReceived) { @@ -1069,7 +1069,7 @@ public class UploadPack { wantIds.addAll(req.getWantsIds()); clientShallowCommits = req.getClientShallowCommits(); depth = req.getDepth(); - shallowSince = req.getShallowSince(); + shallowSince = req.getDeepenSince(); filterBlobLimit = req.getFilterBlobLimit(); deepenNotRefs = req.getDeepenNotRefs(); @@ -1080,7 +1080,7 @@ public class UploadPack { if (!req.getClientShallowCommits().isEmpty()) { verifyClientShallow(req.getClientShallowCommits()); } - if (req.getDepth() != 0 || req.getShallowSince() != 0 + if (req.getDepth() != 0 || req.getDeepenSince() != 0 || !req.getDeepenNotRefs().isEmpty()) { shallowCommits = new ArrayList<>(); processShallow(shallowCommits, unshallowCommits, false); From a8c38bc767778f718b24cca4a97b624c16278fb8 Mon Sep 17 00:00:00 2001 From: Ivan Frade Date: Mon, 27 Aug 2018 11:00:41 -0700 Subject: [PATCH 09/16] Extract protocol v2 fetch request parsing to its own class The parsing code for protocol v2 fetch doesn't have any dependency on the rest of UploadPack. Move it to its own class. This makes testing easier (no need to instantiate the full UploadPack), simplifies the code in UploadPack and increases modularity. At the moment, the parser needs to know about the reference database to validate incoming references. This dependency could be easily removed moving the validation later in the flow, after the parsing, where other validations are already happening. Postponing that to keep this patch about moving unmodified code around. Change-Id: I7ad29a6b99caa7c12c06f5a7f30ab6a5f6e44dc7 Signed-off-by: Ivan Frade --- .../jgit/transport/ProtocolV2ParserTest.java | 336 ++++++++++++++++++ .../jgit/transport/ProtocolV2Parser.java | 244 +++++++++++++ .../eclipse/jgit/transport/UploadPack.java | 142 +------- 3 files changed, 585 insertions(+), 137 deletions(-) create mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java create mode 100644 org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java new file mode 100644 index 000000000..4d1150844 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java @@ -0,0 +1,336 @@ +/* + * Copyright (C) 2018, Google LLC. + * 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 static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItems; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import org.eclipse.jgit.errors.PackProtocolException; +import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; +import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; +import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.revwalk.RevCommit; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class ProtocolV2ParserTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private TestRepository testRepo; + + @Before + public void setUp() throws Exception { + testRepo = new TestRepository<>(newRepo("protocol-v2-parser-test")); + } + + private static InMemoryRepository newRepo(String name) { + return new InMemoryRepository(new DfsRepositoryDescription(name)); + } + + private static class ConfigBuilder { + + private boolean allowRefInWant; + + private boolean allowFilter; + + private ConfigBuilder() { + } + + static ConfigBuilder start() { + return new ConfigBuilder(); + } + + static TransferConfig getDefault() { + return start().done(); + } + + ConfigBuilder allowRefInWant() { + allowRefInWant = true; + return this; + } + + ConfigBuilder allowFilter() { + allowFilter = true; + return this; + } + + TransferConfig done() { + Config rc = new Config(); + rc.setBoolean("uploadpack", null, "allowrefinwant", allowRefInWant); + rc.setBoolean("uploadpack", null, "allowfilter", allowFilter); + return new TransferConfig(rc); + } + } + + /* + * Convert the input lines to the PacketLine that the parser reads. + */ + private static PacketLineIn formatAsPacketLine(String... inputLines) + throws IOException { + ByteArrayOutputStream send = new ByteArrayOutputStream(); + PacketLineOut pckOut = new PacketLineOut(send); + for (String line : inputLines) { + if (line == PacketLineIn.END) { + pckOut.end(); + } else if (line == PacketLineIn.DELIM) { + pckOut.writeDelim(); + } else { + pckOut.writeString(line); + } + } + + return new PacketLineIn(new ByteArrayInputStream(send.toByteArray())); + } + + private static List objIdsAsStrings(Collection objIds) { + // TODO(ifrade) Translate this to a matcher, so it would read as + // assertThat(req.wantsIds(), hasObjectIds("...", "...")) + return objIds.stream().map(ObjectId::name).collect(Collectors.toList()); + } + + /* + * Succesful fetch with the basic core commands of the protocol. + */ + @Test + public void testFetchBasicArguments() + throws PackProtocolException, IOException { + PacketLineIn pckIn = formatAsPacketLine( + PacketLineIn.DELIM, + "thin-pack", "no-progress", "include-tag", "ofs-delta", + "want 4624442d68ee402a94364191085b77137618633e", + "want f900c8326a43303685c46b279b9f70411bff1a4b", + "have 554f6e41067b9e3e565b6988a8294fac1cb78f4b", + "have abc760ab9ad72f08209943251b36cb886a578f87", "done", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertTrue(request.getOptions() + .contains(GitProtocolConstants.OPTION_THIN_PACK)); + assertTrue(request.getOptions() + .contains(GitProtocolConstants.OPTION_NO_PROGRESS)); + assertTrue(request.getOptions() + .contains(GitProtocolConstants.OPTION_INCLUDE_TAG)); + assertTrue(request.getOptions() + .contains(GitProtocolConstants.CAPABILITY_OFS_DELTA)); + assertThat(objIdsAsStrings(request.getWantsIds()), + hasItems("4624442d68ee402a94364191085b77137618633e", + "f900c8326a43303685c46b279b9f70411bff1a4b")); + assertThat(objIdsAsStrings(request.getPeerHas()), + hasItems("554f6e41067b9e3e565b6988a8294fac1cb78f4b", + "abc760ab9ad72f08209943251b36cb886a578f87")); + assertTrue(request.getWantedRefs().isEmpty()); + assertTrue(request.wasDoneReceived()); + } + + @Test + public void testFetchWithShallow_deepen() throws IOException { + PacketLineIn pckIn = formatAsPacketLine( + PacketLineIn.DELIM, + "deepen 15", + "deepen-relative", + "shallow 28274d02c489f4c7e68153056e9061a46f62d7a0", + "shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertThat(objIdsAsStrings(request.getClientShallowCommits()), + hasItems("28274d02c489f4c7e68153056e9061a46f62d7a0", + "145e683b229dcab9d0e2ccb01b386f9ecc17d29d")); + assertTrue(request.getDeepenNotRefs().isEmpty()); + assertEquals(15, request.getDepth()); + assertTrue(request.getOptions() + .contains(GitProtocolConstants.OPTION_DEEPEN_RELATIVE)); + } + + @Test + public void testFetchWithShallow_deepenNot() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "shallow 28274d02c489f4c7e68153056e9061a46f62d7a0", + "shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d", + "deepen-not a08595f76159b09d57553e37a5123f1091bb13e7", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertThat(objIdsAsStrings(request.getClientShallowCommits()), + hasItems("28274d02c489f4c7e68153056e9061a46f62d7a0", + "145e683b229dcab9d0e2ccb01b386f9ecc17d29d")); + assertThat(request.getDeepenNotRefs(), + hasItems("a08595f76159b09d57553e37a5123f1091bb13e7")); + } + + @Test + public void testFetchWithShallow_deepenSince() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "shallow 28274d02c489f4c7e68153056e9061a46f62d7a0", + "shallow 145e683b229dcab9d0e2ccb01b386f9ecc17d29d", + "deepen-since 123123123", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertThat(objIdsAsStrings(request.getClientShallowCommits()), + hasItems("28274d02c489f4c7e68153056e9061a46f62d7a0", + "145e683b229dcab9d0e2ccb01b386f9ecc17d29d")); + assertEquals(123123123, request.getDeepenSince()); + } + + @Test + public void testFetchWithNoneFilter() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "filter blob:none", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.start().allowFilter().done()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertEquals(0, request.getFilterBlobLimit()); + } + + @Test + public void testFetchWithBlobSizeFilter() throws IOException { + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "filter blob:limit=15", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.start().allowFilter().done()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertEquals(15, request.getFilterBlobLimit()); + } + + @Test + public void testFetchMustNotHaveMultipleFilters() throws IOException { + thrown.expect(PackProtocolException.class); + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "filter blob:none", + "filter blob:limit=12", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.start().allowFilter().done()); + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertEquals(0, request.getFilterBlobLimit()); + } + + @Test + public void testFetchFilterWithoutAllowFilter() throws IOException { + thrown.expect(PackProtocolException.class); + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "filter blob:limit=12", PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.getDefault()); + parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + } + + @Test + public void testFetchWithRefInWant() throws Exception { + RevCommit one = testRepo.commit().message("1").create(); + RevCommit two = testRepo.commit().message("2").create(); + testRepo.update("branchA", one); + testRepo.update("branchB", two); + + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "want e4980cdc48cfa1301493ca94eb70523f6788b819", + "want-ref refs/heads/branchA", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.start().allowRefInWant().done()); + + + FetchV2Request request = parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + assertEquals(1, request.getWantedRefs().size()); + assertThat(request.getWantedRefs().keySet(), + hasItems("refs/heads/branchA")); + assertEquals(2, request.getWantsIds().size()); + assertThat(objIdsAsStrings(request.getWantsIds()), + hasItems("e4980cdc48cfa1301493ca94eb70523f6788b819", + one.getName())); + } + + @Test + public void testFetchWithRefInWantUnknownRef() throws Exception { + thrown.expect(PackProtocolException.class); + thrown.expectMessage(containsString("refs/heads/branchC")); + + PacketLineIn pckIn = formatAsPacketLine(PacketLineIn.DELIM, + "want e4980cdc48cfa1301493ca94eb70523f6788b819", + "want-ref refs/heads/branchC", + PacketLineIn.END); + ProtocolV2Parser parser = new ProtocolV2Parser( + ConfigBuilder.start().allowRefInWant().done()); + + RevCommit one = testRepo.commit().message("1").create(); + RevCommit two = testRepo.commit().message("2").create(); + testRepo.update("branchA", one); + testRepo.update("branchB", two); + + parser.parseFetchRequest(pckIn, + testRepo.getRepository().getRefDatabase()); + } + +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java new file mode 100644 index 000000000..eae2c6edb --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2018, Google LLC. + * 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 static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_DEEPEN_RELATIVE; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_FILTER; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_INCLUDE_TAG; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_NO_PROGRESS; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_OFS_DELTA; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SIDE_BAND_64K; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_THIN_PACK; +import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_WANT_REF; + +import java.io.IOException; +import java.text.MessageFormat; + +import org.eclipse.jgit.errors.PackProtocolException; +import org.eclipse.jgit.internal.JGitText; +import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.lib.RefDatabase; + +/** + * Parse the incoming git protocol lines from the wire and translate them into a + * Request object. + * + * It requires a transferConfig object to know what the server supports (e.g. + * ref-in-want and/or filters). + */ +final class ProtocolV2Parser { + + private final TransferConfig transferConfig; + + ProtocolV2Parser(TransferConfig transferConfig) { + this.transferConfig = transferConfig; + } + + /** + * Parse the incoming fetch request arguments from the wire. The caller must + * be sure that what is comings is a fetch request before coming here. + * + * This operation requires the reference database to validate incoming + * references. + * + * @param pckIn + * incoming lines + * @param refdb + * reference database (to validate that received references exist + * and point to valid objects) + * @return A FetchV2Request populated with information received from the + * wire. + * @throws PackProtocolException + * incompatible options, wrong type of arguments or other issues + * where the request breaks the protocol. + * @throws IOException + * an IO error prevented reading the incoming message or + * accessing the ref database. + */ + FetchV2Request parseFetchRequest(PacketLineIn pckIn, RefDatabase refdb) + throws PackProtocolException, IOException { + FetchV2Request.Builder reqBuilder = FetchV2Request.builder(); + + // Packs are always sent multiplexed and using full 64K + // lengths. + reqBuilder.addOption(OPTION_SIDE_BAND_64K); + + String line; + + // Currently, we do not support any capabilities, so the next + // line is DELIM. + if ((line = pckIn.readString()) != PacketLineIn.DELIM) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + + boolean filterReceived = false; + while ((line = pckIn.readString()) != PacketLineIn.END) { + if (line.startsWith("want ")) { //$NON-NLS-1$ + reqBuilder.addWantsIds(ObjectId.fromString(line.substring(5))); + } else if (transferConfig.isAllowRefInWant() + && line.startsWith(OPTION_WANT_REF + " ")) { //$NON-NLS-1$ + String refName = line.substring(OPTION_WANT_REF.length() + 1); + // TODO(ifrade): This validation should be done after the + // protocol parsing. It is not a protocol problem asking for an + // unexisting ref and we wouldn't need the ref database here + Ref ref = refdb.exactRef(refName); + if (ref == null) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().invalidRefName, refName)); + } + ObjectId oid = ref.getObjectId(); + if (oid == null) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().invalidRefName, refName)); + } + reqBuilder.addWantedRef(refName, oid); + reqBuilder.addWantsIds(oid); + } else if (line.startsWith("have ")) { //$NON-NLS-1$ + reqBuilder.addPeerHas(ObjectId.fromString(line.substring(5))); + } else if (line.equals("done")) { //$NON-NLS-1$ + reqBuilder.setDoneReceived(); + } else if (line.equals(OPTION_THIN_PACK)) { + reqBuilder.addOption(OPTION_THIN_PACK); + } else if (line.equals(OPTION_NO_PROGRESS)) { + reqBuilder.addOption(OPTION_NO_PROGRESS); + } else if (line.equals(OPTION_INCLUDE_TAG)) { + reqBuilder.addOption(OPTION_INCLUDE_TAG); + } else if (line.equals(OPTION_OFS_DELTA)) { + reqBuilder.addOption(OPTION_OFS_DELTA); + } else if (line.startsWith("shallow ")) { //$NON-NLS-1$ + reqBuilder.addClientShallowCommit( + ObjectId.fromString(line.substring(8))); + } else if (line.startsWith("deepen ")) { //$NON-NLS-1$ + int parsedDepth = Integer.parseInt(line.substring(7)); + if (parsedDepth <= 0) { + throw new PackProtocolException( + MessageFormat.format(JGitText.get().invalidDepth, + Integer.valueOf(parsedDepth))); + } + if (reqBuilder.getDeepenSince() != 0) { + throw new PackProtocolException( + JGitText.get().deepenSinceWithDeepen); + } + if (reqBuilder.hasDeepenNotRefs()) { + throw new PackProtocolException( + JGitText.get().deepenNotWithDeepen); + } + reqBuilder.setDepth(parsedDepth); + } else if (line.startsWith("deepen-not ")) { //$NON-NLS-1$ + reqBuilder.addDeepenNotRef(line.substring(11)); + if (reqBuilder.getDepth() != 0) { + throw new PackProtocolException( + JGitText.get().deepenNotWithDeepen); + } + } else if (line.equals(OPTION_DEEPEN_RELATIVE)) { + reqBuilder.addOption(OPTION_DEEPEN_RELATIVE); + } else if (line.startsWith("deepen-since ")) { //$NON-NLS-1$ + int ts = Integer.parseInt(line.substring(13)); + if (ts <= 0) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().invalidTimestamp, line)); + } + if (reqBuilder.getDepth() != 0) { + throw new PackProtocolException( + JGitText.get().deepenSinceWithDeepen); + } + reqBuilder.setDeepenSince(ts); + } else if (transferConfig.isAllowFilter() + && line.startsWith(OPTION_FILTER + ' ')) { + if (filterReceived) { + throw new PackProtocolException( + JGitText.get().tooManyFilters); + } + filterReceived = true; + reqBuilder.setFilterBlobLimit(filterLine( + line.substring(OPTION_FILTER.length() + 1))); + } else { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + } + + return reqBuilder.build(); + } + + /** + * Process the content of "filter" line from the protocol. It has a shape + * like "blob:none" or "blob:limit=N", with limit a positive number. + * + * @param blobLine + * the content of the "filter" line in the protocol + * @return N, the limit, defaulting to 0 if "none" + * @throws PackProtocolException + * invalid filter because due to unrecognized format or + * negative/non-numeric filter. + */ + static long filterLine(String blobLine) throws PackProtocolException { + long blobLimit = -1; + + if (blobLine.equals("blob:none")) { //$NON-NLS-1$ + blobLimit = 0; + } else if (blobLine.startsWith("blob:limit=")) { //$NON-NLS-1$ + try { + blobLimit = Long + .parseLong(blobLine.substring("blob:limit=".length())); //$NON-NLS-1$ + } catch (NumberFormatException e) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().invalidFilter, blobLine)); + } + } + /* + * 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 (blobLimit < 0) { + throw new PackProtocolException( + MessageFormat.format(JGitText.get().invalidFilter, blobLine)); + } + + return blobLimit; + } + +} 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 b1d7e5447..cd7290edc 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -63,7 +63,6 @@ import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SHALLOW; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SIDE_BAND; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SIDE_BAND_64K; import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_THIN_PACK; -import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_WANT_REF; import java.io.ByteArrayOutputStream; import java.io.EOFException; @@ -944,12 +943,6 @@ public class UploadPack { } private void fetchV2() throws IOException { - FetchV2Request.Builder reqBuilder = FetchV2Request.builder(); - - // Packs are always sent multiplexed and using full 64K - // lengths. - reqBuilder.addOption(OPTION_SIDE_BAND_64K); - // Depending on the requestValidator, #processHaveLines may // require that advertised be set. Set it only in the required // circumstances (to avoid a full ref lookup in the case that @@ -962,105 +955,11 @@ public class UploadPack { advertised = refIdSet(getAdvertisedOrDefaultRefs().values()); } - String line; - - // Currently, we do not support any capabilities, so the next - // line is DELIM. - if ((line = pckIn.readString()) != PacketLineIn.DELIM) { - throw new PackProtocolException(MessageFormat - .format(JGitText.get().unexpectedPacketLine, line)); - } - - boolean includeTag = false; - boolean filterReceived = false; - while ((line = pckIn.readString()) != PacketLineIn.END) { - if (line.startsWith("want ")) { //$NON-NLS-1$ - reqBuilder.addWantsIds(ObjectId.fromString(line.substring(5))); - } else if (transferConfig.isAllowRefInWant() && - line.startsWith(OPTION_WANT_REF + " ")) { //$NON-NLS-1$ - String refName = line.substring(OPTION_WANT_REF.length() + 1); - Ref ref = db.getRefDatabase().exactRef(refName); - if (ref == null) { - throw new PackProtocolException( - MessageFormat.format(JGitText.get().invalidRefName, - refName)); - } - ObjectId oid = ref.getObjectId(); - if (oid == null) { - throw new PackProtocolException( - MessageFormat.format(JGitText.get().invalidRefName, - refName)); - } - reqBuilder.addWantedRef(refName, oid); - reqBuilder.addWantsIds(oid); - } else if (line.startsWith("have ")) { //$NON-NLS-1$ - reqBuilder.addPeerHas(ObjectId.fromString(line.substring(5))); - } else if (line.equals("done")) { //$NON-NLS-1$ - reqBuilder.setDoneReceived(); - } else if (line.equals(OPTION_THIN_PACK)) { - reqBuilder.addOption(OPTION_THIN_PACK); - } else if (line.equals(OPTION_NO_PROGRESS)) { - reqBuilder.addOption(OPTION_NO_PROGRESS); - } else if (line.equals(OPTION_INCLUDE_TAG)) { - reqBuilder.addOption(OPTION_INCLUDE_TAG); - includeTag = true; - } else if (line.equals(OPTION_OFS_DELTA)) { - reqBuilder.addOption(OPTION_OFS_DELTA); - } else if (line.startsWith("shallow ")) { //$NON-NLS-1$ - reqBuilder.addClientShallowCommit( - ObjectId.fromString(line.substring(8))); - } else if (line.startsWith("deepen ")) { //$NON-NLS-1$ - int parsedDepth = Integer.parseInt(line.substring(7)); - if (parsedDepth <= 0) { - throw new PackProtocolException( - MessageFormat.format(JGitText.get().invalidDepth, - Integer.valueOf(parsedDepth))); - } - if (reqBuilder.getDeepenSince() != 0) { - throw new PackProtocolException( - JGitText.get().deepenSinceWithDeepen); - } - if (reqBuilder.hasDeepenNotRefs()) { - throw new PackProtocolException( - JGitText.get().deepenNotWithDeepen); - } - reqBuilder.setDepth(parsedDepth); - } else if (line.startsWith("deepen-not ")) { //$NON-NLS-1$ - reqBuilder.addDeepenNotRef(line.substring(11)); - if (reqBuilder.getDepth() != 0) { - throw new PackProtocolException( - JGitText.get().deepenNotWithDeepen); - } - } else if (line.equals(OPTION_DEEPEN_RELATIVE)) { - reqBuilder.addOption(OPTION_DEEPEN_RELATIVE); - } else if (line.startsWith("deepen-since ")) { //$NON-NLS-1$ - int ts = Integer.parseInt(line.substring(13)); - if (ts <= 0) { - throw new PackProtocolException( - MessageFormat.format( - JGitText.get().invalidTimestamp, line)); - } - if (reqBuilder.getDepth() != 0) { - throw new PackProtocolException( - JGitText.get().deepenSinceWithDeepen); - } - reqBuilder.setDeepenSince(ts); - } else if (transferConfig.isAllowFilter() - && line.startsWith(OPTION_FILTER + ' ')) { - if (filterReceived) { - throw new PackProtocolException(JGitText.get().tooManyFilters); - } - filterReceived = true; - reqBuilder.setFilterBlobLimit(parseFilter( - line.substring(OPTION_FILTER.length() + 1))); - } else { - throw new PackProtocolException(MessageFormat - .format(JGitText.get().unexpectedPacketLine, line)); - } - } + ProtocolV2Parser parser = new ProtocolV2Parser(transferConfig); + FetchV2Request req = parser.parseFetchRequest(pckIn, + db.getRefDatabase()); rawOut.stopBuffering(); - FetchV2Request req = reqBuilder.build(); protocolV2Hook.onFetch(req); // TODO(ifrade): Refactor to pass around the Request object, instead of @@ -1139,7 +1038,7 @@ public class UploadPack { pckOut.writeDelim(); pckOut.writeString("packfile\n"); //$NON-NLS-1$ sendPack(new PackStatistics.Accumulator(), - includeTag + req.getOptions().contains(OPTION_INCLUDE_TAG) ? db.getRefDatabase().getRefsByPrefix(R_TAGS) : null, unshallowCommits); @@ -1459,37 +1358,6 @@ public class UploadPack { return msgOut; } - private long parseFilter(String arg) throws PackProtocolException { - long blobLimit = -1; - - if (arg.equals("blob:none")) { //$NON-NLS-1$ - blobLimit = 0; - } else if (arg.startsWith("blob:limit=")) { //$NON-NLS-1$ - try { - blobLimit = 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 (blobLimit < 0) { - throw new PackProtocolException( - MessageFormat.format(JGitText.get().invalidFilter, - arg)); - } - - return blobLimit; - } - private void recvWants() throws IOException { boolean isFirst = true; boolean filterReceived = false; @@ -1530,7 +1398,7 @@ public class UploadPack { } filterReceived = true; - filterBlobLimit = parseFilter(arg); + filterBlobLimit = ProtocolV2Parser.filterLine(arg); continue; } From c398fb2b6b5be13251a74ba36b5fd5a9ef360a1a Mon Sep 17 00:00:00 2001 From: Minh Thai Date: Fri, 31 Aug 2018 15:54:39 -0700 Subject: [PATCH 10/16] Replace useminimalnegotation flag with maxhaves flag Client will stop sending haves when the number of haves sent reaches maxhaves. Change-Id: I1e5b1525be4c67f20a81ca24a2770c20eb5c1271 Signed-off-by: Minh Thai --- .../jgit/transport/TestProtocolTest.java | 22 ++------ .../transport/BasePackFetchConnection.java | 53 ++++--------------- 2 files changed, 15 insertions(+), 60 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java index 86c92bb52..953c9fc30 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TestProtocolTest.java @@ -77,6 +77,7 @@ public class TestProtocolTest { "+refs/heads/master:refs/heads/master"); private static final int HAVES_PER_ROUND = 32; + private static final int MAX_HAVES = 256; private static class User { private final String name; @@ -187,7 +188,7 @@ public class TestProtocolTest { } @Test - public void testMinimalNegotiation() throws Exception { + public void testMaxHaves() throws Exception { TestProtocol proto = registerDefault(); URIish uri = proto.register(new User("user"), remote.getRepository()); @@ -200,28 +201,13 @@ public class TestProtocolTest { RevCommit master = remote.branch("master").commit() .add("readme.txt", "unique commit").create(); - TestProtocol.setFetchConfig(new FetchConfig(true, true)); + TestProtocol.setFetchConfig(new FetchConfig(true, MAX_HAVES)); try (Git git = new Git(local.getRepository())) { assertNull(local.getRepository().exactRef("refs/heads/master")); git.fetch().setRemote(uri.toString()).setRefSpecs(MASTER).call(); assertEquals(master, local.getRepository() .exactRef("refs/heads/master").getObjectId()); - assertTrue(havesCount <= 2 * HAVES_PER_ROUND); - - // Update the remote master and add local branches for 5 more rounds - // of negotiation, where the local branch commits have newer - // timestamps. Negotiation should send 5 rounds for those newer - // branches before getting to the round that sends its stale version - // of master. - master = remote.branch("master").commit().parent(master).create(); - local.tick(2 * HAVES_PER_ROUND); - for (int i = 0; i < 5 * HAVES_PER_ROUND; i++) { - local.branch("local-" + i).commit().create(); - } - git.fetch().setRemote(uri.toString()).setRefSpecs(MASTER).call(); - assertEquals(master, local.getRepository() - .exactRef("refs/heads/master").getObjectId()); - assertEquals(6 * HAVES_PER_ROUND, havesCount); + assertTrue(havesCount <= MAX_HAVES); } } 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 0dfcd8716..ed7465c82 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackFetchConnection.java @@ -52,7 +52,6 @@ import java.text.MessageFormat; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.Set; import org.eclipse.jgit.errors.PackProtocolException; @@ -235,12 +234,12 @@ public abstract class BasePackFetchConnection extends BasePackConnection private boolean noProgress; - private Set minimalNegotiationSet; - private String lockMessage; private PackLock packLock; + private int maxHaves; + /** RPC state, if {@link BasePackConnection#statelessRPC} is true. */ private TemporaryBuffer.Heap state; @@ -261,12 +260,12 @@ public abstract class BasePackFetchConnection extends BasePackConnection if (local != null) { final FetchConfig cfg = getFetchConfig(); allowOfsDelta = cfg.allowOfsDelta; - if (cfg.minimalNegotiation) { - minimalNegotiationSet = new HashSet<>(); - } + maxHaves = cfg.maxHaves; } else { allowOfsDelta = true; + maxHaves = Integer.MAX_VALUE; } + includeTags = transport.getTagOpt() != TagOpt.NO_TAGS; thinPack = transport.isFetchThin(); filterBlobLimit = transport.getFilterBlobLimit(); @@ -294,17 +293,16 @@ public abstract class BasePackFetchConnection extends BasePackConnection static class FetchConfig { final boolean allowOfsDelta; - final boolean minimalNegotiation; + final int maxHaves; FetchConfig(Config c) { allowOfsDelta = c.getBoolean("repack", "usedeltabaseoffset", true); //$NON-NLS-1$ //$NON-NLS-2$ - minimalNegotiation = c.getBoolean("fetch", "useminimalnegotiation", //$NON-NLS-1$ //$NON-NLS-2$ - false); + maxHaves = c.getInt("fetch", "maxhaves", Integer.MAX_VALUE); //$NON-NLS-1$ //$NON-NLS-2$ } - FetchConfig(boolean allowOfsDelta, boolean minimalNegotiation) { + FetchConfig(boolean allowOfsDelta, int maxHaves) { this.allowOfsDelta = allowOfsDelta; - this.minimalNegotiation = minimalNegotiation; + this.maxHaves = maxHaves; } } @@ -518,15 +516,6 @@ public abstract class BasePackFetchConnection extends BasePackConnection } line.append('\n'); p.writeString(line.toString()); - if (minimalNegotiationSet != null) { - Ref current = local.exactRef(r.getName()); - if (current != null) { - ObjectId o = current.getObjectId(); - if (o != null && !o.equals(ObjectId.zeroId())) { - minimalNegotiationSet.add(o); - } - } - } } if (first) { return false; @@ -610,9 +599,6 @@ public abstract class BasePackFetchConnection extends BasePackConnection pckOut.writeString("have " + o.name() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ havesSent++; havesSinceLastContinue++; - if (minimalNegotiationSet != null) { - minimalNegotiationSet.remove(o); - } if ((31 & havesSent) != 0) { // We group the have lines into blocks of 32, each marked @@ -646,16 +632,6 @@ public abstract class BasePackFetchConnection extends BasePackConnection // pack on the remote side. Keep doing that. // resultsPending--; - if (minimalNegotiationSet != null - && minimalNegotiationSet.isEmpty()) { - // Minimal negotiation was requested and we sent out our - // current reference values for our wants, so terminate - // negotiation early. - if (statelessRPC) { - state.writeTo(out, null); - } - break SEND_HAVES; - } break READ_RESULT; case ACK: @@ -686,14 +662,6 @@ public abstract class BasePackFetchConnection extends BasePackConnection if (anr == AckNackResult.ACK_READY) { receivedReady = true; } - if (minimalNegotiationSet != null && minimalNegotiationSet.isEmpty()) { - // Minimal negotiation was requested and we sent out our current reference - // values for our wants, so terminate negotiation early. - if (statelessRPC) { - state.writeTo(out, null); - } - break SEND_HAVES; - } break; } @@ -709,7 +677,8 @@ public abstract class BasePackFetchConnection extends BasePackConnection state.writeTo(out, null); } - if (receivedContinue && havesSinceLastContinue > MAX_HAVES) { + if (receivedContinue && havesSinceLastContinue > MAX_HAVES + || havesSent >= maxHaves) { // Our history must be really different from the remote's. // We just sent a whole slew of have lines, and it did not // recognize any of them. Avoid sending our entire history From c9e4359c7c87f3a5245bb7a6394192c7a2dea3b2 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sat, 1 Sep 2018 08:22:52 +0200 Subject: [PATCH 11/16] Update Orbit to S20180829155938 for 2018-09 RC1 Change-Id: I48d5a2e06e2833c9745cb71c53600da3ed5f8501 Signed-off-by: Matthias Sohn --- .../org.eclipse.jgit.target/jgit-4.5.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.5.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.6.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.6.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.7.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.7.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.8.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.8.tpd | 2 +- .../org.eclipse.jgit.target/jgit-4.9-staging.target | 4 ++-- .../org.eclipse.jgit.target/jgit-4.9-staging.tpd | 2 +- ...20180820175350-2018-09.tpd => S20180829155938-2018-09.tpd} | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) rename org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/{S20180820175350-2018-09.tpd => S20180829155938-2018-09.tpd} (97%) diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.target index ef21d0469..2c576f539 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.target @@ -1,7 +1,7 @@ - + @@ -66,7 +66,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.tpd index 61cd228d0..1d6ca642c 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.5.tpd @@ -1,7 +1,7 @@ target "jgit-4.5" with source configurePhase include "projects/jetty-9.4.11.tpd" -include "orbit/S20180820175350-2018-09.tpd" +include "orbit/S20180829155938-2018-09.tpd" location "http://download.eclipse.org/releases/mars/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target index 1fdf88252..23850c201 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.target @@ -1,7 +1,7 @@ - + @@ -66,7 +66,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd index 4968e4164..4a6c50f4e 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.6.tpd @@ -1,7 +1,7 @@ target "jgit-4.6" with source configurePhase include "projects/jetty-9.4.11.tpd" -include "orbit/S20180820175350-2018-09.tpd" +include "orbit/S20180829155938-2018-09.tpd" location "http://download.eclipse.org/releases/neon/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target index c5b257bb9..b0a7347c5 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.target @@ -1,7 +1,7 @@ - + @@ -66,7 +66,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd index a2fd37a2e..ca30ba57b 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.7.tpd @@ -1,7 +1,7 @@ target "jgit-4.7" with source configurePhase include "projects/jetty-9.4.11.tpd" -include "orbit/S20180820175350-2018-09.tpd" +include "orbit/S20180829155938-2018-09.tpd" location "http://download.eclipse.org/releases/oxygen/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target index ec1759baa..e55de8655 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.target @@ -1,7 +1,7 @@ - + @@ -66,7 +66,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd index a3be4b7db..7944d0232 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.8.tpd @@ -1,7 +1,7 @@ target "jgit-4.8" with source configurePhase include "projects/jetty-9.4.11.tpd" -include "orbit/S20180820175350-2018-09.tpd" +include "orbit/S20180829155938-2018-09.tpd" location "http://download.eclipse.org/releases/photon/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.target b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.target index 7e2b67524..916d8585b 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.target +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.target @@ -1,7 +1,7 @@ - + @@ -66,7 +66,7 @@ - + diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.tpd index eaaa00a30..05f0cd177 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/jgit-4.9-staging.tpd @@ -1,7 +1,7 @@ target "jgit-4.9-staging" with source configurePhase include "projects/jetty-9.4.11.tpd" -include "orbit/S20180820175350-2018-09.tpd" +include "orbit/S20180829155938-2018-09.tpd" location "http://download.eclipse.org/staging/2018-09/" { org.eclipse.osgi lazy diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20180820175350-2018-09.tpd b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20180829155938-2018-09.tpd similarity index 97% rename from org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20180820175350-2018-09.tpd rename to org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20180829155938-2018-09.tpd index 87c46fcee..efb4d8314 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20180820175350-2018-09.tpd +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/orbit/S20180829155938-2018-09.tpd @@ -1,7 +1,7 @@ -target "S20180820175350-2018-09" with source configurePhase +target "S20180829155938-2018-09" with source configurePhase // see http://download.eclipse.org/tools/orbit/downloads/ -location "http://download.eclipse.org/tools/orbit/downloads/drops/S20180820175350/repository" { +location "http://download.eclipse.org/tools/orbit/downloads/drops/S20180829155938/repository" { org.apache.ant [1.9.6.v201510161327,1.9.6.v201510161327] org.apache.ant.source [1.9.6.v201510161327,1.9.6.v201510161327] org.apache.commons.codec [1.10.0.v20180409-1845,1.10.0.v20180409-1845] From a3cb474c94cb8a75b6dfc13ad36cd855ae969852 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 29 Aug 2018 13:49:35 +0900 Subject: [PATCH 12/16] Specify charset when constructing InputStreamReader ErrorProne warns [1] about implicit use of the platform default charset, which can result in differing behaviour between JVM executions or incorrect behavior if the encoding of the data source doesn't match expectations. [1] http://errorprone.info/bugpattern/DefaultCharset Change-Id: I0fd489d352170339c3867355cd24324dfdbd4b59 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/lfs/LfsPrePushHook.java | 2 +- .../src/org/eclipse/jgit/lfs/SmudgeFilter.java | 3 ++- .../org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java | 2 +- .../tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java | 4 +++- .../tst/org/eclipse/jgit/transport/WalkEncryptionTest.java | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) 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 a20c1d96f..4da3a74f2 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 @@ -221,7 +221,7 @@ public class LfsPrePushHook extends PrePushHook { private void uploadContents(HttpConnection api, Map oid2ptr) throws IOException { try (JsonReader reader = new JsonReader( - new InputStreamReader(api.getInputStream()))) { + new InputStreamReader(api.getInputStream(), CHARSET))) { for (Protocol.ObjectInfo o : parseObjects(reader)) { if (o.actions == null) { continue; 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 6bff12f9c..6a758cfd4 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 @@ -179,7 +179,8 @@ public class SmudgeFilter extends FilterCommand { Integer.valueOf(responseCode))); } try (JsonReader reader = new JsonReader( - new InputStreamReader(lfsServerConn.getInputStream()))) { + new InputStreamReader(lfsServerConn.getInputStream(), + CHARSET))) { Protocol.Response resp = gson.fromJson(reader, Protocol.Response.class); for (Protocol.ObjectInfo o : resp.objects) { 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 26c11c7eb..2a99da0c1 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 @@ -170,7 +170,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase { private String readStream(InputStream stream) throws IOException { try (BufferedReader in = new BufferedReader( - new InputStreamReader(stream))) { + new InputStreamReader(stream, CHARSET))) { StringBuilder out = new StringBuilder(); String line; while ((line = in.readLine()) != null) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java index aaa08a9e3..974750df4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java @@ -42,6 +42,8 @@ */ package org.eclipse.jgit.merge; +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.assertTrue; @@ -881,7 +883,7 @@ public class CrissCrossMergeTest extends RepositoryTestCase { StringBuilder result = new StringBuilder(); ObjectReader or = r.newObjectReader(); try (BufferedReader br = new BufferedReader( - new InputStreamReader(or.open(blobId).openStream()))) { + new InputStreamReader(or.open(blobId).openStream(), CHARSET))) { String line; boolean first = true; while ((line = br.readLine()) != null) { 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 33e252973..97f392e63 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 @@ -420,7 +420,7 @@ public class WalkEncryptionTest { c.setConnectTimeout(500); c.setReadTimeout(500); try (BufferedReader reader = new BufferedReader( - new InputStreamReader(c.getInputStream()))) { + new InputStreamReader(c.getInputStream(), CHARSET))) { return reader.readLine(); } } catch (UnknownHostException | SocketTimeoutException e) { From 685f8c8dbe9e2f1e139a55970588f92d5482b3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scheibe?= Date: Mon, 3 Sep 2018 23:21:10 +0200 Subject: [PATCH 13/16] Simplify file creation in ResetCommandTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use existing test utility methods instead of nested PrintWriter usage. Change-Id: I324852c7971ae644fa499f377a31d1cf265c7fd9 Signed-off-by: René Scheibe --- .../eclipse/jgit/api/ResetCommandTest.java | 55 ++++++------------- 1 file changed, 17 insertions(+), 38 deletions(-) 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 e10a91c5d..2b97b307b 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013, Chris Aniszczyk + * Copyright (C) 2011-2018, Chris Aniszczyk * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -52,7 +52,6 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.api.errors.GitAPIException; @@ -94,45 +93,25 @@ public class ResetCommandTest extends RepositoryTestCase { git = new Git(db); initialCommit = git.commit().setMessage("initial commit").call(); + // create file + indexFile = writeTrashFile("a.txt", "content"); + // create nested file - File dir = new File(db.getWorkTree(), "dir"); - FileUtils.mkdir(dir); - File nestedFile = new File(dir, "b.txt"); - FileUtils.createNewFile(nestedFile); - - 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(); + writeTrashFile("dir/b.txt", "content"); + + // add files and commit them + git.add().addFilepattern("a.txt").addFilepattern("dir/b.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 files and add to index + writeTrashFile("a.txt", "new content"); + writeTrashFile("dir/b.txt", "new content"); + git.add().addFilepattern("a.txt").addFilepattern("dir/b.txt").call(); // create a file not added to the index - untrackedFile = new File(db.getWorkTree(), - "notAddedToIndex.txt"); - FileUtils.createNewFile(untrackedFile); - try (PrintWriter writer2 = new PrintWriter(untrackedFile)) { - writer2.print("content"); - } + untrackedFile = writeTrashFile("notAddedToIndex.txt", "content"); } @Test From 30c6c7542190c149e2aee792f992a312a5fc5793 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 4 Sep 2018 10:53:10 +0900 Subject: [PATCH 14/16] Deprecate Constants.CHARSET in favor of StandardCharsets.UTF_8 Change-Id: I3b748620f067582afef20f144feebe40d0332be2 Signed-off-by: David Pursehouse --- .../jgit/http/server/InfoRefsServlet.java | 3 +- .../http/test/SmartClientSmartServerTest.java | 4 +- .../org/eclipse/jgit/junit/JGitTestUtil.java | 6 +- .../junit/LocalDiskRepositoryTestCase.java | 4 +- .../jgit/junit/RepositoryTestCase.java | 4 +- .../eclipse/jgit/junit/TestRepository.java | 4 +- .../jgit/lfs/server/fs/LfsServerTest.java | 6 +- .../jgit/lfs/server/LfsProtocolServlet.java | 6 +- .../eclipse/jgit/lfs/server/s3/SignerV4.java | 8 +- .../jgit/lfs/test/LongObjectIdTestUtils.java | 4 +- .../jgit/lfs/lib/LongObjectIdTest.java | 6 +- .../src/org/eclipse/jgit/lfs/LfsPointer.java | 8 +- .../org/eclipse/jgit/lfs/LfsPrePushHook.java | 6 +- .../org/eclipse/jgit/lfs/SmudgeFilter.java | 6 +- .../tst/org/eclipse/jgit/pgm/ArchiveTest.java | 6 +- .../org/eclipse/jgit/pgm/CommandCatalog.java | 4 +- .../src/org/eclipse/jgit/pgm/Main.java | 4 +- .../jgit/pgm/debug/BenchmarkReftable.java | 4 +- .../jgit/pgm/debug/RebuildCommitGraph.java | 6 +- .../eclipse/jgit/pgm/debug/WriteReftable.java | 6 +- .../CGitVsJGitRandomIgnorePatternTest.java | 6 +- .../jgit/patch/EGitPatchHistoryTest.java | 4 +- .../jgit/api/EolStreamTypeUtilTest.java | 10 +- .../eclipse/jgit/api/NotesCommandTest.java | 4 +- .../org/eclipse/jgit/api/PullCommandTest.java | 6 +- .../jgit/api/PullCommandWithRebaseTest.java | 6 +- .../eclipse/jgit/api/RebaseCommandTest.java | 8 +- .../jgit/attributes/CGitAttributesTest.java | 6 +- .../jgit/diff/AbstractDiffTestCase.java | 4 +- .../org/eclipse/jgit/diff/RawTextTest.java | 24 ++-- .../jgit/diff/SimilarityIndexTest.java | 8 +- .../DirCacheCGitCompatabilityTest.java | 6 +- .../jgit/gitrepo/ManifestParserTest.java | 8 +- .../eclipse/jgit/gitrepo/RepoCommandTest.java | 16 +-- .../eclipse/jgit/ignore/CGitIgnoreTest.java | 6 +- .../eclipse/jgit/ignore/IgnoreNodeTest.java | 4 +- .../indexdiff/IndexDiffWithSymlinkTest.java | 6 +- .../internal/storage/file/RefUpdateTest.java | 4 +- .../storage/file/T0003_BasicTest.java | 12 +- .../storage/file/WindowCacheGetTest.java | 3 +- .../jgit/junit/TestRepositoryTest.java | 4 +- .../eclipse/jgit/lib/ObjectCheckerTest.java | 10 +- .../jgit/merge/CrissCrossMergeTest.java | 4 +- .../org/eclipse/jgit/merge/MergerTest.java | 15 +-- .../org/eclipse/jgit/patch/GetTextTest.java | 6 +- .../jgit/revwalk/RevCommitParseTest.java | 106 +++++++++--------- .../eclipse/jgit/revwalk/RevTagParseTest.java | 102 ++++++++--------- .../storage/file/FileBasedConfigTest.java | 8 +- .../jgit/transport/BundleWriterTest.java | 5 +- .../org/eclipse/jgit/transport/NetRCTest.java | 4 +- .../jgit/transport/OpenSshConfigTest.java | 4 +- .../jgit/transport/WalkEncryptionTest.java | 10 +- .../treewalk/CanonicalTreeParserTest.java | 5 +- .../jgit/treewalk/FileTreeIteratorTest.java | 3 +- .../jgit/util/RawSubStringPatternTest.java | 4 +- .../jgit/util/io/AutoLFInputStreamTest.java | 4 +- .../org/eclipse/jgit/util/sha1/SHA1Test.java | 14 +-- .../jgit/attributes/AttributesNode.java | 6 +- .../eclipse/jgit/dircache/DirCacheEntry.java | 4 +- .../eclipse/jgit/dircache/DirCacheTree.java | 3 +- .../src/org/eclipse/jgit/hooks/GitHook.java | 6 +- .../org/eclipse/jgit/ignore/IgnoreNode.java | 6 +- .../internal/storage/dfs/DfsStreamKey.java | 4 +- .../jgit/internal/storage/file/GcLog.java | 4 +- .../storage/file/LazyObjectIdSetFile.java | 4 +- .../internal/storage/file/RefDirectory.java | 4 +- .../storage/reftable/BlockReader.java | 8 +- .../storage/reftable/BlockWriter.java | 12 +- .../reftable/ReftableOutputStream.java | 4 +- .../storage/reftable/ReftableReader.java | 8 +- .../org/eclipse/jgit/lib/BlobBasedConfig.java | 4 +- .../org/eclipse/jgit/lib/CommitBuilder.java | 8 +- .../src/org/eclipse/jgit/lib/Config.java | 4 +- .../src/org/eclipse/jgit/lib/Constants.java | 12 +- .../org/eclipse/jgit/lib/RebaseTodoFile.java | 6 +- .../src/org/eclipse/jgit/lib/TagBuilder.java | 4 +- .../eclipse/jgit/lib/TextProgressMonitor.java | 4 +- .../org/eclipse/jgit/patch/FileHeader.java | 18 +-- .../org/eclipse/jgit/patch/FormatError.java | 5 +- .../org/eclipse/jgit/revwalk/RevCommit.java | 4 +- .../src/org/eclipse/jgit/revwalk/RevTag.java | 6 +- .../jgit/storage/file/FileBasedConfig.java | 6 +- .../org/eclipse/jgit/transport/AmazonS3.java | 4 +- .../jgit/transport/BundleFetchConnection.java | 5 +- .../eclipse/jgit/transport/BundleWriter.java | 4 +- .../transport/HMACSHA1NonceGenerator.java | 4 +- .../jgit/transport/HttpAuthMethod.java | 10 +- .../eclipse/jgit/transport/PacketLineIn.java | 7 +- .../eclipse/jgit/transport/PacketLineOut.java | 4 +- .../jgit/transport/ProgressSpinner.java | 4 +- .../jgit/transport/PushCertificateIdent.java | 6 +- .../jgit/transport/PushCertificateStore.java | 7 +- .../eclipse/jgit/transport/RefAdvertiser.java | 4 +- .../jgit/transport/SideBandInputStream.java | 4 +- .../org/eclipse/jgit/transport/Transport.java | 4 +- .../eclipse/jgit/transport/TransportHttp.java | 5 +- .../transport/WalkRemoteObjectDatabase.java | 4 +- .../jgit/treewalk/AbstractTreeIterator.java | 4 +- .../org/eclipse/jgit/treewalk/TreeWalk.java | 8 +- .../jgit/treewalk/WorkingTreeIterator.java | 4 +- .../src/org/eclipse/jgit/util/Base64.java | 8 +- .../eclipse/jgit/util/FS_Win32_Cygwin.java | 4 +- .../src/org/eclipse/jgit/util/FileUtils.java | 4 +- .../org/eclipse/jgit/util/QuotedString.java | 8 +- .../eclipse/jgit/util/io/MessageWriter.java | 5 +- 105 files changed, 442 insertions(+), 397 deletions(-) diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java index 0f4633b5e..1a9d19245 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/InfoRefsServlet.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.http.server; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.http.server.ServletUtils.getRepository; import java.io.IOException; @@ -73,7 +74,7 @@ class InfoRefsServlet extends HttpServlet { final Repository db = getRepository(req); try (OutputStreamWriter out = new OutputStreamWriter( new SmartOutputStream(req, rsp, true), - Constants.CHARSET)) { + UTF_8)) { final RefAdvertiser adv = new RefAdvertiser() { @Override protected void writeOne(CharSequence line) 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 42db0fecd..51aa5f2ba 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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; @@ -1081,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(CHARSET)); + "testInvalidWant".getBytes(UTF_8)); Repository dst = createBareRepository(); try (Transport t = Transport.open(dst, remoteURI); 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 a102da1f4..b59b71499 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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), - CHARSET)) { + UTF_8)) { w.write(body); } } @@ -263,7 +263,7 @@ public abstract class JGitTestUtil { */ public static String read(File file) throws IOException { final byte[] body = IO.readFully(file); - return new String(body, 0, body.length, CHARSET); + return new String(body, 0, body.length, UTF_8); } /** 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 6cdd0eb23..12b216950 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(), CHARSET)); + Constants.OBJ_BLOB).getCachedBytes(), UTF_8)); } 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 e983e5dfb..95fe18b83 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import java.io.File; @@ -192,7 +192,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase { protected static void checkFile(File f, String checkData) throws IOException { try (Reader r = new InputStreamReader(new FileInputStream(f), - CHARSET)) { + UTF_8)) { if (checkData.length() > 0) { char[] data = new char[checkData.length()]; assertEquals(data.length, r.read(data)); 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 49715e559..c9fa2f506 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -268,7 +268,7 @@ public class TestRepository { * @throws Exception */ public RevBlob blob(String content) throws Exception { - return blob(content.getBytes(CHARSET)); + return blob(content.getBytes(UTF_8)); } /** 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 50a06f94d..10823b878 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import java.io.BufferedInputStream; @@ -211,11 +211,11 @@ public abstract class LfsServerTest { if (buf.hasArray()) { error = new String(buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), - CHARSET); + UTF_8); } else { final byte[] b = new byte[buf.remaining()]; buf.duplicate().get(b); - error = new String(b, CHARSET); + error = new String(b, UTF_8); } } catch (IOException e) { error = statusLine.getReasonPhrase(); 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 d22d45967..c7f55dd3c 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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; @@ -202,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(), CHARSET)); + new OutputStreamWriter(res.getOutputStream(), UTF_8)); Reader r = new BufferedReader( - new InputStreamReader(req.getInputStream(), CHARSET)); + new InputStreamReader(req.getInputStream(), UTF_8)); 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 374a56058..b21c94e4e 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + md.update(s.getBytes(UTF_8)); return md.digest(); } private static byte[] sign(String stringData, byte[] key) { try { - byte[] data = stringData.getBytes(CHARSET); + byte[] data = stringData.getBytes(UTF_8); 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, CHARSET.name()); + encoded = URLEncoder.encode(url, UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(LfsServerText.get().unsupportedUtf8, e); } 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 e3c6ef80b..c3c385946 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + md.update(s.getBytes(UTF_8)); return LongObjectId.fromRaw(md.digest()); } diff --git a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java index 8642e7eb3..92a8176f5 100644 --- a/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java +++ b/org.eclipse.jgit.lfs.test/tst/org/eclipse/jgit/lfs/lib/LongObjectIdTest.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.lfs.lib; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.US_ASCII; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -62,7 +63,6 @@ import java.util.Locale; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.lfs.errors.InvalidLongObjectIdException; import org.eclipse.jgit.lfs.test.LongObjectIdTestUtils; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.FileUtils; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -393,7 +393,7 @@ public class LongObjectIdTest { AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); ByteArrayOutputStream os = new ByteArrayOutputStream(64); try (OutputStreamWriter w = new OutputStreamWriter(os, - Constants.CHARSET)) { + UTF_8)) { id1.copyTo(w); } assertEquals(id1, LongObjectId.fromString(os.toByteArray(), 0)); @@ -404,7 +404,7 @@ public class LongObjectIdTest { AnyLongObjectId id1 = LongObjectIdTestUtils.hash("test"); ByteArrayOutputStream os = new ByteArrayOutputStream(64); try (OutputStreamWriter w = new OutputStreamWriter(os, - Constants.CHARSET)) { + UTF_8)) { char[] buf = new char[64]; id1.copyTo(buf, w); } 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 4f959409f..0e3830c09 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.BufferedReader; import java.io.IOException; @@ -134,7 +134,7 @@ public class LfsPointer implements Comparable { */ public void encode(OutputStream out) { try (PrintStream ps = new PrintStream(out, false, - CHARSET.name())) { + UTF_8.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 { ps.print(size + "\n"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { // should not happen, we are using a standard charset - throw new UnsupportedCharsetException(CHARSET.name()); + throw new UnsupportedCharsetException(UTF_8.name()); } } @@ -165,7 +165,7 @@ public class LfsPointer implements Comparable { long sz = -1; try (BufferedReader br = new BufferedReader( - new InputStreamReader(in, CHARSET))) { + new InputStreamReader(in, UTF_8))) { 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 4da3a74f2..3e6a26159 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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; @@ -208,7 +208,7 @@ public class LfsPrePushHook extends PrePushHook { } Gson gson = Protocol.gson(); api.getOutputStream().write( - gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(CHARSET)); + gson.toJson(toRequest(OPERATION_UPLOAD, res)).getBytes(UTF_8)); int responseCode = api.getResponseCode(); if (responseCode != HTTP_OK) { throw new IOException( @@ -221,7 +221,7 @@ public class LfsPrePushHook extends PrePushHook { private void uploadContents(HttpConnection api, Map oid2ptr) throws IOException { try (JsonReader reader = new JsonReader( - new InputStreamReader(api.getInputStream(), CHARSET))) { + new InputStreamReader(api.getInputStream(), UTF_8))) { for (Protocol.ObjectInfo o : parseObjects(reader)) { if (o.actions == null) { continue; 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 6a758cfd4..fac87c177 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,7 +42,7 @@ */ package org.eclipse.jgit.lfs; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.IOException; import java.io.InputStream; @@ -170,7 +170,7 @@ public class SmudgeFilter extends FilterCommand { .write(gson .toJson(LfsConnectionFactory .toRequest(Protocol.OPERATION_DOWNLOAD, res)) - .getBytes(CHARSET)); + .getBytes(UTF_8)); int responseCode = lfsServerConn.getResponseCode(); if (responseCode != HttpConnection.HTTP_OK) { throw new IOException( @@ -180,7 +180,7 @@ public class SmudgeFilter extends FilterCommand { } try (JsonReader reader = new JsonReader( new InputStreamReader(lfsServerConn.getInputStream(), - CHARSET))) { + UTF_8))) { Protocol.Response resp = gson.fromJson(reader, Protocol.Response.class); for (Protocol.ObjectInfo o : resp.objects) { 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 ecc00d37f..47eb156c5 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(), CHARSET)); + new InputStreamReader(proc.getInputStream(), UTF_8)); } private void grepForEntry(String name, String mode, String... cmdline) @@ -750,7 +750,7 @@ public class ArchiveTest extends CLIRepositoryTestCase { // found! List l = new ArrayList<>(); BufferedReader reader = new BufferedReader( - new InputStreamReader(in, CHARSET)); + new InputStreamReader(in, UTF_8)); String line; while ((line = reader.readLine()) != null) l.add(line); 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 2b0e5a717..dbdccc10e 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,7 +43,7 @@ package org.eclipse.jgit.pgm; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.BufferedReader; import java.io.IOException; @@ -148,7 +148,7 @@ public class CommandCatalog { private void scan(URL cUrl) { try (BufferedReader cIn = new BufferedReader( - new InputStreamReader(cUrl.openStream(), CHARSET))) { + new InputStreamReader(cUrl.openStream(), UTF_8))) { String line; while ((line = cIn.readLine()) != null) { if (line.length() > 0 && !line.startsWith("#")) //$NON-NLS-1$ 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 6fa92d3b0..5ed286baa 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.File; import java.io.IOException; @@ -227,7 +227,7 @@ public class Main { } PrintWriter createErrorWriter() { - return new PrintWriter(new OutputStreamWriter(System.err, CHARSET)); + return new PrintWriter(new OutputStreamWriter(System.err, UTF_8)); } private void execute(String[] argv) throws Exception { 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 575a12215..248eaac8a 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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 list = new RefList.Builder<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(lsRemotePath), CHARSET))) { + new FileInputStream(lsRemotePath), UTF_8))) { Ref last = null; String line; while ((line = br.readLine()) != null) { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index 2d16fefa7..8948c2753 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.pgm.debug; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -141,7 +143,7 @@ class RebuildCommitGraph extends TextBuiltin { try (RevWalk rw = new RevWalk(db); final BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(graph), - Constants.CHARSET))) { + UTF_8))) { String line; while ((line = br.readLine()) != null) { final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$ @@ -280,7 +282,7 @@ class RebuildCommitGraph extends TextBuiltin { try (RevWalk rw = new RevWalk(db); BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(refList), - Constants.CHARSET))) { + UTF_8))) { String line; while ((line = br.readLine()) != null) { final String[] parts = line.split("[ \t]{1,}"); //$NON-NLS-1$ 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 c5ea028be..6cbc1b082 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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 readRefs(String inputFile) throws IOException { List refs = new ArrayList<>(); try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(inputFile), CHARSET))) { + new InputStreamReader(new FileInputStream(inputFile), UTF_8))) { String line; while ((line = br.readLine()) != null) { ObjectId id = ObjectId.fromString(line.substring(0, 40)); @@ -227,7 +227,7 @@ class WriteReftable extends TextBuiltin { List log = new ArrayList<>(); try (BufferedReader br = new BufferedReader( - new InputStreamReader(new FileInputStream(logPath), CHARSET))) { + new InputStreamReader(new FileInputStream(logPath), UTF_8))) { @SuppressWarnings("nls") Pattern pattern = Pattern.compile("([^,]+)" // 1: ref + ",([0-9]+(?:[.][0-9]+)?)" // 2: time 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 4d9e86422..438d2d625 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET), StandardOpenOption.CREATE, + (pattern + "\n").getBytes(UTF_8), 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(CHARSET)); + out.write((path + "\n").getBytes(UTF_8)); out.flush(); } return proc; diff --git a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java index 79d8d0e10..f597f2fe3 100644 --- a/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java +++ b/org.eclipse.jgit.test/exttst/org/eclipse/jgit/patch/EGitPatchHistoryTest.java @@ -44,6 +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.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -56,7 +57,6 @@ import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.HashSet; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.RawParseUtils; import org.eclipse.jgit.util.TemporaryBuffer; @@ -176,7 +176,7 @@ public class EGitPatchHistoryTest { i.added = RawParseUtils.parseBase10(buf, ptr.value, ptr); i.deleted = RawParseUtils.parseBase10(buf, ptr.value + 1, ptr); final int eol = RawParseUtils.nextLF(buf, ptr.value); - final String name = RawParseUtils.decode(Constants.CHARSET, + final String name = RawParseUtils.decode(UTF_8, buf, ptr.value + 1, eol - 1); files.put(name, i); ptr.value = eol; 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 bb303cc41..1e3a39aad 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); - byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET); + byte[] outputBytes = output.getBytes(UTF_8); + byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); // 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(CHARSET); - byte[] expectedConversionBytes = expectedConversion.getBytes(CHARSET); + byte[] inputBytes = input.getBytes(UTF_8); + byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); // 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/NotesCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/NotesCommandTest.java index e234aa339..6e06e9545 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(), - CHARSET); + UTF_8); 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 0b0e3bf3e..9461c4250 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + fos.write(string.getBytes(UTF_8)); } } @@ -606,7 +606,7 @@ public class PullCommandTest extends RepositoryTestCase { bos.write(buffer, 0, read); read = fis.read(buffer); } - String content = new String(bos.toByteArray(), CHARSET); + String content = new String(bos.toByteArray(), UTF_8); 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 b349c66ca..913b4ac43 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + fos.write(string.getBytes(UTF_8)); } } @@ -410,7 +410,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase { bos.write(buffer, 0, read); read = fis.read(buffer); } - String content = new String(bos.toByteArray(), CHARSET); + String content = new String(bos.toByteArray(), UTF_8); 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 621e061c7..4401bcedb 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; @@ -1468,7 +1468,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals("GIT_AUTHOR_DATE='@123456789 -0100'", lines[2]); PersonIdent parsedIdent = git.rebase().parseAuthor( - convertedAuthor.getBytes(CHARSET)); + convertedAuthor.getBytes(UTF_8)); assertEquals(ident.getName(), parsedIdent.getName()); assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); // this is rounded to the last second @@ -1485,7 +1485,7 @@ public class RebaseCommandTest extends RepositoryTestCase { assertEquals("GIT_AUTHOR_DATE='@123456789 +0930'", lines[2]); parsedIdent = git.rebase().parseAuthor( - convertedAuthor.getBytes(CHARSET)); + convertedAuthor.getBytes(UTF_8)); assertEquals(ident.getName(), parsedIdent.getName()); assertEquals(ident.getEmailAddress(), parsedIdent.getEmailAddress()); assertEquals(123456789000L, parsedIdent.getWhen().getTime()); @@ -2164,7 +2164,7 @@ public class RebaseCommandTest extends RepositoryTestCase { int count = 0; File todoFile = getTodoFile(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(todoFile), CHARSET))) { + new FileInputStream(todoFile), UTF_8))) { String line = br.readLine(); while (line != null) { int firstBlank = line.indexOf(' '); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java index 344d1af6a..b6615075c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.attributes; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -57,7 +58,6 @@ import java.util.Map; import java.util.Set; import org.eclipse.jgit.junit.RepositoryTestCase; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; @@ -127,14 +127,14 @@ public class CGitAttributesTest extends RepositoryTestCase { builder.directory(db.getWorkTree()); builder.environment().put("HOME", fs.userHome().getAbsolutePath()); ExecutionResult result = fs.execute(builder, new ByteArrayInputStream( - input.toString().getBytes(Constants.CHARSET))); + input.toString().getBytes(UTF_8))); String errorOut = toString(result.getStderr()); assertEquals("External git failed", "exit 0\n", "exit " + result.getRc() + '\n' + errorOut); LinkedHashMap map = new LinkedHashMap<>(); try (BufferedReader r = new BufferedReader(new InputStreamReader( new BufferedInputStream(result.getStdout().openInputStream()), - Constants.CHARSET))) { + UTF_8))) { r.lines().forEach(line -> { // Parse the line and add to result map int start = 0; 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 32f34213e..0f13a68b2 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + return new RawText(r.toString().getBytes(UTF_8)); } } 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 58a8b2d46..5885d9b7e 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -147,8 +147,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(CHARSET)); - RawText b = new RawText("p\na b \nR\n c d \n".getBytes(CHARSET)); + 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)); e = new Edit(0, 4, 0, 4); e = RawTextComparator.WS_IGNORE_ALL.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(2, 3, 2, 3), e); @@ -160,14 +160,14 @@ public class RawTextTest { RawText b; Edit e; - a = new RawText("R\n y\n".getBytes(CHARSET)); - b = new RawText("S\n\n y\n".getBytes(CHARSET)); + a = new RawText("R\n y\n".getBytes(UTF_8)); + b = new RawText("S\n\n y\n".getBytes(UTF_8)); 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(CHARSET)); - b = new RawText("R\n y\n".getBytes(CHARSET)); + a = new RawText("S\n\n y\n".getBytes(UTF_8)); + b = new RawText("R\n y\n".getBytes(UTF_8)); e = new Edit(0, 3, 0, 2); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(0, 2, 0, 1), e); @@ -178,8 +178,8 @@ public class RawTextTest { RawText a; RawText b; Edit e; - a = new RawText("start".getBytes(CHARSET)); - b = new RawText("start of line".getBytes(CHARSET)); + a = new RawText("start".getBytes(UTF_8)); + b = new RawText("start of line".getBytes(UTF_8)); e = new Edit(0, 1, 0, 1); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(0, 1, 0, 1), e); @@ -190,8 +190,8 @@ public class RawTextTest { RawText a; RawText b; Edit e; - a = new RawText("start".getBytes(CHARSET)); - b = new RawText("start of\nlastline".getBytes(CHARSET)); + a = new RawText("start".getBytes(UTF_8)); + b = new RawText("start of\nlastline".getBytes(UTF_8)); e = new Edit(0, 1, 0, 2); e = RawTextComparator.DEFAULT.reduceCommonStartEnd(a, b, e); assertEquals(new Edit(0, 1, 0, 2), e); @@ -250,6 +250,6 @@ public class RawTextTest { r.append(text.charAt(i)); r.append('\n'); } - return new RawText(r.toString().getBytes(CHARSET)); + return new RawText(r.toString().getBytes(UTF_8)); } } 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 51a6f8121..f168e8328 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); + + "B\n").getBytes(UTF_8); 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(CHARSET); + byte[] bytes1 = text.getBytes(UTF_8); src.hash(new ByteArrayInputStream(bytes1), bytes1.length, true); src.sort(); SimilarityIndex dst = new SimilarityIndex(); - byte[] bytes2 = text.replace("\r", "").getBytes(CHARSET); + byte[] bytes2 = text.replace("\r", "").getBytes(UTF_8); 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 c362e7497..847d0abad 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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 readLsFiles() throws Exception { final LinkedHashMap r = new LinkedHashMap<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(pathOf("gitgit.lsfiles")), CHARSET))) { + new FileInputStream(pathOf("gitgit.lsfiles")), UTF_8))) { 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 readLsTree() throws Exception { final LinkedHashMap r = new LinkedHashMap<>(); try (BufferedReader br = new BufferedReader(new InputStreamReader( - new FileInputStream(pathOf("gitgit.lstree")), CHARSET))) { + new FileInputStream(pathOf("gitgit.lstree")), UTF_8))) { 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 024f05480..88a077630 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -85,7 +85,7 @@ public class ManifestParserTest { ManifestParser parser = new ManifestParser( null, null, "master", baseUrl, null, null); - parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(CHARSET))); + parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))); // Unfiltered projects should have them all. results.clear(); results.add("foo"); @@ -139,7 +139,7 @@ public class ManifestParserTest { baseUrl, null, null); try { parser.read(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))); + xmlContent.toString().getBytes(UTF_8))); fail("ManifestParser did not throw exception for missing fetch"); } catch (IOException e) { assertTrue(e.getCause() instanceof SAXException); @@ -164,7 +164,7 @@ public class ManifestParserTest { ManifestParser parser = new ManifestParser(null, null, "master", "https://git.google.com/", null, null); parser.read(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))); + xmlContent.toString().getBytes(UTF_8))); assertEquals(Stream.of("bar", "baz").collect(Collectors.toSet()), parser.getProjects().stream().map(RepoProject::getName) 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 1eca587bf..92f0cf619 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; @@ -217,7 +217,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = cmd .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(repos).setURI("platform/") .setTargetURI("platform/superproject") .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) @@ -226,7 +226,7 @@ public class RepoCommandTest extends RepositoryTestCase { String firstIdStr = commit.getId().name() + ":" + ".gitmodules"; commit = new RepoCommand(dest) .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(repos).setURI("platform/") .setTargetURI("platform/superproject") .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) @@ -254,7 +254,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = cmd .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(repos).setURI("platform/") .setTargetURI("platform/superproject") .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) @@ -288,7 +288,7 @@ public class RepoCommandTest extends RepositoryTestCase { try (Repository dest = cloneRepository(db, true)) { RevCommit commit = new RepoCommand(dest) .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(new IndexedRepos()).setURI("platform/") .setTargetURI("platform/superproject") .setRecordRemoteBranch(true).setIgnoreRemoteFailures(true) @@ -327,7 +327,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = cmd .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(repos).setURI("").setTargetURI("gerrit") .setRecordRemoteBranch(true).setRecordSubmoduleLabels(true) .call(); @@ -376,7 +376,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = cmd .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(repos).setURI(baseUrl) .setTargetURI("gerrit").setRecordRemoteBranch(true) .setRecordSubmoduleLabels(true).call(); @@ -431,7 +431,7 @@ public class RepoCommandTest extends RepositoryTestCase { RevCommit commit = cmd .setInputStream(new ByteArrayInputStream( - xmlContent.toString().getBytes(CHARSET))) + xmlContent.toString().getBytes(UTF_8))) .setRemoteReader(repos).setURI(baseUrl) .setTargetURI(abs + "/superproject") .setRecordRemoteBranch(true) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java index 0c6ed0c19..b4c20a7e4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.ignore; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -56,7 +57,6 @@ import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.jgit.junit.RepositoryTestCase; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.TreeWalk; @@ -113,7 +113,7 @@ public class CGitIgnoreTest extends RepositoryTestCase { "exit " + result.getRc() + '\n' + errorOut); try (BufferedReader r = new BufferedReader(new InputStreamReader( new BufferedInputStream(result.getStdout().openInputStream()), - Constants.CHARSET))) { + UTF_8))) { return r.lines().toArray(String[]::new); } } @@ -131,7 +131,7 @@ public class CGitIgnoreTest extends RepositoryTestCase { "exit " + result.getRc() + '\n' + errorOut); try (BufferedReader r = new BufferedReader(new InputStreamReader( new BufferedInputStream(result.getStdout().openInputStream()), - Constants.CHARSET))) { + UTF_8))) { return r.lines().toArray(String[]::new); } } 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 78d9a82c2..cbc076146 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -767,6 +767,6 @@ public class IgnoreNodeTest extends RepositoryTestCase { for (String line : rules) { data.append(line + "\n"); } - return new ByteArrayInputStream(data.toString().getBytes(CHARSET)); + return new ByteArrayInputStream(data.toString().getBytes(UTF_8)); } } 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 2a99da0c1..7e513d2c3 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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, CHARSET)) { + Writer writer = new OutputStreamWriter(out, UTF_8)) { writer.write("echo `which git` 1>&2\n"); writer.write("echo `git --version` 1>&2\n"); writer.write("git init " + name + " && \\\n"); @@ -170,7 +170,7 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase { private String readStream(InputStream stream) throws IOException { try (BufferedReader in = new BufferedReader( - new InputStreamReader(stream, CHARSET))) { + new InputStreamReader(stream, UTF_8))) { StringBuilder out = new StringBuilder(); String line; while ((line = in.readLine()) != null) { 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 e1adeedc5..3a4356418 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 @@ -46,7 +46,7 @@ package org.eclipse.jgit.internal.storage.file; import static org.eclipse.jgit.junit.Assert.assertEquals; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.LOCK_SUFFIX; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -263,7 +263,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { ObjectId blobId; try (ObjectInserter ins = bareRepo.newObjectInserter()) { - blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(CHARSET)); + blobId = ins.insert(Constants.OBJ_BLOB, "contents".getBytes(UTF_8)); 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 e113db12a..02073226d 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -368,7 +368,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase { + " email = A U Thor # Just an example...\n" + " name = \"A Thor \\\\ \\\"\\t \"\n" + " defaultCheckInComment = a many line\\ncomment\\n to test\n"; - assertEquals(expectedStr, new String(IO.readFully(cfg), Constants.CHARSET)); + assertEquals(expectedStr, new String(IO.readFully(cfg), UTF_8)); } @Test @@ -517,7 +517,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase { 4294967295000L, 60)); commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com", 4294967295000L, 60)); - commit.setEncoding(CHARSET); + commit.setEncoding(UTF_8); commit.setMessage("\u00dcbergeeks"); ObjectId cid = insertCommit(commit); assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name()); @@ -559,7 +559,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase { final ObjectId treeId; try (ObjectInserter oi = db.newObjectInserter()) { final ObjectId blobId = oi.insert(Constants.OBJ_BLOB, - "and this is the data in me\n".getBytes(Constants.CHARSET + "and this is the data in me\n".getBytes(UTF_8 .name())); TreeFormatter fmt = new TreeFormatter(); fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId); @@ -666,9 +666,9 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase { ObjectId id2; try (ObjectInserter ins = db.newObjectInserter()) { id1 = ins.insert( - Constants.OBJ_BLOB, "contents1".getBytes(Constants.CHARSET)); + Constants.OBJ_BLOB, "contents1".getBytes(UTF_8)); id2 = ins.insert( - Constants.OBJ_BLOB, "contents2".getBytes(Constants.CHARSET)); + Constants.OBJ_BLOB, "contents2".getBytes(UTF_8)); ins.flush(); } 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 82ad28ed2..01426eeb8 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 @@ -43,6 +43,7 @@ package org.eclipse.jgit.internal.storage.file; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -77,7 +78,7 @@ public class WindowCacheGetTest extends SampleDataRepositoryTestCase { try (BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(JGitTestUtil .getTestResourceFile("all_packed_objects.txt")), - Constants.CHARSET))) { + UTF_8))) { String line; while ((line = br.readLine()) != null) { final String[] parts = line.split(" {1,}"); 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 965899e7a..b7027f327 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(), CHARSET); + return new String(loader.getCachedBytes(), UTF_8); } } 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 b8e8a12d5..7ea504374 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); + byte[] data = b.toString().getBytes(UTF_8); 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(CHARSET); + byte[] data = b.toString().getBytes(UTF_8); 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(CHARSET); + byte[] data = b.toString().getBytes(UTF_8); 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(CHARSET)); + checker.checkTree(b.toString().getBytes(UTF_8)); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java index 974750df4..a67c750db 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CrissCrossMergeTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.merge; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -883,7 +883,7 @@ public class CrissCrossMergeTest extends RepositoryTestCase { StringBuilder result = new StringBuilder(); ObjectReader or = r.newObjectReader(); try (BufferedReader br = new BufferedReader( - new InputStreamReader(or.open(blobId).openStream(), CHARSET))) { + new InputStreamReader(or.open(blobId).openStream(), UTF_8))) { String line; boolean first = true; while ((line = br.readLine()) != null) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java index da4513d1f..8f12dd7b2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java @@ -42,7 +42,7 @@ */ package org.eclipse.jgit.merge; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -793,7 +793,7 @@ public class MergerTest extends RepositoryTestCase { } binary[50] = '\0'; - writeTrashFile("file", new String(binary, CHARSET)); + writeTrashFile("file", new String(binary, UTF_8)); git.add().addFilepattern("file").call(); RevCommit first = git.commit().setMessage("added file").call(); @@ -801,7 +801,7 @@ public class MergerTest extends RepositoryTestCase { int idx = LINELEN * 1200 + 1; byte save = binary[idx]; binary[idx] = '@'; - writeTrashFile("file", new String(binary, CHARSET)); + writeTrashFile("file", new String(binary, UTF_8)); binary[idx] = save; git.add().addFilepattern("file").call(); @@ -810,7 +810,7 @@ public class MergerTest extends RepositoryTestCase { git.checkout().setCreateBranch(true).setStartPoint(first).setName("side").call(); binary[LINELEN * 1500 + 1] = '!'; - writeTrashFile("file", new String(binary, CHARSET)); + writeTrashFile("file", new String(binary, UTF_8)); git.add().addFilepattern("file").call(); RevCommit sideCommit = git.commit().setAll(true) .setMessage("modified file l 1500").call(); @@ -972,7 +972,7 @@ public class MergerTest extends RepositoryTestCase { merger.getMergeResults().get("file"); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { fmt.formatMerge(out, merger.getMergeResults().get("file"), - "BASE", "OURS", "THEIRS", CHARSET.name()); + "BASE", "OURS", "THEIRS", UTF_8.name()); String expected = "<<<<<<< OURS\n" + "1master\n" + "=======\n" @@ -980,7 +980,7 @@ public class MergerTest extends RepositoryTestCase { + ">>>>>>> THEIRS\n" + "2\n" + "3"; - assertEquals(expected, new String(out.toByteArray(), CHARSET)); + assertEquals(expected, new String(out.toByteArray(), UTF_8)); } } } @@ -1367,6 +1367,7 @@ public class MergerTest extends RepositoryTestCase { if (obj == null) { return null; } - return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), CHARSET); + return new String(rw.getObjectReader().open(obj, OBJ_BLOB).getBytes(), + UTF_8); } } 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 7b5868a39..e383f36bc 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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 = CHARSET; + final Charset csNew = UTF_8; 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 = CHARSET; + final Charset csNew = UTF_8; final Patch p = parseTestPatchFile(); assertTrue(p.getErrors().isEmpty()); assertEquals(1, p.getFiles().size()); 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 cfefac3aa..d55fb4467 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + c.parseCanonical(rw, body.toString().getBytes(UTF_8)); 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(CHARSET)); + c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); 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(CHARSET)); + c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); 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(CHARSET)); + c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); assertEquals(new PersonIdent("", "a_u_thor@example.com", 1218123387000l, 7), c.getAuthorIdent()); assertEquals(new PersonIdent("", "", 1218123390000l, -5), c.getCommitterIdent()); @@ -185,18 +185,18 @@ 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(CHARSET)); - b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(CHARSET)); - b.write("committer C O. Miter 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)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); + b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(UTF_8)); + b.write("committer C O. Miter 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)); final RevCommit c; c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new RevWalk(db), b.toByteArray()); - assertSame(Constants.CHARSET, c.getEncoding()); + assertSame(UTF_8, c.getEncoding()); assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName()); assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); @@ -205,18 +205,18 @@ 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(CHARSET)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(ISO_8859_1)); - b.write("committer C O. Miter 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)); + b.write("committer C O. Miter 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)); final RevCommit c; c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new RevWalk(db), b.toByteArray()); - assertSame(Constants.CHARSET, c.getEncoding()); + assertSame(UTF_8, c.getEncoding()); assertEquals("F\u00f6r fattare", c.getAuthorIdent().getName()); assertEquals("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); assertEquals("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); @@ -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(CHARSET)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(ISO_8859_1)); - b.write("committer C O. Miter 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)); + b.write("committer C O. Miter 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)); 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(CHARSET)); - b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(CHARSET)); - b.write("committer C O. Miter 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)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); + b.write("author F\u00f6r fattare 1218123387 +0700\n".getBytes(UTF_8)); + b.write("committer C O. Miter 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)); 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(CHARSET)); - b.write("author au 1218123387 +0700\n".getBytes(CHARSET)); + .getBytes(UTF_8)); + b.write("author au 1218123387 +0700\n".getBytes(UTF_8)); b.write("committer co 1218123390 -0500\n" - .getBytes(CHARSET)); - b.write("encoding 'utf8'\n".getBytes(CHARSET)); - b.write("\n".getBytes(CHARSET)); - b.write("Sm\u00f6rg\u00e5sbord\n".getBytes(CHARSET)); + .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)); 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(CHARSET)); - b.write("author au 1218123387 +0700\n".getBytes(CHARSET)); - b.write("committer co 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)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); + b.write("author au 1218123387 +0700\n".getBytes(UTF_8)); + b.write("committer co 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)); 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(CHARSET)); - b.write("author au 1218123387 +0700\n".getBytes(CHARSET)); - b.write("committer co 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)); + b.write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes(UTF_8)); + b.write("author au 1218123387 +0700\n".getBytes(UTF_8)); + b.write("committer co 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)); 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 e11cef7c9..1b4547306 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + c.parseCanonical(rw, b.toString().getBytes(UTF_8)); 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(CHARSET)); + c.parseCanonical(rw, body.toString().getBytes(UTF_8)); 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(CHARSET)); + c.parseCanonical(rw, body.toString().getBytes(UTF_8)); 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(CHARSET)); + c.parseCanonical(new RevWalk(db), b.toString().getBytes(UTF_8)); 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(CHARSET)); - b.write("type tree\n".getBytes(CHARSET)); - b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); + .getBytes(UTF_8)); + b.write("type tree\n".getBytes(UTF_8)); + b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); b .write("tagger F\u00f6r fattare 1218123387 +0700\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)); + .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)); 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(CHARSET)); - b.write("type tree\n".getBytes(CHARSET)); - b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); + .getBytes(UTF_8)); + b.write("type tree\n".getBytes(UTF_8)); + b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); b.write("tagger F\u00f6r fattare 1218123387 +0700\n" .getBytes(ISO_8859_1)); - 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)); + 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)); 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(CHARSET)); - b.write("type tree\n".getBytes(CHARSET)); - b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); + .getBytes(UTF_8)); + b.write("type tree\n".getBytes(UTF_8)); + b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); b .write("tagger F\u00f6r fattare 1218123387 +0700\n" .getBytes(ISO_8859_1)); - 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)); + 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)); 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(CHARSET)); - b.write("type tree\n".getBytes(CHARSET)); - b.write("tag v1.2.3.4.5\n".getBytes(CHARSET)); + .getBytes(UTF_8)); + b.write("type tree\n".getBytes(UTF_8)); + b.write("tag v1.2.3.4.5\n".getBytes(UTF_8)); b .write("tagger F\u00f6r fattare 1218123387 +0700\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)); + .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)); 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(CHARSET)); - b.write("type tree\n".getBytes(CHARSET)); - b.write("tag v1.0\n".getBytes(CHARSET)); - b.write("tagger t 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)); + 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 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)); 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(CHARSET)); - b.write("type tree\n".getBytes(CHARSET)); - b.write("tag v1.0\n".getBytes(CHARSET)); - b.write("tagger t 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)); + 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 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)); 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 0dea5ce97..7f0d60295 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + final File file = createFile(CONTENT1.getBytes(UTF_8)); 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(CHARSET)); + bos1.write(CONTENT1.getBytes(UTF_8)); 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(CHARSET)); + bos2.write(CONTENT2.getBytes(UTF_8)); assertArrayEquals(bos2.toByteArray(), IO.readFully(file)); } 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 d30ac840a..7b31bfa3a 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -199,7 +199,8 @@ 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(), CHARSET)); + assertEquals(data, + new String(repo.open(id, OBJ_BLOB).getBytes(), UTF_8)); } } 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 4e5d56acb..2a4e492e3 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,7 +42,7 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; @@ -76,7 +76,7 @@ public class NetRCTest extends RepositoryTestCase { private void config(String data) throws IOException { try (OutputStreamWriter fw = new OutputStreamWriter( - new FileOutputStream(configFile), CHARSET)) { + new FileOutputStream(configFile), UTF_8)) { fw.write(data); } } 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 abf80ecd4..19fcbfd7a 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,7 +43,7 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -94,7 +94,7 @@ public class OpenSshConfigTest extends RepositoryTestCase { long lastMtime = configFile.lastModified(); do { try (final OutputStreamWriter fw = new OutputStreamWriter( - new FileOutputStream(configFile), CHARSET)) { + new FileOutputStream(configFile), UTF_8)) { fw.write(data); } } while (lastMtime == configFile.lastModified()); 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 97f392e63..f2fb0224e 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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()), CHARSET); + return new String(Files.readAllBytes(file.toPath()), UTF_8); } /** @@ -371,7 +371,7 @@ public class WalkEncryptionTest { * @throws Exception */ static void textWrite(File file, String text) throws Exception { - Files.write(file.toPath(), text.getBytes(CHARSET)); + Files.write(file.toPath(), text.getBytes(UTF_8)); } static void verifyFileContent(File fileOne, File fileTwo) @@ -420,7 +420,7 @@ public class WalkEncryptionTest { c.setConnectTimeout(500); c.setReadTimeout(500); try (BufferedReader reader = new BufferedReader( - new InputStreamReader(c.getInputStream(), CHARSET))) { + new InputStreamReader(c.getInputStream(), UTF_8))) { return reader.readLine(); } } catch (UnknownHostException | SocketTimeoutException e) { @@ -738,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(CHARSET)); + s3.put(bucket, path, file.getBytes(UTF_8)); s3.delete(bucket, path); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java index 6195e640f..41bd355a2 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/CanonicalTreeParserTest.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.treewalk; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.FileMode.REGULAR_FILE; import static org.eclipse.jgit.lib.FileMode.SYMLINK; import static org.junit.Assert.assertEquals; @@ -110,7 +111,7 @@ public class CanonicalTreeParserTest { } private String path() { - return RawParseUtils.decode(Constants.CHARSET, ctp.path, + return RawParseUtils.decode(UTF_8, ctp.path, ctp.pathOffset, ctp.pathLen); } @@ -370,7 +371,7 @@ public class CanonicalTreeParserTest { final String name = b.toString(); ctp.reset(entry(m644, name, hash_a)); assertFalse(ctp.eof()); - assertEquals(name, RawParseUtils.decode(Constants.CHARSET, ctp.path, + assertEquals(name, RawParseUtils.decode(UTF_8, ctp.path, ctp.pathOffset, ctp.pathLen)); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java index e03167833..33e32cd81 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.treewalk; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -822,6 +823,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase { } private static String nameOf(AbstractTreeIterator i) { - return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen); + return RawParseUtils.decode(UTF_8, i.path, 0, i.pathLen); } } 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 a748b5221..e8566d243 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); + byte[] bytes = text.getBytes(UTF_8); return new RawCharSequence(bytes, 0, bytes.length); } } 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 505816580..37ca951f6 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; @@ -132,6 +132,6 @@ public class AutoLFInputStreamTest { } private static byte[] asBytes(String in) { - return in.getBytes(CHARSET); + return in.getBytes(UTF_8); } } 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 3c612e1bd..e6045a91b 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + m.update(TEST1.getBytes(UTF_8)); ObjectId m1 = ObjectId.fromRaw(m.digest()); SHA1 s = SHA1.newInstance(); - s.update(TEST1.getBytes(CHARSET)); + s.update(TEST1.getBytes(UTF_8)); ObjectId s1 = ObjectId.fromRaw(s.digest()); s.reset(); - s.update(TEST1.getBytes(CHARSET)); + s.update(TEST1.getBytes(UTF_8)); 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(CHARSET)); + m.update(TEST2.getBytes(UTF_8)); ObjectId m1 = ObjectId.fromRaw(m.digest()); SHA1 s = SHA1.newInstance(); - s.update(TEST2.getBytes(CHARSET)); + s.update(TEST2.getBytes(UTF_8)); ObjectId s1 = ObjectId.fromRaw(s.digest()); s.reset(); - s.update(TEST2.getBytes(CHARSET)); + s.update(TEST2.getBytes(UTF_8)); ObjectId s2 = s.toObjectId(); assertEquals(m1, s1); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesNode.java b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesNode.java index 62bf9f273..bcd72311d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesNode.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesNode.java @@ -42,6 +42,8 @@ */ package org.eclipse.jgit.attributes; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -50,8 +52,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.jgit.lib.Constants; - /** * Represents a bundle of attributes inherited from a base directory. * @@ -115,7 +115,7 @@ public class AttributesNode { } private static BufferedReader asReader(InputStream in) { - return new BufferedReader(new InputStreamReader(in, Constants.CHARSET)); + return new BufferedReader(new InputStreamReader(in, UTF_8)); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java index fee9f5100..6b1d4f4d8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -46,6 +46,8 @@ package org.eclipse.jgit.dircache; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.EOFException; import java.io.IOException; @@ -772,7 +774,7 @@ public class DirCacheEntry { } static String toString(byte[] path) { - return Constants.CHARSET.decode(ByteBuffer.wrap(path)).toString(); + return UTF_8.decode(ByteBuffer.wrap(path)).toString(); } static int getMaximumInfoLength(boolean extended) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java index b605f3ca8..11a3474a3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.dircache; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.FileMode.TREE; import static org.eclipse.jgit.lib.TreeFormatter.entrySize; @@ -276,7 +277,7 @@ public class DirCacheTree { */ public String getNameString() { final ByteBuffer bb = ByteBuffer.wrap(encodedName); - return Constants.CHARSET.decode(bb).toString(); + return UTF_8.decode(bb).toString(); } /** 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 8a61d1b0b..ad43e2ca8 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -158,7 +158,7 @@ abstract class GitHook implements Callable { PrintStream hookErrRedirect = null; try { hookErrRedirect = new PrintStream(errorByteArray, false, - CHARSET.name()); + UTF_8.name()); } catch (UnsupportedEncodingException e) { // UTF-8 is guaranteed to be available } @@ -167,7 +167,7 @@ abstract class GitHook implements Callable { hookErrRedirect, getStdinArgs()); if (result.isExecutedWithError()) { throw new AbortedByHookException( - new String(errorByteArray.toByteArray(), CHARSET), + new String(errorByteArray.toByteArray(), UTF_8), 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 d570fde36..864f8bfc0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/ignore/IgnoreNode.java @@ -42,6 +42,8 @@ */ package org.eclipse.jgit.ignore; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -50,8 +52,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.eclipse.jgit.lib.Constants; - /** * Represents a bundle of ignore rules inherited from a base directory. * @@ -121,7 +121,7 @@ public class IgnoreNode { } private static BufferedReader asReader(InputStream in) { - return new BufferedReader(new InputStreamReader(in, Constants.CHARSET)); + return new BufferedReader(new InputStreamReader(in, UTF_8)); } /** 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 c11f69670..8793d8312 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET), ext); + return new ByteArrayDfsStreamKey(repo, name.getBytes(UTF_8), ext); } final int hash; 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 0e587ce82..82458c1ac 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.File; import java.io.IOException; @@ -171,6 +171,6 @@ class GcLog { if (content.length() > 0) { nonEmpty = true; } - lock.write(content.getBytes(CHARSET)); + lock.write(content.getBytes(UTF_8)); } } 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 c82d52e79..3d0e9c718 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.BufferedReader; import java.io.File; @@ -86,7 +86,7 @@ public class LazyObjectIdSetFile implements ObjectIdSet { private ObjectIdOwnerMap load() { ObjectIdOwnerMap r = new ObjectIdOwnerMap<>(); try (FileInputStream fin = new FileInputStream(src); - Reader rin = new InputStreamReader(fin, CHARSET); + Reader rin = new InputStreamReader(fin, UTF_8); 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/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 6a18df86e..de7e4b3f2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -46,7 +46,7 @@ package org.eclipse.jgit.internal.storage.file; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.lib.Constants.LOGS; import static org.eclipse.jgit.lib.Constants.OBJECT_ID_STRING_LENGTH; @@ -945,7 +945,7 @@ public class RefDirectory extends RefDatabase { try (BufferedReader br = new BufferedReader(new InputStreamReader( new DigestInputStream(new FileInputStream(packedRefsFile), digest), - CHARSET))) { + UTF_8))) { try { return new PackedRefList(parsePackedRefs(br), snapshot, ObjectId.fromRaw(digest.digest())); 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 942d72fe2..ce2ba4a2e 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET, nameBuf, 0, len); + return RawParseUtils.decode(UTF_8, nameBuf, 0, len); } boolean match(byte[] match, boolean matchIsPrefix) { @@ -171,7 +171,7 @@ class BlockReader { } Ref readRef() throws IOException { - String name = RawParseUtils.decode(CHARSET, nameBuf, 0, nameLen); + String name = RawParseUtils.decode(UTF_8, 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(CHARSET, buf, ptr, end); + String s = RawParseUtils.decode(UTF_8, 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 3d8fbf499..b3173e838 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); + return ref.getName().getBytes(UTF_8); } } @@ -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(CHARSET); - this.email = who.getEmailAddress().getBytes(CHARSET); - this.msg = message.getBytes(CHARSET); + this.name = who.getName().getBytes(UTF_8); + this.email = who.getEmailAddress().getBytes(UTF_8); + this.msg = message.getBytes(UTF_8); } static byte[] key(String ref, long index) { - byte[] name = ref.getBytes(CHARSET); + byte[] name = ref.getBytes(UTF_8); 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 44bbb1621..1fc43c9fa 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + writeVarintString(s.getBytes(UTF_8)); } 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 bd52256c2..81b30e4cb 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); + byte[] key = refName.getBytes(UTF_8); RefCursorImpl i = new RefCursorImpl(refEnd, key, false); i.block = seek(REF_BLOCK_TYPE, key, refIndex, 0, refEnd); return i; @@ -193,7 +193,7 @@ public class ReftableReader extends Reftable { public RefCursor seekRefsWithPrefix(String prefix) throws IOException { initRefIndex(); - byte[] key = prefix.getBytes(CHARSET); + byte[] key = prefix.getBytes(UTF_8); RefCursorImpl i = new RefCursorImpl(refEnd, key, true); i.block = seek(REF_BLOCK_TYPE, key, refIndex, 0, refEnd); return i; @@ -232,7 +232,7 @@ public class ReftableReader extends Reftable { initLogIndex(); if (logPosition > 0) { byte[] key = LogEntry.key(refName, updateIndex); - byte[] match = refName.getBytes(CHARSET); + byte[] match = refName.getBytes(UTF_8); 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/BlobBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java index e008be3a3..59154b78b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BlobBasedConfig.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.lib; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.FileNotFoundException; import java.io.IOException; @@ -83,7 +83,7 @@ public class BlobBasedConfig extends Config { super(base); final String decoded; if (isUtf8(blob)) { - decoded = RawParseUtils.decode(CHARSET, blob, 3, blob.length); + decoded = RawParseUtils.decode(UTF_8, blob, 3, blob.length); } else { decoded = RawParseUtils.decode(blob); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java index 59a13f655..c30833d0a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -93,7 +95,7 @@ public class CommitBuilder { */ public CommitBuilder() { parentIds = EMPTY_OBJECTID_LIST; - encoding = Constants.CHARSET; + encoding = UTF_8; } /** @@ -314,7 +316,7 @@ public class CommitBuilder { w.flush(); os.write('\n'); - if (getEncoding() != Constants.CHARSET) { + if (getEncoding() != UTF_8) { os.write(hencoding); os.write(' '); os.write(Constants.encodeASCII(getEncoding().name())); @@ -375,7 +377,7 @@ public class CommitBuilder { r.append(committer != null ? committer.toString() : "NOT_SET"); r.append("\n"); - if (encoding != null && encoding != Constants.CHARSET) { + if (encoding != null && encoding != UTF_8) { r.append("encoding "); r.append(encoding.name()); r.append("\n"); 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 0e01cca99..b666f21d0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -51,7 +51,7 @@ package org.eclipse.jgit.lib; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.text.MessageFormat; import java.util.ArrayList; @@ -1168,7 +1168,7 @@ public class Config { String decoded; if (isUtf8(bytes)) { - decoded = RawParseUtils.decode(CHARSET, bytes, 3, bytes.length); + decoded = RawParseUtils.decode(UTF_8, 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 9a4a3a2a0..f02e95a3d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -227,7 +227,13 @@ public final class Constants { */ public static final byte[] PACK_SIGNATURE = { 'P', 'A', 'C', 'K' }; - /** Native character encoding for commit messages, file names... */ + /** + * Native character encoding for commit messages, file names... + * + * @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8} directly + * instead. + **/ + @Deprecated public static final Charset CHARSET; /** Native character encoding for commit messages, file names... */ @@ -638,7 +644,7 @@ public final class Constants { * @see #CHARACTER_ENCODING */ public static byte[] encode(String str) { - final ByteBuffer bb = Constants.CHARSET.encode(str); + final ByteBuffer bb = UTF_8.encode(str); final int len = bb.limit(); if (bb.hasArray() && bb.arrayOffset() == 0) { final byte[] arr = bb.array(); @@ -655,7 +661,7 @@ public final class Constants { if (OBJECT_ID_LENGTH != newMessageDigest().getDigestLength()) throw new LinkageError(JGitText.get().incorrectOBJECT_ID_LENGTH); CHARSET = UTF_8; - CHARACTER_ENCODING = CHARSET.name(); + CHARACTER_ENCODING = UTF_8.name(); } /** name of the file containing the commit msg for a merge commit */ 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 38716055b..06b4b227c 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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, CHARSET); + nextSpace - tokenBegin - 1, UTF_8); 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, CHARSET); + nextSpace - tokenBegin - 1, UTF_8); tokenBegin = nextSpace; commit = AbbreviatedObjectId.fromString(commitToken); break; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java index bd0316580..7669e95ac 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/TagBuilder.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.lib; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -181,7 +183,7 @@ public class TagBuilder { public byte[] build() { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (OutputStreamWriter w = new OutputStreamWriter(os, - Constants.CHARSET)) { + UTF_8)) { w.write("object "); //$NON-NLS-1$ getObjectId().copyTo(w); w.write('\n'); 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 2f759e53c..936ce3dcc 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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, CHARSET))); + this(new PrintWriter(new OutputStreamWriter(System.err, UTF_8))); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java index d0a5216e1..1f4beb017 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/FileHeader.java @@ -43,6 +43,7 @@ package org.eclipse.jgit.patch; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.encodeASCII; import static org.eclipse.jgit.util.RawParseUtils.decode; import static org.eclipse.jgit.util.RawParseUtils.decodeNoFallback; @@ -63,7 +64,6 @@ import org.eclipse.jgit.diff.DiffEntry; import org.eclipse.jgit.diff.EditList; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.AbbreviatedObjectId; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.util.QuotedString; import org.eclipse.jgit.util.RawParseUtils; @@ -198,7 +198,7 @@ public class FileHeader extends DiffEntry { * Convert the patch script for this file into a string. *

* The default character encoding - * ({@link org.eclipse.jgit.lib.Constants#CHARSET}) is assumed for both the + * ({@link java.nio.charset.StandardCharsets#UTF_8}) is assumed for both the * old and new files. * * @return the patch script, as a Unicode string. @@ -240,8 +240,9 @@ public class FileHeader extends DiffEntry { if (trySimpleConversion(charsetGuess)) { Charset cs = charsetGuess != null ? charsetGuess[0] : null; - if (cs == null) - cs = Constants.CHARSET; + if (cs == null) { + cs = UTF_8; + } try { return decodeNoFallback(cs, buf, startOffset, endOffset); } catch (CharacterCodingException cee) { @@ -290,8 +291,9 @@ public class FileHeader extends DiffEntry { final String[] r = new String[tmp.length]; for (int i = 0; i < tmp.length; i++) { Charset cs = csGuess != null ? csGuess[i] : null; - if (cs == null) - cs = Constants.CHARSET; + if (cs == null) { + cs = UTF_8; + } r[i] = RawParseUtils.decode(cs, tmp[i].toByteArray()); } return r; @@ -429,7 +431,7 @@ public class FileHeader extends DiffEntry { oldPath = QuotedString.GIT_PATH.dequote(buf, bol, sp - 1); oldPath = p1(oldPath); } else { - oldPath = decode(Constants.CHARSET, buf, aStart, sp - 1); + oldPath = decode(UTF_8, buf, aStart, sp - 1); } newPath = oldPath; return eol; @@ -572,7 +574,7 @@ public class FileHeader extends DiffEntry { tab--; if (ptr == tab) tab = end; - r = decode(Constants.CHARSET, buf, ptr, tab - 1); + r = decode(UTF_8, buf, ptr, tab - 1); } if (r.equals(DEV_NULL)) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/FormatError.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/FormatError.java index 1dd24d732..10ea77834 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/FormatError.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/FormatError.java @@ -43,9 +43,10 @@ package org.eclipse.jgit.patch; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.Locale; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.RawParseUtils; /** @@ -120,7 +121,7 @@ public class FormatError { */ public String getLineText() { final int eol = RawParseUtils.nextLF(buf, offset); - return RawParseUtils.decode(Constants.CHARSET, buf, offset, eol); + return RawParseUtils.decode(UTF_8, buf, offset, eol); } /** {@inheritDoc} */ 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 3de442afb..5bd5dd636 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.IOException; import java.nio.charset.Charset; @@ -541,7 +541,7 @@ public class RevCommit extends RevObject { try { return getEncoding(); } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { - return CHARSET; + return UTF_8; } } 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 0050bac0a..32e7adfb0 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET, rawTag, p, nameEnd); + tagName = RawParseUtils.decode(UTF_8, 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 CHARSET; + return UTF_8; } } 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 4b272ba7a..93b3baa61 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,7 +49,7 @@ package org.eclipse.jgit.storage.file; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.ByteArrayOutputStream; import java.io.File; @@ -166,7 +166,7 @@ public class FileBasedConfig extends StoredConfig { } else { final String decoded; if (isUtf8(in)) { - decoded = RawParseUtils.decode(CHARSET, + decoded = RawParseUtils.decode(UTF_8, in, 3, in.length); utf8Bom = true; } else { @@ -224,7 +224,7 @@ public class FileBasedConfig extends StoredConfig { bos.write(0xEF); bos.write(0xBB); bos.write(0xBF); - bos.write(text.getBytes(CHARSET)); + bos.write(text.getBytes(UTF_8)); out = bos.toByteArray(); } else { out = Constants.encode(text); 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 a0fc57ca1..f6ec4b90e 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.ByteArrayOutputStream; import java.io.File; @@ -635,7 +635,7 @@ public class AmazonS3 { try { final Mac m = Mac.getInstance(HMAC); m.init(privateKey); - sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(CHARSET))); + sec = Base64.encodeBytes(m.doFinal(s.toString().getBytes(UTF_8))); } 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/BundleFetchConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java index 449f52944..4b20f6c8b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleFetchConnection.java @@ -47,6 +47,8 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; @@ -66,7 +68,6 @@ import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.storage.file.PackLock; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectIdRef; @@ -173,7 +174,7 @@ class BundleFetchConnection extends BaseFetchConnection { IO.skipFully(bin, 1); done = true; } - line.append(RawParseUtils.decode(Constants.CHARSET, hdrbuf, 0, lf)); + line.append(RawParseUtils.decode(UTF_8, hdrbuf, 0, lf)); } return line.toString(); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java index f2a261bbe..56aaede80 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -231,7 +233,7 @@ public class BundleWriter { packWriter.setTagTargets(tagTargets); packWriter.preparePack(monitor, inc, exc); - final Writer w = new OutputStreamWriter(os, Constants.CHARSET); + final Writer w = new OutputStreamWriter(os, UTF_8); w.write(TransportBundle.V2_BUNDLE_SIGNATURE); w.write('\n'); 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 1415334c6..6c26b7026 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8)); 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 fb03190b0..69745eb31 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(HttpConnection conn) throws IOException { String ident = user + ":" + pass; //$NON-NLS-1$ - String enc = Base64.encodeBytes(ident.getBytes(CHARSET)); + String enc = Base64.encodeBytes(ident.getBytes(UTF_8)); 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(CHARSET)); + md.update(data.getBytes(UTF_8)); return LHEX(md.digest()); } private static String KD(String secret, String data) { MessageDigest md = newMD5(); - md.update(secret.getBytes(CHARSET)); + md.update(secret.getBytes(UTF_8)); md.update((byte) ':'); - md.update(data.getBytes(CHARSET)); + md.update(data.getBytes(UTF_8)); return LHEX(md.digest()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java index cc556f8af..c6e19d576 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java @@ -45,13 +45,14 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; @@ -186,7 +187,7 @@ public class PacketLineIn { if (raw[len - 1] == '\n') len--; - String s = RawParseUtils.decode(Constants.CHARSET, raw, 0, len); + String s = RawParseUtils.decode(UTF_8, raw, 0, len); log.debug("git< " + s); //$NON-NLS-1$ return s; } @@ -218,7 +219,7 @@ public class PacketLineIn { IO.readFully(in, raw, 0, len); - String s = RawParseUtils.decode(Constants.CHARSET, raw, 0, len); + String s = RawParseUtils.decode(UTF_8, raw, 0, len); log.debug("git< " + s); //$NON-NLS-1$ return s; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java index a26d1d77d..e9400919a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineOut.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.io.OutputStream; @@ -141,7 +143,7 @@ public class PacketLineOut { out.write(lenbuffer, 0, 4); out.write(buf, pos, len); if (log.isDebugEnabled()) { - String s = RawParseUtils.decode(Constants.CHARSET, buf, pos, len); + String s = RawParseUtils.decode(UTF_8, buf, pos, len); log.debug("git> " + s); //$NON-NLS-1$ } } 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 2364434b0..41af8078c 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET)); + out.write(s.getBytes(UTF_8)); 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 178c80d22..f9fddbe88 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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(CHARSET); + byte[] raw = str.getBytes(UTF_8); 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, CHARSET); + String id = new String(raw, 0, idEnd, UTF_8); 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 7f5a3408e..aeca63500 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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,8 @@ 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, CHARSET))) { + Reader r = new BufferedReader( + new InputStreamReader(in, UTF_8))) { return PushCertificateParser.fromReader(r); } } @@ -473,7 +474,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(CHARSET)); + final ObjectId certId = inserter.insert(OBJ_BLOB, certText.getBytes(UTF_8)); 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 dc1871b72..4662435ea 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 org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; 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.lib.Repository; public abstract class RefAdvertiser { /** Advertiser which frames lines in a {@link PacketLineOut} format. */ public static class PacketLineOutRefAdvertiser extends RefAdvertiser { - private final CharsetEncoder utf8 = CHARSET.newEncoder(); + private final CharsetEncoder utf8 = UTF_8.newEncoder(); private final PacketLineOut pckOut; private byte[] binArr = new byte[256]; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java index 3100cb444..90600cbb9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/SideBandInputStream.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.transport.SideBandOutputStream.HDR_SIZE; import java.io.IOException; @@ -57,7 +58,6 @@ import java.util.regex.Pattern; import org.eclipse.jgit.errors.PackProtocolException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.JGitText; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.util.IO; import org.eclipse.jgit.util.RawParseUtils; @@ -257,6 +257,6 @@ public class SideBandInputStream extends InputStream { private String readString(int len) throws IOException { final byte[] raw = new byte[len]; IO.readFully(rawIn, raw, 0, len); - return RawParseUtils.decode(Constants.CHARSET, raw, 0, len); + return RawParseUtils.decode(UTF_8, raw, 0, len); } } 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 d342ef46d..621c2ea56 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java @@ -46,7 +46,7 @@ package org.eclipse.jgit.transport; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.BufferedReader; import java.io.IOException; @@ -144,7 +144,7 @@ public abstract class Transport implements AutoCloseable { private static void scan(ClassLoader ldr, URL url) { try (BufferedReader br = new BufferedReader( - new InputStreamReader(url.openStream(), CHARSET))) { + new InputStreamReader(url.openStream(), UTF_8))) { String line; while ((line = br.readLine()) != null) { line = line.trim(); 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 ee64a87f7..8b41ab046 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/TransportHttp.java @@ -46,6 +46,7 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.eclipse.jgit.lib.Constants.HEAD; import static org.eclipse.jgit.util.HttpSupport.ENCODING_GZIP; import static org.eclipse.jgit.util.HttpSupport.ENCODING_X_GZIP; @@ -426,7 +427,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, } private BufferedReader toBufferedReader(InputStream in) { - return new BufferedReader(new InputStreamReader(in, Constants.CHARSET)); + return new BufferedReader(new InputStreamReader(in, UTF_8)); } /** {@inheritDoc} */ @@ -952,7 +953,7 @@ public class TransportHttp extends HttpTransport implements WalkTransport, // Line oriented readable content is likely to compress well. // Request gzip encoding. InputStream is = open(path, AcceptEncoding.GZIP).in; - return new BufferedReader(new InputStreamReader(is, Constants.CHARSET)); + return new BufferedReader(new InputStreamReader(is, UTF_8)); } @Override diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java index aa71c9445..6d4df4fba 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkRemoteObjectDatabase.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.transport; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; @@ -363,7 +365,7 @@ abstract class WalkRemoteObjectDatabase { */ BufferedReader openReader(String path) throws IOException { final InputStream is = open(path).in; - return new BufferedReader(new InputStreamReader(is, Constants.CHARSET)); + return new BufferedReader(new InputStreamReader(is, UTF_8)); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java index 470ed0284..335abe1b5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.treewalk; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -182,7 +184,7 @@ public abstract class AbstractTreeIterator { if (prefix != null && prefix.length() > 0) { final ByteBuffer b; - b = Constants.CHARSET.encode(CharBuffer.wrap(prefix)); + b = UTF_8.encode(CharBuffer.wrap(prefix)); pathLen = b.limit(); path = new byte[Math.max(DEFAULT_PATH_SIZE, pathLen + 1)]; b.get(path, 0, pathLen); 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 d500aae68..82675859d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java @@ -44,6 +44,8 @@ package org.eclipse.jgit.treewalk; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -1045,7 +1047,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { final AbstractTreeIterator t = currentHead; final int off = t.pathOffset; final int end = t.pathLen; - return RawParseUtils.decode(Constants.CHARSET, t.path, off, end); + return RawParseUtils.decode(UTF_8, t.path, off, end); } /** @@ -1378,11 +1380,11 @@ public class TreeWalk implements AutoCloseable, AttributesProvider { } static String pathOf(AbstractTreeIterator t) { - return RawParseUtils.decode(Constants.CHARSET, t.path, 0, t.pathLen); + return RawParseUtils.decode(UTF_8, t.path, 0, t.pathLen); } static String pathOf(byte[] buf, int pos, int end) { - return RawParseUtils.decode(Constants.CHARSET, buf, pos, end); + return RawParseUtils.decode(UTF_8, buf, pos, end); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java index 179fd4679..7c6bfb9d6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java @@ -46,6 +46,8 @@ package org.eclipse.jgit.treewalk; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -1413,7 +1415,7 @@ public abstract class WorkingTreeIterator extends AbstractTreeIterator { IteratorState(WorkingTreeOptions options) { this.options = options; - this.nameEncoder = Constants.CHARSET.newEncoder(); + this.nameEncoder = UTF_8.newEncoder(); } void initializeReadBuffer() { 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 442f0793f..69f854745 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/Base64.java @@ -6,7 +6,7 @@ package org.eclipse.jgit.util; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.text.MessageFormat; import java.util.Arrays; @@ -54,7 +54,7 @@ public class Base64 { + "abcdefghijklmnopqrstuvwxyz" // //$NON-NLS-1$ + "0123456789" // //$NON-NLS-1$ + "+/" // //$NON-NLS-1$ - ).getBytes(CHARSET); + ).getBytes(UTF_8); DEC = new byte[128]; Arrays.fill(DEC, INVALID_DEC); @@ -177,7 +177,7 @@ public class Base64 { e += 4; } - return new String(outBuff, 0, e, CHARSET); + return new String(outBuff, 0, e, UTF_8); } /** @@ -293,7 +293,7 @@ public class Base64 { * @return the decoded data */ public static byte[] decode(String s) { - byte[] bytes = s.getBytes(CHARSET); + byte[] bytes = s.getBytes(UTF_8); return decode(bytes, 0, bytes.length); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java index 3393fbfd1..e5c8d9d39 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,7 +43,7 @@ package org.eclipse.jgit.util; -import static org.eclipse.jgit.lib.Constants.CHARSET; +import static java.nio.charset.StandardCharsets.UTF_8; import java.io.File; import java.io.PrintStream; @@ -126,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$ - CHARSET.name()); + UTF_8.name()); } catch (CommandFailedException e) { LOG.warn(e.getMessage()); return null; 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 2f547c15b..ecfd31647 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java @@ -45,6 +45,8 @@ package org.eclipse.jgit.util; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.File; import java.io.IOException; import java.nio.file.AtomicMoveNotSupportedException; @@ -712,7 +714,7 @@ public class FileUtils { Path nioPath = toPath(file); if (Files.isSymbolicLink(nioPath)) return Files.readSymbolicLink(nioPath).toString() - .getBytes(Constants.CHARSET).length; + .getBytes(UTF_8).length; return Files.size(nioPath); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java index 4d58d0614..a55cad370 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java @@ -43,6 +43,8 @@ package org.eclipse.jgit.util; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.util.Arrays; import org.eclipse.jgit.lib.Constants; @@ -181,7 +183,7 @@ public abstract class QuotedString { continue; } } - return RawParseUtils.decode(Constants.CHARSET, r, 0, rPtr); + return RawParseUtils.decode(UTF_8, r, 0, rPtr); } } @@ -294,7 +296,7 @@ public abstract class QuotedString { public String dequote(byte[] in, int inPtr, int inEnd) { if (2 <= inEnd - inPtr && in[inPtr] == '"' && in[inEnd - 1] == '"') return dq(in, inPtr + 1, inEnd - 1); - return RawParseUtils.decode(Constants.CHARSET, in, inPtr, inEnd); + return RawParseUtils.decode(UTF_8, in, inPtr, inEnd); } private static String dq(byte[] in, int inPtr, int inEnd) { @@ -370,7 +372,7 @@ public abstract class QuotedString { } } - return RawParseUtils.decode(Constants.CHARSET, r, 0, rPtr); + return RawParseUtils.decode(UTF_8, r, 0, rPtr); } private GitPathStyle() { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java index 94e5ef3d7..12d809b51 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/MessageWriter.java @@ -43,13 +43,14 @@ package org.eclipse.jgit.util.io; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.util.RawParseUtils; /** @@ -80,7 +81,7 @@ public class MessageWriter extends Writer { */ public MessageWriter() { buf = new ByteArrayOutputStream(); - enc = new OutputStreamWriter(getRawStream(), Constants.CHARSET); + enc = new OutputStreamWriter(getRawStream(), UTF_8); } /** {@inheritDoc} */ From 559c68cb012b971bf506d12aaf0a0f0504c9780b Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 14 Jun 2018 20:05:38 -0400 Subject: [PATCH 15/16] Parse signature of GPG-signed commits In order to support GPG-signed commits, add some methods which will allow GPG signatures to be parsed out of RevCommit objects. Later, we can add code to verify the signatures. Change-Id: Ifcf6b3ac79115c15d3ec4b4eaed07315534d09ac Signed-off-by: David Turner Signed-off-by: Matthias Sohn --- .../jgit/revwalk/RevCommitParseTest.java | 32 +++++++++++ .../eclipse/jgit/util/RawParseUtilsTest.java | 43 ++++++++++++++ .../org/eclipse/jgit/revwalk/RevCommit.java | 29 ++++++++++ .../org/eclipse/jgit/util/RawParseUtils.java | 56 +++++++++++++++++++ 4 files changed, 160 insertions(+) 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 d55fb4467..b81498493 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 @@ -486,4 +486,36 @@ public class RevCommitParseTest extends RepositoryTestCase { private static ObjectId id(String str) { return ObjectId.fromString(str); } + + @Test + public void testParse_gpgSig() throws Exception { + String commit = "tree e3a1035abd2b319bb01e57d69b0ba6cab289297e\n" + + "parent 54e895b87c0768d2317a2b17062e3ad9f76a8105\n" + + "committer A U Thor + * This method parses and returns the raw content of the gpgsig lines. This + * method is fairly expensive and produces a new byte[] instance on each + * invocation. Callers should invoke this method only if they are certain + * they will need, and should cache the return value for as long as + * necessary to use all information from it. + *

+ * RevFilter implementations should try to use + * {@link org.eclipse.jgit.util.RawParseUtils} to scan the + * {@link #getRawBuffer()} instead, as this will allow faster evaluation of + * commits. + * + * @return contents of the gpg signature; null if the commit was not signed. + * @since 5.1 + */ + public final @Nullable byte[] getRawGpgSignature() { + final byte[] raw = buffer; + final byte[] header = {'g', 'p', 'g', 's', 'i', 'g'}; + final int start = RawParseUtils.headerStart(header, raw, 0); + if (start < 0) { + return null; + } + final int end = RawParseUtils.headerEnd(raw, start); + return Arrays.copyOfRange(raw, start, end); + } + /** * Parse the author identity from the raw buffer. *

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java index c22c8de5d..28f406a49 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java @@ -548,6 +548,62 @@ public final class RawParseUtils { return ptr; } + /** + * Locate the end of the header. Note that headers may be + * more than one line long. + * @param b + * buffer to scan. + * @param ptr + * position within buffer to start looking for the end-of-header. + * @return new position just after the header. This is either + * b.length, or the index of the header's terminating newline. + * @since 5.1 + */ + public static final int headerEnd(final byte[] b, int ptr) { + final int sz = b.length; + while (ptr < sz) { + final byte c = b[ptr++]; + if (c == '\n' && (ptr == sz || b[ptr] != ' ')) { + return ptr - 1; + } + } + return ptr - 1; + } + + /** + * Find the start of the contents of a given header. + * + * @param b + * buffer to scan. + * @param headerName + * header to search for + * @param ptr + * position within buffer to start looking for header at. + * @return new position at the start of the header's contents, -1 for + * not found + * @since 5.1 + */ + public static final int headerStart(byte[] headerName, byte[] b, int ptr) { + // Start by advancing to just past a LF or buffer start + if (ptr != 0) { + ptr = nextLF(b, ptr - 1); + } + while (ptr < b.length - (headerName.length + 1)) { + boolean found = true; + for (int i = 0; i < headerName.length; i++) { + if (headerName[i] != b[ptr++]) { + found = false; + break; + } + } + if (found && b[ptr++] == ' ') { + return ptr; + } + ptr = nextLF(b, ptr); + } + return -1; + } + /** * Locate the first position before a given character. * From 2173f441589fbab7214bf59ea1330fff2c9f4c37 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 4 Sep 2018 14:23:14 +0900 Subject: [PATCH 16/16] UploadPackTest: Avoid unnecessarily boxing int into Integer The statement: assertThat(recvStream.available(), is(0)); results in a warning from Eclipse: The expression of type int is boxed into Integer because recvStream.available() returns int, but the hamcrest is() method takes an Integer. Replace it with the equivalent JUnit assertion. Also remove the suppression of another similar warning and fix that in the same way. Change-Id: I6f18b304a540bcd0a10aec7d3abc7dc6f047fe80 Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/transport/UploadPackTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 4c6076a20..317ac32e6 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 @@ -5,6 +5,7 @@ import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.theInstance; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -577,12 +578,11 @@ public class UploadPackTest { } @Test - @SuppressWarnings("boxing") public void testV2EmptyRequest() throws Exception { ByteArrayInputStream recvStream = uploadPackV2(PacketLineIn.END); // Verify that there is nothing more after the capability // advertisement. - assertThat(recvStream.available(), is(0)); + assertEquals(0, recvStream.available()); } @Test @@ -735,7 +735,7 @@ public class UploadPackTest { pp.parse(NullProgressMonitor.INSTANCE); // Ensure that there is nothing left in the stream. - assertThat(recvStream.read(), is(-1)); + assertEquals(-1, recvStream.read()); return pp.getReceivedPackStatistics(); }