]> source.dussan.org Git - jgit.git/log
jgit.git
7 years agoUpdate Oxygen Orbit p2 repository to R20170516192513 80/103080/1
Matthias Sohn [Mon, 14 Aug 2017 21:37:21 +0000 (23:37 +0200)]
Update Oxygen Orbit p2 repository to R20170516192513

Change-Id: I7f1b733ca414d77c9df5572df02e742e0a84ba2f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoMerge branch 'stable-4.5' into stable-4.6 17/94717/1
David Pursehouse [Sun, 9 Apr 2017 08:22:30 +0000 (17:22 +0900)]
Merge branch 'stable-4.5' into stable-4.6

* stable-4.5:
  Prepare 4.5.3-SNAPSHOT builds
  JGit v4.5.2.201704071617-r

Change-Id: I4e1915d3a88e15c9ef1fb2b470b7f3b821243ff5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoPrepare 4.5.3-SNAPSHOT builds 05/94705/1
Matthias Sohn [Fri, 7 Apr 2017 22:31:09 +0000 (00:31 +0200)]
Prepare 4.5.3-SNAPSHOT builds

Change-Id: I69681b7a5687ca76bd0dd5d3e7ce2cff841d0e32
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoJGit v4.5.2.201704071617-r 00/94700/1 v4.5.2.201704071617-r
Matthias Sohn [Fri, 7 Apr 2017 20:17:27 +0000 (22:17 +0200)]
JGit v4.5.2.201704071617-r

Change-Id: I66402643d7c84c90bf5cefed4d2ec3aa68c94cfb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpdate Jetty to 9.3.17.v20170317 57/94257/2
Matthias Sohn [Sat, 1 Apr 2017 10:38:22 +0000 (12:38 +0200)]
Update Jetty to 9.3.17.v20170317

Update to the latest 9.3 version until we have a solution for bug 514336
we face with 9.4.x versions.

Change-Id: I6d8d476abe8677ce865a08099bb77330effc700a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoRevert "Update Jetty to 9.4.1.v20170120 in buck build" 56/94256/1
Matthias Sohn [Sat, 1 Apr 2017 11:03:48 +0000 (13:03 +0200)]
Revert "Update Jetty to 9.4.1.v20170120 in buck build"

This reverts commit d3b80b951c0bf995f7d210710e3d31e9d529efe2.

Change-Id: I596ba596f3e857346020e01b0a018d90a0b27edd

7 years agoRevert "Update Jetty to 9.4.1.v20170120" 93/94193/1
David Pursehouse [Fri, 31 Mar 2017 05:49:30 +0000 (14:49 +0900)]
Revert "Update Jetty to 9.4.1.v20170120"

This reverts commit e05caf91f1df86a95d3e0454000d345bb90a415e.

Change-Id: Ia4287f130034a790759b5035505a093b4616a05a

7 years agoMerge branch 'stable-4.5' into stable-4.6 62/93862/1
David Pursehouse [Mon, 27 Mar 2017 01:14:50 +0000 (10:14 +0900)]
Merge branch 'stable-4.5' into stable-4.6

* stable-4.5:
  Only mark packfile invalid if exception signals permanent problem
  Don't flag a packfile invalid if opening existing file failed
  Prepare 4.5.2-SNAPSHOT builds

Change-Id: I20b50981adc54c426666015ff04fe3bb1db9abd9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoOnly mark packfile invalid if exception signals permanent problem 44/93844/5
Matthias Sohn [Sat, 25 Mar 2017 01:33:06 +0000 (02:33 +0100)]
Only mark packfile invalid if exception signals permanent problem

Add NoPackSignatureException and UnsupportedPackVersionException to
explicitly mark permanent unrecoverable problems with a pack

Assume problem with a pack is permanent only if we are sure the
exception signals a non-transient problem we can't recover from:
- AccessDeniedException: we lack permissions
- CorruptObjectException: we detected corruption
- EOFException: file ended unexpectedly
- NoPackSignatureException: pack has no pack signature
- NoSuchFileException: file has gone missing
- PackMismatchException: pack no longer matches its index
- UnpackException: unpacking failed
- UnsupportedPackIndexVersionException: unsupported pack index version
- UnsupportedPackVersionException: unsupported pack version

Do not attempt to handle Errors since they are thrown for serious
problems applications should not try to recover from.

Change-Id: I2c416ce2b0e23255c4fb03a3f9a0ee237f7a484a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoDon't flag a packfile invalid if opening existing file failed 75/93775/4
Luca Milanesio [Fri, 24 Mar 2017 00:18:12 +0000 (00:18 +0000)]
Don't flag a packfile invalid if opening existing file failed

A packfile random file open operation may fail with a
FileNotFoundException even if the file exists, possibly
for the temporary lack of resources.

Instead of managing the FileNotFoundException as any generic
IOException it is best to rethrow the exception but prevent
the packfile for being flagged as invalid until it is actually
opened and read successfully or unsuccessfully.

Bug: 514170
Change-Id: Ie37edba2df77052bceafc0b314fd1d487544bf35
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoPrepare 4.5.2-SNAPSHOT builds 43/93843/1
Matthias Sohn [Sat, 25 Mar 2017 00:21:58 +0000 (01:21 +0100)]
Prepare 4.5.2-SNAPSHOT builds

Change-Id: I8485de1f3f63dc9ec445b8fb08093ca144aedc59
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoMerge branch 'stable-4.5' into stable-4.6 87/93587/1
David Pursehouse [Wed, 22 Mar 2017 00:44:42 +0000 (09:44 +0900)]
Merge branch 'stable-4.5' into stable-4.6

* stable-4.5:
  JGit v4.5.1.201703201650-r

Change-Id: Ic9dda2317456308c222928cb8453cb00a231eea1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoJGit v4.5.1.201703201650-r 58/93458/1 v4.5.1.201703201650-r
Matthias Sohn [Mon, 20 Mar 2017 20:44:47 +0000 (21:44 +0100)]
JGit v4.5.1.201703201650-r

