]> source.dussan.org Git - gitblit.git/commitdiff
Reset dashboard and activity commit cache on branch REWIND or DELETE
authorJames Moger <james.moger@gitblit.com>
Tue, 16 Jul 2013 13:35:31 +0000 (09:35 -0400)
committerJames Moger <james.moger@gitblit.com>
Tue, 16 Jul 2013 13:35:31 +0000 (09:35 -0400)
releases.moxie
src/main/java/com/gitblit/git/ReceiveHook.java
src/main/java/com/gitblit/utils/CommitCache.java

index 711bf146e629fdb5b4d9092f94ccd8936910ed57..bff4eb179130c4cd959751699dba3d4418e5548a 100644 (file)
@@ -13,6 +13,7 @@ r18: {
        - Gitblit-as-viewer with no repository urls failed to display summary page (issue 269)
        - Fixed missing model class dependencies in Gitblit Manager build
        - Fix for IE10 compatability mode
+       - Reset dashboard and activity commit cache on branch REWIND or DELETE
     changes: ~
     additions: ~
     dependencyChanges: ~
index e0b779879f38b99de0afc80ac19612ce7dede39d..d75a2385b82deadf0e2d1d4cb079b542153648d7 100644 (file)
@@ -36,6 +36,7 @@ import org.eclipse.jgit.transport.ReceivePack;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import com.gitblit.Constants;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
@@ -44,6 +45,7 @@ import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.ClientLogger;\r
+import com.gitblit.utils.CommitCache;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.RefLogUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -186,6 +188,21 @@ public class ReceiveHook implements PreReceiveHook, PostReceiveHook {
                                return;\r
                        }\r
                }\r
+               \r
+               // reset branch commit cache on REWIND and DELETE\r
+               for (ReceiveCommand cmd : commands) {\r
+                       String ref = cmd.getRefName();\r
+                       if (ref.startsWith(Constants.R_HEADS)) {\r
+                               switch (cmd.getType()) {\r
+                               case UPDATE_NONFASTFORWARD:\r
+                               case DELETE:\r
+                                       CommitCache.instance().clear(repository.name, ref);\r
+                                       break;\r
+                               default:\r
+                                       break;\r
+                               }\r
+                       }\r
+               }\r
 \r
                Set<String> scripts = new LinkedHashSet<String>();\r
                scripts.addAll(GitBlit.self().getPreReceiveScriptsInherited(repository));\r
index 9db5f0c9567c7b41ebe88cbda57f29c27119cc17..e84506ea9f37f4c62ba0f86567771601be35bf23 100644 (file)
@@ -109,6 +109,23 @@ public class CommitCache {
                }
        }
        
+       /**
+        * Clears the commit cache for a specific branch of a specific repository.
+        * 
+        * @param repositoryName
+        * @param branch
+        */
+       public void clear(String repositoryName, String branch) {
+               String repoKey = repositoryName.toLowerCase();
+               ObjectCache<List<RepositoryCommit>> repoCache = cache.get(repoKey);
+               if (repoCache != null) {
+                       List<RepositoryCommit> commits = repoCache.remove(branch.toLowerCase());
+                       if (!ArrayUtils.isEmpty(commits)) {
+                               logger.info(MessageFormat.format("{0}:{1} commit cache cleared", repositoryName, branch));
+                       }
+               }
+       }
+       
        /**
         * Get all commits for the specified repository:branch that are in the cache.
         *