You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommitGraphConfig.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2021, Tencent.
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.internal.storage.commitgraph;
  11. import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_COMMIT_GRAPH_SECTION;
  12. import static org.eclipse.jgit.lib.ConfigConstants.CONFIG_KEY_COMPUTE_GENERATION;
  13. import org.eclipse.jgit.lib.Config;
  14. import org.eclipse.jgit.lib.Repository;
  15. /**
  16. * Configuration used by a commit-graph writer when constructing the stream.
  17. */
  18. public class CommitGraphConfig {
  19. /**
  20. * Default value of compute generation option: {@value}
  21. *
  22. * @see #setComputeGeneration(boolean)
  23. */
  24. public static final boolean DEFAULT_COMPUTE_GENERATION = true;
  25. private boolean computeGeneration = DEFAULT_COMPUTE_GENERATION;
  26. /**
  27. * Create a default configuration.
  28. */
  29. public CommitGraphConfig() {
  30. }
  31. /**
  32. * Create a configuration honoring the repository's settings.
  33. *
  34. * @param db
  35. * the repository to read settings from. The repository is not
  36. * retained by the new configuration, instead its settings are
  37. * copied during the constructor.
  38. */
  39. public CommitGraphConfig(Repository db) {
  40. fromConfig(db.getConfig());
  41. }
  42. /**
  43. * Create a configuration honoring settings in a
  44. * {@link org.eclipse.jgit.lib.Config}.
  45. *
  46. * @param cfg
  47. * the source to read settings from. The source is not retained
  48. * by the new configuration, instead its settings are copied
  49. * during the constructor.
  50. */
  51. public CommitGraphConfig(Config cfg) {
  52. fromConfig(cfg);
  53. }
  54. /**
  55. * Checks whether to compute generation numbers.
  56. *
  57. * @return {@code true} if the writer should compute generation numbers.
  58. */
  59. public boolean isComputeGeneration() {
  60. return computeGeneration;
  61. }
  62. /**
  63. * Whether the writer should compute generation numbers.
  64. *
  65. * Default setting: {@value #DEFAULT_COMPUTE_GENERATION}
  66. *
  67. * @param computeGeneration
  68. * if {@code true} the commit-graph will include the computed
  69. * generation numbers.
  70. */
  71. public void setComputeGeneration(boolean computeGeneration) {
  72. this.computeGeneration = computeGeneration;
  73. }
  74. /**
  75. * Update properties by setting fields from the configuration.
  76. *
  77. * If a property's corresponding variable is not defined in the supplied
  78. * configuration, then it is left unmodified.
  79. *
  80. * @param rc
  81. * configuration to read properties from.
  82. */
  83. public void fromConfig(Config rc) {
  84. computeGeneration = rc.getBoolean(CONFIG_COMMIT_GRAPH_SECTION,
  85. CONFIG_KEY_COMPUTE_GENERATION, computeGeneration);
  86. }
  87. }