Commit Graph

4444 Commits

Author SHA1 Message Date
Matthias Sohn cc8dfe79a9 Remove deprecated LockFile(File, FS) constructor
Use org.eclipse.jgit.internal.storage.file.LockFile#LockFile(File)
instead.

Change-Id: I107d9879c02a2006799a238ccaddf87c89f33f77
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-10 19:41:23 +01:00
Matthias Sohn f0ab2d07b8 Remove deprecated IgnoreNode#isIgnored method
Parameter negateFirstMatch is not honored anymore

Change-Id: Idff1a92643c1431c7e34a7730f8414135e1ac196
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-10 19:41:22 +01:00
David Pursehouse 9441508682 Fix misspelled class name: EmtpyCommitException -> EmptyCommitException
Change-Id: I55196020146f26951988988c14ac9a6f85061ae2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-10 19:40:55 +01:00
Matthias Sohn cc19f64966 Remove deprecated Statistics, UploadPackLogger, UploadPackLoggerChain
Use PackStatistics and PostUploadHook and PostUploadHookChain instead.
Also remove
- UploadPack#getPackStatistics replaced by #getStatistics
- UploadPack#getLogger and UploadPack#setLogger

Change-Id: I70881c539af3094d68d594f19983dea0973604e8
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-10 19:38:36 +01:00
Matthias Sohn f9a4112ecc Remove deprecated StoredObjectRepresentationnotAvailableException ctor
Use #StoredObjectRepresentationNotAvailableException(ObjectToPack,
Throwable) instead.

Change-Id: I766e00bc7292c7bd025aa2d7c54f10d278c7fabd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-09 23:57:36 +01:00
Matthias Sohn 653b31a903 Remove deprecated ArchiveCommand#putEntry method
Use #putEntry(Closeable, ObjectId, String, FileMode, ObjectLoader)}
instead.

Change-Id: I2c58c07da00c6033c583eb2dc6c3a0889661f5f5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-09 23:55:43 +01:00
Matthias Sohn d0f1f5eef6 Prepare 5.0.0-SNAPSHOT builds
Change-Id: I2d2f50ed8a12f310e7cac68eed5536bd460c403f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-08 23:09:18 +01:00
Matthias Sohn f389e18a28 Prepare 4.11.1-SNAPSHOT builds
Change-Id: Id9aa6b7e8f56de5183b6cd57ef0e790ec9debd4d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-08 21:10:08 +01:00
Matthias Sohn f944063517 JGit v4.11.0.201803080745-r
Change-Id: Ie24a33bc8a24c30db06fe7b175f405efb95776ec
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-08 13:43:46 +01:00
Thomas Wolf e00f59b7fe Remove useless for(;;) loop
Change-Id: Ic9a7824cc178e92f44126acc8e77b0304b20ef4f
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-03-07 23:56:35 +01:00
Thomas Wolf 7d3040368f Fix DiffFormatter for diffs against working tree with autocrlf=true
The WorkingTreeSource produced an ObjectLoader that returned
inconsistent sizes: the file size in getSize(), but then a
correctly filtered smaller stream in openStream(). This resulted
either in an IOE "short read of block" or in an EOFException
depending on the resulting filtered size.

Fix this by ensuring that getSize() does return the size of the
filtered stream.

Bug: 530106
Change-Id: I7c7c85036047dc10030ed29c1d5a6c7f34f2bdff
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-03-07 23:25:22 +01:00
Matthias Sohn 0d79bcf151 Merge branch 'stable-4.10'
* stable-4.10:
  Don't subclass ThreadLocal to avoid memory leak in NLS
  Set context classloader to null in WorkQueue

Change-Id: Idacf9a15a27f8e1d73357a80ed11a02237eea49e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-07 22:37:50 +01:00
Markus Duft 0f9ec9e406 LFS: Adjust some API to make integration into tools (EGit,...) easier
Make the install command accessible without requiring reflection.

Expose the isEnabled(Repository) API to be able to check if calling the
install command is required for a repository.

Change-Id: I17e6eaefb6afda17fea8162cbf0cb86a20506753
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-07 22:02:02 +01:00
David Pursehouse 2c29af7867 MergeCommand: Open RevWalk in try-with-resource
Change-Id: I45ce481cc198b8dc78e9c46b433504840597e982
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-07 14:46:08 +09:00
David Pursehouse ee4dd50b3f JschConfigSessionFactory: Open FileInputStream in try-with-resource
Change-Id: I0f8f4629c93ed747f2f604538fccc52da3974b2e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-07 14:39:39 +09:00
David Pursehouse e53edce867 GC: Open auto-closeable resources in try-with-resource
Change-Id: If437e14636de7c5014ee2aa419d6518acd857792
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 17:24:29 +09:00
David Pursehouse d1356bf238 FileRepository: Open FileInputStream in try-with-resource
Change-Id: Ief8aa4834437d76f7e636598bf9861312475e64a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 17:18:23 +09:00
David Pursehouse 336add10c1 FetchProcess: Open OutputStreamWriter in try-with-resource
Change-Id: Ide7768882a95f9e9706e50ca0774edd428dd07c1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 17:14:19 +09:00
David Pursehouse fabd645fad FS: Open TemporaryBuffer in try-with-resource
Change-Id: I52e048e491e838b7f762a5b5f4d148e91049877c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 16:58:12 +09:00
David Pursehouse da63121b0d DirCacheIterator: Open InputStream in try-with-resource
Change-Id: I05d2d1de9a3d39466a6880f6e8107da8681876b1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 16:56:13 +09:00
David Pursehouse e6c456eeae Merge changes from topic 'try-with-resource'
* changes:
  DiffCommand: Open DiffFormatter in try-with-resource
  DiffAlgorithms: Open Repository in try-with-resource
  DescribeCommandTest: Open FileWriter in try-with-resource
  CommitCommand: Open InputStream in try-with-resource
  DefaultNoteMerger: Open UnionInputStream in try-with-resource
2018-03-06 02:55:50 -05:00
David Pursehouse e2d875ee30 DiffCommand: Open DiffFormatter in try-with-resource
Change-Id: I22bd1062d64b01bb98cdaf612482538114624b7f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 10:40:35 +09:00
David Pursehouse 3393f78210 CommitCommand: Open InputStream in try-with-resource
Change-Id: I800a2afae17f84636cae593be7f07628fb8476c1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 09:48:19 +09:00
David Pursehouse 1826341793 DefaultNoteMerger: Open UnionInputStream in try-with-resource
Change-Id: I035aa89cdbf235992f41e752f49d735be4e5df0a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-06 09:47:11 +09:00
Matthias Sohn e88f95146a Silence API error raised for new CONFIG_SECTION_LFS constant
Change-Id: I27e68d245c6b9c972ab9470c14d1f45d15d4c253
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-06 00:28:38 +01:00
David Pursehouse 9e4a455f9b ArchiveCommand: Create archive output stream in try-with-resource
Change-Id: I72f4d303945275d400723aa17212b302e051dc15
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 20:19:25 +09:00
David Pursehouse 40868386db ApplyCommand: Open FileWriter in try-with-resource
Change-Id: Ia473f74dc4608fc43edd57eda4f193c226e9004d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 20:17:32 +09:00
David Pursehouse f6dbc7d472 AmazonS3: Open InputStream/FileInputStream in try-with-resource
Change-Id: I71606e14d2b3cf085b8d1343c3858e7a729a173e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 20:11:59 +09:00
David Pursehouse fa9ee83697 WalkRemoteObjectDatabase: Open auto-closeable resources in try-with-resource
Change-Id: Ie4f67ca8cab1031089782f202588b08cc157dd79
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 17:15:04 +09:00
David Pursehouse 99c187a5da TransportSftp: Open BufferedReader in try-with-resource
Change-Id: Iab94cce80c11a5edeaf8f377001408cc53707c04
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 17:13:20 +09:00
David Pursehouse 4c2f613a5a TransportHttp: Open auto-closeable resources in try-with-resource
Change-Id: I2f713b79ff07f5759c189f384cd25adb9b9f5761
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 16:28:59 +09:00
David Pursehouse 20b750d2f5 LockFile: Open FileInputStream in try-with-resource
Change-Id: I0784266814225428a6a0070d1653c465d268b342
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 11:03:21 +09:00
David Pursehouse 60b43c03e2 Add ConfigConstants.CONFIG_SECTION_LFS
DirCacheCheckout has a warning about non-localised string "lfs". Other
classes use org.eclipse.jgit.lfs.lib.Constants but that is not visible
to DirCacheCheckout.

Add a new constant in ConfigConstants and use that in DirCacheCheckout.

Replace existing uses of org.eclipse.jgit.lfs.lib.Constants.LFS with
the new constant, except where it is referring to the folder name.

Change-Id: I0f21b951babff9a2e579d68c4de0c62ee4bc23d4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-05 10:53:28 +09:00
David Pursehouse bc9e3a31b2 Add|RemoveNoteComand: Reduce duplicated code
The private method commitNoteMap is in both classes with the same
implementation.

Make it static in AddNoteCommand and reuse it from RemoveNoteCommand.

Change-Id: Ia037bf9efdd94ee7b8d33b41321e9cfd6ea4a6a5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:50 +01:00
David Pursehouse cf489d36b9 TagBuilder: Open OutputStreamWriter in try-with-resource
Change-Id: Ic0e23039b0aec6171f192234c6b1474cd32eadff
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:49 +01:00
David Pursehouse a73f6c6009 DaemonService: Open Repository in try-with-resource
Change-Id: I8deec91d91e82c7cb186cfa9507eb443dd87aad3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:49 +01:00
David Pursehouse 63be96f488 RefDirectory: Open BufferedReader in try-with-resource
Change-Id: I9239df3e381b141b48ad7ea1b706e5b5927946cd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:48 +01:00
David Pursehouse db0b7911fe ObjectDirectory: Open BufferedReader in try-with-resource
Change-Id: I4a44954c61647af1e48eade19112697e79297f2e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:48 +01:00
David Pursehouse 86330ca2ad Patch: Open TemporaryBuffer in try-with-resource
Change-Id: I90bff8d49ecc37b8c10ce909cd3ac563205b641c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:48 +01:00
David Pursehouse a573dfc658 Enable warning for resources not managed by try-with-resource
Change-Id: Iefe97de6bdb62af558f1b0e77c9205a9186f9b4c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-03-03 23:58:47 +01:00
Markus Duft c0103bc59d LFS: Enable LFS support for the CLI, better error handling
Enable LFS support for the CLI by registering the according filters.

Errors during filter creation must be propagated up the call stack, as a
failure to create a filter should be treated as fatal if the filter is
required.

Change-Id: I3833757839bdda97cd01b6c21c1613d199e2692d
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
2018-03-03 11:44:01 +01:00
Markus Duft a3f8edbf6a Cleanup stream usage WRT filters
As it is right now some streams leak out of the filter construct. This
change clarifies responsibilities and fixes stream leaks

Change-Id: Ib9717d43a701a06a502434d64214d13a392de5ab
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-03 11:40:55 +01:00
Markus Duft d3ed64bcd4 LFS: support merge/rebase/cherry-pick/diff/compare with LFS files
Respect merge=lfs and diff=lfs attributes where required to replace (in
memory) the content of LFS pointers with the actual blob content from
the LFS storage (and vice versa when staging/merging).

Does not implement general support for merge/diff attributes for any
other use case apart from LFS.

Change-Id: Ibad8875de1e0bee8fe3a1dffb1add93111534cae
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-03-03 11:39:43 +01:00
Terry Parker 5a74b586b3 Correctly exit fetch negotiation for stateless RPC connections
Commit 9530c10192 (2018-02-11)
"Add a minimum negotiation feature for fetch" made fetch
negotiation cheaper for repos with huge numbers of
references (we are seeing a 15x reduction in maximum fetch
times for chromium/chromium/src on trans-Pacific links).
But it inadvertently broke the handling of stateless RPC
connections, so fix that here.

