Commit Graph

4656 Commits

Author SHA1 Message Date
Matthias Sohn e6e9073fc7 Fix IOException when LockToken#close fails
This happened if the LockTokens hard link was already deleted earlier.

Bug: 531759
Change-Id: Idc84bd695fac1a763b3cbb797c9c4c636a16e329
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-15 09:11:17 +02:00
Cliffred van Velzen 0c8200b27b Fix logging null if called process fails
If some process executed by FS#readPipe ends in an error,
the error stream is never set as errorMessage because
FS#GobblerThread#waitForProcessCompletion always returned true.
This caused LOG#warn to be called with null.

Return false whenever FS#GobblerThread#waitForProcessCompletion fails.

Bug: 538723
Change-Id: Ic9492bd688431d52c8665f7a2efec2989e95a4ce
Signed-off-by: Cliffred van Velzen <cliffred@cliffred.nl>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-12 23:42:35 +02:00
David Pursehouse fc480b3efc Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Fix NoSuchFileException during directory cleanup in RefDirectory
  Externalize warning message in RefDirectory.delete()
  Suppress warning for trying to delete non-empty directory

Change-Id: Ic7eaa0b6a4e750bc7853eb549a9e126269ae22cf
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-12 19:03:32 +09:00
David Pursehouse 83c0369e29 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Fix NoSuchFileException during directory cleanup in RefDirectory
  Externalize warning message in RefDirectory.delete()
  Suppress warning for trying to delete non-empty directory

Change-Id: I191d56e3c0f11cf53076b06c7e7a05492c7a03f1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-12 17:02:23 +09:00
David Pursehouse 59ee33aee4 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Fix NoSuchFileException during directory cleanup in RefDirectory
  Externalize warning message in RefDirectory.delete()
  Suppress warning for trying to delete non-empty directory

Change-Id: Ied2d7a70c5544ff012687a1aeb6e07394d9bd6fd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-12 16:38:56 +09:00
David Pursehouse b81092cc99 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Fix NoSuchFileException during directory cleanup in RefDirectory
  Externalize warning message in RefDirectory.delete()
  Suppress warning for trying to delete non-empty directory

Change-Id: I5e6cc35f3673545e7ff857e6ed0bcd2c44e50316
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-12 15:55:07 +09:00
David Pursehouse db756e9147 Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  Fix NoSuchFileException during directory cleanup in RefDirectory
  Externalize warning message in RefDirectory.delete()
  Suppress warning for trying to delete non-empty directory

Change-Id: I9ec6352b5ff57aa1a3380079dc9165890cc76d49
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-12 14:05:54 +09:00
Matthias Sohn 667ac8b318 Fix NoSuchFileException during directory cleanup in RefDirectory
Bug: 538285
Change-Id: Iab5c381a412cb2c2176af55189668c267ed29fbc
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
(cherry picked from commit 8ab89ef066)
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-12 09:12:11 +09:00
Matthias Sohn a44d95c814 Prepare 5.1.1-SNAPSHOT builds
Change-Id: Ie220dd95fae18f894e2a04a5ae6d29a1e5a6d76b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-11 23:28:07 +02:00
Matthias Sohn 47956bcc68 JGit v5.1.0.201809111528-r
Change-Id: I583bf7d60bccc876156be1f605bfda32b89cd08b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-11 21:30:23 +02:00
Matthias Sohn c78d6445ec Externalize warning message in RefDirectory.delete()
Change-Id: Icec16c01853a3f5ea016d454b3d48624498efcce
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
(cherry picked from commit 5e68fe245f)
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-11 08:29:02 +09:00
Thomas Wolf 94fad4412a Suppress warning for trying to delete non-empty directory
This is actually a fairly common occurrence; deleting the parent
directories can work only if the file deleted was the last one
in the directory.

Bug: 537872
Change-Id: I86d1d45e1e2631332025ff24af8dfd46c9725711
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
(cherry picked from commit d9e767b431)
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-11 08:26:52 +09:00
Markus Duft 303adeb8bf Fix replacement quoting for replaceAll in filter command
According to String.replaceAll JavaDoc:

"Note that backslashes (\) and dollar signs ($) in the replacement
string may cause the results to be different than if it were being
treated as a literal replacement string; see Matcher.replaceAll. Use
java.util.regex.Matcher.quoteReplacement to suppress the special meaning
of these characters, if desired."

Bug: 536318
Change-Id: Ib70cfec41bf73e14d23d94d14aee05a25b1e87f6
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
2018-09-10 22:21:15 +02:00
Matthias Sohn c857e7f09b Merge branch 'stable-5.0' into stable-5.1
* stable-5.0:
  Prepare 4.11.3-SNAPSHOT builds
  JGit v4.11.2.201809100523-r

Change-Id: I6bd3cb830b7b44dc6e5fd66ff0732957be6b5710
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-10 21:30:49 +02:00
Matthias Sohn 8527e74ea0 Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Prepare 4.11.3-SNAPSHOT builds
  JGit v4.11.2.201809100523-r

Change-Id: I8a6f2667f9e43d53e995554224c2a538d1959996
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-10 21:29:46 +02:00
Matthias Sohn 34618a4f86 Prepare 4.11.3-SNAPSHOT builds
Change-Id: I4f5dda6da3f6ecd9b99c1d9a220844c5402f1988
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-10 13:13:19 +02:00
Matthias Sohn ae21714768 JGit v4.11.2.201809100523-r
Change-Id: I85dab173a94b3036ccf669c20b9dffb4af0922b4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-10 11:24:32 +02:00
Matthias Sohn b44bba618b Merge branch 'stable-5.0' into stable-5.1
* stable-5.0:
  Prepare 5.0.4-SNAPSHOT builds
  JGit v5.0.3.201809091024-r
  Prepare 4.9.5-SNAPSHOT builds
  JGit v4.9.4.201809090327-r
  Fix @since tag for LOCK_SUFFIX
  Prepare 4.7.4-SNAPSHOT builds
  JGit v4.7.3.201809090215-r

Change-Id: I9117b961035ee527cb8e1dd5df59976fff83829d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 21:05:41 +02:00
Matthias Sohn 0b11e31a4c Prepare 5.0.4-SNAPSHOT builds
Change-Id: Ib9042662c3f2a1544d597d476c5952c61767687b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 17:28:59 +02:00
Matthias Sohn faf1ae230e JGit v5.0.3.201809091024-r
Change-Id: I9e8e74a10dbb235b08c6a5e1b169c5cae440f129
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 16:24:44 +02:00
Matthias Sohn a9e5ee3f06 Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Prepare 4.9.5-SNAPSHOT builds
  JGit v4.9.4.201809090327-r
  Fix @since tag for LOCK_SUFFIX
  Prepare 4.7.4-SNAPSHOT builds
  JGit v4.7.3.201809090215-r

Change-Id: Ia72fc409f0262565cf31b8bc62737c78fc4c3485
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 15:53:35 +02:00
Matthias Sohn 0d4e04c575 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Prepare 4.9.5-SNAPSHOT builds
  JGit v4.9.4.201809090327-r
  Fix @since tag for LOCK_SUFFIX
  Prepare 4.7.4-SNAPSHOT builds
  JGit v4.7.3.201809090215-r

Change-Id: I8e962758973753fe7baffd959050593a059ee44e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 15:44:44 +02:00
Matthias Sohn 8f46488385 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Prepare 4.9.5-SNAPSHOT builds
  JGit v4.9.4.201809090327-r
  Fix @since tag for LOCK_SUFFIX
  Prepare 4.7.4-SNAPSHOT builds
  JGit v4.7.3.201809090215-r

Change-Id: I78099d2a5ba895273ca3ac587c7aa5f3f43fe869
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 15:43:04 +02:00
Matthias Sohn a253c39729 Use the same default diff.renameLimit = 400 like native git
Bug: 434085
Change-Id: I43a0401049cd85b2c7a2162ccc071af7fffdfed3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 13:03:36 +02:00
Matthias Sohn de0a687948 Prepare 4.9.5-SNAPSHOT builds
Change-Id: Ie8d2b60be1803399027e1a3e9734625278a63861
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 09:36:35 +02:00
Matthias Sohn 6657f93adb JGit v4.9.4.201809090327-r
Change-Id: I13488a915fe0ba871c5f37c6e9efc6f436083171
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 09:29:05 +02:00
Matthias Sohn f8de0596d7 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Fix @since tag for LOCK_SUFFIX
  Prepare 4.7.4-SNAPSHOT builds
  JGit v4.7.3.201809090215-r

Change-Id: Id3c85149316cbe671e55f41438bd3a3a892b4ed0
2018-09-09 09:25:54 +02:00
Matthias Sohn b0a0c1004f Fix @since tag for LOCK_SUFFIX
Change-Id: Ia65cf3f12ec6d35a21b4d9332be912f06d8bf834
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 08:46:11 +02:00
Matthias Sohn 6fe4505b2a Prepare 4.7.4-SNAPSHOT builds
Change-Id: Ie4d17e1604270946606e75145012c5b7fa1283eb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 08:24:16 +02:00
Matthias Sohn 9796e86165 JGit v4.7.3.201809090215-r
Change-Id: I1ded7a2b61235509c5a6ba95e7329e288bbfddb1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-09 08:15:48 +02:00
Matthias Sohn 582d623964 Merge branch 'stable-5.0' into stable-5.1
* stable-5.0:
  Fix atomic lock file creation on NFS
  Use constant for ".lock"
  Fix handling of option core.supportsAtomicCreateNewFile
  GC: Avoid logging errors when deleting non-empty folders

Change-Id: I3c8892e33516bdcadd983e7ab668635b7fa3d4c5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-08 22:13:00 +02:00
Matthias Sohn 155dd1c5be Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Fix atomic lock file creation on NFS
  Use constant for ".lock"
  Fix handling of option core.supportsAtomicCreateNewFile
  GC: Avoid logging errors when deleting non-empty folders

Change-Id: Ifcc8bfab4fd05c18a08dd82588860dffd0e6d726
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-08 11:09:27 +02:00
Matthias Sohn 5a583ef393 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Fix atomic lock file creation on NFS
  Use constant for ".lock"
  Fix handling of option core.supportsAtomicCreateNewFile
  GC: Avoid logging errors when deleting non-empty folders

Change-Id: Ie86079d9ad76972306bc80e63d8bfe18ae06a0da
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-08 10:12:48 +02:00
Matthias Sohn 9e26cb106f Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Fix atomic lock file creation on NFS
  Use constant for ".lock"
  Fix handling of option core.supportsAtomicCreateNewFile
  GC: Avoid logging errors when deleting non-empty folders

Change-Id: I32dc651870b7ba7c88de448c7984134b7c99e7e3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-08 10:03:22 +02:00
Matthias Sohn 4ce79bf738 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Fix atomic lock file creation on NFS
  Use constant for ".lock"
  Fix handling of option core.supportsAtomicCreateNewFile
  GC: Avoid logging errors when deleting non-empty folders

Change-Id: Id7f68f4e8fb07a21737e3b7090f600507a13bbbe
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-08 09:15:01 +02:00
Matthias Sohn 8699a95d2d Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  Fix atomic lock file creation on NFS
  Use constant for ".lock"
  Fix handling of option core.supportsAtomicCreateNewFile
  GC: Avoid logging errors when deleting non-empty folders

Change-Id: Ia7a18f69eee173aec9e462c16eee2b0ca4565e76
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-08 08:58:12 +02:00
Matthias Sohn 06e06fc291 Fix atomic lock file creation on NFS
FS_POSIX.createNewFile(File) failed to properly implement atomic file
creation on NFS using the algorithm [1]:
- name of the hard link must be unique to prevent that two processes
  using different NFS clients try to create the same link. This would
  render nlink useless to detect if there was a race.
- the hard link must be retained for the lifetime of the file since we
  don't know when the state of the involved NFS clients will be
  synchronized. This depends on NFS configuration options.

To fix these issues we need to change the signature of createNewFile
which would break API. Hence deprecate the old method
FS.createNewFile(File) and add a new method createNewFileAtomic(File).

