@Autowired public ConfigRepository(SystemEnvironment systemEnvironment) throws IOException { this.systemEnvironment = systemEnvironment; workingDir = this.systemEnvironment.getConfigRepoDir(); File configRepoDir = new File(workingDir, ".git"); gitRepo = new FileRepositoryBuilder().setGitDir(configRepoDir).build(); gitRepo.getConfig().setInt("gc", null, "auto", 0); git = new Git(gitRepo); }
public static Repository openJGitCookbookRepository() throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); return builder .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); }
private static List<RevCommit> getCommitsToCheck() throws Exception { final List<RevCommit> commits; try (Repository repo = new FileRepositoryBuilder().findGitDir().build()) { final RevCommitsPair revCommitsPair = resolveRevCommitsPair(repo); if (COMMITS_RESOLUTION_MODE == CommitsResolutionMode.BY_COUNTER) { commits = getCommitsByCounter(revCommitsPair.getFirst()); commits.addAll(getCommitsByCounter(revCommitsPair.getSecond())); } else { commits = getCommitsByLastCommitAuthor(revCommitsPair.getFirst()); commits.addAll(getCommitsByLastCommitAuthor(revCommitsPair.getSecond())); } } return commits; }
/** * Construct a representation of a Git repository. * <p> * The work tree, object directory, alternate object directories and index * file locations are deduced from the given git directory and the default * rules by running * {@link org.eclipse.jgit.storage.file.FileRepositoryBuilder}. This * constructor is the same as saying: * * <pre> * new FileRepositoryBuilder().setGitDir(gitDir).build() * </pre> * * @param gitDir * GIT_DIR (the location of the repository metadata). * @throws java.io.IOException * the repository appears to already exist but cannot be * accessed. * @see FileRepositoryBuilder */ public FileRepository(File gitDir) throws IOException { this(new FileRepositoryBuilder().setGitDir(gitDir).setup()); }
@Override public FileBasedConfig openUserConfig(Config parent, FS fs) { final File home = fs.userHome(); return new FileBasedConfig(parent, new File(home, ".gitconfig"), fs); //$NON-NLS-1$ }
private AtomicFileCreation getAtomicFileCreationSupportOption( FileBasedConfig config) { try { config.load(); String value = config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_SUPPORTSATOMICFILECREATION); if (value == null) { return AtomicFileCreation.UNDEFINED; } return StringUtils.toBoolean(value) ? AtomicFileCreation.SUPPORTED : AtomicFileCreation.NOT_SUPPORTED; } catch (IOException | ConfigInvalidException e) { return AtomicFileCreation.SUPPORTED; } }
/** * Whether the currently loaded configuration file is outdated * * @return returns true if the currently loaded configuration file is older * than the file on disk */ public boolean isOutdated() { return snapshot.isModified(getFile()); }
private void loadRepoConfig() throws IOException { try { repoConfig.load(); } catch (ConfigInvalidException e) { throw new IOException(JGitText.get().unknownRepositoryFormat, e); } }
private String getPruneExpireStr() { return repo.getConfig().getString( ConfigConstants.CONFIG_GC_SECTION, null, ConfigConstants.CONFIG_KEY_PRUNEEXPIRE); }
static void reconfigure(WindowCacheConfig cfg) { defaultMaxByteCount = cfg.getDeltaBaseCacheLimit(); }
private static int lockCount(WindowCacheConfig cfg) { return Math.max(cfg.getPackedGitOpenFiles(), 32); }
/** {@inheritDoc} */ @Override public void clear() { hash = hash(new byte[0]); super.clear(); }
public static Repository createNewRepository() throws IOException { // prepare a new folder File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // create the directory Repository repository = FileRepositoryBuilder.create(new File(localPath, ".git")); repository.create(); return repository; } }
private int getLooseObjectLimit() { return repo.getConfig().getInt(ConfigConstants.CONFIG_GC_SECTION, ConfigConstants.CONFIG_KEY_AUTO, DEFAULT_AUTOLIMIT); } }
private boolean shouldAutoDetach() { return getConfig().getBoolean(ConfigConstants.CONFIG_GC_SECTION, ConfigConstants.CONFIG_KEY_AUTODETACH, true); }
public static Repository openJGitCookbookRepository() throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); return builder .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); }
repository = new FileRepositoryBuilder() .setGitDir(directory.resolve(".git").toFile()) .build();
@Override public FileBasedConfig openSystemConfig(Config parent, FS fs) { File configFile = fs.getGitSystemConfig(); if (configFile == null) { return new FileBasedConfig(null, fs) { @Override public void load() { // empty, do not load } @Override public boolean isOutdated() { // regular class would bomb here return false; } }; } return new FileBasedConfig(parent, configFile, fs); }
/** * Convenience factory method to construct a * {@link org.eclipse.jgit.internal.storage.file.FileRepository}. * * @param gitDir * {@code GIT_DIR}, the repository meta directory. * @return a repository matching this configuration. * @throws java.io.IOException * the repository could not be accessed to configure the rest of * the builder's parameters. * @since 3.0 */ public static Repository create(File gitDir) throws IOException { return new FileRepositoryBuilder().setGitDir(gitDir).readEnvironment() .build(); } }
private static Repository openMainRepo(File mainRepoDir) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); if(mainRepo.isBare()) { throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare"); } return mainRepo; }