WorkingTreeOptions.java

  1. /*
  2.  * Copyright (C) 2010, Marc Strapetz <marc.strapetz@syntevo.com>
  3.  * Copyright (C) 2012-2013, Robin Rosenberg and others
  4.  *
  5.  * This program and the accompanying materials are made available under the
  6.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  7.  * https://www.eclipse.org/org/documents/edl-v10.php.
  8.  *
  9.  * SPDX-License-Identifier: BSD-3-Clause
  10.  */
  11. package org.eclipse.jgit.treewalk;

  12. import org.eclipse.jgit.lib.Config;
  13. import org.eclipse.jgit.lib.Config.SectionParser;
  14. import org.eclipse.jgit.lib.ConfigConstants;
  15. import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
  16. import org.eclipse.jgit.lib.CoreConfig.CheckStat;
  17. import org.eclipse.jgit.lib.CoreConfig.EOL;
  18. import org.eclipse.jgit.lib.CoreConfig.HideDotFiles;
  19. import org.eclipse.jgit.lib.CoreConfig.SymLinks;

  20. /**
  21.  * Options used by the {@link org.eclipse.jgit.treewalk.WorkingTreeIterator}.
  22.  */
  23. public class WorkingTreeOptions {
  24.     /** Key for {@link Config#get(SectionParser)}. */
  25.     public static final Config.SectionParser<WorkingTreeOptions> KEY =
  26.             WorkingTreeOptions::new;

  27.     private final boolean fileMode;

  28.     private final AutoCRLF autoCRLF;

  29.     private final EOL eol;

  30.     private final CheckStat checkStat;

  31.     private final SymLinks symlinks;

  32.     private final HideDotFiles hideDotFiles;

  33.     private final boolean dirNoGitLinks;

  34.     private WorkingTreeOptions(Config rc) {
  35.         fileMode = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION,
  36.                 ConfigConstants.CONFIG_KEY_FILEMODE, true);
  37.         autoCRLF = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
  38.                 ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
  39.         eol = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
  40.                 ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE);
  41.         checkStat = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
  42.                 ConfigConstants.CONFIG_KEY_CHECKSTAT, CheckStat.DEFAULT);
  43.         symlinks = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
  44.                 ConfigConstants.CONFIG_KEY_SYMLINKS, SymLinks.TRUE);
  45.         hideDotFiles = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
  46.                 ConfigConstants.CONFIG_KEY_HIDEDOTFILES,
  47.                 HideDotFiles.DOTGITONLY);
  48.         dirNoGitLinks = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
  49.                 ConfigConstants.CONFIG_KEY_DIRNOGITLINKS,
  50.                 false);
  51.     }

  52.     /** @return true if the execute bit on working files should be trusted. */
  53.     /**
  54.      * Whether the execute bit on working files should be trusted.
  55.      *
  56.      * @return {@code true} if the execute bit on working files should be
  57.      *         trusted.
  58.      */
  59.     public boolean isFileMode() {
  60.         return fileMode;
  61.     }

  62.     /**
  63.      * Get automatic CRLF conversion configuration.
  64.      *
  65.      * @return how automatic CRLF conversion has been configured.
  66.      */
  67.     public AutoCRLF getAutoCRLF() {
  68.         return autoCRLF;
  69.     }

  70.     /**
  71.      * Get how text line endings should be normalized.
  72.      *
  73.      * @return how text line endings should be normalized.
  74.      * @since 4.3
  75.      */
  76.     public EOL getEOL() {
  77.         return eol;
  78.     }

  79.     /**
  80.      * Get how stat data is compared.
  81.      *
  82.      * @return how stat data is compared.
  83.      * @since 3.0
  84.      */
  85.     public CheckStat getCheckStat() {
  86.         return checkStat;
  87.     }

  88.     /**
  89.      * Get how we handle symbolic links
  90.      *
  91.      * @return how we handle symbolic links
  92.      * @since 3.3
  93.      */
  94.     public SymLinks getSymLinks() {
  95.         return symlinks;
  96.     }

  97.     /**
  98.      * Get how we create '.'-files (on Windows)
  99.      *
  100.      * @return how we create '.'-files (on Windows)
  101.      * @since 3.5
  102.      */
  103.     public HideDotFiles getHideDotFiles() {
  104.         return hideDotFiles;
  105.     }

  106.     /**
  107.      * Whether or not we treat nested repos as directories.
  108.      *
  109.      * @return whether or not we treat nested repos as directories. If true,
  110.      *         folders containing .git entries will not be treated as gitlinks.
  111.      * @since 4.3
  112.      */
  113.     public boolean isDirNoGitLinks() { return dirNoGitLinks; }
  114. }