The new method returns a LockToken which needs to be retained by the
caller (LockFile) until all involved NFS clients synchronized their
state. Since we don't know when the NFS caches are synchronized we need
to retain the token until the corresponding file is no longer needed.
The LockToken must be closed after the LockFile using it has been
committed or unlocked. On Posix, if core.supportsAtomicCreateNewFile =
false this will delete the hard link which guarded the atomic creation
of the file. When acquiring the lock fails ensure that the hard link is
removed.

[1] https://www.time-travellers.org/shane/papers/NFS_considered_harmful.html
also see file creation flag O_EXCL in
http://man7.org/linux/man-pages/man2/open.2.html

Change-Id: I84fcb16143a5f877e9b08c6ee0ff8fa4ea68a90d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-07 12:13:53 +02:00
Matthias Sohn 6bec391d36 Use constant for ".lock"
(cherry picked from commit 5f27032fb8)

Change-Id: I6bc0e9a910b110418a82d8e574fb2aecc3a31d6a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-07 12:13:53 +02:00
Christian Halstrick 2faccd5b32 Fix handling of option core.supportsAtomicCreateNewFile
When core.supportsAtomicCreateNewFile was set to false and the
repository was located on a filesystem which doesn't support the file
attribute "unix:nlink" then FS_POSIX#createNewFile may report an error
even if everything was ok. Modify FS_POSIX#createNewFile to silently
ignore this situation. An example of such a filesystem is sshfs where
reading "unix:nlink" always returns 1 (instead of throwing a exception).

Bug: 537969
Change-Id: I6deda7672fa7945efa8706ea1cd652272604ff19
Also-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-09-07 00:33:14 +02:00
Matthias Sohn 4c8a4eb8fd Prepare 5.1.0-SNAPSHOT builds
Change-Id: I3d06c5237edae54b09f465f415f5a308b5e7ceff
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-05 20:41:53 +02:00
Matthias Sohn e4281f1d5f JGit v5.1.0.201809051400-rc1
Change-Id: I0b53f95ee51d94da8b029c9bb10eb854ff9dd4f6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-05 19:55:38 +02:00
Hector Caballero b7351facd5 GC: Avoid logging errors when deleting non-empty folders
I88304d34c and Ia555bce00 modified the way errors are handled when
trying to delete non-empty reference folders. Before, this error was
silently ignored as it was considered an expected output. Now, every
failed folder delete is logged which can be noisy.

Ignore the DirectoryNotEmptyException but log any other error avoiding
deletion of an eligible folder.

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I194512f67885231d62c03976ae683e5cc450ec7c
2018-09-05 06:59:51 -04:00
David Turner 559c68cb01 Parse signature of GPG-signed commits
In order to support GPG-signed commits, add some methods which will
allow GPG signatures to be parsed out of RevCommit objects.

Later, we can add code to verify the signatures.

Change-Id: Ifcf6b3ac79115c15d3ec4b4eaed07315534d09ac
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-09-04 20:13:16 +02:00
David Pursehouse 30c6c75421 Deprecate Constants.CHARSET in favor of StandardCharsets.UTF_8
Change-Id: I3b748620f067582afef20f144feebe40d0332be2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-09-04 10:53:10 +09:00
Jonathan Nieder ce38391e09 Merge "Replace useminimalnegotation flag with maxhaves flag" 2018-08-31 20:02:51 -04:00
Minh Thai c398fb2b6b Replace useminimalnegotation flag with maxhaves flag
Client will stop sending haves when the number of haves sent reaches maxhaves.

Change-Id: I1e5b1525be4c67f20a81ca24a2770c20eb5c1271
Signed-off-by: Minh Thai <mthai@google.com>
2018-08-31 16:43:46 -07:00
Ivan Frade a8c38bc767 Extract protocol v2 fetch request parsing to its own class
The parsing code for protocol v2 fetch doesn't have any dependency on
the rest of UploadPack.

Move it to its own class. This makes testing easier (no need to
instantiate the full UploadPack), simplifies the code in UploadPack and
increases modularity.

At the moment, the parser needs to know about the reference database to
validate incoming references. This dependency could be easily removed
moving the validation later in the flow, after the parsing, where other
validations are already happening. Postponing that to keep this patch
about moving unmodified code around.

Change-Id: I7ad29a6b99caa7c12c06f5a7f30ab6a5f6e44dc7
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-08-31 15:31:36 -07:00
Jonathan Nieder 346bc34169 FetchV2Request: Rename shallowSince to deepenSince
This fetch parameter is called deepen-since in the protocol.  Call it
the same thing in the request object to make the code easier to reason
about.

This doesn't touch UploadPack#shallowSince, which is likely to be
eliminated altogether in a later patch anyway.

Change-Id: I8ef34bc7ad12fae3a9057ae951367cc024e1a1cb
Suggested-by: Ivan Frade <ifrade@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-08-31 13:07:45 -07:00
Jonathan Nieder 4e8feb96a3 FetchV2Request: Correct typo in parameter name
There is an extra 'd' in deependNotRefs.  Noticed during code review.

Change-Id: I93d8d7951fe5c351b62e23bdf5bad0ebd631017d
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-08-31 13:03:29 -07:00
Ivan Frade 04d27cf70f FetchV2Request round up (doneReceived, renamings)
Make "doneReceived" a member of the fetch request. It indicates if the
"done" line has been received (so it makes sense there) and makes all
the code after the parsing depend only on the request.

Rename "shallowExcludeRefs" to "deepenNot". Those refs come in
"deepen-not" lines in the protocol, and this name makes clearer the
intention.

Change-Id: I7bec65de04930277266491d278de7c3af7d8cbe6
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-08-31 09:16:11 -07:00
Ivan Frade 74d41be0d1 Use right variable in error message about depth
When this exception is thrown, the `depth` member variable isn't set
yet, resulting in a confusing error message: "Invalid depth: 0".

Change-Id: I8a2bd5e1d9bec00acb0b8857bbf6821e95bf1369
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-08-30 14:37:06 -07:00
Ivan Frade e665e3fcd4 UploadPack: avoid conflating shallow commit lists in protocol v2
At the moment there are two copies of the client shallow commit list:
one in the request and another in the clientShallowCommits member of
the class.

The verifyShallowCommit function was removing missing object ids
from the member but not the request list, and code afterwards was
using the request's version.

In practice, this didn't cause trouble because these shallow commits
are used as endpoint for a walk, and missing ids are just never reached.

Change-Id: I70a8f1fd46de135da09f16e5d954693c8438ffcb
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-08-30 13:09:50 -07:00
David Pursehouse 4c77f62ccf Merge branch 'stable-5.0'
* stable-5.0:
  Fix NoSuchFileException in GC.deleteTempPacksIdx()
  Fix NoSuchFileException during directory cleanup in RefDirectory

Change-Id: I35bd4bcbeac2430f674ccb6b947ac3776cec8a82
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-08-27 21:12:59 +02:00
Matthias Sohn 5e68fe245f Externalize warning message in RefDirectory.delete()
Change-Id: Icec16c01853a3f5ea016d454b3d48624498efcce
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-27 10:52:20 +02:00
Matthias Sohn ddf56d6f85 Fix NoSuchFileException in GC.deleteTempPacksIdx()
This exception is thrown in GC.deleteTempPacksIdx() if the repository
has no packs.

Bug: 538286
Change-Id: Ieb482be751226baf0843068a0f847e0cdc6e0cb6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-27 09:12:14 +02:00
Matthias Sohn 8ab89ef066 Fix NoSuchFileException during directory cleanup in RefDirectory
Bug: 538285
Change-Id: Iab5c381a412cb2c2176af55189668c267ed29fbc
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-27 09:12:02 +02:00
Matthias Sohn 851f239951 Merge branch 'stable-5.0'
* stable-5.0:
  Silence API warning for new ObjectIdSerializer introduced in 4.11.1
  Ignore API warnings
  Fix photon target platform to use photon version of org.eclipse.osgi
  Update Photon orbit repository to R20180606145124
  Suppress warning for trying to delete non-empty directory
  Fix fetching with duplicate ref updates
  Fetch(Process): should tolerate duplicate refspecs
  FetchCommandTest: test add/update/delete fetch

Change-Id: I9e7fa37b100a7ea3cbe4104802d36c6f38df9e08
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-25 16:14:22 +02:00
Matthias Sohn cde0e31381 Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Silence API warning for new ObjectIdSerializer introduced in 4.11.1
  Ignore API warnings
  Fix photon target platform to use photon version of org.eclipse.osgi
  Update Photon orbit repository to R20180606145124
  Suppress warning for trying to delete non-empty directory
  Fix fetching with duplicate ref updates
  Fetch(Process): should tolerate duplicate refspecs
  FetchCommandTest: test add/update/delete fetch

Change-Id: I2497f99b7d0686a0e0f773c39c8725e813ce9d4a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-25 08:56:45 +02:00
Matthias Sohn 2dfc9ed6d2 Silence API warning for new ObjectIdSerializer introduced in 4.11.1
Change-Id: Ic271dae300f7554b7e13bb1f44006e5b38c00011
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-25 08:02:31 +02:00
Matthias Sohn 6670ff1663 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Ignore API warnings
  Fix photon target platform to use photon version of org.eclipse.osgi
  Update Photon orbit repository to R20180606145124
  Suppress warning for trying to delete non-empty directory
  Fix fetching with duplicate ref updates
  Fetch(Process): should tolerate duplicate refspecs
  FetchCommandTest: test add/update/delete fetch

Change-Id: I47671108574fcd10fe016a58e38c038af54a6748
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-25 07:55:55 +02:00
Ivan Frade 40e9c38405 Add fetch support to ProtocolV2Hook
This makes it symmetrical with ls-refs operation and gives the
instantiator of UploadPack the chance to run some code after parsing
the protocol and before any actual work for the fetch starts.

Request and Builder methods keep the naming in the original code to
make this change just about request encapsulation and hook invocation.
They are package-private for now to allow further improvements.

Change-Id: I5ad585c914d3a5f23b11c8251803faa224beffb4
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-08-24 13:58:52 -07:00
Matthias Sohn db6c2c2aa5 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Ignore API warnings
  Fix photon target platform to use photon version of org.eclipse.osgi
  Update Photon orbit repository to R20180606145124
  Suppress warning for trying to delete non-empty directory
  Fix fetching with duplicate ref updates
  Fetch(Process): should tolerate duplicate refspecs
  FetchCommandTest: test add/update/delete fetch

Change-Id: I2a83c059b7014c2a9e6267c963422c7785b23f17
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-24 17:39:07 +02:00
Matthias Sohn b0332d0133 Ignore API warnings
The following commits introduced in stable-4.5 and stable-4.9
introduced some minor API additions in service releases.

f7ceeaa2 FileRepository: Add pack-based inserter implementation
085d1f95 Make PackInserter public
10e65cb4 Fix LockFile semantics when running on NFS

Change-Id: I4afed7e0395cf93d828e671080e3ec9ddf20987d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-24 17:23:00 +02:00
Ivan Frade 0b84c5b29e UploadPack: shallowExcludeRefs doesn't need to be nullable
Code can check size instead of null, and that makes the initialization
trivial.

Change-Id: Icbe655816429a7a680926b0e871d96f3b2f1f7ba
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-08-23 15:22:06 -07:00
David Pursehouse e1b971848a RefDirectory: Add missing $NON-NLS suppression
Change-Id: I6afb4f86c3a8a06e5ea3128bf1b9b20c46ca158c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-08-23 16:51:19 +09:00
Michael Keppler 2fc00af44e refactor: simplify collection.toArray()
On recent VMs, collection.toArray(new T[0]) is faster than
collection.toArray(new T[collection.size()]). Since it is also more
readable, it should now be the preferred way of collection to array
conversion.

https://shipilev.net/blog/2016/arrays-wisdom-ancients/

