]> source.dussan.org Git - jgit.git/log
jgit.git
6 years agoRefDatabase: add hasRefs convenience method 02/121902/2
David Pursehouse [Fri, 27 Apr 2018 12:49:08 +0000 (21:49 +0900)]
RefDatabase: add hasRefs convenience method

Callers can now say:

 db.getRefDatabase().hasRefs()

rather than the more verbose:

 !db.getRefDatabase().getAllRefs().isEmpty()

The default implementation simply uses getAllRefs().isEmpty(), but a
derived class could possibly override the method with a more efficient
implementation.

Change-Id: I5244520708a1a7d9adb351f10e43fc39d98e22a1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoFix comparison order in AnyObjectId 99/121899/1
David Turner [Fri, 27 Apr 2018 19:04:18 +0000 (15:04 -0400)]
Fix comparison order in AnyObjectId

The previous version suggested testing w2 first because w1 was used
for hashing, but in fact, hashCode returns w2.  The order (w3, w4, w5,
w1, w2) might be better on 64-bit processors too, since it allows
comparing 64 bits at a time, although perhaps on a modern SIMD
processor, the entire 160 bytes would be compared at once anyway.

Change-Id: Ieb69606d3c1456aeff36bffe99a71587ea76e977
Signed-off-by: David Turner <dturner@twosigma.com>
6 years agoRefDatabase: Introduce getAllRefs method 27/121827/2
David Pursehouse [Fri, 27 Apr 2018 01:42:53 +0000 (10:42 +0900)]
RefDatabase: Introduce getAllRefs method

Currently to get all refs, callers must use:

  getRefsByPrefix(ALL)

Introduce getAllRefs, which does this, and migrate all existing
callers of getRefsByPrefix(ALL).

Change-Id: I7b1687c162c8ae836dc7db3ccc7ac847863f691d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRefDatabase: Update Javadoc for ALL constant 26/121826/1
David Pursehouse [Fri, 27 Apr 2018 01:12:32 +0000 (10:12 +0900)]
RefDatabase: Update Javadoc for ALL constant

The Javadoc refers to the deprecated getRefs method. Update it to refer
to getRefsByPrefix which is the recommended replacement of getRefs.

Change-Id: I61f2abcf1a3794f40a1746317dbc18aa0beb87a7
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoLargePackedWholeObject#openStream: Suppress resource warning 25/121825/1
David Pursehouse [Thu, 26 Apr 2018 23:27:30 +0000 (08:27 +0900)]
LargePackedWholeObject#openStream: Suppress resource warning

Eclipse warns that DfsReader should be managed by try-with-resource.

As described in 1484d6e (LargePackedWholeObject: Do not reuse released
inflater, 2018-04-26), the DfsReader is owned and closed by the
PackInputStream or explicitly closed in the try block's finally.

Suppress the warning with a brief explanatory comment.

Change-Id: I4187c935742072f3ee7f2d3551a6a98d40fc2702
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoLargePackedWholeObject: Do not reuse released inflater 24/121824/2
Jonathan Nieder [Thu, 26 Apr 2018 22:14:50 +0000 (15:14 -0700)]
LargePackedWholeObject: Do not reuse released inflater

LargePackedWholeObject.openStream produces a stream that allows
reading a large object.  This stream holds a DfsReader that takes care
of caching delta bases etc and in particular holds zlib Inflater for
use while reading the each delta in the packfile.

At DfsReader creation time, the Inflater is acquired from a global
InflaterCache to avoid initialization overhead in case there is an
existing Inflater available for reuse.  When done with the Inflater,
the DfsReader is responsible for returning it to the cache for reuse.
The DfsReader is AutoClosable to remind the caller to close it and
release the Inflater when finished with it.

b0ac5f9c8907a4034612543a92eb465e88a9c6f2 (LargePackedWholeObject:
Refactor to open DfsReader in try-with-resource, 2018-04-11) tried to
clarify the lifetime of the DfsReader but was too aggressive: when
this function returns, PackInputStream owns the DfsReader and is
already going to release it.  Worse, the returned InflaterInputStream
holds a reference to the DfsReader's inflater, making releasing the
DfsReader not only unnecessary but unsafe.

The Inflater gets released into the InflaterCache's pool, to be
acquired by another caller that uses it concurrently with the
InflaterInputStream.  This results in errors, such as

 java.util.zip.ZipException: incorrect header check
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
        at java.util.zip.InflaterInputStream.skip(InflaterInputStream.java:208)
        at java.io.BufferedInputStream.skip(BufferedInputStream.java:377)

and

 java.util.zip.DataFormatException: incorrect header check
        at java.util.zip.Inflater.inflateBytes(Native Method)
        at java.util.zip.Inflater.inflate(Inflater.java:259)
        at org.eclipse.jgit.internal.storage.dfs.DfsReader.inflate(DfsReader.java:783)
        at org.eclipse.jgit.internal.storage.dfs.DfsPackFile.decompress(DfsPackFile.java:420)
        at org.eclipse.jgit.internal.storage.dfs.DfsPackFile.load(DfsPackFile.java:767)

and

 Caused by: java.util.zip.ZipException: incorrect header check
        at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
        at org.eclipse.jgit.lib.ObjectStream$Filter.read(ObjectStream.java:219)
        at org.eclipse.jgit.util.IO.readFully(IO.java:233)
        at org.eclipse.jgit.transport.PackParser.checkObjectCollision(PackParser.java:1173)

Verified in production.  It should be possible to make a
straightforward unit test for this using the InflaterCache state but
that can wait for a followup commit.

Change-Id: Iaf1d6fd368b64f76c520d215fd270a6098a1f236

6 years agoUse eclipse compiler in Maven build 00/121700/5
Matthias Sohn [Wed, 25 Apr 2018 01:09:05 +0000 (03:09 +0200)]
Use eclipse compiler in Maven build

Found instructions for configuring maven-compiler-plugin with ecj in
[1]. Verified that ecj run in this way raises build errors when executed
on commit d3ef5213.

Define profiles "ecj" for using Eclipse compiler and "javac" for using
javac including errorprone. By default ecj will be used.

use ecj:
$ mvn -Pecj clean install

use javac:
$ mvn -Pjavac clean install

TODO: find out how to run ecj with errorprone from Maven.

[1] https://stackoverflow.com/questions/33164976/using-eclipse-java-compiler-ecj-in-maven-builds