Change-Id: I0090aa76ffecc55801ebb833ac2e0c933a4a7c54
Signed-off-by: Terry Parker <tparker@google.com>
2018-02-28 15:32:57 -08:00
Markus Duft c0bb992845 LFS: pre-push upload support
If JGit built in LFS support is enabled for the current repository (or
user/system), any existing pre-push hook will cause an exception for the
time beeing, as only a single pre-push hook is supported.

Thus either native pre-push hooks OR JGit built-in LFS support may be
enabled currently, but not both.

Change-Id: Ie7d2b90e26e948d9cca3d05a7a19489488c75895
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-27 18:32:45 +01:00
David Pursehouse 12a589fb57 AmazonS3: Open OutputStream in try-with-resource
Change-Id: I0685a298a0f9fec465973cc718ae3bff373318a4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-26 20:38:12 +09:00
David Pursehouse f0b46e1db4 Add ObjectIdSerializer
This is based on the ObjectIdSerialization class written by Shawn Pearce
for the Gerrit Code Review project in 2009 [1]. As mentioned in the
commit message there, it should be part of core JGit.

This implementation is slightly different to Shawn's version. Rather
than having separate methods for null/non-null ids, single methods are
implemented with @Nullable annotations.

[1] https://gerrit-review.googlesource.com/c/gerrit/+/9792

Change-Id: I7599cf8bd1ecd546e2252783d6d672eb76804060
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-25 23:15:01 +01:00
David Pursehouse c9e3921fbb Fix warnings about boxing/unboxing Boolean
Change-Id: I9d81d510282e9181267750fe3f9c571c35b61407
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-25 17:35:12 +09:00
David Pursehouse e8c69fa5fd WorkingTreeIterator: Fix warnings about variable hiding
Change-Id: I78ed3ae7aa30a7e7f146d0bd2e9feff74554da78
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-25 17:32:33 +09:00
David Pursehouse 6ea21b454c WorkingTreeIterator: Add NON-NLS suppressions
Change-Id: I369b8f68912134fc3880c162e9a2c5a1669bb4ac
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-25 17:30:16 +09:00
Marc Strapetz 78420b7d0a Fix processing of gitignore negations
Processing of negated rules, like !bin/ was not working correctly: they
were interpreted too broad, resulting in unexpected untracked files
which should actually be ignored

Bug: 409664
Change-Id: I0a422fd6607941461bf2175c9105a0311612efa0
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2018-02-23 13:36:48 +01:00
Dave Borowitz 879372eb72 DfsReaderIoStats: Clarify that "blocks" are really cache misses
The previous wording was ambiguous as to whether these were blocks
requested from the cache (hits + misses) or read from underlying storage
(misses only).

They are in fact recording only misses:
Accumulator#{readBlock,readBlockBytes,readBlockMicros} are only
incremented from BlockBasedFile#readOneBlock, which is only called from
the cache miss path in DfsBlockCache#getOrLoad (line 391).

Change-Id: I0135cd1e76d09c1e28e0f1833b34c312511c66ce
2018-02-22 16:27:09 +09:00
Marc Strapetz 49cb6ba5dd PathMatcher: fix handling of **/
**/ should match only directories, but not files

Change-Id: I885c83e5912cac5bff338ba657faf6bb9ec94064
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2018-02-22 14:39:23 +09:00
David Pursehouse 0e20df710a Merge changes Id616611e,Ib6509e81,I52f5d3f2
* changes:
  RepoCommand: generate relative submodule URLs from absolute URLs.
  RepoCommand: don't record new commit if tree did not change
  RepoCommand: persist unreadable submodules in .gitmodules
2018-02-22 00:37:48 -05:00
Shawn Pearce d0fbaf502e dfs: Try to avoid searching UNREACHABLE_GARBAGE during packing
If an object can be found in a non-garbage pack, favor that pack over
paging in the garbage pack's idx and pack content.

Only fall back to garbage packs if an object cannot be found and there
are garbage packs present in the repository.  This fallback is
required to correct race conditions during GC.

Change-Id: Ia7c123975bc069b8e6e713eda2d357303b71e329
2018-02-21 14:46:57 -05:00
Han-Wen Nienhuys 6a420613f7 RepoCommand: generate relative submodule URLs from absolute URLs.
If a manifest file specifies an absolute URL on the same host on which
the superproject resides, rewrite the URLs to be relative.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Id616611e5195998fb665c8e7806539a3a02e219a
2018-02-21 13:41:50 +01:00
Han-Wen Nienhuys 3214171dec RepoCommand: don't record new commit if tree did not change
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Ib6509e816684256d723558d5e8f3c37de58a2ff8
2018-02-19 20:24:07 +09:00
Han-Wen Nienhuys 446a7096ef RepoCommand: persist unreadable submodules in .gitmodules
In cases where a manifest file mixes different remotes, a Gerrit
server process may not have access to all remotes, and won't be able
to produce a full submodule tree.

Preserving this information in .gitmodules will let downstream clients
reconstruct the full tree.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I52f5d3f288e771dca0af2b4dd3f3fa0f940dcf15
2018-02-19 20:24:07 +09:00
Matthias Sohn 44f0a01f24 Silence API error for new constant in ConfigConstants
Change-Id: Ic4bd10b67caf6b2a2cc0c23bb4e7c717e4ccd6d5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-18 22:23:00 +01:00
Matthias Sohn 33d5c0fe4a Silence API errors raised for new public fields in PackStatistics
Change-Id: I8e118282a833361b676aa3cc90cbe774ccd42ed0
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-18 22:08:47 +01:00
Markus Duft 94bcde663c LFS: Add remote download to SmudgeFilter
Transfer data in chunks of 8k Transferring data byte per byte is slow,
running checkout with CleanFilter on a 2.9MB file takes 20 seconds.
Using a buffer of 8k shrinks this time to 70ms.

Also register the filter commands in a way that the native GIT LFS can
be used alongside with JGit.

Implements auto-discovery of LFS server URL when cloning from a Gerrit
LFS server.

Change-Id: I452a5aa177dcb346d92af08b27c2e35200f246fd
Also-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
2018-02-16 18:27:25 +01:00
David Pursehouse 9bebb1eae7 RepoCommand: Don't leave Git open
When the command is run on a non-bare repository, an instance of
Git is created to execute the commit, and is left open when the
command has finished.

Refactor to not use a class scope Git instance, and make sure it
gets closed before returning.

Change-Id: Ic623ae0fd8b9e264b5dfd434da0de6bb4f910984
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-02-15 16:59:42 +09:00
Matthias Sohn 282dc592da Merge "Merge branch 'stable-4.10'" 2018-02-14 18:18:43 -05:00
David Pursehouse 184ddc5afa Merge "InitCommand: Don't leave Repository open after Git is closed" 2018-02-14 18:18:35 -05:00
Matthias Sohn d2d22e1471 Merge branch 'stable-4.10'
* stable-4.10:
  Fix ssh host name handling for Jsch
  Jsch overrides the port in the URI with the one in ~/.ssh/config

