Commit Graph

4123 Commits

Author SHA1 Message Date
David Pursehouse f527d4548f InitCommand: Don't leave Repository open after Git is closed
The InitCommand returns a Git that is instantiated with the newly
created Repository, but the Repository is not closed with the Git
resulting in resource leaks.

Create the Git with `closeRepo` set to true, such that the Repository
is also closed when the Git is closed.

Adjust the tests to use try-with-resource on the Git instance.

Change-Id: Ib26e7428c7d8840956d1edb09e53b93e23e6fe5a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-14 14:09:40 +09:00
Terry Parker 9530c10192 Add a minimum negotiation feature for fetch
Android an Chrome have several repos with >300k refs. We sometimes see
negotiations of >100k rounds. This change provides a "minimal negotiation"
feature on the client side that limits how many "have" lines the client
sends. The client extracts the current SHA-1 values for the refs in its
wants set, and terminates negotiation early when all of those values have
been sent as haves. If a new branch is being fetched then that set will
be empty and the client will terminate after current default minimum
of two rounds.

This feature is gated behind a "fetch.useminimalnegotiation" configuration
flag, which defaults to false.

Change-Id: Ib12b095cac76a59da6e8f72773c4129e3b32ff2b
Signed-off-by: Terry Parker <tparker@google.com>
2018-02-12 14:03:11 -08:00
Terry Parker 302596cc67 Add negotiation statistics to PackStatistics
Add fetch statistics for the counts of advertised refs, wants and haves.
Also add the duration in milliseconds for the negotiation phase. For
non-bidirectional transports like HTTP, this is the time for the final
round that sends the pack back to the user.

Change-Id: I1af7ffd3cb7b62182340682e2a243691ea24ec2e
Signed-off-by: Terry Parker <tparker@google.com>
2018-02-12 13:59:42 -08:00
Minh Thai 5efc3dcc6c MergedReftable to skip shadowed refs in same reftable
This would allow compact and GC process to clean up duplicate ref names in the reftables.

Change-Id: I2b9df0bf72dba63cc3525e374982e60559a776c2
Signed-off-by: Minh Thai <mthai@google.com>
2018-02-09 09:49:24 -08:00
Christian Halstrick 4d5231f001 Fix CleanCommand not to throw FileNotFoundExceptions
When CleanCommand is collecting the files and folders to be deleted
it may happen that the list of directories contains obsolete entries.
E.g. a folder and its parent folder may be in the list. Only the
parent folder would be sufficient.

This was a reason for hitting FileNotFoundExceptions when finally
trying to delete the files and folders. Improve CleanCommand
to ignore files to be deleted which are already gone.

Bug: 514434
Change-Id: I10caa01bfb9cec5967dfdaea50c6e4a713eeeabd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-08 10:27:21 +01:00
Hector Caballero 93654f75a2 GC: Remove empty references folders
After packaging references, the folders containing these references are
not deleted. In a busy repository, this causes operations to slow down
as traversing the references tree becomes longer.

Delete empty reference folders after the loose references have been
packed.
To avoid deleting a folder that was just created by another concurrent
operation, only delete folders that were not modified in the last 30
seconds.

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: Ie79447d6121271cf5e25171be377ea396c7028e0
2018-02-07 18:37:12 -05:00
David Ostrovsky ab1b97234d Bazel: Support building with Java 9
Bazel@HEAD supports Java 9.

The current code has one single issue with Java 9 compliance: the usage
of javax.xml.bind.DatatypeConverter class for printHexBinary() method.
This class is not available on Java 9. One alternative is to use guava
library. Something similar was done here: [1]. But unlike the case with
checkstyle library, JGit currently doesn't use guava. Instead, we add
java.xml.bind module with --add-modules compiler option.

To build (or test) with Java 9, build custom bazel version and issue:

  $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \
    --javacopt='--release 9' \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 :all

The Java 9 support is backwards compatible.

* [1] https://github.com/checkstyle/checkstyle/issues/5027

Change-Id: I2c5203fc4e65885ce7b210f824fda85ba6d6c51d
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
2018-02-07 17:51:35 -05:00
Hector Caballero 6766fc85d0 GC: Merge if statement with the enclosing one
Reported by Sonar.

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: Ib6fe6c67d6f7697e6d60693d5cee7e9c6a227767
2018-02-06 08:41:41 -05:00
Hector Caballero 4644d15bc5 GC: Replace Files methods with File alternatives
The Files.exists method has noticeably poor performance in JDK 8 and can
slow an application significantly when used to check files that do not
actually exist. The same goes for Files.notExists, Files.isDirectory and
Files.isRegularFile [1].

