Commit Graph

6127 Commits

Author SHA1 Message Date
Matthias Sohn 3a12709851 Prepare 6.3.0-SNAPSHOT builds
Change-Id: Ie398b651c5308ec86812bf01fcc563d3e679c828
2022-08-17 07:44:50 +02:00
Matthias Sohn 85a4809996 JGit v6.3.0.202208161710-m3
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Change-Id: I0954d11a1f35eff196b157df3aa8386476c48a7e
2022-08-16 23:09:30 +02:00
Matthias Sohn ab3799be37 Merge changes Ib6689f54,I3b5c22ee
* changes:
  Remove unused API problem filters
  Add missing @since tag for RevCommit#parents introduced in 61b4d105e4
2022-08-16 17:00:43 -04:00
Thomas Wolf b255eb0fb6 DirCacheCheckout: load WorkingTreeOptions only once
Previous code loaded the WorkingTreeOptions afresh for every single
file being checked out. This checked the git config (all three files,
repo, user and system config) for having been modified every time.

These checks can be costly, for instance on Windows, or if one of the
three config files is not on a local disk, or on an otherwise slow
storage.

Improve this by loading the options and thus checking the git config
only once before the checkout.

Bug: 579715
Change-Id: I21cd5a808f9d90b5ca2d022f91f0eeb8ca26091c
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-08-14 21:33:19 +02:00
Thomas Wolf 134ee334fb WorkTreeUpdater: Fix unclosed streams
1. A TemporaryBuffer.LocalFile must be destroyed to ensure the
   temporary file gets deleted on disk.
2. TemporaryBuffer.openInputStream() may be used only after
   TemporaryBuffer.close().
3. The caller of DirCacheCheckout.getContent() is responsible for
   closing the OutputStream!

Change-Id: I46abb0fba27656a1026858e5783fc60d4738a45e
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-08-14 21:33:18 +02:00
Matthias Sohn 1745131add Merge "Fix API errors caused by 23a71696cd" 2022-08-14 05:43:39 -04:00
Thomas Wolf d9c0629ffe Fix adding symlinks to the index when core.symlinks=false
With core.symlinks=false, symlinks are checked out as plain files.
When such a file is re-added to the index, and the index already
contains a symlink there, add the file as a symlink. Previous code
changed the index entry to a regular file.

Bug: 580412
Change-Id: I5497bedc3da89c8b10120b8077c56bc5b67cb791
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-08-13 15:14:15 +02:00
Matthias Sohn 7854122b92 Remove unused API problem filters
Change-Id: Ib6689f545585bd59b8fc06ca3a104080021424d6
2022-08-12 10:44:12 +02:00
Matthias Sohn 4bec6d98b8 Add missing @since tag for RevCommit#parents introduced in 61b4d105e4
Change-Id: I3b5c22eea7d0af5464c7df7a7cd855ea08029853
2022-08-12 10:38:57 +02:00
Matthias Sohn 2417c9f0e4 Fix API errors caused by 23a71696cd
- add missing @since 6.3 for new protected field workTreeUpdater and new
  class WorkTreeUpdater
- suppress API errors caused by removing/adding protected fields and
  methods

We follow OSGi semantic versioning which allows breaking implementers in
minor versions which are e.g. subclassing a public class.

Change-Id: I28f0d7b4fdd9a1f0fbc6b137d6c68dda9fe3c11e
2022-08-12 10:37:09 +02:00
Han-Wen NIenhuys 4d6c6df108 Merge changes Ideaefd51,I6c347393
* changes:
  Reapply "Create util class for work tree updating in both filesystem and index."
  ResolveMerger: add coverage for inCore file => directory transition
2022-08-09 05:10:53 -04:00
Ronald Bhuleskar 8542bf790e Provide default shallowCommits getter and setter in ObjectDatabase
I649db9ae679ec2606cf7c530b040f8b6b93eb81a added a default implementation
for getShallowCommits and setShallowCommits to DfsObjDatabase, for the
convenience of any implementers that define subclasses. But we forgot
that some implementers inherit from ObjectDatabase directly instead.
Move the default getter and setter to the base class so that such
callers do not need source changes to unbreak their build.

This also lets us update the api_filters to reflect that this is no
longer an API-breaking change.

Change-Id: I5dcca462eb306e511e57907b7d9264d51b3f3014
2022-08-08 18:30:00 -04:00
Nitzan Gur-Furman 23a71696cd Reapply "Create util class for work tree updating in both filesystem and index."
This reverts commit 5709317f71.

