Commit Graph

5820 Commits

Author SHA1 Message Date
Matthias Sohn 07a9eb06ff Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Add pack options to preserve and prune old pack files
  Allow to perform PackedBatchRefUpdate without locking loose refs
  Document option "core.sha1Implementation" introduced in 59029aec

Change-Id: I876a38c2de8b7d5eaacd00e36b85599f88173221
2023-02-16 16:59:09 +01:00
Matthias Sohn c46eb91611 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Add pack options to preserve and prune old pack files
  Allow to perform PackedBatchRefUpdate without locking loose refs
  Document option "core.sha1Implementation" introduced in 59029aec

Change-Id: I423f410578f5bbe178832b80fef8998a5372182c
2023-02-16 16:48:24 +01:00
Prudhvi Akhil Alahari 012cb77930 Fix getPackedRefs to not throw NoSuchFileException
Since Files.newInputStream is from java.nio package, it throws
java.nio.file.NoSuchFileException. This was missed in the change
I00da88e. Without this change, getPackedRefs fails with
NoSuchFileException when there is no packed-refs file in a project.

Change-Id: I93c202ddb73a0a5979af8e4d09e45f5645664b45
Signed-off-by: Prudhvi Akhil Alahari <quic_prudhvi@quicinc.com>
2023-02-16 16:44:12 +05:30
Ivan Frade c9552abaf3 PackObjectSizeIndex: interface and impl for the object-size index
Operations like "clone --filter=blob:limit=N" or the "object-info"
command need to read the size of the objects from the storage. An
index would provide those sizes at once rather than having to seek in
the packfile.

Introduce an interface for the Object-size index. This index returns
the inflated size of an object. Not all objects could be indexed (to
limit memory usage).

This implementation indexes only blobs (no trees, nor
commits) *above* certain size threshold (configurable). Lower
threshold adds more objects to the index, consumes more memory and
provides better performance. 0 means "all blobs" and -1 "disabled".

If we don't index everything, for the filter use case is more
efficient to index the biggest objects first: the set is small and
most objects are filtered by NOT being in the index. For the
object-size, the more objects in the index the better, regardless
their size. All together, it is more helpful to index above threshold.

Change-Id: I9ed608ac240677e199b90ca40d420bcad9231489
2023-02-14 11:50:29 -08:00
Ivan Frade 62d0e7be7c UInt24Array: Array of unsigned ints encoded in 3 bytes.
The object size index stores positions of objects in the main
index (when ordered by sha1). These positions are per-pack and usually
a pack has <16 million objects (there are exceptions but rather
rare). It could save some memory storing these positions in three bytes
instead of four. Note that these positions are sorted and always positive.

Implement a wrapper around a byte[] to access and search "ints" while
they are stored as unsigned 3 bytes.

Change-Id: Iaa26ce8e2272e706e35fe4cdb648fb6ca7591972
2023-02-14 10:19:12 -08:00
Ivan Frade 5b9ca7df42 PackIndex: expose the position of an object-id in the index
The primary index returns the offset in the pack for an
objectId. Internally it keeps the object-ids in lexicographical order,
but doesn't expose an API to find the position of an object-id in that
list. This is needed for the object-size index, that we want to store
as "position-in-idx, size".

Add a #findPosition(object-id) method to the PackIndex interface to
know where an object-id sits in the ordered list of ids in the pack.

Note that this index position is over the list of ordered object-ids,
while reverse-index position is over the list of objects in packed
order.

Change-Id: I89fa146599e347a26d3012d3477d7f5bbbda7ba4
2023-02-14 10:01:29 -08:00
Matthias Sohn 9424052f27 Add pack options to preserve and prune old pack files
Add the options
- pack.preserveOldPacks
- pack.prunePreserved

This allows to configure in git config if old packs should be preserved
during gc and pruned during the next gc.

The original implementation in 91132bb0 only allows to set these options
using the API.

Change-Id: I5b23ab4f317d12f5ccd234401419913e8263cc9a
2023-02-11 01:19:28 +01:00
Xing Huang df5b7959be DfsPackFile/DfsGC: Write commit graphs and expose in pack
JGit knows how to read/write commit graphs but the DFS stack is not
using it yet.

The DFS garbage collector generates a commit-graph with commits
reachable from any ref. The pack is stored as extra stream in the GC
pack. DfsPackFile mimicks how other indices are loaded storing the
reference in DFS cache.

Signed-off-by: Xing Huang <xingkhuang@google.com>
Change-Id: I3f94997377986d21a56b300d8358dd27be37f5de
2023-02-07 16:59:56 -05:00
Xing Huang eccae7cf0b ObjectReader: Allow getCommitGraph to throw IOException
ObjectReader#getCommitGraph doesn't report errors loading the
commit graph. The caller should be aware of the situation and
ultimately decide what to do.

Add IOException to ObjectReader#getCommitGraph signature. RevWalk
defaults to an empty commit-graph on IO errors.

Signed-off-by: Xing Huang <xingkhuang@google.com>
Change-Id: I38eeacff76c7f926b6dfb192d1e5916e40770024
2023-02-07 11:32:12 -05:00
Saša Živkov ed2cbd9e8a Allow to perform PackedBatchRefUpdate without locking loose refs
Add another newBatchUpdate method in the RefDirectory where we can
control if the created PackedBatchRefUpdate will lock the loose refs or
not.

This can be useful in cases when we run programs which have exclusive
access to a Git repository and we know that locking loose refs is
unnecessary and just a performance loss.

Change-Id: I7d0932eb1598a3871a2281b1a049021380234df9
(cherry picked from commit cb90ed0852)
2023-02-03 10:18:47 +01:00
Han-Wen NIenhuys a1fa0ee679 Merge "UploadPack: consume delimiter in object-info command" 2023-02-02 09:09:25 -05:00
Han-Wen NIenhuys f94ab7680c Merge "PatchApplier fix - init cache with provided tree" 2023-02-02 09:00:56 -05:00
Han-Wen Nienhuys 341116103e UploadPack: consume delimiter in object-info command
The 'size' packet line is an argument, so it
must be preceeded by a 0001 delimiter. See also git's
t5701-git-serve.sh test,

https://github.com/git/git/blob/8b8d9a2/t/t5701-git-serve.sh#L329

Without this fix, the server will choke on the delimiter line, saying
PackProtocolException: unexpected <empty string>

To test, I ran Gerrit locally with this fix

$ curl -X POST   -H 'git-protocol: version=2'   -H 'content-type:
application/x-git-upload-pack-request'   -H 'accept:
application/x-git-upload-pack-result'   --data
$'0018command=object-info\n00010009size\n0031oid
d38b1b92bdb2893eb4505667375563f2d6d4086b\n0000'
http://localhost:8080/git.git/git-upload-pack

=>

0008size0032d38b1b92bdb2893eb4505667375563f2d6d4086b 268590000


The same command completes identically on Gitlab (which supports the
object-info command)

$ curl -X POST   -H 'git-protocol: version=2'   -H 'content-type:
application/x-git-upload-pack-request'   -H 'accept:
application/x-git-upload-pack-result'   --data
$'0018command=object-info\n00010009size\n0031oid
d38b1b92bdb2893eb4505667375563f2d6d4086b\n0000'
https://gitlab.com/gitlab-org/git.git/git-upload-pack

=>

0008size0032d38b1b92bdb2893eb4505667375563f2d6d4086b 268590000

In this case, the blob is for the COPYING file in the Git source tree,
which is 26859 bytes long.

Change-Id: Ief4ce1eb9303a3b2479547d7950ef01c7c28f472
2023-02-02 08:47:35 -05:00
Nitzan Gur-Furman a399bd13b1 PatchApplier fix - init cache with provided tree
This change only affects inCore repositories.
Before this change, any file that wasn't part of the patch
wasn't read, and therefore wasn't part of the output tree.

Change-Id: I246ef957088f17aaf367143f7a0b3af0f8264ffb
Bug: Google b/267270348
2023-02-02 12:39:26 +01:00
Ivan Frade 8898d62dbc Merge "DfsReaderIoStats: Add Commit Graph fields into DfsReaderIoStats" 2023-02-01 18:06:56 -05:00
Matthias Sohn 8bd960bf2b Merge changes I343cc3cf,I9dedf61b
* changes:
  Avoid error-prone warning
  Fix unused exception error-prone warning
2023-02-01 16:52:37 -05:00
Han-Wen Nienhuys b30c75be40 Fix unused exception error-prone warning
Ignoring the exception seems intended in this case.

Change-Id: I9dedf61b9cb5a6ff39fb141dd5da19143f4f6978
2023-02-01 10:53:43 +01:00
Han-Wen Nienhuys 97e8b4cc71 UploadPack: advertise object-info command if enabled
Change-Id: Iad8e5b5f4fdd84bd275eb19ee0d01eb6986d79f2
2023-02-01 10:52:33 +01:00
Han-Wen NIenhuys 66b871b777 Merge "Move MemRefDatabase creation in a separate method." 2023-02-01 04:15:44 -05:00
Matthias Sohn 580cb13f21 Merge branch 'stable-6.4'
* stable-6.4:
  Shortcut during git fetch for avoiding looping through all local refs
  FetchCommand: fix fetchSubmodules to work on a Ref to a blob
  Silence API warnings introduced by I466dcde6
  Allow the exclusions of refs prefixes from bitmap
  PackWriterBitmapPreparer: do not include annotated tags in bitmap
  BatchingProgressMonitor: avoid int overflow when computing percentage
  Speedup GC listing objects referenced from reflogs
  FileSnapshotTest: Add more MISSING_FILE coverage

Change-Id: Id0ebfbd85eb815716383b9495eb7dd1f54cf4d74
2023-02-01 01:23:34 +01:00
Matthias Sohn ef010db594 Merge branch 'stable-6.3' into stable-6.4
* stable-6.3:
  Shortcut during git fetch for avoiding looping through all local refs
  FetchCommand: fix fetchSubmodules to work on a Ref to a blob
  Silence API warnings introduced by I466dcde6
  Allow the exclusions of refs prefixes from bitmap
  PackWriterBitmapPreparer: do not include annotated tags in bitmap
  BatchingProgressMonitor: avoid int overflow when computing percentage
  Speedup GC listing objects referenced from reflogs
  FileSnapshotTest: Add more MISSING_FILE coverage

Change-Id: Iefcf5d832bd0087c1027876f2200689e1150abce
2023-02-01 01:12:06 +01:00
Matthias Sohn 82e1362e07 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  Shortcut during git fetch for avoiding looping through all local refs
  FetchCommand: fix fetchSubmodules to work on a Ref to a blob
  Silence API warnings introduced by I466dcde6
  Allow the exclusions of refs prefixes from bitmap
  PackWriterBitmapPreparer: do not include annotated tags in bitmap
  BatchingProgressMonitor: avoid int overflow when computing percentage
  Speedup GC listing objects referenced from reflogs
  FileSnapshotTest: Add more MISSING_FILE coverage

Change-Id: I2ff386d9a096277360e6c7bd5535b49984620fb3
2023-02-01 01:10:56 +01:00
Matthias Sohn d8c02aec6a Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Shortcut during git fetch for avoiding looping through all local refs
  FetchCommand: fix fetchSubmodules to work on a Ref to a blob
  Silence API warnings introduced by I466dcde6
  Allow the exclusions of refs prefixes from bitmap
  PackWriterBitmapPreparer: do not include annotated tags in bitmap
  BatchingProgressMonitor: avoid int overflow when computing percentage
  Speedup GC listing objects referenced from reflogs
  FileSnapshotTest: Add more MISSING_FILE coverage

Change-Id: Iff2fba026b49463016015b2fae1a42cf76ee2dbb
2023-02-01 00:54:30 +01:00
Matthias Sohn b5de5ccb9e Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Shortcut during git fetch for avoiding looping through all local refs
  FetchCommand: fix fetchSubmodules to work on a Ref to a blob
  Silence API warnings introduced by I466dcde6
  Allow the exclusions of refs prefixes from bitmap
  PackWriterBitmapPreparer: do not include annotated tags in bitmap
  BatchingProgressMonitor: avoid int overflow when computing percentage
  Speedup GC listing objects referenced from reflogs
  FileSnapshotTest: Add more MISSING_FILE coverage

Change-Id: Ib5055f2f3b8a313c178d6f6c7c5630285ad5a726
2023-02-01 00:41:52 +01:00
Matthias Sohn da21265a14 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Shortcut during git fetch for avoiding looping through all local refs
  FetchCommand: fix fetchSubmodules to work on a Ref to a blob
  Silence API warnings introduced by I466dcde6
  Allow the exclusions of refs prefixes from bitmap
  PackWriterBitmapPreparer: do not include annotated tags in bitmap
  BatchingProgressMonitor: avoid int overflow when computing percentage
  Speedup GC listing objects referenced from reflogs
  FileSnapshotTest: Add more MISSING_FILE coverage

Change-Id: I58ad4c210a5e7e5a1ba6b22315b04211c8909950
2023-02-01 00:33:20 +01:00
Luca Milanesio 21e902dd7f Shortcut during git fetch for avoiding looping through all local refs
The FetchProcess needs to verify that all the refs received point
to objects that are reachable from the local refs, which could be
very expensive but is needed to avoid missing objects exceptions
because of broken chains.

When the local repository has a lot of refs (e.g. millions) and the
client is fetching a non-commit object (e.g. refs/sequences/changes in
Gerrit) the reachability check on all local refs can be very expensive
compared to the time to fetch the remote ref.

Example for a 2M refs repository:
- fetching a single non-commit object: 50ms
- checking the reachability of local refs: 30s

A ref pointing to a non-commit object doesn't have any parent or
successor objects, hence would never need to have a reachability check
done. Skipping the askForIsComplete() altogether would save the 30s
time spent in an unnecessary phase.

Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Change-Id: I09ac66ded45cede199ba30f9e71cc1055f00941b
2023-02-01 00:07:45 +01:00
Matthias Sohn 7650832002 FetchCommand: fix fetchSubmodules to work on a Ref to a blob
FetchCommand#fetchSubmodules assumed that FETCH_HEAD can always be
parsed as a tree. This isn't true if it refers to a Ref referring to a
BLOB. This is e.g. used in Gerrit for Refs like refs/sequences/changes
which are used to implement sequences stored in git.

Change-Id: I414f5b7d9f2184b2d7d53af1dfcd68cccb725ca4
2023-01-31 23:52:20 +01:00
Luca Milanesio ad977f1572 Allow the exclusions of refs prefixes from bitmap
When running a GC.repack() against a repository with over one
thousands of refs/heads and tens of millions of ObjectIds,
the calculation of all bitmaps associated with all the refs
would result in an unreasonable big file that would take up to
several hours to compute.

Test scenario: repo with 2500 heads / 10M obj Intel Xeon E5-2680 2.5GHz
Before this change: 20 mins
After this change and 2300 heads excluded: 10 mins (90s for bitmap)

Having such a large bitmap file is also slow in the runtime
processing and have negligible or even negative benefits, because
the time lost in reading and decompressing the bitmap in memory
would not be compensated by the time saved by using it.

It is key to preserve the bitmaps for those refs that are mostly
used in clone/fetch and give the ability to exlude some refs
prefixes that are known to be less frequently accessed, even
though they may actually be actively written.

Example: Gerrit sandbox branches may even be actively
used and selected automatically because its commits are very
recent, however, they may bloat the bitmap, making it ineffective.

A mono-repo with tens of thousands of developers may have
a relatively small number of active branches where the
CI/CD jobs are continuously fetching/cloning the code. However,
because Gerrit allows the use of sandbox branches, the
total number of refs/heads may be even tens to hundred
thousands.

Change-Id: I466dcde69fa008e7f7785735c977f6e150e3b644
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
2023-01-31 17:14:09 -05:00
Dmitrii Filippov 0f3a3fde95 Move MemRefDatabase creation in a separate method.
The InMemoryRepository is used in tests (e.g. in gerrit tests) and it
can be useful to create a custom MemRefDatabase for some tests.

Change-Id: I6fbbbfe04400ea1edc988c8788c8eeb06ca8480a
2023-01-31 13:55:25 -05:00
Luca Milanesio e4529cd39c PackWriterBitmapPreparer: do not include annotated tags in bitmap
The annotated tags should be excluded from the bitmap associated
with the heads-only packfile. However, this was not happening
because of the check of exclusion of the peeled object instead
of the objectId to be excluded from the bitmap.

Sample use-case:

refs/heads/main
  ^
  |
 commit1 <-- commit2 <- annotated-tag1 <- tag1
  ^
  |
 commit0