Change-Id: I716b603b57612b953e603387c82fd01eb1b5ca97
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove trivial cases of using deprecated RefDatabase.getRefs() 99/121699/2
Matthias Sohn [Tue, 24 Apr 2018 23:44:43 +0000 (01:44 +0200)]
Remove trivial cases of using deprecated RefDatabase.getRefs()

Change-Id: I2d3e426a3391923f8a690ac68fcc33851f3eb419
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoSuppress boxing warning 98/121698/1
Matthias Sohn [Tue, 24 Apr 2018 23:08:58 +0000 (01:08 +0200)]
Suppress boxing warning

Change-Id: I90226674320841774ad691c84609e3fe71bf7852
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove unnecessary semicolon 97/121697/1
Matthias Sohn [Tue, 24 Apr 2018 23:05:33 +0000 (01:05 +0200)]
Remove unnecessary semicolon

Change-Id: I3677ecb106ade209e756cec2c6f4232a416bfb44
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoFix non-externalized String warnings 96/121696/1
Matthias Sohn [Tue, 24 Apr 2018 23:05:13 +0000 (01:05 +0200)]
Fix non-externalized String warnings

- suppress warning for non-translatable texts
- externalize error messages

Change-Id: Ieba42219b2c0b51a288f5a60438a6cc4f9dfe641
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove unused code and link to deprecated code 88/121688/3
Jonathan Tan [Tue, 24 Apr 2018 20:05:16 +0000 (13:05 -0700)]
Remove unused code and link to deprecated code

Eclipse reports these as errors, so remove them.

Change-Id: Ic53d8003f9faef38fe776af5a73794e7bb1dfc49
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
6 years agoFile compile and API errors in JGit 02/121602/3
Michael Keppler [Mon, 23 Apr 2018 20:00:27 +0000 (22:00 +0200)]
File compile and API errors in JGit

* Photon throws null analysis errors on the repeated invocation of those
previously null checked methods. Extract them to a local variable to
avoid this. (the null analysis is configured in project properties)
* setUseProtocolV2() misses @since tag. Problem was introduced with
332bc611249d21f9b604f2c0207bf0bdfbfc3a78. Might be caused by the long
delay of 2 months from creation to merging.

Change-Id: Ibbb1a1580b604b8e7cd4bf7edc4643e292b6b4a8
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
6 years agoMerge "Upgrade error_prone_core to 2.3.1"
Matthias Sohn [Mon, 23 Apr 2018 23:18:34 +0000 (19:18 -0400)]
Merge "Upgrade error_prone_core to 2.3.1"

6 years agoTeach UploadPack "no-progress" in "fetch" 51/119451/10
Jonathan Tan [Thu, 1 Mar 2018 23:45:19 +0000 (15:45 -0800)]
Teach UploadPack "no-progress" in "fetch"

Add support for the "no-progress" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: I6a6d6b1534f44845254b81d0e1f5c4ba2ac3d10b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
6 years agoTeach UploadPack "thin-pack" in "fetch" 50/119450/10
Jonathan Tan [Thu, 1 Mar 2018 22:24:16 +0000 (14:24 -0800)]
Teach UploadPack "thin-pack" in "fetch"

Add support for the "thin-pack" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: I39a37b2b66a16929137d35c718a3acf2afb6b0b5
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
6 years agoTeach UploadPack basic "fetch" command 49/119449/11
Jonathan Tan [Fri, 23 Feb 2018 22:07:02 +0000 (14:07 -0800)]
Teach UploadPack basic "fetch" command

Add basic support for the "fetch" command in the fetch-pack/upload-pack
protocol v2. This patch teaches "have" and "done".

The protocol specification (Documentation/technical/protocol-v2.txt in
the Git project) states:

    want <oid>
Indicates to the server an object which the client wants to
retrieve.  Wants can be anything and are not limited to
advertised objects.

It is unspecified whether the server should respect the
uploadpack.allowtipsha1inwant option etc. when serving packfiles. This
patch is conservative in that the server respects them.

Change-Id: I3dbec172239712ef9286a15b8407e86b87ea7863
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
6 years agoTeach UploadPack "ref-prefix" in "ls-refs" 48/119448/10
Jonathan Tan [Thu, 22 Feb 2018 21:58:29 +0000 (13:58 -0800)]
Teach UploadPack "ref-prefix" in "ls-refs"

Add support for the "ref-prefix" parameter in the "ls-refs" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: If9cf93b2646f75d50a11b5f482594f014d59a836
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
6 years agoUploadPack: Don't buffer ls-refs output 09/121509/2
Jonathan Nieder [Fri, 20 Apr 2018 23:34:15 +0000 (16:34 -0700)]
UploadPack: Don't buffer ls-refs output

Once we have read the user's entire command, there is no more need to
buffer our response --- even the strictest servlet engine allows
writing output once the input has been consumed.  Noticed when the
analogous code in the "fetch" command (introduced in a later patch)
overflowed its buffer:

 java.lang.OutOfMemoryError
        at java.io.ByteArrayOutputStream.hugeCapacity(ByteArrayOutputStream.java:123)
 [...]
        at org.eclipse.jgit.transport.UploadPack.sendPack(UploadPack.java:1905)
        at org.eclipse.jgit.transport.UploadPack.sendPack(UploadPack.java:1741)
        at org.eclipse.jgit.transport.UploadPack.fetchV2(UploadPack.java:1001)
        at org.eclipse.jgit.transport.UploadPack.serviceV2(UploadPack.java:1030)
        at org.eclipse.jgit.transport.UploadPack.upload(UploadPack.java:726)
        at org.eclipse.jgit.http.server.UploadPackServlet.doPost(UploadPackServlet.java:195)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

Change-Id: I33df56f1cb1c6c2c25ee95426cb7ad665134ac6b

6 years agoImplement ls-refs in UploadPack 47/119447/10
Jonathan Tan [Thu, 22 Feb 2018 18:24:19 +0000 (10:24 -0800)]
Implement ls-refs in UploadPack

Implement support for Git protocol v2's "ls-refs" command and its
"symrefs" and "peel" parameters.

This adds support for this command to UploadPack but the git://,
ssh://, and git:// transports do not make use of it yet.  That will
have to wait for later patches.

Change-Id: I8abc6bcc6ed4a88c165677ff1245625aca01267b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
6 years agoUpgrade error_prone_core to 2.3.1 00/121400/2
David Pursehouse [Thu, 19 Apr 2018 10:16:11 +0000 (12:16 +0200)]
Upgrade error_prone_core to 2.3.1

and plexus-compiler-javac-errorprone to 2.8.4.

