Commit Graph

4937 Commits

Author SHA1 Message Date
David Pursehouse 25ab5b4d9b Merge "Don't rely on default locale when using toUpperCase() and toLowerCase()" 2017-01-30 07:32:32 -05:00
David Pursehouse c64412e1f9 Merge FileTreeIteratorJava7Test into FileTreeIteratorTest
JGit now requires Java 8, so it is no longer necessary to have a
separate class for Java 7 specific tests. Remove it and merge its
tests into the existing FileTreeIteratorTest.

FileTreeIteratorTest has an @Before annotated method that sets up
some files in the git, which breaks the tests which have assumptions
on the file names. Add adjustments.

Change-Id: I14f88d8e079e1677c8dfbc1fcbf4444ea8265365
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-30 13:23:52 +01:00
Hongkai Liu b198f77c1e Rename FileUtilTest to FileUtilsTest and merge in FileUtils7Test
Rename the test class to match the name of the class under test.

JGit now requires Java 8 so it is no longer necessary to have a
separate class (FileUtils7Test) for Java 7 tests. Merge those into
FileUtilsTest.

Change-Id: I39dd7e76a2e4ce97319c7d52261b0a1546879788
Signed-off-by: Hongkai Liu <hongkai.liu@ericsson.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-30 02:42:56 -04:00
Hector Caballero 27b710c394 Make GC cancellable when called programmatically
Sometimes, it is necessary to cancel a garbage collection operation.
When GC is called using the standalone executable, i.e., from a command
line, Control-Cing the process does the trick. When calling GC
programmatically, though, there is no mechanism to do it.

Add checks in the GC process so that a custom cancellable progress
monitor could be passed in order to cancel the operation at specific
points. In this case, the calling process set the cancel flag in the
progress monitor and the GC process will throw an exception that can
be caught and handled by the caller accordingly.

Change-Id: Ieaecf3dbdf244539ec734939c065735f6785aacf
Signed-off-by: Hector Caballero <hector.caballero@ericsson.com>
2017-01-29 20:14:37 -04:00
Matthias Sohn a11bb03127 GC.prune(Set<ObjectId>): return early if objects directory is empty
Change-Id: Id56b102604c4e0437230e3e7c59c0a3a1b676256
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-30 00:55:38 +01:00
Hongkai Liu 8fd500e20c Clean up orphan files in GC
An orphan file is either a bitmap or an idx file in pack folder,
and its corresponding pack file is missing.

Change-Id: I3c4cb1f7aa99dd7b398bdb8d513f528d7761edff
Signed-off-by: Hongkai Liu <hongkai.liu@ericsson.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-30 00:55:36 +01:00
Matthias Sohn 53ad437382 RepositoryCacheTest: avoid to close already closed repository
The tearDown() of the superclass closed the repository once more which
led to a negative use count warning logged by Repository.close().

Change-Id: I331f85a540c68264a53456276c32f72b79113d61
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-28 21:19:55 +01:00
David Pursehouse ac6353e9e5 RefUpdateTest: Don't call createBareRepository in try-with-resource
createBareRepository adds the created repo to the list of repos to be
closed in the superclass's teardown. Wrapping it in try-with-resource
causes it to be closed too many times, resulting in a corrupt use
count.

Change-Id: I4c70630bf6008544324dda453deb141f4f89472c
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-28 19:16:48 +01:00
David Pursehouse 25b14084c9 ReceivePackAdvertiseRefsHookTest: Don't close repositories in teardown
The repositories get added to the "toClose" set by createBareRepository,
and are then closed in the superclass's tearDown method.

Explicitly closing them in this test class's teardown causes the use
count to go negative when subsequently closed again by the superclass.

Change-Id: Idcbb16b4cf4bf0640d7e4ac15d1926d8a27c1251
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-28 17:46:28 +01:00
David Pursehouse acc94c475a RepoCommand#readFile: Don't call Git#getRepository() in try-with-resource
Using try-with-resource means that close() will automatically be
called on the Repository object. However, according to the javadoc
of Git#close():

  If the repository was opened by a static factory method in this class,
  then this method calls Repository#close() on the underlying repository
  instance.

This means that Repository#close() is called twice, by Git.close()
and in the outer try-with-resource, leading to a corrupt use count.

