Commit Graph

5820 Commits

Author SHA1 Message Date
Thomas Wolf 0f078da4e4 FileBasedConfig: in-process synchronization for load() and save()
On Windows reading and replacing a file via renaming concurrently may
fail either in the reader or in the thread renaming the file. For
renaming, FileUtils.rename() has a last-case fallback in which it
deletes the target file before attempting the rename. If a reader reads
at that moment, it will produce an empty config, and the snapshot and
hash may be wrong because the concurrently running save() may set them.

It's not really possible to do all this in a thread-safe manner without
some synchronization. Add a read-write lock to synchronize readers and
writers to avoid at least that JGit steps on its own feet.

Bug: 451508
Change-Id: I7e5f0f26e02f34ba02dc925a445044d3e21389b4
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-10-14 23:33:11 +02:00
Thomas Wolf f6774fa8ee FileUtils.rename(): better retry handling
When the atomic move fails on Windows, it may be because some other
thread is currently reading the destination. If we delete the file
then, that reader may get an exception, and conclude the file didn't
exist, even though the rename() would re-create it right away.

Try to avoid this from happening frequently by only deleting the
destination on the last retry. Also don't sleep after the last attempt.

Bug: 451508
Change-Id: I95bb4ec59d6e7efb4a7fc8d67f5df301f690257a
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-10-14 23:33:11 +02:00
Thomas Wolf cb46ee3544 FileBasedConfig: ensure correct snapshot if no file
When no config file exists, use FileSnapshot.MISSING_FILE.

Bug: 451508
Change-Id: I8a09cb756a8a4746189da5b3514dfcf81d10b3b1
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-10-14 23:33:11 +02:00
Thomas Wolf 621685d3ca DeleteBranchCommand: update config only at the end
When multiple branches were to be removed, the git config was updated
after each and every branch. Newly do so only once at the end, after all
branches have been deleted.

Because there may be an exception after some branches have already been
deleted, take care to update the config even if an exception is thrown.

Bug: 451508
Change-Id: I645be8a1a59a1476d421e46933c3f7cbd0639fec
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-10-14 23:33:11 +02:00
Thomas Wolf ecf94d1595 Config.removeSection() telling whether it changed the config
Add a variant of unsetSection() that returns whether it did indeed
change the config. This can be used in to skip saving the config if
it was not changed.

Also fix the iteration over the entries: lastWasMatch was never reset,
and thus all empty lines after a match would be removed.

Change-Id: Iea9e84aa74b1e4bb3c89efe3936fa3a8a09532e5
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-10-14 23:33:10 +02:00
Thomas Wolf f93ccb7fd4 RebaseCommand: return correct status on stash apply conflicts
Ensure that also the fast-forward cases return status
STASH_APPLY_CONFLICTS when applying the stash produces conflicts.

Bug: 582526
Change-Id: Ib989ff431dca6e301eb05156ca054a7115fa6ad5
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-10-13 16:45:55 -04:00
Matthias Sohn e4779dab99 Merge branch 'stable-6.7'
* stable-6.7:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I7e0856a5d70d5d155cf6874383ea1f5622d5238a
2023-10-13 21:31:00 +02:00
Matthias Sohn 01dde5c767 Merge branch 'stable-6.6' into stable-6.7
* stable-6.6:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I29241619e6c09933bb856e486f379be10dd609c2
2023-10-13 09:06:21 +02:00
Matthias Sohn b6098c549d Merge branch 'stable-6.5' into stable-6.6
* stable-6.5:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I7272a22451c0de6b4770767e7bb4e24c81518c20
2023-10-13 08:50:48 +02:00
Matthias Sohn 626264a12d Merge branch 'stable-6.4' into stable-6.5
* stable-6.4:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I2951d01f5f4581bee20079508cd8ee6ca8554f1f
2023-10-13 02:07:39 +02:00
Matthias Sohn da60ac9aa6 Merge branch 'stable-6.3' into stable-6.4
* stable-6.3:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I4b94a2b79941c085fa2f62246e8e879aaa85cd3f
2023-10-13 01:33:56 +02:00
Matthias Sohn c59bf16291 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I22b89bf00dcef26b2096d25397aa9a57a745a92b
2023-10-13 01:31:01 +02:00
Matthias Sohn 1618c3e498 Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: Ib4e4fe407dce334c7537bf278baa39db93aa2f09
2023-10-13 00:51:04 +02:00
Matthias Sohn 1175f14c1d Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: I0c9c0b3c206cac03a93b30eda348177a4de35c36
2023-10-13 00:43:31 +02:00
Matthias Sohn add5c14b4d Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  PackConfig: fix @since tags
  Remove unused API problem filters
  Add support for git config repack.packKeptObjects
  Do not exclude objects in locked packs from bitmap processing