Replace them with their File counterpart.

[1] https://rules.sonarsource.com/java/tag/performance/RSPEC-3725

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I89d23b9cc74bec8e05f6b7f3e49bfd967dbb6373
2018-02-06 08:39:43 -05:00
Hector Caballero 66127d4284 GC: Replace anonymous classes with lambdas
Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: Ic9725bdb1a281c80055a5438a02d961b1d1875f4
2018-02-06 06:29:29 -05:00
Hector Caballero 54053389ef GC: Simplify lambda
filter() stream operation also accepts a lambda expression.

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: Ie0b7fe43d39593172969fd16c3e44b49bac27306
2018-02-06 06:28:10 -05:00
Hector Caballero e00a12f5a2 GC: Simplify reference equals() method
Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I5b2e12e012d5423e9b84c1c66a478960121ea212
2018-02-06 06:26:14 -05:00
Hector Caballero f58c3fce90 GC: Simplify boolean expression
Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I0e7a365c26b2333627fcc26b9ea9f4fcd65e8746
2018-02-06 06:25:57 -05:00
Hector Caballero 6ca4c79063 GC: Simplify expression
Avoid converting path to file to then reconvert it to path.

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I6a8c3ca9b83bf9b0eead9506938f5d68b27a76f5
2018-02-06 06:25:32 -05:00
Hector Caballero 049417d504 GC: Remove redundant type arguments
Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: Id3281a744b08f9d7b2b60f69b4e461b053ac5d02
2018-02-06 06:25:17 -05:00
Hector Caballero e3b73d889c GC: Remove unnecessary continue statement
continue is unnecessary when it is the last statement in a loop

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I12af9f9a0bb2fd7fc0239f1f3b59fb8e64e1f351
2018-02-06 06:24:40 -05:00
Matthias Sohn f7244b81cc Close RevWalk in BranchTrackingStatus.of()
Bug: 530757
Change-Id: I985ee5395e1468981c28ae0a80797732e2f528d2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-06 01:10:26 +01:00
David Turner be2a8ed63b Basic submodule merge handling
This doesn't handle the really hard thing, which is merging spurious
conflicts inside .gitmodules files.  That's OK: git.git doesn't
either.  Users can resolve the conflict themselves and then commit
the merge.

Previously, jgit would crash when attempting to merge conflicting
submodule changes.  Even if there was no conflict, after a merge which
adds submodules, the repository would have been missing empty
directories for newly-added submodules.

This patch fixes the crash, and adds the empty directories where
necessary. It ensures that the index is in a conflicted state when
submodule changes conflict.

Reported-by: Alexey Korobkov
Bug: 494551
Change-Id: I79db6798c2bdcc1159b5b2589b02da198dc906a1
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-04 15:33:24 +01:00
David Pursehouse 595f968b6d Add class to access WindowCache statistics
Change-Id: Iacb5b65539efd92a6b45afc307ebf246e8b8fccf
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-03 22:30:41 +01:00
Thomas Wolf f22a162c47 Use a TemporaryBuffer to do a content merge
This avoids having to re-read the merged file (twice even!) to
update the index.

Change-Id: Id13e0fd38906ed6f859604f86ca352761dca9ffe
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-02-02 10:50:12 +01:00
Thomas Wolf 9ac415aa95 Fix index blob for merges with CRLF translations
Commit fc7d407 corrected line endings for working tree files resulting
from merges when CRLF translations are to be done. However, that also
resulted in the file content being put as-is into the index, which is
wrong. The index must contain the file content with reverse CRLF
translations applied.

With core.autocrlf=true, the working tree file should have CR-LF, but
the index blob must still contain only LF.

Fix this oversight and apply the inverse translation when updating the
index, similar to what is done in AddCommand.

Bug: 499615
Change-Id: I3a33931318bdb580b2390f3450f91ea8f258a6a4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-02-02 08:16:13 +01:00
Thomas Wolf fc7d407d0b Honor CRLF settings when writing merge results
Merges are performed using the raw text as stored in the git
repository. When we write the merge result, we must apply the
correct CRLF settings. Otherwise the line endings in the result
will be wrong.

Bug: 499615
Change-Id: I37a9b987e9404c97645d2720cd1c7c04c076a96b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-02 00:45:32 +01:00
David Pursehouse 9ce7e8e767 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Minor fixes in three error messages

