From cb46ee3544536525446317a98b5cb02377f0cfa5 Mon Sep 17 00:00:00 2001 From: Thomas Wolf Date: Sun, 8 Oct 2023 21:53:06 +0200 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/storage/file/FileBasedConfig.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java index cedc4d6cc9..c80505d709 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java @@ -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) { -- 2.39.5