1 /* 2 * Copyright (C) 2008-2010, Google Inc. 3 * Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com> 4 * and other copyright owners as documented in the project's IP log. 5 * 6 * This program and the accompanying materials are made available 7 * under the terms of the Eclipse Distribution License v1.0 which 8 * accompanies this distribution, is reproduced below, and is 9 * available at http://www.eclipse.org/org/documents/edl-v10.php 10 * 11 * All rights reserved. 12 * 13 * Redistribution and use in source and binary forms, with or 14 * without modification, are permitted provided that the following 15 * conditions are met: 16 * 17 * - Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 20 * - Redistributions in binary form must reproduce the above 21 * copyright notice, this list of conditions and the following 22 * disclaimer in the documentation and/or other materials provided 23 * with the distribution. 24 * 25 * - Neither the name of the Eclipse Foundation, Inc. nor the 26 * names of its contributors may be used to endorse or promote 27 * products derived from this software without specific prior 28 * written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 31 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 32 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 33 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 35 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 37 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 39 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 41 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 42 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 */ 44 45 package org.eclipse.jgit.storage.pack; 46 47 import java.util.concurrent.Executor; 48 import java.util.zip.Deflater; 49 50 import org.eclipse.jgit.internal.storage.file.PackIndexWriter; 51 import org.eclipse.jgit.lib.Config; 52 import org.eclipse.jgit.lib.Repository; 53 54 /** 55 * Configuration used by a pack writer when constructing the stream. 56 * 57 * A configuration may be modified once created, but should not be modified 58 * while it is being used by a PackWriter. If a configuration is not modified it 59 * is safe to share the same configuration instance between multiple concurrent 60 * threads executing different PackWriters. 61 */ 62 public class PackConfig { 63 /** 64 * Default value of deltas reuse option: {@value} 65 * 66 * @see #setReuseDeltas(boolean) 67 */ 68 public static final boolean DEFAULT_REUSE_DELTAS = true; 69 70 /** 71 * Default value of objects reuse option: {@value} 72 * 73 * @see #setReuseObjects(boolean) 74 */ 75 public static final boolean DEFAULT_REUSE_OBJECTS = true; 76 77 /** 78 * Default value of delta compress option: {@value} 79 * 80 * @see #setDeltaCompress(boolean) 81 */ 82 public static final boolean DEFAULT_DELTA_COMPRESS = true; 83 84 /** 85 * Default value of delta base as offset option: {@value} 86 * 87 * @see #setDeltaBaseAsOffset(boolean) 88 */ 89 public static final boolean DEFAULT_DELTA_BASE_AS_OFFSET = false; 90 91 /** 92 * Default value of maximum delta chain depth: {@value} 93 * 94 * @see #setMaxDeltaDepth(int) 95 */ 96 public static final int DEFAULT_MAX_DELTA_DEPTH = 50; 97 98 /** 99 * Default window size during packing: {@value} 100 * 101 * @see #setDeltaSearchWindowSize(int) 102 */ 103 public static final int DEFAULT_DELTA_SEARCH_WINDOW_SIZE = 10; 104 105 /** 106 * Default big file threshold: {@value} 107 * 108 * @see #setBigFileThreshold(int) 109 */ 110 public static final int DEFAULT_BIG_FILE_THRESHOLD = 50 * 1024 * 1024; 111 112 /** 113 * Default delta cache size: {@value} 114 * 115 * @see #setDeltaCacheSize(long) 116 */ 117 public static final long DEFAULT_DELTA_CACHE_SIZE = 50 * 1024 * 1024; 118 119 /** 120 * Default delta cache limit: {@value} 121 * 122 * @see #setDeltaCacheLimit(int) 123 */ 124 public static final int DEFAULT_DELTA_CACHE_LIMIT = 100; 125 126 /** 127 * Default index version: {@value} 128 * 129 * @see #setIndexVersion(int) 130 */ 131 public static final int DEFAULT_INDEX_VERSION = 2; 132 133 /** 134 * Default value of the build bitmaps option: {@value} 135 * 136 * @see #setBuildBitmaps(boolean) 137 * @since 3.0 138 */ 139 public static final boolean DEFAULT_BUILD_BITMAPS = true; 140 141 /** 142 * Default count of most recent commits to select for bitmaps. Only applies 143 * when bitmaps are enabled: {@value} 144 * 145 * @see #setBitmapContiguousCommitCount(int) 146 * @since 4.2 147 */ 148 public static final int DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT = 100; 149 150 /** 151 * Count at which the span between selected commits changes from 152 * "bitmapRecentCommitSpan" to "bitmapDistantCommitSpan". Only applies when 153 * bitmaps are enabled: {@value} 154 * 155 * @see #setBitmapRecentCommitCount(int) 156 * @since 4.2 157 */ 158 public static final int DEFAULT_BITMAP_RECENT_COMMIT_COUNT = 20000; 159 160 /** 161 * Default spacing between commits in recent history when selecting commits 162 * for bitmaps. Only applies when bitmaps are enabled: {@value} 163 * 164 * @see #setBitmapRecentCommitSpan(int) 165 * @since 4.2 166 */ 167 public static final int DEFAULT_BITMAP_RECENT_COMMIT_SPAN = 100; 168 169 /** 170 * Default spacing between commits in distant history when selecting commits 171 * for bitmaps. Only applies when bitmaps are enabled: {@value} 172 * 173 * @see #setBitmapDistantCommitSpan(int) 174 * @since 4.2 175 */ 176 public static final int DEFAULT_BITMAP_DISTANT_COMMIT_SPAN = 5000; 177 178 /** 179 * Default count of branches required to activate inactive branch commit 180 * selection. If the number of branches is less than this then bitmaps for 181 * the entire commit history of all branches will be created, otherwise 182 * branches marked as "inactive" will have coverage for only partial 183 * history: {@value} 184 * 185 * @see #setBitmapExcessiveBranchCount(int) 186 * @since 4.2 187 */ 188 public static final int DEFAULT_BITMAP_EXCESSIVE_BRANCH_COUNT = 100; 189 190 /** 191 * Default age at which a branch is considered inactive. Age is taken as the 192 * number of days ago that the most recent commit was made to a branch. Only 193 * affects bitmap processing if bitmaps are enabled and the 194 * "excessive branch count" has been exceeded: {@value} 195 * 196 * @see #setBitmapInactiveBranchAgeInDays(int) 197 * @since 4.2 198 */ 199 public static final int DEFAULT_BITMAP_INACTIVE_BRANCH_AGE_IN_DAYS = 90; 200 201 private int compressionLevel = Deflater.DEFAULT_COMPRESSION; 202 203 private boolean reuseDeltas = DEFAULT_REUSE_DELTAS; 204 205 private boolean reuseObjects = DEFAULT_REUSE_OBJECTS; 206 207 private boolean deltaBaseAsOffset = DEFAULT_DELTA_BASE_AS_OFFSET; 208 209 private boolean deltaCompress = DEFAULT_DELTA_COMPRESS; 210 211 private int maxDeltaDepth = DEFAULT_MAX_DELTA_DEPTH; 212 213 private int deltaSearchWindowSize = DEFAULT_DELTA_SEARCH_WINDOW_SIZE; 214 215 private long deltaSearchMemoryLimit; 216 217 private long deltaCacheSize = DEFAULT_DELTA_CACHE_SIZE; 218 219 private int deltaCacheLimit = DEFAULT_DELTA_CACHE_LIMIT; 220 221 private int bigFileThreshold = DEFAULT_BIG_FILE_THRESHOLD; 222 223 private int threads; 224 225 private Executor executor; 226 227 private int indexVersion = DEFAULT_INDEX_VERSION; 228 229 private boolean buildBitmaps = DEFAULT_BUILD_BITMAPS; 230 231 private int bitmapContiguousCommitCount = DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT; 232 233 private int bitmapRecentCommitCount = DEFAULT_BITMAP_RECENT_COMMIT_COUNT; 234 235 private int bitmapRecentCommitSpan = DEFAULT_BITMAP_RECENT_COMMIT_SPAN; 236 237 private int bitmapDistantCommitSpan = DEFAULT_BITMAP_DISTANT_COMMIT_SPAN; 238 239 private int bitmapExcessiveBranchCount = DEFAULT_BITMAP_EXCESSIVE_BRANCH_COUNT; 240 241 private int bitmapInactiveBranchAgeInDays = DEFAULT_BITMAP_INACTIVE_BRANCH_AGE_IN_DAYS; 242 243 private boolean cutDeltaChains; 244 245 /** Create a default configuration. */ 246 public PackConfig() { 247 // Fields are initialized to defaults. 248 } 249 250 /** 251 * Create a configuration honoring the repository's settings. 252 * 253 * @param db 254 * the repository to read settings from. The repository is not 255 * retained by the new configuration, instead its settings are 256 * copied during the constructor. 257 */ 258 public PackConfig(Repository db) { 259 fromConfig(db.getConfig()); 260 } 261 262 /** 263 * Create a configuration honoring settings in a {@link Config}. 264 * 265 * @param cfg 266 * the source to read settings from. The source is not retained 267 * by the new configuration, instead its settings are copied 268 * during the constructor. 269 */ 270 public PackConfig(Config cfg) { 271 fromConfig(cfg); 272 } 273 274 /** 275 * Copy an existing configuration to a new instance. 276 * 277 * @param cfg 278 * the source configuration to copy from. 279 */ 280 public PackConfig(PackConfig cfg) { 281 this.compressionLevel = cfg.compressionLevel; 282 this.reuseDeltas = cfg.reuseDeltas; 283 this.reuseObjects = cfg.reuseObjects; 284 this.deltaBaseAsOffset = cfg.deltaBaseAsOffset; 285 this.deltaCompress = cfg.deltaCompress; 286 this.maxDeltaDepth = cfg.maxDeltaDepth; 287 this.deltaSearchWindowSize = cfg.deltaSearchWindowSize; 288 this.deltaSearchMemoryLimit = cfg.deltaSearchMemoryLimit; 289 this.deltaCacheSize = cfg.deltaCacheSize; 290 this.deltaCacheLimit = cfg.deltaCacheLimit; 291 this.bigFileThreshold = cfg.bigFileThreshold; 292 this.threads = cfg.threads; 293 this.executor = cfg.executor; 294 this.indexVersion = cfg.indexVersion; 295 this.buildBitmaps = cfg.buildBitmaps; 296 this.bitmapContiguousCommitCount = cfg.bitmapContiguousCommitCount; 297 this.bitmapRecentCommitCount = cfg.bitmapRecentCommitCount; 298 this.bitmapRecentCommitSpan = cfg.bitmapRecentCommitSpan; 299 this.bitmapDistantCommitSpan = cfg.bitmapDistantCommitSpan; 300 this.bitmapExcessiveBranchCount = cfg.bitmapExcessiveBranchCount; 301 this.bitmapInactiveBranchAgeInDays = cfg.bitmapInactiveBranchAgeInDays; 302 this.cutDeltaChains = cfg.cutDeltaChains; 303 } 304 305 /** 306 * Check whether to reuse deltas existing in repository. 307 * 308 * Default setting: {@value #DEFAULT_REUSE_DELTAS} 309 * 310 * @return true if object is configured to reuse deltas; false otherwise. 311 */ 312 public boolean isReuseDeltas() { 313 return reuseDeltas; 314 } 315 316 /** 317 * Set reuse deltas configuration option for the writer. 318 * 319 * When enabled, writer will search for delta representation of object in 320 * repository and use it if possible. Normally, only deltas with base to 321 * another object existing in set of objects to pack will be used. The 322 * exception however is thin-packs where the base object may exist on the 323 * other side. 324 * 325 * When raw delta data is directly copied from a pack file, its checksum is 326 * computed to verify the data is not corrupt. 327 * 328 * Default setting: {@value #DEFAULT_REUSE_DELTAS} 329 * 330 * @param reuseDeltas 331 * boolean indicating whether or not try to reuse deltas. 332 */ 333 public void setReuseDeltas(boolean reuseDeltas) { 334 this.reuseDeltas = reuseDeltas; 335 } 336 337 /** 338 * Checks whether to reuse existing objects representation in repository. 339 * 340 * Default setting: {@value #DEFAULT_REUSE_OBJECTS} 341 * 342 * @return true if writer is configured to reuse objects representation from 343 * pack; false otherwise. 344 */ 345 public boolean isReuseObjects() { 346 return reuseObjects; 347 } 348 349 /** 350 * Set reuse objects configuration option for the writer. 351 * 352 * If enabled, writer searches for compressed representation in a pack file. 353 * If possible, compressed data is directly copied from such a pack file. 354 * Data checksum is verified. 355 * 356 * Default setting: {@value #DEFAULT_REUSE_OBJECTS} 357 * 358 * @param reuseObjects 359 * boolean indicating whether or not writer should reuse existing 360 * objects representation. 361 */ 362 public void setReuseObjects(boolean reuseObjects) { 363 this.reuseObjects = reuseObjects; 364 } 365 366 /** 367 * True if writer can use offsets to point to a delta base. 368 * 369 * If true the writer may choose to use an offset to point to a delta base 370 * in the same pack, this is a newer style of reference that saves space. 371 * False if the writer has to use the older (and more compatible style) of 372 * storing the full ObjectId of the delta base. 373 * 374 * Default setting: {@value #DEFAULT_DELTA_BASE_AS_OFFSET} 375 * 376 * @return true if delta base is stored as an offset; false if it is stored 377 * as an ObjectId. 378 */ 379 public boolean isDeltaBaseAsOffset() { 380 return deltaBaseAsOffset; 381 } 382 383 /** 384 * Set writer delta base format. 385 * 386 * Delta base can be written as an offset in a pack file (new approach 387 * reducing file size) or as an object id (legacy approach, compatible with 388 * old readers). 389 * 390 * Default setting: {@value #DEFAULT_DELTA_BASE_AS_OFFSET} 391 * 392 * @param deltaBaseAsOffset 393 * boolean indicating whether delta base can be stored as an 394 * offset. 395 */ 396 public void setDeltaBaseAsOffset(boolean deltaBaseAsOffset) { 397 this.deltaBaseAsOffset = deltaBaseAsOffset; 398 } 399 400 /** 401 * Check whether the writer will create new deltas on the fly. 402 * 403 * Default setting: {@value #DEFAULT_DELTA_COMPRESS} 404 * 405 * @return true if the writer will create a new delta when either 406 * {@link #isReuseDeltas()} is false, or no suitable delta is 407 * available for reuse. 408 */ 409 public boolean isDeltaCompress() { 410 return deltaCompress; 411 } 412 413 /** 414 * Set whether or not the writer will create new deltas on the fly. 415 * 416 * Default setting: {@value #DEFAULT_DELTA_COMPRESS} 417 * 418 * @param deltaCompress 419 * true to create deltas when {@link #isReuseDeltas()} is false, 420 * or when a suitable delta isn't available for reuse. Set to 421 * false to write whole objects instead. 422 */ 423 public void setDeltaCompress(boolean deltaCompress) { 424 this.deltaCompress = deltaCompress; 425 } 426 427 /** 428 * Get maximum depth of delta chain set up for the writer. 429 * 430 * Generated chains are not longer than this value. 431 * 432 * Default setting: {@value #DEFAULT_MAX_DELTA_DEPTH} 433 * 434 * @return maximum delta chain depth. 435 */ 436 public int getMaxDeltaDepth() { 437 return maxDeltaDepth; 438 } 439 440 /** 441 * Set up maximum depth of delta chain for the writer. 442 * 443 * Generated chains are not longer than this value. Too low value causes low 444 * compression level, while too big makes unpacking (reading) longer. 445 * 446 * Default setting: {@value #DEFAULT_MAX_DELTA_DEPTH} 447 * 448 * @param maxDeltaDepth 449 * maximum delta chain depth. 450 */ 451 public void setMaxDeltaDepth(int maxDeltaDepth) { 452 this.maxDeltaDepth = maxDeltaDepth; 453 } 454 455 /** 456 * @return true if existing delta chains should be cut at 457 * {@link #getMaxDeltaDepth()}. Default is false, allowing existing 458 * chains to be of any length. 459 * @since 3.0 460 */ 461 public boolean getCutDeltaChains() { 462 return cutDeltaChains; 463 } 464 465 /** 466 * Enable cutting existing delta chains at {@link #getMaxDeltaDepth()}. 467 * 468 * By default this is disabled and existing chains are kept at whatever 469 * length a prior packer was configured to create. This allows objects to be 470 * packed one with a large depth (for example 250), and later to quickly 471 * repack the repository with a shorter depth (such as 50), but reusing the 472 * complete delta chains created by the earlier 250 depth. 473 * 474 * @param cut 475 * true to cut existing chains. 476 * @since 3.0 477 */ 478 public void setCutDeltaChains(boolean cut) { 479 cutDeltaChains = cut; 480 } 481 482 /** 483 * Get the number of objects to try when looking for a delta base. 484 * 485 * This limit is per thread, if 4 threads are used the actual memory used 486 * will be 4 times this value. 487 * 488 * Default setting: {@value #DEFAULT_DELTA_SEARCH_WINDOW_SIZE} 489 * 490 * @return the object count to be searched. 491 */ 492 public int getDeltaSearchWindowSize() { 493 return deltaSearchWindowSize; 494 } 495 496 /** 497 * Set the number of objects considered when searching for a delta base. 498 * 499 * Default setting: {@value #DEFAULT_DELTA_SEARCH_WINDOW_SIZE} 500 * 501 * @param objectCount 502 * number of objects to search at once. Must be at least 2. 503 */ 504 public void setDeltaSearchWindowSize(int objectCount) { 505 if (objectCount <= 2) 506 setDeltaCompress(false); 507 else 508 deltaSearchWindowSize = objectCount; 509 } 510 511 /** 512 * Get maximum number of bytes to put into the delta search window. 513 * 514 * Default setting is 0, for an unlimited amount of memory usage. Actual 515 * memory used is the lower limit of either this setting, or the sum of 516 * space used by at most {@link #getDeltaSearchWindowSize()} objects. 517 * 518 * This limit is per thread, if 4 threads are used the actual memory limit 519 * will be 4 times this value. 520 * 521 * @return the memory limit. 522 */ 523 public long getDeltaSearchMemoryLimit() { 524 return deltaSearchMemoryLimit; 525 } 526 527 /** 528 * Set the maximum number of bytes to put into the delta search window. 529 * 530 * Default setting is 0, for an unlimited amount of memory usage. If the 531 * memory limit is reached before {@link #getDeltaSearchWindowSize()} the 532 * window size is temporarily lowered. 533 * 534 * @param memoryLimit 535 * Maximum number of bytes to load at once, 0 for unlimited. 536 */ 537 public void setDeltaSearchMemoryLimit(long memoryLimit) { 538 deltaSearchMemoryLimit = memoryLimit; 539 } 540 541 /** 542 * Get the size of the in-memory delta cache. 543 * 544 * This limit is for the entire writer, even if multiple threads are used. 545 * 546 * Default setting: {@value #DEFAULT_DELTA_CACHE_SIZE} 547 * 548 * @return maximum number of bytes worth of delta data to cache in memory. 549 * If 0 the cache is infinite in size (up to the JVM heap limit 550 * anyway). A very tiny size such as 1 indicates the cache is 551 * effectively disabled. 552 */ 553 public long getDeltaCacheSize() { 554 return deltaCacheSize; 555 } 556 557 /** 558 * Set the maximum number of bytes of delta data to cache. 559 * 560 * During delta search, up to this many bytes worth of small or hard to 561 * compute deltas will be stored in memory. This cache speeds up writing by 562 * allowing the cached entry to simply be dumped to the output stream. 563 * 564 * Default setting: {@value #DEFAULT_DELTA_CACHE_SIZE} 565 * 566 * @param size 567 * number of bytes to cache. Set to 0 to enable an infinite 568 * cache, set to 1 (an impossible size for any delta) to disable 569 * the cache. 570 */ 571 public void setDeltaCacheSize(long size) { 572 deltaCacheSize = size; 573 } 574 575 /** 576 * Maximum size in bytes of a delta to cache. 577 * 578 * Default setting: {@value #DEFAULT_DELTA_CACHE_LIMIT} 579 * 580 * @return maximum size (in bytes) of a delta that should be cached. 581 */ 582 public int getDeltaCacheLimit() { 583 return deltaCacheLimit; 584 } 585 586 /** 587 * Set the maximum size of a delta that should be cached. 588 * 589 * During delta search, any delta smaller than this size will be cached, up 590 * to the {@link #getDeltaCacheSize()} maximum limit. This speeds up writing 591 * by allowing these cached deltas to be output as-is. 592 * 593 * Default setting: {@value #DEFAULT_DELTA_CACHE_LIMIT} 594 * 595 * @param size 596 * maximum size (in bytes) of a delta to be cached. 597 */ 598 public void setDeltaCacheLimit(int size) { 599 deltaCacheLimit = size; 600 } 601 602 /** 603 * Get the maximum file size that will be delta compressed. 604 * 605 * Files bigger than this setting will not be delta compressed, as they are 606 * more than likely already highly compressed binary data files that do not 607 * delta compress well, such as MPEG videos. 608 * 609 * Default setting: {@value #DEFAULT_BIG_FILE_THRESHOLD} 610 * 611 * @return the configured big file threshold. 612 */ 613 public int getBigFileThreshold() { 614 return bigFileThreshold; 615 } 616 617 /** 618 * Set the maximum file size that should be considered for deltas. 619 * 620 * Default setting: {@value #DEFAULT_BIG_FILE_THRESHOLD} 621 * 622 * @param bigFileThreshold 623 * the limit, in bytes. 624 */ 625 public void setBigFileThreshold(int bigFileThreshold) { 626 this.bigFileThreshold = bigFileThreshold; 627 } 628 629 /** 630 * Get the compression level applied to objects in the pack. 631 * 632 * Default setting: {@value java.util.zip.Deflater#DEFAULT_COMPRESSION} 633 * 634 * @return current compression level, see {@link java.util.zip.Deflater}. 635 */ 636 public int getCompressionLevel() { 637 return compressionLevel; 638 } 639 640 /** 641 * Set the compression level applied to objects in the pack. 642 * 643 * Default setting: {@value java.util.zip.Deflater#DEFAULT_COMPRESSION} 644 * 645 * @param level 646 * compression level, must be a valid level recognized by the 647 * {@link java.util.zip.Deflater} class. 648 */ 649 public void setCompressionLevel(int level) { 650 compressionLevel = level; 651 } 652 653 /** 654 * Get the number of threads used during delta compression. 655 * 656 * Default setting: 0 (auto-detect processors) 657 * 658 * @return number of threads used for delta compression. 0 will auto-detect 659 * the threads to the number of available processors. 660 */ 661 public int getThreads() { 662 return threads; 663 } 664 665 /** 666 * Set the number of threads to use for delta compression. 667 * 668 * During delta compression, if there are enough objects to be considered 669 * the writer will start up concurrent threads and allow them to compress 670 * different sections of the repository concurrently. 671 * 672 * An application thread pool can be set by {@link #setExecutor(Executor)}. 673 * If not set a temporary pool will be created by the writer, and torn down 674 * automatically when compression is over. 675 * 676 * Default setting: 0 (auto-detect processors) 677 * 678 * @param threads 679 * number of threads to use. If <= 0 the number of available 680 * processors for this JVM is used. 681 */ 682 public void setThreads(int threads) { 683 this.threads = threads; 684 } 685 686 /** @return the preferred thread pool to execute delta search on. */ 687 public Executor getExecutor() { 688 return executor; 689 } 690 691 /** 692 * Set the executor to use when using threads. 693 * 694 * During delta compression if the executor is non-null jobs will be queued 695 * up on it to perform delta compression in parallel. Aside from setting the 696 * executor, the caller must set {@link #setThreads(int)} to enable threaded 697 * delta search. 698 * 699 * @param executor 700 * executor to use for threads. Set to null to create a temporary 701 * executor just for the writer. 702 */ 703 public void setExecutor(Executor executor) { 704 this.executor = executor; 705 } 706 707 /** 708 * Get the pack index file format version this instance creates. 709 * 710 * Default setting: {@value #DEFAULT_INDEX_VERSION} 711 * 712 * @return the index version, the special version 0 designates the oldest 713 * (most compatible) format available for the objects. 714 * @see PackIndexWriter 715 */ 716 public int getIndexVersion() { 717 return indexVersion; 718 } 719 720 /** 721 * Set the pack index file format version this instance will create. 722 * 723 * Default setting: {@value #DEFAULT_INDEX_VERSION} 724 * 725 * @param version 726 * the version to write. The special version 0 designates the 727 * oldest (most compatible) format available for the objects. 728 * @see PackIndexWriter 729 */ 730 public void setIndexVersion(int version) { 731 indexVersion = version; 732 } 733 734 /** 735 * True if writer is allowed to build bitmaps for indexes. 736 * 737 * Default setting: {@value #DEFAULT_BUILD_BITMAPS} 738 * 739 * @return true if delta base is the writer can choose to output an index 740 * with bitmaps. 741 * @since 3.0 742 */ 743 public boolean isBuildBitmaps() { 744 return buildBitmaps; 745 } 746 747 /** 748 * Set writer to allow building bitmaps for supported pack files. 749 * 750 * Index files can include bitmaps to speed up future ObjectWalks. 751 * 752 * Default setting: {@value #DEFAULT_BUILD_BITMAPS} 753 * 754 * @param buildBitmaps 755 * boolean indicating whether bitmaps may be included in the 756 * index. 757 * @since 3.0 758 */ 759 public void setBuildBitmaps(boolean buildBitmaps) { 760 this.buildBitmaps = buildBitmaps; 761 } 762 763 /** 764 * Get the count of most recent commits for which to build bitmaps. 765 * 766 * Default setting: {@value #DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT} 767 * 768 * @return the count of most recent commits for which to build bitmaps 769 * @since 4.2 770 */ 771 public int getBitmapContiguousCommitCount() { 772 return bitmapContiguousCommitCount; 773 } 774 775 /** 776 * Set the count of most recent commits for which to build bitmaps. 777 * 778 * Default setting: {@value #DEFAULT_BITMAP_CONTIGUOUS_COMMIT_COUNT} 779 * 780 * @param count 781 * the count of most recent commits for which to build bitmaps 782 * @since 4.2 783 */ 784 public void setBitmapContiguousCommitCount(int count) { 785 bitmapContiguousCommitCount = count; 786 } 787 788 /** 789 * Get the count at which to switch from "bitmapRecentCommitSpan" to 790 * "bitmapDistantCommitSpan". 791 * 792 * Default setting: {@value #DEFAULT_BITMAP_RECENT_COMMIT_COUNT} 793 * 794 * @return the count for switching between recent and distant spans 795 * @since 4.2 796 */ 797 public int getBitmapRecentCommitCount() { 798 return bitmapRecentCommitCount; 799 } 800 801 /** 802 * Set the count at which to switch from "bitmapRecentCommitSpan" to 803 * "bitmapDistantCommitSpan". 804 * 805 * Default setting: {@value #DEFAULT_BITMAP_RECENT_COMMIT_COUNT} 806 * 807 * @param count 808 * the count for switching between recent and distant spans 809 * @since 4.2 810 */ 811 public void setBitmapRecentCommitCount(int count) { 812 bitmapRecentCommitCount = count; 813 } 814 815 /** 816 * Get the span of commits when building bitmaps for recent history. 817 * 818 * Default setting: {@value #DEFAULT_BITMAP_RECENT_COMMIT_SPAN} 819 * 820 * @return the span of commits when building bitmaps for recent history 821 * @since 4.2 822 */ 823 public int getBitmapRecentCommitSpan() { 824 return bitmapRecentCommitSpan; 825 } 826 827 /** 828 * Set the span of commits when building bitmaps for recent history. 829 * 830 * Default setting: {@value #DEFAULT_BITMAP_RECENT_COMMIT_SPAN} 831 * 832 * @param span 833 * the span of commits when building bitmaps for recent history 834 * @since 4.2 835 */ 836 public void setBitmapRecentCommitSpan(int span) { 837 bitmapRecentCommitSpan = span; 838 } 839 840 /** 841 * Get the span of commits when building bitmaps for distant history. 842 * 843 * Default setting: {@value #DEFAULT_BITMAP_DISTANT_COMMIT_SPAN} 844 * 845 * @return the span of commits when building bitmaps for distant history 846 * @since 4.2 847 */ 848 public int getBitmapDistantCommitSpan() { 849 return bitmapDistantCommitSpan; 850 } 851 852 /** 853 * Set the span of commits when building bitmaps for distant history. 854 * 855 * Default setting: {@value #DEFAULT_BITMAP_DISTANT_COMMIT_SPAN} 856 * 857 * @param span 858 * the span of commits when building bitmaps for distant history 859 * @since 4.2 860 */ 861 public void setBitmapDistantCommitSpan(int span) { 862 bitmapDistantCommitSpan = span; 863 } 864 865 /** 866 * Get the count of branches deemed "excessive". If the count of branches in 867 * a repository exceeds this number and bitmaps are enabled, "inactive" 868 * branches will have fewer bitmaps than "active" branches. 869 * 870 * Default setting: {@value #DEFAULT_BITMAP_EXCESSIVE_BRANCH_COUNT} 871 * 872 * @return the count of branches deemed "excessive" 873 * @since 4.2 874 */ 875 public int getBitmapExcessiveBranchCount() { 876 return bitmapExcessiveBranchCount; 877 } 878 879 /** 880 * Set the count of branches deemed "excessive". If the count of branches in 881 * a repository exceeds this number and bitmaps are enabled, "inactive" 882 * branches will have fewer bitmaps than "active" branches. 883 * 884 * Default setting: {@value #DEFAULT_BITMAP_EXCESSIVE_BRANCH_COUNT} 885 * 886 * @param count 887 * the count of branches deemed "excessive" 888 * @since 4.2 889 */ 890 public void setBitmapExcessiveBranchCount(int count) { 891 bitmapExcessiveBranchCount = count; 892 } 893 894 /** 895 * Get the the age in days that marks a branch as "inactive". 896 * 897 * Default setting: {@value #DEFAULT_BITMAP_INACTIVE_BRANCH_AGE_IN_DAYS} 898 * 899 * @return the age in days that marks a branch as "inactive" 900 * @since 4.2 901 */ 902 public int getBitmapInactiveBranchAgeInDays() { 903 return bitmapInactiveBranchAgeInDays; 904 } 905 906 /** 907 * Set the the age in days that marks a branch as "inactive". 908 * 909 * Default setting: {@value #DEFAULT_BITMAP_INACTIVE_BRANCH_AGE_IN_DAYS} 910 * 911 * @param ageInDays 912 * the age in days that marks a branch as "inactive" 913 * @since 4.2 914 */ 915 public void setBitmapInactiveBranchAgeInDays(int ageInDays) { 916 bitmapInactiveBranchAgeInDays = ageInDays; 917 } 918 919 /** 920 * Update properties by setting fields from the configuration. 921 * 922 * If a property's corresponding variable is not defined in the supplied 923 * configuration, then it is left unmodified. 924 * 925 * @param rc 926 * configuration to read properties from. 927 */ 928 public void fromConfig(final Config rc) { 929 setMaxDeltaDepth(rc.getInt("pack", "depth", getMaxDeltaDepth())); //$NON-NLS-1$ //$NON-NLS-2$ 930 setDeltaSearchWindowSize(rc.getInt( 931 "pack", "window", getDeltaSearchWindowSize())); //$NON-NLS-1$ //$NON-NLS-2$ 932 setDeltaSearchMemoryLimit(rc.getLong( 933 "pack", "windowmemory", getDeltaSearchMemoryLimit())); //$NON-NLS-1$ //$NON-NLS-2$ 934 setDeltaCacheSize(rc.getLong( 935 "pack", "deltacachesize", getDeltaCacheSize())); //$NON-NLS-1$ //$NON-NLS-2$ 936 setDeltaCacheLimit(rc.getInt( 937 "pack", "deltacachelimit", getDeltaCacheLimit())); //$NON-NLS-1$ //$NON-NLS-2$ 938 setCompressionLevel(rc.getInt("pack", "compression", //$NON-NLS-1$ //$NON-NLS-2$ 939 rc.getInt("core", "compression", getCompressionLevel()))); //$NON-NLS-1$ //$NON-NLS-2$ 940 setIndexVersion(rc.getInt("pack", "indexversion", getIndexVersion())); //$NON-NLS-1$ //$NON-NLS-2$ 941 setBigFileThreshold(rc.getInt( 942 "core", "bigfilethreshold", getBigFileThreshold())); //$NON-NLS-1$ //$NON-NLS-2$ 943 setThreads(rc.getInt("pack", "threads", getThreads())); //$NON-NLS-1$ //$NON-NLS-2$ 944 945 // These variables aren't standardized 946 // 947 setReuseDeltas(rc.getBoolean("pack", "reusedeltas", isReuseDeltas())); //$NON-NLS-1$ //$NON-NLS-2$ 948 setReuseObjects( 949 rc.getBoolean("pack", "reuseobjects", isReuseObjects())); //$NON-NLS-1$ //$NON-NLS-2$ 950 setDeltaCompress( 951 rc.getBoolean("pack", "deltacompression", isDeltaCompress())); //$NON-NLS-1$ //$NON-NLS-2$ 952 setCutDeltaChains( 953 rc.getBoolean("pack", "cutdeltachains", getCutDeltaChains())); //$NON-NLS-1$ //$NON-NLS-2$ 954 setBuildBitmaps( 955 rc.getBoolean("pack", "buildbitmaps", isBuildBitmaps())); //$NON-NLS-1$ //$NON-NLS-2$ 956 setBitmapContiguousCommitCount( 957 rc.getInt("pack", "bitmapcontiguouscommitcount", //$NON-NLS-1$ //$NON-NLS-2$ 958 getBitmapContiguousCommitCount())); 959 setBitmapRecentCommitCount(rc.getInt("pack", "bitmaprecentcommitcount", //$NON-NLS-1$ //$NON-NLS-2$ 960 getBitmapRecentCommitCount())); 961 setBitmapRecentCommitSpan(rc.getInt("pack", "bitmaprecentcommitspan", //$NON-NLS-1$ //$NON-NLS-2$ 962 getBitmapRecentCommitSpan())); 963 setBitmapDistantCommitSpan(rc.getInt("pack", "bitmapdistantcommitspan", //$NON-NLS-1$ //$NON-NLS-2$ 964 getBitmapDistantCommitSpan())); 965 setBitmapExcessiveBranchCount(rc.getInt("pack", //$NON-NLS-1$ 966 "bitmapexcessivebranchcount", getBitmapExcessiveBranchCount())); //$NON-NLS-1$ 967 setBitmapInactiveBranchAgeInDays( 968 rc.getInt("pack", "bitmapinactivebranchageindays", //$NON-NLS-1$ //$NON-NLS-2$ 969 getBitmapInactiveBranchAgeInDays())); 970 } 971 972 public String toString() { 973 final StringBuilder b = new StringBuilder(); 974 b.append("maxDeltaDepth=").append(getMaxDeltaDepth()); //$NON-NLS-1$ 975 b.append(", deltaSearchWindowSize=").append(getDeltaSearchWindowSize()); //$NON-NLS-1$ 976 b.append(", deltaSearchMemoryLimit=") //$NON-NLS-1$ 977 .append(getDeltaSearchMemoryLimit()); 978 b.append(", deltaCacheSize=").append(getDeltaCacheSize()); //$NON-NLS-1$ 979 b.append(", deltaCacheLimit=").append(getDeltaCacheLimit()); //$NON-NLS-1$ 980 b.append(", compressionLevel=").append(getCompressionLevel()); //$NON-NLS-1$ 981 b.append(", indexVersion=").append(getIndexVersion()); //$NON-NLS-1$ 982 b.append(", bigFileThreshold=").append(getBigFileThreshold()); //$NON-NLS-1$ 983 b.append(", threads=").append(getThreads()); //$NON-NLS-1$ 984 b.append(", reuseDeltas=").append(isReuseDeltas()); //$NON-NLS-1$ 985 b.append(", reuseObjects=").append(isReuseObjects()); //$NON-NLS-1$ 986 b.append(", deltaCompress=").append(isDeltaCompress()); //$NON-NLS-1$ 987 b.append(", buildBitmaps=").append(isBuildBitmaps()); //$NON-NLS-1$ 988 b.append(", bitmapContiguousCommitCount=") //$NON-NLS-1$ 989 .append(getBitmapContiguousCommitCount()); 990 b.append(", bitmapRecentCommitCount=") //$NON-NLS-1$ 991 .append(getBitmapRecentCommitCount()); 992 b.append(", bitmapRecentCommitSpan=") //$NON-NLS-1$ 993 .append(getBitmapRecentCommitSpan()); 994 b.append(", bitmapDistantCommitSpan=") //$NON-NLS-1$ 995 .append(getBitmapDistantCommitSpan()); 996 b.append(", bitmapExcessiveBranchCount=") //$NON-NLS-1$ 997 .append(getBitmapExcessiveBranchCount()); 998 b.append(", bitmapInactiveBranchAge=") //$NON-NLS-1$ 999 .append(getBitmapInactiveBranchAgeInDays()); 1000 return b.toString(); 1001 } 1002 }