@SuppressWarnings("unchecked") private DfsBlockCache(DfsBlockCacheConfig cfg) { tableSize = tableSize(cfg); if (tableSize < 1) throw new IllegalArgumentException(JGitText.get().tSizeMustBeGreaterOrEqual1); table = new AtomicReferenceArray<>(tableSize); loadLocks = new ReentrantLock[cfg.getConcurrencyLevel()]; for (int i = 0; i < loadLocks.length; i++) loadLocks[i] = new ReentrantLock(true /* fair */); maxBytes = cfg.getBlockLimit(); maxStreamThroughCache = (long) (maxBytes * cfg.getStreamRatio()); blockSize = cfg.getBlockSize(); blockSizeShift = Integer.numberOfTrailingZeros(blockSize); clockLock = new ReentrantLock(true /* fair */); String none = ""; //$NON-NLS-1$ clockHand = new Ref<>( DfsStreamKey.of(new DfsRepositoryDescription(none), none, null), -1, 0, null); clockHand.next = clockHand; statHit = new AtomicReference<>(newCounters()); statMiss = new AtomicReference<>(newCounters()); statEvict = new AtomicReference<>(newCounters()); liveBytes = new AtomicReference<>(newCounters()); }
/** {@inheritDoc} */ @SuppressWarnings("nls") @Override public String toString() { return "DfsRepositoryDescription[" + getRepositoryName() + "]"; } }
@Override public boolean equals(Object o) { if (o instanceof ByteArrayDfsStreamKey) { ByteArrayDfsStreamKey k = (ByteArrayDfsStreamKey) o; return hash == k.hash && repo.equals(k.repo) && Arrays.equals(name, k.name); } return false; } }
ByteArrayDfsStreamKey(DfsRepositoryDescription repo, byte[] name, @Nullable PackExt ext) { super(repo.hashCode() * 31 + Arrays.hashCode(name), ext); this.repo = repo; this.name = name; }
ByteArrayDfsStreamKey(DfsRepositoryDescription repo, byte[] name, @Nullable PackExt ext) { super(repo.hashCode() * 31 + Arrays.hashCode(name), ext); this.repo = repo; this.name = name; }
/** {@inheritDoc} */ @Override public B setup() throws IllegalArgumentException, IOException { super.setup(); if (getReaderOptions() == null) setReaderOptions(new DfsReaderOptions()); if (getRepositoryDescription() == null) setRepositoryDescription(new DfsRepositoryDescription()); return self(); }
/** {@inheritDoc} */ @Override public boolean equals(Object b) { if (b instanceof DfsRepositoryDescription){ String name = getRepositoryName(); String otherName = ((DfsRepositoryDescription) b).getRepositoryName(); return name != null ? name.equals(otherName) : this == b; } return false; }
/** {@inheritDoc} */ @Override public boolean equals(Object b) { if (b instanceof DfsPackDescription) { DfsPackDescription desc = (DfsPackDescription) b; return packName.equals(desc.packName) && getRepositoryDescription().equals(desc.getRepositoryDescription()); } return false; }
@Nonnull public static GfsConfiguration inMemoryRepo() { return repo(new InMemoryRepository(new DfsRepositoryDescription())); }
/** {@inheritDoc} */ @Override public int hashCode() { if (getRepositoryName() != null) return getRepositoryName().hashCode(); return System.identityHashCode(this); }
@Override public boolean equals(Object o) { if (o instanceof ByteArrayDfsStreamKey) { ByteArrayDfsStreamKey k = (ByteArrayDfsStreamKey) o; return hash == k.hash && repo.equals(k.repo) && Arrays.equals(name, k.name); } return false; } }
@Nonnull public static GfsConfiguration inMemoryRepo() { return repo(new InMemoryRepository(new DfsRepositoryDescription())); }
private static String computeKey(Repository repo) { if (repo instanceof DfsRepository) { DfsRepository dfs = (DfsRepository) repo; return dfs.getDescription().getRepositoryName(); } if (repo.getDirectory() != null) { return repo.getDirectory().toURI().toString(); } throw new IllegalArgumentException(); } }
@Override public boolean equals(Object b) { if (b instanceof DfsPackDescription) { DfsPackDescription desc = (DfsPackDescription) b; return packName.equals(desc.packName) && getRepositoryDescription().equals(desc.getRepositoryDescription()); } return false; }
public TestRepository(boolean bare) { super(new DfsRepositoryDescription()); File mockLocation = new File(System.getProperty("java.io.tmpdir")); directory = bare ? mockLocation : new File(mockLocation, DOT_GIT); workTree = bare ? null : mockLocation; }
/** {@inheritDoc} */ @Override public synchronized String createNonce(Repository repo, long timestamp) throws IllegalStateException { String path; if (repo instanceof DfsRepository) { path = ((DfsRepository) repo).getDescription().getRepositoryName(); } else { File directory = repo.getDirectory(); if (directory != null) { path = directory.getPath(); } else { throw new IllegalStateException(); } } String input = path + ":" + String.valueOf(timestamp); //$NON-NLS-1$ byte[] rawHmac = mac.doFinal(input.getBytes(UTF_8)); return Long.toString(timestamp) + "-" + toHex(rawHmac); //$NON-NLS-1$ }
/** {@inheritDoc} */ @Override public boolean equals(Object b) { if (b instanceof DfsPackDescription) { DfsPackDescription desc = (DfsPackDescription) b; return packName.equals(desc.packName) && getRepositoryDescription().equals(desc.getRepositoryDescription()); } return false; }
public static Repository emptyRepository() throws IOException { final Repository repository = new InMemoryRepository(new DfsRepositoryDescription(null)); repository.create(); return repository; } }
@SuppressWarnings("nls") @Override public String toString() { return "DfsRepositoryDescription[" + getRepositoryName() + "]"; } }
@SuppressWarnings("unchecked") private DfsBlockCache(DfsBlockCacheConfig cfg) { tableSize = tableSize(cfg); if (tableSize < 1) throw new IllegalArgumentException(JGitText.get().tSizeMustBeGreaterOrEqual1); table = new AtomicReferenceArray<>(tableSize); loadLocks = new ReentrantLock[cfg.getConcurrencyLevel()]; for (int i = 0; i < loadLocks.length; i++) loadLocks[i] = new ReentrantLock(true /* fair */); maxBytes = cfg.getBlockLimit(); maxStreamThroughCache = (long) (maxBytes * cfg.getStreamRatio()); blockSize = cfg.getBlockSize(); blockSizeShift = Integer.numberOfTrailingZeros(blockSize); clockLock = new ReentrantLock(true /* fair */); String none = ""; //$NON-NLS-1$ clockHand = new Ref<>( DfsStreamKey.of(new DfsRepositoryDescription(none), none, null), -1, 0, null); clockHand.next = clockHand; statHit = new AtomicReference<>(newCounters()); statMiss = new AtomicReference<>(newCounters()); statEvict = new AtomicReference<>(newCounters()); liveBytes = new AtomicReference<>(newCounters()); }