Change-Id: Ibd6bcecb40a6d97c46c66360020dca7453876298
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-01 17:36:10 +09:00
Thomas Wolf 3d6455331d Minor fixes in three error messages
* Fix "can not" -> "cannot" in two messages
* Re-word "Cannot mkdir" to "Cannot create directory"

Change-Id: Ide0cec55eeeebd23bccc136257c80f47638ba858
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-01-31 14:29:49 +09:00
Thomas Wolf 6eb053734d Minor fixes in three error messages
* Fix "can not" -> "cannot" in two messages
* Re-word "Cannot mkdir" to "Cannot create directory"

Change-Id: Ide0cec55eeeebd23bccc136257c80f47638ba858
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-01-30 07:36:37 +01:00
Thomas Wolf e12c6b58ee Minor improvements in git config file inclusions
* Section and key names in git config files are case-insensitive.
* If an include directive is invalid, include the line in the
  exception message.
* If inclusion of the included file fails, put the file name into
  the exception message so that the user knows in which file the
  problem is.

Change-Id: If920943af7ff93f5321b3d315dfec5222091256c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-01-28 16:13:04 +01:00
Markus Duft 1c43af8b97 Progress reporting for checkout
The reason for the change is LFS: when using a lot of LFS files,
checkout can take quite some time on larger repositories. To avoid
"hanging" UI, provide progress reporting.

Also implement (partial) progress reporting for cherry-pick, reset,
revert which are using checkout internally.

The feature is also useful without LFS, so it is independent of it.

Change-Id: I021e764241f3c107eaf2771f6b5785245b146b42
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-01-23 00:48:00 +01:00
Dave Borowitz 14167272c2 Enforce DFS blockLimit is a multiple of blockSize
Change-Id: I2821124ff88d7d1812a846ed20f3828fc9123b38
2018-01-22 10:36:58 -05:00
David Pursehouse bd96feab24 Revert usage of TYPE_USE in Nullable and NonNull annotations
Using TYPE_USE causes compilation errors in Eclipse Neon.3 (JDT 3.12.3)
and Eclipse Oxygen.2 (JDT 3.13.2).

This reverts commit 8e217517e2.
This reverts commit 55eba8d0f5.

Reported-by: Thomas Wolf <thomas.wolf@paranor.ch>
Change-Id: I96869f80dd11ee238911706581b224bca4fb12cd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-01-19 22:42:38 +09:00
David Pursehouse 8e217517e2 Nullable: Switch to TYPE_USE
Since JGit now requires Java 8, we can switch to TYPE_USE instead
of explicitly specifying the target type.

Some of the existing uses of Nullable need to be reworked slightly
as described in [1] to prevent the compilation error:

  scoping construct cannot be annotated with type-use annotation

[1] https://stackoverflow.com/a/21385939/381622

Change-Id: Idba48f67a09353b5237685996ce828c8ca398168
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-01-18 13:35:44 +09:00
David Pursehouse 55eba8d0f5 NonNull: Switch to TYPE_USE
Since JGit now requires Java 8, we can switch to TYPE_USE instead
of explicitly specifying the target type.

Change-Id: I373d47c3d92507459685789df1fad0933d5625ff
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-01-18 13:23:34 +09:00
David Pursehouse cd2489423d NonNull: Fix typo in javadoc
Change-Id: Ia8e6559047a12391223645e2768f46666f198f6d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-01-18 13:19:52 +09:00
David Pursehouse 94cf82dbc5 RevWalk: Annotate methods documented to return "Never null" as @NonNull
Change-Id: If1a1bed4b04dd48c9573fd3c4eacbf73de40622f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-01-18 10:45:07 +09:00
Zhen Chen 5452ac1dea Skip broken symbolic ref in DfsReftableDatabase
We skipped the broken symbolic reference in other implementation like
DfsRefDatabase, RefDirectory. The broken symbolic reference may cause
NPE when caller forget to have a null check against the object id before
calling parse it.

Change-Id: If5e07202e9ee329d0bd9488936d79c98143c7ad9
Signed-off-by: Zhen Chen <czhen@google.com>
2018-01-17 15:19:05 -08:00
Han-Wen Nienhuys f40ebed124 Make SideBandInputStream public
This mirrors SideBandOutputStream which is also public

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Ic0983af663f0c4c85bf5486b195108c45cddc4c2
2018-01-17 11:20:09 +01:00
Matthias Sohn 28aa3be21b Merge branch 'stable-4.10'
* stable-4.10:
  Revert handling of ssh IdentityFile to pre-4.9 behavior
  Prepare 4.10.1-SNAPSHOT builds
  JGit v4.10.0.201712302008-r

