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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. } else {
  333. throw new IllegalStateException();
  334. }
  335. }
  336. /** {@inheritDoc} */
  337. @Override
  338. public FileBasedConfig getConfig() {
  339. try {
  340. SystemReader.getInstance().getUserConfig();
  341. if (repoConfig.isOutdated()) {
  342. loadRepoConfig();
  343. }
  344. } catch (IOException | ConfigInvalidException e) {
  345. throw new RuntimeException(e);
  346. }
  347. return repoConfig;
  348. }
  349. /** {@inheritDoc} */
  350. @Override
  351. @Nullable
  352. public String getGitwebDescription() throws IOException {
  353. String d;
  354. try {
  355. d = RawParseUtils.decode(IO.readFully(descriptionFile()));
  356. } catch (FileNotFoundException err) {
  357. return null;
  358. }
  359. if (d != null) {
  360. d = d.trim();
  361. if (d.isEmpty() || UNNAMED.equals(d)) {
  362. return null;
  363. }
  364. }
  365. return d;
  366. }
  367. /** {@inheritDoc} */
  368. @Override
  369. public void setGitwebDescription(@Nullable String description)
  370. throws IOException {
  371. String old = getGitwebDescription();
  372. if (Objects.equals(old, description)) {
  373. return;
  374. }
  375. File path = descriptionFile();
  376. LockFile lock = new LockFile(path);
  377. if (!lock.lock()) {
  378. throw new IOException(MessageFormat.format(JGitText.get().lockError,
  379. path.getAbsolutePath()));
  380. }
  381. try {
  382. String d = description;
  383. if (d != null) {
  384. d = d.trim();
  385. if (!d.isEmpty()) {
  386. d += '\n';
  387. }
  388. } else {
  389. d = ""; //$NON-NLS-1$
  390. }
  391. lock.write(Constants.encode(d));
  392. lock.commit();
  393. } finally {
  394. lock.unlock();
  395. }
  396. }
  397. private File descriptionFile() {
  398. return new File(getDirectory(), "description"); //$NON-NLS-1$
  399. }
  400. /**
  401. * {@inheritDoc}
  402. * <p>
  403. * Objects known to exist but not expressed by {@code #getAllRefs()}.
  404. * <p>
  405. * When a repository borrows objects from another repository, it can
  406. * advertise that it safely has that other repository's references, without
  407. * exposing any other details about the other repository. This may help a
  408. * client trying to push changes avoid pushing more than it needs to.
  409. */
  410. @Override
  411. public Set<ObjectId> getAdditionalHaves() {
  412. return getAdditionalHaves(null);
  413. }
  414. /**
  415. * Objects known to exist but not expressed by {@code #getAllRefs()}.
  416. * <p>
  417. * When a repository borrows objects from another repository, it can
  418. * advertise that it safely has that other repository's references, without
  419. * exposing any other details about the other repository. This may help a
  420. * client trying to push changes avoid pushing more than it needs to.
  421. *
  422. * @param skips
  423. * Set of AlternateHandle Ids already seen
  424. *
  425. * @return unmodifiable collection of other known objects.
  426. */
  427. private Set<ObjectId> getAdditionalHaves(Set<AlternateHandle.Id> skips) {
  428. HashSet<ObjectId> r = new HashSet<>();
  429. skips = objectDatabase.addMe(skips);
  430. for (AlternateHandle d : objectDatabase.myAlternates()) {
  431. if (d instanceof AlternateRepository && !skips.contains(d.getId())) {
  432. FileRepository repo;
  433. repo = ((AlternateRepository) d).repository;
  434. for (Ref ref : repo.getAllRefs().values()) {
  435. if (ref.getObjectId() != null)
  436. r.add(ref.getObjectId());
  437. if (ref.getPeeledObjectId() != null)
  438. r.add(ref.getPeeledObjectId());
  439. }
  440. r.addAll(repo.getAdditionalHaves(skips));
  441. }
  442. }
  443. return r;
  444. }
  445. /**
  446. * Add a single existing pack to the list of available pack files.
  447. *
  448. * @param pack
  449. * path of the pack file to open.
  450. * @throws java.io.IOException
  451. * index file could not be opened, read, or is not recognized as
  452. * a Git pack file index.
  453. */
  454. public void openPack(File pack) throws IOException {
  455. objectDatabase.openPack(pack);
  456. }
  457. /** {@inheritDoc} */
  458. @Override
  459. public void scanForRepoChanges() throws IOException {
  460. getRefDatabase().getRefs(); // This will look for changes to refs
  461. detectIndexChanges();
  462. }
  463. /** Detect index changes. */
  464. private void detectIndexChanges() {
  465. if (isBare()) {
  466. return;
  467. }
  468. File indexFile = getIndexFile();
  469. synchronized (snapshotLock) {
  470. if (snapshot == null) {
  471. snapshot = FileSnapshot.save(indexFile);
  472. return;
  473. }
  474. if (!snapshot.isModified(indexFile)) {
  475. return;
  476. }
  477. }
  478. notifyIndexChanged(false);
  479. }
  480. /** {@inheritDoc} */
  481. @Override
  482. public void notifyIndexChanged(boolean internal) {
  483. synchronized (snapshotLock) {
  484. snapshot = FileSnapshot.save(getIndexFile());
  485. }
  486. fireEvent(new IndexChangedEvent(internal));
  487. }
  488. /** {@inheritDoc} */
  489. @Override
  490. public ReflogReader getReflogReader(String refName) throws IOException {
  491. Ref ref = findRef(refName);
  492. if (ref != null)
  493. return new ReflogReaderImpl(this, ref.getName());
  494. return null;
  495. }
  496. /** {@inheritDoc} */
  497. @Override
  498. public AttributesNodeProvider createAttributesNodeProvider() {
  499. return new AttributesNodeProviderImpl(this);
  500. }
  501. /**
  502. * Implementation a {@link AttributesNodeProvider} for a
  503. * {@link FileRepository}.
  504. *
  505. * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a>
  506. *
  507. */
  508. static class AttributesNodeProviderImpl implements
  509. AttributesNodeProvider {
  510. private AttributesNode infoAttributesNode;
  511. private AttributesNode globalAttributesNode;
  512. /**
  513. * Constructor.
  514. *
  515. * @param repo
  516. * {@link Repository} that will provide the attribute nodes.
  517. */
  518. protected AttributesNodeProviderImpl(Repository repo) {
  519. infoAttributesNode = new InfoAttributesNode(repo);
  520. globalAttributesNode = new GlobalAttributesNode(repo);
  521. }
  522. @Override
  523. public AttributesNode getInfoAttributesNode() throws IOException {
  524. if (infoAttributesNode instanceof InfoAttributesNode)
  525. infoAttributesNode = ((InfoAttributesNode) infoAttributesNode)
  526. .load();
  527. return infoAttributesNode;
  528. }
  529. @Override
  530. public AttributesNode getGlobalAttributesNode() throws IOException {
  531. if (globalAttributesNode instanceof GlobalAttributesNode)
  532. globalAttributesNode = ((GlobalAttributesNode) globalAttributesNode)
  533. .load();
  534. return globalAttributesNode;
  535. }
  536. static void loadRulesFromFile(AttributesNode r, File attrs)
  537. throws FileNotFoundException, IOException {
  538. if (attrs.exists()) {
  539. try (FileInputStream in = new FileInputStream(attrs)) {
  540. r.parse(in);
  541. }
  542. }
  543. }
  544. }
  545. private boolean shouldAutoDetach() {
  546. return getConfig().getBoolean(ConfigConstants.CONFIG_GC_SECTION,
  547. ConfigConstants.CONFIG_KEY_AUTODETACH, true);
  548. }
  549. /** {@inheritDoc} */
  550. @Override
  551. public void autoGC(ProgressMonitor monitor) {
  552. GC gc = new GC(this);
  553. gc.setPackConfig(new PackConfig(this));
  554. gc.setProgressMonitor(monitor);
  555. gc.setAuto(true);
  556. gc.setBackground(shouldAutoDetach());
  557. try {
  558. gc.gc();
  559. } catch (ParseException | IOException e) {
  560. throw new JGitInternalException(JGitText.get().gcFailed, e);
  561. }
  562. }
  563. }