Change-Id: I80388532fb4b2b0663ee1fe8baa94f5df55c8442
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
2018-08-23 01:34:39 -04:00
David Pursehouse 7058493fea UploadPack: Add missing $NON-NLS suppressions
Change-Id: Ica2cc0ed23a7667bcb8d2006fd0a6ba6bddfee9a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-08-23 11:35:06 +09:00
David Pursehouse 985e6342b3 UploadPack: Remove redundant specification of type
Change-Id: I257635ed3f9ce012e03a3c45ed666fb9195019e0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-08-23 11:33:17 +09:00
Thomas Wolf d9e767b431 Suppress warning for trying to delete non-empty directory
This is actually a fairly common occurrence; deleting the parent
directories can work only if the file deleted was the last one
in the directory.

Bug: 537872
Change-Id: I86d1d45e1e2631332025ff24af8dfd46c9725711
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-22 18:36:31 +02:00
Thomas Wolf ffd1ac5dde Fix fetching with duplicate ref updates
If packed refs are used, duplicate updates result in an exception
because JGit tries to lock the same lock file twice. With non-atomic
ref updates, this used to work, since the same ref would simply be
locked and updated twice in succession.

Let's be more lenient in this case and remove duplicates before
trying to do the ref updates. Silently skip duplicate updates
for the same ref, if they both would update the ref to the same
object ID. (If they don't, behavior is undefined anyway, and we
still throw an exception.)

Add a test that results in a duplicate ref update for a tag.

Bug: 529400
Change-Id: Ide97f20b219646ac24c22e28de0c194a29cb62a5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-22 11:09:01 +02:00
Marc Strapetz 65a0cfc82a Fetch(Process): should tolerate duplicate refspecs
Bug: 529314
Change-Id: I91eaeda8a988d4786908fba6de00478cfc47a2a2
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-22 11:09:00 +02:00
Masaya Suzuki 36346bd81c Add SuppressWarnings for FutureReturnValueIgnored
https://errorprone.info/bugpattern/FutureReturnValueIgnored

The submitted task logs the error in case it fails.

Change-Id: I280442ddb8046da47aeb79d005886f65d2e3067b
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
2018-08-21 10:28:37 -07:00
Jonathan Nieder af75250a45 Merge "Support remove-project node in the manifest parser" 2018-08-20 22:14:35 -04:00
Masaya Suzuki 58a90f7a70 Support remove-project node in the manifest parser
This directive removes the projects added by other directives.

https://gerrit.googlesource.com/git-repo/+/65b0ba5aa0447f7ee25103828115662b1eb80ff9/manifest_xml.py#614
https://gerrit.googlesource.com/git-repo/+/e469a0c741832f6584513f4a382d6b93f417b8d2/docs/manifest-format.txt#339

Change-Id: I90d7b9fc711b586dec05f475422d34d67d909986
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
2018-08-20 18:27:32 -07:00
Matthias Sohn 0c12df54f1 Remove unnecessary maven dependency of org.eclipse.jgit to httpclient
Change-Id: Icc3c696a46adaf0e7b633913a3f36f0440a81e3a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-20 04:54:51 -04:00
Andrey Loskutov 5a95e7e74b SubmoduleDeinitTest fails on Windows
Bug: 538068
Change-Id: I982e8b12936582e8e119f45d7a3bf4888d3e0e1a
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2018-08-19 20:53:31 +02:00
Matthias Sohn 60c7791918 Merge branch 'stable-5.0'
* stable-5.0:
  Fix GC run in foreground to not use executor

Change-Id: I484391e5589d70de136126d153f886f5afa12e88
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-18 13:57:42 +02:00
Matthias Sohn 78d7d9916c Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Fix GC run in foreground to not use executor

Change-Id: I9bb1506805a2d5e79a420a1152bc45321c081229
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-18 13:55:24 +02:00
Matthias Sohn c415e93e8a Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Fix GC run in foreground to not use executor

Change-Id: I565b95de6c89f021475667caaacdbb08caddd881
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-18 13:51:45 +02:00
Matthias Sohn 9b55f1a278 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Fix GC run in foreground to not use executor

Change-Id: Ib4d76125fca7eec9e88666688b5e614e7e20dde7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-18 13:51:00 +02:00
Matthias Sohn ce84d0dfc6 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Fix GC run in foreground to not use executor

Change-Id: Id9d864a8e727fefa35ca87eccb4e3801eb689c3c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-18 13:47:51 +02:00
Matthias Sohn 96beadbbc1 Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  Fix GC run in foreground to not use executor

Change-Id: Ib150d132e2ce055d36ddffb2dbc37b5cb355e77a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-18 13:40:33 +02:00
Matthias Sohn 7a536cef06 Merge branch 'stable-5.0'
* stable-5.0:
  Fix wrong warning message in case of lock failures

Change-Id: Ia9b813652a2f5b6c78e9587367c35c3a6c177a7a
2018-08-17 01:24:10 +02:00
Christian Halstrick 982be5db14 Fix wrong warning message in case of lock failures
Bug: 537969
Change-Id: I0854bbbe7393abaca36640d429886c30d95d5bf1
2018-08-16 14:30:46 -05:00
Masaya Suzuki 3aa2b8064c Introduce ProtocolV2Hook
In Git protocol v2, UploadPack and ReceivePack have the same
capabilities and can process any protocol v2 request. For example, a
client can sent a "fetch" command to the "/git-receive-pack" endpoint.

This makes it difficult for existing hook interfaces. For example,
PreUploadHook takes UploadPack, but a "fetch" command may be received by
ReceivePack.

To resolve this skew, this change introduce a different hook interface
for the protocol v2. The hook takes a request that is independent to the
handlers (UploadPack, ReceivePack). Also this makes it clear what
parameters the hook is counting on, instead of keep track of the hook
using getters from UploadPack / ReceivePack.

Bug: 534847
Change-Id: I71f3266584483db1e2b2edfc1a72d0bdf1bb6041
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
2018-08-16 11:22:17 -07:00
Hugo Arès d4a19c328f Fix GC run in foreground to not use executor
Since I3870cadb4, GC task was always delegated to an executor even when
background option was set to false. This was an issue because if more
than one GC object was instantiated and executed in parallel, only one GC
was actually running because of the single thread executor.

Change-Id: I8c587d22d63c1601b7d75914692644a385cd86d6
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
2018-08-15 19:53:33 -05:00
Dave Borowitz 62562295c0 Add EMPTY_TREE_ID as a sibling of EMPTY_BLOB_ID
Change-Id: Id68b3e1db7294cf9adb8b4ce8eecb1d828687eef
2018-08-15 15:59:55 -07:00
Dave Borowitz 289f116dbb Update javadoc for EMPTY_BLOB_ID
Found original version with:

  $ git describe --contains $(git blame fc4d4b5340 org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java | grep EMPTY_BLOB_ID | cut -d' ' -f1)
  v0.9.1~164

Change-Id: I1f86bde42615c8b64064894bde44f82660b38d0f
2018-08-15 15:59:23 -07:00
Jonathan Nieder fc4d4b5340 Merge "Declare ConfigConstants and GitProtocolConstants final" 2018-08-14 18:55:26 -04:00
Matthias Sohn 31a72f5da7 Declare ConfigConstants and GitProtocolConstants final
This avoids that we have to suppress API errors whenever we add a new
constant in a minor release. This change affects implementors only which
is ok to do in a minor release following OSGi semantic versioning rules.

Change-Id: Iece841886fbe00f1ba567c5ff68093c542ba265e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-15 00:32:41 +02:00
Jonathan Tan 3227348e5e Respond with shallow-info before wanted-refs
When fetching with protocol v2, git expects the shallow-info section to
appear before wanted-refs if both appear in the response. Teach
UploadPack to do this.

Change-Id: Ie26a91edcce5d27a1d727d7fba5c30e1144e118b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-08-13 16:57:25 -07:00
Han-Wen Nienhuys d1dc49e968 Use a TreeMap to construct the list of renamed projects
This eliminates one source of unpredictable ordering of entries in .gitmodules.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: I834ae57bd18f51966ef76c039f5212ebf60a33e8
2018-08-13 12:17:58 -04:00
Gunnar Wagenknecht 82e0c4a084 Merge "Fix ResolveMerger: rebase with autocrlf=true, direct checkout" 2018-08-13 07:36:44 -04:00
Thomas Wolf 4027c5c9ff Fix ResolveMerger: rebase with autocrlf=true, direct checkout
ResolveMerger.checkout() and cleanUp() check out files directly and
must honor CR/LF settings and also smudge filters.

Deprecate the 3-argument version of DirCacheCheckout.checkoutEntry().
It isn't used anymore anywhere in JGit (nor in EGit).

Bug: 537410
Change-Id: I062b35401c8bd5bc99deb2f68f91089a0643504c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-13 13:15:24 +02:00
Jonathan Tan c477b0ddcb Support protocol v2 want-ref in UploadPack
UploadPack already allows the client to send wanted OIDs as "want"
lines. Extend UploadPack to also allow the client to send wanted ref
names as "want-ref" lines when the fetch is done using protocol v2.

