/* * Copyright (C) 2017, Google Inc. and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at * https://www.eclipse.org/org/documents/edl-v10.php. * * SPDX-License-Identifier: BSD-3-Clause */ package org.eclipse.jgit.internal.storage.reftable; import static org.eclipse.jgit.internal.storage.reftable.ReftableConstants.MAX_BLOCK_SIZE; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Repository; /** * Configuration used by a reftable writer when constructing the stream. */ public class ReftableConfig { private int refBlockSize = 4 << 10; private int logBlockSize; private int restartInterval; private int maxIndexLevels; private boolean alignBlocks = true; private boolean indexObjects = true; /** * Create a default configuration. */ public ReftableConfig() { } /** * Create a configuration honoring the repository's settings. * * @param db * the repository to read settings from. The repository is not * retained by the new configuration, instead its settings are * copied during the constructor. */ public ReftableConfig(Repository db) { fromConfig(db.getConfig()); } /** * Create a configuration honoring settings in a * {@link org.eclipse.jgit.lib.Config}. * * @param cfg * the source to read settings from. The source is not retained * by the new configuration, instead its settings are copied * during the constructor. */ public ReftableConfig(Config cfg) { fromConfig(cfg); } /** * Copy an existing configuration to a new instance. * * @param cfg * the source configuration to copy from. */ public ReftableConfig(ReftableConfig cfg) { this.refBlockSize = cfg.refBlockSize; this.logBlockSize = cfg.logBlockSize; this.restartInterval = cfg.restartInterval; this.maxIndexLevels = cfg.maxIndexLevels; this.alignBlocks = cfg.alignBlocks; this.indexObjects = cfg.indexObjects; } /** * Get desired output block size for references, in bytes. * * @return desired output block size for references, in bytes. */ public int getRefBlockSize() { return refBlockSize; } /** * Set desired output block size for references, in bytes. * * @param szBytes * desired output block size for references, in bytes. */ public void setRefBlockSize(int szBytes) { if (szBytes > MAX_BLOCK_SIZE) { throw new IllegalArgumentException(); } refBlockSize = Math.max(0, szBytes); } /** * Get desired output block size for log entries, in bytes. * * @return desired output block size for log entries, in bytes. If 0 the * writer will default to {@code 2 * getRefBlockSize()}. */ public int getLogBlockSize() { return logBlockSize; } /** * Set desired output block size for log entries, in bytes. * * @param szBytes * desired output block size for log entries, in bytes. If 0 will * default to {@code 2 * getRefBlockSize()}. */ public void setLogBlockSize(int szBytes) { if (szBytes > MAX_BLOCK_SIZE) { throw new IllegalArgumentException(); } logBlockSize = Math.max(0, szBytes); } /** * Get number of references between binary search markers. * * @return number of references between binary search markers. */ public int getRestartInterval() { return restartInterval; } /** *
Setter for the field restartInterval
.