private void loadPathNames() { pathToName = null; if (modulesConfig != null) { HashMap<String, String> pathNames = new HashMap<>(); for (String name : modulesConfig .getSubsections(ConfigConstants.CONFIG_SUBMODULE_SECTION)) { pathNames.put(modulesConfig.getString( ConfigConstants.CONFIG_SUBMODULE_SECTION, name, ConfigConstants.CONFIG_KEY_PATH), name); } pathToName = pathNames; } }
private CoreConfig(Config rc) { compression = rc.getInt(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_COMPRESSION, DEFAULT_COMPRESSION); packIndexVersion = rc.getInt(ConfigConstants.CONFIG_PACK_SECTION, ConfigConstants.CONFIG_KEY_INDEXVERSION, 2); logAllRefUpdates = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true); excludesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EXCLUDESFILE); attributesfile = rc.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_ATTRIBUTESFILE); }
boolean fsck = rc.getBoolean("transfer", "fsckobjects", false); fetchFsck = rc.getBoolean("fetch", "fsckobjects", fsck); receiveFsck = rc.getBoolean("receive", "fsckobjects", fsck); fsckSkipList = rc.getString(FSCK, null, "skipList"); allowInvalidPersonIdent = rc.getBoolean(FSCK, "allowInvalidPersonIdent", false); safeForWindows = rc.getBoolean(FSCK, "safeForWindows", SystemReader.getInstance().isWindows()); safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", SystemReader.getInstance().isMacOS()); EnumSet<ObjectChecker.ErrorType> set = EnumSet .noneOf(ObjectChecker.ErrorType.class); for (String key : rc.getNames(FSCK)) { if (equalsIgnoreCase(key, "skipList") || equalsIgnoreCase(key, "allowLeadingZeroFileMode") switch (rc.getEnum(FSCK, null, key, FsckMode.ERROR)) { case ERROR: ignore.remove(id); && rc.getBoolean(FSCK, "allowLeadingZeroFileMode", false)) { ignore.add(ObjectChecker.ErrorType.ZERO_PADDED_FILEMODE); allowRefInWant = rc.getBoolean("uploadpack", "allowrefinwant", false); allowTipSha1InWant = rc.getBoolean( "uploadpack", "allowtipsha1inwant", false); allowReachableSha1InWant = rc.getBoolean( "uploadpack", "allowreachablesha1inwant", false);
FetchConfig(Config c) { allowOfsDelta = c.getBoolean("repack", "usedeltabaseoffset", true); //$NON-NLS-1$ //$NON-NLS-2$ maxHaves = c.getInt("fetch", "maxhaves", Integer.MAX_VALUE); //$NON-NLS-1$ //$NON-NLS-2$ }
private WorkingTreeOptions(Config rc) { fileMode = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, ConfigConstants.CONFIG_KEY_FILEMODE, true); autoCRLF = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE); eol = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_EOL, EOL.NATIVE); checkStat = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_CHECKSTAT, CheckStat.DEFAULT); symlinks = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_SYMLINKS, SymLinks.TRUE); hideDotFiles = rc.getEnum(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_HIDEDOTFILES, HideDotFiles.DOTGITONLY); dirNoGitLinks = rc.getBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_DIRNOGITLINKS, false); }
String val; vlst = rc.getStringList(SECTION, name, KEY_URL); Map<String, String> insteadOf = getReplacements(rc, KEY_INSTEADOF); uris = new ArrayList<>(vlst.length); uris.add(new URIish(replaceUri(s, insteadOf))); String[] plst = rc.getStringList(SECTION, name, KEY_PUSHURL); pushURIs = new ArrayList<>(plst.length); for (String s : plst) { fetch = rc.getRefSpecs(SECTION, name, KEY_FETCH); push = rc.getRefSpecs(SECTION, name, KEY_PUSH); val = rc.getString(SECTION, name, KEY_UPLOADPACK); if (val == null) { val = DEFAULT_UPLOAD_PACK; val = rc.getString(SECTION, name, KEY_RECEIVEPACK); if (val == null) { val = DEFAULT_RECEIVE_PACK; val = rc.getString(SECTION, name, KEY_TAGOPT); tagopt = TagOpt.fromOption(val); } catch (IllegalArgumentException e) { mirror = rc.getBoolean(SECTION, name, KEY_MIRROR, DEFAULT_MIRROR); timeout = rc.getInt(SECTION, name, KEY_TIMEOUT, 0);
/** * @param gitConfigFolder e.g. /your/project/root/.git * * @return Returns git config remote.origin.url field of the repository located at gitConfigFolder */ public static String getGitRemoteUrl( String gitConfigFolder ) throws MojoExecutionException { try { Repository repo = new RepositoryBuilder().setGitDir( new File( gitConfigFolder ) ).readEnvironment().findGitDir() .build(); Config config = repo.getConfig(); return config.getString( "remote", "origin", "url" ); } catch ( Exception e ) { throw new MojoExecutionException( "Error trying to get remote origin url of git repository", e ); } }
ObjectInserter inserter = repo.newObjectInserter(); try (RevWalk rw = new RevWalk(repo)) { Config cfg = new Config(); StringBuilder attributes = new StringBuilder(); for (RepoProject proj : renamedProjects) { cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ proj.getRevision()); cfg.setBoolean("submodule", name, "shallow", //$NON-NLS-1$ //$NON-NLS-2$ true); submodUrl = relativize(targetUri, submodUrl); cfg.setString("submodule", name, "path", path); //$NON-NLS-1$ //$NON-NLS-2$ cfg.setString("submodule", name, "url", //$NON-NLS-1$ //$NON-NLS-2$ submodUrl.toString()); String content = cfg.toText();
private void init(Config config, URIish uri) { int postBufferSize = config.getInt(HTTP, POST_BUFFER_KEY, 1 * 1024 * 1024); boolean sslVerifyFlag = config.getBoolean(HTTP, SSL_VERIFY_KEY, true); HttpRedirectMode followRedirectsMode = config.getEnum( HttpRedirectMode.values(), HTTP, null, FOLLOW_REDIRECTS_KEY, HttpRedirectMode.INITIAL); int redirectLimit = config.getInt(HTTP, MAX_REDIRECTS_KEY, MAX_REDIRECTS); if (redirectLimit < 0) { redirectLimit = MAX_REDIRECTS; String match = findMatch(config.getSubsections(HTTP), uri); if (match != null) { postBufferSize = config.getInt(HTTP, match, POST_BUFFER_KEY, postBufferSize); sslVerifyFlag = config.getBoolean(HTTP, match, SSL_VERIFY_KEY, sslVerifyFlag); followRedirectsMode = config.getEnum(HttpRedirectMode.values(), HTTP, match, FOLLOW_REDIRECTS_KEY, followRedirectsMode); int newMaxRedirects = config.getInt(HTTP, match, MAX_REDIRECTS_KEY, redirectLimit); if (newMaxRedirects >= 0) {
Config c = new Config(); try { c.fromText(gitModulesContents); for (String subsection : c.getSubsections(CONFIG_SUBMODULE_SECTION)) { assertValidSubmoduleName(subsection); String url = c.getString( CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_URL); if (url != null) { String path = c.getString( CONFIG_SUBMODULE_SECTION, subsection, CONFIG_KEY_PATH); if (path != null) {
if (filterCommand != null) return filterCommand; filterCommand = config.getString(ConfigConstants.CONFIG_FILTER_SECTION, filterDriverName, filterCommandType); boolean useBuiltin = config.getBoolean( ConfigConstants.CONFIG_FILTER_SECTION, filterDriverName, ConfigConstants.CONFIG_KEY_USEJGITBUILTIN, false);
private List<Project> parseProjects(final Config cfg, final String sectionName) { final List<Project> dst = new ArrayList<Project>(); for (String id : cfg.getSubsections(sectionName)) { String name = cfg.getString(sectionName, id, K_NAME); Project project = new Project(id, name); project.setVersion(cfg.getString(sectionName, id, K_VERSION)); project.setComments(cfg.getString(sectionName, id, K_COMMENTS)); for (String c : cfg.getStringList(sectionName, id, K_SKIP_COMMIT)) project.addSkipCommit(ObjectId.fromString(c)); for (String license : cfg.getStringList(sectionName, id, K_LICENSE)) project.addLicense(license); dst.add(project); } return dst; }
private Map<String, String> getReplacements(final Config config, final String keyName) { final Map<String, String> replacements = new HashMap<>(); for (String url : config.getSubsections(KEY_URL)) for (String insteadOf : config.getStringList(KEY_URL, url, keyName)) replacements.put(insteadOf, url); return replacements; }
private WriteConfig(Config rc) { compression = rc.get(CoreConfig.KEY).getCompression(); fsyncObjectFiles = rc.getBoolean("core", "fsyncobjectfiles", false); //$NON-NLS-1$ //$NON-NLS-2$ fsyncRefFiles = rc.getBoolean("core", "fsyncreffiles", false); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Update properties by setting fields from the configuration. * <p> * If a property is not defined in the configuration, then it is left * unmodified. * * @param rc * configuration to read properties from. * @return {@code this}. * @since 3.0 */ public WindowCacheConfig fromConfig(Config rc) { setPackedGitOpenFiles(rc.getInt( "core", null, "packedgitopenfiles", getPackedGitOpenFiles())); //$NON-NLS-1$ //$NON-NLS-2$ setPackedGitLimit(rc.getLong( "core", null, "packedgitlimit", getPackedGitLimit())); //$NON-NLS-1$ //$NON-NLS-2$ setPackedGitWindowSize(rc.getInt( "core", null, "packedgitwindowsize", getPackedGitWindowSize())); //$NON-NLS-1$ //$NON-NLS-2$ setPackedGitMMAP(rc.getBoolean( "core", null, "packedgitmmap", isPackedGitMMAP())); //$NON-NLS-1$ //$NON-NLS-2$ setDeltaBaseCacheLimit(rc.getInt( "core", null, "deltabasecachelimit", getDeltaBaseCacheLimit())); //$NON-NLS-1$ //$NON-NLS-2$ long maxMem = Runtime.getRuntime().maxMemory(); long sft = rc.getLong( "core", null, "streamfilethreshold", getStreamFileThreshold()); //$NON-NLS-1$ //$NON-NLS-2$ sft = Math.min(sft, maxMem / 4); // don't use more than 1/4 of the heap sft = Math.min(sft, Integer.MAX_VALUE); // cannot exceed array length setStreamFileThreshold((int) sft); return this; }
long cfgBlockLimit = rc.getLong( CONFIG_CORE_SECTION, CONFIG_DFS_SECTION, CONFIG_KEY_BLOCK_LIMIT, getBlockLimit()); int cfgBlockSize = rc.getInt( CONFIG_CORE_SECTION, CONFIG_DFS_SECTION, setBlockSize(cfgBlockSize); setConcurrencyLevel(rc.getInt( CONFIG_CORE_SECTION, CONFIG_DFS_SECTION, getConcurrencyLevel())); String v = rc.getString( CONFIG_CORE_SECTION, CONFIG_DFS_SECTION,
private static @NonNull DiffEntry diffFile(Repository repo, String oldCommit, String newCommit, String path) throws IOException, GitAPIException { Config config = new Config(); config.setBoolean("diff", null, "renames", true); DiffConfig diffConfig = config.get(DiffConfig.KEY); try (Git git = new Git(repo)) { List<DiffEntry> diffList = git.diff(). setOldTree(prepareTreeParser(repo, oldCommit)). setNewTree(prepareTreeParser(repo, newCommit)). setPathFilter(FollowFilter.create(path, diffConfig)). call(); if (diffList.size() == 0) return null; if (diffList.size() > 1) throw new RuntimeException("invalid diff"); return diffList.get(0); } } }
private RemoteConfig newRemoteConfig(String name, String refUrl, RefSpec... refSpec) { try { Config repoConfig = new Config(); // Make up a repo config from the request parameters repoConfig.setString("remote", name, "url", refUrl); List<String> str = new ArrayList<>(); if(refSpec != null && refSpec.length > 0) for (RefSpec rs: refSpec) str.add(rs.toString()); repoConfig.setStringList("remote", name, "fetch", str); return RemoteConfig.getAllRemoteConfigs(repoConfig).get(0); } catch (Exception ex) { throw new GitException("Error trying to create JGit configuration", ex); } }