Change-Id: I36487ce53e70b54d7a04292e666540224c107b43
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoImplement protocol v2 with no capabilities in UploadPack 06/121506/4
Jonathan Tan [Thu, 22 Feb 2018 18:24:19 +0000 (10:24 -0800)]
Implement protocol v2 with no capabilities in UploadPack

Add initial support for protocol v2 of the fetch-pack/upload-pack
protocol. This protocol is described in the Git project in
"Documentation/technical/protocol-v2.txt".

This patch adds support for protocol v2 (without any capabilities) to
UploadPack. Adaptations of callers to make use of this support will
come in subsequent patches.

[jn: split from a larger patch; tweaked the API to make UploadPack
 handle parsing the extra parameters and config instead of requiring
 each caller to do such parsing]

Change-Id: I79399fa0dce533fdc8c1dbb6756748818cee45b0
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
6 years agoPacketLineIn, PacketLineOut: Add support for delim-pkt 98/121498/2
Jonathan Tan [Thu, 22 Feb 2018 18:24:19 +0000 (10:24 -0800)]
PacketLineIn, PacketLineOut: Add support for delim-pkt

Most pkt-lines (data-pkts) have the form

pkt-len pkt-payload

where pkt-len is a string of 4 hexadecimal digits representing the
size in bytes of the pkt-line.  Since this size includes the size of
the pkt-len, no data-pkt has a length less than 4.

A pkt-line with a length field less than 4 can thus be used for
other purposes.  In Git protocol v1, the only such pkt-line was

flush-pkt = "0000"

which was used to mark the end of a stream.  Protocol v2 (see
Documentation/technical/protocol-v2.txt in git.git) introduces a
second special pkt-line type:

delim-pkt = "0001"

used to mark the end of a section within a stream, for example to
separate capabilities from the content of a command.

[jn: split out from a larger patch that made use of this support]

Change-Id: I10e7824fa24ed74c4f45624bd490bba978cf5c34
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
6 years agoAdd RefDatabase#getRefsByPrefix method 73/120873/4
Jonathan Tan [Fri, 6 Apr 2018 22:50:01 +0000 (15:50 -0700)]
Add RefDatabase#getRefsByPrefix method

The existing RefDatabase#getRefs abstract method (to be implemented by
ref database backends) has the following issues:

 - It returns a map with a key (the name of the ref with the prefix
   removed) which is potentially superfluous (it can be derived by the
   caller if need be) and confusing (in that the prefix is removed).
 - The prefix is required to end with a '/', but some backends (e.g.
   reftable) have fast search by prefix regardless of what the last
   character of the prefix is.

Add a new method #getRefsByPrefix that does not have these issues. This
is non-abstract with a default implementation that uses #getRefs (for
backwards compatibility), but ref database backends can reimplement it.

This also prepares for supporting "ref-prefix" in the "ls-refs" command
in the fetch-pack/upload-pack protocol v2, which does not require that
the prefix end with a '/'.

Change-Id: I4c92f852e8c1558095dd460b5fd7b602c1d82df1
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
6 years agoHandle Gerrit Change-Ids for merge commits 71/120871/4
Thomas Wolf [Fri, 6 Apr 2018 21:58:34 +0000 (23:58 +0200)]
Handle Gerrit Change-Ids for merge commits

Otherwise successful, non-conflicting merges will never get a
Gerrit Change-Id.

Bug: 358206
Change-Id: I9b599ad01d9f7332200c1d81a1ba6ce5ef990ab5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
6 years agoPushProcess: Remove unused import of HashMap 08/121208/1
David Pursehouse [Mon, 16 Apr 2018 14:51:32 +0000 (16:51 +0200)]
PushProcess: Remove unused import of HashMap

Bug: 533621
Change-Id: Ie125818d5fc8fef5800108db2ca21151d8d3bfa3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoConfigure WindowCache settings to use in JGit CLI 95/118595/3
Matthias Sohn [Sun, 4 Mar 2018 09:42:46 +0000 (10:42 +0100)]
Configure WindowCache settings to use in JGit CLI

Set the same defaults as in EGit.
Use mmap to map git packfiles into memory.

Change-Id: I7997b9123448a762192d7eeb55e01432549fba98
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoMerge "Push: Ensure ref updates are processed in input order"
David Pursehouse [Fri, 13 Apr 2018 21:43:12 +0000 (17:43 -0400)]
Merge "Push: Ensure ref updates are processed in input order"

6 years agoMerge "Allow '@' as last character of ref"
Christian Halstrick [Fri, 13 Apr 2018 09:14:43 +0000 (05:14 -0400)]
Merge "Allow '@' as last character of ref"

6 years agoPush: Ensure ref updates are processed in input order 87/121087/4
Dave Borowitz [Thu, 12 Apr 2018 15:43:50 +0000 (11:43 -0400)]
Push: Ensure ref updates are processed in input order

Various places on the client side of the push were creating unordered
maps and sets of ref names, resulting in ReceivePack processing commands
in an order other than what the client provided. This is normally not
problematic for clients, who don't typically care about the order in
which ref updates are applied to the storage layer.

However, it does make it difficult to write deterministic tests of
ReceivePack or hooks whose output depends on the order in which commands
are processed, for example if informational per-ref messages are written
to a sideband.[1]

Add a test that ensures the ordering of commands both internally in
ReceivePack and in the output PushResult.

[1] Real-world example:
    https://gerrit-review.googlesource.com/c/gerrit/+/171871/1/javatests/com/google/gerrit/acceptance/git/PushPermissionsIT.java#149

Change-Id: I7f1254b4ebf202d4dcfc8e59d7120427542d0d9e

6 years agoAllow '@' as last character of ref 42/121042/1
Christian Halstrick [Thu, 12 Apr 2018 06:39:29 +0000 (08:39 +0200)]
Allow '@' as last character of ref

Previously @ was allowed e.g. in branch names, but not as the last
character. The case that @ is the last character was not handled.

Change-Id: Ic33870b22236f7a5ec7b54007f1b0cefd9354bfb

6 years agoDirCache: Use constant from StandardCharsets 96/120996/2
David Pursehouse [Wed, 11 Apr 2018 12:31:07 +0000 (21:31 +0900)]
DirCache: Use constant from StandardCharsets

Instead of hard-coding the encoding name, use the constant from
StandardCharsets. As a result it is no longer necessary to catch
the UnsupportedEncodingException.