Change-Id: I37ba517eb2cc67d1cd36813598772c70208d0bc9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-28 17:46:28 +01:00
David Pursehouse 883856110c RepoCommandTest: Don't wrap create{Bare,Work}Directory in t-w-r
These methods add the created Repository into "toClose", and they are
then closed by LocalDiskRepositoryTestCase's tearDown method.

Calling them in try-with-resource causes them to first be closed in
the test method, and then again in tearDown, which results in the use
count going negative and a log message on the console.

While this is not a serious problem, having so many false positives
in the logs will potentially drown out real cases of Repository being
closed too many times.

Change-Id: Ib374445e101dc11cb840957b8b19ee1caf777392
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-28 17:46:27 +01:00
David Pursehouse 5d0ca36d39 LocalDiskRepositoryTestCase: Only add to toClose through access method
Only using the access method means we only have one place where the
toClose set is modified, making it easier to debug either by adding
log statements or by setting a breakpoint.

Change-Id: I4f9f1774d5f2e10bcab381edfd84bb6ee0499a11
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-28 17:46:27 +01:00
David Pursehouse a9a3af4af7 GitConstructionTest: Remove unnecessary calls to Repository.close()
The repositories are already closed in the superclass teardown due
to being added to the "toClose" set.

Change-Id: I768ba8a02fc585907687caf37e2e283434016c04
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-28 17:46:27 +01:00
Matthias Sohn 7dca5dc9f3 Merge "LocalDiskRepositoryTestCase: Prevent duplicates in list of repos to close" 2017-01-28 11:45:21 -05:00
Andrey Loskutov 2845016777 Merge "Remove unused org.apache.http.impl.client.cache requirement" 2017-01-28 10:04:30 -05:00
Matthias Sohn a4feeb0194 Don't rely on default locale when using toUpperCase() and toLowerCase()
Otherwise these methods may produce unexpected results if used for
strings that are intended to be interpreted locale independently.
Examples are programming language identifiers, protocol keys, and HTML
tags. For instance, "TITLE".toLowerCase() in a Turkish locale returns
"t\u0131tle", where '\u0131' is the LATIN SMALL LETTER DOTLESS I
character.

See
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toLowerCase--
http://blog.thetaphi.de/2012/07/default-locales-default-charsets-and.html

Bug: 511238
Change-Id: Id8d8f37d84d62239c918b81f8d883ed798d87656
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-28 15:06:15 +01:00
David Pursehouse d69a829bdb LocalDiskRepositoryTestCase: Prevent duplicates in list of repos to close
Change the "toClose" list to a set, which will not allow duplicate
entries. This reduces the number of false positive logs about corrupt
use count due to the same repository being closed more than once during
teardown.

Change-Id: I5ab0ff8b56e7f2b2c7aab5274d957708d26f42c5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-27 16:00:06 +09:00
David Pursehouse 2eb1bebd60 Repository: Include repository name when logging corrupt use count
Logging the repository name makes it easier to track down what is
incorrectly closing a repository.

Change-Id: I42a8bdf766c0e67f100adbf76d9616584e367ac2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-27 15:59:09 +09:00
Thirumala Reddy Mutchukota c9f55032a2 Record the estimated size of the pack files.
The Compacter and Garbage Collector will record the estimated size of
the newly going to be created compact, gc or garbage packs. This
information can be used by the clients to better make a call on how to
actually store the pack based on the approximated expected size.

Added a new protected method DfsObjDatabase.newPack(PackSource
packSource, long estimatedPackSize), so that the clients can override
this method to make use of the estimatedPackSize while creating a new
PackDescription object. The default implementation of this method is
equivalent to
newPack(packSource).setEstimatedPackSize(estimatedPackSize). I didn't
make it abstract because that would force all the existing sub classes
of DfsObjDatabase to implement this method. Due to this default
implementation, the estimatedPackSize is added to DfsPackDescription
using a setter instead of a constructor parameter (even though
constructor parameter would be a better choice as this value is set only
during the object creation).

Change-Id: Iade1122633ea774c2e842178a6a6cbb4a57b598b
Signed-off-by: Thirumala Reddy Mutchukota <thirumala@google.com>
2017-01-26 12:01:59 -08:00
Andrey Loskutov 7856867664 Remove unused org.apache.http.impl.client.cache requirement
The package is not used by the plugin and seems to be missing in the
platform anyway under some conditions, see bug 508321 (newer
org.apache.httpcomponents.httpclient_4.5.2 does NOT include the package,
org.apache.httpcomponents.httpclient_4.3.6 does).