Change-Id: I88de7c9f52abbc4921a82208ed74d22aa19fb3cd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoMerge branch 'stable-4.5' into stable-4.6 64/93164/2
Matthias Sohn [Wed, 15 Mar 2017 23:12:49 +0000 (00:12 +0100)]
Merge branch 'stable-4.5' into stable-4.6

* stable-4.5:
  Don't remove pack when FileNotFoundException is transient

Change-Id: Ic17c542d78a4cad48ff1ed77dcdc853a4ef2dc06
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoDon't remove pack when FileNotFoundException is transient 64/92864/4
Luca Milanesio [Fri, 10 Mar 2017 00:20:23 +0000 (00:20 +0000)]
Don't remove pack when FileNotFoundException is transient

The FileNotFoundException is typically raised in three conditions:
1. file doesn't exist
2. incompatible read vs. read/write open modes
3. filesystem locking
4. temporary lack of resources (e.g. too many open files)

1. is already managed, 2. would never happen as packs are not
overwritten while with 3. and 4. it is worth logging the exception and
retrying to read the pack again.

Log transient errors using an exponential backoff strategy to avoid
flooding the logs with the same error if consecutive retries to access
the pack fail repeatedly.

Bug: 513435
Change-Id: I03c6f6891de3c343d3d517092eaa75dba282c0cd
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoPrepare 4.6.2-SNAPSHOT builds 53/92553/1
Matthias Sohn [Tue, 7 Mar 2017 19:49:24 +0000 (20:49 +0100)]
Prepare 4.6.2-SNAPSHOT builds

Change-Id: I8835f79145e6a989787d47322c3d8cb9baf0624a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoJGit v4.6.1.201703071140-r 35/92535/1 v4.6.1.201703071140-r
Matthias Sohn [Tue, 7 Mar 2017 16:40:32 +0000 (17:40 +0100)]
JGit v4.6.1.201703071140-r

Change-Id: I842dc95313e5b47b0b7ec983c4a0a91915ed4183
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpdate Jetty to 9.4.1.v20170120 in buck build 32/92432/1
Jonathan Nieder [Sun, 26 Feb 2017 23:09:04 +0000 (15:09 -0800)]
Update Jetty to 9.4.1.v20170120 in buck build

5e8e2179b218ede7d14b69dc5149b0691b5859cf (Update Jetty to
9.4.1.v201470120, 2017-01-26) updated Jetty in the maven build.
Update the buck build to match so buck builds work again.

The buck build will go away soon, but in the meantime (until the bazel
build gets the same level of support) it is convenient as a faster way
of running tests than using maven.

The bazel build doesn't need this change since it doesn't build or run
http tests yet.

Change-Id: Ibbdaf2880e76b32fc9f6b5605a2ff29e3deffda2
(cherry picked from commit 2470f01d0f8bca4c8c754475846c83b9f99c93b8)

7 years agoUpdate Jetty to 9.4.1.v20170120 31/92431/1
Matthias Sohn [Thu, 26 Jan 2017 00:03:16 +0000 (01:03 +0100)]
Update Jetty to 9.4.1.v20170120

MappedLoginService is no longer available in Jetty 9.4 therefore base
TestLoginService on AbstractLoginService.

Apparently Jetty now uses slf4j hence adapt RecordingLogger accordingly
so we can log error messages containing slf4j style formatting anchors
"{}".

Change-Id: Ibb36aba8782882936849b6102001a88b699bb65c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
(cherry picked from commit 5e8e2179b218ede7d14b69dc5149b0691b5859cf)

7 years agoUpdate build to use Tycho 1.0.0 30/92430/1
Matthias Sohn [Wed, 15 Feb 2017 22:44:12 +0000 (23:44 +0100)]
Update build to use Tycho 1.0.0

Change-Id: I10f61962e1496f079a39e0f533506816be56e925
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
(cherry picked from commit 92d8c9bec2bd990cec937b3a6c5f4ab4011d3f73)

7 years agoUpdate minimum JDK version in README 29/92429/1
David Pursehouse [Fri, 10 Feb 2017 06:58:26 +0000 (15:58 +0900)]
Update minimum JDK version in README

Change-Id: I655d896b268e946e3492661b08add0ebac22c6f0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
(cherry picked from commit 67da5635a47ad7680b3c60358a1fec080eef7d1e)

7 years agoGC: delete empty directories after purging loose objects 24/89824/3
Matthias Sohn [Mon, 30 Jan 2017 00:24:45 +0000 (01:24 +0100)]
GC: delete empty directories after purging loose objects

In order to limit the number of directories we check for emptiness only
consider fanout directories which contained unreferenced loose objects
we deleted in the same gc run.

Change-Id: Idf8d512867ee1c8ed40bd55752122ce83a98ffa2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoGC.prune(Set<ObjectId>): return early if objects directory is empty 23/89823/1
Matthias Sohn [Sun, 29 Jan 2017 23:52:33 +0000 (00:52 +0100)]
GC.prune(Set<ObjectId>): return early if objects directory is empty

Change-Id: Id56b102604c4e0437230e3e7c59c0a3a1b676256
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoClean up orphan files in GC 95/89395/8
Hongkai Liu [Mon, 23 Jan 2017 16:33:40 +0000 (11:33 -0500)]
Clean up orphan files in GC

An orphan file is either a bitmap or an idx file in pack folder,
and its corresponding pack file is missing.

Change-Id: I3c4cb1f7aa99dd7b398bdb8d513f528d7761edff
Signed-off-by: Hongkai Liu <hongkai.liu@ericsson.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpdate Orbit to S20170120205402 and com.jcraft.jsch to 0.1.54 60/89560/1
Matthias Sohn [Sat, 21 Jan 2017 08:32:00 +0000 (09:32 +0100)]
Update Orbit to S20170120205402 and com.jcraft.jsch to 0.1.54