The corresponding Git commit is 516e2b76bd ("upload-pack: implement
ref-in-want", 2018-06-28).

To support a two-stage rollout, two configuration variables are
provided: uploadpack.allowrefinwant (default "false") allows clients to
specify "want-ref" in their requests, and uploadpack.advertiserefinwant
(default "true") makes UploadPack advertise this capability. If
uploadpack.allowrefinwant is true but uploadpack.advertiserefinwant is
false, UploadPack will not advertise that it supports "want-ref", but it
will support it.

Change-Id: I3c24077949640d453af90d81a7f48ce4b8ac9833
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-08-10 18:44:49 -04:00
Thomas Wolf bd1a825026 Merge remote-tracking branch 'origin/stable-5.0'
* stable-5.0:
  Ensure that JSch knows HostKeyAlgorithms ssh-rsa and ssh-dss

Change-Id: I76899a1f6b3d9348d138266e05e1320b7429bfd1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-09 12:06:49 +02:00
Thomas Wolf 09753591fa Ensure that JSch knows HostKeyAlgorithms ssh-rsa and ssh-dss
Without these registrations, JSch's up-front checks which algorithms
are available at all fail if the ssh config explicitly sets only these
algorithms.

Bug: 537790
Change-Id: Idb0431190a7f101913363ee95af6c8fcbda6c923
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-08 13:36:35 +02:00
Matthias Sohn cf6463bddc Fix API breakage introduced by da254106
Use org.eclipse.jgit.errors.CancelledException which is a subclass of
IOException instead of org.eclipse.jgit.api.errors.CanceledException in
order to avoid breaking API. We can reconsider this with the next major
version 6.0.

Bug: 536324
Change-Id: Ia6f84f59aa6b7d78b8fccaba24ade320a54f7458
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-08-08 11:44:55 +02:00
Matthias Sohn da254106a7 Abort rename detection in a timely manner if cancelled
If progress monitor is cancelled break loops in rename detection by
throwing a CanceledException.

Bug: 536324
Change-Id: Ia3511fb749d2a5d45005e72c156b874ab7a0da26
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-07 00:09:43 +02:00
Jonathan Nieder 26c5d0e56a RebaseCommand: Remove unnecessary fall through comments
It's easier to read a list of cases

	case A:
	case B:
	case C:
		... do something ...;
		break;

without intervening "// fall through" lines separating the cases.

This also makes it clearer that JGit uses "$FALL-THROUGH$", not "fall
through", to suppress fallthrough warnings in switch statements.
Eclipse does not pay attention to the second comment style.

Change-Id: I5279a727aee2868854d06bfcaac8cb8186b4299e
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-08-04 14:04:29 -07:00
Matthias Sohn 2f7bf6b536 Prepare 5.0.3-SNAPSHOT builds
Change-Id: Iae9d763a65481b09af6e19b33e41375f27038357
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-01 01:30:05 +02:00
Matthias Sohn 40813388e7 JGit v5.0.2.201807311906-r
Change-Id: Iccb98c03a069fee85a52325e1ed22cba8b76bcd8
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-08-01 01:06:30 +02:00
Matthias Sohn a8c7c42ff1 Prepare 4.11.2-SNAPSHOT builds
Change-Id: I02630900ab131478b30abe68b2133d2c8a5a67ab
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-31 22:07:17 +02:00
Matthias Sohn e51d2fcda8 JGit v4.11.1.201807311124-r
Change-Id: Ic58a916d7e2c380b84690afa5e3517c6c178af8c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-31 17:31:30 +02:00
Matthias Sohn 6a813c64ff Prepare 4.9.4-SNAPSHOT builds
Change-Id: Ibb2ee9d00d5d049f681e1abbb449656105e553a7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-31 16:57:13 +02:00
Matthias Sohn 56b435a61c JGit v4.9.3.201807311005-r
Change-Id: I3f4f437649736c6a27e78d536344c7b31c8a0f65
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-31 16:05:49 +02:00
Jonathan Nieder 8ef7cd4df4 Merge "Use project names instead of paths for the submodule name" 2018-07-27 18:15:14 -04:00
Masaya Suzuki 6658f36768 Use project names instead of paths for the submodule name
Two submodules at the same path on different branches need not represent
the same repository, and two submodules at different paths can represent
the same one.

The C Git implementation uses the submodule name to internally manage
the submodule repositories under .git/modules. When a submodule
represents different repositories in different branches, it makes a
conflict inside .git/modules.

The current RepoCommand implementation uses submodule paths as the
submodule names. When the manifest file mounts different repositories to
the same path in different branches, this makes a situation described
above. To solve this issue, we can use the project name instead of
the path as the submodule name.

On the other hand, since repo v1.12.8~3^2 (repo: Support multiple
branches for the same project., 2013-10-11), a manifest file can mount
the same project to different paths. If we naively use the project
name as the submodule name, it makes a conflict in .git/modules, too.

This patch uses the project name as the submodule name basically, but
when the same project is mounted to different paths, it uses the project
name and path as the submodule name.

Change-Id: I09dc7d62ba59016fe28852d3139a56ef7ef49b8f
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Reported-by: JP Sugarbroad <jpsugar@google.com>
2018-07-27 15:07:30 -07:00
Matthias Sohn 435975e7a9 Merge branch 'stable-5.0'
* stable-5.0:
  Prepare 4.7.3-SNAPSHOT builds
  JGit v4.7.2.201807261330-r
  Delete all loose refs empty directories
  Use java.nio to delete path to get detailed errors
  GC: Remove empty references folders
  Do not ignore path deletion errors

Change-Id: I9717444c42ea89195dfcde8bb10121b9bb178e87
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-27 14:16:49 +02:00
Matthias Sohn 0db128acd5 Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  Prepare 4.7.3-SNAPSHOT builds
  JGit v4.7.2.201807261330-r
  Delete all loose refs empty directories
  Use java.nio to delete path to get detailed errors
  GC: Remove empty references folders
  Do not ignore path deletion errors

Change-Id: I780d4a1624fbb97a2acdf5321b9c3244b0626444
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-27 14:06:22 +02:00
Matthias Sohn fd4a62fdf0 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Prepare 4.7.3-SNAPSHOT builds
  JGit v4.7.2.201807261330-r
  Delete all loose refs empty directories
  Use java.nio to delete path to get detailed errors
  GC: Remove empty references folders
  Do not ignore path deletion errors

Change-Id: I2b44d862869d4453c57db668fc7c925da591f671
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-27 13:38:21 +02:00
Matthias Sohn 8b97c266c3 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Prepare 4.7.3-SNAPSHOT builds
  JGit v4.7.2.201807261330-r
  Delete all loose refs empty directories
  Use java.nio to delete path to get detailed errors
  GC: Remove empty references folders
  Do not ignore path deletion errors

Change-Id: Ie7029bc91621af32e7bfd2e0d76a424b991b1995
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-27 11:03:24 +02:00
Matthias Sohn a0b818ce01 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Prepare 4.7.3-SNAPSHOT builds
  JGit v4.7.2.201807261330-r
  Delete all loose refs empty directories
  Use java.nio to delete path to get detailed errors
  GC: Remove empty references folders
  Do not ignore path deletion errors

Change-Id: I6ab2b951dd94a9fc1c4f5283847a3e2ec37d0895
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-27 10:52:13 +02:00
David Pursehouse e90a013e45 Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  Prepare 4.7.3-SNAPSHOT builds
  JGit v4.7.2.201807261330-r
  Delete all loose refs empty directories
  Use java.nio to delete path to get detailed errors
  GC: Remove empty references folders
  Do not ignore path deletion errors

Change-Id: Iadc8275fbaa3d6f7d08a96ab66d49f392f6aab78
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-27 08:22:51 +01:00
Matthias Sohn 29118ed117 Prepare 4.7.3-SNAPSHOT builds
Change-Id: I5c437f45d5bc469e3c32bef1180c127d96d24d23
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-27 01:00:35 +02:00
Matthias Sohn 01787756aa JGit v4.7.2.201807261330-r
Change-Id: I0d8c7ca756e6236e315c91da000fe8103ce83d05
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-26 19:28:38 +02:00
Luca Milanesio 977726e5bb Delete all loose refs empty directories
Remove completely the empty directories under refs/<namespace>
including the first level partition of the changes, when they are
completely empty.

Bug: 536777
Change-Id: I88304d34cc42435919c2d1480258684d993dfdca
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-26 01:13:56 +02:00
Luca Milanesio eea9a7a0ba Use java.nio to delete path to get detailed errors
Get the full IOException of the reason why a directory
cannot be removed during GC.

Change-Id: Ia555bce009fa48087a73d677f1ce3b9c0b685b57
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-26 01:02:42 +02:00
Jonathan Nieder 0c75097830 Merge "Send only 1 flush pkt at the end of v2 fetch" 2018-07-24 18:56:42 -04:00
Jonathan Tan 7e7b00f1a5 Send only 1 flush pkt at the end of v2 fetch
When processing a fetch using protocol v2, UploadPack#fetchV2 sends an
extraneous flush pkt when also sending a packfile (#sendPack sending its
own flush pkt). Update that method to only send the flush pkt if the
packfile is not being sent.

Change-Id: I7117a264bccd2d7f3a048645fcb8425a9d78d526
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-07-24 15:39:32 -07:00
Matthias Sohn e0e52cb011 Fix NPE in BlameGenerator.getSourceStart()
Bug: 499543
Change-Id: I99f6ebb1c3ceea20e8ca093acbe824c9f0362d45
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-07-24 00:41:34 +02:00
Jonathan Tan 32798dcfdb Always send refs' objects despite "filter" in pack
In a0c9016abd ("upload-pack: send refs' objects despite "filter"",
2018-07-09), Git updated the "filter" option in the fetch-pack
upload-pack protocol to not filter objects explicitly specified in
"want" lines, even if they match the criterion of the filter. Update
JGit to match that behavior.

Change-Id: Ia4d74326edb89e61062e397e05483298c50f9232
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-07-20 17:09:05 -07:00
Jonathan Nieder fb9031c956 RepoCommand: record remote branch, group, shallow bit by default
Propagating more information from the manifest to the superproject
tends to work out well.  These particular settings mean:

Recording the remote branch in .gitmodules allows
- "git submodule update --remote" to fetch the right branch
- Gerrit's submodule subscription feature to subscribe from the
  right branch, if requested

Recording groups in .gitattributes allows commands like "git clone
--recurse-submodules=:(attr:platform-linux) $superproject" to clone
the correct set of projects.

Recording the shallow bit in .gitmodules means that "git clone
--recurse-submodules" will use shallow clone in submodules where that
was requested in the manifest.

Gerrit's supermanifest plugin records the remote branch and shallow
bit by default already, and most users of that plugin configure it to
record groups in .gitattributes as well, so for most users this will
be a no-op.

Change-Id: Id2ed47cbca5ce822bde517494673c86ab8c58da9
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-07-20 00:48:22 -07:00
Thomas Wolf a9b54b026d ResolveMerger: don't try needlessly to delete directories
Don't try to delete folders if the merger chooses THEIRS, but all of
BASE, OURS, and THEIRS contain the folder.

Add a test for rebase with auto-stash and subdirectories that
verifies this case. The needless directory deletion and reporting
such directories in getModifiedFiles() was the root cause of bug
536880.

Note even with this fix, bug 536880 will not be fixed in all cases
yet. There may still be cases where the set of modified files ends
up containing directories. This will be dealt with in EGit where
this set is used. (See https://git.eclipse.org/r/#/c/126242/ .)

Bug: 536880
Change-Id: I62b4571a1c1d4415934a6cb4270e0c8036deb2e9
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-07-19 12:38:28 +02:00
Terry Parker e4774f45c4 GC: Trim more EWAHCompressedBitmaps to free unused memory
04b9f4436 fixed places where compressed bitmaps were holding on to their
full buffers, but missed this StoredBitmap.getBitmap() case where a
bitmap is resonstituted from an xor chain.

Change-Id: I7cf75d9e49c18a1a8a880a4df7e821502edc68a4
Signed-off-by: Terry Parker <tparker@google.com>
2018-07-16 14:44:43 -07:00
Masaya Suzuki 579bff6653 Add API to specify the submodule name
Currently SubmoduleAddCommand always uses the path as submodule name.
This patch lets the caller specify a submodule name.

SubmoduleUpdateCommand still does not make use of the submodule name
(see bug 535027) but Git does.  To avoid triggering CVE-2018-11235,
do some validation on the name to avoid '..' path components.

[jn: fleshed out commit message, mostly to work around flaky CI]

Change-Id: I6879c043c6d7973556e2080387f23c246e3d76a5
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-07-12 12:27:28 -07:00
Minh Thai 263a8c1c06 Make Reftable seek* and has* method names more consistent
Make the method names more consistent and their semantics simpler:
hasRef and seekRef to look up a single exact reference by name and
hasRefsByPrefix and seekRefsByPrefix to look up multiple references by
name prefix.

In particular, splitting hasRef into two separate methods for its
different uses makes DfsReftableDatabase.isNameConflicting easier to
follow.

[jn: fleshed out commit message]

Change-Id: I71106068ff3ec4f7e14dd9eb6ee6b5fab8d14d0b
Signed-off-by: Minh Thai <mthai@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-07-11 14:08:35 -07:00
Minh Thai e04d96e3fa Seek references by prefix in reftable
Reftable implementation of RefDatabase.getRefsByPrefix() should be
more performant, as references are filtered directly by prefix;
instead of fetching the whole subtree then filter by prefix.

Change-Id: If4f5f8c08285ea1eaec9efb83c3d864cea7a1321
Signed-off-by: Minh Thai <mthai@google.com>
2018-07-10 19:40:29 -04:00
Terry Parker 04b9f44367 GC: Trim EWAHCompressedBitmaps to free unused memory
The "Building bitmaps" GC phase fails for large repositories (repos with
10M objects use 1.25MB per uncompressed bitmap, and those with long
histories may build >25k bitmaps). Since these bitmaps xor well against
each other, the actual space needed for each compressed bitmap is
usually no more than a few KB. Calling trim() will ensure we aren't
holding on to excess memory.

Change-Id: I40bf78c730b9f6051da6025f9777ce27220a5b0a
Signed-off-by: Terry Parker <tparker@google.com>
2018-07-10 14:10:11 -04:00
Terry Parker dd7d479bd4 Merge "Add progress monitor step to first phase of GC commit selection" 2018-07-10 11:23:38 -04:00
Dave Borowitz 3447e2a776 Make DfsConfig public
This may be convenient for downstream implementers who require a dummy
StoredConfig implementation, rather than making them reimplement the two
abstract StoredConfig methods.

Change-Id: I2b7bc6250d722c2b95d9f99e4eff1e5bf97cb567
2018-07-10 20:28:39 +09:00
Hector Caballero 4eea4ea508 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
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-10 20:24:59 +09:00
Terry Parker 7fe15d4428 Add progress monitor step to first phase of GC commit selection
Change-Id: I10e3d53de5e2b1fc1be9a59b236da5780473d841
Signed-off-by: Terry Parker <tparker@google.com>
2018-07-09 17:51:39 -07:00
Luca Milanesio 5a8ad44208 Do not ignore path deletion errors
Log as warning when an attempt to remove a directory
fails. This helps troubleshooting some bugs like the GC leaving
behind empty directories.

Change-Id: Idb94ce17f8be9668a970c7ecae31436bf434073c
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
2018-07-08 23:44:17 +01:00
David Pursehouse 67f7ca5bb6 Merge branch 'stable-5.0'
* stable-5.0:
  ResolveMerger: Fix encoding with string; use bytes

Change-Id: I8e6d0c92144db3bf57ea05f93852ac015458260b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-04 14:16:51 +09:00
David Pursehouse 6ba60a3127 Merge branch 'stable-4.11' into stable-5.0
* stable-4.11:
  ResolveMerger: Fix encoding with string; use bytes

Change-Id: I40b7b4b3fd6d53bbad32f8f550e885c0e698faf1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-04 14:13:27 +09:00
David Pursehouse 55b1335084 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  ResolveMerger: Fix encoding with string; use bytes

Change-Id: I2f02298d0ff7caafeca4020cde4fdfa29a46e585
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-04 14:11:11 +09:00
David Pursehouse a96d640365 Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  ResolveMerger: Fix encoding with string; use bytes

Change-Id: Ibd8f2a041b0de6e008a1ea84b92823f8cbc6e3d2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-04 14:10:29 +09:00
David Pursehouse b6a6ba10c7 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  ResolveMerger: Fix encoding with string; use bytes

Change-Id: Id6a85804695d5dcb32f26ed1d861b7c93577c5e4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-04 14:09:53 +09:00
David Pursehouse c296342333 Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  ResolveMerger: Fix encoding with string; use bytes

Change-Id: If17328fbd101d596a8a16d9c4a190e9b6e120902
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-07-04 14:09:01 +09:00
Thomas Wolf 55ebb83c98 Add response message, if any, on HTTP status 404
Try to give as much information as possible. The connection's
response message might contain additional hints as to why the
connection could not be established.

Bug: 536541
Change-Id: I7230e4e0be9417be8cedeb8aaab35186fcbf00a5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-07-03 13:54:32 +02:00
Terry Parker 115a740e2f Correctly handle initialization of shallow commits
In a new RevWalk, if the first object parsed is one of the
shallow commits, the following happens:
1) RevCommit.parseCanonical() is called on a new "r1" RevCommit.
2) RevCommit.parseCanonical() immediately calls
   RevWalk.initializeShallowCommits().