When creating a bitmap for the above commit graph, before this
change all the commits are included (3 bitmaps), which is
incorrect, because all commits reachable from annotated tags
should not be included.

The heads-only bitmap should include only commit0 and commit1
but because PackWriterBitPreparer was checking for the peeled
pointer of tag1 to be excluded (commit2) which was not found in
the list of tags to exclude (annotated-tag1), the commit2 was
included, even if it wasn't reachable only from the head.

Add an additional check for exclusion of the original objectId
for allowing the exclusion of annotated tags and their pointed
commits. Add one specific test associated with an annotated tag
for making sure that this use-case is covered also.

Example repository benchmark for measuring the improvement:
# refs: 400k (2k heads, 88k tags, 310k changes)
# objects: 11M (88k of them are annotate tags)
# packfiles: 2.7G

Before this change:
GC time: 5h
clone --bare time: 7 mins

After this change:
GC time: 20 mins
clone --bare time: 3 mins

Bug: 581267
Signed-off-by: Luca Milanesio <luca.milanesio@gmail.com>
Change-Id: Iff2bfc6587153001837220189a120ead9ac649dc
2023-01-31 14:15:56 +01:00
Matthias Sohn 611412a055 BatchingProgressMonitor: avoid int overflow when computing percentage
When cloning huge repositories I observed percentage of object counts
turning negative. This happened if lastWork * 100 exceeded
Integer.MAX_VALUE.

Change-Id: Ic5f5cf5a911a91338267aace4daba4b873ab3900
2023-01-31 14:15:53 +01:00
Xing Huang 66ad43a6c7 DfsReaderIoStats: Add Commit Graph fields into DfsReaderIoStats
We are adding commit-graph loading to the DFS stack and the stats object doesn't have fields to track that.

This change replicates the stats of the primary index for the commit-graph.

Signed-off-by: Xing Huang <xingkhuang@google.com>
Change-Id: I4a657bed50083c4ae8bc9f059d4943d612ea2d49
2023-01-25 15:29:04 -06:00
Matthias Sohn cd3fc7a299 Speedup GC listing objects referenced from reflogs
GC needs to get a ReflogReader for all existing refs to list all objects
referenced from reflogs. The existing Repository#getReflogReader method
accepts the ref name and then resolves the Ref to create a ReflogReader.
GC calling that for a huge number of Refs one by one is very slow. GC
first gets all Refs in bulk and then calls getReflogReader for each of
them.

Fix this by adding another getReflogReader method to Repository which
accepts a Ref directly.

This speeds up running JGit gc on a mirror clone of the Gerrit
repository from 15:36 min to 1:08 min. The repository used in this test
had 45k refs, 275k commits and 1.2m git objects.

Change-Id: I474897fdc6652923e35d461c065a29f54d9949f4
2023-01-23 17:19:14 +01:00
Matthias Sohn a1901305b2 Merge branch 'stable-6.4'
* stable-6.4:
  Cache trustFolderStat/trustPackedRefsStat value per-instance
  Refresh 'objects' dir and retry if a loose object is not found

Change-Id: Iea8038dfde29ab988501469f86ee829e578a2fe8
2023-01-13 19:33:54 +01:00
Matthias Sohn 14300dd77b Merge branch 'stable-6.3' into stable-6.4
* stable-6.3:
  Cache trustFolderStat/trustPackedRefsStat value per-instance
  Refresh 'objects' dir and retry if a loose object is not found

Change-Id: I1db2b51ae8101f345d08235d4f3dc416bfcb42d5
2023-01-13 19:32:56 +01:00
Matthias Sohn 5bd2832134 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  Cache trustFolderStat/trustPackedRefsStat value per-instance
  Refresh 'objects' dir and retry if a loose object is not found

Change-Id: Ibc9bffab8c9ef9c39384b53c142d99878f7f3f98
2023-01-13 19:32:06 +01:00
Matthias Sohn 9eef6790cf Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Cache trustFolderStat/trustPackedRefsStat value per-instance
  Refresh 'objects' dir and retry if a loose object is not found

Change-Id: I9e876f72f735f58bf02c7862a3d8e657fc46a7b9
2023-01-13 19:31:18 +01:00
Nasser Grainawi 21b2aef0aa Cache trustFolderStat/trustPackedRefsStat value per-instance
Instead of re-reading the config every time the methods using these
values were called, cache the config value at the time of instance
construction. Caching the values improves performance for each of the
method calls. These configs are set based on the filesystem storing the
repository and unlikely to change while an application is running.

Change-Id: I1cae26dad672dd28b766ac532a871671475652df
Signed-off-by: Nasser Grainawi <quic_nasserg@quicinc.com>
2023-01-13 18:45:02 +01:00
Kaushik Lingarkar fed1a54935 Refresh 'objects' dir and retry if a loose object is not found
A new loose object may not be immediately visible on a NFS
client if it was created on another client. Refreshing the
'objects' dir and trying again can help work around the NFS
behavior.

Here's an E2E problem that this change can help fix. Consider
a Gerrit multi-primary setup with repositories based on NFS.
Add a new patch-set to an existing change and then immediately
fetch the new patch-set of that change. If the fetch is handled
by a Gerrit primary different that the one which created the
patch-set, then we sometimes run into a MissingObjectException
that causes the fetch to fail.

Bug: 581317
Change-Id: Iccc6676c68ef13a1e8b2ff52b3eeca790a89a13d
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
2023-01-13 18:44:35 +01:00
kylezhao de7d06775c RevWalk: integrate commit-graph with commit parsing
RevWalk#createCommit() will inspect the commit-graph file to find the
specified object's graph position and then return a new RevCommitCG
instance.