Change-Id: I13797f064de919c257feb8e96da226d7b1faaf7a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-01-13 01:06:42 +01:00
Matthias Sohn e72b2771a0 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Revert handling of ssh IdentityFile to pre-4.9 behavior

Change-Id: I7cd2f0fe93be5193d6de2a376a023bdece5d84a9
2018-01-13 00:51:28 +01:00
Thomas Wolf bea3b46678 Revert handling of ssh IdentityFile to pre-4.9 behavior
Jsch caches keys (aka identities) specified in ~/.ssh/config via
IndentityFile only for the current Jsch Session. This results in
multiple password prompts for successive sessions.

Do the handling of IdentityFile exclusively in JGit, as it was before
4.9. JGit uses different Jsch instances per host and caches the
IdentityFile there, allowing it to be re-used in different sessions
for the same host.

* Add comments to explain this.
* Move the JschBugFixingConfig from OpenSshConfig to
  JschConfigSessionFactory to have all these Jsch work-arounds
  in one place.
* Make that config hide the IdentityFile config from Jsch to avoid
  that Jsch overrides the JGit behavior.

Bug: 529173
Change-Id: Ib36c34a2921ba736adeb64de71323c2b91151613
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-01-12 12:56:00 +01:00
David Pursehouse 338d0a81bb RefDirectory#hasLooseRef: Fix stream resource leak reported by error-prone
Error-prone reports:

  [StreamResourceLeak] Streams that encapsulate a closeable resource
  should be closed using try-with-resources

Change-Id: I86154fba2b896723feaecf8991ed3c8e96ea2499
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-01-10 16:39:20 +09:00
Dave Borowitz 1c16ea4601 Ensure DirectoryStream is closed promptly
From the javadoc for Files.list:

"The returned stream encapsulates a DirectoryStream. If timely disposal
of file system resources is required, the try-with-resources construct
should be used to ensure that the stream's close method is invoked
after the stream operations are completed."

This is the only call to Files#newDirectoryStream that is not already in
a try-with-resources.

Change-Id: I91e6c56b5d74e8435457ad6ed9e6b4b24d2aa14e
2018-01-05 13:02:47 -05:00
Matthias Sohn cdc88247b9 Add com.jcraft.jzlib 1.1.1
com.jcraft.jsch requires com.jcraft.jzlib to provide optional zlib
packet compression support. Add this library so that jgit can handle
packet compression.

CQ: 15292
Bug: 529129
Change-Id: I0297bd0488753547a5f5d47dbf0db508a79dd265
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-01-04 13:53:29 -05:00
Matthias Sohn 992980d856 Merge "Fix file handle leak in FetchCommand#fetchSubmodules" 2018-01-04 06:45:00 -05:00
Tim Hosey 67a8858b94 Fix file handle leak in FetchCommand#fetchSubmodules
The private fetchSubmodules method in the FetchCommand class creates a
Repository instance for each submodule being fetched, but never calls
closes on it.

This leads to the leaking of file handles.

Bug: 526494
Change-Id: I7070388b8b62063d9d5cd31afae3015a8388044f
Signed-off-by: Tim Hosey <timhoseydev@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-01-04 02:58:05 +01:00
Zhen Chen 21d22e6f63 Skip unborn branches in UploadPack
The ObjectId of an unborn branch is null, skip those in UploadPack.

Change-Id: I7cbf66b05dff98c4fe9f33e20a647ba6acf364b2
Signed-off-by: Zhen Chen <czhen@google.com>
2018-01-03 14:21:05 -08:00
Matthias Sohn 5a4b6fd237 Prepare 4.11.0-SNAPSHOT builds
Change-Id: I5d5e2befcf530d93457d44684bd9e4fc2392e5eb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-31 04:05:07 +01:00
Matthias Sohn 757fecd697 Prepare 4.10.1-SNAPSHOT builds
Change-Id: I139fb660c4630d9d073eabf37ff26ea3a823bcbd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-31 03:22:35 +01:00
Matthias Sohn 55bf5a6c11 JGit v4.10.0.201712302008-r
Change-Id: I9cc3a839d906acd01829df1de64cfafca8a6d008
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-31 02:08:55 +01:00
Marc Strapetz 8779092716 WorkingTreeIterator should pass FS to submodules
Change-Id: I4b7bc6bab449b9e3aebba8170788ff9e4a04195a
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-30 00:27:14 +01:00
Marc Strapetz de49edbffb CloneCommand: option to set FS to be used
Change-Id: If8342974d07b7d89a6c5721a6dd03826886aa89e
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-29 23:46:01 +01:00
Marc Strapetz 0213a71a82 InitCommand: option to set FS to be used
Change-Id: I95c72f3bdc2da748adbb0d82af72f60650821aab
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-29 23:46:00 +01:00
Marc Strapetz 2352561bfb TransportLocal should reuse FS from source repo
This is necessary to make sure that the FS set to e.g. the
CloneCommand will be passed on and used by the new repository