Change-Id: I860fc61ceb12ae792b1ee7421046ecd32373b9f8
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-14 23:28:28 +01:00
Matthias Sohn 95fc2b210f Don't subclass ThreadLocal to avoid memory leak in NLS
These problem usually occur when you subclass ThreadLocal (usually to
implement initialValue). Those classes reference the webapp's
classloader. The ThreadLocal subclass in turn is referenced by each
Thread instance (that's how ThreadLocals are implemented, they have a
"helper-Map" in each Thread instance, so the leak is actually not a tiny
Random instance but the whole webapp's classloader with a bunch of class
definitions and statically referenced parts of the webapp.

Bug: 449321
Change-Id: Ie7a8b0b90e40229e2471202f2a12637b9e0b1d11
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-14 21:39:25 +01:00
Matthias Sohn 95f868f246 Set context classloader to null in WorkQueue
If threads created by the executor have a reference to the context
classloader this may cause a leak.

See: https://wiki.apache.org/tomcat/MemoryLeakProtection#cclThreadSpawnedByWebApp
Bug: 517107
Change-Id: If79c1ebd3f9cf733fd88a5fce38fd46ff0d08d10
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-14 21:39:24 +01:00
Matthias Sohn 6e0f8bacd4 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Fix ssh host name handling for Jsch
  Jsch overrides the port in the URI with the one in ~/.ssh/config

Change-Id: Iff9076f65e767bbe8df016337b631bdaeb40ad98
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-02-14 21:25:16 +01:00
Matthias Sohn 105bfd9b56 Merge "TransportLocal should reuse FS from source repo" 2018-02-14 15:02:22 -05:00
Thomas Wolf 185e53bce4 Fix ssh host name handling for Jsch
If we give Jsch access to the ssh config file, we must _not_ resolve
the host name from the alias. Instead we must give the alias (i.e.,
the host name as is in the URI) to Jsch, so that it finds the same
ssh config entry.

Otherwise if the hostname in the URI, which is taken as an alias in
ssh config ("Host" line), is unequal to the "Hostname" line, and
there happens to be another ssh config entry with that translated
host name as alias, Jsch will pick up that second entry, and we end
up with a strange mixture of both.

Add tests for this case.

Bug: 531118
Change-Id: I249d8c073b0190ed110a69dca5b9be2a749822c3
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-02-14 13:39:28 +01:00
Thomas Wolf 891103609d Jsch overrides the port in the URI with the one in ~/.ssh/config
Jsch unconditionally overwrites the port from the ssh config
file (if a port is specified there), even if the URI explicitly does
give a different port.

Fix this, and add tests.

Change-Id: I7b014543c7ece26270e366db39d7647f82d64f0d
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-02-14 13:32:37 +01:00
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
Matthias Sohn 6c83cc1660 Fix javadoc in org.eclipse.jgit fnmatch package
Change-Id: I14384c3bf3c41f8e1c62ec117837c2fc782a832f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:08 +01:00
Matthias Sohn dc91f4ef2c Fix javadoc in org.eclipse.jgit events package
Change-Id: Ifcb9c67daeb9da84a1461a4f731523ac5df3a223
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:08 +01:00
Matthias Sohn 6478577899 Fix javadoc in org.eclipse.jgit errors package
Change-Id: I46aa5c3073b99a311a1a97fc57d8f29d32524482
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:07 +01:00
Matthias Sohn c281692c06 Fix javadoc in org.eclipse.jgit dircache package
Change-Id: Ib485eb217ac6be70519816f8cc0396931043a3d1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 13:19:07 +01:00
David Pursehouse 1463bb9b87 EmtpyCommitException: Add TODO to fix misspelled class name in 5.0
Change-Id: I5bb145d6d6cbaaa2d8cfb2febad7a008ca921236
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-18 05:51:14 -05:00
Matthias Sohn 4d8233f237 Fix javadoc org.eclipse.jgit diff package
Change-Id: I7162d72916abc8533ad37e8b17335ff4a70d6519
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 10:47:19 +01:00
Matthias Sohn 0210e0e299 Fix javadoc in org.eclipse.jgit annotations and api packages
Change-Id: I2761ea91f8dfed16ea54e7a6646af03a30c15ec9
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-18 10:45:50 +01:00
Matthias Sohn 4e27a16081 Fix javadoc in org.eclipse.jgit blame package
Change-Id: I116dacc7f4ace341ec6ffae2ab96b53496d89f64
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-17 20:23:33 -05:00
Matthias Sohn df2bcbfb23 Fix javadoc in org.eclipse.jgit attributes package
Change-Id: I12968f4be805266f285a518a014b8bd1d0c23bae
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-17 20:23:24 -05:00
David Pursehouse ed38840eba Merge branch 'stable-4.9'
* stable-4.9:
  Prepare 4.9.3-SNAPSHOT builds
  JGit v4.9.2.201712150930-r
  Write packed-refs directly when cloning

Change-Id: I3b0fad9c45cdf3a918ddb8ea4a37b8d3403aae90
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-16 14:04:01 +01:00
Matthias Sohn 1e56842742 Prepare 4.9.3-SNAPSHOT builds
Change-Id: Ife3f2b0b5407227f89ded42358adbf01d53e14cf
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-16 03:49:03 +01:00
Zhen Chen 99e70530b9 DfsFsck: Skip unborn branches and symrefs to nowhere
The map returned by getAllRefs includes all refs, including symrefs like
HEAD that may not point to any object yet. That is a valid state (e.g.,
in a new repository that has just been created by "git init"), so skip
such refs.

Change-Id: Ieff8a1aa738b8d09a2990d075eb20601156b70d3
Signed-off-by: Zhen Chen <czhen@google.com>
2017-12-15 14:16:33 -08:00
Matthias Sohn 24b7e91264 JGit v4.9.2.201712150930-r
Change-Id: I013964045d532659a4be3b81d6612b59bc9ffb14
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-15 15:29:36 +01:00
Thomas Wolf c86327979f Write packed-refs directly when cloning
When we are cloning we have no refs at all yet, and there cannot
(or at least should not) be any other thread doing something with
refs yet.

Locking loose refs is thus not needed, since there are no loose
refs yet and nothing should be trying to create them concurrently.

Let's skip the whole loose ref locking when we are cloning a repository.
As a result, JGit will write the refs directly to the packed-refs
file, and will not create the refs/remotes/ directories nor the
lock files underneath when cloning and packed refs are used. Since
no lock files are created, any problems on case-insensitive file
systems with tag or branch names that differ only in case are avoided
during cloning.

Detect if we are cloning based on the following heuristics:
* HEAD is a dangling symref
* There is no loose ref
* There is no packed-refs file

Note, however, that there may still be problems with such tag or
branch names later on. This is primarily a five-minutes-past-twelve
stop-gap measure to resolve the referenced bug, which affects the
Oxygen.2 release.

Bug: 528497
Change-Id: I57860c29c210568165276a123b855e462b6a107a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-15 14:14:03 +01:00
David Pursehouse ec7f88eec8 Config: Remove the include functionality
The Config class must be safe to run against untrusted input files.
Reading arbitrary local system paths using include.path is risky for
servers, including Gerrit Code Review.

This was fixed on master [1] by making "readIncludedConfig" a noop
by default. This allows only FileBasedConfig, which originated from
local disk, to read local system paths.

However, the "readIncludedConfig" method was only introduced in [2]
which was needed by [3], both of which are only on the master branch.
On the stable branch only Config supports includes. Therefore this
commit simply disables the include functionality.

[1] https://git.eclipse.org/r/#/c/113371/
[2] https://git.eclipse.org/r/#/c/111847/
[3] https://git.eclipse.org/r/#/c/111848/

Bug: 528781
Change-Id: I9a3be3f1d07c4b6772bff535a2556e699a61381c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-15 08:58:00 +09:00
David Pursehouse 5fa129555a Merge branch 'stable-4.9'
* stable-4.9:
  InMemoryRepository: Make inner class MemObjDatabase static

Change-Id: I62bb5957de1ae3bc6030ea2181b09efccc48252b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-14 11:05:05 +09:00
Shawn Pearce 3a7704638a Make Config.readIncludedConfig a noop by default
The Config class must be safe to run against untrusted input files.
Reading arbitrary local system paths using include.path is risky for
servers, including Gerrit Code Review.  Return null by default to
incide the include should be ignored.

Only FileBasedConfig which originated from local disk should be trying
to read local system paths.  FileBasedConfig already overrides this
method with its own implementation.

Change-Id: I2ff31753868aa1bbac4a6843a4c23e50bd6f46f3
2017-12-13 17:50:52 -08:00
Shawn Pearce f635aa51f8 DfsBlockCache.hasBlock0: quickly check for file in cache
This can be useful for sophisticated pre-read algorithms to quickly
determine if a file is likely already in cache, especially small
reftables which may be smaller than a typical DFS block size.

Change-Id: I7756948063b722ff650c9ba82060ff9ad554b0ba
2017-12-13 17:10:51 -08:00
David Pursehouse c09ed93e85 Merge branch 'stable-4.9'
* stable-4.9:
  TransportCommand#setTimeout: Specify units for timeout in Javadoc
  Fix typo in key of a JGitText externalized string

Change-Id: Icb60537d2e99cb6e928d9fe07f66695ed69081b5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-13 09:51:57 +09:00
David Pursehouse 2edf66bdd7 Remove unused API filters
Change-Id: Ie8bfa4e8473c2a68a6308de7dbf29ccbca97495d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-13 01:03:55 +01:00
David Pursehouse c40e150790 InMemoryRepository: Make inner class MemObjDatabase static
FindBugs reports:

  This class is an inner class, but does not use its embedded reference
  to the object which created it. This reference makes the instances
  of the class larger, and may keep the reference to the creator object
  alive longer than necessary. If possible, the class should be made
  static.

Change-Id: I9f49de32b4cd81b7ef1239b390353689263bf66e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-12 00:39:21 -05:00
David Turner 623851ec16 TransportCommand#setTimeout: Specify units for timeout in Javadoc
Change-Id: Iadf0e2c6483794e43a5326f6be6bb34c19b00564
Signed-off-by: David Turner <dturner@twosigma.com>
2017-12-12 13:25:05 +09:00
Matthias Sohn 9d79dc95e2 Fix typo in key of a JGitText externalized string
Change-Id: I0d22e24a0aa3b17339ef68849554f7c99b350dde
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-11 09:35:15 +09:00
Matthias Sohn b46656077a Fix typo in key of a JGitText externalized string
Change-Id: I0d22e24a0aa3b17339ef68849554f7c99b350dde
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-10 18:33:23 +01:00
Matthias Sohn 032750acbf Merge branch 'stable-4.9'
* stable-4.9:
  Fix IllegalThreadStateException if stderr closed without exiting

Change-Id: I8a6a6788c2bb000171233b88d9592ed0640ad15e
2017-12-10 18:10:34 +01:00
Dmitry Pavlenko 7ccf38adc6 Fix IllegalThreadStateException if stderr closed without exiting
If some process executed by FS#readPipe lived for a while after
closing stderr, FS#GobblerThread#run failed with an
IllegalThreadStateException exception when accessing p.exitValue()
for the process which is still alive.

Add Process#waitFor calls to wait for the process completion.

Bug: 528335
Change-Id: I87e0b6f9ad0b995dbce46ddfb877e33eaf3ae5a6
Signed-off-by: Dmitry Pavlenko <pavlenko@tmatesoft.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-10 18:00:55 +01:00
David Pursehouse 0e5b9f8a39 CloneCommand: Refactor listing of files in deleteChildren
File.listFiles() returns null if the given File does not represent a
directory, so we can just test for null instead of making a separate
call to FS.DETECTED.isDirectory()

This also avoids a false-positive error from SpotBugs which claims
that there is a potential null-pointer exception on dereferencing the
result of Files.listFiles().

Change-Id: I18e09e391011db997470f5a09d8e38bb604c0213
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-08 17:16:34 +09:00
David Pursehouse c89a11213e DfsBlockCache#creditSpace: release clockLock in finally block
Enclose the call to getStat in a `try`, and release the previously
acquired lock in the `finally`. This prevents that the lock is left
unreleased in the case of an exception being raised in getStat.

Change-Id: I17b4cd134dae887e23a1165253be0ac2d4fd452c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-07 20:02:59 +09:00
David Pursehouse 61790cb931 FS_POSIX: Fix boxing/unboxing of Boolean
Boolean is being abused to represent three possible states of atomic
file creation support (true/enabled, false/disabled, null/undefined).

Replace this with an enum of the three explicit states.

Change-Id: I2cd7fa6422311dc427823304b082ce8da50d2fbe
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-07 20:02:59 +09:00
David Pursehouse 171f84a041 Use constants from StandardCharsets instead of hard-coded strings
Instead of hard-coding the charset strings "US-ASCII", "UTF-8", and
"ISO-8859-1", use the corresponding constants from StandardCharsets.

UnsupportedEncodingException is not thrown when the StandardCharset
constants are used, so remove the now redundant handling.

Because the encoding names are no longer hard-coded strings, also
remove redundant $NON-NLS warning suppressions.

Also replace existing usages of the constants with static imports.

Change-Id: I0a4510d3d992db5e277f009a41434276f95bda4e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-07 20:02:59 +09:00
David Pursehouse 34d56fd277 Merge branch 'stable-4.9'
* stable-4.9:
  LfsStore: Make inner class AppServer static
  DirCacheCheckout#processEntry: Fix typo in javadoc

Change-Id: Id8e4a3c4dc741e6e0182522e72ecb4b34ae419eb
2017-12-07 08:13:45 +09:00
Thomas Wolf 7f2ef4b6ba TransportHttp: retry on IOException with another mechanism
When a 401 occurs on POST and the server advertises Negotiate, we
may get an exception from GSSAPI if the client isn't configured
at all for Kerberos.

Add exception logic similar to the GET case: keep trying other
authentication mechanisms if this occurs.

Bug: 501167
Change-Id: Ic3a3368378d4b3408a35aec93e78ef425d54b3e4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-12-06 17:12:48 -05:00
David Pursehouse 2f0a880bd6 DirCacheCheckout#processEntry: Fix typo in javadoc
Change-Id: Ie08a6275f4656ebb46abe8748b73b0fb52a98a35
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-06 20:00:21 +09:00
David Pursehouse df3a7c32a4 ConfigTest: Move pathToString to FileUtils
ConfigTest#pathToString is not visible to FileBasedConfigTest when
bulding with bazel.

Move it to FileUtils rather than messing about with the bazel build
rules to make it visible.

Change-Id: Idcfd4822699dac9dc4a426088a929a9cd31bf53f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-12-06 09:34:07 +09:00
Marc Strapetz 26d78902f8 FileBasedConfig: support for relative includes
Relative include.path are now resolved against the config's parent
directory. include.path starting with ~/ are resolved against the
user's home directory

Change-Id: I91911ef404126618b1ddd3589294824a0ad919e6
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-04 23:38:24 +01:00
Marc Strapetz b8f2577472 Config: extract method to read included config
Change-Id: I2c55af3e5fe29e0ce8e3d05e4b54ec961d3f863a
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-12-04 23:38:24 +01:00
Matthias Sohn 68c77a4d39 Prepare 4.9.2-SNAPSHOT builds
Change-Id: I5879ad4aee94ff6783b5589728912117f2495dd3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-03 14:17:43 +01:00
Matthias Sohn a3588cbb2a JGit v4.9.1.201712030800-r
Change-Id: I8bf477778c9dac41cb65233a9e7d590531a836b7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-03 13:59:36 +01:00
Matthias Sohn d2a23afb53 Silence API warnings for reintroduced ResolveMerger#processEntry
This was silenced before but suppression was unintentionally lost in
merge commit 6858339c1e.
This method was removed in 4.9.0 and reintroduced in 4.9.1 to avoid
breaking EMF compare versions which were built against older versions.

See: abf420302b
Change-Id: I152d58ac885e044bcab682b9423f6cc83b667989
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-12-03 13:58:34 +01:00
Matthias Sohn 470629a237 Merge branch 'stable-4.9'
* stable-4.9:
  GC: Delete stale temporary packs and indexes

Change-Id: I49b37845ee8a465404b801a2d8de0205a2e7ba30
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-11-30 23:24:25 +09:00
Shawn Pearce 64ec65ee47 Merge "Break down DfsBlockCache stats by pack file extension." 2017-11-28 15:37:30 -05:00
Jonathan Nieder 04b8168beb RepoCommand: Skip RemoteReader when encountering a full SHA-1
There is no point in calling back to the RemoteReader to resolve a
40-digit hex SHA-1 to itself.  We already skip that call when not
ignoring remote failures; skip it when ignoring remote failures, too.

This should simplify RemoteReader implementations.

Reported-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I7566968ed1f39b1ad73574fa903faf3ee308eb87
2017-11-28 08:17:04 -08:00
Minh Thai 159da6dacc Break down DfsBlockCache stats by pack file extension.
Change-Id: Iaecf0580279b33e3e2439784528cae7b69fb28bc
Signed-off-by: Minh Thai <mthai@google.com>
2017-11-27 21:55:21 -08:00
Hector Caballero bac4d32d39 GC: Delete stale temporary packs and indexes
When a GC operation is interrupted, temporary packs and indexes can be
left on the pack folder. In big, busy repositories this can lead to
significant amounts of wasted disk space if this interruption is done
with a certain frequency.

Remove stale temporary packs and indexes at the end of the GC process so
they do not accumulate. To avoid interfering with a possible concurrent
JGit GC process in the same repository, only delete temporary files that
are older than one day.

Change-Id: If9b6c1e57fac8a6a0ecc0a703089634caba4caae
Signed-off-by: Hector Caballero <hector.caballero@ericsson.com>
2017-11-24 05:13:24 -05:00
Stephen Lawson e3f19a5298 Performance improvement on writing a large index
The index header consists of a 4-byte version number. The current
supported version numbers are 2 and 3. The code checks if any entries
are extended. If it finds any entries that are extended it picks version
'3', otherwise it chooses version '2'.


DirCache.java
-Changed the 'extended' check to exit early when any entry is considered
'extended' in the index.

(Of course, I maybe missing a bitwise optimization that is made in
the Java bytecode.)

Change-Id: If70db9454befe683319b974ebd3774060be9445d
Signed-off-by: Stephen Lawson <slawson@ptc.com>
2017-11-23 20:07:41 -05:00
Matthias Sohn ced98986f9 Fix discouraged access warnings in RefsUnreadableInMemoryRepository
Change-Id: I16e291f533625c80b1d39f7cbaf40efbdfcc2c3c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-24 01:23:07 +01:00
Matthias Sohn f0c119de4f Merge branch 'stable-4.9'
* stable-4.9:
  Ignore warning for minor version change without API change
  Silence boxing warning
  Prepare 4.5.5-SNAPSHOT builds
  JGit v4.5.4.201711221230-r
  Fix LockFile semantics when running on NFS
  Honor trustFolderStats also when reading packed-refs
  Prepare 4.5.4-SNAPSHOT builds
  JGit v4.5.3.201708160445-r

Change-Id: Icc33d2e36f140e8714fce088379673a8834ae9de
2017-11-24 01:18:13 +01:00
Matthias Sohn 03abd1dff2 Ignore warning for minor version change without API change
- this is a new warning option in Eclipse 4.7 and higher
- we always change version of all bundles in a release to keep release
engineering simple

Change-Id: Ic7523d77b67b2802f1bab3bc70af250d712a034f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-24 01:12:14 +01:00
Matthias Sohn 6858339c1e Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Silence boxing warning
  Prepare 4.5.5-SNAPSHOT builds
  JGit v4.5.4.201711221230-r
  Fix LockFile semantics when running on NFS
  Honor trustFolderStats also when reading packed-refs
  Prepare 4.5.4-SNAPSHOT builds
  JGit v4.5.3.201708160445-r

Change-Id: I7cf2e48934195430b3945b6d74b092f93a3ccd36
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-24 01:08:23 +01:00
Matthias Sohn 4ac790fda8 Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  Silence boxing warning
  Prepare 4.5.5-SNAPSHOT builds
  JGit v4.5.4.201711221230-r
  Fix LockFile semantics when running on NFS
  Honor trustFolderStats also when reading packed-refs
  Prepare 4.5.4-SNAPSHOT builds
  JGit v4.5.3.201708160445-r

Change-Id: Iaa99ec84594baf733c993c2d6768281ff14f545a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-22 23:30:13 +01:00
Matthias Sohn 5f79ef0ba4 Merge branch 'stable-4.6' into stable-4.7
* stable-4.6:
  Silence boxing warning
  Prepare 4.5.5-SNAPSHOT builds
  JGit v4.5.4.201711221230-r
  Fix LockFile semantics when running on NFS
  Honor trustFolderStats also when reading packed-refs
  Prepare 4.5.4-SNAPSHOT builds
  JGit v4.5.3.201708160445-r

Change-Id: I8f6bc09540727c6273d22775a9f9ca382a729c9b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-22 23:07:01 +01:00
Matthias Sohn 182d3b3dad Silence boxing warning
Change-Id: I36c40eb91ce0c51f89b47911fa14beffcbc0a7cd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-22 21:34:37 +01:00
Matthias Sohn 3ac44f1b38 Merge branch 'stable-4.5' into stable-4.6
* stable-4.5:
  Prepare 4.5.5-SNAPSHOT builds
  JGit v4.5.4.201711221230-r
  Fix LockFile semantics when running on NFS
  Honor trustFolderStats also when reading packed-refs
  Prepare 4.5.4-SNAPSHOT builds
  JGit v4.5.3.201708160445-r

Change-Id: Ie9c8e0d9172c8d53f075c284bf2a9677980d8dfb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-22 21:34:08 +01:00
Matthias Sohn 7608de5e5d Prepare 4.5.5-SNAPSHOT builds
Change-Id: I71f946f2875716670a2d74c21a8ab38a1f53a25c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-22 19:27:22 +01:00
Matthias Sohn 6372c60ab2 JGit v4.5.4.201711221230-r
Change-Id: Ia1079da239c5b3fde1ba8d2acc4e465a46297b4d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-22 18:31:24 +01:00
Christian Halstrick 10e65cb4fa Fix LockFile semantics when running on NFS
When running on NFS there was a chance that JGits LockFile
semantic is broken because File#createNewFile() may allow
multiple clients to create the same file in parallel. This
change provides a fix which is only used when the new config
option core.supportsAtomicCreateNewFile is set to false. The
default for this option is true. This option can only be set in the
global or the system config file. The repository config file is not
taken into account in this case.

If the config option core.supportsAtomicCreateNewFile is true
then File#createNewFile() is trusted and the behaviour doesn't
change.

But if core.supportsAtomicCreateNewFile is set to false then after
successful creation of the lock file a hardlink to that lock file is
created and the attribute nlink of the lock file is checked to be 2. If
multiple clients manage to create the same lock file nlink would be
greater than 2 showing the error.

This expensive workaround is described in
 https://www.time-travellers.org/shane/papers/NFS_considered_harmful.html
section III.d) "Exclusive File Creation"