Change-Id: Ifeaa4b4f0c5944d4ecd3042be429833ff72b43ed
2023-10-13 00:26:22 +02:00
Matthias Sohn 4d6671b4ce PackConfig: fix @since tags
Change-Id: Ia513f7cdbf3c197e8661720fc804984ff165fc5c
2023-10-13 00:19:12 +02:00
Antonio Barone f103a1d5c6 Add support for git config repack.packKeptObjects
Change Ide3445e652 introduced the `--pack-kept-objects` option to GC for
including the objects contained in the locked packfiles during the
repack phase.

Whilst this allowed to explicitly pass a command line argument to the
jgit gc program, it did not allow the option to be read from
configuration.

Allow the pack kept objects option to be configured exactly as C-Git
documents [1], by introducing a new `repack.packKeptObjects`
configuration.

`repack.packKeptObjects` defaults to `true`, when the
`pack.buildBitmaps` is `true` (which is the default case), `false`
otherwise.

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

Bug: 582292
Change-Id: Ia931667277410d71bc079d27c097a57094299840
2023-10-12 22:51:14 +02:00
Luca Milanesio f5f4bf0ad9 Do not exclude objects in locked packs from bitmap processing
Packfiles having an equivalent .keep file are associated with in-flight
pushes that haven't been completed, with potentially a set of git
objects not yet referenced by a ref.

If the Git client is not up-to-date, it may result in pushing a
packfile, generating a <packfile>.keep on the server, which
may also contain existing commits due to the lack of Git protocol
negotiation in the git-receive-pack.

The Git protocol negotiation is the phase where the client and the
server exchange the list of refs they have for trying to find a common
base and minimise the amount of objects to be transferred.

The repack phase in GC was previously skipping all objects that were
contained in all packfiles having a <packfile>.keep file associated
(aka "locked packfiles"), which did not take into consideration the
fact that excluding the existing commits would have resulted in the
generation of an invalid bitmap file.

The code for excluding the objects in the locked packfiles was written
well before the bitmap was introduced, hence could not consider a use
case that did not exist at that time.

However, when the bitmap was introduced, the exclusion of locked
packfiles was not changed, hence creating a potential problem.
The issue went unnoticed for many years because the bitmap generation
was disabled when JGit noticed any locked packfiles; however, the
bitmaps are enabled again since  Id722e68d9f , and the the issue is now
visible and is impacting the GC repack phase.

Introduce the '--pack-kept-objects' option in GC for including the
objects contained in the locked packfiles during the repack phase,
which is not an issue because of the following:

- If there are any existing commits duplicated in the packfiles
  they will be just considered once anyway because the repack doesn't
  generate duplicates in the output packfile.

- If there are any new commits that do not have any ref pointing to
  them, they will be automatically excluded from the output repacked
  packfile.

The same identical solution is adopted in the C implementation of git
in repack.c.

Because the locked packfile is not pruned, any new commits not pointed
by any refs will remain in the repository and there will not be any
accidental pruning or object loss as it is today before this change.

As a side-effect of this change, it is now potentially possible to still
have duplicate BLOBs after GC when the keep packfile contained existing
objects. However, it is way better to keep the duplication until the
next GC phase rather than omitting existing objects from repacking and,
therefore generating an invalid bitmap and incorrect packfile.

Bug: 582292
Bug: 582455
Change-Id: Ide3445e652fcf256a7912f881cb898897c99b8f8
2023-10-12 22:46:08 +02:00
Ivan Frade 42917767f9 UploadPack: Delay freeing refs in sendPack()
Change [1] set refs to null at the beggining of sendPack claiming they
are not needed anymore, but they are still used few lines below to
hoist referenced objects to the front of the pack. With refs nullified,
the hoist doesn't happened. This hasn't caused any problem so far,
probably because it is just an optimization and the objects are in the
pack anyway.

Move the nullification after the hoisting to keep the optimization and
save the memory.

[1] https://git.eclipse.org/r/c/jgit/jgit/+/161341

Change-Id: I8455249d8482f616af362d3912b718064d473b49
2023-09-28 15:06:40 -07:00
Thomas Wolf e8955fb506 Merge "Fix log level for successful execution of ShutdownHook#notify to debug" 2023-09-26 17:40:52 -04:00
Thomas Wolf 39707c673a ByteBufferInputStream: add missing @since 6.8
Change-Id: I80574a514ade608b87bed2dae79851e53a850c31
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-09-26 23:11:07 +02:00
Matthias Sohn 0ca7438f1b Fix log level for successful execution of ShutdownHook#notify to debug
This is debug trace and shouldn't be logged as a warning.

Change-Id: Ibb24e91e857a05aa6b74b0e2c5b11ab057f6206a
2023-09-26 22:39:27 +02:00
David Ostrovsky b6b1e0a0ad Fix DefaultCharset bug pattern flagged by error prone
See more details in: [1].

[1] https://errorprone.info/bugpattern/DefaultCharset

