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.

FileRepository.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
  3. * Copyright (C) 2008-2010, Google Inc.
  4. * Copyright (C) 2006-2010, Robin Rosenberg <robin.rosenberg@dewire.com>
  5. * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org>
  6. * and other copyright owners as documented in the project's IP log.
  7. *
  8. * This program and the accompanying materials are made available
  9. * under the terms of the Eclipse Distribution License v1.0 which
  10. * accompanies this distribution, is reproduced below, and is
  11. * available at http://www.eclipse.org/org/documents/edl-v10.php
  12. *
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * - Neither the name of the Eclipse Foundation, Inc. nor the
  28. * names of its contributors may be used to endorse or promote
  29. * products derived from this software without specific prior
  30. * written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  35. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  44. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. package org.eclipse.jgit.internal.storage.file;
  47. import java.io.File;
  48. import java.io.FileInputStream;
  49. import java.io.FileNotFoundException;
  50. import java.io.IOException;
  51. import java.text.MessageFormat;
  52. import java.text.ParseException;
  53. import java.util.HashSet;
  54. import java.util.Locale;
  55. import java.util.Objects;
  56. import java.util.Set;
  57. import org.eclipse.jgit.annotations.Nullable;
  58. import org.eclipse.jgit.api.errors.JGitInternalException;
  59. import org.eclipse.jgit.attributes.AttributesNode;
  60. import org.eclipse.jgit.attributes.AttributesNodeProvider;
  61. import org.eclipse.jgit.errors.ConfigInvalidException;
  62. import org.eclipse.jgit.events.ConfigChangedEvent;
  63. import org.eclipse.jgit.events.ConfigChangedListener;
  64. import org.eclipse.jgit.events.IndexChangedEvent;
  65. import org.eclipse.jgit.internal.JGitText;
  66. import org.eclipse.jgit.internal.storage.file.ObjectDirectory.AlternateHandle;
  67. import org.eclipse.jgit.internal.storage.file.ObjectDirectory.AlternateRepository;
  68. import org.eclipse.jgit.internal.storage.reftree.RefTreeDatabase;
  69. import org.eclipse.jgit.lib.BaseRepositoryBuilder;
  70. import org.eclipse.jgit.lib.ConfigConstants;
  71. import org.eclipse.jgit.lib.Constants;
  72. import org.eclipse.jgit.lib.CoreConfig.HideDotFiles;
  73. import org.eclipse.jgit.lib.CoreConfig.SymLinks;
  74. import org.eclipse.jgit.lib.ObjectId;
  75. import org.eclipse.jgit.lib.ProgressMonitor;
  76. import org.eclipse.jgit.lib.Ref;
  77. import org.eclipse.jgit.lib.RefDatabase;
  78. import org.eclipse.jgit.lib.RefUpdate;
  79. import org.eclipse.jgit.lib.ReflogReader;
  80. import org.eclipse.jgit.lib.Repository;
  81. import org.eclipse.jgit.lib.StoredConfig;
  82. import org.eclipse.jgit.storage.file.FileBasedConfig;
  83. import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
  84. import org.eclipse.jgit.storage.pack.PackConfig;
  85. import org.eclipse.jgit.util.FileUtils;
  86. import org.eclipse.jgit.util.IO;
  87. import org.eclipse.jgit.util.RawParseUtils;
  88. import org.eclipse.jgit.util.StringUtils;
  89. import org.eclipse.jgit.util.SystemReader;
  90. import org.slf4j.Logger;
  91. import org.slf4j.LoggerFactory;
  92. /**
  93. * Represents a Git repository. A repository holds all objects and refs used for
  94. * managing source code (could by any type of file, but source code is what
  95. * SCM's are typically used for).
  96. *
  97. * In Git terms all data is stored in GIT_DIR, typically a directory called
  98. * .git. A work tree is maintained unless the repository is a bare repository.
  99. * Typically the .git directory is located at the root of the work dir.
  100. *
  101. * <ul>
  102. * <li>GIT_DIR
  103. * <ul>
  104. * <li>objects/ - objects</li>
  105. * <li>refs/ - tags and heads</li>
  106. * <li>config - configuration</li>
  107. * <li>info/ - more configurations</li>
  108. * </ul>
  109. * </li>
  110. * </ul>
  111. * <p>
  112. * This class is thread-safe.
  113. * <p>
  114. * This implementation only handles a subtly undocumented subset of git features.
  115. */
  116. public class FileRepository extends Repository {
  117. private static final Logger LOG = LoggerFactory
  118. .getLogger(FileRepository.class);
  119. private static final String UNNAMED = "Unnamed repository; edit this file to name it for gitweb."; //$NON-NLS-1$
  120. private final FileBasedConfig repoConfig;
  121. private final RefDatabase refs;
  122. private final ObjectDirectory objectDatabase;
  123. private final Object snapshotLock = new Object();
  124. // protected by snapshotLock
  125. private FileSnapshot snapshot;
  126. /**
  127. * Construct a representation of a Git repository.
  128. * <p>
  129. * The work tree, object directory, alternate object directories and index
  130. * file locations are deduced from the given git directory and the default
  131. * rules by running
  132. * {@link org.eclipse.jgit.storage.file.FileRepositoryBuilder}. This
  133. * constructor is the same as saying:
  134. *
  135. * <pre>
  136. * new FileRepositoryBuilder().setGitDir(gitDir).build()
  137. * </pre>
  138. *
  139. * @param gitDir
  140. * GIT_DIR (the location of the repository metadata).
  141. * @throws java.io.IOException
  142. * the repository appears to already exist but cannot be
  143. * accessed.
  144. * @see FileRepositoryBuilder
  145. */
  146. public FileRepository(File gitDir) throws IOException {
  147. this(new FileRepositoryBuilder().setGitDir(gitDir).setup());
  148. }
  149. /**
  150. * A convenience API for {@link #FileRepository(File)}.
  151. *
  152. * @param gitDir
  153. * GIT_DIR (the location of the repository metadata).
  154. * @throws java.io.IOException
  155. * the repository appears to already exist but cannot be
  156. * accessed.
  157. * @see FileRepositoryBuilder
  158. */
  159. public FileRepository(String gitDir) throws IOException {
  160. this(new File(gitDir));
  161. }
  162. /**
  163. * Create a repository using the local file system.
  164. *
  165. * @param options
  166. * description of the repository's important paths.
  167. * @throws java.io.IOException
  168. * the user configuration file or repository configuration file
  169. * cannot be accessed.
  170. */
  171. public FileRepository(BaseRepositoryBuilder options) throws IOException {
  172. super(options);
  173. StoredConfig userConfig = null;
  174. try {
  175. userConfig = SystemReader.getInstance().getUserConfig();
  176. } catch (ConfigInvalidException e) {
  177. LOG.error(e.getMessage(), e);
  178. throw new IOException(e.getMessage(), e);
  179. }
  180. repoConfig = new FileBasedConfig(userConfig, getFS().resolve(
  181. getDirectory(), Constants.CONFIG),
  182. getFS());
  183. loadRepoConfig();
  184. repoConfig.addChangeListener(new ConfigChangedListener() {
  185. @Override
  186. public void onConfigChanged(ConfigChangedEvent event) {
  187. fireEvent(event);
  188. }
  189. });
  190. final long repositoryFormatVersion = getConfig().getLong(
  191. ConfigConstants.CONFIG_CORE_SECTION, null,
  192. ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
  193. String reftype = repoConfig.getString(
  194. "extensions", null, "refStorage"); //$NON-NLS-1$ //$NON-NLS-2$
  195. if (repositoryFormatVersion >= 1 && reftype != null) {
  196. if (StringUtils.equalsIgnoreCase(reftype, "reftree")) { //$NON-NLS-1$
  197. refs = new RefTreeDatabase(this, new RefDirectory(this));
  198. } else {
  199. throw new IOException(JGitText.get().unknownRepositoryFormat);
  200. }
  201. } else {
  202. refs = new RefDirectory(this);
  203. }
  204. objectDatabase = new ObjectDirectory(repoConfig, //
  205. options.getObjectDirectory(), //
  206. options.getAlternateObjectDirectories(), //
  207. getFS(), //
  208. new File(getDirectory(), Constants.SHALLOW));
  209. if (objectDatabase.exists()) {
  210. if (repositoryFormatVersion > 1)
  211. throw new IOException(MessageFormat.format(
  212. JGitText.get().unknownRepositoryFormat2,
  213. Long.valueOf(repositoryFormatVersion)));
  214. }
  215. if (!isBare()) {
  216. snapshot = FileSnapshot.save(getIndexFile());
  217. }
  218. }
  219. private void loadRepoConfig() throws IOException {
  220. try {
  221. repoConfig.load();
  222. } catch (ConfigInvalidException e) {
  223. throw new IOException(JGitText.get().unknownRepositoryFormat, e);
  224. }
  225. }
  226. /**
  227. * {@inheritDoc}
  228. * <p>
  229. * Create a new Git repository initializing the necessary files and
  230. * directories.
  231. */
  232. @Override
  233. public void create(boolean bare) throws IOException {
  234. final FileBasedConfig cfg = getConfig();
  235. if (cfg.getFile().exists()) {
  236. throw new IllegalStateException(MessageFormat.format(
  237. JGitText.get().repositoryAlreadyExists, getDirectory()));
  238. }
  239. FileUtils.mkdirs(getDirectory(), true);
  240. HideDotFiles hideDotFiles = getConfig().getEnum(
  241. ConfigConstants.CONFIG_CORE_SECTION, null,
  242. ConfigConstants.CONFIG_KEY_HIDEDOTFILES,
  243. HideDotFiles.DOTGITONLY);
  244. if (hideDotFiles != HideDotFiles.FALSE && !isBare()
  245. && getDirectory().getName().startsWith(".")) //$NON-NLS-1$
  246. getFS().setHidden(getDirectory(), true);
  247. refs.create();
  248. objectDatabase.create();
  249. FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$
  250. FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$
  251. RefUpdate head = updateRef(Constants.HEAD);
  252. head.disableRefLog();
  253. head.link(Constants.R_HEADS + Constants.MASTER);
  254. final boolean fileMode;
  255. if (getFS().supportsExecute()) {
  256. File tmp = File.createTempFile("try", "execute", getDirectory()); //$NON-NLS-1$ //$NON-NLS-2$
  257. getFS().setExecute(tmp, true);
  258. final boolean on = getFS().canExecute(tmp);
  259. getFS().setExecute(tmp, false);
  260. final boolean off = getFS().canExecute(tmp);
  261. FileUtils.delete(tmp);
  262. fileMode = on && !off;
  263. } else {
  264. fileMode = false;
  265. }
  266. SymLinks symLinks = SymLinks.FALSE;
  267. if (getFS().supportsSymlinks()) {
  268. File tmp = new File(getDirectory(), "tmplink"); //$NON-NLS-1$
  269. try {
  270. getFS().createSymLink(tmp, "target"); //$NON-NLS-1$
  271. symLinks = null;
  272. FileUtils.delete(tmp);
  273. } catch (IOException e) {
  274. // Normally a java.nio.file.FileSystemException
  275. }
  276. }
  277. if (symLinks != null)
  278. cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
  279. ConfigConstants.CONFIG_KEY_SYMLINKS, symLinks.name()
  280. .toLowerCase(Locale.ROOT));
  281. cfg.setInt(ConfigConstants.CONFIG_CORE_SECTION, null,
  282. ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
  283. cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
  284. ConfigConstants.CONFIG_KEY_FILEMODE, fileMode);
  285. if (bare)
  286. cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
  287. ConfigConstants.CONFIG_KEY_BARE, true);
  288. cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
  289. ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, !bare);
  290. if (SystemReader.getInstance().isMacOS())
  291. // Java has no other way
  292. cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
  293. ConfigConstants.CONFIG_KEY_PRECOMPOSEUNICODE, true);
  294. if (!bare) {
  295. File workTree = getWorkTree();
  296. if (!getDirectory().getParentFile().equals(workTree)) {
  297. cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
  298. ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree()
  299. .getAbsolutePath());
  300. LockFile dotGitLockFile = new LockFile(new File(workTree,
  301. Constants.DOT_GIT));
  302. try {
  303. if (dotGitLockFile.lock()) {
  304. dotGitLockFile.write(Constants.encode(Constants.GITDIR
  305. + getDirectory().getAbsolutePath()));
  306. dotGitLockFile.commit();
  307. }
  308. } finally {
  309. dotGitLockFile.unlock();
  310. }
  311. }
  312. }
  313. cfg.save();
  314. }
  315. /**
  316. * Get the directory containing the objects owned by this repository
  317. *
  318. * @return the directory containing the objects owned by this repository.
  319. */
  320. public File getObjectsDirectory() {
  321. return objectDatabase.getDirectory();
  322. }
  323. /** {@inheritDoc} */
  324. @Override
  325. public ObjectDirectory getObjectDatabase() {
  326. return objectDatabase;
  327. }
  328. /** {@inheritDoc} */
  329. @Override
  330. public RefDatabase getRefDatabase() {
  331. return refs;
  332. }
  333. /** {@inheritDoc} */
  334. @Override
  335. public FileBasedConfig getConfig() {
  336. try {
  337. SystemReader.getInstance().getUserConfig();
  338. if (repoConfig.isOutdated()) {
  339. loadRepoConfig();
  340. }
  341. } catch (IOException | ConfigInvalidException e) {
  342. throw new RuntimeException(e);
  343. }
  344. return repoConfig;
  345. }
  346. /** {@inheritDoc} */
  347. @Override
  348. @Nullable
  349. public String getGitwebDescription() throws IOException {
  350. String d;
  351. try {
  352. d = RawParseUtils.decode(IO.readFully(descriptionFile()));
  353. } catch (FileNotFoundException err) {
  354. return null;
  355. }
  356. if (d != null) {
  357. d = d.trim();
  358. if (d.isEmpty() || UNNAMED.equals(d)) {
  359. return null;
  360. }
  361. }
  362. return d;
  363. }
  364. /** {@inheritDoc} */
  365. @Override
  366. public void setGitwebDescription(@Nullable String description)
  367. throws IOException {
  368. String old = getGitwebDescription();
  369. if (Objects.equals(old, description)) {
  370. return;
  371. }
  372. File path = descriptionFile();
  373. LockFile lock = new LockFile(path);
  374. if (!lock.lock()) {
  375. throw new IOException(MessageFormat.format(JGitText.get().lockError,
  376. path.getAbsolutePath()));
  377. }
  378. try {
  379. String d = description;
  380. if (d != null) {
  381. d = d.trim();
  382. if (!d.isEmpty()) {
  383. d += '\n';
  384. }
  385. } else {
  386. d = ""; //$NON-NLS-1$
  387. }
  388. lock.write(Constants.encode(d));
  389. lock.commit();
  390. } finally {
  391. lock.unlock();
  392. }
  393. }
  394. private File descriptionFile() {
  395. return new File(getDirectory(), "description"); //$NON-NLS-1$
  396. }
  397. /**
  398. * {@inheritDoc}
  399. * <p>
  400. * Objects known to exist but not expressed by {@code #getAllRefs()}.
  401. * <p>
  402. * When a repository borrows objects from another repository, it can
  403. * advertise that it safely has that other repository's references, without
  404. * exposing any other details about the other repository. This may help a
  405. * client trying to push changes avoid pushing more than it needs to.
  406. */
  407. @Override
  408. public Set<ObjectId> getAdditionalHaves() {
  409. return getAdditionalHaves(null);
  410. }
  411. /**
  412. * Objects known to exist but not expressed by {@code #getAllRefs()}.
  413. * <p>
  414. * When a repository borrows objects from another repository, it can
  415. * advertise that it safely has that other repository's references, without
  416. * exposing any other details about the other repository. This may help a
  417. * client trying to push changes avoid pushing more than it needs to.
  418. *
  419. * @param skips
  420. * Set of AlternateHandle Ids already seen
  421. *
  422. * @return unmodifiable collection of other known objects.
  423. */
  424. private Set<ObjectId> getAdditionalHaves(Set<AlternateHandle.Id> skips) {
  425. HashSet<ObjectId> r = new HashSet<>();
  426. skips = objectDatabase.addMe(skips);
  427. for (AlternateHandle d : objectDatabase.myAlternates()) {
  428. if (d instanceof AlternateRepository && !skips.contains(d.getId())) {
  429. FileRepository repo;
  430. repo = ((AlternateRepository) d).repository;
  431. for (Ref ref : repo.getAllRefs().values()) {
  432. if (ref.getObjectId() != null)
  433. r.add(ref.getObjectId());
  434. if (ref.getPeeledObjectId() != null)
  435. r.add(ref.getPeeledObjectId());
  436. }
  437. r.addAll(repo.getAdditionalHaves(skips));
  438. }
  439. }
  440. return r;
  441. }
  442. /**
  443. * Add a single existing pack to the list of available pack files.
  444. *
  445. * @param pack
  446. * path of the pack file to open.
  447. * @throws java.io.IOException
  448. * index file could not be opened, read, or is not recognized as
  449. * a Git pack file index.
  450. */
  451. public void openPack(File pack) throws IOException {
  452. objectDatabase.openPack(pack);
  453. }
  454. /** {@inheritDoc} */
  455. @Override
  456. public void scanForRepoChanges() throws IOException {
  457. getRefDatabase().getRefs(); // This will look for changes to refs
  458. detectIndexChanges();
  459. }
  460. /** Detect index changes. */
  461. private void detectIndexChanges() {
  462. if (isBare()) {
  463. return;
  464. }
  465. File indexFile = getIndexFile();
  466. synchronized (snapshotLock) {
  467. if (snapshot == null) {
  468. snapshot = FileSnapshot.save(indexFile);
  469. return;
  470. }
  471. if (!snapshot.isModified(indexFile)) {
  472. return;
  473. }
  474. }
  475. notifyIndexChanged(false);
  476. }
  477. /** {@inheritDoc} */
  478. @Override
  479. public void notifyIndexChanged(boolean internal) {
  480. synchronized (snapshotLock) {
  481. snapshot = FileSnapshot.save(getIndexFile());
  482. }
  483. fireEvent(new IndexChangedEvent(internal));
  484. }
  485. /** {@inheritDoc} */
  486. @Override
  487. public ReflogReader getReflogReader(String refName) throws IOException {
  488. Ref ref = findRef(refName);
  489. if (ref != null)
  490. return new ReflogReaderImpl(this, ref.getName());
  491. return null;
  492. }
  493. /** {@inheritDoc} */
  494. @Override
  495. public AttributesNodeProvider createAttributesNodeProvider() {
  496. return new AttributesNodeProviderImpl(this);
  497. }
  498. /**
  499. * Implementation a {@link AttributesNodeProvider} for a
  500. * {@link FileRepository}.
  501. *
  502. * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
  503. *
  504. */
  505. static class AttributesNodeProviderImpl implements
  506. AttributesNodeProvider {
  507. private AttributesNode infoAttributesNode;
  508. private AttributesNode globalAttributesNode;
  509. /**
  510. * Constructor.
  511. *
  512. * @param repo
  513. * {@link Repository} that will provide the attribute nodes.
  514. */
  515. protected AttributesNodeProviderImpl(Repository repo) {
  516. infoAttributesNode = new InfoAttributesNode(repo);
  517. globalAttributesNode = new GlobalAttributesNode(repo);
  518. }
  519. @Override
  520. public AttributesNode getInfoAttributesNode() throws IOException {
  521. if (infoAttributesNode instanceof InfoAttributesNode)
  522. infoAttributesNode = ((InfoAttributesNode) infoAttributesNode)
  523. .load();
  524. return infoAttributesNode;
  525. }
  526. @Override
  527. public AttributesNode getGlobalAttributesNode() throws IOException {
  528. if (globalAttributesNode instanceof GlobalAttributesNode)
  529. globalAttributesNode = ((GlobalAttributesNode) globalAttributesNode)
  530. .load();
  531. return globalAttributesNode;
  532. }
  533. static void loadRulesFromFile(AttributesNode r, File attrs)
  534. throws FileNotFoundException, IOException {
  535. if (attrs.exists()) {
  536. try (FileInputStream in = new FileInputStream(attrs)) {
  537. r.parse(in);
  538. }
  539. }
  540. }
  541. }
  542. private boolean shouldAutoDetach() {
  543. return getConfig().getBoolean(ConfigConstants.CONFIG_GC_SECTION,
  544. ConfigConstants.CONFIG_KEY_AUTODETACH, true);
  545. }
  546. /** {@inheritDoc} */
  547. @Override
  548. public void autoGC(ProgressMonitor monitor) {
  549. GC gc = new GC(this);
  550. gc.setPackConfig(new PackConfig(this));
  551. gc.setProgressMonitor(monitor);
  552. gc.setAuto(true);
  553. gc.setBackground(shouldAutoDetach());
  554. try {
  555. gc.gc();
  556. } catch (ParseException | IOException e) {
  557. throw new JGitInternalException(JGitText.get().gcFailed, e);
  558. }
  559. }
  560. }