3) RevWalk.initializeShallowCommits() calls lookupCommit(id),
   creating and adding a new "r2" version of this same object and
   marking its parents empty.
4) RevCommit.parseCanonical() initializes the "r1" RevCommit's
   fields, including the parents.
5) RevCommit.parseCanonical()'s caller uses the "r1" commit that
   has parents, losing the fact that it is a shallow commit.

This change passes the current RevCommit as an argument to
RevWalk.initializeShallowCommits() so that method can set its
parents empty rather than creating the duplicate "r2" commit.

Change-Id: I67b79aa2927dd71ac7b0d8f8917f423dcaf08c8a
Signed-off-by: Terry Parker <tparker@google.com>
2018-06-26 20:13:47 -07:00
Terry Parker e8e4fe7af6 Merge changes Ib6019b10,I82c71b52
* changes:
  Fix a GC scalability issue when selecting commit bitmaps
  Test uniform bitmap commit selection across multiple branches
2018-06-26 12:29:11 -04:00
tparker 2070d146cb Fix a GC scalability issue when selecting commit bitmaps
The previous algorithm selected commits by creating bitmaps at
each branch tip, doing a revwalk to populate each bitmap, and
looping in this way:
1) Select the remaining branch with the most commits (the branch
   whose bitmap has the highest cardinality)
2) Select well-spaced bitmaps in that branch
3) Remove commits in the selected branch from the remaining
   branch-tip bitmaps
4) Repeat at #1

This algorithm gave good commit selection on all branches but
a more uniform selection on "important" branches, where branch
length is the proxy for "important". However the algorithm
required N bitmaps of size M solely for the purpose of commit
selection, where N is the number of branch tips in the primary
GC pack, and M is the number of objects in the pack.

This new algorithm uses branch modification date as the proxy for
"important" branches, replacing the N*M memory allocation with a
single M-sized bitmap and N revwalks from new branch tips to
shared history (which will be short when there is a lot of shared
history).

GcCommitSelectionTest.testDistributionOnMultipleBranches verifies
that this algorithm still yields good coverage on all branches.

Change-Id: Ib6019b102b67eabb379e6b85623e4b5549590e6e
Signed-off-by: Terry Parker <tparker@google.com>
2018-06-26 09:23:46 -07:00
Thomas Wolf f508a00176 CleanCommand: don't fire WorkingTreeModifiedEvent on dry run
Since no files are actually deleted it makes no sense to fire such an
event.

Change-Id: I66e87afc1791f27fddaa873bafe8bb8b61662535
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-06-26 08:26:38 +02:00
Matthias Sohn ff15df05c3 Prepare 5.0.2-SNAPSHOT builds
Change-Id: I65e83f39a4082278c4cb809dbb08d44a119cebe0
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-22 01:42:14 +02:00
Matthias Sohn a7e38fb0b0 JGit v5.0.1.201806211838-r
Change-Id: I594cd85d46698953c27da3687e4ec40aeb73b445
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-22 00:40:01 +02:00
Marco Miller 1dcb0688c7 ResolveMerger: Fix encoding with string; use bytes
This change fixes the issue [1]. Before this fix, a merge involving
the caching of consecutive yet similar filenames with Norwegian
characters [2] used to throw an IllegalStateException: Duplicate
stages not allowed. This was caused by inaccurate decoding of the
filenames, using string values assuming default encoding. In the
toString method of DirCacheEntry, used before through getPathString,
UTF-8 encoding is used, but the end result becomes default encoding,
through Object's default toString usage. The special characters in
those two consecutive (particular) filenames [2] were becoming the
very same decoded /single character, lending consecutive -but then
identical- filenames. Thus the perceived duplicate 0-staging of the
file(s).

Replace getPathString usage with getRawPath for this specific case,
or use byte array representations of cached entries instead of string.

Adding a test for this change is not possible, as there is no known
way to change the default encoding for filenames such as [2] (e.g.).
JGitTestUtil does write file contents through UTF-8, but encoding like
so does not apply to the actual file name. Hence there is no way to
create files with names properly made of special characters such as
[2]'s. And the test that is necessary for this case assumes such
Norwegian (or similar characters) filenames. Changing the default
locale programmatically in a test has no effect either. And changing
the LANG value passed to the JVM is only possible upon starting it.

[1] https://bugs.chromium.org/p/gerrit/issues/detail?id=9153

[2] <=>
(...)
"a/b/SíÒr-Norge.map",
"a/b/Sør-Norge.map",
(...)

Change-Id: Ib9f2f5297932337c9817064cc09d9f774dd168f4
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
2018-06-21 15:38:56 -04:00
Jonathan Nieder 82ae431e45 Merge branch 'stable-5.0'
* stable-5.0:
  Respect "unshallow" lines in protocol v2
  Temporarily @Ignore flaky CommitCommandTest methods

Change-Id: I14bd522d2f6bafb1b41e3c730d6dbef827e3e88a
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-20 21:24:05 -07:00
Jonathan Nieder 7df024b276 Respect "unshallow" lines in protocol v2
If I run

 git config --global protocol.version 2
 mkdir repo
 cd repo
 git init --bare
 git remote add origin https://go.googlesource.com/proposal
 git fetch --depth=1
 git fetch --unshallow

then I expect to have a full history, just as though I had fetched
without --depth in the first place.  Instead, it reports success
but does not fetch enough objects:

 $ git fsck
 notice: HEAD points to an unborn branch (master)
 Checking object directories: 100% (256/256), done.
 Checking objects: 100% (468/468), done.
 broken link from  commit 2c6bc83f234085c8eadb7ea33405ce6223c44d1b
               to  commit 878975cf2b600675b4c905e5d9591bd24541ae9e
 missing commit 878975cf2b600675b4c905e5d9591bd24541ae9e
 dangling commit 314be00dae78dd526851f5635e6349014e2ad0c2

The false success indicates problems in the client and the server.
Git 2.18-rc2 (the client) ought to have been more defensive, noticing
the incomplete history.  The greater error is in JGit (the server),
which neglects to send the objects requested.

When serving protocol v0 requests, JGit sends the correct objects by
taking unshallowCommits into account when generating the pack to send
to the client.  Do the same in the protocol v2 code path.  I forgot to
do this in v5.0.0.201806050710-rc3~6 (Teach UploadPack shallow fetch
in protocol v2, 2018-03-15).

Reported-by: Russ Cox <rsc@golang.org>
Change-Id: I282b45f47616a641b9e8d6210b4a070d3efdbb9b
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-20 21:20:41 -07:00
Thomas Wolf 2e76daec14 Avoid expensive getAllRefsByPeeledObjectId() in PlotWalk constructor
Instead, do it when we return the first PlotCommit from next().
On a repository with many refs, getAllRefsByPeeledObjectId() can
take a while. Doing a late initialization simplifies the handling
of a PlotWalk.

EGit, for instance, creates and configures an instance, and then
does the real walk in a background job. With late initialization,
the potentially expensive getAllRefsByPeeledObjectId() also occurs
in that background job.

Bug: 485743
Change-Id: I84c020cf8f7afda6f181778786612b8e6ddd7ed8
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-06-15 16:11:10 +02:00
Matthias Sohn 331f1a8e49 Merge branch 'stable-5.0'
* stable-5.0:
  Prepare 5.0.1-SNAPSHOT builds
  JGit v5.0.0.201806131550-r
  JGit v5.0.0.201806131210-r
  Downgrade Apache httpclient to 4.5.2.v20170210-0925
  RefUpdateTest: Refactor to not use deprecated Repository#getAllRefs
  Propagate failure of ssh command to caller of SshSupport
  Make JGit describe behaves same as c-git for lightweight tags
  Fix issues with LFS on GitHub (SSH)

Change-Id: I0471440919adfdbfc72996711d9e0bbd1f3cf477
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-14 00:00:30 +02:00
Matthias Sohn 0dbaf9d951 Prepare 5.0.1-SNAPSHOT builds
Change-Id: Iadf12dbdd63ef17c3f712c0fc18495304aa35016
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-13 23:24:42 +02:00
Matthias Sohn e729a83bd2 JGit v5.0.0.201806131550-r
Change-Id: Ia2d548676217250593c3f0c383aec19e12e5e4a4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-13 21:42:40 +02:00
Matthias Sohn 94a585e6e8 JGit v5.0.0.201806131210-r
Change-Id: Iedccfcaf57c11822f1faf5d5195357de42b2a14e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-13 18:11:23 +02:00
Matthias Sohn f7fbc7fcd7 Propagate failure of ssh command to caller of SshSupport
When SshSupport.runSshCommand fails since the executed external ssh
command failed throw a CommandFailedException.

If discovery of LFS server fails due to failure of the
git-lfs-authenticate command chain the CommandFailureException to the
LfsConfigInvalidException in order to allow root cause analysis in the
application using that.

Change-Id: I2f9ea2be11274549f6d845937164c248b3d840b2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-13 11:24:24 +02:00
Marcel Trautwein 5429d1a0cf Make JGit describe behaves same as c-git for lightweight tags
JGit now considers lightweight tags only if the --tags option is set
i.e. `git.describe().setAllTags(true)` has to be set, else the default
is now as in c git:

Only annotated tags are evaluated unless you pass true
equivalent to --tags (or --all) by the option setAllTags.

Hint: This (still) doesn't address any difference between c-git
`--all` and `!--all --tags` behavior;
perhaps this might be a follow up request

Bug: 423206
Change-Id: I9a3699756df0b9c6a7c74a7e8887dea0df17c8e7
Signed-off-by: Marcel Trautwein <me+eclipse@childno.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-13 09:37:47 +02:00
Markus Duft 01c52a58f6 Fix issues with LFS on GitHub (SSH)
* URIish seems to have a tiny feature (bug?). The path of the URI
   starts with a '/' only if the URI has a port set (it seems).
 * GitHub does not return SSH authorization on a single line as Gerrit
   does - need to account for that.
 * Increase the SSH git-lfs-authenticate timeout, as GitHub sometimes
   responds slower than expected.
 * Guard against NPE in case the download action does not contain any
   additional headers.