Add a bugfix for deletions in ResolveMergers instantiated with just an
ObjectInserter as argument.

Original change description:

Create util class for work tree updating in both filesystem and index.

This class intends to make future support in index updating easier.

This class currently extracts some logic from ResolveMerger. Logic
related to StreamSupplier was copied from ApplyCommand, which will be
integrated in a following change.

Co-authored-by: Nitzan Gur-Furman <nitzan@google.com>
Co-authored-by: Han-Wen Nienhuys <hanwen@google.com>
Change-Id: Ideaefd51789a382a8b499d1ca7ae0146d032f48b
2022-08-08 18:38:23 +02:00
Jonathan Nieder 5709317f71 Revert "Create util class for work tree updating in both filesystem and index."
This reverts commit 5151b324f4. It is
producing NullPointerExceptions during merges, causing Gerrit's
acceptance tests to fail:

com.google.gerrit.extensions.restapi.RestApiException: Cannot rebase ps
[...]
	at com.google.gerrit.server.api.changes.RevisionApiImpl.rebase(RevisionApiImpl.java:280)
	at com.google.gerrit.acceptance.api.change.ChangeIT.rebaseChangeBase(ChangeIT.java:1584)
Caused by: com.google.gerrit.server.update.UpdateException: java.lang.NullPointerException: repository is required
	at com.google.gerrit.server.update.BatchUpdate.executeUpdateRepo(BatchUpdate.java:588)
[...]
Caused by: java.lang.NullPointerException: repository is required
	at org.eclipse.jgit.merge.Merger.nonNullRepo(Merger.java:128)
	at org.eclipse.jgit.merge.ResolveMerger.addDeletion(ResolveMerger.java:380)
	at org.eclipse.jgit.merge.ResolveMerger.processEntry(ResolveMerger.java:553)
	at org.eclipse.jgit.merge.ResolveMerger.mergeTreeWalk(ResolveMerger.java:1224)
	at org.eclipse.jgit.merge.ResolveMerger.mergeTrees(ResolveMerger.java:1174)
	at org.eclipse.jgit.merge.ResolveMerger.mergeImpl(ResolveMerger.java:299)
	at org.eclipse.jgit.merge.Merger.merge(Merger.java:233)
	at org.eclipse.jgit.merge.Merger.merge(Merger.java:186)
	at org.eclipse.jgit.merge.ThreeWayMerger.merge(ThreeWayMerger.java:96)
	at com.google.gerrit.server.change.RebaseChangeOp.rebaseCommit(RebaseChangeOp.java:360)

Change-Id: Idf63de81666d0df118d2d93c4f6e014e00dc05b8
2022-08-05 18:38:56 -04:00
Ronald Bhuleskar 05a2485075 Provide a default implementation for set/get shallowCommits on DfsObjDatabase
Jgit change https://git.eclipse.org/r/c/jgit/jgit/+/193329 adds an implementation for get/set shallow commits in ObjectDatabase. This failed gerrit's acceptance tests since there is no default implementation for them in DfsObjDatabase.

Change-Id: I649db9ae679ec2606cf7c530b040f8b6b93eb81a
2022-08-05 17:25:54 -04:00
Terry Parker 1c7b4a580f Merge "Revert "Option to pass start RevCommit to be blamed on to the BlameGenerator."" 2022-08-03 18:38:05 -04:00
Terry Parker 7f89b0fa16 Merge "Revert "Adds FilteredRevCommit that can overwrites its parents in the DAG."" 2022-08-03 18:37:57 -04:00
Ronald Bhuleskar e5e46bc536 Revert "Adds FilteredRevCommit that can overwrites its parents in the DAG."
This reverts commit ceb51a5e0e.

Reason for revert: The change in https://git.eclipse.org/r/c/jgit/jgit/+/194354 broke the egit test [1]. Calling c.getShortMessage() causes an NPE.

[1] https://ci.eclipse.org/egit/job/egit.gerrit/2711/

Change-Id: I411565b6eaa0bbb562cc1c8a355942ff09fd29bc
2022-08-03 17:16:34 -04:00
Ronald Bhuleskar 3d2f087932 Revert "Option to pass start RevCommit to be blamed on to the BlameGenerator."
This reverts commit 59e8bec6e7.

Reason for revert: The change in https://git.eclipse.org/r/c/jgit/jgit/+/194354 broke the egit test [1]. Calling c.getShortMessage() causes an NPE.

[1] https://ci.eclipse.org/egit/job/egit.gerrit/2711/