Change-Id: I3d2cc48d8eb280d5f7039eb94da37804f903be6a
2017-11-22 18:15:11 +01:00
David Pursehouse bd052b94aa Merge branch 'stable-4.9'
* stable-4.9:
  Yet another work-around for a Jsch bug: timeouts

Change-Id: I7cf227c62a3c06f91cee1a6c61719b6fe50da883
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-11-22 11:31:29 +09:00
Christian Halstrick 218cf3403d Honor trustFolderStats also when reading packed-refs
Then list of packed refs was cached in RefDirectory based on mtime of
the packed-refs file. This may fail on NFS when attributes are cached.
A cached mtime of the packed-refs file could cause JGit to trust the
cached content of this file and to overlook that the file is modified.

Honor the config option trustFolderStats and always read the packed-refs
content if the option is false. By default this option is set to true
and this fix is not active.

Change-Id: I2b65cfaa8f4aba2efbf8a5e865d3f09f927e2eec
2017-11-21 21:21:22 +01:00
Thomas Wolf 5284cc1bf7 Yet another work-around for a Jsch bug: timeouts
Jsch 0.1.54 passes on the values from ~/.ssh/config for
"ServerAliveInterval" and "ConnectTimeout" as read from
the config file to java.net.Socket.setSoTimeout(). That
method expects milliseconds, but the values in the config
file are seconds!

The missing conversion in Jsch means that the timeout is
set way too low, and if the server doesn't respond within
that very short time frame, Jsch kills the connection and
then throws an exception with a message such as "session is
down" or "timeout in waiting for rekeying process".

As a work-around, do the conversion to milliseconds in the
Jsch-facing Config interface of OpenSshConfig. That way Jsch
already gets these values as milliseconds.

Bug: 526867
Change-Id: Ibc9b93f7722fffe10f3e770dfe7fdabfb3b97e74
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-11-20 22:44:23 +01:00
Dave Borowitz 8b3ab4343c Config: Handle leading/trailing single whitespaces
Change-Id: I468106acd2006d0a174c76dfd4bce231f1c7a6f8
2017-11-20 13:55:25 -05:00
David Pursehouse 3efea067a3 Merge branch 'stable-4.9'
* stable-4.9:
  Fix NPE in TransportGitSsh.ExtSession.exec()
  Add missing help text for rev-parse's --verify option
  Remove final modifier on args4j argument field in RevParse

Change-Id: I5ac9e2f185f2210ee76970501710b99b12e93e75
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-11-20 15:38:43 +09:00
Matthias Sohn 29c5f49f63 Fix NPE in TransportGitSsh.ExtSession.exec()
Bug: 527383
Change-Id: I965860b4e0e9aa1adf6a1bb0735940cbd22adced
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-20 00:35:37 -05:00
Minh Thai 15a189e4e0 Add flag for keeping ref tombstones in GC reftable
A tombstone will prevent a delayed reference update from resurrecting the
deleted reference.

Change-Id: Id9f4df43d435a299ff16cef614821439edef9b11
Signed-off-by: Minh Thai <mthai@google.com>
2017-11-15 22:48:04 -08:00
Minh Thai f3897ac6c3 Preserve ref tombstone when compact top retable stack
Change-Id: I07f5ad572b4642a7cdd76d92aa98f3b6c63d9fa2
Signed-off-by: Minh Thai <mthai@google.com>
2017-11-15 22:47:09 -08:00
David Pursehouse 6ec5d8ddb1 TreeWalk: Make getEolStreamType(OperationType) public
and deprecate getEolStreamType().

This resolves a TODO that was apparently supposed to be done in
version 4.4.

Change-Id: I5c9861aedabdc3f99dcf47519b3959a979e6a591
2017-11-15 10:37:56 +09:00
David Pursehouse 2a15a63005 TreeWalk: Fix indentation
Change-Id: I040aaaf4e3f1e3458e0ece52d1d046f501272fc2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-11-15 10:37:56 +09:00
David Pursehouse ef12214a7c Merge "ObjectDirectory: Add pack directory getter" 2017-11-14 20:37:26 -05:00
David Pursehouse 33b796869c Merge "Add return tag" 2017-11-14 20:37:14 -05:00
Jonathan Nieder 295c5ea7d3 Merge "ReftableCompactor should accept 0 for minUpdateIndex" 2017-11-14 15:05:19 -05:00
Minh Thai 0e5abbfafc ReftableCompactor should accept 0 for minUpdateIndex
Do not use 0 as the unset value for minUpdateIndex, as input reftables
may have minUpdateIndex starting at 0.

Change-Id: Ie040a6b73d4a5eba5521e51d0ee4580713c84a3e
Signed-off-by: Minh Thai <mthai@google.com>
2017-11-14 10:50:24 -08:00
Hector Caballero 4334b27d3c ObjectDirectory: Add pack directory getter
So far, in order to get the pack directory it was necessary to resolve
it from the object directory. This resolution is already done when
creating the object directory, so simplify the call by just adding a
getter to the pack directory.

Change-Id: I69e783141dc6739024e8b3d5acc30843edd651a7
Signed-off-by: Hector Caballero <hector.caballero@ericsson.com>
2017-11-14 10:08:42 -05:00
Hector Caballero 178c5d2f0e Add return tag
Eclipse was complaining about the missing tag for the return type.

Change-Id: I43c7e823c3090b19dc8202c1e4d7968e1fa8e6bb
Signed-off-by: Hector Caballero <hector.caballero@ericsson.com>
2017-11-14 10:08:42 -05:00
Marc Strapetz 9bb126d12d FileUtils.toPath to convert File to Path
When invoking File.toPath(), an (unchecked) InvalidPathException may be
thrown which should be converted to a checked IOException.

For now, we will replace File.toPath() by FileUtils.toPath() only for
code which can already handle IOExceptions.