Change-Id: I9f81f65df784099b07e548b91482e7ace3f5a17e
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-29 12:37:24 +01:00
David Turner 243fba9a0a Add a command to deinitialize submodules
Change-Id: Iaaefc2cbafbf083d6ab158b1c378ec69cc76d282
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-27 23:47:25 +01:00
David Turner 4bbc74ba40 Use submodule name instead of path as key in config
When a submodule is moved, the "name" field remains the same, while
the "path" field changes.  Git uses the "name" field in .git/config
when a submodule is initialized, so this patch makes JGit do so too.

Change-Id: I48d8e89f706447b860c0162822a8e68170aae42b
Signed-off-by: David Turner <dturner@twosigma.com>
2017-12-27 22:55:54 +01:00
Marc Strapetz 8cc783ca7d URIish: support for empty ports
Properly parse URLs like "ssh://host:/path"

Bug: 519187
Change-Id: I0054868e30509e4ba919444be16c2a20f741545a
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-23 21:18:12 +01:00
Karsten Thoms 3832527b02 Add header Automatic-Module-Name for Java 9
Bug: 529075
Change-Id: I4532ce2c80eb91531d46026676502d636ccda706
Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-23 01:00:01 +01:00
Matthias Sohn 32775124d1 Merge branch 'stable-4.9'
* stable-4.9:
  Strings#convertGlob: fix escaping of patterns like [\[].

Change-Id: I18d55537002b3153db35f8a6b60f2f5317d17248
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-23 00:36:54 +01:00
Dmitry Pavlenko 279eaf0690 Strings#convertGlob: fix escaping of patterns like [\[].
Originally the patterns were escaped twice leading
to wrong matching results.

Bug: 528886
Change-Id: I26e201b4b0ef51cac08f940b76f381260fa925ca
Signed-off-by: Dmitry Pavlenko <pavlenko@tmatesoft.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-21 18:33:22 -05:00
Dave Borowitz 83a7a3482e Merge changes I0f1df93b,Ifd40129b,I1b059e1a
* changes:
  ConfigTest: Add some additional comment parsing tests
  Config: Drop backslash in invalid escape sequences in subsections
  Config: Match C git behavior more closely in escaping values
2017-12-21 12:01:04 -05:00
Dave Borowitz d8a24ac1cf Merge branch 'stable-4.9'
* stable-4.9:
  Make PackInserter public

Change-Id: I367c6111661f3005419e2becd695e04e65202f97
2017-12-21 11:12:13 -05:00
Dave Borowitz 085d1f9599 Make PackInserter public
The intent with the setCompressionLevel and checkExisting methods (which
are already public) is for callers to be able to call them, but they
can't do that if the class itself is not public.

Change-Id: I014044fec3bfa1d33775500345efd60eb5d45bde
2017-12-21 09:46:55 -05:00
Dave Borowitz be224f8d4c Config: Drop backslash in invalid escape sequences in subsections
These are ignored by C git when parsing:

$ git config -f - --list <<EOF
[foo "x\0y"]
bar = baz
[foo "x\qy"]
bar = baz
[foo "x\by"]
bar = baz
[foo "x\ny"]
bar = baz
[foo "x\ty"]
bar = baz
EOF
foo.x0y.bar=baz
foo.xqy.bar=baz
foo.xby.bar=baz
foo.xny.bar=baz
foo.xty.bar=baz

This behavior is different from value parsing, where an invalid escape
sequence is an error (which JGit already does as well):

$ git config -f - --list <<EOF
[foo]
bar = x\qy
EOF
fatal: bad config line 2 in standard input

Change-Id: Ifd40129b37d9a62df3d886d8d7e22f766f54e9d1
2017-12-21 09:30:52 -05:00
Dave Borowitz fa24425c60 Config: Match C git behavior more closely in escaping values
So this happened:

$ git config -f foo.config foo.a 'x"y'
$ git config -f foo.config foo.b x\\y
$ git config -f foo.config foo.c $'x\ny'
$ git config -f foo.config foo.d $'x\ty'
$ git config -f foo.config foo.e $'x\by'
$ cat foo.config
[foo]
        a = x\"y
        b = x\\y
        c = x\ny
        d = x\ty
        e = y