Change-Id: I3cb6de921a78e05e2a894c220e0d5a5c85e172cc
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoUse Constants.CHARACTER_ENCODING in tests 82/120982/2
David Pursehouse [Wed, 11 Apr 2018 05:10:02 +0000 (14:10 +0900)]
Use Constants.CHARACTER_ENCODING in tests

Change-Id: Iba9fc991aee54fcb8b0dc5e5841da24c2d54dfc2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoLargePackedWholeObject: Refactor to open DfsReader in try-with-resource 81/120981/2
David Pursehouse [Wed, 11 Apr 2018 04:59:00 +0000 (13:59 +0900)]
LargePackedWholeObject: Refactor to open DfsReader in try-with-resource

Change-Id: Ia9557e6c1ab230dbe2e94e025a49e93159d8658c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoDon't throw if a pre-push hook is ignored. 38/120438/3
Markus Duft [Thu, 29 Mar 2018 13:28:07 +0000 (15:28 +0200)]
Don't throw if a pre-push hook is ignored.

This breaks any scenario where native git (with LFS) clones a repository
(and thus installs the hook) and later on JGit is used to push changes.

Change-Id: I2a17753377265a0b612ba3451b9df63a577a1c38
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
6 years agoMerge branch 'stable-4.11' 87/120887/1
David Pursehouse [Mon, 9 Apr 2018 07:40:37 +0000 (16:40 +0900)]
Merge branch 'stable-4.11'

* stable-4.11:
  LFS: Fix potential NPE in LfsPrePushHook

Change-Id: If721bd18035870541d216d2dcd9d47484e9af3e5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoLFS: Fix potential NPE in LfsPrePushHook 54/119754/2
Markus Duft [Tue, 20 Mar 2018 07:40:14 +0000 (08:40 +0100)]
LFS: Fix potential NPE in LfsPrePushHook

The NPE occurred in conjunction with a symbolic ref (origin/HEAD).

Change-Id: I291636818a121ca00e0df25de5b6fc71a48d447f
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
6 years agoSilence API error for ObjectIdSerializer.readWithoutMarker() 03/120303/2
Thomas Wolf [Tue, 27 Mar 2018 20:11:57 +0000 (22:11 +0200)]
Silence API error for ObjectIdSerializer.readWithoutMarker()

Change-Id: I99111797253b04148c42c83e1ef3d2cc383cc627
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
6 years agoMerge branch 'stable-4.11' 21/120221/2
Matthias Sohn [Mon, 26 Mar 2018 22:51:05 +0000 (00:51 +0200)]
Merge branch 'stable-4.11'

* stable-4.11:
  Remove package import for javax.servlet.http from org.eclipse.jgit
  Add missing @since tag and silence API error

Change-Id: I2783a15ead26ab19de31a8fb3bfb148ef19de91a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove package import for javax.servlet.http from org.eclipse.jgit 20/120220/1
Matthias Sohn [Mon, 26 Mar 2018 22:33:00 +0000 (00:33 +0200)]
Remove package import for javax.servlet.http from org.eclipse.jgit

This package import is unused.

Change-Id: I9f202bb3162736a1ef8054516f1a3145d3a7bb9b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoAdd missing @since tag and silence API error 19/120219/1
Matthias Sohn [Mon, 26 Mar 2018 22:35:40 +0000 (00:35 +0200)]
Add missing @since tag and silence API error

These methods were introduced for 4.11.1 so we have to silence the API
error adding API in a service release raises.

Change-Id: Ic847cebbed439912d3979ec2ec1809f77a28f61e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoSignificantly speed up FileTreeIterator on Windows 18/120118/4
Thomas Wolf [Sun, 18 Mar 2018 22:29:59 +0000 (23:29 +0100)]
Significantly speed up FileTreeIterator on Windows

Getting attributes of files on Windows is an expensive operation.
Windows stores file attributes in the directory, so they are
basically available "for free" when a directory is listed. The
implementation of Java's Files.walkFileTree() takes advantage of
that (at least in the OpenJDK implementation for Windows) and
provides the attributes from the directory to a FileVisitor.

Using Files.walkFileTree() with a maximum depth of 1 is thus a
good approach on Windows to get both the file names and the
attributes in one go.

In my tests, this gives a significant speed-up of FileTreeIterator
over the "normal" way: using File.listFiles() and then reading the
attributes of each file individually. The speed-up is hard to
quantify exactly, but in my tests I've observed consistently 30-40%
for staging 500 files one after another, each individually, and up
to 50% for individual TreeWalks with a FileTreeIterator.

On Unix, this technique is detrimental. Unix stores file attributes
differently, and getting attributes of individual files is not costly.
On Unix, the old way of doing a listFiles() and getting individual
attributes (both native operations) is about three times faster than
using walkFileTree, which is implemented in Java.

Therefore, move the operation to FS/FS_Win32 and call it from
FileTreeIterator, so that we can have different implementations
depending on the file system.

A little performance test program is included as a JUnit test (to be
run manually).

While this does speed up things on Windows, it doesn't solve the basic
problem of bug 532300: the iterator always gets the full directory
listing and the attributes of all files, and the more files there are
the longer that takes.

Bug: 532300
Change-Id: Ic5facb871c725256c2324b0d97b95e6efc33282a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
6 years agoTransportHttp: Refactor to use try-with-resource and suppress resource warning 37/119737/3
David Pursehouse [Tue, 20 Mar 2018 02:37:30 +0000 (11:37 +0900)]
TransportHttp: Refactor to use try-with-resource and suppress resource warning

Change-Id: I130269e7c5e46aea2152dea6b02539529208eea2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoAdd missing @since tags for new API 36/120136/3
Matthias Sohn [Sat, 24 Mar 2018 21:05:53 +0000 (22:05 +0100)]
Add missing @since tags for new API

These methods were added after 4.11 so strictly speaking they violate
semantic versioning since new API requires increasing the minor version
number. Hence pretend these methods were introduced in 5.0

Change-Id: I7793ead16577dc1f2ddea09ba6b055103c783555
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoFix API problem filter warnings 37/120137/3
Matthias Sohn [Sat, 24 Mar 2018 21:14:15 +0000 (22:14 +0100)]
Fix API problem filter warnings

Silence warnings for bundles which haven't broken API since 4.11 but
we increased major version to 5 since we always use the same version
for all jgit bundles

Change-Id: If4f9a6aa4ef21f9b511946c5fc4bd7c0af6094c4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove unused API problem filters 68/119468/2
David Pursehouse [Thu, 15 Mar 2018 06:46:54 +0000 (15:46 +0900)]
Remove unused API problem filters

