|
|
@@ -94,6 +94,8 @@ import org.eclipse.jgit.util.IO; |
|
|
|
import org.eclipse.jgit.util.RawParseUtils; |
|
|
|
import org.eclipse.jgit.util.SystemReader; |
|
|
|
import org.eclipse.jgit.util.io.SafeBufferedOutputStream; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
/** |
|
|
|
* Represents a Git repository. |
|
|
@@ -104,6 +106,8 @@ import org.eclipse.jgit.util.io.SafeBufferedOutputStream; |
|
|
|
* This class is thread-safe. |
|
|
|
*/ |
|
|
|
public abstract class Repository implements AutoCloseable { |
|
|
|
private static Logger LOG = LoggerFactory.getLogger(Repository.class); |
|
|
|
|
|
|
|
private static final ListenerList globalListeners = new ListenerList(); |
|
|
|
|
|
|
|
/** @return the global listener list observing all events in this JVM. */ |
|
|
@@ -866,12 +870,24 @@ public abstract class Repository implements AutoCloseable { |
|
|
|
|
|
|
|
/** Decrement the use count, and maybe close resources. */ |
|
|
|
public void close() { |
|
|
|
if (useCnt.decrementAndGet() == 0) { |
|
|
|
int newCount = useCnt.decrementAndGet(); |
|
|
|
if (newCount == 0) { |
|
|
|
if (RepositoryCache.isCached(this)) { |
|
|
|
closedAt.set(System.currentTimeMillis()); |
|
|
|
} else { |
|
|
|
doClose(); |
|
|
|
} |
|
|
|
} else if (newCount == -1) { |
|
|
|
// should not happen, only log when useCnt became negative to |
|
|
|
// minimize number of log entries |
|
|
|
LOG.warn(JGitText.get().corruptUseCnt); |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
IllegalStateException e = new IllegalStateException(); |
|
|
|
LOG.debug("", e); //$NON-NLS-1$ |
|
|
|
} |
|
|
|
if (RepositoryCache.isCached(this)) { |
|
|
|
closedAt.set(System.currentTimeMillis()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|