That last line is my shell interpreting the backspace byte:

$ python -c 'print repr(open("foo.config").read())'
'[foo]\n\ta = x\\"y\n\tb = x\\\\y\n\tc = x\\ny\n\td = x\\ty\n\te = x\x08y\n'

Change-Id: I1b059e1afb544c39ddb587c07bf79a06e99d0a09
2017-12-21 09:30:52 -05:00
Matthias Sohn 2464fa440f Fix remaining javadoc errors raised by doclint
For now ignore doclint "missing" warnings.

Change-Id: I0e5af7a757f4d92ffeeb113f30576a35414d6781
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-21 02:42:14 +01:00
Matthias Sohn fdbaa25db9 Fix javadoc in org.eclipse.jgit util packages
Change-Id: Ia655f45153bcf1d422ffffce6dcf914847e14c4c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-20 22:10:11 +01:00
Matthias Sohn c4207c5fbe Fix javadoc in org.eclipse.jgit treewalk package
Change-Id: I1f9d9a005c7228c9881762a78228accad2c7a6d4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-20 22:10:10 +01:00
Matthias Sohn 781e106a26 Fix javadoc in org.eclipse.jgit transport package
Change-Id: Id70e2c27e38bf12f87e66b28fbd0b06908494764
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-20 22:10:09 +01:00
Dave Borowitz c1a02f497a Merge branch 'stable-4.9'
* stable-4.9:
  PackInserter: Ensure objects are written at the end of the pack
  ObjectInserter: Add warning about mixing read-back with writes

Change-Id: I308e7c1c6b72e8d4d9b5d0f4f51e9815fc92d7d7
2017-12-20 14:39:11 -05:00
Dave Borowitz 43ef5dabf1 PackInserter: Ensure objects are written at the end of the pack
When interleaving reads and writes from an unflushed pack, we forgot to
reset the file pointer back to the end of the file before writing more
new objects. This had at least two unfortunate effects:
  * The pack data was potentially corrupt, since we could overwrite
    previous portions of the file willy-nilly.
  * The CountingOutputStream would report more bytes read than the size
    of the file, which stored the wrong PackedObjectInfo, which would
    cause EOFs during reading.

We already had a test in PackInserterTest which was supposed to catch
bugs like this, by interleaving reads and writes. Unfortunately, it
didn't catch the bug, since as an implementation detail we always read a
full buffer's worth of data from the file when inflating during
readback. If the size of the file was less than the offset of the object
we were reading back plus one buffer (8192 bytes), we would completely
accidentally end up back in the right place in the file.

So, add another test for this case where we read back a small object
positioned before a large object. Before the fix, this test exhibited
exactly the "Unexpected EOF" error reported at crbug.com/gerrit/7668.

Change-Id: I74f08f3d5d9046781d59e5bd7c84916ff8225c3b
2017-12-20 12:43:31 -05:00
Dave Borowitz f63ee965d4 ObjectInserter: Add warning about mixing read-back with writes
Change-Id: Ib0460d3c7df315d86f9adca5f66a8fd4c39e4060
2017-12-20 12:16:40 -05:00
Matthias Sohn 7f6aaa5768 Fix javadoc leftovers in org.eclipse.jgit api package
Change-Id: I2150889b5ed04e8739e2367fc9023b750b516398
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-20 08:51:16 +09:00
Matthias Sohn 1c35379100 Remove unused imports
Change-Id: I35370c66e54d93d9b0aa3995e300706956ec0923
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-20 08:21:26 +09:00
David Pursehouse 0c259eaf1d Replace explicit calls to initCause where possible
Where the exception being thrown has a constructor that takes a
Throwable, use that instead of instantiating the exception and then
explicitly calling initCause.

Change-Id: I06a0df407ba751a7af8c1c4a46f9e2714f13dbe3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-20 08:02:34 +09:00
David Pursehouse 19864c6c02 Merge changes I50095928,Idadec0ab,I1f2747d6,I6d2a7e28
* changes:
  LargeObjectException: Add constructor that takes Throwable
  InvalidPatternException: Add constructor that takes Throwable
  Don't unnecessarily explicitly call CorruptObjectException#initCause
  Use new StoredObjectRepresentationNotAvailableException constructor