CQ: 12553
Change-Id: Ie72b48d00f363e3dc05b9733018a6ddca32c3e6e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoFix preparation of 4.6.1-SNAPSHOT builds 59/89559/1
Matthias Sohn [Mon, 23 Jan 2017 19:29:20 +0000 (20:29 +0100)]
Fix preparation of 4.6.1-SNAPSHOT builds

Change-Id: Ib241c4f45192672712526599898c0bd0bd356436
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpdate tycho version to 0.26 45/87745/1
Matthias Sohn [Mon, 26 Dec 2016 22:21:46 +0000 (23:21 +0100)]
Update tycho version to 0.26

Change-Id: I1cf3402c057de89d1afe161d2d4106896fa8753f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpdate maven plugins 29/87729/2
Matthias Sohn [Sat, 24 Dec 2016 14:50:39 +0000 (15:50 +0100)]
Update maven plugins

Change-Id: I2d18f69d25362f565df071c320970cbc973199cd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoSkip javadoc generation for org.eclipse.jgit.http.test 28/87728/1
Matthias Sohn [Sat, 24 Dec 2016 14:50:22 +0000 (15:50 +0100)]
Skip javadoc generation for org.eclipse.jgit.http.test

This fixes the error the javadoc plugin raises when generating the maven
site for this bundle.

Change-Id: I72026aa33be86960747a246af4a70f6a91b40102
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoPrepare 4.6.1-SNAPSHOT builds 27/87727/1
Matthias Sohn [Sat, 24 Dec 2016 14:51:54 +0000 (15:51 +0100)]
Prepare 4.6.1-SNAPSHOT builds

Change-Id: I6b05a6f6c3f92365c272e1bdaf76093ca01f2d58
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoJGit v4.6.0.201612231935-r 21/87721/1 v4.6.0.201612231935-r
Matthias Sohn [Sat, 24 Dec 2016 00:42:38 +0000 (01:42 +0100)]
JGit v4.6.0.201612231935-r

Change-Id: Iaa88fe1b195dfe6be99a7b4cb064684e75563715
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoMerge branch 'stable-4.5' 20/87720/1
Matthias Sohn [Fri, 23 Dec 2016 23:29:31 +0000 (00:29 +0100)]
Merge branch 'stable-4.5'

* origin/stable-4.5:
  Fix one case of missing object

Change-Id: Ia6384f4be71086d5a0a8c42c7521220f57dfd086
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leak in IndexDiff 85/87385/2
Matthias Sohn [Mon, 19 Dec 2016 07:45:49 +0000 (08:45 +0100)]
[infer] Fix resource leak in IndexDiff

We only need the tree id to add it to a TreeWalk so change tree's type
to AnyObjectId.

Bug: 509385
Change-Id: I98dd5fef15cd173fe1fd84273f0f48e64e12e608
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leak in ObjectChecker 46/87446/2
Matthias Sohn [Tue, 20 Dec 2016 00:08:38 +0000 (01:08 +0100)]
[infer] Fix resource leak in ObjectChecker

Bug: 509385
Change-Id: I6b6ff5b721d959eb0708003a40c8f97d6826ac46
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix a resource leak in PackWriter 84/87384/1
Matthias Sohn [Mon, 19 Dec 2016 07:38:41 +0000 (08:38 +0100)]
[infer] Fix a resource leak in PackWriter

Bug: 509385
Change-Id: Ic8a82895fa39be73f1bd8427cfe9437be6fc4e3e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leaks in DfsInserter 83/87383/1
Matthias Sohn [Sun, 18 Dec 2016 23:02:43 +0000 (00:02 +0100)]
[infer] Fix resource leaks in DfsInserter

Bug: 509385
Change-Id: Id5dc40bb3fb9da97ea0795cca1f2bcdcde347767
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leak in ManifestParser 66/87366/5
Matthias Sohn [Sun, 18 Dec 2016 11:06:55 +0000 (12:06 +0100)]
[infer] Fix resource leak in ManifestParser

Bug: 509385
Change-Id: Icfe58ac2e5344546448a55ad14ec082356be968c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leak in RepoCommand 67/87367/5
Matthias Sohn [Sun, 18 Dec 2016 00:54:51 +0000 (01:54 +0100)]
[infer] Fix resource leak in RepoCommand

Bug: 509385
Change-Id: I30c427f0dd2fc1fceb6b003dfdee0a05efaefca9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leak in DirCache 65/87365/5
Matthias Sohn [Sun, 18 Dec 2016 00:42:24 +0000 (01:42 +0100)]
[infer] Fix resource leak in DirCache

Bug: 509385
Change-Id: I5f914c910ef3a7583594fb31c7757d3dddf6a05e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix SubmoduleWalk leaks in submodule commands 64/87364/4
Matthias Sohn [Sun, 18 Dec 2016 00:37:01 +0000 (01:37 +0100)]
[infer] Fix SubmoduleWalk leaks in submodule commands

Bug: 509385
Change-Id: I4cba81d8ea596800a40799dc9cb763fae01fe508
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leaks in SubmoduleAddCommand 63/87363/4
Matthias Sohn [Sun, 18 Dec 2016 00:33:58 +0000 (01:33 +0100)]
[infer] Fix resource leaks in SubmoduleAddCommand

Bug: 509385
Change-Id: I9d25cf117cfb19df108f5fe281232193fd898474
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leaks in RebaseCommand 62/87362/3
Matthias Sohn [Sun, 18 Dec 2016 00:24:56 +0000 (01:24 +0100)]
[infer] Fix resource leaks in RebaseCommand

Bug: 509385
Change-Id: I9fbdfda59f7bc577aab55dc92ff897b00b5cb050
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years ago[infer] Fix resource leak in BlameCommand 61/87361/2
Matthias Sohn [Sun, 18 Dec 2016 00:10:25 +0000 (01:10 +0100)]
[infer] Fix resource leak in BlameCommand