Change-Id: Ida5d926a611812b5177af651b3cf22f1b2519e02
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2017-01-26 15:30:36 -04:00
David Pursehouse 635bff2d50 Merge branch 'stable-4.6'
* stable-4.6:
  Update Orbit to S20170120205402 and com.jcraft.jsch to 0.1.54
  Fix preparation of 4.6.1-SNAPSHOT builds

Change-Id: Ifd1f81cb199a0b5bd35e8652cac116e377136b2d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-26 11:01:32 +09:00
Lars Vogel 71edc8bd6f Fixes Javadoc error in org.eclipse.jgit created with I59539ac
Adds the param information to the private method. These are generated
via tooltip to resolve the compile errors.

Bug: 511043
Change-Id: I9ba551978eab750326d1a067b296e3ae93925871
Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
2017-01-25 12:40:59 -04:00
Jonathan Nieder 061d24f6d5 Remove @since tags from internal packages
These packages don't use @since tags because they are not part of the
stable public API.  Some @since tags snuck in, though.  Remove them to
make the convention easier to find for new contributors and the
expectations clearer for users.

Change-Id: I6c17d3cfc93657f1b33cf5c5708f2b1c712b0d31
2017-01-24 14:41:24 -08:00
David Turner 8bec98cec0 gc: loosen unreferenced objects
An unreferenced object might appear in a pack.  This could only happen
because it was previously referenced, and then later that reference
was removed.  When we gc, we copy the referenced objects into a new
pack, and delete the old pack.  This would remove the unreferenced
object.  Now we first create a loose object from any unreferenced
object in the doomed pack.  This kicks off the two-week grace period
for that object, after which it will be collected if it's not
referenced.

This matches the behavior of regular git.

Change-Id: I59539aca1d0d83622c41aa9bfbdd72fa868ee9fb
Signed-off-by: David Turner <dturner@twosigma.com>
Signed-off-by: Jonathan Nieder <jrn@google.com>
2017-01-24 14:22:45 -08:00
Matthias Sohn efbecb9764 Update Orbit to S20170120205402 and com.jcraft.jsch to 0.1.54
CQ: 12553
Change-Id: Ie72b48d00f363e3dc05b9733018a6ddca32c3e6e
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-23 20:29:43 +01:00
Matthias Sohn fd874b4024 Fix preparation of 4.6.1-SNAPSHOT builds
Change-Id: Ib241c4f45192672712526599898c0bd0bd356436
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-23 20:29:42 +01:00
Matthias Sohn d3c4c0622f [infer] Mark ManifestParse.getFilteredProjects non-null
Change-Id: I05653df7a0337443d2c8e53f47f4e95ec9ca1a9c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-23 19:55:20 +01:00
Matthias Sohn b686c8468c [infer] Fix potential NPE in DiffFormatter
Change-Id: Ia33e2af9ce3393d9173ca0dc7efefd86c965d8c8
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-23 19:55:18 +01:00
Matthias Sohn 423a583fcc [infer] Fix potential NPE in CloneCommand
Change-Id: Ie7eeba3ae719ff207c7535d535a9e0bd6c9e99e6
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-23 19:55:12 +01:00
David Pursehouse 9d1474431f Implement Bazel build for http-apache, lfs, lfs-server
Test plan:

  $ bazel build all

  $ unzip -t bazel-genfiles/all.zip
    Archive:  bazel-genfiles/all.zip
      testing: libhttp-apache.jar       OK
      testing: libjgit-archive.jar      OK
      testing: libjgit-lfs-server.jar   OK
      testing: libjgit-lfs.jar          OK
      testing: libjgit-servlet.jar      OK
      testing: libjgit.jar              OK
      testing: libjunit.jar             OK
    No errors detected in compressed data of bazel-genfiles/all.zip.

Change-Id: I9e6c60898ccc6d2a4557ec7544c297442a9702b4
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-22 22:34:12 +01:00
David Pursehouse dd5e500a57 Format Bazel files with buildifier
Change-Id: I934114315d2c7cab917f1011b8e55c52367d429f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-22 22:34:11 +01:00
Shawn Pearce 131b09106f Change StreamGobbler to Runnable to avoid unused Future
It can be considered a programming error to create a Future<T>
but do nothing with that object. There is an async computation
happening and without holding and checking the Future for done
or exception the caller has no idea if it has completed.

