]> source.dussan.org Git - jgit.git/commitdiff
Honor trustFolderStats also when reading packed-refs 15/112015/1
authorChristian Halstrick <christian.halstrick@sap.com>
Tue, 14 Nov 2017 16:20:02 +0000 (17:20 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Tue, 21 Nov 2017 20:21:22 +0000 (21:21 +0100)
Then list of packed refs was cached in RefDirectory based on mtime of
the packed-refs file. This may fail on NFS when attributes are cached.
A cached mtime of the packed-refs file could cause JGit to trust the
cached content of this file and to overlook that the file is modified.

Honor the config option trustFolderStats and always read the packed-refs
content if the option is false. By default this option is set to true
and this fix is not active.

Change-Id: I2b65cfaa8f4aba2efbf8a5e865d3f09f927e2eec

org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

index 108065913a6d3b34fd824ad41115e9d2c183c76d..cd98539102976636774bc03f211f9b8cbd90ad40 100644 (file)
@@ -80,6 +80,7 @@ import org.eclipse.jgit.errors.MissingObjectException;
 import org.eclipse.jgit.errors.ObjectWritingException;
 import org.eclipse.jgit.events.RefsChangedEvent;
 import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.lib.ConfigConstants;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectIdRef;
@@ -765,14 +766,20 @@ public class RefDirectory extends RefDatabase {
        }
 
        private PackedRefList getPackedRefs() throws IOException {
+               boolean trustFolderStat = getRepository().getConfig().getBoolean(
+                               ConfigConstants.CONFIG_CORE_SECTION,
+                               ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
+
                final PackedRefList curList = packedRefs.get();
-               if (!curList.snapshot.isModified(packedRefsFile))
+               if (trustFolderStat && !curList.snapshot.isModified(packedRefsFile)) {
                        return curList;
+               }
 
                final PackedRefList newList = readPackedRefs();
                if (packedRefs.compareAndSet(curList, newList)
-                               && !curList.id.equals(newList.id))
+                               && !curList.id.equals(newList.id)) {
                        modCnt.incrementAndGet();
+               }
                return newList;
        }