Change-Id: Icd1ead3d015479fd4b8bbd42ed42129b0abfb95c
Signed-off-by: Markus Duft <markus.duft@ssi-schaefer.com>
2018-06-12 09:49:15 +02:00
Matthias Sohn e512d919ec Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Ensure DirectoryStream is closed promptly

Change-Id: I62674a1db9266c04fb353ab697e2c0a24a7369b7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-11 10:54:59 +02:00
David Pursehouse 0bcf88bc0d Merge branch 'stable-5.0'
* stable-5.0:
  Fix Javadoc typo

Change-Id: Ib864f5871f8e99d2a776b7ae9f782ec3eb312d50
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-06-11 08:09:09 +09:00
Michael Keppler e710f14ed1 Fix Javadoc typo
Change-Id: Ib4ebc57236bdea663f27295764886413e2550580
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-06-10 23:19:20 +09:00
Matthias Sohn 0f8f6746ed Merge branch 'stable-5.0'
* stable-5.0:
  Ensure Jsch checks all configured algorithms
  RawTextTest#testBinary: use array comparison to compare arrays
  LFS: Better SSH authentication token timeout handling
  Ensure DirectoryStream is closed promptly
  Validate branch names on branch creation

Change-Id: Ic4f6a24b6ccee6730eee3fd5dcb0d1f3e291c478
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-10 12:12:16 +02:00
Thomas Wolf 4ef8769f81 Ensure Jsch checks all configured algorithms
Jsch checks only for the availability of the algorithms given by
Jsch-internal config keys "CheckCiphers", "CheckKexes", and
"CheckSignatures". If the ssh config defines any algorithms
unknown to Jsch not listed in those keys, it'll still propose them
during the negotiation phase, and run into an NPE later on if the
server happens to propose such an algorithm and it gets chosen.

Jsch reads those "CheckCiphers" and the other values from either a
session-local config, or the global static Jsch config. It bypasses
~/.ssh/config for these values.

Therefore, copy these values from the config as read from
~/.ssh/config into the session-specific config. That makes Jsch
check _all_ configured algorithms up front, discarding any for
which it has no implementation. Thus it proposes only algorithms
it actually can handle.

Bug: 535672
Change-Id: I6a68e54f4d9a3267e895c536bcf3c58099826ad5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-06-10 12:06:59 +02:00
Dave Borowitz 5fe8e31d43 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
(cherry picked from commit 1c16ea4601)
2018-06-09 17:34:29 +09:00
Matthias Sohn 62460b42b7 Validate branch names on branch creation
Since v2.16.0-rc0~89^2~1 (branch: correctly reject
refs/heads/{-dash,HEAD}, 2017-11-14),
native git does not allow branch names
- refs/heads/HEAD
- starting with '-'

Bug: 535655
Change-Id: Ib1c4ec9ea844073901a4ebe6a29ff6cc8ae58e93
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-09 01:20:13 +02:00
Jonathan Nieder d2cb1e7bf5 Merge branch 'stable-5.0'
* stable-5.0:
  Use constant for ".lock"
  Simplify locking of FileRepository's index snapshot
  Refactor FileRepository.detectIndexChange()

Change-Id: Ifd427711359bcf38b2c877b2143d45bff0c9895a
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-08 14:56:06 -07:00
Matthias Sohn 5f27032fb8 Use constant for ".lock"
Change-Id: Id65dc94c970ffd3ca3d3d4a5d57123c95d29e8af
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-08 21:43:39 +02:00
Matthias Sohn 1cb8c5d7fe Simplify locking of FileRepository's index snapshot
synchronize on simple Object monitor instead of using ReentrantLock

Change-Id: I897020ab35786336b51b0fef76ea6071aff8aefa
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-08 09:54:38 +02:00
Matthias Sohn b782518cae Refactor FileRepository.detectIndexChange()
Change-Id: I50c751e2e90f685dc27043c569da2eb210d4611b
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-08 09:42:13 +02:00
Jonathan Nieder c86c1d5549 Merge branch 'stable-5.0'
* stable-5.0:
  Update to latest Photon Orbit R20180606145124
  Ensure index change event is fired when index snapshot changed

Change-Id: I8724fc92999d2bc0f8bde5e401156738dd9f1ee6
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-07 22:36:00 -07:00
Matthias Sohn a3738ef137 Ensure index change event is fired when index snapshot changed
Ensure that notifyIndexChanged is called every time we call
FileSnapshot.save, except the first.

Change-Id: I5a4e9826e791f518787366ae7c3a0ef3d416d2c1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-06 00:45:27 +02:00
Matthias Sohn cb0abf787e Prepare 5.0.0-SNAPSHOT builds
Change-Id: I9acca328146aa7100fbc1b457fcb1f8fd87cf52a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-05 15:31:07 +02:00
Matthias Sohn ca57743a45 JGit v5.0.0.201806050710-rc3
Change-Id: Ic7a6a87dd3a21351e60fbf6cd330456adf1f6800
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-05 13:10:10 +02:00
Jonathan Nieder 903432ef4d Merge branch 'stable-5.0'
* stable-5.0:
  Teach UploadPack "filter" in protocol v2 fetch
  Refactor test of capabilities output
  Refactor v2 advertisement into own function
  Refactor parsing of "filter" into its own method
  Disallow unknown args to "fetch" in protocol v2
  Teach UploadPack shallow fetch in protocol v2
  Refactor unshallowCommits to local variable
  Add protocol v2 support in http
  Give info/refs services more control over response

Change-Id: I1683902222e076e1091795e94790a264550afb7b
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-04 22:22:24 -07:00
Jonathan Tan 7dbd2bfe7e Teach UploadPack "filter" in protocol v2 fetch
If the configuration variable uploadpack.allowfilter is true, advertise
that "filter" is supported, and support it if the client sends such an
argument.

Change-Id: I7de66c0a0ada46ff71c5ba124d4ffa7c47254c3b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-06-04 22:09:07 -07:00
Jonathan Tan e319a6f8d4 Refactor v2 advertisement into own function
A subsequent patch needs dynamic generation of this advertisement
depending on a configuration variable in the underlying repository, so
refactor it into a function instead of using a constant list.

Change-Id: Ie00584add1fb56c9e88c7b57f75703981ea5bb85
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-06-04 22:09:06 -07:00
Jonathan Tan 62c4d3a133 Refactor parsing of "filter" into its own method
The implementation of protocol v2 will also need to parse the "filter"
option, so refactor it into its own method.

Change-Id: I751f6e6ca63fab873298594653a3885202297a2e
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-06-04 22:08:29 -07:00
Jonathan Tan 2f60804396 Disallow unknown args to "fetch" in protocol v2
JGit's implementation of the fetch command of protocol v2, unlike its
implementation of ls-refs, currently tolerates unknown arguments.
Tighten fetch to not allow unrecognized arguments and add tests to
verify this behavior for both ls-refs and fetch.

Change-Id: I321161d568bd638252fab1a47b06b924d472a669
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-06-04 22:08:21 -07:00
Jonathan Tan f7e501c36c Teach UploadPack shallow fetch in protocol v2
Add support for the "shallow" and "deepen" parameters in the "fetch"
command in the fetch-pack/upload-pack protocol v2. Advertise support for
this in the capability advertisement.

TODO: implement deepen-relative, deepen-since, deepen-not

Change-Id: I7ffd80d6c38872f9d713ac7d6e0412106b3766d7
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-04 22:08:18 -07:00
Jonathan Tan cd0d69ffec Refactor unshallowCommits to local variable
This reduces the amount of state held as instance variables in
UploadPack, and makes it easier for a future patch to contain a clearer
version of UploadPack#processShallow.

Change-Id: I6df80b42f9e5118fda1420692e02e417670cced3
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-04 22:04:18 -07:00
Jonathan Tan f516c1df9d Add protocol v2 support in http
Teach UploadPack to support protocol v2 with non-bidirectional pipes,
and add support to the HTTP protocol for v2. This is only activated if
the repository's config has "protocol.version" equal to 2.

Change-Id: I093a14acd2c3850b8b98e14936a716958f35a848
Helped-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-06-04 21:59:20 -07:00
David Pursehouse 61e2414ef7 Merge branch 'stable-5.0'
* stable-5.0:
  Chain RemoteAddCommand methods

Change-Id: I20d3cef5b5579c72ffd6809b7f6a8d787d631aaa
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-06-03 08:58:58 +09:00
Mincong HUANG 36a8c21069 Chain RemoteAddCommand methods
Change-Id: I1cf64c90a5cd2220034810b0d65d59582b420c4e
Signed-off-by: Mincong Huang <mincong.h@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-06-02 02:04:20 +02:00
Dave Borowitz 5c02ce52d6 Allow overriding DfsPackDescription comparator for scanning packs
Provide a factory for comparators that use the default heuristics except
with a different ordering of PackSources.

Change-Id: I0809b64deb3d0486040076946fdbdad650d69240
2018-06-01 12:41:31 -04:00
Dave Borowitz 96512f5d3b Move DfsPackDescription comparators to common location
There are several ways of comparing DfsPackDescriptions for different
purposes, such as object lookup search order and reftable ordering. Some
of these are later compounded into comparators on other objects, so they
appear in the code as Comparator<DfsReftable>, for example.

Put all the DfsPackDescription comparators in static methods on
DfsPackDescription itself. Stop implementing Comparable, to avoid giving
the impression that there is always one true and correct way of sorting
packs.

Change-Id: Ia5ca65249c13373f7ef5b8a5d1ad50a26577706c
2018-06-01 12:41:31 -04:00
Dave Borowitz e7bacf0a7f Use Comparators for PackSource
Rather than requiring callers to do their own computations based on the
package-private "category" number, provide an actual
Comparator<PackSource> instance, and explicitly discourage usage of
default Enum comparison.

Construct the default comparator using a builder pattern based on
defining equivalence classes. This gives us the same behavior as the old
category field in PackSource, with an abstraction that does not leak the
implementation detail of comparing rank numbers.

Change-Id: I6757211397ab1bc181d61298e073f88b69dbefc3
2018-06-01 12:41:17 -04:00
Dave Borowitz 43ec590d0e DfsPackDescription: Disallow null PackSource
In normal operation, the source of a pack should never be null; the DFS
implementation should always know where a pack came from. Existing
implementations in InMemoryRepository and at Google always have the
source available at construction time.

The problem with null PackSources in the previous implementation was it
made the DfsPackDescription#compareTo method intransitive. Specifically,
it skips comparing the sources at all if *either* operand is null.
Suppose we have three descriptions A, B, and C, where all fields are
equal except the PackSource, and:
 * A's source is INSERT
 * B's source is null
 * C's source is RECEIVE
In this case, A.compareTo(B) == 0, and B.compareTo(C) == 0, since all
fields are equal except the source, which is skipped. But
A.compareTo(C) != 0, since A and B have different sources.

Avoid this problem in compareTo by enforcing that the source is never
null. We could of course assign an arbitrary category number to a null
source in order to make comparison transitive[1], but it's simpler to
implement and reason about if the field is non-nullable, and there is no
real-world use case to make it null.

Although a non-null source is required at construction time, the field
is currently still mutable: DfsPackDecscription#setPackSource is used by
DfsInserterTest to mark packs as garbage. This could probably be
avoided as well, allowing us to convert packSource to a final field, but
doing so is beyond the scope of this change.

[1] The astute reader will notice this is already done by
    DfsObjDatabase#reftableComparator(). In fact, the reason that
    different comparator implementations non-obviously have different
    semantics for this nullable field is another reason why it's clearer
    to avoid null entirely.