Change-Id: I414ebba1db831686fd378dadcb7c4882eb323115
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoDfsInserter#openStream: Suppress resource warning about DfsReader 38/119738/3
David Pursehouse [Tue, 20 Mar 2018 02:43:15 +0000 (11:43 +0900)]
DfsInserter#openStream: Suppress resource warning about DfsReader

DfsReader is not opened in a try-with-resource because in the case where
the method returns an ObjectStream.Filter, the DfsReader should only be
closed from within the Filter's close() method.

Suppress the resource warning.

Change-Id: Ifcaf5e4a326bd1d03c6331b476c645ca43943b34
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoCloneCommand: Suppress resource warning about Repository 36/119736/2
David Pursehouse [Tue, 20 Mar 2018 02:28:18 +0000 (11:28 +0900)]
CloneCommand: Suppress resource warning about Repository

Repository is not opened in try-with-resource because it is wrapped
in a Git instance which should be closed by the caller. On exeptions
during fetch, it is explicitly closed in the catch blocks.

Suppress the warning with an explanatory comment.

Change-Id: Ib32c74ce39bb810077ab84db33002bdde806f3b6
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRename RecursiveMergerTest and ResolveMergerTest to reduce confusion 60/119660/3
David Pursehouse [Mon, 19 Mar 2018 12:13:53 +0000 (21:13 +0900)]
Rename RecursiveMergerTest and ResolveMergerTest to reduce confusion

The class names imply that RecursiveMergerTest tests the RecursiveMerger
and ResolveMergerTest tests the ResolveMerger.

In fact, both of them include coverage of both strategies; the difference
is that RecursiveMergerTest is only testing criss-cross merges.

The tests cannot be combined into a single class because the criss-cross
test methods have additional data points.

Instead, rename the classes to more meaningful names.

Change-Id: I7ca8a03a3b7e351e2d4fcaca3b3186c098a3ca66
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoResolveMergerTest: Use @DataPoints instead of @DataPoint 59/119659/3
David Pursehouse [Mon, 19 Mar 2018 12:10:04 +0000 (21:10 +0900)]
ResolveMergerTest: Use @DataPoints instead of @DataPoint

Define strategiesUnderTest as an array of MergeStrategy using the
@DataPoints annotation, rather than two separate variables each
annotated as @DataPoint.

This makes the implementation consistent with RecursiveMergerTest.

Change-Id: I9f1d525b38cb59634ba054c7779dc4af1fc46e25
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoSubmoduleSyncCommand: Refactor to open Repository in try-with-resource 67/119467/5
David Pursehouse [Thu, 15 Mar 2018 06:43:13 +0000 (15:43 +0900)]
SubmoduleSyncCommand: Refactor to open Repository in try-with-resource

Change-Id: I502904ff7dbe074f7bbcb2a56a17bf4729f4f4d3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoSubmoduleUpdateCommand: Refactor to open Repository in try-with-resource 66/119466/5
David Pursehouse [Thu, 15 Mar 2018 05:27:01 +0000 (14:27 +0900)]
SubmoduleUpdateCommand: Refactor to open Repository in try-with-resource

Change-Id: I1a303fdfdb6823043fa6751c43eaeaf678f2e64f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoTransportGitAnon: Suppress resource warning about Socket 64/119464/5
David Pursehouse [Thu, 15 Mar 2018 05:09:50 +0000 (14:09 +0900)]
TransportGitAnon: Suppress resource warning about Socket

Change-Id: Id1f5c0db4273324748a0ead2e6dac58d9114cf86
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoFS#runProcess: Fix OutputStream left unclosed after IOException 63/119463/6
David Pursehouse [Thu, 15 Mar 2018 04:44:00 +0000 (13:44 +0900)]
FS#runProcess: Fix OutputStream left unclosed after IOException

The runProcess method creates an OutputStream that is not managed by
a try-with-resource because it's manually closed and any IOException
raised by the close() method is explicitly ignored.

Suppress the resource warning with an explanatory comment.

Enclose the call to StreamGobbler#copy in an inner try-block, and move
the call to close() inside its finally block. This prevents the stream
from being left unclosed if StreamGobbler#copy raises IOException.

Change-Id: Idca9adfc4d87e0989d787ad8239c055c0c849814
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoMerge changes from topic 'If72b4b422-cleanup'
Jonathan Nieder [Fri, 23 Mar 2018 01:01:31 +0000 (21:01 -0400)]
Merge changes from topic 'If72b4b422-cleanup'

* changes:
  UploadPackTest: Fix name hiding introduced by If72b4b422
  Suppress non-localized string warnings introduced by If72b4b422

6 years agoscanPacks to return reftables even if no packs 28/120028/1
Minh Thai [Fri, 23 Mar 2018 00:11:45 +0000 (17:11 -0700)]
scanPacks to return reftables even if no packs

An empty repository may have a dangling symref HEAD pointing to
refs/heads/master.  In this case, there will be a reftable even though
there are no packs yet.

Change-Id: Ib759ffbbfc490953481853e74263dd46d2592888
Signed-off-by: Minh Thai <mthai@google.com>
6 years agoUploadPackTest: Fix name hiding introduced by If72b4b422 46/119646/2
David Pursehouse [Mon, 19 Mar 2018 08:02:16 +0000 (17:02 +0900)]
UploadPackTest: Fix name hiding introduced by If72b4b422

The local variable 'remote' hides the class scope variable
of the same name.

Change-Id: I7410c33678677ce2a14691772466d91e8139e3fa
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoSuppress non-localized string warnings introduced by If72b4b422 45/119645/2
David Pursehouse [Mon, 19 Mar 2018 07:58:05 +0000 (16:58 +0900)]
Suppress non-localized string warnings introduced by If72b4b422

Change-Id: I2e4544d715b4284f544a26f504d01159c5843160
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoPackWriter: Fix Eclipse errors about missing Javadoc 44/119644/2
David Pursehouse [Mon, 19 Mar 2018 07:55:35 +0000 (16:55 +0900)]
PackWriter: Fix Eclipse errors about missing Javadoc

Change If72b4b422 added a new method filterAndAddObject with a
partial Javadoc, which causes errors in Eclipse.

Since it's a private method, Javadoc is not strictly necessary, so
just convert it to a standard comment block.

