]> source.dussan.org Git - jgit.git/commitdiff
FileBasedConfig: ensure correct snapshot if no file 21/204921/1
authorThomas Wolf <twolf@apache.org>
Sun, 8 Oct 2023 19:53:06 +0000 (21:53 +0200)
committerThomas Wolf <twolf@apache.org>
Sat, 14 Oct 2023 21:33:11 +0000 (23:33 +0200)
When no config file exists, use FileSnapshot.MISSING_FILE.

Bug: 451508
Change-Id: I8a09cb756a8a4746189da5b3514dfcf81d10b3b1
Signed-off-by: Thomas Wolf <twolf@apache.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

index cedc4d6cc9074c97252b0b0609d7d8ff43c2b12f..c80505d70981dca8afa1291bda47840ffbda8e77 100644 (file)
@@ -117,13 +117,11 @@ public class FileBasedConfig extends StoredConfig {
        @Override
        public void load() throws IOException, ConfigInvalidException {
                try {
-                       FileSnapshot[] lastSnapshot = { null };
                        Boolean wasRead = FileUtils.readWithRetries(getFile(), f -> {
                                final FileSnapshot oldSnapshot = snapshot;
                                final FileSnapshot newSnapshot;
                                // don't use config in this snapshot to avoid endless recursion
                                newSnapshot = FileSnapshot.saveNoConfig(f);
-                               lastSnapshot[0] = newSnapshot;
                                final byte[] in = IO.readFully(f);
                                final ObjectId newHash = hash(in);
                                if (hash.equals(newHash)) {
@@ -149,7 +147,7 @@ public class FileBasedConfig extends StoredConfig {
                        });
                        if (wasRead == null) {
                                clear();
-                               snapshot = lastSnapshot[0];
+                               snapshot = FileSnapshot.MISSING_FILE;
                        }
                        exists.set(wasRead != null);
                } catch (IOException e) {