| | |
| | | */
|
| | | package com.gitblit.service;
|
| | |
|
| | | import java.lang.reflect.Field;
|
| | | import java.text.MessageFormat;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | |
| | | import java.util.Properties;
|
| | | import java.util.concurrent.ConcurrentHashMap;
|
| | | import java.util.concurrent.atomic.AtomicBoolean;
|
| | | import java.util.concurrent.atomic.AtomicInteger;
|
| | |
|
| | | import org.eclipse.jgit.api.GarbageCollectCommand;
|
| | | import org.eclipse.jgit.api.Git;
|
| | |
| | |
|
| | | import com.gitblit.IStoredSettings;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.Keys.git;
|
| | | import com.gitblit.manager.IRepositoryManager;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.FileUtils;
|
| | |
| | | continue;
|
| | | }
|
| | |
|
| | | if (!isRepositoryIdle(repository)) {
|
| | | if (!repositoryManager.isIdle(repository)) {
|
| | | logger.debug(MessageFormat.format("GCExecutor is skipping {0} because it is not idle", repositoryName));
|
| | | continue;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | running.set(false);
|
| | | }
|
| | |
|
| | | private boolean isRepositoryIdle(Repository repository) {
|
| | | try {
|
| | | // Read the use count.
|
| | | // An idle use count is 2:
|
| | | // +1 for being in the cache
|
| | | // +1 for the repository parameter in this method
|
| | | Field useCnt = Repository.class.getDeclaredField("useCnt");
|
| | | useCnt.setAccessible(true);
|
| | | int useCount = ((AtomicInteger) useCnt.get(repository)).get();
|
| | | return useCount == 2;
|
| | | } catch (Exception e) {
|
| | | logger.warn(MessageFormat
|
| | | .format("Failed to reflectively determine use count for repository {0}",
|
| | | repository.getDirectory().getPath()), e);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | }
|