Change-Id: Ib6aa279f9dcf63dff0672df5b5be3ea72597b1d8
2023-09-25 18:38:12 -04:00
Matthias Sohn a2bce029aa WorkingTreeIterator: directly filter input stream
This way we can avoid to access the byte buffers backing array.
Implement a ByteBufferInputStream to wrap a byte buffer which we can use
to expose the filter result as an input stream.

Change-Id: I461c82090de2562ea9b649b3f953aad4571e3d25
2023-09-25 22:06:13 +02:00
Matthias Sohn 84ced89dc3 [errorprone] Add missing javadoc summary
see https://google.github.io/styleguide/javaguide.html#s7.2-summary-fragment

Change-Id: Iaf4a6b55d4e4c59b7a2da3451164abb1bb47d4a1
2023-09-25 22:06:13 +02:00
Matthias Sohn d56ae55c83 [errorprone] Fix BadImport
See https://errorprone.info/bugpattern/BadImport

Change-Id: Iea98b15862ed0bc4bcad759a7240133769680808
2023-09-25 22:06:13 +02:00
Matthias Sohn a7edc7889c [errorprone] Prevent int expression may overflow
see https://errorprone.info/bugpattern/IntLongMath

Change-Id: Id201b7fc49b953d500e88b95e183127fe40ef6cc
2023-09-25 22:06:13 +02:00
Matthias Sohn 4cfe27dd06 [errorprone] Suppress ByteBufferBackingArray
The byte buffers used here are created by wrapping a byte[].

See https://errorprone.info/bugpattern/ByteBufferBackingArray

Change-Id: Idbc16d5ae4ff9f64b97be07a3cdf190716da191f
2023-09-25 22:06:12 +02:00
Matthias Sohn ac3794bf01 [errorprone] Suppress JavaLangClash to avoid breaking change
Renaming this class is a breaking change. Add a todo to rename it in
next major release.

See https://errorprone.info/bugpattern/JavaLangClash

Change-Id: I3528fd654e30d98f4ea43e71107d83324942141c
2023-09-25 22:06:12 +02:00
Matthias Sohn 7b79feb078 [errorprone] InternalFetchConnection: Suppress CatchAndPrintStackTrace
Handled by the client side pipe handling.

See https://errorprone.info/bugpattern/CatchAndPrintStackTrace

Change-Id: I4ae19dbd0d20d1a75b6587ce7ad36f58cb58dbc2
2023-09-25 22:06:12 +02:00
Matthias Sohn f8d91c2736 [errorprone] Don't swallow exception
See https://errorprone.info/bugpattern/UnusedException

Change-Id: I01568dfa22adbbaa50191aa2d0a445a3c252b803
2023-09-25 22:06:12 +02:00
Matthias Sohn 298f93e989 [errorprone] Fix inconsistent capitalization
See https://errorprone.info/bugpattern/InconsistentCapitalization

Change-Id: I5eaa35a053aca738e180fe22a05fad97877b7e0f
2023-09-25 22:06:12 +02:00
Matthias Sohn e5e54b61b4 [errorprone] PageRef#isStringRef: suppress UnusedMethod
See https://errorprone.info/bugpattern/UnusedMethod

Change-Id: I8c2ca60ac786e20edb7112c268d638aa2488bcb8
2023-09-25 22:06:12 +02:00
Matthias Sohn 37f60c7984 [errorprone] FileReftableStack: fix EqualsUnsafeCast
See https://errorprone.info/bugpattern/EqualsUnsafeCast

Change-Id: I23274c1850061f0574133f52692e125cfa6b92ff
2023-09-25 22:06:12 +02:00
Matthias Sohn bf92bb9bca [errorprone] Suppress MissingSummary for translation bundles
Change-Id: I4da51c7e089366b016a0cc64f768a151c24bc956
2023-09-25 22:06:12 +02:00
Matthias Sohn e23796cbdb [errorprone] CommandLineMergeTool: Remove unused constuctor
See https://errorprone.info/bugpattern/UnusedMethod

Change-Id: I711279d7b81c61111c7c129b3d119affc515fe70
2023-09-25 22:06:12 +02:00
Matthias Sohn 254ffbfb0d [errorprone] SimilarityRenameDetector: suppress IntLongMath
Indexes are positiv.

See https://errorprone.info/bugpattern/IntLongMath

Change-Id: I9ef90b3667f833e2d708ff608929990e0a09036c
2023-09-25 22:06:12 +02:00
Matthias Sohn 7092803ad2 Add comment why protocol list uses WeakReference
Change-Id: I997933cbf1bcae94a6edd9db58c25ec1bb96445f
2023-09-25 22:06:12 +02:00
Matthias Sohn d5bcf199c7 [errorprone] Transport: Suppress ModifyCollectionInEnhancedForLoop
CopyOnWriteArrayList is thread-safe.