FS doesn't really care about these StreamGobblers finishing.
Instead use Runnable with execute(Runnable), which doesn't
return a Future.

Change-Id: I93b66d1f6c869e66be5c1169d8edafe781e601f6
2017-01-21 09:44:14 +01:00
Matthias Sohn f503a9f5b7 Add missing @since tags on new API constants
Change-Id: Ia8b861da07fba99644ccc9eb5578a46cc39600a1
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-19 23:56:25 +01:00
James Melvin 91132bb05e gc: Add options to preserve and prune old pack files
The new --preserve-oldpacks option moves old pack files into the
preserved subdirectory instead of deleting them after repacking.

The new --prune-preserved option prunes old pack files from the
preserved subdirectory after repacking, but before potentially
moving the latest old packfiles to this subdirectory.

These options are designed to prevent stale file handle exceptions
during git operations which can happen on users of NFS repos when
repacking is done on them. The strategy is to preserve old pack files
around until the next repack with the hopes that they will become
unreferenced by then and not cause any exceptions to running processes
when they are finally deleted (pruned).

Change-Id: If3f729f0d9ce920ee2c3e6acdde46f2068be61d2
Signed-off-by: James Melvin <jmelvin@codeaurora.org>
2017-01-19 11:00:18 +01:00
David Pursehouse d3148f300a Make ObjectDownloadListener public
The same was already done for ObjectUploadListener in I5b0fb1220.

Change-Id: Ie8a79f715fe69bed9331962fb478f7e35acf8680
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-19 13:42:59 +09:00
David Ostrovsky e92a0c3adc Implement initial framework of Bazel build
The initial implementation only builds the packages consumed by
Gerrit Code Review.

Test build and execution is not implemented.

We prefer to consume maven_jar custom rule from bazlets repository,
for the same reasons as in the Gerrit project:

* Caching artifacts across different clones and projects
* Exposing source classifiers and neverlink artifact

TEST PLAN:

  $ bazel build :all
  $ unzip -t bazel-genfiles/all.zip
  Archive: bazel-genfiles/all.zip
    testing: libjgit-archive.jar      OK
    testing: libjgit-servlet.jar      OK
    testing: libjgit.jar              OK
    testing: libjunit.jar             OK
  No errors detected in compressed data of bazel-genfiles/all.zip.

Change-Id: Ia837ce95d9829fe2515f37b7a04a71a4598672a0
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-18 19:13:16 -04:00
Wim Jongman b667c182cb Normalizer creating a valid branch name from a string
Generic normalization method for a possible invalid branch name.
The method compresses dividers between spaces, then replaces spaces
and non word characters with underscores.

This method is needed in preparation for subsequent EGit changes.

Bug: 509878
Change-Id: Ic0d12f098f90f912a45bcc5693d6accf751d4e58
Signed-off-by: Wim Jongman <wim.jongman@remainsoftware.com>
2017-01-18 22:05:28 +01:00
Christian Halstrick 8a46b60371 Merge "Fix StashApplyCommand for stashes containing untracked changes." 2017-01-16 03:45:00 -05:00
Thomas Wolf 46af7192a2 Fix StashApplyCommand for stashes containing untracked changes.
If there are untracked changes, apply only the untracked tree
after a successful merge. The merge tree from merging untracked
with HEAD would also contain files already reset before (changes
in tracked files) and try to reset those again,leading to false
checkout conflicts.

Bug: 505804
Change-Id: Iaced4d277623334d11e3d1cca5969590d7c5093e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2017-01-15 21:54:12 +01:00
Marc Strapetz 1c4b3f8c45 Fix possible InvalidObjectIdException in ObjectDirectory
ObjectDirectory.getShallowCommits should throw an IOException
instead of an InvalidArgumentException if invalid SHAs are present
in .git/shallow (as this file is usually edited by a human).