Bug: 532540
Change-Id: I06aa79211d1223dccf6c931451ca885ca6d39cbc
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoReflogWriter: Refactor to open FileOutputStream in try-with-resource 62/119462/2
David Pursehouse [Thu, 15 Mar 2018 04:32:47 +0000 (13:32 +0900)]
ReflogWriter: Refactor to open FileOutputStream in try-with-resource

Change-Id: I028ced10eecc99214a4c4a8055c379af72193f13
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoPushCommand: Suppress resource warning for Transport in for loop 83/119383/5
David Pursehouse [Wed, 14 Mar 2018 04:11:16 +0000 (13:11 +0900)]
PushCommand: Suppress resource warning for Transport in for loop

A list of Transport instances is provided by Transport.openAll, and
then iterated over in a for loop. Eclipse warns that the Transport
in the for-loop should be managed by try-with-resource.

The Transport is explicitly closed in the finally block, so just
suppress the warning.

Change-Id: I92b73cd90902637cf1ac1ab7b02b5ee5ed6bdb1e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoMerge branch 'stable-4.11' 61/119461/2
David Pursehouse [Fri, 16 Mar 2018 02:59:41 +0000 (11:59 +0900)]
Merge branch 'stable-4.11'

* stable-4.11:
  ObjectIdSerializer: Support serialization of known non-null ObjectId

Change-Id: Ie430fa2c5d13ae698d884a37d0d03884ebbf25ec
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoTeach UploadPack to support filtering by blob size 76/110476/13
Jonathan Tan [Tue, 17 Oct 2017 22:48:53 +0000 (15:48 -0700)]
Teach UploadPack to support filtering by blob size

Teach UploadPack to advertise the filter capability and support a
"filter" line in the request, accepting blob sizes only, if the
configuration variable "uploadpack.allowfilter" is true. This feature is
currently in the "master" branch of Git, and as of the time of writing,
this feature is to be released in Git 2.17.

This is incomplete in that the filter-by-sparse-specification feature
also supported by Git is not included in this patch.

If a JGit server were to be patched with this commit, and a repository
on that server configured with RequestPolicy.ANY or
RequestPolicy.REACHABLE_COMMIT_TIP, a Git client built from the "master"
branch would be able to perform a partial clone.

Change-Id: If72b4b422c06ab432137e9e5272d353b14b73259
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
6 years agoSubmoduleStatusCommand: Open Repository in try-with-resource 87/119387/4
David Pursehouse [Wed, 14 Mar 2018 04:39:23 +0000 (13:39 +0900)]
SubmoduleStatusCommand: Open Repository in try-with-resource

Change-Id: Id65c8a94d43bc01e76733eb2ff87635d0f8a8dc2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRepositoryCache#registerRepository: Refactor to use try-with-resource 86/119386/4
David Pursehouse [Wed, 14 Mar 2018 04:37:44 +0000 (13:37 +0900)]
RepositoryCache#registerRepository: Refactor to use try-with-resource

Change-Id: Iaad45b66cc10ac267f6aed7999cc8dc8c07f92e6
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRepoCommandSymlinkTest#testLinkFileBare: Use try-with-resource 85/119385/4
David Pursehouse [Wed, 14 Mar 2018 04:35:50 +0000 (13:35 +0900)]
RepoCommandSymlinkTest#testLinkFileBare: Use try-with-resource

Change-Id: I72756d92dc5ea54ad009dddb9cebbcd6d1a0b4f8
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRepoCommandTest: Refactor to use try-with-resource 84/119384/4
David Pursehouse [Wed, 14 Mar 2018 04:34:44 +0000 (13:34 +0900)]
RepoCommandTest: Refactor to use try-with-resource

Change-Id: If37ce4447feb431169a75594194a7ef02e362d4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoObjectIdSerializer: Support serialization of known non-null ObjectId 56/119456/3
David Pursehouse [Wed, 14 Mar 2018 23:25:43 +0000 (08:25 +0900)]
ObjectIdSerializer: Support serialization of known non-null ObjectId

The implementation of ObjectIdSerializer, added in change I7599cf8bd,
is not equivalent to the original implementation in Gerrit [1].

The Gerrit implementation provides separate methods to (de)serialize
instances of ObjectId that are known to be non-null. In these methods,
no "marker" is written to the stream. Replacing Gerrit's implementation
with ObjectIdSerializer [2] broke persistent caches because it started
writing markers where they were not expected [3].

Since ObjectIdSerializer is included in JGit 4.11 we can't change the
existing #write and #read methods. Keep those as-is, but extend the
Javadoc to clarify that they support possibly null ObjectId instances.

Add new methods #writeWithoutMarker and #readWithoutMarker to support
the cases where the ObjectId is known to be non-null and the marker
should not be written to the serialization stream.

Also:

- Replace the hard-coded `0` and `1` markers with constants that can
  be linked from the Javadocs.

- Include the marker value in the "Invalid flag before ObjectId"
  exception message.

[1] https://gerrit-review.googlesource.com/c/gerrit/+/9792
[2] https://gerrit-review.googlesource.com/c/gerrit/+/165851
[3] https://gerrit-review.googlesource.com/c/gerrit/+/165952

Change-Id: Iaf84c3ec32ecf83efffb306fdb4940cc85740f3f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoReceivePackAdvertiseRefsHookTest#testSuccess: Open TransportLocal in t-w-r 82/119382/2
David Pursehouse [Wed, 14 Mar 2018 04:05:41 +0000 (13:05 +0900)]
ReceivePackAdvertiseRefsHookTest#testSuccess: Open TransportLocal in t-w-r

Change-Id: I198ff2ff36de482445141b5ce489204a9c2f4933
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoDfsPackCompactor: Open PackWriter in try-with-resource 81/119381/2
David Pursehouse [Wed, 14 Mar 2018 04:01:59 +0000 (13:01 +0900)]
DfsPackCompactor: Open PackWriter in try-with-resource

Change-Id: I2c7b3fdf6a51471c35434a6176865d622b13653d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoDfsPackFile: Refactor getBitmapIndex to open ReadableChannel in try-with-resource 80/119380/2
David Pursehouse [Wed, 14 Mar 2018 03:15:38 +0000 (12:15 +0900)]
DfsPackFile: Refactor getBitmapIndex to open ReadableChannel in try-with-resource

Refactor getBitmapIndex to open ReadableChannel in try-with-resource
instead of closing the channel in the finally block.

The same cannot be done in copyPackThroughCache, so just suppress the
warning with an explanatory comment.