Change-Id: I0f0c5fd2a11739e7a02071adae9a5550985d4df6
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
2017-11-14 10:07:37 +01:00
Matthias Sohn 4bdf0ec679 Silence invalid @since 3.5 API warning on ResolveMerge#processEntry
This method was removed in 4.9 and reintroduced in
I48ba4308dee73925fa32d6c2fd6b5fd89632c571 as deprecated in 4.9.1 in
order to help EMF Compare to avoid breakage.

Change-Id: Ia638517178313da42ae13ebcf88ad535d9a02723
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-13 22:41:57 +01:00
David Pursehouse 1a091ff5f9 Merge changes I335587ee,I4182a174
* changes:
  Merge branch 'stable-4.9'
  Remove an unused import from PackParserTest
2017-11-10 22:05:50 -05:00
Zhen Chen c93c653ccf Add a setting for fsck to check connectivity only
The object checks may take a long time and sometimes we are only
interested in connectivity check.

This is similar to 'git fsck --connectivity-only'.

Change-Id: I654e8fdccdb16d796f920088429d188cc96734bc
Signed-off-by: Zhen Chen <czhen@google.com>
2017-11-10 19:33:28 -05:00
Matthias Sohn 19ef730d74 Merge branch 'stable-4.9'
* stable-4.9:
  Work around a Jsch bug: ensure the user name is set from URI
  Reintroduce protected method which removal broke EMF Compare

Change-Id: I335587eee279f91bd36c9ba9fc149b17a6db6110
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-11 01:01:03 +01:00
Jonathan Nieder b88204edfb Merge changes I22a8874b,I68ed4abd,I740bc4bf,Icbd17d15
* changes:
  BitmapWalker: do not revisit objects in bitmap
  Use bitmaps for non-commit reachability checks
  Make PackWriterBitmapWalker public
  UploadPackTest: construct commits in test method
2017-11-10 18:52:53 -05:00
Jonathan Tan c9d25505d8 BitmapWalker: do not revisit objects in bitmap
Currently, BitmapWalker walks through every object returned by the
internal ObjectWalk, regardless of whether that object has already
been marked in the bitmap. Set an object filter to ensure that only
bitmap-unmarked objects are walked through.

