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

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