aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src
Commit message (Collapse)AuthorAgeFilesLines
* RawParseUtils: Avoid import of java.nio.charset.StandardCharsetsDavid Pursehouse2019-01-201-2/+1
| | | | | | | | | The import is only needed because of a reference to it in the Javadoc, and can be avoided by explicitly specifying the package instead, which is how it's referenced in other cases (Constants, FileHeader). Change-Id: I0c6254a9adf1f52fb8f2c04a858b11696ad264f5 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* UploadPack: Suppress false-positive resource leak warningDavid Pursehouse2019-01-201-0/+1
| | | | | Change-Id: Ida09cabb11740e6752a6f079d0528d38021fa2dd Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
* Implement signing commits using BouncyCastleMedha Bhargav Prabhala2019-01-167-3/+727
| | | | | | | | | | | | | This also includes a change to generating the jgit CLI jar. Shading is no longer possible because it breaks the signature of BouncyCastle. Instead, the Spring Boot Loader Maven plug-in is now used to generate an executable jar. Bug: 382212 Change-Id: I35ee3d4b06d9d479475ab2e51b29bed49661bbdc Also-by: Gunnar Wagenknecht <gunnar@wagenknecht.org> Signed-off-by: Gunnar Wagenknecht <gunnar@wagenknecht.org> Signed-off-by: Medha Bhargav Prabhala <mprabhala@salesforce.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* Allow CommitCommand to sign commitsGunnar Wagenknecht2019-01-166-1/+434
| | | | | | | | | | | | This change introduces the concept of a GpgSigner which will sign commits. The GpgSigner will be of a specific implementation (eg., Bouncycastle or OpenPgP executable). The actual implementation is not part of this change. Bug: 382212 Change-Id: Iea5da1e885c039e06bc8d679d46b124cbe504c8e Also-by: Medha Bhargav Prabhala <mprabhala@salesforce.com> Signed-off-by: Medha Bhargav Prabhala <mprabhala@salesforce.com> Signed-off-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
* dfs: Remove synchronization in BlockBasedFile#LazyChannelJonathan Nieder2019-01-141-6/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As explained in 'The "Double-Checked Locking is Broken" Declaration'[*], Java's memory model does not support double-checked locking: class LazyReadableChannel { private ReachableChannel rc = null; public ReadableChannel get() { if (rc == null) { synchronized (this) { if (rc == null) { rc = new ReadableChannel(); } } } return rc; } } With JDK 5 and newer, there is a formal memory model that ensures this works if "rc" is volatile, but it is still not thread-safe without that. Fortunately, this ReadableChannelSupplier is never passed between threads, so it does not need to be thread-safe. Simplify by removing the synchronization. [*] https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html Change-Id: I0698ee6618d734fc129dd4f63fc047c1c17c94a9 Signed-off-by: Jonathan Nieder <jrn@google.com>
* UploadPack: Read wanted refs in one shotJonathan Nieder2019-01-111-29/+69
| | | | | | | | | This allows scanning through refs once instead of once per ref, which should make the lookup less expensive for some RefDatabase implementations. Change-Id: I1434f834186cc9a6b4e52659e692b1000c926995 Signed-off-by: Jonathan Nieder <jrn@google.com>
* Merge branch 'stable-5.2'Jonathan Nieder2019-01-104-70/+161
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-5.2: Prepare 5.2.2-SNAPSHOT builds JGit v5.2.1.201812262042-r Prepare 5.1.6-SNAPSHOT builds JGit v5.1.5.201812261915-r UploadPack: Filter refs used for deepen-not resolution UploadPack: Avoid calling AdvertiseRefsHook twice Prepare 5.1.5-SNAPSHOT builds JGit v5.1.4.201812251853-r UploadPack: Filter refs used for want-ref resolution UploadPack: Defer want-ref resolution to after parsing Call AdvertiseRefsHook for protocol v2 Prepare 4.11.7-SNAPSHOT builds JGit v4.11.6.201812241910-r Prepare 4.9.9-SNAPSHOT builds JGit v4.9.8.201812241815-r UploadPack: Test filtering by AdvertiseRefsHook in stateless transports Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: Ia56348e54d62630d7c50a4747df89516fc5afad9 Signed-off-by: Jonathan Nieder <jrn@google.com>
| * UploadPack: Filter refs used for deepen-not resolutionJonathan Nieder2018-12-261-1/+34
| | | | | | | | | | | | | | | | | | | | Clients can use --shallow-exclude to obtain information about what commits are reachable from refs they are not supposed to be able to see. Plug the hole by allowing the AdvertiseRefsHook and RefFilter to take effect here, too. Change-Id: If2b8e95344fa49e10a6a202144318b60d002490e Signed-off-by: Jonathan Nieder <jrn@google.com>
| * Merge branch 'stable-5.1' into stable-5.2Jonathan Nieder2018-12-264-69/+127
| |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-5.1: UploadPack: Avoid calling AdvertiseRefsHook twice Prepare 5.1.5-SNAPSHOT builds JGit v5.1.4.201812251853-r UploadPack: Filter refs used for want-ref resolution UploadPack: Defer want-ref resolution to after parsing Call AdvertiseRefsHook for protocol v2 Prepare 4.11.7-SNAPSHOT builds JGit v4.11.6.201812241910-r Prepare 4.9.9-SNAPSHOT builds JGit v4.9.8.201812241815-r UploadPack: Test filtering by AdvertiseRefsHook in stateless transports Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: I5879df9b723a0dbf6a1eff89a34bbb269f3b773d Signed-off-by: Jonathan Nieder <jrn@google.com>
| | * Merge branch 'stable-5.0' into stable-5.1Jonathan Nieder2018-12-261-2/+4
| | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-5.0: UploadPack: Avoid calling AdvertiseRefsHook twice Change-Id: Ie9ce67921e38fff8338a148c4d9f2776be01d0b0 Signed-off-by: Jonathan Nieder <jrn@google.com>
| | | * UploadPack: Avoid calling AdvertiseRefsHook twiceJonathan Nieder2018-12-261-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The AdvertiseRefsHook can be called twice if the following conditions hold: 1. This AdvertiseRefsHook doesn't set this.refs. 2. getAdvertisedOrDefaultRefs is called after getFilteredRefs. For example, this can happen when fetchV2 is called after lsRefsV2 when using a stateful bidirectional transport. The second call does not accomplish anything useful. Guard it with 'if (!advertiseRefsHookCalled)' to avoid wasted work. Reported-by: Jonathan Tan <jonathantanmy@google.com> Change-Id: Ib746582e4ef645b767a5b3fb969596df99ac2ab5 Signed-off-by: Jonathan Nieder <jrn@google.com>
| | * | UploadPack: Filter refs used for want-ref resolutionJonathan Nieder2018-12-262-1/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the longer term, we can add support for this to the RequestValidator interface. In the short term, this is a minimal band-aid to ensure any refs the client requests are visible to the client. Change-Id: I0683c7a00e707cf97eef6c6bb782671d0a550ffe Reported-by: Ivan Frade <ifrade@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | * | UploadPack: Defer want-ref resolution to after parsingJonathan Nieder2018-12-263-47/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ProtocolV2Parser explains: // TODO(ifrade): This validation should be done after the // protocol parsing. It is not a protocol problem asking for an // unexisting ref and we wouldn't need the ref database here. Do so. This way all ref database accesses are in one place, in the UploadPack class. No user-visible change intended --- this is just to make the code easier to manipulate. Change-Id: I68e87dff7b9a63ccc169bd0836e8e8baaf5d1048 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | * | Merge branch 'stable-5.0' into stable-5.1Matthias Sohn2018-12-251-25/+54
| | |\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-5.0: Call AdvertiseRefsHook for protocol v2 Prepare 4.11.7-SNAPSHOT builds JGit v4.11.6.201812241910-r Prepare 4.9.9-SNAPSHOT builds JGit v4.9.8.201812241815-r UploadPack: Test filtering by AdvertiseRefsHook in stateless transports Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: Icdc212bf5be2485d0f8028acf6c62fb8531d0e3c Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | * Call AdvertiseRefsHook for protocol v2Masaya Suzuki2018-12-251-14/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | AdvertiseRefsHook is used to limit the visibility of the refs in Gerrit. If this hook is not called, then all refs are treated as visible. In protocol v2, the hook is not called, causing the server to advertise all refs. This bug was introduced in v5.0.0.201805221745-rc1~1^2~9 (Execute AdvertiseRefsHook only for protocol v0 and v1, 2018-05-14). Even before then, the hook was not called in requests after the capability advertisement, so in transports like HTTP that do not retain state between round-trips, the server would advertise all refs in response to an ls-refs (ls-remote) request. Fix both cases by using getAdvertisedOrDefaultRefs to retrieve the advertised refs in lsRefs, ensuring the hook is called in all cases that use its result. [jn: backported to stable-5.0; split out from a larger patch that also fixes protocol v0; avoided filtering this.refs by ref prefix] Change-Id: I64bce0e72d15b90baccc235c067e57b6af21b55f Signed-off-by: Masaya Suzuki <masayasuzuki@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | * Merge branch 'stable-4.11' into stable-5.0Matthias Sohn2018-12-251-11/+8
| | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.11: Prepare 4.11.7-SNAPSHOT builds JGit v4.11.6.201812241910-r Prepare 4.9.9-SNAPSHOT builds JGit v4.9.8.201812241815-r UploadPack: Test filtering by AdvertiseRefsHook in stateless transports Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: Ie81284ca6d580b0712c49eec610393d0c0c50203 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | * Merge branch 'stable-4.10' into stable-4.11Matthias Sohn2018-12-251-13/+9
| | | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.10: Prepare 4.9.9-SNAPSHOT builds JGit v4.9.8.201812241815-r UploadPack: Test filtering by AdvertiseRefsHook in stateless transports Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: I937e9a4547fc10e4de7c887163022d1ab0322d64 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | | * Merge branch 'stable-4.9' into stable-4.10Matthias Sohn2018-12-251-13/+9
| | | | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.9: Prepare 4.9.9-SNAPSHOT builds JGit v4.9.8.201812241815-r UploadPack: Test filtering by AdvertiseRefsHook in stateless transports Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: I2e499f34b1c481af794fa9325b0dfebaccdf3cb0 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | | | * Merge branch 'stable-4.8' into stable-4.9Matthias Sohn2018-12-241-13/+9
| | | | | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.8: Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: Ib44e314a68bca2349b45f4937257aa1298c8d74b Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | | | | * Merge branch 'stable-4.7' into stable-4.8Matthias Sohn2018-12-241-13/+9
| | | | | | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.7: Prepare 4.7.8-SNAPSHOT builds JGit v4.7.7.201812240805-r Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: I68a21067705b580b40840f8039001ff1e5273c15 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | | | | | * Merge branch 'stable-4.6' into stable-4.7Matthias Sohn2018-12-241-13/+9
| | | | | | | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.6: Fix feature versions imported by feature org.eclipse.jgit.pgm Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: If637694f80dbd1e774d60c672fe78a6500650bb8 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | | | | | | * Merge branch 'stable-4.5' into stable-4.6Matthias Sohn2018-12-241-13/+9
| | | | | | | | | |\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stable-4.5: Prepare 4.5.6-SNAPSHOT builds JGit v4.5.5.201812240535-r Call AdvertiseRefsHook before validating wants Change-Id: I0fd67ddd9c4966c20d82cdfe78b2f9d4898b4665 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
| | | | | | | | | | * Call AdvertiseRefsHook before validating wantsMasaya Suzuki2018-12-241-13/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | AdvertiseRefsHook is used to limit the visibility of the refs in Gerrit. If this hook is not called, then all refs are treated as visible, causing the server to serve commits reachable from branches the client should not be able to access, if asked to via a request naming a guessed object id. This bug was introduced in v2.0.0.201206130900-r~123 (Modify refs in UploadPack/ReceivePack using a hook interface, 2012-02-08). Stateful bidirectional transports are not affected. Fix it by moving the AdvertiseRefsHook call to getAdvertisedOrDefaultRefs, ensuring the hook is called in all cases. [jn: backported to stable-4.5 by splitting out tests and the protocol v2 specific parts] Change-Id: I159f396216354f2eda3968d17802e166d8c8ec2d Signed-off-by: Masaya Suzuki <masayasuzuki@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Lazily open ReadableChannel in BlockBasedFile.getOrLoadBlockMinh Thai2019-01-104-7/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To avoid opening the readable channel in case of DfsBlockCache hits. Also cleaning up typos around DfsBlockCache. Change-Id: I615e349cb4838387c1e6743cdc384d1b81b54369 Signed-off-by: Minh Thai <mthai@google.com>
* | | | | | | | | | | Fix warnings for usage of deprecated RefDatabase#getRefMatthias Sohn2019-01-084-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change-Id: I22a244114ef973b3801cf3b639ff782f21c02f98 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | DfsBlockCache: Consolidate where ReadableChannel is openedMinh Thai2019-01-084-87/+75
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Opening a readable channel can be expensive and the number of channels can be limited in DFS. Ensure that caller of BlockBasedFile.readOneBlock() is responsible for opening and closing the file, and that the ReadableChannel is reused in the request. As a side effect, this makes the code easier to read, with better use of try-with-resources. The downside is that this means a readable channel is always opened, even when the entire pack is already available for copying from cache. This should be an acceptable cost: it's rare enough not to overload the server and from a client latency perspective, the latency cost is in the noise relative to the data transfer cost involved in a clone. If this turns out to be a problem in practice, we can reintroduce that optimization in a followup change. Change-Id: I340428ee4bacd2dce019d5616ef12339a0c85f0b Signed-off-by: Minh Thai <mthai@google.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | DfsBlockCache to lock while loading object referencesMinh Thai2019-01-083-144/+289
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We see the same index being loaded by multiple threads. Each is hundreds of MB and takes several seconds to load, causing server to run out of memory. This change introduces a lock to avoid these duplicate works. It uses a new set of locks similar in implementation to the loadLocks for getOrLoad of blocks. The locks are kept separate to prevent long-running index loading from blocking out fast block loading. The cache instance can be configured with a consumer to monitor the wait time of the new locks. Change-Id: I44962fe84093456962d5981545e3f7851ecb6e43 Signed-off-by: Minh Thai <mthai@google.com>
* | | | | | | | | | | Fix "jgit checkout -f" to overwrite dirty worktree filesChristian Halstrick2019-01-082-14/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CheckoutCommand had a setForce() method. But this didn't correspond to native git's 'git checkout -f' option. Deprecate the old setForce() method and move its implementation to a new method setForceRefUpdate() and use it to implement the -B option in the CLI class Checkout. Add a setForced() method and use it to fix the associated '-f' option of the CLI Checkout class to behave like native git's 'git checkout -f' which overwrites dirty worktree files during checkout. This is still not fully matching native git's behavior: updating additionally dirty index entries is not done yet. Bug: 530771 Change-Id: I776b78eb623b6ea0aca42f681788f2e4b1667f15 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Return 'this' from setters in commandsMario Molina2019-01-073-20/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | To avoid breaking ABI, take the opportunity to give these setters (hopefully sometimes better) names and deprecate their old names. Change-Id: Ib45011678c3d941f8ecc1a1e0fdf4c09cdc337e3 Signed-off-by: Mario Molina <mmolimar@gmail.com> Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | Don't swallow IOExceptionJonathan Nieder2019-01-071-9/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Swallowing intermittent errors and trying to recover from them makes JGit's behavior hard to predict and difficult to debug. Propagate the errors instead. This doesn't violate JGit's usual backward compatibility promise for clients because in these contexts an IOException indicates either repository corruption or a true I/O error. Let's consider these cases one at a time. In the case of repository corruption, falling back e.g. to an empty set of refs or a missing ref will not serve a caller well. The fallback does not indicate the nature of the corruption, so they are not in a good place to recover from the error. This is analogous to Git, which attempts to provide sufficient support to recover from corruption (by ensuring commands like "git branch -D" cope with corruption) but little else. In the case of an I/O error, the best we can do is to propagate the error so that the user sees a dialog and has an opportunity to try again. As in the corruption case, the fallback behavior does not provide enough information for a caller to rely on the current error handling, and callers such as EGit already need to be able to handle runtime exceptions. To be conservative, keep the existing behavior for the deprecated Repository#peel method. In this example, the fallback behavior is to return an unpeeled ref, which is distinguishable from the ref not existing and should thus at least be possible to debug. Change-Id: I0eb58eb8c77519df7f50d21d1742016b978e67a3 Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | Deprecate Repository#hasObjectJonathan Nieder2019-01-046-9/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Its implementation contains } catch (IOException e) { // Legacy API, assume error means "no" return false; } Better to use ObjectDatabase#has, which throws IOException to report errors. Change-Id: I7de02f7ceb8f57b2a8ebdb16d2aa4376775ff933 Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | Deprecate RawParseUtils.UTF8-CHARSETMichael Keppler2019-01-041-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | That constant is just a redirection to a java standard constant meanwhile. It is not referenced anymore in jgit code (and egit is just removing it). Clients can use the redirection target directly. Change-Id: I058d013f61da8d7b771c499d8743aafb8faa5ea8 Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Fix detection of "initial checkout"Christian Halstrick2019-01-021-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A checkout done directly after cloning (the "initial checkout") has a different semantic as a default checkout. That is defined in the documentation of "git read-tree" [1]. JGit was detecting that it is doing an initial checkout differently from native git: jgit used to check that the index is empty but native git required that the index file does not exist [2]. Teach JGit to behave like native git. [1] https://github.com/git/git/blob/master/Documentation/git-read-tree.txt#L187 [2] https://marc.info/?t=154150811200001&r=1&w=2 Change-Id: I1dd0f1ede7cd7ea60d28607916d0165269a9f628
* | | | | | | | | | | Move BaseReceivePack#advertisedRefs getter and setter to ReceivePackJonathan Nieder2018-12-294-27/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Another step toward merging BaseReceivePack into ReceivePack. Change-Id: If861e28ce512f556e574352fa7d4a0df0984693f Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Move BaseReceivePack#walk getter to ReceivePackJonathan Nieder2018-12-292-4/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Another step toward merging BaseReceivePack into ReceivePack. Change-Id: I43cf2e36e2d5b0cd85bf23c81469909c14757b63 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Move BaseReceivePack#db getter to ReceivePackJonathan Nieder2018-12-292-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Another step toward eliminating BaseReceivePack as a separate API. Change-Id: If7b7d5c65a043607a2424211adb479fa33a9077b Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Move BaseReceivePack#pushCert getter and setter to ReceivePackJonathan Nieder2018-12-292-7/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a first step toward eliminating the BaseReceivePack API. Inspired by a larger change by Dan Wang <dwwang@google.com>. Change-Id: I5c876a67d8db24bf808823d9ea44d991b1ce5277 Signed-off-by: Jonathan Nieder <jrn@google.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Suppress API errors and add missing @since tags caused by 6ea888aMatthias Sohn2018-12-292-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change-Id: Id042d46ba078af35b9c22a079da4ae14fc5fa231 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
* | | | | | | | | | | Merge changes Id3bb9443,I1be1948bJonathan Nieder2018-12-286-48/+57
|\ \ \ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * changes: RefDatabase: Introduce findRef synonym for getRef RefDirectory: Look up several exact refs in one shot
| * | | | | | | | | | | RefDatabase: Introduce findRef synonym for getRefJonathan Nieder2018-12-266-62/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using findRef instead of getRef makes it clearer that the caller wants to search for the ref in the search path, instead of looking for a ref that exactly matches the input. This change introduces the new findRef method and deprecates getRef. It updates Repository#findRef to use the new method, ensuring some test coverage. Other callers will be updated in followup changes. A nice side effect of introducing the new findRef method is that it is final and based on firstExactRef, so implementers can focus on implementing the latter efficiently and do not have to carefully write custom path search code respecting SEARCH_PATH. Change-Id: Id3bb944344a9743705fd1f20193ab679298fa51c Signed-off-by: Jonathan Nieder <jrn@google.com>
| * | | | | | | | | | | RefDirectory: Look up several exact refs in one shotJonathan Nieder2018-12-261-0/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Override exactRef(String...) and firstExactRef(String...) with implementations specific to FileRepository. The specialized implementations are similar to the generic ones from RefDatabase, but because these use readRef directly instead of exactRef, they only need to call fireRefsChanged once. This will allow replacing RefDirectory#getRef with a generic implementation that uses firstExactRef without hurting performance. Change-Id: I1be1948bd6121c1a1e8152e201aab97e7fb308bb Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | | Move first line parsing for v0 push out of BaseReceivePackJonathan Nieder2018-12-272-15/+120
|/ / / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This simplifies the BaseReceivePack class and decreases its API surface, which should make merging with ReceivePack easier. Inspired by 6aca8899a5c02b3f6be7b9196cf5e935914476f0 (Move first line parsing for v0/v1 pack negotiation out of UploadPack, 2018-09-17). Change-Id: I1fc175d15aa7cb5968c26fc83a95480403af617c
* | | | | | | | | | | RefDirectory: Do not use search path to find additional refsJonathan Nieder2018-12-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Psuedorefs like FETCH_HEAD and MERGE_HEAD are supposed to be directly under the .git directory, not in other locations in the SEARCH_PATH like refs/ and refs/heads/. Use exactRef to access them. Change-Id: Iab8ac47008822fa78fc0691e239e518c34d7a98e Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | RefDatabase: Remove fallback exactRef implementationJonathan Nieder2018-12-261-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is simpler to implement than getRef. Make it abstract so implementers remember to override it. Change-Id: I5f319be1fb1206d7a0142ea939dc4e1039f850ab Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | RefDirectory: Fire RefsChangedEvent on error, tooJonathan Nieder2018-12-261-11/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | getRef and exactRef can produce recoverable exceptions --- for example, a corrupt loose ref that cannot be parsed. If readRef was called and updated looseRefs in the process, RefsChangedEvent should still be fired. Noticed while improving the implementation of getRef. This commit only affects exactRef and getRef. Other methods might be similarly skipping firing RefsChangedEvent in their error handling code, and this change does not fix them. Change-Id: I0f460f6c8d9a585ad8453a4a47c1c77e24a1fb83 Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | RefDirectory: Refactor getRef and exactRef to share codeJonathan Nieder2018-12-261-20/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Both getRef and exactRef look for a ref or pseudoref in the $GIT_DIR directory, with careful error handling to handle non-refs like .git/config. Avoid the duplication by factoring out a helper that takes care of this. This should make the code easier to understand and manipulate. Change-Id: I2ea67816d2385e84e2d3394b897e23df5826ba50 Signed-off-by: Jonathan Nieder <jrn@google.com>
* | | | | | | | | | | Merge changes from topic 'update-index-ref-decorator'Jonathan Nieder2018-12-2611-47/+169
|\ \ \ \ \ \ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * changes: RefCursor: Remove unnecessary getUpdateIndex method RefDatabase/Ref: Add versioning to reference database
| * | | | | | | | | | | RefCursor: Remove unnecessary getUpdateIndex methodIvan Frade2018-12-264-26/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now the reference carries its updateIndex, so the cursor doesn't need to expose it. Change-Id: Icbfca46f92a13f3d8215ad10b2a166a6f40b0b0f Signed-off-by: Ivan Frade <ifrade@google.com>
| * | | | | | | | | | | RefDatabase/Ref: Add versioning to reference databaseIvan Frade2018-12-268-23/+169
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In DFS implementations the reference table can fall out of sync, but it is not possible to check this situation in the current API. Add a property to the Refs indicating the order of its updates. This version is set only by RefDatabase implementations that support versioning (e.g reftable based). Caller is responsible to check if the reference db creates versioned refs before accessing getUpdateIndex(). E.g: Ref ref = refdb.exactRef(...); if (refdb.hasVersioning()) { ref.getUpdateIndex(); } Change-Id: I0d5ec8e8df47c730301b2e12851a6bf3dac9d120 Signed-off-by: Ivan Frade <ifrade@google.com>
* | | | | | | | | | | | JGitInternalException: Fix typo in JavadocDavid Pursehouse2018-12-221-1/+1
|/ / / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change-Id: I46fabab3cb2d9164234ce04de346826687a3fa35 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>