Change-Id: I22a8874b1e571df3c33643b365036d95f52fe7c7
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2017-11-10 15:41:31 -08:00
Jonathan Tan d3021788d2 Use bitmaps for non-commit reachability checks
Currently, unless RequestPolicy#ANY is used, UploadPack rejects all
non-commit "want" lines unless they were advertized. This is fine,
except when "uploadpack.allowreachablesha1inwant" is true
(corresponding to RequestPolicy#REACHABLE_COMMIT), in which case one
would expect that "want"-ing anything reachable would work.

(There is no restriction that "want" lines must only contain commits -
it is allowed for refs to directly point to trees and blobs, and
requesting for them using "want" lines works.)

This commit has been written to avoid performance regressions as much
as possible. In the usual (and currently working) case where the only
unadvertized things requested are commits, we do a standard RevWalk in
order to avoid incurring the cost of loading bitmaps. However, if
unadvertized non-commits are requested, bitmaps are used instead, and
if there are no bitmaps, a WantNotValidException is thrown (as is
currently done).

Change-Id: I68ed4abd0e477ff415c696c7544ccaa234df7f99
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2017-11-10 15:41:31 -08:00
Jonathan Tan ccf25f9541 Make PackWriterBitmapWalker public
Make PackWriterBitmapWriter class public and move it to a more central
location, in preparation for its use by another class (in a subsequent
commit).

One of its inner static classes, AddUnseenToBitmapFilter, previously
package-private, is also used directly in its former package. Therefore,
AddUnseenToBitmapFilter and its sibling class have been moved to an
internal package instead.

Change-Id: I740bc4bfc4e4e3c857d1ee7d25fe45e90cd22a75
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2017-11-10 15:41:31 -08:00
Thomas Wolf f67af4e16b Work around a Jsch bug: ensure the user name is set from URI
JSch unconditionally overrides the user name given in the connection
URI by the one found in ~/.ssh/config (if that does specify one for
the used host). If the SSH config file has a different user name,
we'll end up using the wrong name, which typically results in an
authentication failure or in Eclipse/EGit asking for a password for
the wrong user.

Unfortunately there is no way to prevent or circumvent this Jsch
behavior up front; it occurs already in the Session constructor at
com.jcraft.jsch.Session() and the Session.applyConfig() method. And
while there is a Session.setUserName() that would enable us to correct
this, that latter method has package visibility only.

So resort to reflection to invoke that setUserName() method to ensure
that Jsch uses the user name from the URI, if there is one.

Bug: 526778
Change-Id: Ia327099b5210a037380b2750a7fd76ff25c41a5a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-11-10 10:16:58 +01:00
Shawn Pearce 2ec71a7c0e Reject pack if delta exceeds array size limit
JGit's delta handling code requires the target to be a single byte
array. Any attempt to inflate a delta larger than fits in the 2GiB
limit will fail with some form of array index exceptions. Check for
this overflow early and abort pack parsing.

Change-Id: I5bb3a71f1e4f4e0e89b8a177c7019a74ee6194da
2017-11-09 09:27:54 -08:00
Zhen Chen fdf8620ec9 Check non-flushed packs for existence of object
Change-Id: Id466909d70ec6f828c904692139891dec880305e
Signed-off-by: Zhen Chen <czhen@google.com>
2017-11-07 14:12:19 -08:00
Matthias Sohn 021e72b801 Update spotbugs-maven-plugin to 3.1.0-RC7
Change-Id: Ic1c2c5b6e3955a1404780e51206513d226600e4b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-11-04 12:45:22 -04:00
Matthias Sohn 031646963f Merge "Reintroduce protected method which removal broke EMF Compare" into stable-4.9 2017-11-02 12:59:11 -04:00
David Pursehouse 651e17baca Merge branch 'stable-4.9'
* stable-4.9:
  PackInserter: Implement newReader()
  Move some strings from DfsText to JGitText
  FileRepository: Add pack-based inserter implementation
  ObjectDirectory: Factor a method to close open pack handles
  ObjectDirectory: Remove last modified check in insertPack

Change-Id: Ifc9ed6f5d8336bc978818a64eae122bceb933e5d
2017-11-02 08:30:01 +09:00
Dave Borowitz 678c99c057 PackInserter: Implement newReader()
Change-Id: Ib9e7f6439332eaed3d936f895a5271a7d514d3e9
2017-11-01 13:00:24 -04:00
Dave Borowitz 080b4770e7 Move some strings from DfsText to JGitText
Change-Id: I60050e5127d12b6139d81859dba929fcfaabe504
2017-11-01 12:41:38 -04:00
Dave Borowitz f7ceeaa23f FileRepository: Add pack-based inserter implementation
Applications that use ObjectInserters to create lots of individual
objects may prefer to avoid cluttering up the object directory with
loose objects. Add a specialized inserter implementation that produces a
single pack file no matter how many objects. This inserter is loosely
based on the existing DfsInserter implementation, but is simpler since
we don't need to buffer blocks in memory before writing to storage.

An alternative for such applications would be to write out the loose
objects and then repack just those objects later. This operation is not
currently supported with the GC class, which always repacks existing
packs when compacting loose objects. This in turn requires more
CPU-intensive reachability checks and extra I/O to copy objects from old
packs to new packs.

So, the choice was between implementing a new variant of repack, or not
writing loose objects in the first place. The latter approach is likely
less code overall, and avoids unnecessary I/O at runtime.

The current implementation does not yet support newReader() for reading
back objects.

Change-Id: I2074418f4e65853b7113de5eaced3a6b037d1a17
2017-11-01 12:40:53 -04:00
Dave Borowitz 5ce1cc3d43 ObjectDirectory: Factor a method to close open pack handles
Change-Id: I9490c4583fdf801de9c0bb09595ebb8fb4926988
2017-11-01 12:40:13 -04:00
Dave Borowitz 5b5c3a2e1d ObjectDirectory: Remove last modified check in insertPack
GC explicitly handles the case where a new pack has the same name as an
existing pack due to it containing the exact same set of objects. In
this case, the pack passed to insertPack will have the same name as an
existing pack, but it will also almost certainly have a later mtime than
the existing pack.

The loop in insertPack tried to short-circuit when inserting a new pack,
to avoid walking more of the pack list than necessary. Unfortunately,
this means it will never get to the check for an identical name,
resulting in a duplicate entry for the same PackFile in the pack list.
Remove the short-circuit so that insertPack does not insert a duplicate
entry.

Change-Id: I00711b28594622ad3bd104332334e8a3592cda7f
2017-11-01 10:47:59 -04:00
Saša Živkov 176466ed28 Move loggers to the top of their class
There is a possibility of hitting NPE on a logger if it is not the first
statically initialized member. For example, if another static
initializer creates an instance of its class and the logger is used
from the constructor.

Change-Id: I51fa855a8883c107f2e4ef5ac039dc12a571a7ae
2017-10-30 04:43:51 -04:00
Terry Parker 7fcb7854b2 Merge "Align PackStatistics and DfsPackDescription list length" 2017-10-26 18:22:49 -04:00
Matthias Sohn abf420302b Reintroduce protected method which removal broke EMF Compare
So far we follow OSGi semantic versioning [1] which says the following:

"A change in the second (minor) part of the version signals that the
change is backward compatible with consumers of the API package but not
with the providers of that API. That is, when the API package goes from
version 1.5 to 1.6 it is no longer compatible with a provider of that
API but consumers of that API are backward compatible with that API
package."

The change Ib5fbf17bdaf727bc5d0e106ce88f2620d9f87a6f broke EMF Compare
which subclasses ResolveMerger since we added a new parameter to the
protected ResolveMerger.processEntry() method. According to the above
cited OSGi semantic versioning this is ok, implementers should expect
that they break on minor version changes of the API they implement.

This change reintroduces the old processEntry() method in order to help
avoid breakage for existing EMF Compare versions which expect breakage
also for the implementer case only for major version change (in this
case from JGit 4.x to 5.x).

[1] http://www.osgi.org/wp-content/uploads/SemanticVersioning1.pdf

See: https://dev.eclipse.org/mhonarc/lists/jgit-dev/msg03431.html
Change-Id: I48ba4308dee73925fa32d6c2fd6b5fd89632c571
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-24 23:13:37 +02:00
Han-Wen NIenhuys dc24383b6b Revert "Throw BinaryBlobException from RawParseUtils#lineMap."
This reverts commit f2e64cd895.

The newly added throws clause breaks backward compatibility. 

Change-Id: Ifa76a1b95935e52640b81cd53c171eb17da175c2
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2017-10-24 11:26:10 -04:00
Han-Wen Nienhuys f5ae26f74d Fix typo in comment
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I04912b32b55dd61ad2d2e7ccb5d688655b1dc335
2017-10-24 15:32:50 +02:00
Han-Wen Nienhuys f2e64cd895 Throw BinaryBlobException from RawParseUtils#lineMap.
This makes detection of binaries exact for ResolveMerger and
DiffFormatter: they will classify files as binary regardless of where
the '\0' occurs in the text.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Id4342a199628d9406bfa04af1b023c27a47d4014
2017-10-24 15:31:34 +02:00
Han-Wen Nienhuys ced658c445 Avoid loading and merging binary data in ResolveMerger
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Ide4b68872d426aa262142f224acf636c776b35d3
2017-10-24 15:07:04 +02:00
Han-Wen Nienhuys 2b444d781c Introduce ObjectLoader.Filter for delegation
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I78ada3f4023c4304b19f94fb044024f0f0b2cbbe
2017-10-24 15:03:38 +02:00
Han-Wen Nienhuys ea2a4e3abe Introduce RawText#load.
This method creates a RawText from a blob, but avoids reading the blob
if the start contains null bytes. This should reduce the amount of
garbage that Gerrit produces for changes with binaries.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Idd202d20251f2d1653e5f1ca374fe644c2cf205f
2017-10-24 14:49:10 +02:00
Matthias Sohn fbefe1e999 Add missing @since tags for new API in ReceiveCommand
Change-Id: I6e5d29390b71a1c123bc90ec2e3435706ea9211c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-23 14:22:28 +02:00
David Pursehouse f89101105e Merge branch 'stable-4.9'
* stable-4.9:
  Avoid bad rounding "1 year, 12 months" in date formatter
  Ensure that ~ in ssh config is replaced before Jsch sees it

Change-Id: If6ca55f9447aaea3d7c2d36c03520d5e6dd5193e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-10-23 12:08:59 +09:00
Michael Keppler e1a39cbbe7 Avoid bad rounding "1 year, 12 months" in date formatter
Round first, then calculate the labels. This avoids "x years, 12 months"
and instead produces "x+1 years".

One test case has been added for the original example the bug was found
with, and one assertion has been moved from an existing test case to the
new test case, since it also triggered the bug.

Bug: 525907
Change-Id: I3270af3850c4fb7bae9123a0a6582f93055c9780
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-23 11:33:55 +09:00
Masaya Suzuki 45837ff189 Align PackStatistics and DfsPackDescription list length
Without this the caller cannot tell which PackStatistics is for which
pack file.

Change-Id: Ifa530f8bc82459611ae694c0a0d111daec3e08f3
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
2017-10-20 12:28:34 -07:00
Shawn Pearce 7cd5d77ae3 dfs: Switch InMemoryRepository to DfsReftableDatabase
This ensure DfsReftableDatabase is tested by the same test suites that
use/test InMemoryRepository. It also simplifies the logic of
InMemoryRepository and brings its compatibility story closer to any
other DFS repository that uses reftables for its reference storage.

Change-Id: I881469fd77ed11a9239b477633510b8c482a19ca
Signed-off-by: Minh Thai <mthai@google.com>
Signed-off-by: Terry Parker <tparker@google.com>
2017-10-18 17:35:27 -07:00
Terry Parker 4b75d5223a Merge changes from topic 'reftable'
* changes:
  dfs: reftable backed DfsRefDatabase
  Support symbolic references in ReceiveCommand
2017-10-18 20:25:08 -04:00
Shawn Pearce 1d31257a5d dfs: reftable backed DfsRefDatabase
DfsReftableDatabase is a new alternative for DfsRefDatabase that
handles more operations for the implementor by delegating through
reftables. All reftable files are stored in sibling DfsObjDatabase
using PackExt.REFTABLE and PackSource.INSERT.

Its assumed the DfsObjDatabase periodically runs compactions and GCs
using DfsPackCompactor and DfsGarbageCollector. Those passes are
essential to collapsing the stack of reftables.

Change-Id: Ia03196ff6fd9ae2d0623c3747cfa84357c6d0c79
Signed-off-by: Minh Thai <mthai@google.com>
Signed-off-by: Terry Parker <tparker@google.com>
2017-10-18 16:45:02 -07:00
Thomas Wolf adbf0935e1 Ensure that ~ in ssh config is replaced before Jsch sees it
Do tilde replacement for values from the ssh config file that are
file names in all cases to make sure that they are already replaced
when Jsch tries to get the values.

Previously, OpenSshConfig did tilde replacement only for the
IdentityFile in the JGit-facing "Host" interface and left the
replacement in the Jsch-facing "Config" interface to Jsch.

But on Windows the JGit notion of what should be used to replace the
tilde differs from Jsch's replacement. Jsch always replaces the tilde
by the value of the system property "user.home", whereas JGit also
considers some environment variables like %HOME%. This can lead to
rather surprising failures as in the case of bug 526175 where
%HOME% != user.home.

Prior to commit 9d24470 (i.e.,prior to JGit 4.9.0) this problem never
occurred because Jsch was completely unaware of the ssh config file
and all host and IdentityFile handling happened exclusively in JGit.

Bug: 526175
Change-Id: I1511699664ffea07cb58ed751cfdb79b15e3a99e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-10-18 22:45:36 +02:00
Shawn Pearce 7f59cfe143 Support symbolic references in ReceiveCommand
Allow creating symbolic references with link, and deleting them or
switching to ObjectId with unlink.  How this happens is up to the
individual RefDatabase.

The default implementation detaches RefUpdate if a symbolic reference
is involved, supporting these command instances on RefDirectory.
Unfortunately the packed-refs file does not support storing symrefs,
so atomic transactions involving more than one symref command are
failed early.

Updating InMemoryRepository is deferred until reftable lands, as I
plan to switch InMemoryRepository to use reftable for its internal
storage representation.

Change-Id: Ibcae068b17a2fc6d958f767f402a570ad88d9151
Signed-off-by: Minh Thai <mthai@google.com>
Signed-off-by: Terry Parker <tparker@google.com>
2017-10-18 13:42:20 -07:00
Michael Keppler b81c980a35 Avoid bad rounding "1 year, 12 months" in date formatter
Round first, then calculate the labels. This avoids "x years, 12 months"
and instead produces "x+1 years".

One test case has been added for the original example the bug was found
with, and one assertion has been moved from an existing test case to the
new test case, since it also triggered the bug.

Bug: 525907
Change-Id: I3270af3850c4fb7bae9123a0a6582f93055c9780
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-18 00:39:46 +02:00
Zhen Chen 0f814a2a6c Skip unreachable garbage packs in dfs fsck
Change-Id: I8899e0faf1e4e6386dfd57340dfa4f4fdebc3cf3
Signed-off-by: Zhen Chen <czhen@google.com>
2017-10-09 11:00:32 -07:00
Matthias Sohn 6b544da293 Prepare 4.10.0-SNAPSHOT builds
Change-Id: I5ca462d1db18a2c5c9382cfb9c83972510fa2b88
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-08 11:35:54 +02:00
Matthias Sohn 8180183289 Prepare 4.9.1-SNAPSHOT builds
Change-Id: Ic49fd093d3fe4324c4d83aba74033040fcaa37a6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-08 11:25:06 +02:00
Matthias Sohn 6877730fa0 JGit v4.9.0.201710071750-r
Change-Id: I487f6aa3d0c4ef1d57f91cdc36177d994ae24c51
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-07 23:46:52 +02:00
Till Brychcy 401c6c98b5 Terminate StreamCopy threads in case of errors
- fix NPE: don't invoke close() if no exception happened.

Bug: 513554
Change-Id: I29f9b2ac1607ee26521e8aba334facd20e4ad79c
Signed-off-by: Till Brychcy <register.eclipse@brychcy.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-10-07 00:03:45 +02:00
Zhen Chen 65f9046547 Use a new RevWalk for validating not advertised wants
Shadow commits in the RevWalk in the UploadPack object may cause the
UNINTERESTING flag not being carried over to their parents commits since
they were marked NO_PARENTS during the assumeShallow or
initializeShallowCommits call.

A new RevWalk needs to be created for this reason, but instead of
creating a new RevWalk from Repository, we can reuse the ObjectReader in
the RevWalk of UploadPack to load objects.

Change-Id: Ic3fee0512d35b4f555c60e696a880f8b192e4439
Signed-off-by: Zhen Chen <czhen@google.com>
2017-10-05 17:16:13 -07:00
Dmitry Neverov a0a8a6a3e4 Terminate StreamCopy threads in case of errors
Bug: 513554
Change-Id: I065836b8fc77ade6de92e4a809fcf770a4f793ec
Signed-off-by: Dmitry Neverov <dmitry.neverov@gmail.com>
2017-09-30 14:01:16 +01:00
Dave Borowitz 2bbe15abd4 ReflogWriter: Align auto-creation defaults with C git
Per git-config(1), core.logAllRefUpdates auto-creates reflogs for HEAD
and for refs under heads, notes, tags, and for HEAD. Add notes and
remove stash from ReflogWriter#shouldAutoCreateLog. Explicitly force
writing reflogs for refs/stash at call sites, now that this is
supported.

Change-Id: I3a46d2c2703b7c243e0ee2bbf6948279800c485c
2017-09-30 12:01:19 +01:00
Dave Borowitz 77a28e0d58 Support force writing reflog on a per-update basis
Even if a repository has core.logAllRefUpdates=true, ReflogWriter does
not create reflog files unless the refs are under a hard-coded list of
prefixes, or unless the forceWrite bit is set. Expose the forceWrite bit
on a per-update basis in RefUpdate/BatchRefUpdate/ReceiveCommand,
creating RefLogWriters as necessary.

Change-Id: Ifc851fba00f76bf56d4134f821d0576b37810f80
2017-09-30 11:55:31 +01:00
Dave Borowitz b1ae96bf84 Ensure ReflogWriter only works with a RefDirectory
The ReflogWriter constructor just took a Repository and called
getDirectory() on it to figure out the reflog dirs, but not all
Repository instances use this storage format for reflogs, so it's
incorrect to attempt to use ReflogWriter when there is not a
RefDirectory directly involved. In practice, ReflogWriter was mostly
only used by the implementation of RefDirectory, so enforcing this is
mostly just shuffling around calls in the same internal package.

The one exception is StashDropCommand, which writes to a reflog lock
file directly. This was a reasonable implementation decision, because
there is no general reflog interface in JGit beyond using
(Batch)RefUpdate to write new entries to the reflog. So to implement
"git stash drop <N>", which removes an arbitrary element from the
reflog, it's fair to fall back to the RefDirectory implementation.
Creating and using a more general interface is well beyond the scope of
this change.

That said, the old behavior of writing out the reflog file even if
that's not the reflog format used by the given Repository is clearly
wrong. Fail fast in this case instead.

Change-Id: I9bd4b047bc3e28a5607fd346ec2400dde9151730
2017-09-30 11:54:05 +01:00
Thomas Wolf 6dab29f4b5 HttpConfig: load user config before reading values from it
Same problem as in commit c227268: openUserConfig() just creates the
FileBasedConfig object, but doesn't read the file yet. An explicit
load() is needed.

As HttpConfig is read-only this omission did not cause any bad effects,
but it simply ignored values from the user config. Most uses of
HttpConfig go through the two-argument constructor, though, where
HttpConfig is given an already loaded repo config.

Change-Id: Ibe7c562c17d6ef37de8b661ab7f6fa0246db01a2
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-26 23:54:45 +02:00
Thomas Wolf c227268995 Load the user config before modifying it
SystemReader.openUserConfig() does not load the config yet; an
explicit StoredConfig.load() is needed.

Bug: 374703
Change-Id: I1c397e2fb1a07ac4d9de3675d996417734ff90e9
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-23 11:15:27 +02:00
David Pursehouse e32aed6d75 SubmoduleUpdateCommand: Add fetch callback
When the submodule already exists, it is fetched instead of
cloned.

Use the fetch callback instead of clone callback in this case.

Change-Id: I170c21ab92b4117f25fdf940fe6807f214b04d39
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-09-20 21:49:47 +02:00
Michael FIG 06835f3e4f Fetch submodule repo before resolving commits
By default, this is turned off unless cmd.setFetch(true) is given.  It
will default to true in a future release to mimic c-git behaviour.

This is needed to prevent Eclipse from crashing with "Missing unknown
[REF]" when cloning a repo with submodules.

Bug: 470318
Change-Id: I8ae37c7c5bd2408cead8d57dd13e93e01e0e9dc1
Signed-off-by: Michael FIG <michael@fig.org>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-09-20 21:49:46 +02:00
Thomas Wolf d946f95c9c Handle SSL handshake failures in TransportHttp
When a https connection could not be established because the SSL
handshake was unsuccessful, TransportHttp would unconditionally
throw a TransportException.

Other https clients like web browsers or also some SVN clients
handle this more gracefully. If there's a problem with the server
certificate, they inform the user and give him a possibility to
connect to the server all the same.

In git, this would correspond to dynamically setting http.sslVerify
to false for the server.

Implement this using the CredentialsProvider to inform and ask the
user. We offer three choices:

1. skip SSL verification for the current git operation, or
2. skip SSL verification for the server always from now on for
   requests originating from the current repository, or
3. always skip SSL verification for the server from now on.

For (1), we just suppress SSL verification for the current instance of
TransportHttp.

For (2), we store a http.<uri>.sslVerify = false setting for the
original URI in the repo config.

For (3), we store the http.<uri>.sslVerify setting in the git user
config.

Adapt the SmartClientSmartServerSslTest such that it uses this
mechanism instead of setting http.sslVerify up front.

Improve SimpleHttpServer to enable setting it up also with HTTPS
support in anticipation of an EGit SWTbot UI test verifying that
cloning via HTTPS from a server that has a certificate that doesn't
validate pops up the correct dialog, and that cloning subsequently
proceeds successfully if the user decides to skip SSL verification.

Bug: 374703
Change-Id: Ie1abada9a3d389ad4d8d52c2d5265d2764e3fb0e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-13 23:23:08 +02:00
Thomas Wolf fdcd4f9a34 Support http.<url>.* configs
Git has a rather elaborate mechanism to specify HTTP configuration
options per URL, based on pattern matching the URL against "http"
subsection names.[1] The URLs used for this matching are always the
original URLs; redirected URLs do not participate.

* Scheme and host must match exactly case-insensitively.
* An optional user name must match exactly.
* Ports must match exactly after default ports have been filled in.
* The path of a subsection, if any, must match a segment prefix of
  the path of the URL.
* Matches with user name take precedence over equal-length path
  matches without, but longer path matches are preferred over
  shorter matches with user name.

Implement this for JGit. Factor out the HttpConfig from TransportHttp
and implement the matching and override mechanism.

The set of supported settings is still the same; JGit currently
supports only followRedirects, postBuffer, and sslVerify, plus the
JGit-specific maxRedirects key.

Add tests for path normalization and prefix matching only on segment
separators, and use the new mechanism in SmartClientSmartServerSslTest
to disable sslVerify selectively for only the test server URLs.

Compare also bug 374703 and bug 465492. With this commit it would be
possible to set sslVerify to false for only the git server using a
self-signed certificate instead of having to switch it off globally
via http.sslVerify.

[1] https://git-scm.com/docs/git-config

Change-Id: I42a3c2399cb937cd7884116a2a32fcaa7a418fcb
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-10 17:37:54 -04:00
David Pursehouse 2dbfe49a42 Add PushConfig class with PushRecurseSubmodulesMode
This will be used later when adding for support for recursing
submodules on push.

Change-Id: Ie2a183e5404a32046de9f6524e6ceeec37919671
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-09-09 13:58:09 -04:00
Thomas Wolf c27f36dfc7 Fix missing RefsChangedEvent when packed refs are used
With atomic ref updates using packed refs, JGit did not fire a
RefsChangedEvent. This resulted in a user-visible regression in
EGit: the UI would not update after a "Fetch from upstream...".
Presumably it would also make Gerrit miss out on ref changes?

Strengthen the BatchRefUpdateTest by also asserting the expected
number of RefsChangedEvents, and ensure modCnt is incremented in
RefDirectory.commitPackedRefs() when refs really changed (as opposed
to some internal housekeeping operation, such as packing loose refs).

Bug: 521296
Change-Id: Ia985bda1d99f45a5f89c8020ca4845e7a66e743e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-07 18:47:45 -04:00
Dave Borowitz bb09e09344 Add FetchCommand#setRefSpecs(String...) variant
Much of the time the caller can specify a RefSpec succinctly using a
string, and doesn't care about calling setters. Add a convenience method
for this case, and use it where applicable in JGit core.

Change-Id: Ic3fac7fc568eee4759236a5264d2e7e5f9b9716d
2017-09-07 07:46:25 -04:00
Shawn Pearce e68a9b3ed8 ReceivePack: clear advertised .haves if application changes refs
An application can choose to invoke setAdvertisedRefs multiple times,
for example several AdvertiseRefsHook installed in a chain. Each of
these invocations populates the advertisedHaves collection with the
unique set of ObjectIds.

This can lead to a server over-advertising with ".have" lines if the
first hook pushes in a lot of references, and the second hook filters
this to a subset.  ReceivePack will advertise the unique objects from
the first hook using ".have" lines, which may lead to a huge
advertisement sent to the client.

This can also contribute to a very slow connectivity check after the
pack is parsed as ReceivePack calls markUninteresting on every commit
in advertisedHaves.  This may require expanding a lot of subtrees to
mark all trees as uninteresting as well.  On a very big repository
this can lead to a many-second stall.

Clear the advertisedHaves collection any time the refs are updated.
Add a test to verify the correct set of objects was sent.

Change-Id: I97f6998d0597251444a2e846a3ea1f461bae96f9
2017-09-07 05:39:47 -04:00
Shawn Pearce d0d15c3848 DfsGarbageCollector: support disabling conversion to reftable
When a repository is initially created using only reftable but doesn't
yet have a GC pack, the garbage collector shouldn't scan the ref
database. Support disabling the reftable conversion path.

Change-Id: Iaaf3a4375cd43760b7181c1bd10244de8b2c5d9e
2017-09-06 16:37:54 -07:00
Shawn Pearce f0a40b1933 Remove dead warning about minUpdaeIndex and maxUpdateIndex affecting refresh
DfsGarbageCollector always performs refreshes.  This warning was from
a prior iteration of the patch set and should have been removed before
the change was merged.

Change-Id: Id4750bb6c1c177e1ef040fd22912f434bbb5e992
2017-09-06 11:12:34 -07:00
Matthias Sohn 5bd9392f96 Remove no longer needed API problem filters
Change-Id: I206682a60ad9228c89efa22f8db9e72e19f17f6d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-09-06 00:58:09 +02:00
David Pursehouse f9ac86fde2 SubmoduleConfig: Simplify #toConfigValue
Just return configValue instead of transforming name().

Change-Id: I7f94ab2e206e93d1370467e187c5e68e8f6a8836
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-09-05 23:30:17 +02:00
Shawn Pearce d26309c4d9 Merge changes from topic 'dfs-reftable'
* changes:
  dfs: write reftable from DfsGarbageCollector
  dfs: compact reftables during DfsPackCompactor
2017-09-05 12:39:53 -04:00
Shawn Pearce d13dfac9dc dfs: write reftable from DfsGarbageCollector
If a ReftableConfig has been supplied by the caller, write out a
reftable as a sibling of the the GC pack, alongside the heads.

To bootstrap from a non-reftable system, the refs are read from the
DfsRefDatabase if no GC reftables are present.  Its assumed the
references are fully current, and do not need to be merged with any
other reftables.  Any non-GC reftables will be pruned at the end of
the GC cycle, just like any packs that were replaced.

If a GC reftable is present, all existing reftables are compacted, and
references from DfsRefDatabase are only used to seed the packer.  Its
assumed these are consistent with each other.

Change-Id: Ie397eb58aaaefb6865c816d9b39de3ac12998019
2017-09-05 09:10:16 -07:00
Shawn Pearce d126bcc5c8 dfs: compact reftables during DfsPackCompactor
Combine intermediate, non-GC reftables when combining pack files.
This shrinks the reftable stack, improving lookup times.

Change-Id: I5dbba41806f99af5ecaff3a3119f6630e9404256
2017-09-05 09:05:08 -07:00
Thomas Wolf 11c476346d Fix Daemon.stop() to actually stop the listener thread
ServerSocket.accept() is not interruptible: a thread busy in accept()
may not react to Thread.interrupt() and may not return from accept()
via an InterruptedException. Close the socket instead to make the
daemon's listener thread terminate.

* Close the listening socket to get the listening thread to exit
  instead of interrupting it.
* Add a stopAndWait() method that stops the listening thread and
  then waits until it has indeed finished.
* Set SO_REUSE_ADDRESS on the listening socket.

Bug: 376369
Change-Id: I9d6014103e6dcb0173daea134feb44dc52c5c69a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-04 23:50:48 +02:00
Shawn Pearce de4e0acc30 Merge "Remove workaround for bug in Java's ReferenceQueue" 2017-09-04 14:35:58 -04:00
Matthias Sohn 39b193b6f4 Remove workaround for bug in Java's ReferenceQueue
Sun's Java 5, 6, 7 implementation had a bug [1] where a Reference can be
enqueued and dequeued twice on the same reference queue due to a race
condition within ReferenceQueue.enqueue(Reference).

This bug was fixed for Java 8 [2] hence remove the workaround.

[1] http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6837858
[2] http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/858c75eb83b5

Change-Id: I2deeb607e3d237f9f825a207533acdee305c7e73
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-09-04 14:44:12 +02:00
Thomas Wolf 6d27869659 Use Config.getEnum() to read the IgnoreSubmoduleMode
Doing so goes through the TypedConfigGetter and thus allows library
clients (for instance EGit) to warn about invalid configurations.

Change-Id: If1080ad90b8aff54a903d4d75637614faad6469b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-09-04 09:19:03 +02:00
Thomas Wolf 06ea633c18 Don't assume name = path in .gitmodules
While parsing .gitmodules, the name of the submodule subsection is
purely arbitrary: it frequently is the path of the submodule, but
there's no requirement for it to be. By building a map of paths to
the section name in .gitmodules, we can more accurately return
the submodule URL.

Bug: 508801
Change-Id: I8399ccada1834d4cc5d023344b97dcf8d5869b16
Also-by: Doug Kelly <dougk.ff7@gmail.com>
Signed-off-by: Doug Kelly <dougk.ff7@gmail.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-09-04 09:19:03 +02:00
David Pursehouse 53deba1b4f FsckPackParser: Fix warning about int being boxed to Integer
Change-Id: I525164090e3990ce353bbb1627aaafaad2c903b6
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-09-01 00:14:32 +09:00
David Pursehouse de5eb5e2cd FsckPackParser: Fix "Empty block should be documented" warnings
Add "Do nothing" comments, consistent with other empty methods in
the same class.

Change-Id: I27a13a402e94104af617be0e14d8982e75fa73bd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-08-31 21:40:10 +09:00
David Pursehouse 9c1fcf6ad7 FsckPackParser: Fix warnings about variable hiding
Change-Id: Id1ada1cedfad5671e79df303c6dbcb6017b777ce
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-08-31 21:40:10 +09:00
David Pursehouse f8c2067410 Silence API errors caused by adding enum constants in 1baf86d4d2
Change-Id: I23338c04567f95aedd909ab310e01277e8f7db69
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-08-31 21:40:10 +09:00
Shawn Pearce f4329b09d4 Merge changes from topic 'dfs-reftable'
* changes:
  dfs: helper to open multiple reftables
  dfs: expose DfsReftable from DfsObjDatabase
  dfs: support reading reftables through DfsBlockCache
2017-08-30 20:42:23 -04:00
Shawn Pearce 0ca1fb0fe0 Merge changes from topic 'fsck'
* changes:
  DfsFsck: reduce memory usage during verifyIndex
  DfsFsck: refactor pack verify into its own method
  DfsFsck: run connectivity check pass exactly once
2017-08-30 08:42:37 -04:00
Shawn Pearce e5db7c1f0e DfsFsck: reduce memory usage during verifyIndex
Don't convert a lot of ObjectId to String stored in generic
java.util.HashSet.  This is a very expensive way to store objects.

Instead rely on "this" from the FsckPackParser to lookup information
about the objects in this pack file, which lets the verify code avoid
sorting the object list.

Use ObjectIdOwnerMap, which is the most efficient format JGit has
for storing lots of objects.

Change-Id: Ib68f93acb4d91b96d0a44c0612f704500d332ac1
2017-08-30 03:11:53 -07:00
Shawn Pearce 69588c21fe DfsFsck: refactor pack verify into its own method
This simplifies the logic about allocation of the DfsReader, and
clarifies the code considerably by using smaller scopes with less
indentation.

A few static imports from PackExt and slightly shorter variable names
make for a more understandable-at-glance implementation.

Change-Id: Iaf5a0e14fe0349215d9e44446f68d1129ad3bb3d
2017-08-30 03:11:43 -07:00
Shawn Pearce 153c11a49b DfsFsck: run connectivity check pass exactly once
The simpler algorithm is to load all branch tips into an ObjectWalk
and run that walk exactly once.  This avoids redoing work related to
parsing and considering trees reused across side branches.

Move the connectivity check into its own helper method.  This moves it
left one level of identation, and makes it easier to fit the method's
logic with less line wrapping.

Add a "Counting objects..." progress monitor around this phase.  Its
what is used when a server receives a push and is also trying to
verify the client sent all required objects.

Change-Id: I4d53d75d0cdd1a13fff7d513a6ae0b2d14ea4090
2017-08-29 18:14:51 -07:00
Matthias Sohn f4c5a54aa9 Cleanup: Remove redundant type arguments
Change-Id: I81ce2e25666f5acfce4d3ada6b71ae8c81a97a4d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-30 03:07:34 +02:00
Matthias Sohn e9fb111182 Cleanup: Organize imports
Change-Id: I6065e59519bc42bd18f5cc5ee3ec5210764ab03c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-30 03:07:33 +02:00
Matthias Sohn 41baa7a791 Partially revert c0ad77d8 "Enhance Eclipse save actions"
Do not automatically organize imports using a save action since this
seems to be buggy and removed some annotations org.eclipse.jgit.pgm
needs to use args4j.

Change-Id: I5a91292c3b9241ce2dde3e4ecce14ad460097129
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-30 03:07:18 +02:00
Matthias Sohn 1052678372 Cleanup: Remove trailing whitespace
Change-Id: I7c08b60fb6afafd1874210320da3da7519632e08
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-30 01:24:48 +02:00
Matthias Sohn 9906f09868 Partially revert c0ad77d8 "Enhance Eclipse save actions"
Revert the following save actions which were introduced in c0ad77d8:
- always use braces around blocks
- remove unused imports

Other than I expected save actions are run globally on edited files -
and not only on edited code lines only.

Hence revert the save action "Convert control statement bodies to
blocks" which would affect a large number of code lines not affected by
the change editing some small part of a class. This would generate a
large number of changes which may lead to many unnecessary conflicts.
Total number of affected lines across jgit would be around 10k lines.

Also revert "Remove unused imports" since it erroneously removes imports
of some annotations needed by pgm classes using args4j.

Change-Id: I879a47f68e664129e6124cf25c1ae1f6a2d7a5aa
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-30 01:24:47 +02:00
Thomas Wolf dbef8e2537 Pass along the original exception when an ssh connection fails
Otherwise, the stack trace doesn't really tell anything.
See for instance [1].

[1] https://www.eclipse.org/forums/index.php/t/1088535/

Change-Id: If22f2c63c36fec6b32818d2c2acecf20531b4185
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-29 15:08:08 -04:00
Shawn Pearce 4f7ce2b46b dfs: helper to open multiple reftables
ReftableStack maintains multiple open reftables
in an AutoCloseable format, making it easier for
higher level code to handle multiple files.

Change-Id: I7ac35c18e67b7e771fb3de29169d1ee50fab62ca
2017-08-28 15:07:05 -07:00
Shawn Pearce 1a7b8a11df dfs: expose DfsReftable from DfsObjDatabase
Reftable storage in DFS is related to pack storage.  Reftables are
stored in the same namespace, but with PackExt.REFTABLE.  Include
the set of DfsReftable instances in the PackList and export some
helpers to access the tables.

Change-Id: I6a4f5f953ed6b0ff80a7780f4c6cbcc5eda0da3e
2017-08-28 15:07:04 -07:00
Shawn Pearce 1222f34506 dfs: support reading reftables through DfsBlockCache
DfsBlockCache directly shares its internal byte[] with ReftableReader,
avoding copying between the DfsBlockCache and the BlockReader
instances used by ReftableReader.

Change-Id: Icaa4f40052b26f952681414653a8b5314b7c2c23
2017-08-28 15:07:04 -07:00
Shawn Pearce d684ade3d3 Merge "reftable: explicitly store update_index per ref" 2017-08-28 17:57:13 -04:00
David Pursehouse 10a8df22fa Merge "Enhance Eclipse save actions" 2017-08-28 12:08:01 -04:00
Terry Parker cb24de07d0 Merge "Add BlobObjectChecker" 2017-08-28 12:00:53 -04:00
Matthias Sohn c0ad77d84c Enhance Eclipse save actions
Add the following Eclipse save actions executed when saving modified
lines. This should help to reduce manual work needed to maintain a clean
and consistent code style:
- organize imports
- always use braces around blocks
- add missing annotations
  - @Override including implementation of interface methods
  - @Deprecated
- remove
  - unused imports
  - unnecessary $NON-NLS$ tags
  - redundant type arguments

Also add default values for new settings that were introduced in recent
Eclipse versions up to Neon since we updated save rules the last time.

Change-Id: Idc90b249df044d0552f04edf01a5f607c4846f50
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-28 11:52:45 -04:00
Masaya Suzuki fd74cf2f78 Add BlobObjectChecker
Some repositories can have a policy that do not accept certain blobs. To
check if the incoming pack file contains such blobs, ObjectChecker can
be used. However, this ObjectChecker is not called by PackParser if the
blob is stored as a whole. This is because the object can be so large
that it doesn't fit in memory.

This change introduces BlobObjectChecker. This interface takes chunks of
a blob instead of the entire object. ObjectChecker can optionally return
a BlobObjectChecker. This won't change existing ObjectChecker
implementation; existing implementation continues to receive deltified
blob objects only.

Change-Id: Ic33a92c2de42bd7a89786a4da26b7a648b25218d
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
2017-08-28 08:42:27 -07:00
Thomas Wolf 1637c44048 FetchCommand: pass on CredentialsProvider to submodule fetches
When a JGit API command is implemented in terms of other API
commands, the child command must "inherit" all relevant settings.
Calling configure() ensures that the CredentialsProvider and the
connection timeout are propagated correctly.

Bug: 515325
Change-Id: I948e306693a9edb7b199a735877413b6eddcfba4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-27 16:37:43 +02:00
Thomas Wolf d031b64667 Exclude file matching: fix backtracking on match failures after **
** matching always tries the empty match first. If a mismatch occurs
later, the ** must be extended by exactly one segment and matching must
resume with the matcher following the ** matcher.

Bug: 520920
Change-Id: Id019ad1c773bd645ae92e398021952f8e961f45c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-27 16:02:41 +02:00
Thomas Wolf d80b999c76 Fix path pattern matching to work also for gitattributes
Path pattern matching for attribute rules is different than matching
for excluded files.

The first difference concerns patterns without slashes. For
gitattributes those must match on the last component only, not on
any earlier segment. This is true also for directory-only patterns.

The second difference concerns directory-only patterns. Those also
must not match on a prefix or segment except the last one. They do
not apply recursively to all files beneath.

And third, matches only on a prefix must match for gitattributes
only if the last matcher was "/**".

Add a new parameter for such path matching to IMatcher.matches() and
pass it through as appropriate (false for gitignore, true for
gitattributes). As far as gitignore is concerned, there is no change.

New tests have been added, and some existing attribute matching tests
have been fixed since they operated on wrong assumptions.

Bug: 508568
Change-Id: Ie825dc2cac8a85a72a7eeb0abb888f3193d21dd2
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-27 16:02:40 +02:00
Thomas Wolf 426caf99ee Ignore invalid TagOpt values
C git silently ignores invalid tagopt values; so make JGit behave the
same way.

Bug: 429625
Change-Id: I99587cc46c7e0c19348bcc63f602038fa9a7f378
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-26 09:11:03 +02:00
Thomas Wolf 8cbdf523cd Add a getter for a list of RefSpecs to Config
Reading RefSpecs from a Config can be seen as another typed value
conversion, so add a getter to Config and to TypedConfigGetter. Use
it in RemoteConfig.

Doing this allows clients of the JGit library to customize the
handling of invalid RefSpecs in git config files by installing a
custom TypedConfigGetter.

Bug: 517314
Change-Id: I0ebc0f073fabc85c2a693b43f5ba5962d8a795ff
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-26 09:11:02 +02:00
Thomas Wolf d32ad1cadd Improve getting typed values from a Config
Make the handling of typed values somewhat configurable by using
a separate converter. The default converter is the same as before;
just the implementations of the getters were moved. They also still
raise IllegalArgumentException on invalid values as before.

The converter can be set globally via Config.setTypedConfigGetter(),
which EGit can use in its core Activator to plug in a variant that
catches the IllegalArgumentException, logs the problem, and then
returns the default value.

In this way the behavior for other users of the JGit library is
unchanged, while EGit can deal gracefully with invalid git configs.

Bug: 520978
Change-Id: Ie8f81d206e358b6cc57aa29b9d7ad2a5d34b86a1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-26 09:11:02 +02:00
Matthias Sohn 960d7ff3e5 Prepare 4.5.4-SNAPSHOT builds
Change-Id: Id8b902bf2bf590b41f2e246c5ecf1592e1c411f2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-26 08:08:46 +02:00
David Pursehouse e237c28936 Merge "Fix JGit set core.fileMode to false by default instead of true for non Windows OS." 2017-08-25 20:58:07 -04:00
David Pursehouse 40f40e496a Merge "Fix default directory set when setDirectory wasn't called." 2017-08-25 20:57:52 -04:00
David Pursehouse 0e12692d8c FileMode: Remove unnecessary @SuppressWarnings("synthetic-access")
In Eclipse Oxygen, the following warning is emitted:

  At least one of the problems in category 'synthetic-access' is not
  analysed due to a compiler option being ignored

Removing the suppression gets rid of the warning.

Change-Id: Ibfe5cc1e347150b699f54e2f204ab5ee770da202
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-08-25 20:57:11 -04:00
Matthias Sohn d979dfd00c Add toString() methods to OpenSshConfig to help debugging
Change-Id: I81b60a13a97e78d5ccd593ba8e4aa614df19f925
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-26 01:44:37 +02:00
Thomas Wolf c758a8cd37 Do most %-token substitutions in OpenSshConfig
Except for %p and %r and partially %C, we can do token substitutions
as defined by OpenSSH inside the config file parser. %p and %r can
be replaced only if specified in the config; if not, it would be the
caller's responsibility to replace them with values obtained from the
URI to connect to.

Jsch doesn't know about token substitutions at all. By doing the
replacements as good as we can in the config file parser, we can
make Jsch support most of these tokens.

%i is not handled at all as Java has no concept of a "user ID".

Includes unit tests.

Bug: 496170
Change-Id: If9d324090707de5d50c740b0d4455aefa8db46ee
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-08-26 01:44:36 +02:00
Thomas Wolf 9d2447063d Let Jsch know about ~/.ssh/config
Ensure the Jsch instance used knows about ~/.ssh/config. This
enables Jsch to honor more user configurations (see
com.jcraft.jsch.Session.applyConfig()), in particular also the
UserKnownHostsFile configuration, or additional identities given
via multiple IdentityFile entries.

Turn JGit's OpenSshConfig into a full parser that can be a
Jsch-compliant ConfigRepository. This avoids a few bugs
in Jsch's OpenSSHConfig and keeps the JGit-facing interface
unchanged. At the same time we can supply a JGit OpenSshConfig
instance as a ConfigRepository to Jsch. And since they'll both
work from the same object, we can also be sure that the parsing
behavior is identical.

The parser does not handle the "Match" and "Include" keys, and it
doesn't do %-token substitutions (yet).

Note that Jsch doesn't handle multi-valued UserKnownHostFile
entries as known by modern OpenSSH.[1]

[1] http://man.openbsd.org/OpenBSD-current/man5/ssh_config.5

Additional tests for new features are provided in OpenSshConfigTest.

Bug: 490939
Change-Id: Ic683bd412fa8c5632142aebba4a07fad4c64c637
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-08-26 01:41:50 +02:00