See
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/CopyOnWriteArrayList.html
https://errorprone.info/bugpattern/ModifyCollectionInEnhancedForLoop

Change-Id: I97c411e7d171cb39a9c0676b076d48103db6ff88
2023-09-25 22:05:14 +02:00
Matthias Sohn 8302377d91 [errorprone] Rename method parameter to silence InvalidParam
See https://errorprone.info/bugpattern/InvalidParam

Change-Id: I53279bc5e0fc59788d42994be9931857b918414b
2023-09-25 16:15:35 +02:00
Matthias Sohn e6c808600d [errorprone] MyersDiff#main: fix CatchAndPrintStackTrace
Use a PrintWriter similarly like Main#run of org.eclipse.jgit.pgm does.

See https://errorprone.info/bugpattern/CatchAndPrintStackTrace

Change-Id: I8ee34da53d94ddb72b73ae86bfebc3b7f0a3dc04
2023-09-25 16:15:35 +02:00
Matthias Sohn 2d16df1a07 [errorprone] TagCommand: Remove unused parameter of private method
See https://errorprone.info/bugpattern/UnusedVariable

Change-Id: I7e8aae3494ce60dbeb474f6bead0817c36276e69
2023-09-25 16:15:35 +02:00
Matthias Sohn 28d4b34902 [errorprone] PathFilter#getPathsBestEffort: fix ArrayAsKeyOfSetOrMap
See https://errorprone.info/bugpattern/ArrayAsKeyOfSetOrMap

Change-Id: Ia94899bfa68db39f4eb8bfca455c92f5c888647c
2023-09-25 16:15:35 +02:00
Matthias Sohn cda8ffdbb4 [errorprone] DirCacheEntry: suppress JavaInstantGetSecondsGetNano
We get the seconds in the line before we access nanos.

See https://errorprone.info/bugpattern/JavaInstantGetSecondsGetNano

Change-Id: If79690378d5b31d76b06d26e07434d3dff8c92fb
2023-09-25 16:15:34 +02:00
Matthias Sohn d0b9ab1c4a [errorprone] Directly implement functional interface
instead of saving it in a lambda. Prefer to implement the functional
interface method directly and use a method reference instead.

See https://errorprone.info/bugpattern/UnnecessaryLambda

Change-Id: I7f7ebd27cd6354545c157960718d9845882e1732
2023-09-25 16:15:34 +02:00
Matthias Sohn ba2f9affc6 [errorprone] InterruptTimer#terminate: ensure Thread#join succeeds
See https://errorprone.info/bugpattern/ThreadJoinLoop

Change-Id: Ia67a284311a156c22c18575470ee5fbf734e10cc
2023-09-25 16:15:34 +02:00
Matthias Sohn a17e05437b [errorprone] RawParseUtils@parseHexInt64: suppress IntLongMath
see https://errorprone.info/bugpattern/IntLongMath

Change-Id: I71acd5eec252b8c43d7c411f513e502694830727
2023-09-25 16:15:34 +02:00
Matthias Sohn 978cbb84c4 [errorprone] Exceptions should not override #toString
Instead of overriding #toString provide getter for additional
information so that code handling the exception can access it.

See https://errorprone.info/bugpattern/OverrideThrowableToString

Change-Id: Ie577ae9327e0234d55481253f2604b1644ea3f01
2023-09-25 16:15:34 +02:00
Matthias Sohn 1e92426c5a [errorprone] Fix invalid param in javadoc
See https://errorprone.info/bugpattern/InvalidParam

Change-Id: Ife74575bb4080c3386affbfbaf9373931d72c3f3
2023-09-25 16:15:33 +02:00
Matthias Sohn e53c1864e6 [errorprone] FS#searchPath: handle surprising behavior of String#split
See https://errorprone.info/bugpattern/StringSplitter

Change-Id: Ic80f6c53ea96537ed4d046621e774288fced7ce1
2023-09-25 16:15:33 +02:00
Matthias Sohn a94e54ce87 [errorprone] FileStoreAttributes#FUTURE_RUNNER: Fix corePoolSize
[ErroneousThreadPoolConstructorChecker] Thread pool size will never go
beyond corePoolSize if an unbounded queue is used.

see https://errorprone.info/bugpattern/ErroneousThreadPoolConstructorChecker

Change-Id: Icdeaffa05301567611682da86130440f863f2ecc
2023-09-22 23:31:28 +02:00
Matthias Sohn 13bea495c7 [errorprone] Express duration using seconds which is clearer
[CanonicalDuration] Duration can be expressed more clearly with
different units.

see https://errorprone.info/bugpattern/CanonicalDuration

Change-Id: I7f358b5adabee1523e56b109a2c81c74ec523b74
2023-09-22 23:31:28 +02:00
Matthias Sohn ec0657ba01 [errorprone] Use ArrayList instead of LinkedList
[JdkObsolete] It is very rare for LinkedList to out-perform ArrayList or
ArrayDeque.

