/** * Creates new PersonIdent from config info in repository, with current time. * This new PersonIdent gets the info from the default committer as available * from the configuration. * * @param repo a {@link org.eclipse.jgit.lib.Repository} object. */ public PersonIdent(Repository repo) { this(repo.getConfig().get(UserConfig.KEY)); }
FetchConfig getFetchConfig() { return local.getConfig().get(FetchConfig::new); }
/** * Create a new iterator to traverse the work tree and its children. * * @param repo * the repository whose working tree will be scanned. */ public FileTreeIterator(Repository repo) { this(repo, repo.getConfig().get(WorkingTreeOptions.KEY).isDirNoGitLinks() ? NoGitlinksStrategy.INSTANCE : DefaultFileModeStrategy.INSTANCE); }
/** * Create a new rename detector for the given repository * * @param repo * the repository to use for rename detection */ public RenameDetector(Repository repo) { this(repo.newObjectReader(), repo.getConfig().get(DiffConfig.KEY)); }
/** * Create a new pack receive for an open repository. * * @param into * the destination repository. */ protected BaseReceivePack(Repository into) { db = into; walk = new RevWalk(db); TransferConfig tc = db.getConfig().get(TransferConfig.KEY); objectChecker = tc.newReceiveObjectChecker(); ReceiveConfig rc = db.getConfig().get(ReceiveConfig::new); allowCreates = rc.allowCreates; allowAnyDeletes = true; allowBranchDeletes = rc.allowDeletes; allowNonFastForwards = rc.allowNonFastForwards; allowOfsDelta = rc.allowOfsDelta; allowPushOptions = rc.allowPushOptions; maxCommandBytes = rc.maxCommandBytes; maxDiscardBytes = rc.maxDiscardBytes; advertiseRefsHook = AdvertiseRefsHook.DEFAULT; refFilter = RefFilter.DEFAULT; advertisedHaves = new HashSet<>(); clientShallowCommits = new HashSet<>(); signedPushConfig = rc.signedPush; }
private boolean isEnabledFor(Repository db) { if (isOverridable()) return db.getConfig().get(configKey).enabled; return isEnabled(); }
private boolean isLogAllRefUpdates() { return refdb.getRepository().getConfig().get(CoreConfig.KEY) .isLogAllRefUpdates(); }
private ReflogWriter log(String refName, byte[] rec) throws IOException { File log = refdb.logFor(refName); boolean write = forceWrite || (isLogAllRefUpdates() && shouldAutoCreateLog(refName)) || log.isFile(); if (!write) return this; WriteConfig wc = refdb.getRepository().getConfig().get(WriteConfig.KEY); try (FileOutputStream out = getFileOutputStream(log)) { if (wc.getFSyncRefFiles()) { FileChannel fc = out.getChannel(); ByteBuffer buf = ByteBuffer.wrap(rec); while (0 < buf.remaining()) { fc.write(buf); } fc.force(true); } else { out.write(rec); } } return this; }
private RawText getRawText(File inTree) throws IOException, FileNotFoundException { RawText rawText; WorkingTreeOptions workingTreeOptions = getRepository().getConfig() .get(WorkingTreeOptions.KEY); AutoCRLF autoCRLF = workingTreeOptions.getAutoCRLF(); switch (autoCRLF) { case FALSE: case INPUT: // Git used the repo format on checkout, but other tools // may change the format to CRLF. We ignore that here. rawText = new RawText(inTree); break; case TRUE: try (AutoLFInputStream in = new AutoLFInputStream( new FileInputStream(inTree), true)) { // Canonicalization should lead to same or shorter length // (CRLF to LF), so the file size on disk is an upper size bound rawText = new RawText(toByteArray(in, (int) inTree.length())); } break; default: throw new IllegalArgumentException( "Unknown autocrlf option " + autoCRLF); //$NON-NLS-1$ } return rawText; }
/** * Create a new iterator to traverse the work tree and its children. * * @param repo * the repository whose working tree will be scanned. * @param fileModeStrategy * the strategy to use to determine the FileMode for a FileEntry; * controls gitlinks etc. * @since 4.3 */ public FileTreeIterator(Repository repo, FileModeStrategy fileModeStrategy) { this(repo.getWorkTree(), repo.getFS(), repo.getConfig().get(WorkingTreeOptions.KEY), fileModeStrategy); initRootIterator(repo); }
/** * Get merge configuration for the current branch of the repository * * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. * @return merge configuration for the current branch of the repository */ public static MergeConfig getConfigForCurrentBranch(Repository repo) { try { String branch = repo.getBranch(); if (branch != null) return repo.getConfig().get(getParser(branch)); } catch (IOException e) { // ignore } // use defaults if branch can't be determined return new MergeConfig(); }
/** * Create a new transport instance. * * @param local * the repository this instance will fetch into, or push out of. * This must be the repository passed to * {@link #open(Repository, URIish)}. * @param uri * the URI used to access the remote repository. This must be the * URI passed to {@link #open(Repository, URIish)}. */ protected Transport(Repository local, URIish uri) { final TransferConfig tc = local.getConfig().get(TransferConfig.KEY); this.local = local; this.uri = uri; this.objectChecker = tc.newObjectChecker(); this.credentialsProvider = CredentialsProvider.getDefault(); prePush = Hooks.prePush(local, hookOutRedirect); }
/** * Load the attributes node * * @return the attributes node * @throws java.io.IOException */ public AttributesNode load() throws IOException { AttributesNode r = new AttributesNode(); FS fs = repository.getFS(); String path = repository.getConfig().get(CoreConfig.KEY) .getAttributesFile(); if (path != null) { File attributesFile; if (path.startsWith("~/")) { //$NON-NLS-1$ attributesFile = fs.resolve(fs.userHome(), path.substring(2)); } else { attributesFile = fs.resolve(null, path); } FileRepository.AttributesNodeProviderImpl.loadRulesFromFile(r, attributesFile); } return r.getRules().isEmpty() ? null : r; } }
/** * Constructor for ResolveMerger. * * @param local * the {@link org.eclipse.jgit.lib.Repository}. * @param inCore * a boolean. */ protected ResolveMerger(Repository local, boolean inCore) { super(local); Config config = local.getConfig(); mergeAlgorithm = getMergeAlgorithm(config); inCoreLimit = getInCoreLimit(config); commitNames = defaultCommitNames(); this.inCore = inCore; if (inCore) { implicitDirCache = false; dircache = DirCache.newInCore(); } else { implicitDirCache = true; workingTreeOptions = local.getConfig().get(WorkingTreeOptions.KEY); } }
@Override IgnoreNode load() throws IOException { IgnoreNode r; if (entry != null) { r = super.load(); if (r == null) r = new IgnoreNode(); } else { r = new IgnoreNode(); } FS fs = repository.getFS(); String path = repository.getConfig().get(CoreConfig.KEY) .getExcludesFile(); if (path != null) { File excludesfile; if (path.startsWith("~/")) //$NON-NLS-1$ excludesfile = fs.resolve(fs.userHome(), path.substring(2)); else excludesfile = fs.resolve(null, path); loadRulesFromFile(r, excludesfile); } File exclude = fs.resolve(repository.getDirectory(), Constants.INFO_EXCLUDE); loadRulesFromFile(r, exclude); return r.getRules().isEmpty() ? null : r; }
FileUtils.mkdirs(parentDir, true); FS fs = repo.getFS(); WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY); if (entry.getFileMode() == FileMode.SYMLINK && opt.getSymLinks() == SymLinks.TRUE) {
/** {@inheritDoc} */ @Override protected Result doUpdate(Result status) throws IOException { WriteConfig wc = database.getRepository().getConfig() .get(WriteConfig.KEY); lock.setFSync(wc.getFSyncRefFiles()); lock.setNeedStatInformation(true); lock.write(getNewObjectId()); String msg = getRefLogMessage(); if (msg != null) { if (isRefLogIncludingResult()) { String strResult = toResultString(status); if (strResult != null) { if (msg.length() > 0) msg = msg + ": " + strResult; //$NON-NLS-1$ else msg = strResult; } } database.log(isForceRefLog(), this, msg, shouldDeref); } if (!lock.commit()) return Result.LOCK_FAILURE; database.stored(this, lock.getCommitSnapshot()); return status; }
/** {@inheritDoc} */ @Override protected Result doLink(String target) throws IOException { WriteConfig wc = database.getRepository().getConfig() .get(WriteConfig.KEY); lock.setFSync(wc.getFSyncRefFiles()); lock.setNeedStatInformation(true); lock.write(encode(RefDirectory.SYMREF + target + '\n')); String msg = getRefLogMessage(); if (msg != null) database.log(isForceRefLog(), this, msg, false); if (!lock.commit()) return Result.LOCK_FAILURE; database.storedSymbolicRef(this, lock.getCommitSnapshot(), target); if (getRef().getStorage() == Ref.Storage.NEW) return Result.NEW; return Result.FORCED; } }
/** * Create a new rename detector for the given repository * * @param repo * the repository to use for rename detection */ public RenameDetector(Repository repo) { this(repo.newObjectReader(), repo.getConfig().get(DiffConfig.KEY)); }
private boolean isEnabledFor(final Repository db) { if (isOverridable()) return db.getConfig().get(configKey).enabled; return isEnabled(); }