RevCommitGC is a RevCommit with an additional "pointer" (the position)
to the commit-graph, so it can load the headers and metadata from there
instead of the pack. This saves IO access in walks where the body is not
needed (i.e. #isRetainBody is false and #parseBody is not invoked).

RevWalk uses automatically the commit-graph if available, no action
needed from callers. The commit-graph is fetched on first access from
the reader (that internally can keep it loaded and reuse it between
walks).

The startup cost of reading the entire commit graph is small. After
testing, reading a commit-graph with 1 million commits takes less than
50ms. If we use RepositoryCache, it will not be initialized util the
commit-graph is rewritten.

Bug: 574368
Change-Id: I90d0f64af24f3acc3eae6da984eae302d338f5ee
Signed-off-by: kylezhao <kylezhao@tencent.com>
2023-01-10 14:56:33 +08:00
Matthias Sohn 801a56b48a Merge branch 'stable-6.4'
* stable-6.4:
  Introduce core.trustPackedRefsStat config
  Fix documentation for core.trustFolderStat

Change-Id: I93ad0c49b70113134026364c9f647de89d948693
2023-01-06 22:09:55 +01:00
kylezhao 05e5e9907c GC: disable writing commit-graph for shallow repos
In shallow repos, GC writes to the commit-graph that shallow commits
do not have parents. This won't be true after a "git fetch --unshallow"
(and before another GC).

Do not write the commit-graph from shallow clones of a repo. The
commit-graph must have the real metadata of commits and that is not
available in a shallow view of the repo.

Change-Id: Ic9f2358ddaa607c74f4dbf289c9bf2a2f0af9ce0
Signed-off-by: kylezhao <kylezhao@tencent.com>
2023-01-06 13:13:13 -05:00
Matthias Sohn 6a35235d16 Merge branch 'stable-6.3' into stable-6.4
* stable-6.3:
  Introduce core.trustPackedRefsStat config
  Fix documentation for core.trustFolderStat

Change-Id: I18d9fc89c9ac1ef069dcefa7d7f992a28539ccf3
2023-01-05 16:09:58 +01:00
Matthias Sohn e4c2331af6 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  Introduce core.trustPackedRefsStat config
  Fix documentation for core.trustFolderStat

Change-Id: I48b6c095ac62dc859829d6fef45325accbb0a144
2023-01-05 16:05:14 +01:00
Matthias Sohn 62ed46da16 Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Introduce core.trustPackedRefsStat config
  Fix documentation for core.trustFolderStat

Change-Id: Ic78630f74c72624932a384eed52ef79ae1eff3e5
2023-01-05 15:55:19 +01:00
Kaushik Lingarkar 82b5aaf7e3 Introduce core.trustPackedRefsStat config
Currently, we always read packed-refs file when 'trustFolderStat'
is false. Introduce a new config 'trustPackedRefsStat' which takes
precedence over 'trustFolderStat' when reading packed refs. Possible
values for this new config are:

* always: Trust packed-refs file attributes
* after_open: Same as 'always', but refresh the file attributes of
              packed-refs before trusting it
* never: Always read the packed-refs file
* unset: Fallback to 'trustFolderStat' to determine if the file
  attributes of packed-refs can be trusted

Folks whose repositories are on NFS and have traditionally been
setting 'trustFolderStat=false' can now get some performance improvement
with 'trustPackedRefsStat=after_open' as it refreshes the file
attributes of packed-refs (at least on some NFS clients) before
considering it.

For example, consider a repository on NFS with ~500k packed-refs. Here
are some stats which illustrate the improvement with this new config
when reading packed refs on NFS:

trustFolderStat=true trustPackedRefsStat=unset: 0.2ms
trustFolderStat=false trustPackedRefsStat=unset: 155ms
trustFolderStat=false trustPackedRefsStat=after_open: 1.5ms

Change-Id: I00da88e4cceebbcf3475be0fc0011ff65767c111
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
2023-01-05 15:52:36 +01:00
Matthias Sohn 8ef58089a8 RefDatabase: fix javadoc formatting
Change-Id: I547819ac380a0e6a88d05206ff171b69f46a8549
2023-01-04 23:51:30 +01:00
Matthias Sohn ddf1c1ed3c Pull up additionalRefsNames from RefDirectory to RefDatabase
This enables to reuse this constant in all RefDatabase implementations.

Change-Id: I13d8fb780de24f71e005b698965fb5bcdbf3c728
2023-01-04 23:51:30 +01:00
Matthias Sohn 70b436b1b2 Add TernarySearchTree
A ternary search tree is a type of tree where nodes are arranged in a
manner similar to a binary search tree, but with up to three children
rather than the binary tree's limit of two.

Each node of a ternary search tree stores a single character, a
reference to a value object and references to its three children named
equal kid, lo kid and hi kid. The lo kid pointer must point to a node
whose character value is less than the current node. The hi kid pointer
must point to a node whose character is greater than the current
node.[1] The equal kid points to the next character in the word. Each
node in a ternary search tree represents a prefix of the stored strings.
All strings in the middle subtree of a node start with that prefix.

Like other prefix trees, a ternary search tree can be used as an
associative map with the ability for incremental string search. Ternary
search trees are more space efficient compared to standard prefix trees,
at the cost of speed.

They allow efficient prefix search which is important to implement
searching refs by prefix in a RefDatabase.

Searching by prefix returns all keys if the prefix is an empty string.

Bug: 576165
Change-Id: If160df70151a8e1c1bd6716ee4968e4c45b2c7ac
2023-01-04 23:51:23 +01:00
kylezhao 414bfe05ff CommitGraph: teach ObjectReader to get commit-graph
FileRepository's ObjectReader#getCommitGraph will return commit-graph
when it exists and core.commitGraph is true.

DfsRepository is not supported currently.

Change-Id: I992d43d104cf542797e6949470e95e56de025107
Signed-off-by: kylezhao <kylezhao@tencent.com>
2023-01-04 14:50:38 +08:00
Ivan Frade 93ac99b52a Merge "CommitGraph: add commit-graph for FileObjectDatabase" 2023-01-03 14:56:53 -05:00
Thomas Wolf 9a6d602488 PatchApplier: fix handling of last newline in text patch
If the last line came from the patch, use the patch to determine whether
or not there should be a trailing newline. Otherwise use the old text.

Add test cases for
- no newline at end, last line not in patch hunk
- no newline at end, last line in patch hunk
- patch removing the last newline
- patch adding a newline at the end of file not having one

all for core.autocrlf false, true, and input.

Add a test case where the "no newline" indicator line is not the last
line of the last hunk. This can happen if the patch ends with removals
at the file end.

Bug: 581234
Change-Id: I09d079b51479b89400ad300d0662c1dcb50deab6
Also-by: Yuriy Mitrofanov <a2terminator@mail.ru>
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-12-26 11:51:25 +01:00
kylezhao 8a7348df69 CommitGraph: add commit-graph for FileObjectDatabase
This change makes JGit can read .git/objects/info/commit-graph file
and then get CommitGraph.

Loading a new commit-graph into memory requires additional time. After
testing, loading a copy of the Linux's commit-graph(1039139 commits)
is under 50ms.

Bug: 574368
Change-Id: Iadfdd6ed437945d3cdfdbe988cf541198140a8bf
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-12-23 13:06:06 +08:00
Thomas Wolf aeb74f63d4 Reformat PatchApplier and PatchApplierTest
Some lines were too long, unnecessary fully qualified class names,
and an assertEquals(actual, expected) when it should have been
assertEquals(expected, actual).

Change-Id: I3b3c46c963afe2fb82a79c1e93970e73778877e5
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-12-22 23:30:02 +01:00
Anna Papitto 6722f25d56 PackWriter#prepareBitmapIndex: add clarifying comments
New readers of #prepareBitmapIndex may be confused about the manual
memory management (hidden mutation and nulling out pointers).

Add two clarifying comments to help future readers.

Change-Id: I93cab1919066efda37e96c47667f6991f67e377e
2022-12-20 13:56:11 -05:00
Anna Papitto 9b7c3ac11f IO#readFully: provide overload that fills the full array
IO#readFully is often called with the intent to fill the destination
array from beginning to end. The redundant arguments for where to start
and stop filling are opportunities for bugs if specified incorrectly or
if not changed to match a changed array length.

Provide a overloaded method for filling the full destination array.

Change-Id: I964f18f4a061189cce1ca00ff0258669277ff499
Signed-off-by: Anna Papitto <annapapitto@google.com>
2022-12-19 10:26:41 -08:00
Anna Papitto 0d10ebe560 PackReverseIndex#findPosition: fix typo in method name
The package-private findPostion method has a type in it. The typo will
become more widespread when a file-based implementation class is
introduced.

Correct the spelling to findPosition before the file-based
implementation is introduced.

Change-Id: Ib285f5a3f9a333ace1782dae9b5d425505eb962a
Signed-off-by: Anna Papitto <annapapitto@google.com>
2022-12-16 16:48:43 -05:00
kylezhao b082c58e0f GC: Write commit-graph files when gc
If 'core.commitGraph' and 'gc.writeCommitGraph' are both true, then gc
will rewrite the commit-graph file when 'git gc' is run. Defaults to
false while the commit-graph feature matures.

Bug: 574368
Change-Id: Ic94cd69034c524285c938414610f2e152198e06e
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-12-16 11:11:45 -05:00
kylezhao 7016e2ddae CommitGraph: add core.commitGraph config
Change-Id: I3b5e735ebafba09ca18fd83da479c7950fa3ea8d
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-12-16 10:21:09 -05:00
Ivan Frade 6ea36794d1 Merge "Gc#deleteOrphans: avoid dependence on PackExt alphabetical ordering" 2022-12-16 08:20:24 -05:00
kylezhao 7b0f633b67 CommitGraph: implement commit-graph read
Git introduced a new file storing the topology and some metadata of
the commits in the repo (commitGraph). With this data, git can browse
commit history without parsing the pack, speeding up e.g.
reachability checks.

This change teaches JGit to read commit-graph-format file, following
the upstream format([1]).

JGit can read a commit-graph file from a buffered stream, which means
that we can provide this feature for both FileRepository and
DfsRepository.

[1] https://git-scm.com/docs/commit-graph-format/2.21.0

Bug: 574368
Change-Id: Ib5c0d6678cb242870a0f5841bd413ad3885e95f6
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-12-16 06:57:06 -05:00
Anna Papitto 5c6c374ff6 Gc#deleteOrphans: avoid dependence on PackExt alphabetical ordering
Deleting orphan files depends on .pack and .keep being reverse-sorted
to before the corresponding index files that could be orphans. The new
reverse index file extension (.rev) will break that frail dependency.

Rewrite Gc#deleteOrphans to avoid that dependence by tracking which pack
names have a .pack or .keep file and then deleting any index files that
without a corresponding one. This approach takes linear time instead of
the O(n logn) time needed for sorting.

Change-Id: If83c378ea070b8871d4b01ae008e7bf8270de763
Signed-off-by: Anna Papitto <annapapitto@google.com>
2022-12-15 11:54:11 -08:00
Jeremy T. Braun 514ebfdc7e WalkPushConnection: Sanitize paths given to transports
These paths are given to the underlying URI-based transports (s3, sftp,
http), all of which expect forward-slash as the path separator
character.

Change-Id: I3cbb5928c9531a4da4691411bd8ac248fdf47ef2
2022-12-15 12:53:19 -05:00
Matthias Sohn 61f4a036c6 Merge changes Iad832fe1,Icef9658c
* changes:
  CommitGraphWriter: fix UnusedException errorprone error
  Update jetty to 10.0.13
2022-12-14 04:50:54 -05:00
Ivan Frade 91587aebd0 GraphCommits: Remove unused getter by position
CommitGraphWriter uses the GraphCommits in for-each loops and doesn't
need the access by position anymore. This was a left-over from
https://git.eclipse.org/r/c/jgit/jgit/+/182832

Remove the unused method.

Change-Id: I39df9bfab2601d581705ddf4cea3c04ed4765ff9
2022-12-13 14:37:37 -08:00
Matthias Sohn 04245494bb CommitGraphWriter: fix UnusedException errorprone error
Errorprone run in the bazel build raised this exception:

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/CommitGraphWriter.java:105:
error: [UnusedException] This catch block catches an exception and
re-throws another, but swallows the caught exception rather than setting
it as a cause. This can make debugging harder.
		} catch (InterruptedIOException e) {
		  ^
    (see https://errorprone.info/bugpattern/UnusedException)
  Did you mean 'throw new
IOException(JGitText.get().commitGraphWritingCancelled, e);'?

Change-Id: Iad832fe17955fc1e60e6a4902bc50fd9dca76b9d
2022-12-13 15:04:45 +01:00
Xing Huang 3a136d2000 PackExt: Add a commit graph extension.
There is no commit graph PackExt because the non-DFS stack is not writing using PackExt mechanism. The extension is needed in DFS to determine the stream to write the commit-graph.

Add a commit graph extension that matches the one in cgit
(https://git-scm.com/docs/commit-graph#_file_layout)
in preparation for adding DFS support for reading and writing commit graphs.

Change-Id: Id14eda9f116a319124981e0bcbc533928b1b5e8c
Signed-off-by: Xing Huang <xingkhuang@google.com>
2022-12-12 17:26:12 -05:00
Matthias Sohn e74f3855ad Merge "commitgraph package: fix exports/imports, add @since tag for new API" 2022-12-08 14:10:23 -05:00
Sergey ec7c61eac3 BatchRefUpdate: Consistent switch branches in ref update
The expression RefUpdate ru = newUpdate(cmd) is eagerly evaluated before the switch statement.
But it is not used in some switch cases and thus is calculated uselessly.

Move expression evaluation to the switch case where it is actually used.
After such a move, several cases became identical and thus were squashed.

Change-Id: Ifd1976f1c28378e092fb24d7ca9c415cba49f07f
2022-12-08 05:27:35 -05:00
Sergey 2b21d9bbb6 RefWriter#writePackedRefs: Remove a redundant "if" check
After checking the variable, the same variable was checked again inside
the "if" block, and after the first check, this variable does not
change. Remove the second unnecessary check.

Change-Id: I6a38e67073f7f93105575b8f415ad32d350af602
2022-12-08 10:59:58 +01:00
Matthias Sohn ebc1f7d65c commitgraph package: fix exports/imports, add @since tag for new API
Change-Id: I9175b1d796f91f5ba4e21d3418550ae451c054b0
2022-12-08 02:00:58 +01:00
kylezhao cf70e7cbe4 CommitGraph: implement commit-graph writer
Teach JGit to write a commit-graph formatted file by walking commit
graph from specified commit objects.

See: https://git-scm.com/docs/commit-graph-format/2.21.0

Bug: 574368
Change-Id: I34f9f28f8729080c275f86215ebf30b2d05af41d
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-12-06 20:34:46 +08:00
Dmitrii Filippov cb9f058f9b Fix crashes on rare combination of file names
The NameConflictTreeWalk class is used in merge for iterating over
entries in commits. The class uses a separate iterator for each
commit's tree. In rare cases it can incorrectly report the same entry
twice. As a result, duplicated entries are added to the merge result
and later jgit throws an exception when it tries to process merge
result.

The problem appears only when there is a directory-file conflict for
the last item in trees. Example from the bug:
Commit 1:
* subtree - file
* subtree-0 - file
Commit 2:
* subtree - directory
* subtree-0 - file
Here the names are ordered like this:
"subtree" file <"subtree-0" file < "subtree" directory.

The NameConflictTreeWalk handles similar cases correctly if there are
other files after subtree... in commits - this is processed in the
AbstractTreeIterator.min function. Existing code has a special
optimization for the case, when all trees are pointed to the same
entry name - it skips additional checks. However, this optimization
incorrectly skips checks if one of trees reached the end.

The fix processes a situation when some trees reached the end, while
others are still point to an entry.

bug: 535919
Change-Id: I62fde3dd89779fac282479c093400448b4ac5c86
2022-11-29 10:49:27 +01:00
Han-Wen NIenhuys 1d5a6c77a6 Merge "Fix crashes on rare combination of file names" 2022-11-28 09:34:46 -05:00
alerthak c14e6f5c6c [pgm] Add options --name-only, --name-status to diff, log, show
Change-Id: Ib218bd2ccbd7990feca4c35d8c8dc34d4a8291e6
2022-11-23 16:12:54 +01:00
Matthias Sohn 9fc9ae6de9 Fix warning about non-externalized String
Change-Id: I00b2132eac6d6ad2701d3f8151eb8c80ad6d679d
2022-11-20 20:30:45 +01:00
Matthias Sohn fe3908076e Merge branch 'stable-6.3'
* stable-6.3:
  Remove unused imports
  Suppress non-externalized String warnings
  Remove unused API problem filters
  Silence API errors
  Silence API errors
  Silence API warnings

Change-Id: I6778c8266bc7e918c943dcabf23aa230f4e998d5
2022-11-20 20:24:14 +01:00
Matthias Sohn 246981c850 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  Remove unused imports
  Suppress non-externalized String warnings
  Remove unused API problem filters
  Silence API errors
  Silence API errors
  Silence API warnings

Change-Id: I71aa9f890c5eb05849ad16a00b9974da5e51171e
2022-11-20 20:22:24 +01:00
Matthias Sohn 3301032c6a Suppress non-externalized String warnings
Change-Id: I95c61bd906bd3f7cdea9581e0ffa92ec607c6140
2022-11-20 20:16:28 +01:00
Matthias Sohn 71f50e52af Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Silence API errors
  Silence API errors
  Silence API warnings

Change-Id: Id3efa1b32710661cde63e93c5b8832785a805415
2022-11-20 20:10:37 +01:00
Matthias Sohn 97ad9bdae6 Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Silence API errors
  Silence API warnings

Change-Id: I2b8336652e60dec97666582cf9331c8505729473
2022-11-20 20:08:42 +01:00
Matthias Sohn 41b33a16b8 Silence API errors
Change-Id: Ie112b2099ea2125bc85863524e56f09ba4907373
2022-11-20 19:55:22 +01:00
Matthias Sohn 12f48276bd Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Silence API warnings

Change-Id: If5ab988a0e177c37b125e0b10625e506eeb2a74f
2022-11-20 19:54:44 +01:00
Matthias Sohn aa9f736c33 Silence API warnings
introduced by
- addition of configurable SHA1 implementation in 5.13.2
- 3-digit @since 5.9.1 annotations on GitServlet methods

Change-Id: If19853fcc5e3677e5b18e8e3fbbcd2773378dffc
2022-11-20 19:45:54 +01:00
Anna Papitto bd515f1c2a DfsBlockCache: Report IndexEventConsumer metrics for reverse indexes.
IndexEventConsumer metrics are reported per index PackExt and reverse
indexes did not have one, so they were not included.

Now that there is a REVERSE_INDEX PackExt, enable reporting
IndexEventConsumer metrics for reverse indexes.

Change-Id: Ia6a752f6eb8932a5b4ba45cc15cbc7e0786fd247
Signed-off-by: Anna Papitto <annapapitto@google.com>
2022-11-17 12:38:48 -05:00
Anna Papitto accacc27a1 DfsStreamKey: Replace ForReverseIndex to separate metrics.
Keys used for identifying reverse indexes in the DfsBlockCache use a
custom subclass ForReverseIndex because there was no PackExt for them.
This conflates BlockCacheMetrics for reverse indexes with those for
packs, since the key falls back onto 0 when there is no extension.

Replace the custom ForReverseIndex with a DfsStreamKey usage to bring
keys for the new REVERSE_INDEX extension in line with INDEX and BITMAP
and separate reverse index and pack BlockCacheMetrics.

Change-Id: I305e2c16d2a8cb2a824855ea92e0c9a9b188fce5
Signed-off-by: Anna Papitto <annapapitto@google.com>
2022-11-17 12:38:36 -05:00
Ivan Frade 5c033a98f6 Merge "PackExt: Add a reverse index extension." 2022-11-17 12:38:10 -05:00
Thomas Wolf 1c886d92f6 RawText.isBinary(): handle complete buffer correctly
Make sure we always get consistent results, whether or not we have the
full data in the buffer.

Change-Id: Ieb379a0c375ad3dd352e63ac2f23bda6ef16c215
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-11-16 15:17:19 -05:00
Matthias Sohn 0fb9d26eff Merge branch 'stable-6.3'
* stable-6.3:
  [benchmarks] Remove profiler configuration
  Add SHA1 benchmark
  [benchmarks] Set version of maven-compiler-plugin to 3.8.1
  Fix running JMH benchmarks
  Add option to allow using JDK's SHA1 implementation
  Fix API breakage caused by extracting WorkTreeUpdater
  Extract Exception -> HTTP status code mapping for reuse
  Don't handle internal git errors as an HTTP error
  Ignore IllegalStateException if JVM is already shutting down
  Allow to perform PackedBatchRefUpdate without locking loose refs

Change-Id: Ib58879be292c54a2a7f4936ac0986997985c822b
2022-11-16 10:15:30 +01:00
Matthias Sohn 1cd9a1f804 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  Extract Exception -> HTTP status code mapping for reuse
  Don't handle internal git errors as an HTTP error
  Allow to perform PackedBatchRefUpdate without locking loose refs

Change-Id: I562be0802efa231023c5f10e6461339b2d7fbacf
2022-11-16 10:14:13 +01:00
Matthias Sohn a24b22632f Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Extract Exception -> HTTP status code mapping for reuse
  Don't handle internal git errors as an HTTP error
  Allow to perform PackedBatchRefUpdate without locking loose refs

Change-Id: Icb321779184d20f3871e236fda1a3acba605a6da
2022-11-16 10:13:20 +01:00
Matthias Sohn 77e2f4bd27 Merge "Merge branch 'stable-6.0' into stable-6.1" into stable-6.1 2022-11-16 04:10:43 -05:00
Matthias Sohn f3e0e9d5a3 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  [benchmarks] Remove profiler configuration
  Add SHA1 benchmark
  [benchmarks] Set version of maven-compiler-plugin to 3.8.1
  Fix running JMH benchmarks
  Add option to allow using JDK's SHA1 implementation
  Ignore IllegalStateException if JVM is already shutting down

Change-Id: I9c1576011c11b4ff8f453d18d9e786cee59860fa
2022-11-16 09:56:08 +01:00
Matthias Sohn d588c2c9ad Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  [benchmarks] Remove profiler configuration
  Add SHA1 benchmark
  [benchmarks] Set version of maven-compiler-plugin to 3.8.1
  Fix running JMH benchmarks
  Add option to allow using JDK's SHA1 implementation
  Ignore IllegalStateException if JVM is already shutting down

Change-Id: Ie433c46a01a0f33848d54ecf99b30a44ca01e286
2022-11-16 09:55:22 +01:00
Matthias Sohn 7f36943d0c Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  [benchmarks] Remove profiler configuration
  Add SHA1 benchmark
  [benchmarks] Set version of maven-compiler-plugin to 3.8.1
  Fix running JMH benchmarks
  Add option to allow using JDK's SHA1 implementation
  Ignore IllegalStateException if JVM is already shutting down

Change-Id: I176419026c3f4fdd8ebd34c61468c1ec3482ff45
2022-11-16 09:54:28 +01:00
Anna Papitto ed99797970 PackExt: Add a reverse index extension.
There is no reverse index PackExt because the reverse index is not currently
written to a file. This prevents fine-grained performance reporting for reverse
indexes, which will be useful when introducing a reverse index file and
observing performance changes.

Add a reverse index extension that matches the one in cgit
(9bf691b78c/Documentation/gitformat-pack.txt (L302))
in preparation for adding a reverse index file while observing
performance before and after.

Change-Id: Iee53f1e01cf645a3c468892fcf97c8444f9a784a
Signed-off-by: Anna Papitto <annapapitto@google.com>
2022-11-15 15:30:50 -08:00
Matthias Sohn f1909615d3 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  [benchmarks] Remove profiler configuration
  Add SHA1 benchmark
  [benchmarks] Set version of maven-compiler-plugin to 3.8.1
  Fix running JMH benchmarks
  Add option to allow using JDK's SHA1 implementation
  Ignore IllegalStateException if JVM is already shutting down

Change-Id: I40105336f0b9e593a8a2c242a9557f854c274fdc
2022-11-16 00:15:17 +01:00
Matthias Sohn 59029aec30 Add option to allow using JDK's SHA1 implementation
The change If6da9833 moved the computation of SHA1 from the JVM's
JCE to a pure Java implementation with collision detection.
The extra security for public sites comes with a cost of slower
SHA1 processing compared to the native implementation in the JDK.

When JGit is used internally and not exposed to any traffic from
external or untrusted users, the extra cost of the pure Java SHA1
implementation can be avoided, falling back to the previous
native MessageDigest implementation.

Bug: 580310
Change-Id: Ic24c0ba1cb0fb6282b8ca3025ffbffa84035565e
2022-11-15 23:08:13 +01:00
Matthias Sohn 4d9e004f57 Fix API breakage caused by extracting WorkTreeUpdater
448052dc2e made WorkTreeUpdater package visible which breaks API for
subclasses of ResolveMerger since they cannot access WorkTreeUpdater.

Fix this by moving WorkTreeUpdater into ResolveMerger as a nested class
and mark it protected so that subclasses can use it.

Bug: 581049
Change-Id: I5a2c4953f8514dc0a1b8041c8e069d28370bb2eb
2022-11-15 15:18:38 +01:00
Eryk Szymanski bd2aced4a3 Use replace instead of replaceAll in toCleanString
This is from SonarLint (rule.java:S4348)
Regex patterns should not be created needlessly:

When String::replaceAll is used, the first argument should be a real
regular expression. If it’s not the case, String::replace does exactly
the same thing as String::replaceAll without the performance drawback of
the regex.

Change-Id: I00ba967ff4a27eeeb6fccf9373f6df2c94ecd823
2022-11-10 20:08:25 +01:00
Dmitrii Filippov 1e04046a6d Fix crashes on rare combination of file names
The NameConflictTreeWalk class is used in merge for iterating over
entries in commits. The class uses a separate iterator for each
commit's tree. In rare cases it can incorrectly report the same entry
twice. As a result, duplicated entries are added to the merge result
and later jgit throws an exception when it tries to process merge
result.

The problem appears only when there is a directory-file conflict for
the last item in trees. Example from the bug:
Commit 1:
* subtree - file
* subtree-0 - file
Commit 2:
* subtree - directory
* subtree-0 - file
Here the names are ordered like this:
"subtree" file <"subtree-0" file < "subtree" directory.

The NameConflictTreeWalk handles similar cases correctly if there are
other files after subtree... in commits - this is processed in the
AbstractTreeIterator.min function. Existing code has a special
optimization for the case, when all trees are pointed to the same
entry name - it skips additional checks. However, this optimization
incorrectly skips checks if one of trees reached the end.

The fix processes a situation when some trees reached the end, while
others are still point to an entry.

bug: 535919
Change-Id: I62fde3dd89779fac282479c093400448b4ac5c86
2022-11-03 14:09:56 -04:00
Josh Brown fe9aeb02e6 UploadPack: Receive and parse client session-id
Before this change JGit did not support the session-id capability
implemented by native Git in UploadPack. This change implements
advertising the capability from the server and parsing the session-id
received from the client during an UploadPack operation.

Enable the transfer.advertisesid config setting to advertise the
capability from the server. The client may send a session-id capability
in response. If received, the value from this is parsed and available
via the getClientSID method on the UploadPack object.

This change does not add the capability to send a session-id from the
JGit client.

https://git-scm.com/docs/gitprotocol-capabilities#_session_idsession_id

Change-Id: Ib1b6929ff1b3a4528e767925b5e5c44b5d18182f
Signed-off-by: Josh Brown <sjoshbrown@google.com>
2022-11-02 16:13:22 -04:00
Josh Brown 7b0a71a5e9 TransferConfig: Move reading advertisesid setting into TransferConfig
The config setting to enable advertising the session-id capability is
currently read in the ReceivePack class. This change moves it to a
common location in the TransferConfig class so that it can be reused
in other places like UploadPack. TransferConfig is also a more logical
place for the setting as it resides in the `transfer` config section.

Set the transfer.advertisesid setting to true to send the session-id
capability to the client.

Change-Id: If68ecb5e68b59f5c452a7992d02e3688b0a86747
Signed-off-by: Josh Brown <sjoshbrown@google.com>
2022-11-02 16:13:08 -04:00
Josh Brown e8068188f1 FirstWant: Parse client session-id if received.
In protocol V0 the client capabilities are appended to the first line.
Parsing session-id is currently only supported during a ReceivePack
operation. This change will parse the client session-id capability if
it has been sent by the client.

If the server sends the session-id capability to the client. The client
may respond with a session ID of its own. FirstWant.fromLine will now
parse the ID and make it available via the getClientSID method.

This change does not add support to send the session-id capability from
the server. The change is necessary to support session-id in UploadPack.

Change-Id: Id3fe44fdf9a72984ee3de9cf40cc4e71d434df4a
Signed-off-by: Josh Brown <sjoshbrown@google.com>
2022-11-02 20:12:03 +00:00
Josh Brown 93097f0018 ReceivePack: Receive and parse client session-id.
Before this change JGit did not support the session-id capability
implemented by native Git. This change implements advertising the
capability from the server and parsing the session-id received from
the client during a ReceivePack operation.

Enable the transfer.advertisesid config setting to advertise the
capability from the server. The client may send a session-id capability
in response. If received, the value from this is parsed and available
via the getClientSID method on the ReceivePack object. All capabilities
in the form `capability=value` are now split into key value pairs at the
first `=` character. This change replaces specific handling for the 
agent capability.

This change does not add advertisement or parsing to UploadPack. This
change also does not add the ability to send a session ID from the JGit
client.

https://git-scm.com/docs/protocol-v2/2.33.0#_session_idsession_id

Change-Id: I56fb115e843b11b27e128c4ac427b05d5ec129d0
Signed-off-by: Josh Brown <sjoshbrown@google.com>
2022-10-27 16:17:50 -04:00
Matthias Sohn 924491d4df Ignore IllegalStateException if JVM is already shutting down
Trying to register/unregister a shutdown hook when the JVM is already in
shutdown throws an IllegalStateException. Ignore this exception since we
can't do anything about it.

Bug: 580953
Change-Id: I8fc6fdd5585837c81ad0ebd6944430856556d90e
2022-10-27 20:31:58 +02:00
Saša Živkov cb90ed0852 Allow to perform PackedBatchRefUpdate without locking loose refs
Add another newBatchUpdate method in the RefDirectory where we can
control if the created PackedBatchRefUpdate will lock the loose refs or
not.

This can be useful in cases when we run programs which have exclusive
access to a Git repository and we know that locking loose refs is
unnecessary and just a performance loss.

Change-Id: I7d0932eb1598a3871a2281b1a049021380234df9
2022-10-26 16:51:08 +02:00
kylezhao ad9c217f49 PushCommand: allow users to disable use of bitmaps for push
Reachability bitmaps are designed to speed up the "counting objects"
phase of generating a pack during a clone or fetch. They are not
optimized for Git clients sending a small topic branch via "git push".
In some cases (see [1]), using reachability bitmaps during "git push"
can cause significant performance regressions.

Add PushCommand#setUseBitmaps(boolean) to allow users to tell "git push"
not to use bitmaps.

[1]: https://lore.kernel.org/git/87zhoz8b9o.fsf@evledraar.gmail.com/

Change-Id: I7fb7d26084ec63ddfa7249cf58abb85929b30e56
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-10-21 08:11:33 +02:00
Thomas Wolf 71af0d6a5c I/O redirection for the pre-push hook
Fix and complete the implementation of calling the pre-push hook.
Add the missing error stream redirect, and add the missing setters
in Transport and in PushCommand. In Transport, delay setting up a
PrePushHook such that it happens only on a push. Previously, the
hook was set up also for fetches.

Bug: 549246
Change-Id: I64a576dfc6b139426f05d9ea6654027ab805734e
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-10-20 23:34:56 +02:00
Ivan Frade 96236fdcb5 PackParser: populate full size of the PackedObjectInfos
We need the full size of the objects to populate the object-size index
of a pack. This size is not always the one encoded in the object header
in the pack (e.g. for deltas).

Populate the full size of PackedObjectInfos in the PackParser, which is
invoked when receiving a pack e.g. in a push.

Change-Id: I102c20901aefb5e85047e2e526c0d733f82ff74b
2022-10-18 11:19:21 -07:00
Ivan Frade 60206ea95f PackedObjectInfo: add the full size to the description
So we can create a size index later.

Change-Id: I9db47ced929fbf045fc37bead6449bbf5484d308
2022-10-18 11:19:21 -07:00
Ivan Frade b58ea5c6c9 ObjectReader: New #isNotLargerThan method
Partial clones filter the objects to send by size calling
ObjectReader#getObjectSize per object. This method reads the object from
storage to get the size, which can be expensive.

Offer a #isNotLargerThan method. The default implementation reads the
object, but subclasses can override it with more efficient lookups (e.g.
adding an index).

isNotLargerThan gives implementors more options to optimize than
getObjectIndex (e.g. can be implemented storing only object over certain
size).

Change-Id: Iefd4b1370cb9144f15cc0391286aeeb365e6ea87
2022-10-18 11:18:46 -07:00
Jörg Kubitz 2021ce3423 ObjectDirectory: avoid using File.getCanonicalPath()
On java 17 + Windows OS java.io.File.getCanonicalPath is a very slow
system call which uses most time during clone.

That is since JDK 12 the result of File.getCanonicalPath is not cached
anymore by default:
https://bugs.openjdk.java.net/browse/JDK-8207005

* Use toRealPath() to follow symbolic links also on windows.
* Cache the result.

Bug: 580568
Change-Id: I95f4f5b2babefd7210ee4740646230225ebf3788
2022-09-22 10:48:50 +02:00
Jörg Kubitz eb5124c74f AutoCRLFOutputStream: use BufferedOutputStream
This should improve performance of autocrlf checkout.

Bug: 580651
Change-Id: I2e2fe0273ac3c71fad50a575278234804ee28306
2022-09-20 10:00:17 +02:00
Thomas Wolf f71fcbf36b CloneCommand: set HEAD also when not checking out
CloneCommand, when setNoCheckout(true) was set, did not set HEAD.
With C git, "git clone --no-checkout" does.

Change-Id: Ief3df7e904ce90829a6345a6c3e9ee6a68486ab0
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-09-18 19:43:40 +02:00
Thomas Wolf 4f4204914c Pass on shallowSince only if not null
FetchCommand.setShallowSince() and Transport.setDeepenSince() require
a non-null argument.

Change-Id: I1c3a20be518374e380a4e90787ed834438da40ee
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-09-18 19:32:31 +02:00
Thomas Wolf ccad49a28c Fix wrong @since tag
PatchApplier was merged only in JGit 6.4.

Change-Id: Ica84d8184c1d3a1acce8beba9b076f6c32e749d7
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-09-18 17:02:51 +02:00
Han-Wen NIenhuys 21a497843c Merge "Split out ApplyCommand logic to PatchApplier class" 2022-09-15 04:16:48 -04:00
Nitzan Gur-Furman acde6c8f5b Split out ApplyCommand logic to PatchApplier class
PatchApplier now routes updates through the index. This has two
results:

* we can now execute patches in-memory.

* the JGit apply command will now always update the
index to match the working tree.

Change-Id: Id60a88232f05d0367787d038d2518c670cdb543f
Co-authored-by: Han-Wen Nienhuys <hanwen@google.com>
Co-authored-by: Nitzan Gur-Furman <nitzan@google.com>
2022-09-15 09:15:55 +02:00
kylezhao ac3bf7896e Fix typo in FetchV2Request javadoc
Change-Id: I905dda15e1b7f5e431816d3fbb01a1672e5fc786
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-09-14 15:49:39 +08:00
Thomas Wolf a8e683fef6 [merge] Fix merge conflicts with symlinks
Previous code would do a content merge on symlinks, and write the merge
result to the working tree as a file. C git doesn't do this; it leaves
a symlink in the working tree unchanged, or in a delete-modify conflict
it would check out "theirs".

Moreover, previous code would write the merge result to the link target,
not to the link. This would overwrite an existing link target, or fail
if the link pointed to a directory.

In link/file conflicts or file/link conflicts, C git always puts the
file into the working tree.

Change conflict handling accordingly. Add tests for all the conflict
cases.

Bug: 580347
Change-Id: I3cffcb4bcf8e336a85186031fff23f0c4b6ee19d
Signed-off-by: Thomas Wolf <twolf@apache.org>
2022-09-07 15:02:02 +02:00
Matthias Sohn 370d1170e8 Merge branch 'master' into stable-6.3
* master:
  Move WorkTreeUpdater to merge package
  WorkTreeUpdater: use DirCacheCheckout#StreamSupplier
  DirCacheCheckout#getContent: also take InputStream supplier
  WorkTreeUpdater: remove safeWrite option

Change-Id: I8be570dbc4ad0d0b46046b85cbda24c3adcba170
2022-09-06 15:58:47 +02:00
Matthias Sohn 57087e2b92 Merge changes I888f313f,I98de155c,I2efa9a6d,Ifa79dac2
* changes:
  Move WorkTreeUpdater to merge package
  WorkTreeUpdater: use DirCacheCheckout#StreamSupplier
  DirCacheCheckout#getContent: also take InputStream supplier
  WorkTreeUpdater: remove safeWrite option
2022-09-06 09:42:14 -04:00
Han-Wen Nienhuys 448052dc2e Move WorkTreeUpdater to merge package
This avoids making it public with the associated costs for backward
compatibility guarantees.

Change-Id: I888f313f3854deace8d4cd92f354a6ef0d3b5460
2022-09-06 14:48:13 +02:00
Han-Wen Nienhuys 6ed4c074ca WorkTreeUpdater: use DirCacheCheckout#StreamSupplier
This avoids having to introduce the StreamLoader bridging class.

Change-Id: I98de155c458745236df24d6323eabed5061e7f8c
2022-09-06 14:48:13 +02:00
Han-Wen Nienhuys 6d2bcb6043 DirCacheCheckout#getContent: also take InputStream supplier
This lets us use DirCacheCheckout for routines that want to write
files in the worktree that aren't available as a git object.

DirCacheCheckout#getContent takes a InputStream supplier rather than
InputStream: if filtering fails with IOException, the data is placed
unfiltered in the checkout. This means that the stream has to be read
again, from the start.

Use it in this way in ApplyCommand. This use is incorrect, though: the
same InputStream is returned twice, so if the read to be retried, the
stream will return 0 bytes. It doesn't really matter, because in
either case, the SHA1 will not match up, and the patch fails.

Change-Id: I2efa9a6da06806ff79b155032fe4b34be8fec09e
2022-09-06 14:38:41 +02:00
Matthias Sohn 7c4a5421cc Revert "Adds FilteredRevCommit that can overwrites its parents in the
DAG."

This reverts commit 6297491e8a.

This is done as a quick fix for the failure of egit tests caused by  the
introduction of FilteredRevCommit.

Bug: 580690
Change-Id: Ia6b651dd11b0a4b02d5e52247eb4bf13adf94e27
2022-09-06 10:40:26 +02:00
Matthias Sohn ee6334bccf Revert "Option to pass start RevCommit to be blamed on to the
BlameGenerator."

This reverts commit 5747bba48b.

This is done as a quick fix for the failure of egit tests caused by  the
introduction of FilteredRevCommit.

Bug: 580690
Change-Id: Ia0178bc2de4fc825a81207bbd7979bf3a386c955
2022-09-06 10:40:26 +02:00
Han-Wen Nienhuys 2778bb2cc9 WorkTreeUpdater: remove safeWrite option
This was added in Ideaefd5178 to anticipate on writing files for
ApplyCommand, but we are keeping WorkTreeUpdater private to the merge
package for now.

Change-Id: Ifa79dac245e60eb7a77eaea4cc1249222e347d38
2022-09-06 10:01:44 +02:00
Ivan Frade ca166a0c62 BaseSuperprojectWriter: report invalid paths as manifest errors
An invalid path in the manifest (e.g. '.') is reported by DirCache in a
runtime exception. In server context this becomes a 500 instead of a user error.

Wrap the runtime invalid path exception into a checked ManifestErrorException that
caller can handle.

Change-Id: I61a2104922765506ae232334891057bb06141d97
2022-08-23 12:10:27 -07:00
Han-Wen Nienhuys 25aceffdc5 ApplyCommand: fix ApplyResult#updatedFiles
On executing a copy, mark the destination as updated.

On executing a rename, mark both source and destination as updated.

Change-Id: Ied5b9b0e5a14eac59a06cdd0961e25e143f50ff0
2022-08-23 09:23:23 -04:00
Han-Wen Nienhuys 0887111ba5 WorkTreeUpdater: rename metadata maps
Change-Id: I8ff3803da8fc13377d11c2dc5523e9e32d0650cb
2022-08-23 05:13:43 -04:00
Han-Wen Nienhuys ddb1a0c3a2 WorkTreeUpdater#Result: hide data members
This is the standard across JGit.

Change-Id: Ie52ad7000d8725657b33dd4f3adcc05ab9666875
2022-08-23 04:24:37 -04:00
Han-Wen NIenhuys d718127a7e Merge "WorkTreeUpdater: re-format and clean-up" 2022-08-18 11:22:46 -04:00
Ronald Bhuleskar 1a2aa740c8 Add javadoc on RevCommit
Change-Id: Ib413154fe52983286cb6307862a7373af4fec6e8
2022-08-17 19:16:45 -04:00
Ronald Bhuleskar 5747bba48b 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: Ie127cb710d004079e9f53a5802130afdb49a7de1
2022-08-17 13:50:34 -04:00
Thomas Wolf aaae9ecd57 WorkTreeUpdater: re-format and clean-up
Reformat using the standard JGit formatter settings. Clean-ups:

* Try to improve javadoc.
* Remove blindly copy-pasted "@since 6.1" annotations.
* Get rid of private method nonNullNonBareRepo(); it's not needed.
* Simplify method nonNullRepo(), and annotate as @NonNull.
* Rename setInCoreFileSizeLimit() to getInCoreFileSizeLimit().

Change-Id: Ib1797e7cf925d87554307468330971e8ab2e05e9
Signed-off-by: Thomas Wolf <twolf@apache.org>
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
2022-08-17 18:44:21 +02:00
Ronald Bhuleskar 6297491e8a Adds FilteredRevCommit that can overwrites its parents in the DAG.
Change-Id: I1ea63a3b56074099688fc45d6a22943a8ae3c2ae
2022-08-16 21:32:25 -07: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 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
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
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
Matthias Sohn d1e173ba40 Merge "Merge branch 'stable-6.2'" 2022-06-17 03:35:40 -04:00
Ronald Bhuleskar 7f4fa5655a Annotate the exception with the possible failure reason when Bitmaps are not enabled.
When bitmaps are not enabled the RevWalk is expensive. AllowFilter
provides an override to continue walking. PedestrianWalk can be
expensive and fails when the clone is a partial clone using
--filter=tree:0. This can only work when bitmaps are enabled.

Having a message to the exception improves debuggability of such cases.

Change-Id: Ie61de20a39a765e6f6f77e81b4c3bbda2eefbaf3
2022-06-15 16:42:39 -04:00
Matthias Sohn c67d951a0a Merge branch 'stable-6.2'
* stable-6.2:
  Prepare 5.13.2-SNAPSHOT builds
  JGit v5.13.1.202206130422-r
  AmazonS3: Add support for AWS API signature version 4

Change-Id: I13514595f3a710b0d6e3c2de62f6508b950d22f9
2022-06-15 17:40:31 +02:00
Matthias Sohn 58f5302e1d Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Prepare 5.13.2-SNAPSHOT builds
  JGit v5.13.1.202206130422-r
  AmazonS3: Add support for AWS API signature version 4

Change-Id: Id4965aacd4e2ea1e8575a2c1bd4845729db6049a
2022-06-15 17:39:52 +02:00
Matthias Sohn d0bc2b544a Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Prepare 5.13.2-SNAPSHOT builds
  JGit v5.13.1.202206130422-r
  AmazonS3: Add support for AWS API signature version 4

Change-Id: Ie9c38ab8033fe1283e8b444b6acd3f4298062bf3
2022-06-15 16:32:08 +02:00
Matthias Sohn d961bb6502 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Prepare 5.13.2-SNAPSHOT builds
  JGit v5.13.1.202206130422-r
  AmazonS3: Add support for AWS API signature version 4

Change-Id: Ibd663a1d874d1aac274abc3dd44354fd99f64c39
2022-06-15 16:31:38 +02:00
eric.steele e9a5430c25 AmazonS3: Add support for AWS API signature version 4
Updating the AmazonS3 class to support AWS Signature version 4 because
version 2 is no longer supported in all AWS regions. The version can be
selected with the new 'aws.api.signature.version' property (defaults to
2 for backwards compatibility). When set to '4', the user must also
specify the AWS region via the 'region' property. The 'region' property
must match the region that the 'domain' property resolves to.

Bug: 579907
Change-Id: If289dbc6d0f57323cfeaac2624c4eb5028f78d13
2022-06-13 09:44:23 +02:00
Matthias Sohn 5868543f17 Fix typo in DiffTools#compare javadoc
Change-Id: Ib9f8453b3b948b098d433e1b1426c32b4b4f5af8
2022-06-13 00:58:47 +02:00
Matthias Sohn 4e2651e538 Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Fix connection leak for smart http connections

Change-Id: I4d38c62fa5416fd40b699de5b0ecfa03d498c21d
2022-06-07 11:36:46 +02:00
Matthias Sohn 1bd087a7f5 Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Fix connection leak for smart http connections

Change-Id: I8b7e643b87c0f788cdafb060a2c9e8b4ef6f7375
2022-06-07 11:36:11 +02:00
Matthias Sohn a96645a5f3 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Fix connection leak for smart http connections

Change-Id: Ic851f2c4660ed761f5527e405b116b54da42fb7c
2022-06-07 11:35:13 +02:00
Matthias Sohn 5efd32e91d Merge branch 'stable-5.12' into stable-5.13
* stable-5.12:
  Fix connection leak for smart http connections

Change-Id: Id34f29c1b27a80c2b56c911cad7e3f64ef63af48
2022-06-07 11:34:25 +02:00
Matthias Sohn 8bb17e518f Merge branch 'stable-5.11' into stable-5.12
* stable-5.11:
  Fix connection leak for smart http connections

Change-Id: I6caabf4774ccf34706cef846c1087710f67e2ecd
2022-06-07 11:33:38 +02:00
Matthias Sohn c7335f32e9 Merge branch 'stable-5.10' into stable-5.11
* stable-5.10:
  Fix connection leak for smart http connections

Change-Id: I3885c6114caed897f762f5ce523d3b27288205b2
2022-06-07 10:53:24 +02:00
Matthias Sohn 85011b8b07 Merge branch 'stable-5.9' into stable-5.10
* stable-5.9:
  Fix connection leak for smart http connections

Change-Id: I5e7144b2f5cd850978220c476947001ae2debb8e
2022-06-07 10:42:22 +02:00
Saša Živkov 011c26ff36 Fix connection leak for smart http connections
SmartHttpPushConnection: close InputStream and OutputStream after
processing. Wrap IOExceptions which aren't TransportExceptions already
as a TransportException.

Also-By: Matthias Sohn <matthias.sohn@sap.com>
Change-Id: I8e11d899672fc470c390a455dc86367e92ef9076
2022-06-06 08:14:18 +02:00
Andre Bossert c32694e5ae Teach JGit to handle external diff/merge tools defined in .gitattributes
Adds API that allows UI to find (and handle) diff/merge tools, specific
for the given path. The assumption is that user can specify file type
specific diff/merge tools via gitattributes.

Bug: 552840
Change-Id: I1daa091e9afa542a9ebb5417853dff0452ed52dd
Signed-off-by: Mykola Zakharchuk <zakharchuk.vn@gmail.com>
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
2022-06-02 10:36:39 +02:00
Andre Bossert ff77d412a9 Adapt diff- and merge tool code for PGM and EGit usage
see: https://git-scm.com/docs/git-mergetool

* DiffTools and MergeTools
  * store FS, gitDir and workTree for usage without
git repository (for EGit preferences)
  * add getUserDefinedToolNames() and getPredefinedToolNames()
  * replace getToolNames() with getAllToolNames() that combines the two
lists and put default tool name (diff.tool or merge.tool) as first
element (for EGit preferences)
* FileElement: refactoring of getFile() and friends to have midName
(LOCAL, REMOTE etc.) always added to the temp file name (also for EGit)
* FileElement: added directory attribute that is used in getFile() to
return path with workDir as parent
* DiffTool and MergeTool
  * added errw.flush(), because sometimes stderr is not printed in case
of die()
  * print e.getMessage() always to stderr
* Moved toolname and prompt logic into managers
* Exported internal packages required for egit.ui

Bug: 356832
Change-Id: I71e7f4dc362169a7612ca4f6546a021bc4b2b5f4
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
Signed-off-by: Tim Neumann <Tim.Neumann@advantest.com>
2022-06-02 10:36:31 +02:00
Andre Bossert 973e955ead Add availability check of pre-defined tools
see: https://git-scm.com/docs/git-difftool
see: https://git-scm.com/docs/git-mergetool

* now all available tools are printed with "--tool-help"
* if no diff.tool or merge.tool is defined the first available
pre-defined tool is used

TODO:
- add mergetools to difftools --> extra change or merge to this
- return the exit-code of the tool to jgit / java runtime

Bug: 356832
Change-Id: I20fb04e71ced981f5625020f461bbac24e6cec70
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
2022-06-01 14:23:48 +02:00
Andrey Loskutov bb30be6b33 Merge "Add filtering with help of DirCacheCheckout.getContent()" 2022-05-30 12:42:20 -04:00
Andrey Loskutov 8c681aac50 Fixed since tags added for new merge constants
Bug: 356832
Change-Id: I70197522675de0e9b53399ee3d9ed3f10312ff6b
2022-05-30 16:34:30 +02:00
Andre Bossert e81085944f Add filtering with help of DirCacheCheckout.getContent()
see: https://git-scm.com/docs/git-mergetool

* refactoring of content (FileElement) handling
* now the temporary files are already filled with filtered content in
the calling classes (PGM), that can be used with EGit content too

TODO:
 * keep the temporaries when no change detected and the user answers no
to the question if the merge was successful

Bug: 356832
Change-Id: I86a0a052d059957d4d152c1bb94c262902c377d2
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
2022-05-30 13:28:32 +02:00
Matthias Sohn 29dce2e7be Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Remove stray files (probes or lock files) created by background threads

Change-Id: Iab21b9776c2ebecd4cad5d015028cadd4b6541db
2022-05-27 16:22:09 +02:00
Matthias Sohn 9612aae885 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Remove stray files (probes or lock files) created by background threads

Change-Id: I7af1355a77f14995118145162f6bb8a4f1755f2b
2022-05-27 16:20:28 +02:00
Andrey Loskutov d2489ffa70 Merge "Add mergetool merge feature (execute external tool)" 2022-05-27 01:02:15 -04:00
Andrey Loskutov 5828ca1602 Merge "Add command line support for "git mergetool"" 2022-05-27 00:59:22 -04:00
Andrey Loskutov fde3e8b5d8 Merge "Add config reader for user-defined mergetools" 2022-05-27 00:58:42 -04:00
Andrey Loskutov 2b80dd968c Merge "Add difftool compare feature (execute external tool)" 2022-05-27 00:57:51 -04:00
James Z.M. Gao d67ac798f1 Remove stray files (probes or lock files) created by background threads
NOTE: port back from master branch.

On process exit, it was possible that the filesystem timestamp
resolution measurement left behind .probe files or even a lock file
for the jgit.config.

Ensure the SAVE_RUNNER is shut down when the process exits (via
System.exit() or otherwise). Move lf.lock() into the try-finally
block when saving the config file.

Delete .probe files on JVM shutdown -- they are created in daemon
threads that may terminate abruptly, not executing the "finally"
clause that normally removes these files.

Bug: 579445
Change-Id: Iaee2301eb14e6201406398a90228ad10cfea6098
2022-05-27 01:20:16 +02:00
Andre Bossert eaf4d500b8 Add mergetool merge feature (execute external tool)
see: https://git-scm.com/docs/git-mergetool

* implement mergetool merge function (execute external tool)
* add ExecutionResult and commandExecutionError to ToolException
* handle "base not present" case (empty or null base file path)
* handle deleted (rm) and modified (add) conflicts
* handle settings
 * keepBackup
 * keepTemporaries
 * writeToTemp

Bug: 356832
Change-Id: Id323c2fcb1c24d12ceb299801df8bac51a6d463f
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
2022-05-25 13:52:04 +02:00
Andre Bossert 8573435635 Add command line support for "git mergetool"
see: https://git-scm.com/docs/git-mergetool
see: https://git-scm.com/docs/git-config

* add command line support for "git mergetool"
  * add option handling for "--tool-help", "--tool=<mytool>",
"--[no-]prompt",  "--[no-]gui"
  * handle prompt
  * add MergeTools
  * add pre-defined mergetools
  * print merge actions --> no execute, will be done later

Bug: 356832
Change-Id: I6e505ffc3d03f75ecf4bba452a25d25dfcf5793f
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
2022-05-25 13:52:04 +02:00
Andre Bossert 24171b05f0 Add config reader for user-defined mergetools
see: https://git-scm.com/docs/git-mergetool
see: https://git-scm.com/docs/git-config

* add config reader for user-defined mergetools
  * merge.tool
  * merge.guitool
  * mergetool.prompt
  * mergetool.keepBackup
  * mergetool.keepTemporaries
  * mergetool.writeToTemp
  * mergetool.<tool>.path
  * mergetool.<tool>.cmd
  * mergetool.<tool>.trustExitCode

Bug: 356832
Change-Id: Ic4f07376630713d8e06cbad284d9c72c9ecc0405
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
2022-05-25 13:50:50 +02:00
Andre Bossert b63c2f39a1 Add difftool compare feature (execute external tool)
see: http://git-scm.com/docs/git-difftool

* add CommandExecutor that handles tool execution with help of "jgit.FS"
  * it handles tool execution with temporary created "command file" -->
for for all "command interpreters" and parameters with spaces etc.
  * using of external bash.exe at Windows (MinGW) if shell-script is
used as difftool command. It can be enabled with parameter
"jgit.usemsys2bash=auto" that checks if command contains ".sh" or
enabled / disabled with "jgit.usemsys2bash=true|false"
* added special handling for empty files (e.g. deleted, added etc.) that
are named "/dev/null"
* added creation and deletion of temporary files needed for compare
* added own Exception class for reporting to pgm / command line / EGit
* added prompt option handling before executing difftool
* reworked trustExitCode option for specific difftool and override for
all difftools from config and command line
* tested with command line options "--[no]-trust-exit-code",
"--tool=<toolname>", "--[no]-gui", --[no]-prompt
* ContentSource
  * added close() methods to close / cleanup used resources
(like ObjectReader TreeWalk etc.)
  * added isWorkingTreeSource() methods to check if file can be used
from working tree instead of copy from "ObjectLoader / ObjectReader" to
temporary file (fixes "difftool <commit> <commit>")

Bug: 356832
Change-Id: I5462fb6dbe4ecfd9da7c74117fce4070bbfd4d7a
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
2022-05-25 13:23:50 +02:00
Simon Sohrt ca62b3447b RewriteGenerator: Fully buffering of input is no longer necessary
Fully buffering by the previous generator of the input for the RewriteGenerator is no longer necessary.

Bug: 577948
Signed-off-by: Simon Sohrt <sohrt@his.de>
Change-Id: I59c7a7c7f3766e97627764608bc8dc733804274c
2022-05-25 05:49:28 -04:00
Fabio Ponciroli 4ac6e7b505 PackFileSnapshot: Resolve warnings by using "equals" instead of "=="
Errorprone raises the following warning: "[ReferenceEquality] Comparison
using reference equality instead of value equality"

Added Equality#isSameInstance util method to be reused in similar cases.

Change-Id: Ifc9885c9806dcafa1c5ee1351d3095bf1517dbf5
2022-05-20 20:12:29 +02:00
James Z.M. Gao 88d5f51e61 Remove stray files (probes or lock files) created by background threads
On process exit, it was possible that the filesystem timestamp
resolution measurement left behind .probe files or even a lock file
for the jgit.config.

Ensure the SAVE_RUNNER is shut down when the process exits (via
System.exit() or otherwise). Move lf.lock() into the try-finally
block when saving the config file.

Delete .probe files on JVM shutdown -- they are created in daemon
threads that may terminate abruptly, not executing the "finally"
clause that normally removes these files.

Bug: 579445
Change-Id: Ie27aca1fdaddfa487ebe072c3913d78355910df8
2022-05-15 19:41:24 +02:00
Thomas Wolf 563a7b5828 RefSpec: add missing @since
New API needs an @since 6.2 annotation.

Change-Id: I16b01ea820cc651605166acc13591b515541d06b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-04-25 07:45:55 +02:00
Thomas Wolf 7f9cd7d2ba De-couple ServiceLoader calls from class loading
Use the holder pattern to de-couple the loading of super classes from
the ServiceLoader calls to set up global instances. This prevents
potential lock inversions.

Bug: 579550
Change-Id: Ie8284e4d6d680ddd4cc6a486bbefe8ed00266240
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-04-14 10:52:55 +02:00
Thomas Wolf 7e06e51750 CommitCommand: call GpgSigner.getDefault() only if indeed signing
If we're not signing the commit, we don't need the GpgSigner at all.

Change-Id: Ica35651c73d82b7604c8a67487b0d9474c908aae
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-04-14 10:52:55 +02:00
Thomas Wolf fbce3122e0 GpgSigner: prevent class lock inversion on the default signer
Don't store the default signer in a static field of the abstract
superclass GpgSigner. This many lead to a lock inversion on the class
initialization locks if there are concurrent loads of the GpgSigner
class and of one of its subclasses, and that subclass happens to be
the one the ServiceLoader wants to load.

Use the holder pattern to de-couple the loading of class GpgSigner
from the ServiceLoader call.

Bug: 579550
Change-Id: Ifac0ea0c8985a09fe0518d0dabc072fafd6db907
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-04-14 10:52:55 +02:00
yunjieli eca101fc05 Fetch: Introduce negative refspecs.
Implement negative refspecs in JGit fetch, following C Git. Git
supports negative refspecs in source only while this change supports
them in both source and destination.

If one branch is equal to any branch or matches any pattern in the
negative refspecs collection, the branch will not be fetched even if
it's in the toFetch collection.

With this feature, users can express more complex patterns during fetch.

Change-Id: Iaa1cd4de5c08c273e198b72e12e3dadae7be709f
Sign-off-by: Yunjie Li<yunjieli@google.com>
2022-04-13 10:21:20 -07:00
Fabio Ponciroli 98029e6758 BaseSearch: Suppress ReferenceEquality Warnings
Errorprone raises the following warning:
"[ReferenceEquality] Comparison using reference equality
instead of value equality"

Change-Id: Ib7542506dcdf5a0c7775a99a2c0972930d622879
2022-04-02 04:18:54 -04:00
Fabio Ponciroli 47a16f5f22 RewriteGenerator: Suppress ReferenceEquality Warnings
Errorprone raises the following warning:
"[ReferenceEquality] Comparison using reference equality
instead of value equality"

Change-Id: Idfe3f044730019fb49dccee25a0563c6fc01fc6a
2022-04-01 17:41:56 -04:00
Fabio Ponciroli cc8b2e627b PlotCommit: Suppress ReferenceEquality Warnings
Errorprone raises the following warning:
"[ReferenceEquality] Comparison using reference equality
instead of value equality"

Change-Id: Ia0dc2df68c77e40ff509a2c39568abce92525ee9
2022-04-01 17:27:42 -04:00
Fabio Ponciroli f1362e857e PlotCommitList: Suppress ReferenceEquality Warnings
Errorprone raises the following warning:
"[ReferenceEquality] Comparison using reference equality
instead of value equality"

A single pointer comparison is fine here.
A comparison with 'equals' would complicate the code and
also impact performance.

Change-Id: I6677dfc483acb95a64afbf433fd2b9460e408264
2022-04-01 17:07:19 -04:00
Thomas Wolf 8f02807164 Use git config core.commentChar
This concerns committing, creating merge conflict messages and creating
and editing squash messages. In a squash message, once the comment
character has been determined initially is always the first character.
Note that if core.commentChar=auto and there is a sequence of squashes,
it may be necessary to change the comment character when a new message
is added.

Bug: 579325
Change-Id: Idca19284a0240cd322e7512ea299a03658e1b2c1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-26 19:53:37 +01:00
Thomas Wolf a187d12dd9 CommitConfig: add support for core.commentChar
Provide  access to the core.commentChar git config, and provide a
utility method to determine an unused comment character if the setting
is "auto".

Bug: 579325
Change-Id: I1ec7e4deffea6ac5929a8538a624d73bb59e4ecc
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-26 19:53:37 +01:00
Thomas Wolf a171360292 [push, lfs] Tell the pre-push hook whether the push is a dry run
This is a feature that does not exist in C git: an external pre-push
hook doesn't know whether the push is run as a dry run. But for
internal hooks written in Java it is entirely possible to give a hook
this information.

In JGit with its internal LFS implementation, this enables us to not
perform LFS uploads in a dry run. This is kind of important because
EGit frequently does a dry-run before doing the actual push to give the
user a way to review what would be pushed before it actually happens.

Doing an LFS upload of potentially huge files during a dry-run is
wasteful, makes the dry run not actually a dry run, and leads to
uploading the same file twice if followed by a real push.

Use the information in the LfsPrePushHook to only do the initial call
to the LFS server, but then skipping the actual upload if the push is
a dry run. That way, a failure to contact the LFS server leads to an
error in the dry run, as it should.

Bug: 546567
Change-Id: I155430f27c4979d91096ba72fd95c3775dd3f28b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-23 18:55:31 -04:00
Matthias Sohn 30a137dfe5 Merge changes I5df54a92,Iecc61d1c
* changes:
  LsRemoteCommand: apply url.*.insteadOf
  Factor out URL replacement from RemoteConfig
2022-03-22 12:15:33 -04:00
Thomas Wolf 0ae37d4000 DirCacheCheckout: use a LinkedHashMap instead of HashMap
This guarantees that updates are checked out in git order, which
is important for LFS if a .lfsconfig file is used. That file comes
early in git order, and the LFS smudge filter will consider the
working tree version. To ensure that on branch switches the correct
version of that file is used, the checkout order must be stable and
should be the git order.

Change-Id: I20f6d11bf08558f9d5adfd2be71e36321460038c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-19 21:41:55 +01:00
Thomas Wolf 7b1c8cf147 Re-try reading a file when there are concurrent writes
Git and JGit are very careful to replace git files atomically when
writing. The normal mechanism for this is to write to a temporary
file and then to rename it atomically to the final destination. This
works fine on POSIX-compliant systems, but on systems where renaming
may not be atomic, exceptions may be thrown if code tries to read
the file while the rename is still ongoing. This happens in particular
on Windows, where the typical symptom is that a FileNotFoundException
with message "The process cannot access the file because it is being
used by another process" is thrown, but file.isFile() == true at the
same time.

In FileBasedConfig, a re-try was already implemented for this case.
But the same problem can also occur in other places, for instance
in RefDirectory when reading loose or packed refs. Additionally,
JGit has similar re-tries when a stale NFS file handle is detected,
but that mechanism wasn't used consistently (only for git configs
and packed refs, but not for loose refs).

Factor out the general re-try mechanism for reading into a new method
FileUtils.readWithRetry() and use that in all three places. The
re-try parameters are hardcoded: at most 5 times for stale NFS handles,
and at most 5 times with increasing backoff delays (50, 100, 200, 400,
and 800ms) for the above concurrent write case.

Bug: 579116
Change-Id: If0c2ad367446d3c0f32b509274cf8e814aca12cf
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-19 21:33:51 +01:00
Thomas Wolf ac78c17523 [sideband] Ensure last bit of progress channel is written
If the last sideband progress message didn't end in \r or \n, there
may still be a buffered message at the end of a fetch or push. Ensure
that message gets written, too, even if it may be only partial.

Bug: 575629
Change-Id: I38edccb5cffb89e00e468480b43c7d951fb63e8e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-19 12:13:37 +01:00
Thomas Wolf 2c1a8798ca LsRemoteCommand: apply url.*.insteadOf
If LsRemoteCommand is used without repository, the remote URI was not
translated. If the git user config contains e.g.

  [url "ssh://git@github.com/"]
    insteadOf = https://github.com/

and LsRemoteCommand is called with an HTTPS GitHub repository URL, the
command should actually rewrite this to an SSH URI and use the SSH
transport.

Actually this same problem may exist everywhere Transport is used with
an URIish instead of with a remote name. However, doing this translation
in Transport.open(URIish) and in Transport.open(Repository, URIish,
String) if no remote name is given would change the behavior and might
break assumptions made in existing clients. For instance, EGit's
PushOperation assumes that the URI obtained from PushResult.getURI()
was the same as was passed in to Transport.open(Repository, URIish).

URIs obtained from a RemoteConfig have this translation applied
transparently, and in Transport we cannot know for sure whether or
not a URI has already been translated, if needed. So doing this in
Transport might also lead to translating URIs twice.

Therefore this commit does the translation in LsRemoteCommand, where
we can be sure that it won't affect other use cases. If other cases
besides LsRemoteCommand are found where such a URI translation is
missing, it'll have to be done at higher levels, possibly even in
client code directly.

Bug: 544769
Change-Id: I5df54a925d30b55d98e21f37f2851fe79649b064
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-15 20:58:52 +01:00
Thomas Wolf c127a1a652 Factor out URL replacement from RemoteConfig
Add a new UrlConfig that encapsulates the basic URL replacement logic
for git configs url.<base>.insteadOf and pushInsteadof.

Change-Id: Iecc61d1c5e6089533552afa1d1e684ae72393b38
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-15 20:43:51 +01:00
Thomas Wolf f26ab4ebee [checkout] Use .gitattributes from the commit to be checked out
JGit used only one set of attributes constructed from the global and
info attributes, plus the attributes from working tree, index, and
HEAD.

These attributes must be used to determine whether the working tree is
dirty.

But for actually checking out a file, one must use the attributes from
global, info, and *the commit to be checked out*. Otherwise one may not
pick up definitions that are only in the .gitattributes of the commit
to be checked out or that are changed in that commit with respect to
the attributes currently in HEAD, the index, or the working tree.

Maintain in TreeWalk different Attributes per tree, and add operations
to determine EOL handling and smudge filters per tree.

Use the new methods in DirCacheCheckout and ResolveMerger. Note that
merging in JGit actually used the attributes from the base, not those
from ours, which looks dubious at least. It now uses those from ours,
and for checking out the ones from theirs.

The canBeContentMerged() determination was also done from the base
attributes, and is newly done from the ours attributes. Possibly this
should take into account all three attributes, and only if all three
agree the item can be content merged, a content merge should be
attempted? (What if the binary/text setting changes between base, ours,
or theirs?)

Also note that JGit attempts to perform content merges on non-binary
LFS files; there it used the filter attribute from base, too, even for
the ours and theirs versions. Newly it takes the filter attribute from
the correct tree. I'm not convinced doing content merges on potentially
huge files like LFS files is really a good idea.

Add tests in FilterCommandsTest and LfsGitTest to verify the behavior.

Open question: using index and working tree as fallback for the
attributes of ours (assuming it is HEAD) is OK. But does it also make
sense for base and theirs in merging?

Bug: 578707
Change-Id: I0bf433e9e3eb28479b6272e17c0666e175e67d08
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-07 18:45:25 +01:00
Matthias Sohn 72bba7bd53 Don't use final for method parameters
See https://wiki.eclipse.org/EGit/Contributor_Guide#Use_of_the_.22final.22_modifier

Change-Id: Idc6ed85483e381689e5085c4a1bacd75d26f5489
2022-03-06 18:52:59 +01:00
Thomas Wolf 8a2c769417 [push] support the "matching" RefSpecs ":" and "+:"
The implementation of push.default=matching was not correct.
It used the RefSpec "refs/heads/*:refs/heads/*", which would push
_all_ local branches. But "matching" must push only those local
branches for which a remote branch with the same name already exists
at the remote.

This RefSpec can be expanded only once the advertisement from the
remote has been received.

Enhance RefSpec so that ":" and "+:" can be represented. Introduce a
special RemoteRefUpdate for such a RefSpec; it must carry through the
fetch RefSpecs to be able to fill in the remote tracking updates as
needed. Implement the expansion in PushProcess.

Bug: 353405
Change-Id: I54a4bfbb0a6a7d77b9128bf4a9c951d6586c3df4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-06 17:30:01 +01:00
Thomas Wolf 90df7c123e [push] Call the pre-push hook later in the push process
Call the pre-push hook only after having received the remote
advertisement and having determined rejections, like C git does.
Also similar to C git, don't pass rejected or up-to-date updates
to the pre-push hook.

Bug: 578852
Change-Id: I51d379ea7bd8234ec815f8f4a9fa325816f476cf
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-06 17:30:01 +01:00
Thomas Wolf 72ae234e79 IndexDiff: use tree filter also for SubmoduleWalk
The only uses of IndexDiff.setFilter() in JGit and EGit set a path
filter. Passing the filter on to the SubmoduleWalk gives the desired
result, which is consistent with command-line git.

Bug: 565251
Change-Id: I8eca1ed73eb1d237b8785f369352f72af9e0e168
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-03-06 11:11:26 +01:00
Matthias Sohn 6f175ea6c4 Describe: add support for core.abbrev config option
If core.abbrev is unset or "auto" estimate abbreviation length like C
git does:
- Estimate repository's object count by only considering packed objects,
  round up to next power of 2
- With the order of 2^len objects, we expect a collision at 2^(len/2).
  But we also care about hex chars, not bits, and there are 4 bits per
  hex. So all together we need to divide by 2; but we also want to round
  odd numbers up, hence adding one before dividing.
- For small repos use at least 7 hexdigits
- If object database fails to determine object count use 7 hexdigits as
  fallback

If it is set to "no" do not abbreviate object-ids.

Otherwise set it to the configured value capped to the range between 4
and length of an unabbreviated object-id.

Change-Id: I425f9724b69813dbb57872466bf2d2e1d6dc72c6
2022-03-02 19:29:48 +01:00
Matthias Sohn 9244c07d73 Add a typed config getter for integers confined to a range
Use Integer#MIN_VALUE to denote unset option.

Change-Id: I4d65f2434013111f25520c0ed2b9a9dc8123c6cf
2022-03-02 19:28:14 +01:00
David Ostrovsky 67097f5de4 PersonIdent: Add ctors that accept Instant in addition to Date
Error Prone is flagging Date-API as obsolete and recommends to migrate
to Instant and LocalDate. Given that more JGit users starting to migrate
to new Time API, offer ctors that accept Instant type and also add new
getter that returns when attribute as Instant type.

Change-Id: I64a36bf40f191495c6889c1dff314ede06848880
2022-03-02 16:38:44 +01:00
Fabio Ponciroli c543b8ee1a Make precedence more explicit
Errorprone was failing the build with: "[OperatorPrecedence]. Use
grouping parenthesis to make the operator precedence explicit"

Add parentheses to silence it.

Change-Id: I81f1f249e38fd2543f5412b3501b0179d0759f55
2022-03-02 16:24:44 +01:00
Matthias Sohn 85d8b31cb2 Cap describe abbrev option
- minimum is 4 [1]
- maximum is length of a full ObjectId

[1] https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreabbrev

Change-Id: I145bde1a218f71b87b8d8260761dd0853770bb76
2022-03-02 09:56:03 +01:00
Matthias Sohn a2d5650b8f DescribeCommand: Add support for --abbrev=0
Setting --abbrev=0 suppresses long format and only shows the closest tag
[1].

[1] https://git-scm.com/docs/git-describe#Documentation/git-describe.txt---abbrevltngt

Change-Id: Ifcf4d7786dd0f0fb0315d8093fdb54384ed9d5f9
2022-03-02 09:56:03 +01:00
Sebastian Schuberth a7386ffe3a DescribeCommand: Support configuring the hash abbreviation
Bug: 537883
Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
Change-Id: Ic52dcebc564bbb0d934cc3a6205704b7aeaee30e
2022-02-19 22:04:28 +01:00
Thomas Wolf 69ef598bd9 Simplify implementation of WorkingTreeIterator
All the filtering in WorkingTreeIterator is for check-in, i.e., clean
filtering. The implementation was in some parts too general, passing
around an OperationType. But since it's always CHECKIN_OP, that's not
actually necessary.

Change-Id: I73f8bc059e485a073e456962868f52b3a3db4fc1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-16 18:51:28 +01:00
Thomas Wolf 63c1c6e4d8 Transport: load all refs only if push refspecs have wildcards
There is no need to load all refs if there are no wildcard push
refspecs. Load them lazily on the first wildcard refspec encountered
instead of loading them up-front.

Change-Id: I6d0e981f9ed4997dbdefeb7f83f37ff4f33e06a5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-14 10:45:15 +01:00
Thomas Wolf 855a734875 PushCommand: determine remote from git config if not given
Add ConfigConstants and expose branch.<name>.pushRemote in the
BranchConfig. Use the branch configuration and remote.pushDefault
if no remote is given explicitly. If nothing is configured, fall
back to "origin".

Bug: 578676
Change-Id: I6bb141ff02c8b04980ec34b26ef248b72614c3c9
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-14 10:45:15 +01:00
Rolf Theunissen 504001228b PushCommand: consider push.default when no RefSpecs are given
When no RefSpecs are given, PushCommand until now simply fell back to
pushing the current branch to an upstream branch of the same name. This
corresponds to push.default=current. Any setting from the git config
for push.default was simply ignored.

Implement the other modes (nothing, matching, upstream, and simple),
too. Add a setter and getter for the PushDefault so that an application
can force a particular mode to be used. For backwards compatibility,
use "current" as the default setting; to figure out the value from the
git config, which defaults to "simple", call setPushDefault(null).

Bug: 351314
Change-Id: I86c5402318771e47d80b137e99947762e1150bb4
Signed-off-by: Rolf Theunissen <rolf.theunissen@gmail.com>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-14 10:45:15 +01:00
Thomas Wolf c3fbd2cdf9 Prevent that an instance of PushCommand is reused
We checked if the command instance is called but missed to set the flag
tracking if it actually was used.

Change-Id: I0f9fb85c47945a4d91eab01ec5e1abc1ab83332a
2022-02-14 10:44:51 +01:00
Fabio Ponciroli db2d379c9c Remove unused warning suppression
SuppressWarnings is not used. Remove  to avoid
warnings at compile  time.

Change-Id: I84e3e57017cf9fd68d3377f866d4dd907ccde454
2022-02-11 09:42:06 +01:00
Thomas Wolf 2883762219 Support for git config push.default
Enhance the (unused!?) PushConfig; include a PushDefault enumeration.
Add simple tests for this PushConfig.

Bug: 351314
Change-Id: Ibc5656a2a1fccf70d00c5e15de8ed3dd8add6337
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-09 18:33:31 +01:00
Matthias Sohn 94a4d30b95 Merge branch 'stable-6.0'
* stable-6.0:
  Stop initCause throwing in readAdvertisedRefs

Change-Id: I2266814c613fd81e9dfc722532ac3daa30ca66b5
2022-02-09 00:54:06 +01:00
Matthias Sohn cec6db62af Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Stop initCause throwing in readAdvertisedRefs

Change-Id: I94251601aa7fae9cc65164eaddcf16471874b11e
2022-02-09 00:46:49 +01:00
Darius Jokilehto 78c9b9260a Stop initCause throwing in readAdvertisedRefs
BasePackConnection::readAdvertisedRefsImpl was creating an exception by
calling `noRepository`, and then blindly calling `initCause` on it. As
`noRepository` can be overridden, it's not guaranteed to be missing a
cause.

BasePackPushConnection overrides `noRepository` and initiates a fetch,
which may throw a `NoRemoteRepositoryException` with a cause.

In this case calling `initCause` threw an `IllegalStateException`.

In order to throw the correct exception, we now return the
BasePackPushConnection exception and suppress the one thrown by
BasePackConnection

Bug: 578511
Change-Id: Ic1018b214be1e83d895979ee6c7cbce3f6765f6f
2022-02-08 09:52:03 +00:00
Nail Samatov a054f3ce76 Support LFS Server URL without .git suffix
According to Git LFS documentation, URLs with and without .git suffix
should be supported. By default, Git LFS will append .git/info/lfs to
the end of a Git remote URL. To build the LFS server URL it will use:

Git Remote: https://git-server.com/foo/bar
LFS Server: https://git-server.com/foo/bar.git/info/lfs

Git Remote: https://git-server.com/foo/bar.git
LFS Server: https://git-server.com/foo/bar.git/info/lfs

Fix the LfsConnectionFactory accordingly. Move a utility method to
add the ".git" suffix if not present yet from FileResolver to
StringUtils and use it.

Bug: 578621
Change-Id: I8d3645872d5f03bb8e82c9c73647adb3e81ce484
Signed-off-by: Nail Samatov <sanail@yandex.ru>
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-08 09:11:12 +01:00
Thomas Wolf 7e752364a6 [rebase] InteractiveHandler2: handle Gerrit Change-Ids
Add a way for the handler to tell whether the commit should generate a
Gerrit Change-Id. Augment the ModifyResult interface, and set the flag
on the CommitCommand.

This enables users to have a Change-ID be generated when squashing or
rewording commits. A possibly already existing Change-Id will remain
unchanged.

Bug: 440211
Change-Id: I66a72e0646876d162a7011235cca969e20acf060
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-04 13:42:12 +01:00
Sebastian Schuberth 20bdcf9ea8 Introduce a constant for the length of an abbreviated hash string
Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch.io>
Change-Id: I196d58a813f7caa1965af4cf8e2f977ed4cdc350
2022-02-03 00:21:25 +01:00
Thomas Wolf 035d24097d RebaseCommand: fix commit message in "fixup" case
JGit accumulated in MESSAGE_FIXUP commit messages of a fixup sequence,
just like it did in MESSAGE_SQUASH, and on the last step of a sequence
of fixups used that file, after stripping all comment lines, as the
commit message. That also stripped any lines from the original commit
message that happened to start with the comment character.

This is not how this is supposed to work. MESSAGE_FIXUP must contain
the original commit message of the base commit that is amended, and
the file contains the verbatim commit message for the final fixup.[1]

Change the implementation accordingly, and add new tests.

[1] https://github.com/git/git/blob/df3c41adeb/sequencer.c#L86 ff.

Bug: 513726
Change-Id: I885a2b7f10d6c74460a8693aa6cbf867ee0494a1
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-02 14:40:58 +01:00
Han-Wen Nienhuys 92158af52e reftable: close old Db in FileRepository#convertToPackedRefs
This fixes test failures on Windows.

Change-Id: I701fbeb99ffd7951514ae6eae8b28cceb9aebd9f
2022-02-02 14:12:18 +01:00
Han-Wen Nienhuys a650ae8ad3 reftable: tweaks for Windows
Reload the stack _before_ trying to delete the files. This ensures we
don't trip over our own open file handles when deleting compacted
tables.

If there is another process reading the file, it may be impossible to
delete the compacted tables. In this case, ignore the failure.

For cleaning the garbage in this case, the protocol as described in
https://www.git-scm.com/docs/reftable#_windows should be implemented.
This is left for another commit.

Bug: 578454
Change-Id: I7aa43508450041eb9376d9f67a0262ff7cc53c73
2022-02-02 14:12:15 +01:00
Ivan Frade 424c861477 Merge changes I11366273,I256e1572
* changes:
  RepoCommand: Offer to set extra files in the destination repository
  RepoCommand: Move bare/regular superproject writing to their own classes
2022-02-01 17:41:44 -05:00
Matthias Sohn 48aae36a22 Merge branch 'stable-6.0'
* stable-6.0:
  Fix warning: The value of the parameter otp is not used

Change-Id: I47996285c49ce85ab0bb835956a9ef58ed71de20
2022-02-01 00:28:05 +01:00
Thomas Wolf 8dcb86b602 Fix FS_Win32 if a non-directory is listed
FS.list() is supposed to return an empty array if the File given is not
a directory.

Bug: 550111
Change-Id: I245da5f1f2bdafd9dfb38fb8d7eff27d900cd5a8
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-02-01 00:05:53 +01:00
Ivan Frade dba66dbfce RepoCommand: Offer to set extra files in the destination repository
We want to save in the destination repository what manifest created its
structure. This helps to detect and debug failures in the manifest ->
superproject translations. The src commit should be easily readable from
the superproject tip.

Offer an API to write a file in the destination repository. RepoCommand
callers (e.g. gerrit supermanifest plugin) can use this to add a
file with the repo/ref/hash of the manifest.

Alternatives considered to write the source repo/ref/hash:

  * .gitattributes of the .gitmodules file. Some updates in the manifest
    don't touch the .gitmodules (e.g. a linkfile change), so it can fall
    out of sync.

  * commit message. Caller would need to follow the commit history to
    find the latest modification by repo command. This is not helpful
    e.g. for build bots that want to get the value in one call.

Change-Id: I113662734a7ccd39cbc60b46ad3f73038c807682
2022-01-31 14:51:23 -08:00
Ivan Frade dee4240ce8 RepoCommand: Move bare/regular superproject writing to their own classes
RepoCommand parses the manifest to get a list of projects, clears up
conflicts and then writes to the superproject. The first steps are
common but the writing is completely different for bare or "regular"
(with working dir) repository.

Split writing to bare and regular repos into its own classes. This
simplifies RepoCommand class and makes clearer what happens on each side
(e.g. many options apply only to bare repos).

Change-Id: I256e15729bd53ee15fc56de88bce86a2edb2417a
2022-01-31 14:47:33 -08:00
Thomas Wolf 1fd15e40cc Merge conflict messages: prefix conflict lines with a hash
C git also does so. Note that currently the comment character is
hard-coded as the hash '#' throughout JGit.

Bug: 548529
Change-Id: I4a5597694082a9e5b07412b365cfaf41fa034cfa
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-31 00:42:35 +01:00
Thomas Wolf e297f503a1 RebaseCommand: better commit message rewording
Respect git config commit.cleanup for rewording. Note that by default
this is CleanupMode.STRIP, whereas before this change, JGit would take
the reworded message verbatim.

Squashing was the only place in JGit where it automatically and
unconditionally removed comment lines from commit messages. In other
places it didn't do so, and client code needed to do so.

Unconditionally removing comments is problematic if the commit message
_should_ contain some line starting with a hash, which can easily occur
with the way Github, Gitlab, and other git web servers link to issues
or PRs: they all allow the short-hand "#<number>".

Introduce a new InteractiveHandler2 extension interface, which can
return the edited message _and_ a clean-up mode. This way, client code
can decide on its own how to clean the message, and if JGit shouldn't
do any further cleaning, it can return CleanupMode.VERBATIM. Or
CleanupMode.WHITESPACE. (In the case of SQUASH, it is then of course
the client's responsibility to remove the squash comment lines.)

If the old InteractiveHandler interface is used, CleanupMode.STRIP is
applied unconditionally for squashing, as before.

Bug: 578173
Change-Id: Ia0040c247884e684587dd45d6cb85f8b72a4b876
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-31 00:42:35 +01:00
Thomas Wolf 513c7318de CommitCommand: commit message cleanup
Use CommitConfig.CleanupMode to implement git commit --cleanup. Add
setters for the clean-up mode, the comment character, and for the
default default clean-up mode.

Behavior of existing client code is unchanged as the default clean-up
mode is set to "verbatim". To use git config defaults, one can call
setCleanupMode(CleanupMode.DEFAULT). The default comment character
is hard-coded as '#' for now, as in other parts of JGit. Implementing
full support for core.commentChar shall be done in a separate change.

Bug: 553065
Change-Id: I470785e464a762d3f409f163f1cbdbb98dd81aaf
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-31 00:42:35 +01:00
Thomas Wolf 318a25f0e6 Provide git config commit.cleanup
Add an enumeration for the possible values, and a method to resolve the
"default" value. Give CommitConfig a static method to process a text
according to a given clean-up mode and comment character.

(The core.commentChar is not yet handled by JGit; it's hard-coded as #.)

Bug: 553065
Change-Id: If6e384522275f73b713fbc29ffcaa1753c239dea
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-31 00:42:35 +01:00
Thomas Wolf 4bb87a957f ObjectWalk: close ObjectReader on close() if needed
If the walk is created via ObjectWalk(Repository), it creates a new
ObjectReader. This reader was closed only on dispose(). If such an
ObjectWalk was used in a try-with-resource statement the reader might
not get closed.

Bug: 578458
Change-Id: I1be31829dc466530f23006a53c29b657fd5fb410
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-30 22:18:30 +01:00
Thomas Wolf 8bca5245e0 BinaryHunkInputStream: accept CR-LF
Let's be lenient and accept hunk lines terminated by CR-LF, too, not
just lines terminated by LF.

Bug: 550111
Change-Id: I7f796df666300ab56cc6c07f22eda45fbf4c941e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-30 17:58:34 +01:00
Thomas Wolf 8e9a42b7c0 sshd: support the ConnectTimeout ssh config
Parse the value from the ssh config and if set use it when connecting.

Change-Id: I85b44c9468a5027602375706612c46ea7a99b2bd
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-30 17:13:47 +01:00
Thomas Wolf b73548bc4c sshd: support the AddKeysToAgent ssh config
Add parsing of the config. Implement the SSH agent protocol for adding
a key. In the pubkey authentication, add keys to the agent as soon as
they've been loaded successfully, before even attempting to use them
for authentication. OpenSSH does the same.

Bug: 577052
Change-Id: Id1c08d9676a74652256b22281c2f8fa0b6508fa6
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-30 17:13:46 +01:00
Thomas Wolf 68bd2c1462 sshd: handle "IdentityAgent SSH_AUTH_SOCK" in ssh config
OpenSSH has (for legacy reasons?) the option of specifying the default
environment variable directly, instead of using ${SSH_AUTH_SOCK}. Make
sure the plain variable name is not taken as a relative path name.

Bug: 577053
Change-Id: If8f550dffc43887254f71aa0b487c50fa14d0627
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-30 17:13:46 +01:00
Thomas Wolf 4efc6a396a sshd: support IdentityAgent config
Handle the 'none' value, and change the value to select Pageant to
something that looks like an absolute UNC path name to avoid it's
handled as an relative path name.

Bug: 577053
Change-Id: I4ccf047abbc1def50e2782319e4fa7c744069401
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2022-01-30 17:13:44 +01:00
Ivan Frade 27e554e465 Merge "PackOutputStream: Extract cancellation and digest to superclass" 2022-01-27 11:42:54 -05:00
kylezhao 1a86c1044d PackOutputStream: Extract cancellation and digest to superclass
Checking the cancelled status and keeping a digest of the written data
is useful for other output streams. e.g. to write commit-graphs.

Pull up that functionality to a superclass, so it can be reused.

Change-Id: I177b50be09c4ea631e7a144cc6127085ec2ca411
Signed-off-by: kylezhao <kylezhao@tencent.com>
2022-01-27 19:21:31 +08:00
Ivan Frade 076ecf8ded Merge "DFS block cache: report index load and evict stats" 2022-01-21 14:59:30 -05:00
Alina Djamankulova b536dbdb9b DFS block cache: report index load and evict stats
Enhance cache performance monitoring for large data such as pack and
bitmap indexes. Provide details about what is loaded and evicted from
cache like total number of cache hits, time in cache before eviction.

Add a custom consumer to report loading events and eviction events when
enabled.

Signed-off-by: Alina Djamankulova <adjama@google.com>
Change-Id: I5739325db7ff7ec370e4defd8f7e46f1c3f5d2dd
2022-01-21 11:27:31 -08:00
Antonio Barone 788f439c0e Fix warning: The value of the parameter otp is not used
Silence warning by removing unused argument to the beginCopyAsIs()
method.

Change-Id: I94e7ff1c61cf8b03752de2974baa24b9c061c163
2022-01-20 12:37:16 +01:00
Matthias Sohn 5f556588a9 Merge branch 'stable-6.0'
* stable-6.0:
  [bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory
  [errorprone] Fix InfiniteRecursion error in RecordingLogger
  [errorprone] Suppress Finally error in ObjectDownloadListener
  [errorprone] Fix implicit use of default charset in FileBasedConfigTest
  [errorprone] Suppress FutureReturnValueIgnored in FileRepository#autoGc

Change-Id: I08d58c8f3f04e3a920da43b5fb252b1654c2b33c
2022-01-19 09:53:21 +01:00
Matthias Sohn b55c224ef3 Merge "[errorprone] Suppress FutureReturnValueIgnored in FileRepository#autoGc" into stable-6.0 2022-01-19 03:43:27 -05:00
Matthias Sohn d017a655df Merge branch 'stable-6.0'
* stable-6.0:
  UploadPack v2 protocol: Stop negotiation for orphan refs
  Complete update to servlet api 4.0.0

Change-Id: I55ab6e8fd4a76e4313e37b12f9fc5d5e4b84a681
2022-01-18 18:09:03 +01:00
Matthias Sohn de1abd3237 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  UploadPack v2 protocol: Stop negotiation for orphan refs

Change-Id: I6a9ed8338ffbf5363e48d640a2c4209e4e503549
2022-01-18 18:07:59 +01:00
Matthias Sohn 2cc0009737 Merge branch 'stable-5.12' into stable-5.13
* stable-5.12:
  UploadPack v2 protocol: Stop negotiation for orphan refs

Change-Id: Ib43068c32d9cb8effe4b873396391dc3c9197a6e
2022-01-18 17:51:14 +01:00
Matthias Sohn 1e59cabc08 Merge branch 'stable-5.11' into stable-5.12
* stable-5.11:
  UploadPack v2 protocol: Stop negotiation for orphan refs

Change-Id: I5db432bd416cfa8d3dd295bdce63e31d5f160a8a
2022-01-18 17:49:03 +01:00
Matthias Sohn 2fed62528a [errorprone] Suppress FutureReturnValueIgnored in FileRepository#autoGc
Ignore the FutureReturnValueIgnored warning for the unused return value
of #gc.

Change-Id: I4e7a2f85d404962c01726f9a1d079fe4a6430a1b
2022-01-18 16:11:50 +01:00
Marcin Czech 78d4fb1ca0 UploadPack v2 protocol: Stop negotiation for orphan refs
The fetch of a single orphan ref (for example Gerrit meta ref:
refs/changes/21/21/meta) did not stop the negotiation so client
had to advertise all refs. This impacts the fetch performance
on repositories with a large number of refs (for example on
Gerrit repository it takes 20 seconds to fetch meta ref
comparing to 1.2 second to fetch ref with parent).

To avoid this issue UploadPack, used on the server side,
now checks if all `want` refs have parents, if not this
means that client doesn't need any extra objects, hence
the server responds with `ready` and finishes the
negotiation phase.

Bug: 577937
Change-Id: Ia3001b400b415d5cf6aae45e72345ca08d3af058
2022-01-18 08:00:03 -04:00
Matthias Sohn 4d34cdf345 Merge branch 'stable-6.0'
* stable-6.0:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: Icc38ce20c1c791c8cf0ca3dcab46b1151f122805
2021-12-31 00:33:30 +01:00
Matthias Sohn fa82b80c9b Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: Iaff40b144aea9ad5e6d0fa6b448ad7d527992832
2021-12-31 00:30:51 +01:00
Matthias Sohn c8ab1392d1 Merge branch 'stable-5.12' into stable-5.13
* stable-5.12:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I6a0266cbcaaf18d0d60f0abecb5434fd919c44b7
2021-12-31 00:29:40 +01:00
Matthias Sohn 44bad3d98e Merge branch 'stable-5.11' into stable-5.12
* stable-5.11:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I4e241860c2ca50750e22c2761c515c9895688c55
2021-12-31 00:28:53 +01:00
Matthias Sohn 8a4b983767 Merge branch 'stable-5.10' into stable-5.11
* stable-5.10:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: Ie3f2d05aeb1aa04af707cfafef5780349be4d981
2021-12-31 00:26:24 +01:00
Matthias Sohn 95bf9bbfe8 Merge branch 'stable-5.9' into stable-5.10
* stable-5.9:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I4f954c48ad6e8ff18826fdc72d225bff3e3ae2d9
2021-12-31 00:05:40 +01:00
Matthias Sohn c6b0ee04e4 Merge branch 'stable-5.8' into stable-5.9
* stable-5.8:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: Ic97d38fc85daa00297abbfa186f83b779966e7ef
2021-12-30 23:58:41 +01:00
Matthias Sohn 725e77a517 Merge branch 'stable-5.7' into stable-5.8
* stable-5.7:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: If9cc2f2bae5dbead7a38218828da461540be942e
2021-12-30 23:56:32 +01:00
Matthias Sohn 1343dd2de7 Merge branch 'stable-5.6' into stable-5.7
* stable-5.6:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I274d46d73cc896dcfde6e24c69c71f33aaa78d20
2021-12-30 23:53:54 +01:00
Matthias Sohn a461472bd5 Merge branch 'stable-5.5' into stable-5.6
* stable-5.5:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: If904289feecd1e0d8466c1fb998f160f14d54b61
2021-12-30 23:51:41 +01:00
Matthias Sohn d87e5e07a5 Merge branch 'stable-5.4' into stable-5.5
* stable-5.4:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I84e11bdaa9306e23212dac9d8670557a18d40107
2021-12-30 23:41:54 +01:00
Matthias Sohn 7f51f8acd8 Merge branch 'stable-5.3' into stable-5.4
* stable-5.3:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I3d8eb2fa721e1a791db47a2342acc690ced01715
2021-12-30 23:40:21 +01:00
Matthias Sohn 62c2159b62 Merge branch 'stable-5.2' into stable-5.3
* stable-5.2:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: Ib79c310c5b632e845ba69ce65e739ae0146103ca
2021-12-30 23:33:06 +01:00
Matthias Sohn f33ae743ad Merge branch 'stable-5.1' into stable-5.2
* stable-5.1:
  Use FileSnapshot without using configs for FileBasedConfig

Change-Id: I17ede8876a0cf231c38cb9652c7bf51553b1e90e
2021-12-30 23:18:21 +01:00
Luca Milanesio fed0ab9baa Use FileSnapshot without using configs for FileBasedConfig
FileBasedConfig should not rely on auto-detection of
the file-snapshot attribute computation based on config.

The check was already performed when a new FileBasedConfig
is created at L158:

// don't use config in this snapshot to avoid endless recursion
newSnapshot = FileSnapshot.saveNoConfig(getFile());

The check was missing though when the FileBasedConfig is saved
to disk and the new snapshot is obtained from the associated
LockFile.

This change fixes the issue by keeping a non-config based
FileSnapshot also after a FileBasedConfig is saved.

Bug: 577983
Change-Id: Id1e410ba687e683ff2b2643af31e1110b103b356
2021-12-30 11:14:47 +01:00
Thomas Wolf f77519775d Merge branch 'stable-6.0'
* stable-6.0:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"
  TreeRevFilter: fix wrong stop when the given path disappears

Change-Id: Id7540d03991cdcf6f405e946b8cbbcc6a9696a31
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 16:06:00 +01:00
Thomas Wolf 7146bde45f Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"
  TreeRevFilter: fix wrong stop when the given path disappears

Change-Id: Ibd69e9d941ad9262b61dd0c4368e48cb82597a12
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 16:04:44 +01:00
Thomas Wolf 41406e278f Merge branch 'stable-5.12' into stable-5.13
* stable-5.12:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I6576872cc0f5dd452252fa6e4526086cdee65c28
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 16:03:20 +01:00
Thomas Wolf f86d82fc30 Merge branch 'stable-5.11' into stable-5.12
* stable-5.11:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: Ib80336a42e22da729b9db1e573772504cc0a3e77
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 16:02:35 +01:00
Thomas Wolf 5f8c593bb6 Merge branch 'stable-5.10' into stable-5.11
* stable-5.10:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I9e79ea2a0c554a184e4ce3b13e375eac8b7a4ac5
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 16:01:49 +01:00
Thomas Wolf 8a9b4972b4 Merge branch 'stable-5.9' into stable-5.10
* stable-5.9:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I2a84c838a886d1d6383c34f50b418baa743c57b0
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 16:00:48 +01:00
Thomas Wolf 95ea1c1123 Merge branch 'stable-5.8' into stable-5.9
* stable-5.8:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I88a629e571fec5a9820114ebf5765b5d94a276bd
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:58:28 +01:00
Thomas Wolf 9fd632b0e4 Merge branch 'stable-5.7' into stable-5.8
* stable-5.7:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: Ied786ab5e3c0dd05f701705fce2d4ad85502c4d6
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:57:42 +01:00
Thomas Wolf d295294dbe Merge branch 'stable-5.6' into stable-5.7
* stable-5.6:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I454622dae6eb95aedbd858e3b12da72282d36673
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:56:33 +01:00
Thomas Wolf 1c689d18c4 Merge branch 'stable-5.5' into stable-5.6
* stable-5.5:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I2622f1d384a88a556ba9d88f0d08a37af69e530c
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:55:32 +01:00
Thomas Wolf fd612a1282 Merge branch 'stable-5.4' into stable-5.5
* stable-5.4:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: Ia1665dd92ccc3811a6116f41421a05aca10fc6eb
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:54:12 +01:00
Thomas Wolf 4cc21ccd3d Merge branch 'stable-5.3' into stable-5.4
* stable-5.3:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I52a57a17abe60e30e3d7615f8cb4d0c5e6aebd9b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:53:17 +01:00
Thomas Wolf 7edb062d8c Merge branch 'stable-5.2' into stable-5.3
* stable-5.2:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: Id37f47a5ef2e3c8329eca30c171941f7e5606a85
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:52:03 +01:00
Thomas Wolf f2d4783c52 Merge branch 'stable-5.1' into stable-5.2
* stable-5.1:
  Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"

Change-Id: I625667c2718ab31ae7df907c3dd6024a933913b8
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:50:42 +01:00
Thomas Wolf 7828ef349c Revert "RefDirectory.scanRef: Re-use file existence check done in snapshot creation"
This reverts commit f829f5f838.

Using MISSING_FILEKEY as indicator for a non-existing file doesn't work
on Windows.

Bug: 577954
Change-Id: I92102a3d259f6cc0f367096a3213cfa794466817
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2021-12-26 15:38:26 +01:00
kylezhao 3d7351ee50 TreeRevFilter: fix wrong stop when the given path disappears
When chgs[i] == adds[i], it indicated that a commit added some files
that pList[i] did not have, but didn't mean pList[i] is "empty tree
root".

Follow the example below:

.                           .
└── src                     └── src
    └── d1          ==>          └── d1
        └─ file1                    ├─  file1
                                    └── file2
   c.parents[i]                   c

The variable chg[i] equals to variable add[i],
but commit c.parents[i] is not "empty tree root".

We should add an additional check for no paths matching the filter.

Bug: 577227
Change-Id: I834e9ddd0de86b108b280a1139519ea962913b38
Signed-off-by: kylezhao <kylezhao@tencent.com>
2021-12-17 00:29:11 +01:00
Ivan Frade ab8a5a3ccb Merge "PackBitmapIndexV1: support parallel loading of reverse index" 2021-12-13 16:02:01 -05:00
Andre Bossert 14a59bdc7b Add config reader for user-defined difftools
see: http://git-scm.com/docs/git-difftool

* add config reader for user-defined difftools
  * diff.tool
  * diff.guitool
  * difftool.prompt
  * difftool.trustExitCode
  * difftool.<tool>.path
  * difftool.<tool>.cmd
* add pre-defined difftools
* implemented "git difftool --tool-help" to verify config reader and
pre-defined difftools

Bug: 356832
Change-Id: Idde8fddbef61f3378ee565c6321570b3962d0e1d
Signed-off-by: Andre Bossert <andre.bossert@siemens.com>
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
2021-12-08 10:43:00 +01:00
Alina Djamankulova 4e915f9568 PackBitmapIndexV1: support parallel loading of reverse index
Speed up bitmap creation by loading reverse index in parallel
to reading bitmap from storage. Latency changes from
(time_to_read_bitmap + time_to_load_reverse_index) to
max(time_to_read_bitmap, time_to_load_reverse_index).

Add new option to DfsReaderOptions to control parallel reverse index
loading. Static cached thread pool is added to PackBitmapIndexV1 for
reverse index loading, and when not in use consumes minimal resources.

Signed-off-by: Alina Djamankulova <adjama@google.com>
Change-Id: Ia37a1d739631d053e8bddb925ac8b0b81d22379e
2021-12-06 18:38:41 -04:00
Matthias Sohn caea5a26f0 Merge branch 'stable-6.0'
* stable-6.0:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I694c011f322f9a19479ef67b9fc725371da7418f
2021-12-04 21:21:52 +01:00
Matthias Sohn 284d2b5b9c Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: Icea0a4dced9688392e7f2411b98df52aed2b9c8c
2021-12-04 21:15:42 +01:00
Matthias Sohn 35713588fe Merge branch 'stable-5.12' into stable-5.13
* stable-5.12:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I9c85b3a774480c4f4b56ecdf5015916349a0ddc0
2021-12-04 21:06:33 +01:00
Matthias Sohn 1cffba4385 Merge branch 'stable-5.11' into stable-5.12
* stable-5.11:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I72f39fbe82dd578d71aa2e3ceccebb39a25c4e00
2021-12-04 20:42:56 +01:00
Matthias Sohn e14b25f240 Merge branch 'stable-5.10' into stable-5.11
* stable-5.10:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I84c73e11381c31566a12033db94e9afdcef5b705
2021-12-04 20:28:53 +01:00
Matthias Sohn 8583b3c56c Merge branch 'stable-5.9' into stable-5.10
* stable-5.9:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I971745b529ff903ea8bf9c3dbbc746fa09f41041
2021-12-04 19:31:53 +01:00
Matthias Sohn 70b894da19 Merge branch 'stable-5.8' into stable-5.9
* stable-5.8:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I5e7c204c0e4c428df6f3b27ba1fc06326983f27c
2021-12-04 19:19:16 +01:00
Matthias Sohn 73b3cbd26b Merge branch 'stable-5.7' into stable-5.8
* stable-5.7:
  Add missing @since tags
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot
creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: Ibe46e8479b57a54591ad7bd3cc29bf4a5274e43d
2021-12-04 18:55:17 +01:00
Matthias Sohn 85e11bd597 Merge branch 'stable-5.6' into stable-5.7
* stable-5.6:
  Add missing @since tag
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I53e6cb4b3a34b32d964e486c1ff3d130eed6e406
2021-12-04 18:14:00 +01:00
Matthias Sohn a1c9c82e85 Merge branch 'stable-5.5' into stable-5.6
* stable-5.5:
  Add missing @since tags
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I007e92c12fde8d765b75f103e9d530aa0834b7d7
2021-12-04 18:06:32 +01:00
Matthias Sohn d8f5b5c691 Merge branch 'stable-5.4' into stable-5.5
* stable-5.4:
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I5ce55c6c152a59602fef9fb08c16dedf666444e2
2021-12-04 17:46:20 +01:00
Matthias Sohn 7ae2ee300a Merge branch 'stable-5.3' into stable-5.4
* stable-5.3:
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: I0e80612c8ddb934466105312f9107e91d581de0b
2021-12-04 02:31:06 +01:00
Matthias Sohn dc41de0e3c Merge branch 'stable-5.2' into stable-5.3
* stable-5.2:
  Remove unused import in ApacheSshTest
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: Id989365446cb55b9188e02e6e1f8cbc8ab71071c
2021-12-04 01:58:53 +01:00
Matthias Sohn c25e8b3dee Merge branch 'stable-5.1' into stable-5.2
* stable-5.1:
  Update maven plugins
  Ignore missing javadoc in test bundles
  storage: file: De-duplicate File.exists()+File.isFile()
  RefDirectory.scanRef: Re-use file existence check done in snapshot creation
  FileSnapshot: Lazy load file store attributes cache
  Update eclipse-jarsigner-plugin to 1.3.2
  Fix p2 repository URLs

Change-Id: If3ad2cfb6c341b0ff5c2120a5a1646f6368d86e7
2021-12-04 01:26:11 +01:00
Nasser Grainawi 38db89142d storage: file: De-duplicate File.exists()+File.isFile()
File.isFile() [1] checks if the file exists and is a normal file.

[1] https://docs.oracle.com/javase/8/docs/api/java/io/File.html#isFile--

Change-Id: I0a883f2482ecc5ac58b270351b416742b568eb68
Signed-off-by: Nasser Grainawi <quic_nasserg@quicinc.com>
2021-12-03 22:09:50 +01:00
Kaushik Lingarkar f829f5f838 RefDirectory.scanRef: Re-use file existence check done in snapshot creation
Return immediately in scanRef if the loose ref was identified as
missing when a snapshot was attempted for the ref. This will help
performance of scanRef when the ref is packed but has a corresponding
empty dir in 'refs/'.

For example, consider the case where we create 50k sharded refs in
a new namespace called 'new-refs' using an atomic 'BatchRefUpdate'.
The refs are named like 'refs/new-refs/01/1/1', 'refs/new-refs/01/1/2',
'refs/new-refs/01/1/3' and so on. After the refs are created, the
'new-refs' namespace looks like below:

$ find refs/new-refs -type f | wc -l
0

$ find refs/new-refs -type d | wc -l
5101

At this point, an 'exactRef' call on each of the 50k refs without
this change takes ~2.5s, where as with this change it takes ~1.5s.

Change-Id: I926bc41b9ae89a1a792b1b5ec9a17b05271c906b
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
2021-12-03 22:06:46 +01:00
Kaushik Lingarkar 5606a53151 FileSnapshot: Lazy load file store attributes cache
Doing a getFileStoreAttributes call even when the file doesn't
exist is unnecessary. This call is particularly slow on some
filesystems. Instead, do it only when the file exists and load
the appropriate cache.

This update can help speed up RefDirectory.exactRef when the ref
is packed, but has a corresponding empty dir for it under 'refs/'.
This scenario can happen when an atomic 'BatchRefUpdate' creates
new sharded refs.

For example, consider the case where we create 50k sharded refs in
a new namespace called 'new-refs' using an atomic 'BatchRefUpdate'.
The refs are named like 'refs/new-refs/01/1/1', 'refs/new-refs/01/1/2',
'refs/new-refs/01/1/3' and so on. After the refs are created, the
'new-refs' namespace looks like below:

$ find refs/new-refs -type f | wc -l
0

$ find refs/new-refs -type d | wc -l
5101

At this point, an 'exactRef' call on each of the 50k refs without
this change takes ~30s, where as with this change it takes ~2.5s.

Change-Id: I4a5d4c6a652dbeed1f4bc3b4f2b2f1416f7ca0e7
Signed-off-by: Kaushik Lingarkar <quic_kaushikl@quicinc.com>
2021-12-02 10:45:37 +01:00
Matthias Sohn ea4480d7e1 Merge branch 'stable-6.0'
* stable-6.0:
  Prepare 6.0.1-SNAPSHOT builds
  JGit v6.0.0.202111291000-r
  Don't block in GC#gc until garbage collection finished

Change-Id: Ibdbcea607000621bf974b56a7399383d1372ce21
2021-11-29 20:17:12 +01:00
Matthias Sohn 26fb2b7f08 Don't block in GC#gc until garbage collection finished
Let GC#gc return collection of newly created packs as CompletableFuture
to enable using gc() asynchronously.

Change-Id: I3627014fd458c738cfe54225e631d6f7d9cfb1a7
2021-11-28 12:09:24 +01:00
Matthias Sohn 3cb02ccfdf Merge branch 'stable-6.0'
* stable-6.0:
  FS: debug logging only if system config file cannot be found
  FS: debug logging only if system config file cannot be found
  Update .factorypath used by annotation processor for benchmarks
  Use  maven-compiler-plugin's release tag instead of source and target
  Don't use deprecated Repository#getAllRefs in Repository
  Don't use deprecated Repository#getAllRefs in FileRepository
  RevListTest: fix warning that method parameter hides field 'git'
  Implement RecordingLogger based on org.slf4j.Logger
  Let ObjectDatabase implement AutoClosable

Change-Id: Ie6b3cfa66b319033d4448dcf20362b753c0e9d7c
2021-11-28 12:07:48 +01:00
Matthias Sohn 7ca091a526 Merge branch 'stable-5.12' into stable-5.13
* stable-5.12:
  FS: debug logging only if system config file cannot be found

Change-Id: I4f6fd422e15361118134c4d1534507e0bd81a172
2021-11-28 12:04:55 +01:00
Matthias Sohn b868f91013 Merge branch 'stable-5.11' into stable-5.12
* stable-5.11:
  FS: debug logging only if system config file cannot be found

Change-Id: Ib32079d58900328f9fc7c91648a1eee9c2bccba5
2021-11-28 12:04:15 +01:00
Matthias Sohn 91233eea56 Merge branch 'stable-5.10' into stable-5.11
* stable-5.10:
  FS: debug logging only if system config file cannot be found

Change-Id: Icd52afc3a74e0d2618181f62515d7e2a8d6c9739
2021-11-28 12:02:45 +01:00
Matthias Sohn 684ec2c316 Merge branch 'stable-5.9' into stable-5.10
* stable-5.9:
  FS: debug logging only if system config file cannot be found

Change-Id: Ib9eb4f4cc44ecc1958c9b6455ab7865913f8b247
2021-11-28 12:02:03 +01:00