Change-Id: I85a2aaf3fd6d4868f241f7972a0349f087830ffa
2018-06-01 12:40:35 -04:00
Matthias Sohn c473bbf802 Prepare 5.0.0-SNAPSHOT builds
Change-Id: I9c4a0465f8e85041d24da97f4b4c7ad5f5eed3e4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-30 23:16:23 +02:00
Matthias Sohn dbf091a7ee JGit v5.0.0.201805301535-rc2
Change-Id: Ifad678794525c01838b03e52bada66e1c089c5ae
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-30 21:33:49 +02:00
David Pursehouse 2ab42b74d9 Merge branch 'stable-5.0'
* stable-5.0:
  Don't prune symbolic refs when fetch.prune = true
  Prepare 5.0.0-SNAPSHOT builds
  JGit v5.0.0.201805221745-rc1
  Prepare 5.0.0-SNAPSHOT builds
  JGit v5.0.0.201805151920-m7

Change-Id: I9a9a4a3ab36a2bd83e4eaed90151740d59af171b
2018-05-28 08:56:27 +09:00
Thomas Wolf de21c58d03 Don't prune symbolic refs when fetch.prune = true
The canonical implementation also doesn't. Compare current
code in remote.c, function get_stale_heads_cb.[1] Not handling
symrefs in this case was introduced in canonical git in [2]
in 2008.

[1] https://github.com/git/git/blob/v2.17.0/remote.c#L2259
[2] https://github.com/git/git/commit/740fdd27f0

Bug: 533549
Change-Id: If348d56bb4a96b8aa7141f7e7b5a0d3dd4e7808b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-05-25 06:08:25 -05:00
Matthias Sohn 2f1b4ffcd2 Prepare 5.1.0-SNAPSHOT builds
Change-Id: I8523a993ae1f7b62573d7547273bc1356bf64fa7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-23 10:18:18 +02:00
David Pursehouse 1f6d43a652 Fix trivial usages of deprecated Repository#getAllRefs
Callers of getAllRefs that only iterate over the `values()` of the
returned map can be trivially fixed to call getRefDatabase().getRefs()
instead.

Only fix those where the calling method is already declared to throw
IOException, to avoid potential API changes.

Change-Id: I2b05f785077a1713953cfd42df7bf915f889f90b
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-23 13:31:22 +09:00
David Pursehouse 4162ad0dd3 Repository: Deprecate the #getAllRefs method
Callers should instead use getRefDatabase().getRefs(), which does not
swallow the IOException.

Replace @link with @code in the Javadoc of FileRepository, since linking
to the deprecated method causes an error:

  Javadoc: The method getAllRefs() from the type Repository is deprecated

Existing callers of the deprecated method are not adapted in this commit
because many of them require more refactoring. They will be done in
separate follow-up commits.

Bug: 534731
Change-Id: Id84e70e4cd7be3d1ca1795512950c6abe3d18ffd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-23 12:56:27 +09:00
Matthias Sohn 9ad7031381 Prepare 5.0.0-SNAPSHOT builds
Change-Id: Ie343ccf37f46168041046500a2e19acc80814cfe
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-23 01:54:32 +02:00
Matthias Sohn 812abefd58 JGit v5.0.0.201805221745-rc1
Change-Id: Ie2c35fab87f294b00f9754b07b60a848bf256b10
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-22 23:43:43 +02:00
David Pursehouse 51599ebb84 DescribeCommand: Refactor to not use deprecated Repository#peel
Change-Id: I76073ad62d1bc4fc21d8a1f5fc7eb92060a73baa
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-22 12:08:08 +09:00
David Pursehouse f6c4a492d0 Repository: Deprecate #peel method
Callers should use getRefDatabase().peel(ref) instead since it
doesn't swallow the IOException.

Adapt all trivial callers to user the alternative.

DescribeCommand still uses the deprecated method and is not adapted in
this change since it will require more refactoring to add handling of
the IOException.

Change-Id: I14d4a95a5e0570548753b9fc5c03d024dc3ff832
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-22 11:49:37 +09:00
David Pursehouse e701c59a85 Repository: Make #exactRef and #findRef final
This means less cognitive overhead for both implementors and callers,
since this way we can guarantee that they are always synonyms for
RefDatabase#exactRef and RefDatabase#findRef, respectively.

Change-Id: Ic8aeb52fc7ed65672f3f6cd1da39a66908d88baa
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-22 10:21:42 +09:00
Thomas Wolf d7deda98d0 Skip ignored directories in FileTreeIterator
Make FileTreeIterator not enter ignored directories by default. We
only need to enter ignored directories if we do some operation against
git, and there is at least one tracked file underneath an ignored
directory.

Walking ignored directories should be avoided as much as possible as
it is a potential performance bottleneck. Some projects have a lot of
files or very deep hierarchies in ignored directories; walking those
may be costly (especially so on Windows). See for instance also bug
500106.

Provide a FileTreeIterator.setWalkIgnoredDirectories() operation to
force the iterator to iterate also through otherwise ignored
directories. Useful for tests (IgnoreNodeTest, CGitIgnoreTest), or
to implement things like "git ls-files --ignored".

Add tests in DirCacheCheckoutTest, and amend IndexDiffTest to test a
little bit more.

Bug: 388582
Change-Id: I6ff584a42c55a07120a4369fd308409431bdb94a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-05-22 03:03:35 +02:00
David Pursehouse 1da2ff7242 Repository: Deprecate getTags method
Callers should use getRefDatabase().getRefsByPrefix(R_TAGS) instead.

Adjust the tests accordingly.

Bug: 534731
Change-Id: Ib28ae365e42720268996ff46e34cae1745ad545c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-22 09:40:54 +09:00
David Pursehouse 04560921c3 RefAdvertiser: Add send(Collection<Ref>) and deprecate send(Map<String, Ref>)
Bug: 534731
Change-Id: If15032a34dc62f420569e2b2b6d8e14e2dfed522
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-21 10:57:47 +09:00
Han-Wen Nienhuys f3ec7cf3f0 Remove further unnecessary 'final' keywords
Remove it from

 * package private functions.

 * try blocks

 * for loops

this was done with the following python script:

$ cat f.py
import sys
import re
import os

def replaceFinal(m):
  return m.group(1) + "(" +  m.group(2).replace('final ', '') + ")"

methodDecl = re.compile(r"^([\t ]*[a-zA-Z_ ]+)\(([^)]*)\)")

def subst(fn):
  input = open(fn)
  os.rename(fn, fn + "~")

  dest = open(fn, 'w')
  for l in input:
    l = methodDecl.sub(replaceFinal, l)
    dest.write(l)
  dest.close()


for root, dirs, files in os.walk(".", topdown=False):
  for f in files:
    if not f.endswith('.java'):
      continue

    full = os.path.join(root, f)
    print full
    subst(full)

Change-Id: If533a75a417594fc893e7c669d2c1f0f6caeb7ca
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2018-05-18 17:59:45 +02:00
Masaya Suzuki 667e30678a Execute AdvertiseRefsHook only for protocol v0 and v1
Refs are not advertised as part of the protocol v2 capability
advertisement. Don't call AdvertiseRefsHook.

Noticed because many implementations of AdvertiseRefsHook read all
refs in order to call UploadPack#setAdvertisedRefs, causing the
capability advertisement to be as slow as a v0 ref advertisement with
some RefDatabase implementations.

Such an AdvertiseRefsHook is of dubious utility (a better place to
determine which refs are advertised is in the RefDatabase
implementation itself, as in Gerrit), but at any rate since it's not
bringing about any benefit here, we can skip the hook call.