Change-Id: Ia3a39d38f7aec4282109c7698438f0795fbec905
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-15 15:05:51 +01:00
Zhen Chen d3148f9410 Add missing slf4j dependency in BUCK file for jgit-lfs-server
Change-Id: I0c7fcae123f94ebd8e5eb2700e3d601a1b199be9
Signed-off-by: Zhen Chen <czhen@google.com>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-14 15:49:14 +09:00
Zhen Chen d6b354f60f Skip pack header bytes in DfsPackFile
The 12 bytes `PACK...` header is written in PackWriter before reading
CachedPack files. In DfsPackFile#copyPackBypassCache, the header was not
skipped when the first block is not in cache.

Change-Id: Ibbe2e564d36b79922a936657f286addb1044d237
Signed-off-by: Zhen Chen <czhen@google.com>
2017-01-13 22:10:42 -08:00
David Pursehouse 55c629a9f3 LfsProtocolServlet#LfsRequest: Add operation type helper methods
Server implementations may need to check what type of operation is
being performed. Add helper methods to make it a bit simpler.

Change-Id: Ia33ed6699ebcb9000ef514ce79bcddbebf94e1c5
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-14 01:07:52 +01:00
David Pursehouse 56fe217784 Expose LFS operation strings as public constants
So that they can be used either by third party LFS server implementations
or from within other parts of JGit's internal LFS implementation.

Change-Id: I58da6230247204588e017c010ce5b14e4615448d
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-13 19:23:33 -04:00
David Pursehouse 590141163f LfsProtocolServlet: Improve error on getLargeFileRepository failure
Externalize the error message and make it more specific. Also emit
an error log.

Change-Id: Ie7b1c90c54673bfb8e133fb0aa19a117d4ca6587
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-14 00:05:56 +01:00
David Pursehouse 7245aa0316 Add support for refusing LFS request due to invalid authorization
Add a new exception type that server implementations can throw when a
client attempts to make an unauthorized LFS operation, which will result
in HTTP 401 Unauthorized being returned to the client.

An example of this is a Gerrit server that rejects a request to perform
an LFS operation on a ref that is not visible to the caller.

As defined in the LFS spec [1] the request may include authentication,
and per RFC 2616 [2], "401 response indicates that authorization has been
refused for those credentials".

[1] https://github.com/git-lfs/git-lfs/blob/master/docs/api/batch.md
[2] https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Change-Id: I2aa22e2144df5fb7972df0e3285b77b08ecc63f2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2017-01-13 10:46:15 +09:00
Dariusz Luksza 0e187f1484 Add LfsPointerFilter TreeFilter
Add new variation of TreeFilter in order to detect LFS pointer files in
the repository.

Additionally, update LfsPointer to support the legacy version URL [1] as
described in [2], and to allow arbitrary fields in the pointer file.

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

Change-Id: I621eb058619fb1b78888a54c4b60bb110a722fc3
Signed-off-by: Dariusz Luksza <dariusz@luksza.org>
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2017-01-10 00:13:24 +01:00
Shawn Pearce db77610256 Pack refs/tags/ with refs/heads/
This fixes a nasty performance issue for repositories that have many
objects referenced through refs/tags/, but not in refs/heads/.
Situations like this can arise when a project has made releases like
refs/tags/v1.0, and then decides to orphan history and start over for
version 2. The v1.0 objects are not reachable from master anymore,
but are still live due to the v1.0 tag.

When tags are packed in the GC_OTHER pack, bitmaps are not able to
cover the repository's contents. This may cause very slow counting
times during git clone, as the server must enumerate the ancient
history under refs/tags/ to respond to the client.

Clients by default always ask for all tags when asking for all heads
during clone. This has been true since git-core commit 8434c2f1afedb
(Apr 27 2008), when clone was converted to a builtin. Including tags
in the main GC pack should still allow servers to benefit from the
fast full pack reuse path when serving a clone to a client.

Change-Id: I22e29517b5bc6fa3d6b19a19f13bef0c68afdca3
2017-01-03 14:46:41 -08:00
Marc Strapetz 6087031469 Get rid of javax.servlet API dependency for core org.eclipse.jgit
Change-Id: I57d5d4fab7e0b1bd4cf5f1850e8569c8ac5def88
Signed-off-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
2017-01-03 18:50:55 +01:00
Matthias Sohn 5dc30db56e [findBugs] PackWriter.NONE should be final
Change-Id: I4b5621bcb4db82e0560408b3cde6f18b0cc55b29
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2016-12-30 01:19:58 +01:00