Change-Id: I9b95373d350728e85a159423d5ca80e8b215914d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoIndexDiff: Refactor to open Repository in try-with-resource 79/119379/2
David Pursehouse [Wed, 14 Mar 2018 03:10:50 +0000 (12:10 +0900)]
IndexDiff: Refactor to open Repository in try-with-resource

Change-Id: I667d685ccedc730e786f1e52323fdeba4b91af3e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoDirCache: Suppress resource warning related to TemporaryBuffer 77/119377/3
David Pursehouse [Wed, 14 Mar 2018 01:56:18 +0000 (10:56 +0900)]
DirCache: Suppress resource warning related to TemporaryBuffer

In #writeTo, the TemporaryBuffer can't be opened in try-with-resource
because it's referenced in the finally block. Instead it is explicitly
closed within the try block. Suppress the warning with an explanatory
comment.

Change-Id: I02009f77f9630d5d55afc34eb86d304ff103b8b0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoAdd SilentFileInputStream to allow ignoring exceptions raised by close() 94/119294/6
David Pursehouse [Tue, 13 Mar 2018 07:11:40 +0000 (16:11 +0900)]
Add SilentFileInputStream to allow ignoring exceptions raised by close()

There are several cases where a FileInputStream is opened outside of
a try-with-resource because we want to explicitly close it and ignore
any IOException that is raised by the close() method.

Introduce a helper class, SilentFileInputStream, that overrides the
close method and ignores the exceptions. This allows to open the stream
in a try-with-resource block and remove the explicit handling of the
close method.

Change-Id: I8612f948a1a5b3d1031344922ad75ce4492cfc61
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoWorkingTreeIterator#idSubmodule: Refactor to open Repository in try-with-resource 76/119376/2
David Pursehouse [Wed, 14 Mar 2018 01:19:06 +0000 (10:19 +0900)]
WorkingTreeIterator#idSubmodule: Refactor to open Repository in try-with-resource

Change-Id: I991f0096c833da721b98c1e0423a8dadc67cd64f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoUploadPack: Suppress resource warning about PackWriter 75/119375/2
David Pursehouse [Wed, 14 Mar 2018 00:39:48 +0000 (09:39 +0900)]
UploadPack: Suppress resource warning about PackWriter

PackWriter is auto-closeable and should be opened in try-with-resource,
but this is not possible since the variable is being referenced in the
finally block before being explicitly closed there.

Suppress the warning and add an explanatory comment.

Change-Id: I161923f35142132234fd951c0146d3cb30920b7b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoShowPackDelta: Refactor to use try-with-resource 74/119374/2
David Pursehouse [Wed, 14 Mar 2018 00:35:08 +0000 (09:35 +0900)]
ShowPackDelta: Refactor to use try-with-resource

Remove the resource warning suppression and refactor the code to open
the TemporaryBuffer and InflaterInputStream in a try-with-resource.

Change-Id: I3082e5ac7565c5000d5a4364f750dd0a0952fc6e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoSubmoduleWalk#forIndex: Suppress resource warning and update Javadoc 13/119313/4
David Pursehouse [Tue, 13 Mar 2018 11:31:38 +0000 (20:31 +0900)]
SubmoduleWalk#forIndex: Suppress resource warning and update Javadoc

SubmoduleWalk is auto-closeable, and Eclipse warns that is is not
managed by try-with-resource. However in this case the resource should
not be closed, because the caller needs to use it. Instead, it is the
responsibility of the caller to close it after use.

Update the Javadoc to clarify this, and suppress the warning.

Change-Id: Ib7ba349353bfd3341bdcbe4bb19abaeb9f3aeba5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoSubmoduleWalk: Open Repository in try-with-resource 11/119311/4
David Pursehouse [Tue, 13 Mar 2018 11:24:45 +0000 (20:24 +0900)]
SubmoduleWalk: Open Repository in try-with-resource

Change-Id: Ib29aaf26b49aa94a5a7cc0b0264a0a93ecff0c16
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRepositoryFilter: Refactor doFilter to open Repository in try-with-resource 02/119302/4
David Pursehouse [Tue, 13 Mar 2018 08:55:05 +0000 (17:55 +0900)]
RepositoryFilter: Refactor doFilter to open Repository in try-with-resource

Change-Id: Ic4a056eebe567ff933519d6a805edb7e97c71b22
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoNetRC: Open BufferedReader in try-with-resource 16/119316/3
David Pursehouse [Tue, 13 Mar 2018 11:43:44 +0000 (20:43 +0900)]
NetRC: Open BufferedReader in try-with-resource

Change-Id: Ie0688b0ce19f657834a23438f112569a86491b3b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoPackParser: Refactor to open InputStream in try-with-resource 15/119315/3
David Pursehouse [Tue, 13 Mar 2018 11:41:36 +0000 (20:41 +0900)]
PackParser: Refactor to open InputStream in try-with-resource

Change-Id: I8d002ccc8f168f5891492a4c5742c82f8cb7a0b6
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoAutoLFInputStreamTest: Use try-with-resource 10/119310/3
David Pursehouse [Tue, 13 Mar 2018 11:20:09 +0000 (20:20 +0900)]
AutoLFInputStreamTest: Use try-with-resource

Change-Id: I162bfa6b2f87f2ce9154f3ed6bb628c4cda88f50
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoDfsInserter: Refactor writePackIndex to use try-with-resource 01/119301/3
David Pursehouse [Tue, 13 Mar 2018 08:51:10 +0000 (17:51 +0900)]
DfsInserter: Refactor writePackIndex to use try-with-resource

Refactor to allow the temporary buffer to be opened in try-with-resource.

Change-Id: Id913e6c3ed3913fd5d79d66238b779e0c225b47d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoAmazonS3: Refactor error method to avoid 'should be managed by try-with-resource... 92/119292/2
David Pursehouse [Tue, 13 Mar 2018 07:00:41 +0000 (16:00 +0900)]
AmazonS3: Refactor error method to avoid 'should be managed by try-with-resource' warning

Change-Id: I205fc1c77777870b0a036e52fa9954de5d9f60b5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoCommandCatalog: Simplify scan method using try-with-resource 91/119291/2
David Pursehouse [Tue, 13 Mar 2018 06:56:47 +0000 (15:56 +0900)]
CommandCatalog: Simplify scan method using try-with-resource

The IOExceptions caught in the nested try blocks are all ignored,
so we can just wrap them all up into a single try-with-resource
block.