Change-Id: Iaf5feb35f4bb4c3487b04be15d1fe11376975523
2022-08-03 17:14:18 -04:00
Thomas Wolf 8184683f7e CleanCommand: fix prefix matching
String.startsWith() is not a valid test for file path prefixes:
directory "a" is _not_ a prefix of a file "ab", only of "a/b".

Add a proper Paths.isEqualOrPrefix() method and use it in CleanCommand.

Bug: 580478
Change-Id: I6863e6ba94a8ffba6561835cc57044a0945d2770
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-08-03 07:42:27 +02:00
Ronald Bhuleskar 59e8bec6e7 Option to pass start RevCommit to be blamed on to the BlameGenerator.
This can allow passing a FilteredRevCommit which is the filtered list of
commit graph making it easier for Blame to work on. This can
significantly improve blame performance since blame can skip expensive
RevWalk.

Change-Id: I5dab25301d6aef7df6a0bc25a4c553c730199272
2022-08-02 21:02:33 -04:00
Ronald Bhuleskar ceb51a5e0e Adds FilteredRevCommit that can overwrites its parents in the DAG.
Change-Id: I2df9843dde0f589f5fea6cedaaff52e313eea6de
2022-08-02 20:25:58 -04:00
Ronald Bhuleskar 61b4d105e4 Add the ability to override parents on RevCommit.
This makes RevCommit extensible to allow having different structure of
child-parent relationship. This change is a pre-requsite for having a
FilteredRevCommit that overrides parents from the RevCommit. That then
provides a cheaper way to walk over a subset of RevCommits instead of
an expensive way that applies filters while walking over selected
commits. Useful with Blame which works on a single file and that can be
made performant, if we know all the commits needed by the Blame
algorithm. So Blame algorithm can avoid walking over finding what
commits to blame on.

This change makes parents field on RevCommit private and exposes it
thrrough overrideable methods such as getParents, getParent at index,
getParentCount and setParents. All other files other than RevCommit are
updating the usages of accessing RevCommits parents.

Change-Id: I2d13b001c599cc4ebc92d1ab6e07b07acb3b7fe5
2022-08-02 10:50:16 -07:00
Dmitrii Filippov b544da795b Refactor NameConflictTreeWalk.fastMin method
Change-Id: Iac2e6f615463e18ddf788e6ddfe15ef023cac977
2022-08-01 13:31:26 -04:00
Dmitrii Filippov f8e229d569 Rename fastMinHasMatch to allTreesNamesMatchFastMinRef
Change-Id: I2d9165616650e9d44745c6848d2cf1045f53f33c
2022-08-01 13:31:07 -04:00
Han-Wen NIenhuys e030b106c5 Merge "Document TreeWalk#min()" 2022-08-01 13:07:29 -04:00
Han-Wen NIenhuys 688c83d93a Merge "NameConflictTreeWalk: respect git order on multi-tree iteration" 2022-08-01 11:25:10 -04:00
Han-Wen Nienhuys 8a3a6a99af Document TreeWalk#min()
Change-Id: I29a6c023929d8270a8cdd1e7f012817a06428f42
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2022-08-01 17:21:49 +02:00
Han-Wen Nienhuys 3bec0b56a5 Squash error-prone messages
Change-Id: Ibbccc4d1faf1f0a1f0f4136c5bf075f155d80157
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2022-08-01 15:47:20 +02:00
Thomas Wolf eef4da5dac Use constants for git packet protocol line identifiers
Introduce named constants for packet line headers and use them instead
of direct string literals everywhere. This not only makes the code more
readable because we don't need NON-NLS markers, it also makes it more
robust since we can use the length of these constants instead of magic
numbers.

Change-Id: Ie4b7239e0b479a68a2dc23e6e05f25061d481a31
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-07-31 14:08:48 +02:00
Robin Müller 673007d529 ObjectDirectory: improve reading of shallow file
Use FileUtils.readWithRetries().

Change-Id: I5929184caca6b83a1ee87b462e541620bd68aa90
2022-07-31 14:08:48 +02:00
Robin Müller 207dd4c938 Fetch: add support for shallow
This adds support for shallow cloning. The CloneCommand and the
FetchCommand now have the new methods setDepth, setShallowSince and
addShallowExclude to tell the server that the client doesn't want to
download the complete history.

Bug: 475615
Change-Id: Ic80fb6efb5474543ae59be590ebe385bec21cc0d
2022-07-31 14:08:47 +02:00
Dmitrii Filippov 8584ac7048 NameConflictTreeWalk: respect git order on multi-tree iteration
The NameConflictTreeWalk class is used in 3-way merge for iterating over
entries in 3 different commits. The class provides information about a
current entry and a state of the entry in commits (e.g entry is file,
entry is directory, entry is missing). In rare cases, the tree walker
can mix information about entries with different name.