2017-12-19 18:02:11 -05:00
David Pursehouse c228f201a6 LargeObjectException: Add constructor that takes Throwable
Change-Id: I500959286075f8ba4d0aa5820febd28c9c94ea1b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-19 23:27:53 +09:00
David Pursehouse 06bab95e00 InvalidPatternException: Add constructor that takes Throwable
Change-Id: Idadec0abc1c6d76f19f51a65a4b45df444c20486
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-19 23:27:53 +09:00
David Pursehouse 0f1c160aa7 Don't unnecessarily explicitly call CorruptObjectException#initCause
CorruptObjectException has a constructor that takes Throwable and
calls initCause with it.  Use that instead of instantiating the
exception and explicitly calling initCause.

Change-Id: I1f2747d6c4cc5249e93401b9787eb4ceb50cb995
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-19 23:27:53 +09:00
David Pursehouse 365c6cb387 Use new StoredObjectRepresentationNotAvailableException constructor
In 5e7eed4 a new StoredObjectRepresentationNotAvailableException
constructor was added, that takes a Throwable to initialize the
exception cause.

Update more call sites to use this constructor instead of first
instantiating it and explicitly calling initCause().

All callers now use the new constructor, so annotate the other one as
deprecated.

Change-Id: I6d2a7e289a95f0360ddebf904cfd8b6c18fef10c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-19 23:27:53 +09:00
Matthias Sohn 7b93ae0987 Fix javadoc in org.eclipse.jgit submodule package
Change-Id: Idc2a32a2e10d1cfc0b23a4f3fd1bf29840724336
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 14:03:21 +01:00
Matthias Sohn 56cc6afeba Fix javadoc in org.eclipse.jgit storage/file and pack package
Change-Id: If1fee165782823dc21d896073f60ee838365463d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 14:00:29 +01:00
Matthias Sohn 0cba440277 Fix javadoc in org.eclipse.jgit revwalk package
Change-Id: I3fabab8afa284b1919ab7bc656cab19e56ed474e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:57:14 +01:00
Matthias Sohn 23f3b6ab24 Fix javadoc in org.eclipse.jgit patch and revplot package
Change-Id: I6f1aba98bf7034cb51494c546806cf1b72dd1473
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:57:11 +01:00
Matthias Sohn 463dad2ed6 Fix javadoc in org.eclipse.jgit nls and notes package
Change-Id: I1b65fba5b4856f98974dc10f549540d401ef916f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:49:59 +01:00
Matthias Sohn a2f2f65390 Fix javadoc in org.eclipse.jgit merge package
Change-Id: I735d0f2e9f10531ed43b7b3dd6314c574392422f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:48:55 +01:00
Matthias Sohn 8a6af368c4 Fix javadoc in org.eclipse.jgit lib package
Change-Id: I1e85a951488177993521ce177fdea212615e6164
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:43:54 +01:00
Matthias Sohn d0342be42d Fix javadoc in org.eclipse.jgit storage/reftree package
Change-Id: Ie206b5340ad2019a1e0bd2bcede2c1e5a279f2d5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:39:10 +01:00
Matthias Sohn 43e26de7ec Fix javadoc in org.eclipse.jgit storage/reftable package
Change-Id: I14764c5d5b2309d82fe2ccc0593120b51328bf41
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:39:10 +01:00
Matthias Sohn 783dbf1b03 Fix javadoc in org.eclipse.jgit storage/pack package
Change-Id: Id1b7d392e1bb36079edaf16450e73a044a318e7e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:39:09 +01:00
Matthias Sohn c6d17443ad Fix javadoc in org.eclipse.jgit storage/io package
Change-Id: I2db781311af79510b26fd05cc0556623e75e3eff
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:39:09 +01:00
Matthias Sohn 5480da5999 Fix javadoc in org.eclipse.jgit storage/file package
Change-Id: Ieb2f66aef2cab7e2a6d8e35c5f5047da881994dd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:39:07 +01:00
Matthias Sohn a224b78675 Fix javadoc in org.eclipse.jgit dfs package
Change-Id: I1f5e3dc3ba34b323ee7244dbefee207ce19e6021
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-19 13:35:25 +01:00
David Pursehouse 305b488975 StoredObjectRepresentationNotAvailableException: Add TODO to fix API in 5.0
Change-Id: I9a0e6acac1b88ddf257fe7b2b7d0142be20250ea
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-19 10:48:06 +09:00
David Pursehouse 5e7eed41f6 StoredObjectRepresentationNotAvailableException: Add constructor that takes cause
If the cause can be passed into the constructor, callers don't need to
instantiate it and then explicitly call initCause.

Note that the constructors in this class cause "non-API parameter type"
warnings because ObjectToPack is internal, however it's probably OK
since the only non-internal reference to it is in the pgm.debug package.