Change-Id: Id85850b3f54c408af73063220e6fead20cb0fd80
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoTransport: Simplify scan method using try-with-resource 90/119290/2
David Pursehouse [Tue, 13 Mar 2018 06:50:27 +0000 (15:50 +0900)]
Transport: Simplify scan method using try-with-resource

The IOExceptions caught in the nested try blocks are all ignored,
so we can just wrap them all up into a single try-with-resource
block.

Change-Id: I536d682f1017c5088b94ff9f98ffa2b7c783d8bf
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoUse CHARSET in FileOutputStream instead of hard-coded "UTF-8" 87/119287/4
David Pursehouse [Tue, 13 Mar 2018 05:21:29 +0000 (14:21 +0900)]
Use CHARSET in FileOutputStream instead of hard-coded "UTF-8"

Change-Id: I63ad25e1ebd94081c8848f4d21044cf9041f971d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoTemporaryBufferTest: Suppress "should be managed by try-with-resource" 97/119297/2
David Pursehouse [Tue, 13 Mar 2018 08:24:10 +0000 (17:24 +0900)]
TemporaryBufferTest: Suppress "should be managed by try-with-resource"

In most of the tests, the temporary buffer is explicitly destroyed in
a finally block after being closed. This is not possible if using the
try-with-resource construct, because the variable is not accessible in
the finally block scope.

Change-Id: I3bab30695ddd12e1a0ae107989638428fe3ef551
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoOpen auto-closeable resources in try-with-resource 86/119286/4
David Pursehouse [Tue, 13 Mar 2018 02:44:23 +0000 (11:44 +0900)]
Open auto-closeable resources in try-with-resource

When an auto-closeable resources is not opened in try-with-resource,
the warning "should be managed by try-with-resource" is emitted by
Eclipse.

Fix the ones that can be silenced simply by moving the declaration of
the variable into a try-with-resource.

In cases where we explicitly call the close() method, for example in
tests where we are testing specific behavior caused by the close(),
suppress the warning.

Leave the ones that will require more significant refcactoring to fix.
They can be done in separate commits that can be reviewed and tested
in isolation.

Change-Id: I9682cd20fb15167d3c7f9027cecdc82bc50b83c4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoImplement --force option in FetchCommand and CLI fetch command 85/119285/1
Matthias Sohn [Tue, 13 Mar 2018 01:20:29 +0000 (02:20 +0100)]
Implement --force option in FetchCommand and CLI fetch command

Change-Id: I42cdb57b8fb54ce466d1958391f12f911045327f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoMerge "Introduce SshSupport to centralize SSH related utility code"
Matthias Sohn [Mon, 12 Mar 2018 23:52:43 +0000 (19:52 -0400)]
Merge "Introduce SshSupport to centralize SSH related utility code"

6 years agoIntroduce SshSupport to centralize SSH related utility code 51/118951/2
Markus Duft [Thu, 8 Mar 2018 07:29:03 +0000 (08:29 +0100)]
Introduce SshSupport to centralize SSH related utility code

As discussed with Thomas here:
https://git.eclipse.org/r/#/c/83506/31/org.eclipse.jgit.lfs/src/org/eclipse/jgit/lfs/SmudgeFilter.java@349

Move the code from ConfigureGerritAfterCloneTask to SshSupport and
eliminate the slightly modified copy of the code from
LfsConnectionFactory. Separate EGit commit will eliminate the code from
ConfigureGerritAfterCloneTask.

Change-Id: Ifb5adb1342e0fc1f2a70cddf693408d4e0ef7906
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
6 years agoUploadPack: Remove redundant suppression of deprecation warning 89/119189/1
David Pursehouse [Mon, 12 Mar 2018 01:52:03 +0000 (10:52 +0900)]
UploadPack: Remove redundant suppression of deprecation warning

Change-Id: I9a7f46e1da42fd86adedc18b3394d5f755722624
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoConsistently use Constants.CHARSET rather than StandardCharsets.UTF_8 47/118947/4
David Pursehouse [Thu, 8 Mar 2018 00:44:01 +0000 (09:44 +0900)]
Consistently use Constants.CHARSET rather than StandardCharsets.UTF_8

Change-Id: I6714fc3666e1bced22abba94ceb700477349586e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoConstants: Initialize CHARSET and CHARACTER_ENCODING from StandardCharsets.UTF_8 45/118945/4
David Pursehouse [Thu, 8 Mar 2018 00:42:02 +0000 (09:42 +0900)]
Constants: Initialize CHARSET and CHARACTER_ENCODING from StandardCharsets.UTF_8

Change-Id: Ib4e0a35429892fa1581db09a9b77717120d03275
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
6 years agoRemove deprecated LfsProtocolServlet#getLargeFileRepository 28/119128/2
Matthias Sohn [Fri, 9 Mar 2018 23:57:57 +0000 (00:57 +0100)]
Remove deprecated LfsProtocolServlet#getLargeFileRepository

Use LfsProtocolServlet##getLargeFileRepository(LfsRequest, String,
String) instead.

Change-Id: If68d06f2e6edbf843dc9d3b4e3b99c33b0fab766
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove deprecated Lfs#Lfs(Path) 27/119127/2
Matthias Sohn [Fri, 9 Mar 2018 23:56:04 +0000 (00:56 +0100)]
Remove deprecated Lfs#Lfs(Path)

Use Lfs#Lfs(Repository) instead.

Change-Id: I7303987ed047b42fd1bac8e27ed49333080e556b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove deprecated StreamCopyThread#flush 26/119126/2
Matthias Sohn [Fri, 9 Mar 2018 23:54:51 +0000 (00:54 +0100)]
Remove deprecated StreamCopyThread#flush

StreamCopyThread: Do not let flush interrupt a write.
flush calls interrupt() to interrupt a pending read and trigger a
flush.  Unfortunately that interrupt() call can also interrupt a
pending write, putting Jsch in a bad state and triggering "Short read
of block" errors.

Change-Id: I11f8a014fd72df06617cc8731d992eb14cc32a67
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
6 years agoRemove deprecated SafeBufferedOutputStream 25/119125/2
Matthias Sohn [Fri, 9 Mar 2018 23:52:22 +0000 (00:52 +0100)]
Remove deprecated SafeBufferedOutputStream

Use Java 8 BufferedOutputStream instead. Java 8 fixed the silent flush
during close issue by FilterOutputStream (base class of
BufferedOutputStream) using try-with-resources to close the stream,
getting a behavior matching what JGit's SafeBufferedOutputStream
was doing

Change-Id: Ieeab59f49b44519585abda213d287b19c7863b17
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>