Bug: 509385
Change-Id: Ic57fd3bf940752229e35102e7761823f7d3d8732
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoIgnore infer output folder 60/87360/2
Matthias Sohn [Sun, 18 Dec 2016 00:26:29 +0000 (01:26 +0100)]
Ignore infer output folder

Infer [1] is a static code checker.

[1] http://fbinfer.com/

Change-Id: I880cefe0a20f6af88ab10f6e862fda44fbe0883d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpdate maven-source-plugin to 3.0.1 to fix OOM during build 76/87376/1
Matthias Sohn [Sun, 18 Dec 2016 09:37:47 +0000 (10:37 +0100)]
Update maven-source-plugin to 3.0.1 to fix OOM during build

Recently we frequently suffer from OutOfMemoryError when creating source
archives in the Maven build. maven-source-plugin 3.0.0 has a bug [1]
causing OOM which is fixed in 3.0.1.

[1] https://issues.apache.org/jira/browse/MSOURCES-94

Change-Id: Ie900bd546c42523c5a04e22bd3d3f510d2a81ca2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoFix one case of missing object 57/87057/1
Hector Oswaldo Caballero [Tue, 13 Dec 2016 12:38:39 +0000 (07:38 -0500)]
Fix one case of missing object

When a repository is being GCed and a concurrent push is received, there
is the possibility of having a missing object. This is due to the fact
that after the list of objects to delete is built, there is a window of
time when an unreferenced and ready to delete object can be referenced
by the incoming push. In that case, the object would be deleted because
there is no way to know it is no longer unreferenced. This will leave
the repository in an inconsistent state and most of the operations fail
with a missing tree/object error.

Given the incoming push change the last modified date for the now
referenced object, verify this one is still a candidate to delete
before actually performing the delete operation.

Change-Id: Iadcb29b8eb24b0cb4bb9335b670443c138a60787
Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
7 years agoFix FileSnapshot.isModified 38/86738/5
Christian Halstrick [Thu, 8 Dec 2016 14:44:23 +0000 (15:44 +0100)]
Fix FileSnapshot.isModified

FileSnapshot.isModified may have reported a file to be clean although it
was actually dirty.

Imagine you have a FileSnapshot on file f. lastmodified and lastread are
both t0. Now time is t1 and you
1) modify the file
2) update the FileSnapshot of the file (lastModified=t1, lastRead=t1)
3) modify the file again
4) wait 3 seconds
5) ask the Filesnapshot whether the file is dirty or not. It erroneously
answered it's clean.

Any file which has been modified longer than 2.5 seconds ago was
reported to be clean. As the test shows that's not always correct.

The real-world problem fixed by this change is the following:
* A gerrit server using JGit to serve git repositories is processing
fetch requests while simultaneously a native git garbage collection
runs on the repo.
* At time t1 native git writes temporary files in the pack folder
setting the mtime of the pack folder to t1.
* A fetch request causes JGit to search for new packfiles and JGit
remembers this scan in a Filesnapshot on the packs folder. Since the gc
is not finished JGit doesn't see any new packfiles.
* The fetch is processed and the gc ends while the filesystem timer is
still t1. GC writes a new packfile and deletes the old packfile.
* 3 seconds later another request arrives. JGit does not yet know about
the new packfile but is also not rescanning the pack folder because it
cached that the last scan happened at time t1 and pack folder's mtime is
also t1. Now JGit will not be able to resolve any object contained in
this new pack. This behavior may be persistent if objects referenced by
the ref/meta/config branch are affected so gerrit can't read permissions
stored in the refs/meta/config branch anymore and will not allow any
pushes anymore. The pack folder will not change its mtime and therefore
no rescan will take place.

Change-Id: I3efd0ccffeb97b01207dc3e7a6b85c6b06928fad
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoDecide whether to "Accept-Encoding: gzip" on a request-by-request basis 47/85647/12
Zhen Chen [Wed, 23 Nov 2016 00:39:27 +0000 (16:39 -0800)]
Decide whether to "Accept-Encoding: gzip" on a request-by-request basis

When the reply is already compressed (e.g. a packfile fetched using dumb
HTTP), "Content-Encoding: gzip" wastes bandwidth relative to sending the
content raw. So don't "Accept-Encoding: gzip" for such requests.

Change-Id: Id25702c0b0ed2895df8e9790052c3417d713572c
Signed-off-by: Zhen Chen <czhen@google.com>
7 years agoConfigure max heap size for Maven build 06/86806/1
Matthias Sohn [Fri, 9 Dec 2016 10:02:10 +0000 (11:02 +0100)]
Configure max heap size for Maven build

We faced many OOM errors on Hudson recently, so increase maximum heap size.

Change-Id: I81d4d562a06afcd8b4ff7d1f69c4d7f12099afad
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoUpgrade errorprone to 2.0.15 23/86423/3
David Pursehouse [Tue, 6 Dec 2016 05:02:42 +0000 (14:02 +0900)]
Upgrade errorprone to 2.0.15

Change-Id: I05d3e12178f8f0b5a687c8e09c2dcf80580acfb4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoReplace usage of deprecated EWAHCompressedBitmap.add(long) 84/86684/2
David Pursehouse [Thu, 8 Dec 2016 02:10:35 +0000 (11:10 +0900)]
Replace usage of deprecated EWAHCompressedBitmap.add(long)

The add(long) method was deprecated in favor of addWord(long) in
the 0.8.3 release of JavaEWAH [1].

[1] https://github.com/lemire/javaewah/commit/e443cf5e

Change-Id: I89c397ed02e040f57663d04504399dfdc0889626
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoExpose getObjectToTransfer method of FileLfsServlet 68/85668/3
Jacek Centkowski [Thu, 24 Nov 2016 09:58:14 +0000 (10:58 +0100)]
Expose getObjectToTransfer method of FileLfsServlet

Providing own implementation to doGet/doPut methods is troublesome when
this method is private.