The problem appears, because git uses unusual sorting order for
files. Example (this is a simplified real-life example):
Commit 1:
* gradle.properties - file
* gradle - directory (with nested files)
*   gradle/file - file in gradle directory
Commit 2:
* gradle.properties - file
* no entry with the name gradle
Commit 3:
* gradle.properties - file
* gradle - file
Here the names are ordered like this:
"gradle" file <"gradle.properties" file < "gradle/file" file.

NameConflictTreeWalk iterator already have code for processing
git sorting order, however in the example above the code doesn't
work correctly. Before the fix, NameConflictTreeWalk returns:
#next()
"gradle - directory" | "gradle.properties" | "gradle - file" - which is
wrong. The expected result is
#next()
"gradle - directory | MISSED_FILE | "gradle - file"
#next()
"gradle.properties"|"gradle.properties"|"gradle.properties"

Ensure that the "matches" field of tree iterators (which contains the
current path) is kept in sync in the case above.

Change-Id: Ief5aa06d80b358f4080043c8694aa0fd7c60045b
Signed-off-by: Dmitrii Filippov <dmfilippov@google.com>
2022-07-29 19:35:22 +02:00
Han-Wen NIenhuys 800a4dc20c Merge "Create util class for work tree updating in both filesystem and index." 2022-07-25 09:44:28 -04:00
Nitzan Gur-Furman 5151b324f4 Create util class for work tree updating in both filesystem and index.
This class intends to make future support in index updating easier.

This class currently extracts some logic from ResolveMerger. Logic
related to StreamSupplier was copied from ApplyCommand, which will be
integrated in a following change.

Change-Id: I8dc5a582433fc9891038c628385d3970b5a8984b
2022-07-25 14:29:46 +03:00
Thomas Wolf a1ce9063fb Fix the handling of .git/info/exclude and core.excludesFile
The RootIgnoreNode in a WorkingTreeIterator must _not_ add the rules
from .git/info/exclude or from the file designated by git config
core.excludesFile to the list of rules read from the root .gitignore.
These really must be separate nodes in a hierarchy, otherwise the
precedence rules from [1] are violated and the outcome is not the
same as in C git.

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

Bug: 580381
Change-Id: I57802ba7bbbe4f183504c882b6c77a78cc3a9b99
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-07-15 21:00:16 +02:00
Matthias Sohn f6935d8cd2 Merge branch 'stable-6.2'
* stable-6.2:
  UploadPack: don't prematurely terminate timer in case of error
  Do not create reflog for remote tracking branches during clone
  UploadPack: do not check reachability of visible SHA1s
  Add missing package import javax.management to org.eclipse.jgit

Change-Id: Ia2280b848cea7bdfa5bc48356484e040d159845d
2022-07-06 17:02:58 +02:00
Matthias Sohn 34600e3ca2 Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  UploadPack: don't prematurely terminate timer in case of error
  Do not create reflog for remote tracking branches during clone
  UploadPack: do not check reachability of visible SHA1s
  Add missing package import javax.management to org.eclipse.jgit

Change-Id: Ib3ff6a038e1b92a931a7f2624c19bbefd8cb95fd
2022-07-06 17:02:04 +02:00
Matthias Sohn d01376106a Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  UploadPack: don't prematurely terminate timer in case of error
  Do not create reflog for remote tracking branches during clone
  UploadPack: do not check reachability of visible SHA1s
  Add missing package import javax.management to org.eclipse.jgit

Change-Id: I08734ee2c8f3296d908da6a29d53ed87c4b48eb2
2022-07-06 17:00:42 +02:00
Matthias Sohn 9f7d77b608 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  UploadPack: don't prematurely terminate timer in case of error
  Do not create reflog for remote tracking branches during clone
  UploadPack: do not check reachability of visible SHA1s
  Add missing package import javax.management to org.eclipse.jgit

Change-Id: I6db0a4d74399fde892eeec62efd2946f97547a5d
2022-07-06 16:59:30 +02:00
Simeon Andreev 1a364c49ec JGit blame very slow for large merge commits that rename files
Adjusted BlameGenerator to filter rename detection with the blame path.
This reduces the running time of the blame computation significantly,
for repositories with massive commits involving renames.

The filtered rename detection is made (internally) available with:
org.eclipse.jgit.internal.diff.FilteredRenameDetector

