From 827849017dc7a6ae269a37727d1e28e18b5aa966 Mon Sep 17 00:00:00 2001
From: kylezhao <kylezhao@tencent.com>
Date: Mon, 27 Mar 2023 14:48:31 +0800
Subject: Ensure FileCommitGraph scans commit-graph file if it already exists

When commit-graph file already exists in the repository, a newly
created FileCommitGraph didn't scan CommitGraph until the file was
modified, resulting in wrong result.

Change-Id: Ic85676f2d3b6a88f3ae28d4065729926b6fb2f23
Signed-off-by: kylezhao <kylezhao@tencent.com>
---
 .../src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'org.eclipse.jgit')

diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java
index 3e411a125a..44429a7786 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileCommitGraph.java
@@ -85,10 +85,10 @@ public class FileCommitGraph {
 		private final CommitGraph graph;
 
 		GraphSnapshot(@NonNull File file) {
-			this(file, FileSnapshot.save(file), null);
+			this(file, null, null);
 		}
 
-		GraphSnapshot(@NonNull File file, @NonNull FileSnapshot snapshot,
+		GraphSnapshot(@NonNull File file, FileSnapshot snapshot,
 				CommitGraph graph) {
 			this.file = file;
 			this.snapshot = snapshot;
@@ -104,7 +104,7 @@ public class FileCommitGraph {
 				// commit-graph file didn't exist
 				return this;
 			}
-			if (!snapshot.isModified(file)) {
+			if (snapshot != null && !snapshot.isModified(file)) {
 				// commit-graph file was not modified
 				return this;
 			}
-- 
cgit v1.2.3