Change-Id: I098cdc5cb90410eaaebc56c88c2d9e168584dd6d
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoMerge branch 'stable-4.5' 32/86432/1
David Pursehouse [Tue, 6 Dec 2016 07:55:16 +0000 (16:55 +0900)]
Merge branch 'stable-4.5'

* stable-4.5:
  Use the same variable to check and extract LFS object id

Change-Id: I314bd4373f40843c68853b3999f60d85e08628d9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoUpgrade buck to latest version 17/86117/1
David Pursehouse [Thu, 1 Dec 2016 06:57:17 +0000 (15:57 +0900)]
Upgrade buck to latest version

The latest version removes dependency on `realpath` which is not
available by default on OSX.

This upgrades buck to the same version used on Gerrit master.

Change-Id: I584211986be4e64f68d4eb905c09d3c5d60133e7
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
7 years agoFix merge-base calculation 80/85580/5
Christian Halstrick [Wed, 23 Nov 2016 11:52:16 +0000 (12:52 +0100)]
Fix merge-base calculation

Fix JGits merge-base calculation in case of inconsistent commit times.
JGit was potentially failing to compute correct merge-bases when the
commit times where inconsistent (a parent commit was younger than a
child commit). The code in MergeBaseGenerator was aware of the fact that
sometimes the discovery of a merge base x can occur after the parents of
x have been seen (see comment in #carryOntoOne()). But in the light of
inconsistent commit times it was possible that these parents of a
merge-base have already been returned as a merge-base.

This commit fixes the bug by buffering all commits generated by
MergeBaseGenerator. It is expected that this buffer will be small
because the number of merge-bases will be small. Additionally a new
flag is used to mark the ancestors of merge-bases. This allows to filter
out the unwanted commits.

Bug: 507584
Change-Id: I9cc140b784c3231b972bd2c3de61a789365237ab

7 years agoConfigure Maven to run tests concurrently by default 30/85730/1
Matthias Sohn [Thu, 24 Nov 2016 23:43:11 +0000 (00:43 +0100)]
Configure Maven to run tests concurrently by default

Maven 3.3.1 or later supports sharing project specific command line
options
https://maven.apache.org/docs/3.3.1/release-notes.html

Change-Id: I61ddf08ff8c0ebb76fc2e1d0a0cd5902c65f9469
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoEnable error-prone for the Maven build 29/85729/1
David Pursehouse [Fri, 18 Nov 2016 01:30:27 +0000 (17:30 -0800)]
Enable error-prone for the Maven build

- update maven-compiler-plugin to 3.6.0
- exclude InsecureCipherFactory from errorprone checks

See
https://maven.apache.org/guides/mini/guide-default-execution-ids.html#Example:_Configuring_compile_to_run_twice
https://groups.google.com/d/topic/error-prone-discuss/pzT45ZMCQOc/discussion

Change-Id: Ic16d3f15cf2ef40de62fe6bfe4b8b35f0c1edc4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
7 years agoFix encoding of LFSPointer files 68/84668/4
Christian Halstrick [Tue, 8 Nov 2016 12:42:34 +0000 (13:42 +0100)]
Fix encoding of LFSPointer files

LFS pointer files have to be UTF-8 with \n as line ending character.
That is described in [1]. Fix JGit to follow this rules.

[1] https://github.com/github/git-lfs/blob/master/docs/spec.md

Bug: 507120
Change-Id: Ib6bd13f1cc17f1a3de125249b4f250b7b0692396

7 years agoUse the same variable to check and extract LFS object id 71/85671/1
Jacek Centkowski [Thu, 24 Nov 2016 10:32:48 +0000 (11:32 +0100)]
Use the same variable to check and extract LFS object id

It is easier to maintain when the same variable is used for both check
and extraction of LFS object id.

Change-Id: I5406f9bc4a085aa164c4565a9667ad2925105190
Signed-off-by: Jacek Centkowski <geminica.programs@gmail.com>
7 years agoSpecify RevisionSyntaxException message in Repository#resolve 52/85552/3
Grace Wang [Wed, 23 Nov 2016 02:05:39 +0000 (21:05 -0500)]
Specify RevisionSyntaxException message in Repository#resolve

This does not address all cases where no message is specified, only
cases where Repository#isValidRefName returns false.

Change-Id: Ib88cdabfdcdf37be0053e06949b0e21ad87a9575
Signed-off-by: Grace Wang <gracewang92@gmail.com>
7 years agoAdd missing @since tags for new API 37/85637/1
Matthias Sohn [Wed, 23 Nov 2016 22:29:41 +0000 (23:29 +0100)]
Add missing @since tags for new API

Change-Id: I900d745195f58c067fadf209bb92cd3c852c59f4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
8 years agodump HTTP: Avoid being confused by Content-Length of a gzipped stream 45/85545/5
Zhen Chen [Tue, 22 Nov 2016 23:53:06 +0000 (15:53 -0800)]
dump HTTP: Avoid being confused by Content-Length of a gzipped stream

TransportHttp sets 'Accept-Encoding: gzip' to allow the server to
compress HTTP responses. When fetching a loose object over HTTP, it
uses the following code to read the response:

       InputStream in = openInputStream(c);
       int len = c.getContentLength();
       return new FileStream(in, len);

If the content is gzipped, openInputStream decompresses it and produces
the correct content for the object. Unfortunately the Content-Length
header contains the length of the compressed stream instead of the
actual content length. Use a length of -1 instead since we don't know
the actual length.

Loose objects are already compressed, so the gzip encoding typically
produces a longer compressed payload. The value from the Content-Length
is too high, producing EOFException: Short read of block.

Change-Id: I8d5284dad608e3abd8217823da2b365e8cd998b0
Signed-off-by: Zhen Chen <czhen@google.com>
Helped-by: Jonathan Nieder <jrn@google.com>
8 years agoMerge "Close input stream after use"
Jonathan Nieder [Tue, 22 Nov 2016 20:38:05 +0000 (15:38 -0500)]
Merge "Close input stream after use"

8 years agoFix content length in HttpClientConnection 27/85527/4
Zhen Chen [Tue, 22 Nov 2016 01:15:15 +0000 (17:15 -0800)]
Fix content length in HttpClientConnection

Per the interface specification, the getContentLength method should
return -1 if content length is unknown or greater than
Integer.MAX_VALUE.

For chunked transfer encoding, the content length is not included in the
header, hence will cause a NullPointerException when trying to parse the
content length header.

Change-Id: Iaa36b5c146a8d654e364635fa0bd2d14129baf17
Signed-off-by: Zhen Chen <czhen@google.com>
8 years agoClose input stream after use 29/85529/1
Zhen Chen [Tue, 22 Nov 2016 19:59:32 +0000 (11:59 -0800)]
Close input stream after use

The InputStream in FileStream in downloadPack is never closed.

Change-Id: I59975d0b8d51f4b3e3ba9d4496b254d508cb936d
Signed-off-by: Zhen Chen <czhen@google.com>
8 years agoDefine MonotonicClock interface for advanced timestamps 06/85106/9
Shawn Pearce [Wed, 16 Nov 2016 01:34:07 +0000 (17:34 -0800)]
Define MonotonicClock interface for advanced timestamps

MonotonicClock can be implemented to provide more certainity about
time than the standard System.currentTimeMillis() can provide. This
can be used by classes such as PersonIdent and Ketch to rely on
more certainity about time moving in a strictly ascending order.

Gerrit Code Review can also leverage this interface through its
embedding of JGit and use MonotonicClock and ProposedTimestamp to
provide stronger assurance that NoteDb time is moving forward.

Change-Id: I1a3cbd49a39b150a0d49b36d572da113ca83a786

8 years agoAdd Oxygen target platform and remove target platforms older than Mars 80/85180/2
Matthias Sohn [Wed, 16 Nov 2016 23:28:05 +0000 (00:28 +0100)]
Add Oxygen target platform and remove target platforms older than Mars

Change-Id: I196c3c95dafa5ea5f165d20aaac2ce07a2c53631
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
8 years agoUpdate JavaEWAH to 1.1.6 04/77604/3
Dave Borowitz [Wed, 20 Jul 2016 14:16:26 +0000 (10:16 -0400)]
Update JavaEWAH to 1.1.6

Use Oxygen M3 Orbit repository which provides the bundles built using
the new orbit-recipe based build.

CQ: 11658
Change-Id: I7f3dcc966732b32830c75d5daa55383bd028d182
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
8 years agoAdd missing @since tags for new API 21/85021/2
Matthias Sohn [Mon, 14 Nov 2016 23:57:00 +0000 (00:57 +0100)]
Add missing @since tags for new API

Change-Id: Iaf83f66637d6a13e4a6d096ba8529553af7e30ed
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
8 years agoFix cryptoVer constant name to CRYPTO_VER 17/85017/2
Shawn Pearce [Mon, 14 Nov 2016 22:52:46 +0000 (14:52 -0800)]
Fix cryptoVer constant name to CRYPTO_VER

Change-Id: I46c39f2eceb4d58e49bd6273b87711f35250ab5c

8 years agoRepositoryCache: simplify code 16/85016/2
Shawn Pearce [Mon, 14 Nov 2016 22:52:23 +0000 (14:52 -0800)]
RepositoryCache: simplify code

The type parameters can now be inferred when creating
ConcurrentHashMap.

A for loop over the keys of a ConcurrentHashMap doesn't
need to use an Iterator<Map.Entry>; loop syntax handles
this just fine over keySet().

Change-Id: I1f85bb81b77f7cd1caec77197f2f0bf78e4a82a1

8 years agoAdd missing @Override found by ErrorProne 15/85015/2
Shawn Pearce [Mon, 14 Nov 2016 22:51:08 +0000 (14:51 -0800)]
Add missing @Override found by ErrorProne

Change-Id: I585242507815aad4aa0103fd55a6c369e342ab33

8 years agoDeprecate SafeBufferedOutputStream 40/84940/4
Shawn Pearce [Sun, 13 Nov 2016 19:24:41 +0000 (11:24 -0800)]
Deprecate SafeBufferedOutputStream

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:

  try {
    flush();
  } finally {
    out.close();
  }

With Java 8 as the minimum required version to run JGit
it is no longer necessary to override close() or have
this class. Deprecate the class, and use the JRE's version
of close.

Change-Id: Ic0584c140010278dbe4062df2e71be5df9a797b3

8 years agoMerge "Support {get,set}GitwebDescription on InMemoryRepository"
David Pursehouse [Mon, 14 Nov 2016 22:54:15 +0000 (17:54 -0500)]
Merge "Support {get,set}GitwebDescription on InMemoryRepository"

8 years agoSupport {get,set}GitwebDescription on InMemoryRepository 10/85010/2
Shawn Pearce [Mon, 14 Nov 2016 21:59:59 +0000 (13:59 -0800)]
Support {get,set}GitwebDescription on InMemoryRepository

This simplifies testing for Gerrit Code Review where
application code is updating the repository description
and the test harness uses InMemoryRepository.

Change-Id: I9fbcc028ae24d90209a862f5f4f03e46bfb71db0

8 years agoOrganize imports 02/85002/1
David Pursehouse [Mon, 14 Nov 2016 21:25:20 +0000 (13:25 -0800)]
Organize imports

Change-Id: I7c545d06b1bced678c020fab9af1382bc4416b6e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
8 years agoAdd {get,set}GitwebDescription to Repository 94/84994/4
Shawn Pearce [Mon, 14 Nov 2016 19:00:34 +0000 (11:00 -0800)]
Add {get,set}GitwebDescription to Repository

This method pair allows the caller to read and modify the description
file that is traditionally used by gitweb and cgit when rendering a
repository on the web.

Gerrit Code Review has offered this feature for years as part of
its GitRepositoryManager interface, but its fundamentally a feature
of JGit and its Repository abstraction.

git-core typically initializes a repository with a default value
inside the description file. During getDescription() this string
is converted to null as it is never a useful description.

Change-Id: I0a457026c74e9c73ea27e6f070d5fbaca3439be5

8 years agoMerge "Don't serialize internal hash collision chain link"
Shawn Pearce [Mon, 14 Nov 2016 18:27:09 +0000 (13:27 -0500)]
Merge "Don't serialize internal hash collision chain link"

8 years agoMerge "Reduce synchronized scope around ConcurrentHashMap"
Shawn Pearce [Mon, 14 Nov 2016 18:25:36 +0000 (13:25 -0500)]
Merge "Reduce synchronized scope around ConcurrentHashMap"

8 years agoMerge changes Id89b3cd0,I5b0fb122
Shawn Pearce [Mon, 14 Nov 2016 18:23:36 +0000 (13:23 -0500)]
Merge changes Id89b3cd0,I5b0fb122

* changes:
  FileLfsServlet: Make sendError protected
  Make ObjectUploadListener public

8 years agoMerge "StreamCopyThread: Remove unused AtomicInteger import"
Jonathan Nieder [Mon, 14 Nov 2016 00:05:48 +0000 (19:05 -0500)]
Merge "StreamCopyThread: Remove unused AtomicInteger import"

8 years agoStreamCopyThread: Remove unused AtomicInteger import 51/84951/1
Jonathan Nieder [Mon, 14 Nov 2016 00:01:16 +0000 (16:01 -0800)]
StreamCopyThread: Remove unused AtomicInteger import

I forgot to do this in 97f3baa0d3df7ed26a55b2240cc5ce1a04861a4c
(StreamCopyThread: Remove unnecessary flushCount, 2016-11-13).

Change-Id: Iaed9f345848cf0f854c9d0debcf94bc831d53054

8 years agoMerge "Extract insecure Cipher factory"
Matthias Sohn [Mon, 14 Nov 2016 00:00:24 +0000 (19:00 -0500)]
Merge "Extract insecure Cipher factory"

8 years agoMerge "Get rid of SoftReference in RepositoryCache"
Jonathan Nieder [Sun, 13 Nov 2016 23:43:54 +0000 (18:43 -0500)]
Merge "Get rid of SoftReference in RepositoryCache"

8 years agoExtract insecure Cipher factory 41/84941/2
Shawn Pearce [Sun, 13 Nov 2016 19:52:12 +0000 (11:52 -0800)]
Extract insecure Cipher factory

Bazel runs ErrorProne by default and ErrorProne rightly complains that
allowing the user to specify any Cipher can lead to insecure code
(in particular, getCipher("AES") operates in ECB mode). Unfortunately
this is required to support existing repositories insecurely stored
on S3.

Extract the insecure factory code to its own class so this can be built
as a java_library() with this check disabled.

Change-Id: I34f381965bdaa25d5aa8ebf6d8d5271b238334e0

8 years agoFileLfsServlet: Make sendError protected 33/84933/2
David Pursehouse [Wed, 9 Nov 2016 02:30:15 +0000 (11:30 +0900)]
FileLfsServlet: Make sendError protected

Change-Id: Id89b3cd0da86a535946feb15254737bbf8d855d4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
8 years agoMake ObjectUploadListener public 32/84932/2
David Pursehouse [Sat, 12 Nov 2016 21:22:24 +0000 (13:22 -0800)]
Make ObjectUploadListener public

Change-Id: I5b0fb1220bc0e5c660f1b5373abc5868d985c60b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
8 years agoStreamCopyThread: flush cannot interrupt a write 45/84945/2
Jonathan Nieder [Sun, 13 Nov 2016 21:26:33 +0000 (13:26 -0800)]
StreamCopyThread: flush cannot interrupt a write

Because flush calls interrupt with writeLock held, it cannot interrupt
a write.  Simplify by no longer defending against that.

Change-Id: Ib0b39b425335ff7b0ea1b1733562da5392576a15

8 years agoStreamCopyThread: Remove unnecessary flushCount 44/84944/1
Jonathan Nieder [Sun, 13 Nov 2016 21:16:48 +0000 (13:16 -0800)]
StreamCopyThread: Remove unnecessary flushCount

StreamCopyThread#run consistently interrupts itself whenever it
discovers it has been interrupted by StreamCopyThread#flush while not
reading.  The flushCount is not needed to avoid lost flushes.

All in-tree users of StreamCopyThread never flush.  As a nice side
benefit, this avoids the expense of atomic operations that have no
purpose for those users.

Change-Id: I1afe415cd09a67f1891c3baf712a9003ad553062

8 years agoMerge "Switch JSchSession to simple isolated OutputStream"
Shawn Pearce [Sun, 13 Nov 2016 21:13:02 +0000 (16:13 -0500)]
Merge "Switch JSchSession to simple isolated OutputStream"

8 years agoGet rid of SoftReference in RepositoryCache 43/84743/2
Hugo Arès [Wed, 9 Nov 2016 13:49:41 +0000 (08:49 -0500)]
Get rid of SoftReference in RepositoryCache

Now that RepositoryCache have a time based eviction strategy, get rid
of the strategy to evict cache entries if heap memory is running low,
i.e. soft references. Main reason why time based eviction was
implemented was to offer an alternative to the unpredictable soft
references.

Relying on soft references is not working, especially in large heap. The
JVM GC will consider collecting soft references as last resort before
throwing an out of memory error. For example, an application like Gerrit
configured with a 128GB heap, GC will wait until all 128GB is filled
before collecting the soft references so the application will be
suffering long pauses caused by GC for a long time already. In other
words, you will have to restart application because it's unusable before
JVM eviction kicks in.

Keeping the SoftReference in RepositoryCache is causing more harm than
good. If you use the time based eviction (which is the default strategy)
and want to tune JVM to release soft references more aggressively, it
will release repositories from the cache even though they are not
expired which defeats the purpose of the repository cache.

Gerrit uses Lucene library which uses soft references and this is
causing a "memory leak" except if you configure JVM to release soft
references more aggressively which have the nasty side effect of
evicting non expired repositories from the cache.

Change-Id: I9940bd800464c7f007696d0ccde52ea617b2ebce
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
8 years agoSwitch JSchSession to simple isolated OutputStream 34/84934/4
Shawn Pearce [Sun, 13 Nov 2016 01:06:39 +0000 (17:06 -0800)]
Switch JSchSession to simple isolated OutputStream

Work around issues with JSch not handling interrupts by
isolating the JSch interactions onto another thread.

Run write and flush on a single threaded Executor using
simple Callable operations wrapping the method calls,
waiting on the future to determine the outcome before
allowing the caller to continue.

If any operation was interrupted the state of the stream
becomes fuzzy at close time. The implementation tries to
interrupt the pending write or flush, but this is very
likely to corrupt the stream object, so exceptions are
ignored during such a dirty close.

Change-Id: I42e3ba3d8c35a2e40aad340580037ebefbb99b53

8 years agoWalkEncryption: Cleanup Java 8 support 36/84936/2
Shawn Pearce [Sun, 13 Nov 2016 07:01:13 +0000 (23:01 -0800)]
WalkEncryption: Cleanup Java 8 support

Java 8 is now the minimum for JGit, so Java 7
only paths are not necessary.

Change-Id: I0151625fed4d0da95321ebed5cca648b8c29d5f1

8 years agoReduce synchronized scope around ConcurrentHashMap 65/84565/2
Philipp Marx [Sat, 12 Nov 2016 10:11:19 +0000 (11:11 +0100)]
Reduce synchronized scope around ConcurrentHashMap

Change-Id: I982a78070efb6bc2d3395330456d62e0d5ce6da7
Signed-off-by: Philipp Marx <smigfu@googlemail.com>
8 years agoCheck that DfsBlockCache#blockSize is a power of 2 69/84569/5
Philipp Marx [Fri, 11 Nov 2016 09:43:09 +0000 (10:43 +0100)]
Check that DfsBlockCache#blockSize is a power of 2

In case a value is used which isn’t a power of 2 there will be a high
chance of java.lang.ArrayIndexOutBoundsException and
org.eclipse.jgit.errors.CorruptObjectException due to a mismatching
assumption for the DfsBlockCache#blockSizeShift parameter.

Change-Id: Ib348b3704edf10b5f93a3ffab4fa6f09cbbae231
Signed-off-by: Philipp Marx <smigfu@googlemail.com>
8 years agoFix loop in auto gc 28/84628/1
Matthias Sohn [Mon, 7 Nov 2016 21:31:10 +0000 (22:31 +0100)]
Fix loop in auto gc

* GC.tooManyLooseObjects() always responded true since the loop missed
to advance the iterator so it always incremented until the threshold was
exceeded.
* Also fix loop exit criterion which was off by 1.
* Add some tests.

Change-Id: I70976dfaa026efbcf3c46bd45941f37277a18e04
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
8 years agoUpdate buck to latest version 58/84458/2
David Pursehouse [Fri, 4 Nov 2016 11:09:00 +0000 (20:09 +0900)]
Update buck to latest version

Update to the same version used on Gerrit's master branch.

Change-Id: I20e4edd099a095c42f23df8cc57241efad2de2ce
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
8 years agoStreamCopyThread: Do not drop data when flush is observed before writing 13/84513/2
Jonathan Nieder [Fri, 4 Nov 2016 22:59:32 +0000 (15:59 -0700)]
StreamCopyThread: Do not drop data when flush is observed before writing

StreamCopyThread.flush was introduced in
61645b938bc934fda3b0624c5bac1e3495634750 (Add timeouts to smart
transport clients, 2009-06-19) to support timeouts on write in JSch.
The commit message from that change explains:

   JSch made a timeout on write difficult because they explicitly do
   a catch for InterruptedException inside of their OutputStream.  We
   have to work around that by creating an additional thread that just
   shuttles data between our own OutputStream and the real JSch stream.

The code that runs on that thread is structured as follows:

while (!done) {
int n = src.read(buf);
dst.write(buf, 0, n);
}

with src being a PipedInputStream representing the data to be written
to JSch.  To add flush support, that change wanted to add an extra step

if (wantFlush)
dst.flush();

but to handle the case where the thread is blocked in the read() call
waiting for new input, it needs to interrupt the read. So that is how
it works: the caller runs

pipeOut.write(some data);
pipeOut.flush();
copyThread.flush();

to write some data and force it to flush by interrupting the read.

After the pipeOut.flush(), the StreamCopyThread reads the data that was
written and prepares to copy it out.  If the copyThread.flush() call
interrupts the copyThread before it acquires writeLock and starts
writing, we throw away the data we just read to fulfill the flush.
Oops.

Noticed during the review of e67d59df3fb8ae1efe94a54efce36784f7cc83e8
(StreamCopyThread: Do not let flush interrupt a write, 2016-11-04),
which introduced this bug.

Change-Id: I4aceb5610e1bfb251046097adf46bca54bc1d998

8 years agoStreamCopyThread: Do not let flush interrupt a write 97/84497/2
Jonathan Nieder [Fri, 4 Nov 2016 18:48:38 +0000 (11:48 -0700)]
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.  Add locking to ensure the flush only interrupts
reads as intended.

Change-Id: Ib105d9e107ae43549ced7e6da29c22ee41cde9d8

8 years agoFix flush call race condition in StreamCopyThread 61/84261/1
Zhen Chen [Mon, 31 Oct 2016 21:27:36 +0000 (14:27 -0700)]
Fix flush call race condition in StreamCopyThread

If there was a new flush() call during flush previous bytes, we need to
catch it in order to process the new bytes between the two flush()
calls instead of going to last catch IOException clause and end the
thread.

Change-Id: Ibc58a1fa97559238c13590aedbb85e482d85e465
Signed-off-by: Zhen Chen <czhen@google.com>