Change-Id: Ia4eab24e79f9afe6214ea8160137d941d4048319
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-19 10:40:57 +09:00
David Pursehouse 1e141469f1 Merge changes Ifc34e96a,I72be0a0d
* changes:
  Fix javadoc in org.eclipse.jgit rewalk package
  Fix javadoc in org.eclipse.jgit ketch package
2017-12-18 18:33:40 -05:00
Dave Borowitz 31a2d09c9c Config: Rewrite subsection and value escaping and parsing
Previously, Config was using the same method for both escaping and
parsing subsection names and config values. The goal was presumably code
savings, but unfortunately, these two pieces of the git config format
are simply different.

In git v2.15.1, Documentation/config.txt says the following about
subsection names:

  "Subsection names are case sensitive and can contain any characters
  except newline (doublequote `"` and backslash can be included by
  escaping them as `\"` and `\\`, respectively).  Section headers cannot
  span multiple lines.  Variables may belong directly to a section or to
  a given subsection."

And, later in the same documentation section, about values:

  "A line that defines a value can be continued to the next line by
  ending it with a `\`; the backquote and the end-of-line are stripped.
  Leading whitespaces after 'name =', the remainder of the line after
  the first comment character '#' or ';', and trailing whitespaces of
  the line are discarded unless they are enclosed in double quotes.
  Internal whitespaces within the value are retained verbatim.

  Inside double quotes, double quote `"` and backslash `\` characters
  must be escaped: use `\"` for `"` and `\\` for `\`.

  The following escape sequences (beside `\"` and `\\`) are recognized:
  `\n` for newline character (NL), `\t` for horizontal tabulation (HT,
  TAB) and `\b` for backspace (BS).  Other char escape sequences
  (including octal escape sequences) are invalid."

The main important differences are that subsection names have a limited
set of supported escape sequences, and do not support newlines at all,
either escaped or unescaped. Arguably, it would be easy to support
escaped newlines, but C git simply does not:

  $ git config -f foo.config $'foo.bar\nbaz.quux' value
  error: invalid key (newline): foo.bar
  baz.quux

I468106ac was an attempt to fix one bug in escapeValue, around leading
whitespace, without having to rewrite the whole escaping/parsing code.
Unfortunately, because escapeValue was used for escaping subsection
names as well, this made it possible to write invalid config files, any
time Config#toText is called with a subsection name with trailing
whitespace, like {foo }.

Rather than pile hacks on top of hacks, fix it for real by largely
rewriting the escaping and parsing code.

In addition to fixing escape sequences, fix (and write tests for) a few
more issues in the old implementation:

* Now that we can properly parse it, always emit newlines as "\n" from
  escapeValue, rather than the weird (but still supported) syntax with a
  non-quoted trailing literal "\n\" before the newline. In addition to
  producing more readable output and matching the behavior of C git,
  this makes the escaping code much simpler.
* Disallow '\0' entirely within both subsection names and values, since
  due to Unix command line argument conventions it is impossible to pass
  such values to "git config".
* Properly preserve intra-value whitespace when parsing, rather than
  collapsing it all to a single space.

Change-Id: I304f626b9d0ad1592c4e4e449a11b136c0f8b3e3
2017-12-18 17:46:37 -05:00
Matthias Sohn 5bd3e75094 Fix javadoc in org.eclipse.jgit rewalk package
Change-Id: Ifc34e96a56df30e3b73bef812eea943623af7906
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 17:11:46 +01:00
Matthias Sohn e3a04b6c41 Fix javadoc in org.eclipse.jgit ketch package
Change-Id: I72be0a0d5ac7d3e957597803bd103dbbec141ba4
2017-12-18 17:10:20 +01:00
Matthias Sohn 6dca3cc024 Fix javadoc in org.eclipse.jgit internal and fsck packages
Change-Id: Ib12da10aacda9389d594bf4f521e9a58d1935701
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:25:04 +01:00
Matthias Sohn 107c71a6e6 Fix javadoc in org.eclipse.jgit ignore package
Change-Id: I1a81d371420cd4cf90ab9e048026c0ab8a763018
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:10 +01:00
Matthias Sohn d1804d3f74 Fix javadoc in org.eclipse.jgit hooks package
Change-Id: I3b644048eb0fc19f94ba8f9799b5a2310481103f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:09 +01:00
Matthias Sohn 5e2e111280 Fix javadoc in org.eclipse.jgit gitrepo package
Change-Id: I2604c7bca87f005004d6d6c80fa9a39a7a1e3807
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:09 +01:00