TODO:
- call an appropriate hook instead (https://bugs.eclipse.org/534847)
- add tests

[jn: fleshed out commit message; added TODO notes]

Change-Id: I6eb60ccfb251a45432954467a9ae9c1079a8c8b5
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-05-17 19:15:40 -07:00
Jonathan Tan 2841bab938 Add protocol v2 support in "jgit daemon"
With this patch, a server spawned by "jgit daemon" can be accessed using
protocol v2 from a Git client that supports it (for example, "git" with
the appropriate patches). This is only activated if the repository's
config has "protocol.version" be 2.

This required a change to the package-private #execute methods in
DaemonService to allow passing of extra parameters.

This has been tested with a patched Git.

Change-Id: Icf043efec7ce956d72b075fc6dc7a87d5a2da82a
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-05-16 20:58:31 -04:00
Jonathan Tan 526f5cf984 Teach UploadPack "ofs-delta" in "fetch"
Add support for the "ofs-delta" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: I728cf986082fce4ddeb6a6435897692e15e60cc7
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-05-16 20:54:03 -04:00
Jonathan Tan 5a87d50408 Teach UploadPack "include-tag" in "fetch"
Add support for the "include-tag" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

In order to determine which tags to include, only objects pointed to by
refs starting with "refs/tags/" are checked. This restriction is for
performance reasons and to match the behavior of Git (see add_ref_tag()
in builtin/pack-objects.c).

Change-Id: I7d70aa09bcc8a525218ff1559e286c2a610258ca
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-05-16 17:16:35 -07:00
Jonathan Tan c79e7f1c27 Avoid using #refs in UploadPack#sendPack
When OPTION_INCLUDE_TAG is set, UploadPack#sendPack uses the #refs
instance variable as a source of information of tags. A subsequent patch
will need to supply this information to #sendPack without
modifying #refs, so refactor #sendPack to take in this information
through a parameter instead.

Note that prior to this patch, #refs was used twice in #sendPack: once
to generate the argument to PackWriter#setTagTargets, and once to
determine if any tags need to be included in the packfile. This patch
only updates the latter use, since the former is meant not only for
"true" tag targets but any object that should be hoisted earlier during
packing (see the documentation of PackWriter#setTagTargets).

This patch does not introduce any functionality change.

Change-Id: I70ed65a1041334abeda8d4bac98cce7cae7efcdf
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-05-16 16:57:54 -07:00
David Pursehouse 1046ba12f9 FileRepository: Don't use deprecated RefDatabase#getRefs(String)
Change-Id: Iec58c973537ddbe0f4e6b8b62fcda5cecc961661
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-15 18:04:08 -04:00
David Pursehouse 46b7128a2e BatchRefUpdate: Don't use deprecated RefDatabase#getRefs(String)
Change-Id: I672c9cfe221ddc4acbde7a8040bd6ba83b16626e
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-05-15 18:02:39 -04:00
Han-Wen Nienhuys 6d370d837c Remove 'final' in parameter lists
Change-Id: Id924f79c8b2c720297ebc49bf9c5d4ddd6d52547
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2018-05-15 17:05:02 -04:00
Han-Wen Nienhuys f6873ffe52 Fixup javadoc and formatting in RawText and RawParseUtils
Change-Id: I9d6002941a33ec204d29e4fd920dde965387bb24
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2018-05-14 17:42:03 -07:00
Jonathan Nieder 7d9246f163 RawParseUtils#lineMap: Simplify by using null sentinel internally
Add an internal lineMapOrNull helper that returns null when the file
is binary.

This is simpler than using an exception for control flow and avoids
having to override fillInStackTrace to avoid a performance regression.

Change-Id: Ib8bb8df6a6bbd60c62cfb3b4c484a962a98b7507
2018-05-14 09:02:44 -07:00
Matthias Sohn e9e150fdd2 Store in IndexChangedEvent if it was caused by JGit itself
This allows to differentiate if index was changed by an external git
command or by JGit itself.

Change-Id: Iae692ba7d9bf01a288b3fb2dc2d07aec9891c712
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-13 22:38:54 +02:00
Han-Wen Nienhuys 08d2e0188c Introduce new RawText constructor and RawParseUtils.lineMapOrBinary
This makes binary detection exact in ResolveMerger and DiffFormatter

This has the same intention as
Id4342a199628d9406bfa04af1b023c27a47d4014 but preserves backward
compatibility of the signature of RawParseUtils.lineMap.

Change-Id: Ia24a4e716592bab3363ae24e3a46315a7511154f
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-12 10:18:37 +02:00
Matthias Sohn 78db9bd175 Use a secure random generator to seed nonce for digest authentication
https://tools.ietf.org/html/rfc7616 says:

5.12.  Parameter Randomness

The security of this protocol is critically dependent on the
randomness of the randomly chosen parameters, such as client and
server nonces.  These should be generated by a strong random or
properly seeded pseudorandom source (see [RFC4086]).

Change-Id: I4da5316cb1eb3f59ae06c070ce1c3335e9ee87d6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-11 14:06:53 +02:00
Matthias Sohn 81fa158e7c Merge branch 'stable-4.11'
* stable-4.11:
  Retry stale file handles on .git/config file

Change-Id: I4fe6152c3c40dde9cb88913cc9706852de0fd712
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-10 13:41:45 +02:00
Matthias Sohn 9bdbb06324 Merge branch 'stable-4.10' into stable-4.11
* stable-4.10:
  Retry stale file handles on .git/config file

Change-Id: Ice5c8ae8c2992243a81da77e166406bc1930fe0e
2018-05-10 13:36:27 +02:00
Matthias Sohn 9fdc595cdd Merge branch 'stable-4.9' into stable-4.10
* stable-4.9:
  Retry stale file handles on .git/config file

Change-Id: I6db7256dbd1c71b23e1231809642ca21e996e066
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-10 12:51:57 +02:00
Matthias Sohn dd9a14a762 Merge branch 'stable-4.8' into stable-4.9
* stable-4.8:
  Retry stale file handles on .git/config file

Change-Id: Ib029b5536c038190626e7a7ff43b70f0a5673721
2018-05-10 12:30:05 +02:00
Matthias Sohn d5ff94d575 Merge branch 'stable-4.7' into stable-4.8
* stable-4.7:
  Retry stale file handles on .git/config file

Change-Id: Ib665c094b28eefb8236752bb273de0c2d9bf9578
2018-05-10 12:08:46 +02:00
Matthias Sohn 1887c83477 Merge branch 'stable-4.6' into stable-4.7
* stable-4.6:
  Retry stale file handles on .git/config file

Change-Id: If5a21d38224528edfc551b3216daca6a2582e3ac
2018-05-10 11:59:56 +02:00
Matthias Sohn 9253a6c5ca Merge branch 'stable-4.5' into stable-4.6
* stable-4.5:
  Retry stale file handles on .git/config file

Change-Id: Ib6e6ec0846c3ef261ec1016bfa6d26d2eadc3f26
2018-05-10 11:39:52 +02:00
Nasser Grainawi d13918310f Retry stale file handles on .git/config file
On a local non-NFS filesystem the .git/config file will be orphaned if
it is replaced by a new process while the current process is reading the
old file. The current process successfully continues to read the
orphaned file until it closes the file handle.

Since NFS servers do not keep track of open files, instead of orphaning
the old .git/config file, such a replacement on an NFS filesystem will
instead cause the old file to be garbage collected (deleted).  A stale
file handle exception will be raised on NFS clients if the file is
garbage collected (deleted) on the server while it is being read.  Since
we no longer have access to the old file in these cases, the previous
code would just fail. However, in these cases, reopening the file and
rereading it will succeed (since it will open the new replacement file).
Since retrying the read is a viable strategy to deal with stale file
handles on the .git/config file, implement such a strategy.

Since it is possible that the .git/config file could be replaced again
while rereading it, loop on stale file handle exceptions, up to 5 extra
times, trying to read the .git/config file again, until we either read
the new file, or find that the file no longer exists. The limit of 5 is
arbitrary, and provides a safe upper bounds to prevent infinite loops
consuming resources in a potential unforeseen persistent error
condition.

Change-Id: I6901157b9dfdbd3013360ebe3eb40af147a8c626
Signed-off-by: Nasser Grainawi <nasser@codeaurora.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-05-10 11:13:32 +02:00
Jonathan Nieder b1f8ddfb70 Replace http://errorprone.info with https://errorprone.info
That site serves from https now.

Reported-by: Nicholas Glorioso <glorioso@google.com>
Change-Id: I2150a18425a1fe3ab5a022882ffe06ccbde17f16
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-05-04 15:09:22 -07:00
Carsten Pfeiffer 34bcb255ef ssh: Kill the external process when we're done instead of waiting forever
Bug: 529463
Change-Id: Iaf6fe20a1c759ac5e91a2393d7bc40a94f859e84
Signed-off-by: Carsten Pfeiffer <carsten.pfeiffer@gebit.de>
2018-05-02 17:41:39 +02:00
Jonathan Nieder 0a35e5f25b Rename RefDatabase#getAllRefs to getRefs
This is easier to type and makes it clearer that it only returns refs
and not the pseudo-refs returned by getAdditionalRefs. It also puts us
in a better position to add a method to the Repository class later
that delegates to this one without colliding with the existing
Repository#getAllRefs method that returns a Map<String, Ref>.

While at it, clarify the javadoc of getRefs and hasRefs to make the
same point.

Suggested-by: David Pursehouse <david.pursehouse@gmail.com>
Change-Id: I23497c66ac7b5e0c987b91efbc9e9cc29924ca66
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-04-29 17:19:43 -07:00
David Pursehouse 9fb724f1b9 RefDatabase: add hasRefs convenience method
Callers can now say:

 db.getRefDatabase().hasRefs()

rather than the more verbose:

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

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

Change-Id: I5244520708a1a7d9adb351f10e43fc39d98e22a1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-04-29 22:03:07 +02:00
David Turner d4f3ae0c43 Fix comparison order in AnyObjectId
The previous version suggested testing w2 first because w1 was used
for hashing, but in fact, hashCode returns w2.  The order (w3, w4, w5,
w1, w2) might be better on 64-bit processors too, since it allows
comparing 64 bits at a time, although perhaps on a modern SIMD
processor, the entire 160 bytes would be compared at once anyway.

Change-Id: Ieb69606d3c1456aeff36bffe99a71587ea76e977
Signed-off-by: David Turner <dturner@twosigma.com>
2018-04-27 15:21:30 -04:00
David Pursehouse 4dcf2f93db RefDatabase: Introduce getAllRefs method
Currently to get all refs, callers must use:

  getRefsByPrefix(ALL)

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

Change-Id: I7b1687c162c8ae836dc7db3ccc7ac847863f691d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-04-27 11:16:10 +09:00
David Pursehouse 57f158632d RefDatabase: Update Javadoc for ALL constant
The Javadoc refers to the deprecated getRefs method. Update it to refer
to getRefsByPrefix which is the recommended replacement of getRefs.

Change-Id: I61f2abcf1a3794f40a1746317dbc18aa0beb87a7
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-04-27 10:14:11 +09:00
David Pursehouse 20d431f79b LargePackedWholeObject#openStream: Suppress resource warning
Eclipse warns that DfsReader should be managed by try-with-resource.

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

Suppress the warning with a brief explanatory comment.

Change-Id: I4187c935742072f3ee7f2d3551a6a98d40fc2702
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-04-27 08:29:34 +09:00
Jonathan Nieder 1484d6eb0a LargePackedWholeObject: Do not reuse released inflater
LargePackedWholeObject.openStream produces a stream that allows
reading a large object.  This stream holds a DfsReader that takes care
of caching delta bases etc and in particular holds zlib Inflater for
use while reading the each delta in the packfile.

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

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

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

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

and

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

and

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

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

Change-Id: Iaf1d6fd368b64f76c520d215fd270a6098a1f236
2018-04-26 15:54:39 -07:00
Matthias Sohn 9edf9bf2d6 Remove trivial cases of using deprecated RefDatabase.getRefs()
Change-Id: I2d3e426a3391923f8a690ac68fcc33851f3eb419
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-04-25 03:28:51 +02:00
Matthias Sohn e341ec0afe Fix non-externalized String warnings
- suppress warning for non-translatable texts
- externalize error messages

Change-Id: Ieba42219b2c0b51a288f5a60438a6cc4f9dfe641
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-04-25 01:05:13 +02:00
Jonathan Tan ce7ac03c2f Remove unused code and link to deprecated code
Eclipse reports these as errors, so remove them.

Change-Id: Ic53d8003f9faef38fe776af5a73794e7bb1dfc49
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-04-25 00:46:13 +02:00
Michael Keppler 32a8162bc3 File compile and API errors in JGit
* Photon throws null analysis errors on the repeated invocation of those
previously null checked methods. Extract them to a local variable to
avoid this. (the null analysis is configured in project properties)
* setUseProtocolV2() misses @since tag. Problem was introduced with
332bc61124. Might be caused by the long
delay of 2 months from creation to merging.

Change-Id: Ibbb1a1580b604b8e7cd4bf7edc4643e292b6b4a8
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
2018-04-25 00:46:01 +02:00
Jonathan Tan df1f3c0f3c Teach UploadPack "no-progress" in "fetch"
Add support for the "no-progress" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: I6a6d6b1534f44845254b81d0e1f5c4ba2ac3d10b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-04-23 10:26:51 -07:00
Jonathan Tan a5dee1c125 Teach UploadPack "thin-pack" in "fetch"
Add support for the "thin-pack" parameter in the "fetch" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: I39a37b2b66a16929137d35c718a3acf2afb6b0b5
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-04-23 10:26:51 -07:00
Jonathan Tan adc73c4ba1 Teach UploadPack basic "fetch" command
Add basic support for the "fetch" command in the fetch-pack/upload-pack
protocol v2. This patch teaches "have" and "done".

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

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

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

Change-Id: I3dbec172239712ef9286a15b8407e86b87ea7863
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-04-23 10:26:51 -07:00
Jonathan Tan 038765cc55 Teach UploadPack "ref-prefix" in "ls-refs"
Add support for the "ref-prefix" parameter in the "ls-refs" command in
the fetch-pack/upload-pack protocol v2.

Change-Id: If9cf93b2646f75d50a11b5f482594f014d59a836
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-04-23 10:26:51 -07:00
Jonathan Nieder a99bbf162a UploadPack: Don't buffer ls-refs output
Once we have read the user's entire command, there is no more need to
buffer our response --- even the strictest servlet engine allows
writing output once the input has been consumed.  Noticed when the
analogous code in the "fetch" command (introduced in a later patch)
overflowed its buffer:

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

Change-Id: I33df56f1cb1c6c2c25ee95426cb7ad665134ac6b
2018-04-23 10:26:51 -07:00
Jonathan Tan 332bc61124 Implement ls-refs in UploadPack
Implement support for Git protocol v2's "ls-refs" command and its
"symrefs" and "peel" parameters.

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

Change-Id: I8abc6bcc6ed4a88c165677ff1245625aca01267b
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-04-23 10:26:51 -07:00
Jonathan Tan 2661bc0813 Implement protocol v2 with no capabilities in UploadPack
Add initial support for protocol v2 of the fetch-pack/upload-pack
protocol. This protocol is described in the Git project in
"Documentation/technical/protocol-v2.txt".

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

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

Change-Id: I79399fa0dce533fdc8c1dbb6756748818cee45b0
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-04-20 16:17:40 -07:00
Jonathan Tan 75b0703692 PacketLineIn, PacketLineOut: Add support for delim-pkt
Most pkt-lines (data-pkts) have the form

	pkt-len pkt-payload

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

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

	flush-pkt = "0000"

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

	delim-pkt = "0001"

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

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

Change-Id: I10e7824fa24ed74c4f45624bd490bba978cf5c34
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-04-20 12:21:23 -07:00
Jonathan Tan 4faec31c0a Add RefDatabase#getRefsByPrefix method
The existing RefDatabase#getRefs abstract method (to be implemented by
ref database backends) has the following issues:

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

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

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

Change-Id: I4c92f852e8c1558095dd460b5fd7b602c1d82df1
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-04-20 11:10:48 -07:00
Thomas Wolf 42e69409d7 Handle Gerrit Change-Ids for merge commits
Otherwise successful, non-conflicting merges will never get a
Gerrit Change-Id.

Bug: 358206
Change-Id: I9b599ad01d9f7332200c1d81a1ba6ce5ef990ab5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-04-18 23:33:37 +02:00
David Pursehouse cbb2e65dbc PushProcess: Remove unused import of HashMap
Bug: 533621
Change-Id: Ie125818d5fc8fef5800108db2ca21151d8d3bfa3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-04-16 16:51:32 +02:00
David Pursehouse 5b0129641e Merge "Push: Ensure ref updates are processed in input order" 2018-04-13 17:43:12 -04:00
Christian Halstrick 7cf29ba3e3 Merge "Allow '@' as last character of ref" 2018-04-13 05:14:43 -04:00