final String name = params.getParameter(0);
if (new File(name).isDirectory()) {
- setter.addValue(new FileTreeIterator(new File(name), FS.DETECTED, WorkingTreeOptions.createDefaultInstance()));
+ setter.addValue(new FileTreeIterator(
+ new File(name),
+ FS.DETECTED,
+ clp.getRepository().getConfig().get(WorkingTreeOptions.KEY)));
return 1;
}
import junit.framework.TestCase;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectReader;
-import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
public class AbstractTreeIteratorTest extends TestCase {
public class FakeTreeIterator extends WorkingTreeIterator {
public FakeTreeIterator(String pathName, FileMode fileMode) {
- super(prefix(pathName), new WorkingTreeOptions(AutoCRLF.FALSE));
+ super(prefix(pathName), new Config().get(WorkingTreeOptions.KEY));
mode = fileMode.getBits();
final int s = pathName.lastIndexOf('/');
final File r = new File(trash, paths[0]);
assertTrue(r.isFile());
final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
- WorkingTreeOptions.createConfigurationInstance(db.getConfig()));
+ db.getConfig().get(WorkingTreeOptions.KEY));
assertTrue(fti.first());
assertTrue(fti.eof());
}
final File r = new File(trash, "not-existing-file");
assertFalse(r.exists());
final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
- WorkingTreeOptions.createConfigurationInstance(db.getConfig()));
+ db.getConfig().get(WorkingTreeOptions.KEY));
assertTrue(fti.first());
assertTrue(fti.eof());
}
assertTrue(r.isDirectory());
final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
- WorkingTreeOptions.createConfigurationInstance(db.getConfig()));
+ db.getConfig().get(WorkingTreeOptions.KEY));
assertTrue(fti.first());
assertTrue(fti.eof());
}
public void testSimpleIterate() throws Exception {
final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(),
- WorkingTreeOptions.createConfigurationInstance(db.getConfig()));
+ db.getConfig().get(WorkingTreeOptions.KEY));
assertTrue(top.first());
assertFalse(top.eof());
public void testComputeFileObjectId() throws Exception {
final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(),
- WorkingTreeOptions.createConfigurationInstance(db.getConfig()));
+ db.getConfig().get(WorkingTreeOptions.KEY));
final MessageDigest md = Constants.newMessageDigest();
md.update(Constants.encodeASCII(Constants.TYPE_BLOB));
import java.util.SortedSet;
import java.util.TreeSet;
+import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
import org.eclipse.jgit.util.FS;
/**
public FileTreeIteratorWithTimeControl(File f, FS fs,
TreeSet<Long> modTimes) {
- super(f, fs, new WorkingTreeOptions(AutoCRLF.FALSE));
+ super(f, fs, new Config().get(WorkingTreeOptions.KEY));
this.modTimes = modTimes;
}
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.EmptyTreeIterator;
*/
public DirCacheCheckout(Repository repo, ObjectId headCommitTree,
DirCache dc, ObjectId mergeCommitTree) throws IOException {
- this(repo, headCommitTree, dc, mergeCommitTree, new FileTreeIterator(
- repo.getWorkTree(), repo.getFS(),
- WorkingTreeOptions.createDefaultInstance()));
+ this(repo, headCommitTree, dc, mergeCommitTree, new FileTreeIterator(repo));
}
/**
*/
public DirCacheCheckout(Repository repo, DirCache dc,
ObjectId mergeCommitTree) throws IOException {
- this(repo, null, dc, mergeCommitTree, new FileTreeIterator(
- repo.getWorkTree(), repo.getFS(),
- WorkingTreeOptions.createDefaultInstance()));
+ this(repo, null, dc, mergeCommitTree, new FileTreeIterator(repo));
}
/**
if (m != null) {
if (i == null || f == null || !m.idEqual(i)
|| (i.getDirCacheEntry() != null && (f.isModified(
- i.getDirCacheEntry(), true, config_filemode()) ||
+ i.getDirCacheEntry(), true) ||
i.getDirCacheEntry().getStage() != 0))) {
update(m.getEntryPathString(), m.getEntryObjectId(),
m.getEntryFileMode());
file.getParentFile().mkdirs();
file.createNewFile();
DirCacheEntry entry = dc.getEntry(path);
- checkoutEntry(repo, file, entry, config_filemode());
+ checkoutEntry(repo, file, entry);
}
case 0xFFD: // 12 13 14
if (hId.equals(iId)) {
dce = i.getDirCacheEntry();
- if (f == null || f.isModified(dce, true, config_filemode()))
+ if (f == null || f.isModified(dce, true))
conflict(name, i.getDirCacheEntry(), h, m);
else
remove(name);
if (m == null || mId.equals(iId)) {
if (m==null && walk.isDirectoryFileConflict()) {
if (dce != null
- && (f == null || f.isModified(dce, true,
- config_filemode())))
+ && (f == null || f.isModified(dce, true)))
conflict(name, i.getDirCacheEntry(), h, m);
else
remove(name);
*/
if (hId.equals(iId)) {
- if (f == null || f.isModified(dce, true, config_filemode()))
+ if (f == null || f.isModified(dce, true))
conflict(name, i.getDirCacheEntry(), h, m);
else
remove(name);
if (!hId.equals(mId) && !hId.equals(iId) && !mId.equals(iId))
conflict(name, i.getDirCacheEntry(), h, m);
else if (hId.equals(iId) && !mId.equals(iId)) {
- if (dce != null
- && (f == null || f.isModified(dce, true,
- config_filemode())))
+ if (dce != null && (f == null || f.isModified(dce, true)))
conflict(name, i.getDirCacheEntry(), h, m);
else
update(name, mId, m.getEntryFileMode());
}
}
- private Boolean filemode;
-
- private boolean config_filemode() {
- // TODO: temporary till we can actually set parameters. We need to be
- // able to change this for testing.
- if (filemode == null) {
- StoredConfig config = repo.getConfig();
- filemode = Boolean.valueOf(config.getBoolean("core", null,
- "filemode", true));
- }
- return filemode.booleanValue();
- }
-
/**
* If <code>true</code>, will scan first to see if it's possible to check
* out, otherwise throw {@link CheckoutConflictException}. If
private boolean isModified(String path) throws CorruptObjectException, IOException {
NameConflictTreeWalk tw = new NameConflictTreeWalk(repo);
tw.addTree(new DirCacheIterator(dc));
- tw.addTree(new FileTreeIterator(repo.getWorkTree(), repo.getFS(),
- WorkingTreeOptions.createDefaultInstance()));
+ tw.addTree(new FileTreeIterator(repo));
tw.setRecursive(true);
tw.setFilter(PathFilter.create(path));
DirCacheIterator dcIt;
wtIt = tw.getTree(1, WorkingTreeIterator.class);
if (dcIt == null || wtIt == null)
return true;
- if (wtIt.isModified(dcIt.getDirCacheEntry(), true,
- config_filemode())) {
+ if (wtIt.isModified(dcIt.getDirCacheEntry(), true)) {
return true;
}
}
* has to exist already
* @param entry
* the entry containing new mode and content
- * @param config_filemode
- * whether the mode bits should be handled at all.
* @throws IOException
*/
- public static void checkoutEntry(final Repository repo, File f, DirCacheEntry entry,
- boolean config_filemode) throws IOException {
+ public static void checkoutEntry(final Repository repo, File f,
+ DirCacheEntry entry) throws IOException {
ObjectLoader ol = repo.open(entry.getObjectId());
File parentDir = f.getParentFile();
File tmpFile = File.createTempFile("._" + f.getName(), null, parentDir);
channel.close();
}
FS fs = repo.getFS();
- if (config_filemode && fs.supportsExecute()) {
+ WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
+ if (opt.isFileMode() && fs.supportsExecute()) {
if (FileMode.EXECUTABLE_FILE.equals(entry.getRawMode())) {
if (!fs.canExecute(tmpFile))
fs.setExecute(tmpFile, true);
private final boolean logAllRefUpdates;
- private final boolean fileMode;
-
- private final AutoCRLF autoCRLF;
-
private CoreConfig(final Config rc) {
compression = rc.getInt("core", "compression", DEFAULT_COMPRESSION);
packIndexVersion = rc.getInt("pack", "indexversion", 2);
logAllRefUpdates = rc.getBoolean("core", "logallrefupdates", true);
- fileMode = rc.getBoolean("core", "filemode", true);
- autoCRLF = rc.getEnum("core", null, "autocrlf", AutoCRLF.FALSE);
}
/**
public boolean isLogAllRefUpdates() {
return logAllRefUpdates;
}
-
- /**
- * @return whether to trust file modes
- */
- public boolean isFileMode() {
- return fileMode;
- }
-
- /**
- * @return whether automatic CRLF conversion has been configured
- */
- public AutoCRLF getAutoCRLF() {
- return autoCRLF;
- }
}
createDir(f.getParentFile());
DirCacheCheckout.checkoutEntry(db,
f,
- entry.getValue(), true);
+ entry.getValue());
} else {
if (!f.delete())
failingPathes.put(entry.getKey(),
// is not modified
if (work != null
&& (!nonTree(work.getEntryRawMode()) || work
- .isModified(index.getDirCacheEntry(), true,
- true))) {
+ .isModified(index.getDirCacheEntry(), true))) {
failingPathes.put(tw.getPathString(),
MergeFailureReason.DIRTY_WORKTREE);
return false;
* the repository whose working tree will be scanned.
*/
public FileTreeIterator(Repository repo) {
- this(repo.getWorkTree(), repo.getFS(), WorkingTreeOptions
- .createConfigurationInstance(repo.getConfig()));
+ this(repo.getWorkTree(), repo.getFS(),
+ repo.getConfig().get(WorkingTreeOptions.KEY));
initRootIterator(repo);
}
* @param forceContentCheck
* True if the actual file content should be checked if
* modification time differs.
- * @param checkFilemode
- * whether the executable-bit in the filemode should be checked
- * to detect modifications
* @return true if content is most likely different.
*/
- public boolean isModified(DirCacheEntry entry, boolean forceContentCheck,
- boolean checkFilemode) {
+ public boolean isModified(DirCacheEntry entry, boolean forceContentCheck) {
if (entry.isAssumeValid())
return false;
// Ignore the executable file bits if checkFilemode tells me to do so.
// Ignoring is done by setting the bits representing a EXECUTABLE_FILE
// to '0' in modeDiff
- if (!checkFilemode)
+ if (!state.options.isFileMode())
modeDiff &= ~FileMode.EXECUTABLE_FILE.getBits();
if (modeDiff != 0)
// Report a modification if the modes still (after potentially
package org.eclipse.jgit.treewalk;
import org.eclipse.jgit.lib.Config;
-import org.eclipse.jgit.lib.CoreConfig;
+import org.eclipse.jgit.lib.Config.SectionParser;
import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
-/**
- * Contains options used by the WorkingTreeIterator.
- */
+/** Options used by the {@link WorkingTreeIterator}. */
public class WorkingTreeOptions {
+ /** Key for {@link Config#get(SectionParser)}. */
+ public static final Config.SectionParser<WorkingTreeOptions> KEY = new SectionParser<WorkingTreeOptions>() {
+ public WorkingTreeOptions parse(final Config cfg) {
+ return new WorkingTreeOptions(cfg);
+ }
+ };
- /**
- * Creates default options which reflect the original configuration of Git
- * on Unix systems.
- *
- * @return created working tree options
- */
- public static WorkingTreeOptions createDefaultInstance() {
- return new WorkingTreeOptions(AutoCRLF.FALSE);
- }
-
- /**
- * Creates options based on the specified repository configuration.
- *
- * @param config
- * repository configuration to create options for
- *
- * @return created working tree options
- */
- public static WorkingTreeOptions createConfigurationInstance(Config config) {
- return new WorkingTreeOptions(config.get(CoreConfig.KEY).getAutoCRLF());
- }
+ private final boolean fileMode;
- /**
- * Indicates whether EOLs of text files should be converted to '\n' before
- * calculating the blob ID.
- **/
private final AutoCRLF autoCRLF;
- /**
- * Creates new options.
- *
- * @param autoCRLF
- * indicates whether EOLs of text files should be converted to
- * '\n' before calculating the blob ID.
- */
- public WorkingTreeOptions(AutoCRLF autoCRLF) {
- this.autoCRLF = autoCRLF;
+ private WorkingTreeOptions(final Config rc) {
+ fileMode = rc.getBoolean("core", "filemode", true);
+ autoCRLF = rc.getEnum("core", null, "autocrlf", AutoCRLF.FALSE);
+ }
+
+ /** @return true if the execute bit on working files should be trusted. */
+ public boolean isFileMode() {
+ return fileMode;
}
- /**
- * Indicates whether EOLs of text files should be converted to '\n' before
- * calculating the blob ID.
- *
- * @return true if EOLs should be canonicalized.
- */
+ /** @return how automatic CRLF conversion has been configured. */
public AutoCRLF getAutoCRLF() {
return autoCRLF;
}