see https://errorprone.info/bugpattern/JdkObsolete

Change-Id: I13fb953f55fc7b6e007d6fd6a6a1bfd377773588
2023-09-22 23:31:28 +02:00
Matthias Sohn b4f4ae472a [errorprone] AddCommand#filepattern: use a more specific type
Variable type can use a more specific type to convey more information to
callers.
	private Collection<String> filepatterns;
	                  ^
    (see https://errorprone.info/bugpattern/PreferredInterfaceType)

Change-Id: I68b74de65aba3bb849ef508d7dcdd8b85b0ab100
2023-09-22 23:31:28 +02:00
Matthias Sohn ebdf71c117 [errorprone] Suppress UnnecessaryParentheses
for the sake of readability.

See https://errorprone.info/bugpattern/UnnecessaryParentheses

Change-Id: I8444db78c408d4e8bd71bf7e575b9af637900629
2023-09-22 23:31:28 +02:00
Matthias Sohn 4cf246c9ab [errorprone] Remove unnecessary parentheses
see https://errorprone.info/bugpattern/UnnecessaryParentheses

Change-Id: Id08cf0e05b3d35f139fc34e0aa83882555a8a81a
2023-09-22 23:31:27 +02:00
Matthias Sohn 01d6d8a193 DfsPackFile: remove unnecessary @SuppressWarnings("boxing")
Change-Id: I7af999dc4434b7b57bb7e0b84b9b64d24efce220
2023-09-22 17:04:18 +02:00
Matthias Sohn 1924d353ef CommitGraphWriter: Remove unnecessary semicolon
Change-Id: I8ea87d0ff3be8a541e72210f0da7fec1f43008e8
2023-09-22 17:00:15 +02:00
Matthias Sohn 4262150f74 CommitGraphWriter: fix boxing warnings
Change-Id: I35c3a3baadb8d7d73c01252fe4333fa2159722ee
2023-09-22 17:00:15 +02:00
Matthias Sohn c57257bc01 CommitGraphWriter#createCoreChunks: Remove not-thrown exceptions
Change-Id: I0e6f32ed415dc3a0ccadbeae46c979c378ebb0fc
2023-09-22 17:00:14 +02:00
Ivan Frade 2390a89f28 CommitGraphWriter: Decouple Stats from computing bloom filters
The public stats object is created only to be populated by the computation of
bloom filters.

Make the computation return its numbers with the results and copy them
to the stats when needed. This eliminates the side effects from the
computation and makes it easier to add more data to the stats later.

Change-Id: I7a5e55fc3a17f5a294edf3a3b725b2d9c0280a5a
2023-09-21 11:45:04 -07:00
Ivan Frade f1a9d92a30 CommitGraphWriter: Move bloom filter calculation out of createChunks
It looks confusing that the createChunks method calculates bloom
filters.

Make the calculations before and pass the result to the method.

Change-Id: If6e3c0e644f7f940f268ca7266f577f012278ff3
2023-09-20 13:55:11 -07:00
Matthias Sohn 916200e278 [errorprone] Fix wrong comparison which always evaluated to false
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/commitgraph/GraphObjectIndex.java:59:
error: [ComparisonOutOfRange] ints may have a value in the range
-2147483648 to 2147483647; therefore, this comparison to
Integer.MAX_VALUE will always evaluate to false
			if (table[k] > Integer.MAX_VALUE) {
			             ^

See https://errorprone.info/bugpattern/ComparisonOutOfRange

We need to check if variable `uint` of type `long` exceeds the maximum
possible int value before casting it to `int` below.

This was introduced in Ib5c0d6678cb242870a0f5841bd413ad3885e95f6

Change-Id: I675d594f523084be4c1678328cc343065e32d998
2023-09-15 12:12:25 +02:00
Matthias Sohn cf5ec856bd [errorprone] Remove unnecessary comparison
Raised by errorprone:

org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitConfig.java:406: error:
[ComparisonOutOfRange] chars may have a value in the range 0 to 65535;
therefore, this comparison to 0 will always evaluate to true
					if (ch >= 0 && ch < inUse.length) {
					       ^
see https://errorprone.info/bugpattern/ComparisonOutOfRange

Change-Id: I9625aa7894a34dbffd77d39a40c6e285c86b56d5
2023-09-15 11:55:04 +02:00
Matthias Sohn 0acc5aeafa [errorprone] Suppress ImmutableEnumChecker for ShutdownHook
Here we use enum to implement a singleton. Hence suppress the errorprone
error ImmutableEnumChecker.

Change-Id: I21f6ed83c08936dfc9aa591af809e69f3053a050
2023-09-15 00:50:19 +02:00
Matthias Sohn 642f160236 Use ShutdownHook to gracefully handle JVM shutdown
in all classes which already registered their own shutdown hook
- CloneCommand
- GC#PidLock
- FS#FileStoreAttributes
- LocalDiskRepositoryTestCase#Cleanup

Change-Id: I3efc1f83f3cbbf43eeeaaedcd2bee1ef31971a72
2023-09-12 22:43:15 +02:00
Matthias Sohn d4d6c2b5af Add ShutdownHook to cleanup FileLocks on graceful JVM shutdown
This should avoid stale lock files if the JVM is terminated gracefully.

Implement a ShutdownHook which can register/unregister listeners which
need to do some cleanup during graceful JVM shutdown. This hook is
registered as a Java shutdown hook and  when the JVM shuts down
calls #onShutdown of registered listeners using a parallel stream
to let them run concurrently.

See https://docs.oracle.com/javase/8/docs/technotes/guides/lang/hook-design.html

Bug: 582379
Change-Id: I1621dc5f7d9a8c832b6d1b74cbc47578b1c2f0b8
2023-09-12 22:43:15 +02:00
Matthias Sohn f94be665f1 Unregister ShutdownHook when GC#PidLock is closed
Otherwise the JVM will accumulate the ShutdownHook objects of all GCs
run while the JVM is up.

Change-Id: Iadc723a939238a3a75b4ba47f898918eb4554ea3
2023-09-12 22:43:15 +02:00
Thomas Wolf 82c6638c72 RevertCommand: support for inserting a Gerrit change ID
Add a setter for the flag to be passed through to the CommitCommand.

Bug: 342790
Change-Id: I87548d7c2742af8af5ef6105115e3ab9c58d1d9f
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-09-08 22:58:02 +02:00
Ivan Frade 7baa5a157b DfsPackFile: Record index loads only in one place
Each index can be set in the reader from two locations: the dfs cache
callback or the code afterwards. The pack is emitting the load event
in both cases, when the reference is set. This is brittle (right now
it is missing events for BITMAP_INDEX and COMMIT_GRAPH).

Emit the index loaded event only once, after going through the cache
code. The fact that the reference was set in the callback or the main
code is irrelevant. Also, the reader is per-thread, so there shouldn't
be any concurrency involved triggering double counts.

Change-Id: I7f3d078a53741ecc1e81b96353ed8faa8fef3a49
2023-09-08 11:03:38 -07:00
Ivan Frade 30427485dd DfsPackfile: Emit the index load with the index object
The DfsReader#emitIndexLoad expects a reference to the loaded object,
not to its identity hash. This makes listeneres recalculate an
identity hash over an Int object.

Pass the expected reference to the method.

Change-Id: Iee982fdd0169c93c5c7cd9cfe4260a7a82d23f6a
2023-09-08 08:29:04 -07:00
Matthias Sohn 6416de9563 Merge branch 'stable-6.7'
* stable-6.7:
  Prepare 6.7.1-SNAPSHOT builds
  Switch back to wagon-ssh-external
  Fix generation of maven site
  JGit v6.7.0.202309050840-r
  Remove unused API problem filters
  [releng] Bump japicmp base version to 6.6.0.202305301015-r
  Fix list of 3rd party bundles in p2 repo
  Add missing source bundle org.osgi.service.cm.source to target platform
  Prepare 6.6.2-SNAPSHOT builds
  JGit v6.6.1.202309021850-r
  Checkout: better directory handling
  Document commit-graph options supported by JGit
  Fix warning raised for local variable hiding DfsPackFile#index
  Suppress boxing warnings in DfsPackFile
  Remove unused API problem filters
  Suppress boxing warnings in tests
  Fix warning about empty block
  Update mockito to 5.5.0
  Update byte-buddy to 1.14.7
  Prepare 6.7.0-SNAPSHOT builds
  JGit v6.7.0.202308301100-rc1

Change-Id: Ib2a1000ead5ca6cf3816e9e9496ad5d92f4dc963
2023-09-07 02:24:08 +02:00
Ivan Frade 4f5afe9d7c CommitGraphWriter: Make the list of chunks immutable
The chunk list is calculated before start writing and it is
immutable afterwards.

Make this explicit using an unmodifiable list for the chunks.

Change-Id: I4a5cfb1f3d06a9393d8d93a3fac3c128cf3faec0
2023-09-05 11:25:54 -07:00
Ivan Frade f90f0717a0 CommitGraphWriter: Assert written bytes
The final size of the commit-graph is known before-hand. As a
safety-net, assert the written size matches the expected value.

Change-Id: Ib0828a7cce5bacb33f6325ee3910f4eebd95eb8c
2023-09-05 10:30:23 -07:00
Matthias Sohn 7a6e852745 Merge branch 'stable-6.6' into stable-6.7
* stable-6.6:
  Prepare 6.6.2-SNAPSHOT builds
  JGit v6.6.1.202309021850-r
  Checkout: better directory handling

Change-Id: Ice82d68b2d343a5fac214807cdb369e486481aab
2023-09-03 02:16:04 +02:00
Thomas Wolf 9072103f3b Checkout: better directory handling
When checking out a file into the working tree ensure that all parent
directories of the file below the working tree root are actually
directories and do exist before we try to create the file.

When multiple files are to be checked out (or even a whole tree), this
may check the same directories over and over again. Asking the file
system every time for file attributes is a potentially expensive
operation. As a remedy, introduce an in-memory cache of directory
states for a particular check-out operation.

Apply the same fix also in the ResolveMerger, which may also check out
files, and also in the PatchApplier. In PatchApplier, also validate
paths.

Change-Id: Ie12864c54c9f901a2ccee7caddec73027f353111
Signed-off-by: Thomas Wolf <twolf@apache.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2023-09-03 00:16:26 +02:00
Matthias Sohn 96934c9a80 Merge branch 'master' into stable-6.7
* master:
  CommitGraphWriter: throw exception on unknown chunk

Change-Id: Iaa0c563917c4195fccd57f5e6839a37008c9b808
2023-09-02 09:40:19 +02:00
Ivan Frade 13c8dacae5 CommitGraphWriter: throw exception on unknown chunk
CommitGraphWriter first defines the chunks and then writes them. If at
write time a chunk is unknown, it is ignored. This is brittle: if
somebody adds a chunk to the header but not to the actual writing, the
commit-graph is broken and there is no error reported anywhere.

Throw exception if at write time a chunk is unknown. This can only
happen by a coding error in the writer.

Change-Id: Iade677bb6ce368b6941b75a21c622917afa3b751
2023-09-01 11:39:40 -07:00
Matthias Sohn a40abb0a19 Fix warning raised for local variable hiding DfsPackFile#index
Change-Id: I45cd3be942f798d51af1e024ceb3f4d26c7af324
2023-08-31 15:13:34 +02:00
Matthias Sohn 4f3db912ce Suppress boxing warnings in DfsPackFile
Change-Id: I4b5a0a7ffdeaf7d7839787aa8b98ea9c72f70850
2023-08-31 15:11:50 +02:00
Thomas Wolf a2f326b762 Handle global git config $XDG_CONFIG_HOME/git/config
C git uses this alternate fallback location if the file exists and
~/.gitconfig does not. Implement this also for JGit.

If both files exist, reading behavior is as if the XDG config was
inserted between the HOME config and the system config. Writing
behaviour is different: all changes will be applied only in the HOME
config. Updates will occur in the XDG config only if the HOME config
does not exist.

This is consistent with the behavior of C git; compare [1], especially
the sections on FILES and SCOPES, and the description of the --global
option.

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

Bug: 581875
Change-Id: I2460b9aa963fd2811ed8a5b77b05107d916f2b44
Signed-off-by: Thomas Wolf <twolf@apache.org>
2023-08-28 22:05:47 +02:00
Jörg Kubitz 0d5e017612 IO: use JDK convenience methods
The benefit is that certain InputStreams can override the default
implementation for performance reasons.

Change-Id: I4c924157ec0f0ec63b0eca7cdbdc9325af24cab6
2023-08-28 21:50:14 +02:00
Martin Fick e7a09e316d Introduce core.packedIndexGitUseStrongRefs config key
Introduce a core.packedIndexGitUseStrongRefs configuration key, which
defaults to true so that the current behavior does not change. However,
setting it to false allows soft references to be used for Pack indices
instead of strong references so that they can be garbage collected when
there is memory pressure.

Pack objects can be large when associated with pack files with large
object counts, and this memory is not really accounted for or tracked by
the WindowCache and it can be very substantial at times, especially with
many large object count projects. A particularly problematic use case is
Gerrit's ls-projects command which loads very little data in the
WindowCache via ByteWindows, but ends up loading and holding many entire
indices in memory, sometimes even after the ByteWindows for their Pack
objects have already been garbage collected since they won't get cleared
until after a new ByteWindow is loaded. By using SoftReferences, single
use indices can get cleared when there is memory pressure and OOMs can
be easily avoided, drastically reducing the amount of memory required to
perform an ls-projects on large sites with many projects and large
object counts.

On one of our test sites, an ls-projects command with strong index
references requires more than 66GB of heap to complete successfully,
with soft index references it requires less than 23GB.

Change-Id: I3cb3df52f4ce1b8c554d378807218f199077d80b
Signed-off-by: Martin Fick <quic_mfick@quicinc.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2023-08-26 16:16:43 +02:00
Jonathan Tan f8f5979aa2 Merge "DfsGarbageCollector: provide commit graph stats" 2023-08-21 13:07:51 -04:00
Ivan Frade 9919a9faaf DfsReader: Make PackLoadListener interface visible to subclasses
A subclass cannot implement a listener with the default access.

Make the interface protected. Not public because so far only
subclasses are interested in this interface. We can widen the
visibility later if needed.

Change-Id: I54e5c0ef1312dfe2fa660bc8fb54e2be35c0f6df
2023-08-18 11:43:10 -07:00
Jonathan Tan 551ca93cc6 DfsGarbageCollector: provide commit graph stats
Provide commit graph stats in the same way that we provide reftable
stats.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Change-Id: Ib80c892a26f9b552bc90f3cbe7da83b02ffebdfd
2023-08-17 15:41:02 -07:00
Ivan Frade 6f73336939 DfsGarbageCollector: put only GC commits into the commit graph
GC puts all commits reachable from heads and tags into the GC pack,
and commits reachable only from other refs (e.g. refs/changes) into
GC_REST. The commit-graph contains all commits in GC and GC_REST. This
produces too big commit graphs in some repos, beating the purpose of
loading the index.

Limit the commit graph to commits reachable from heads and tags
(i.e. commits in the GC pack).

Change-Id: I4962faea5a726d2ea3e548af0aeae370a6cc8588
2023-08-16 13:31:55 -07:00
Ivan Frade b4b8f05eea DfsReader: Expose when indices are loaded
We want to measure the data used to serve a request. As a first step,
we want to know how many indices are accessed during the request and
their sizes.

Expose an interface in DfsReader to announce when an index is loaded
into the reader, i.e. when its reference is set.

The interface is more flexible to implementors (what/how to collect)
than the existing DfsReaderIOStats object.

Change-Id: I56f7658fde1758efaf869fa779d11b533a81a0a7
2023-08-03 23:53:13 +02:00
Matthias Sohn abe155ea94 Merge branch 'stable-6.6' into stable-6.7
* stable-6.6:
  Update to Tycho 4.0.1
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: I7294c21748897eb3f94eeffbda944b62e3206c0d
2023-08-03 10:17:22 +02:00
Matthias Sohn b4c3a5da0d Merge branch 'stable-6.5' into stable-6.6
* stable-6.5:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: Id2e49252a9dc268210c9439848e77604885371aa
2023-08-03 10:14:45 +02:00
Matthias Sohn 82e277c813 Merge branch 'stable-6.4' into stable-6.5
* stable-6.4:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: Idb6dd6160e023673e3650653a15f6b1c540de96e
2023-08-03 01:55:12 +02:00
Matthias Sohn 76dfbb2ccd Merge branch 'stable-6.3' into stable-6.4
* stable-6.3:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: I0bccc36d9cc9a36f1be9b1562df35ce3a0e95eee
2023-08-03 01:51:36 +02:00
Matthias Sohn 05ded4ee62 Merge branch 'stable-6.2' into stable-6.3
* stable-6.2:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: I589ed444b5cbfc5b073cac91323e2cc97ab98087
2023-08-03 01:37:43 +02:00
Matthias Sohn 6483c7d209 Merge branch 'stable-6.1' into stable-6.2
* stable-6.1:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: I5b16c3b613a95b7f28c8f6ac0b20c4c593759cea
2023-08-03 01:28:07 +02:00
Matthias Sohn 55ff4ed9de Merge branch 'stable-6.0' into stable-6.1
* stable-6.0:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: Ib08037f6055dac1776e38cfb4ff8c88a50ad3e60
2023-08-03 01:19:21 +02:00
Matthias Sohn c7849fbb19 Merge branch 'stable-5.13' into stable-6.0
* stable-5.13:
  Add verification in GcKeepFilesTest that bitmaps are generated
  Express the explicit intention of creating bitmaps in GC
  GC: prune all packfiles after the loosen phase
  Prepare 5.13.3-SNAPSHOT builds
  JGit v5.13.2.202306221912-r

Change-Id: I1f50995d9d9c592ec0e02a04e0e409440b49f9f3
2023-08-03 01:17:17 +02:00
Matthias Sohn 24b6a35d30 Add missing @since tags
This was missed in c353645a09

Change-Id: I4ae5b13bd7bfd09c113d91ece727a26706660826
2023-08-02 00:19:02 +02:00
Han-Wen NIenhuys d96a91e77e Merge "Merge: Add diff3 style merge conflict formatter." 2023-08-01 13:08:34 -04:00
Nitzan Gur-Furman c353645a09 Move footer-line parsing methods from RevCommit to FooterLine
This allows extracting footers from a messages not associated with a
commit.

The public API of RevCommit is kept intact.

Change-Id: I5809c23df7b7d49641a4be3a26d6f987d3d57c9b
Bug: Google b/287891316
2023-08-01 10:37:24 +02:00
Haamed Gheibi 462c57ec8d Merge: Add diff3 style merge conflict formatter.
Add base section to the merge conflict hunks.

Bug: 442284
Change-Id: I977b43e7dd8119d6b72d11f09c4e8ec241750383
2023-07-31 11:57:28 -07:00