Bug: 578900
Change-Id: I6580004e81102d685081b8180da1587a35073d36
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
2022-07-01 16:10:13 +02:00
Matthias Sohn 035e0e23f2 UploadPack: don't prematurely terminate timer in case of error
In uploadWithExceptionPropagation don't prematurely terminate timer in
case of error to enable reporting it to the client. Expose a close
method so that callers can terminate it at the appropriate time.

If the timer is already terminated when trying to report it to the
client this failed with the error java.lang.IllegalStateException:
"Timer already terminated".

Bug: 579670
Change-Id: I95827442ccb0f9b1ede83630cf7c51cf619c399a
2022-06-30 14:45:31 +02:00
Matthias Sohn ca6b518432 Merge "Do not create reflog for remote tracking branches during clone" into stable-5.13 2022-06-26 15:36:03 -04:00
Luca Milanesio 4bb4693633 Do not create reflog for remote tracking branches during clone
When using JGit on a non-bare repository, the CloneCommand
it previously created local reflogs for all branches including remote
tracking ones, causing the generation of a potentially large
number of files on the local filesystem.

The creation of the remote-tracking branches (refs/remotes/*) during
clone is not an issue for the local filesystem because all of them are
stored in a single packed-refs file. However, the creation of a large
number of ref logs on a local filesystem IS an issue because it
may not be tuned or initialised in term of inodes to contain a very
large number of files.

When a user (or a CI system) performs the CloneCommand against
a potentially large repository (e.g., millions of branches), it is
interested in working or validating a single branch or tag and is
unlikely to work with all the remote-tracking branches.
The eager creation of a reflogs for all the remote-tracking branches is
not just a performance issue but may also compromise the ability to
use JGit for cloning a large repository.

The behaviour implemented in this change is also consistent with the
optimisation done in the C code-base [1].

We differentiate between clone and fetch commands using --branch
<initialBranch> option, that is only available in clone command,
and is set as HEAD per default.

[1] 58f233ce1e

Bug: 579805
Change-Id: I58d0d36a8a4ce42e0f59b8bf063747c4b81bd859
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
2022-06-25 12:09:01 +01:00
Luca Milanesio 66ace4b9af UploadPack: do not check reachability of visible SHA1s
When JGit needs to serve a Git client requesting SHA1s
during the want phase, it needs to make a full reachability
check from the advertised refs to the ones requested to
keep all objects in the correct scope of confidentiality
allowed by the avertised refs.

The check is also performed when the SHA1 corresponds to
one of the tips of the advertised refs which is a waste of
resources.

Example:

fetch> ref-prefix refs/heads/foo
fetch< 900505eb8ce8ced2a1757906da1b25c357b9654e refs/heads/foo
fetch< 0000
fetch> command=fetch
fetch> 0001
fetch> thin-pack
fetch> ofs-delta
fetch> want 900505eb8ce8ced2a1757906da1b25c357b9654e

The SHA1 in the want is the tip of refs/heads/foo and therefore
the full reachability check can be shortened and resolved more
quickly.

Change-Id: I49bd9e2464e0bd3bca2abf14c6e9df550d07383b
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
2022-06-25 06:45:05 -04:00
Thomas Wolf ba93cd36d8 Fix warnings about non-externalized string literals
Four occurrences in RefSpec marked with //$NON-NLS-<n>$.

Change-Id: Ie603a58c41357562f0739445e3fe77ca87a3eb54
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-06-23 20:34:35 +02:00
Simeon Andreev 0c32889ebc Run tests that checks araxis output only on Linux
Bug: 580189
Change-Id: Ieb14f5cf061fcb468b602c7f27e27b672e3b09e2
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
2022-06-17 14:39:48 +02:00
Matthias Sohn f4cbf31ae4 Add missing package import javax.management to org.eclipse.jgit
Class org.eclipse.jgit.util.Monitoring uses JMX hence we need this
import otherwise OSGi applications can face ClassNotFoundException.

Bug: 577018
Change-Id: Ifd75337b87c7faec95d333b771bb0a2f3e46a418
2022-06-17 13:49:59 +02:00
Matthias Sohn f014febe34 Suppress API errors raised for new API introduced in 5.13.1
Change-Id: I55ec887c3192468d7773e8cf0236c7ed48af3ade
2022-06-17 10:24:03 +02:00
David Ostrovsky 87391ccee9 Fix DefaultCharset bug pattern flagged by error prone
See more details in: [1].

[1] https://errorprone.info/bugpattern/DefaultCharset
Change-Id: I3de0be57a2d74490a5b4e66801e9767b38f13bf9
2022-06-17 09:44:14 +02:00