Procházet zdrojové kódy

Fix javadoc in org.eclipse.jgit treewalk package

Change-Id: I1f9d9a005c7228c9881762a78228accad2c7a6d4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v4.10.0.201712302008-r
Matthias Sohn před 6 roky
rodič
revize
c4207c5fbe
21 změnil soubory, kde provedl 476 přidání a 243 odebrání
  1. 55
    25
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java
  2. 38
    15
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java
  3. 18
    2
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java
  4. 9
    5
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java
  5. 12
    11
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
  6. 119
    72
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
  7. 55
    30
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java
  8. 27
    7
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java
  9. 4
    3
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java
  10. 1
    0
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java
  11. 40
    23
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java
  12. 7
    2
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilter.java
  13. 6
    1
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java
  14. 9
    1
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java
  15. 4
    3
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java
  16. 18
    5
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java
  17. 5
    4
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java
  18. 6
    3
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathSuffixFilter.java
  19. 4
    0
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/SkipWorkTreeFilter.java
  20. 23
    20
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java
  21. 16
    11
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilterMarker.java

+ 55
- 25
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/AbstractTreeIterator.java Zobrazit soubor



import org.eclipse.jgit.attributes.AttributesHandler; import org.eclipse.jgit.attributes.AttributesHandler;
import org.eclipse.jgit.attributes.AttributesNode; import org.eclipse.jgit.attributes.AttributesNode;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException; import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.MutableObjectId; import org.eclipse.jgit.lib.MutableObjectId;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.eclipse.jgit.util.Paths; import org.eclipse.jgit.util.Paths;


/** /**
*/ */
protected int pathLen; protected int pathLen;


/** Create a new iterator with no parent. */
/**
* Create a new iterator with no parent.
*/
protected AbstractTreeIterator() { protected AbstractTreeIterator() {
parent = null; parent = null;
path = new byte[DEFAULT_PATH_SIZE]; path = new byte[DEFAULT_PATH_SIZE];
* @param name * @param name
* file name to find (will not find a directory). * file name to find (will not find a directory).
* @return true if the file exists in this tree; false otherwise. * @return true if the file exists in this tree; false otherwise.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* tree is invalid. * tree is invalid.
* @since 4.2 * @since 4.2
*/ */
* @param name * @param name
* file name to find (will not find a directory). * file name to find (will not find a directory).
* @return true if the file exists in this tree; false otherwise. * @return true if the file exists in this tree; false otherwise.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* tree is invalid. * tree is invalid.
* @since 4.2 * @since 4.2
*/ */
otherIterator.idBuffer(), otherIterator.idOffset()); otherIterator.idBuffer(), otherIterator.idOffset());
} }


/** @return true if the entry has a valid ObjectId. */
/**
* Whether the entry has a valid ObjectId.
*
* @return {@code true} if the entry has a valid ObjectId.
*/
public abstract boolean hasId(); public abstract boolean hasId();


/** /**
out.fromRaw(idBuffer(), idOffset()); out.fromRaw(idBuffer(), idOffset());
} }


/** @return the file mode of the current entry. */
/**
* Get the file mode of the current entry.
*
* @return the file mode of the current entry.
*/
public FileMode getEntryFileMode() { public FileMode getEntryFileMode() {
return FileMode.fromBits(mode); return FileMode.fromBits(mode);
} }


/** @return the file mode of the current entry as bits */
/**
* Get the file mode of the current entry as bits.
*
* @return the file mode of the current entry as bits.
*/
public int getEntryRawMode() { public int getEntryRawMode() {
return mode; return mode;
} }


/** @return path of the current entry, as a string. */
/**
* Get path of the current entry, as a string.
*
* @return path of the current entry, as a string.
*/
public String getEntryPathString() { public String getEntryPathString() {
return TreeWalk.pathOf(this); return TreeWalk.pathOf(this);
} }
return path; return path;
} }


/** @return length of the path in {@link #getEntryPathBuffer()}. */
/**
* Get length of the path in {@link #getEntryPathBuffer()}.
*
* @return length of the path in {@link #getEntryPathBuffer()}.
*/
public int getEntryPathLength() { public int getEntryPathLength() {
return pathLen; return pathLen;
} }
* @param reader * @param reader
* reader to load the tree data from. * reader to load the tree data from.
* @return a new parser that walks over the current subtree. * @return a new parser that walks over the current subtree.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the current entry is not actually a tree and cannot be parsed * the current entry is not actually a tree and cannot be parsed
* as though it were a tree. * as though it were a tree.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public abstract AbstractTreeIterator createSubtreeIterator( public abstract AbstractTreeIterator createSubtreeIterator(
* @param idBuffer * @param idBuffer
* temporary ObjectId buffer for use by this method. * temporary ObjectId buffer for use by this method.
* @return a new parser that walks over the current subtree. * @return a new parser that walks over the current subtree.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the current entry is not actually a tree and cannot be parsed * the current entry is not actually a tree and cannot be parsed
* as though it were a tree. * as though it were a tree.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public AbstractTreeIterator createSubtreeIterator( public AbstractTreeIterator createSubtreeIterator(
* method of repositioning the iterator to its first entry, so subclasses * method of repositioning the iterator to its first entry, so subclasses
* are strongly encouraged to override the method. * are strongly encouraged to override the method.
* *
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the tree is invalid. * the tree is invalid.
*/ */
public void reset() throws CorruptObjectException { public void reset() throws CorruptObjectException {
* @param delta * @param delta
* number of entries to move the iterator by. Must be a positive, * number of entries to move the iterator by. Must be a positive,
* non-zero integer. * non-zero integer.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the tree is invalid. * the tree is invalid.
*/ */
public abstract void next(int delta) throws CorruptObjectException; public abstract void next(int delta) throws CorruptObjectException;
* @param delta * @param delta
* number of entries to move the iterator by. Must be a positive, * number of entries to move the iterator by. Must be a positive,
* non-zero integer. * non-zero integer.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the tree is invalid. * the tree is invalid.
*/ */
public abstract void back(int delta) throws CorruptObjectException; public abstract void back(int delta) throws CorruptObjectException;
* Advance to the next tree entry, populating this iterator with its data. * Advance to the next tree entry, populating this iterator with its data.
* <p> * <p>
* This method behaves like <code>seek(1)</code> but is called by * This method behaves like <code>seek(1)</code> but is called by
* {@link TreeWalk} only if a {@link TreeFilter} was used and ruled out the
* current entry from the results. In such cases this tree iterator may
* perform special behavior.
* {@link org.eclipse.jgit.treewalk.TreeWalk} only if a
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter} was used and ruled
* out the current entry from the results. In such cases this tree iterator
* may perform special behavior.
* *
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the tree is invalid. * the tree is invalid.
*/ */
public void skip() throws CorruptObjectException { public void skip() throws CorruptObjectException {
} }


/** /**
* @return true if the iterator implements {@link #stopWalk()}.
* Whether the iterator implements {@link #stopWalk()}.
*
* @return {@code true} if the iterator implements {@link #stopWalk()}.
* @since 4.2 * @since 4.2
*/ */
protected boolean needsStopWalk() { protected boolean needsStopWalk() {
} }


/** /**
* @return the length of the name component of the path for the current entry
* Get the length of the name component of the path for the current entry.
*
* @return the length of the name component of the path for the current
* entry.
*/ */
public int getNameLength() { public int getNameLength() {
return pathLen - pathOffset; return pathLen - pathOffset;
} }


/** /**
* JGit internal API for use by {@link DirCacheCheckout}
* JGit internal API for use by
* {@link org.eclipse.jgit.dircache.DirCacheCheckout}
* *
* @return start of name component part within {@link #getEntryPathBuffer()} * @return start of name component part within {@link #getEntryPathBuffer()}
* @since 2.0 * @since 2.0
System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset); System.arraycopy(path, pathOffset, buffer, offset, pathLen - pathOffset);
} }


/** {@inheritDoc} */
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {
} }


/** /**
* @return whether or not this Iterator is iterating through the Work Tree
* Whether or not this Iterator is iterating through the working tree.
* *
* @return whether or not this Iterator is iterating through the working
* tree
* @since 4.3 * @since 4.3
*/ */
public boolean isWorkTree() { public boolean isWorkTree() {

+ 38
- 15
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/CanonicalTreeParser.java Zobrazit soubor

import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;


/** Parses raw Git trees from the canonical semi-text/semi-binary format. */
/**
* Parses raw Git trees from the canonical semi-text/semi-binary format.
*/
public class CanonicalTreeParser extends AbstractTreeIterator { public class CanonicalTreeParser extends AbstractTreeIterator {
private static final byte[] EMPTY = {}; private static final byte[] EMPTY = {};
private static final byte[] ATTRS = encode(DOT_GIT_ATTRIBUTES); private static final byte[] ATTRS = encode(DOT_GIT_ATTRIBUTES);
/** Offset one past the current entry (first byte of next entry). */ /** Offset one past the current entry (first byte of next entry). */
private int nextPtr; private int nextPtr;


/** Create a new parser. */
/**
* Create a new parser.
*/
public CanonicalTreeParser() { public CanonicalTreeParser() {
reset(EMPTY); reset(EMPTY);
} }
* messages if data corruption is found. * messages if data corruption is found.
* @throws MissingObjectException * @throws MissingObjectException
* the object supplied is not available from the repository. * the object supplied is not available from the repository.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the object supplied as an argument is not actually a tree and * the object supplied as an argument is not actually a tree and
* cannot be parsed as though it were a tree. * cannot be parsed as though it were a tree.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public CanonicalTreeParser(final byte[] prefix, final ObjectReader reader, public CanonicalTreeParser(final byte[] prefix, final ObjectReader reader,
} }


/** /**
* @return the parent of this tree parser
* Get the parent of this tree parser.
*
* @return the parent of this tree parser.
* @deprecated internal use only * @deprecated internal use only
*/ */
@Deprecated @Deprecated
* @return the root level parser. * @return the root level parser.
* @throws MissingObjectException * @throws MissingObjectException
* the object supplied is not available from the repository. * the object supplied is not available from the repository.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the object supplied as an argument is not actually a tree and * the object supplied as an argument is not actually a tree and
* cannot be parsed as though it were a tree. * cannot be parsed as though it were a tree.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public CanonicalTreeParser resetRoot(final ObjectReader reader, public CanonicalTreeParser resetRoot(final ObjectReader reader,
return p; return p;
} }


/** @return this iterator, or its parent, if the tree is at eof. */
/**
* Get this iterator, or its parent, if the tree is at eof.
*
* @return this iterator, or its parent, if the tree is at eof.
*/
public CanonicalTreeParser next() { public CanonicalTreeParser next() {
CanonicalTreeParser p = this; CanonicalTreeParser p = this;
for (;;) { for (;;) {
* messages if data corruption is found. * messages if data corruption is found.
* @throws MissingObjectException * @throws MissingObjectException
* the object supplied is not available from the repository. * the object supplied is not available from the repository.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the object supplied as an argument is not actually a tree and * the object supplied as an argument is not actually a tree and
* cannot be parsed as though it were a tree. * cannot be parsed as though it were a tree.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public void reset(final ObjectReader reader, final AnyObjectId id) public void reset(final ObjectReader reader, final AnyObjectId id)
reset(reader.open(id, OBJ_TREE).getCachedBytes()); reset(reader.open(id, OBJ_TREE).getCachedBytes());
} }


/** {@inheritDoc} */
@Override @Override
public CanonicalTreeParser createSubtreeIterator(final ObjectReader reader, public CanonicalTreeParser createSubtreeIterator(final ObjectReader reader,
final MutableObjectId idBuffer) final MutableObjectId idBuffer)
* @param id * @param id
* ObjectId of the tree to open. * ObjectId of the tree to open.
* @return a new parser that walks over the current subtree. * @return a new parser that walks over the current subtree.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public final CanonicalTreeParser createSubtreeIterator0( public final CanonicalTreeParser createSubtreeIterator0(
return p; return p;
} }


/** {@inheritDoc} */
@Override @Override
public CanonicalTreeParser createSubtreeIterator(final ObjectReader reader) public CanonicalTreeParser createSubtreeIterator(final ObjectReader reader)
throws IncorrectObjectTypeException, IOException { throws IncorrectObjectTypeException, IOException {
return createSubtreeIterator(reader, new MutableObjectId()); return createSubtreeIterator(reader, new MutableObjectId());
} }


/** {@inheritDoc} */
@Override @Override
public boolean hasId() { public boolean hasId() {
return true; return true;
} }


/** {@inheritDoc} */
@Override @Override
public byte[] idBuffer() { public byte[] idBuffer() {
return raw; return raw;
} }


/** {@inheritDoc} */
@Override @Override
public int idOffset() { public int idOffset() {
return nextPtr - OBJECT_ID_LENGTH; return nextPtr - OBJECT_ID_LENGTH;
} }


/** {@inheritDoc} */
@Override @Override
public void reset() { public void reset() {
if (!first()) if (!first())
reset(raw); reset(raw);
} }


/** {@inheritDoc} */
@Override @Override
public boolean first() { public boolean first() {
return currPtr == 0; return currPtr == 0;
} }


/** {@inheritDoc} */
@Override @Override
public boolean eof() { public boolean eof() {
return currPtr == raw.length; return currPtr == raw.length;
} }


/** {@inheritDoc} */
@Override @Override
public void next(int delta) { public void next(int delta) {
if (delta == 1) { if (delta == 1) {
parseEntry(); parseEntry();
} }


/** {@inheritDoc} */
@Override @Override
public void back(int delta) { public void back(int delta) {
if (delta == 1 && 0 <= prevPtr) { if (delta == 1 && 0 <= prevPtr) {
} }


/** /**
* Retrieve the {@link AttributesNode} for the current entry.
* Retrieve the {@link org.eclipse.jgit.attributes.AttributesNode} for the
* current entry.
* *
* @param reader * @param reader
* {@link ObjectReader} used to parse the .gitattributes entry.
* @return {@link AttributesNode} for the current entry.
* @throws IOException
* {@link org.eclipse.jgit.lib.ObjectReader} used to parse the
* .gitattributes entry.
* @return {@link org.eclipse.jgit.attributes.AttributesNode} for the
* current entry.
* @throws java.io.IOException
* @since 4.2 * @since 4.2
*/ */
public AttributesNode getEntryAttributesNode(ObjectReader reader) public AttributesNode getEntryAttributesNode(ObjectReader reader)

+ 18
- 2
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/EmptyTreeIterator.java Zobrazit soubor

import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;


/** Iterator over an empty tree (a directory with no files). */
/**
* Iterator over an empty tree (a directory with no files).
*/
public class EmptyTreeIterator extends AbstractTreeIterator { public class EmptyTreeIterator extends AbstractTreeIterator {
/** Create a new iterator with no parent. */
/**
* Create a new iterator with no parent.
*/
public EmptyTreeIterator() { public EmptyTreeIterator() {
// Create a root empty tree. // Create a root empty tree.
} }
pathLen = childPathOffset - 1; pathLen = childPathOffset - 1;
} }


/** {@inheritDoc} */
@Override @Override
public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader)
throws IncorrectObjectTypeException, IOException { throws IncorrectObjectTypeException, IOException {
return new EmptyTreeIterator(this); return new EmptyTreeIterator(this);
} }


/** {@inheritDoc} */
@Override @Override
public boolean hasId() { public boolean hasId() {
return false; return false;
} }


/** {@inheritDoc} */
@Override @Override
public ObjectId getEntryObjectId() { public ObjectId getEntryObjectId() {
return ObjectId.zeroId(); return ObjectId.zeroId();
} }


/** {@inheritDoc} */
@Override @Override
public byte[] idBuffer() { public byte[] idBuffer() {
return zeroid; return zeroid;
} }


/** {@inheritDoc} */
@Override @Override
public int idOffset() { public int idOffset() {
return 0; return 0;
} }


/** {@inheritDoc} */
@Override @Override
public void reset() { public void reset() {
// Do nothing. // Do nothing.
} }


/** {@inheritDoc} */
@Override @Override
public boolean first() { public boolean first() {
return true; return true;
} }


/** {@inheritDoc} */
@Override @Override
public boolean eof() { public boolean eof() {
return true; return true;
} }


/** {@inheritDoc} */
@Override @Override
public void next(final int delta) throws CorruptObjectException { public void next(final int delta) throws CorruptObjectException {
// Do nothing. // Do nothing.
} }


/** {@inheritDoc} */
@Override @Override
public void back(final int delta) throws CorruptObjectException { public void back(final int delta) throws CorruptObjectException {
// Do nothing. // Do nothing.
} }


/** {@inheritDoc} */
@Override @Override
public void stopWalk() { public void stopWalk() {
if (parent != null) if (parent != null)
parent.stopWalk(); parent.stopWalk();
} }


/** {@inheritDoc} */
@Override @Override
protected boolean needsStopWalk() { protected boolean needsStopWalk() {
return parent != null && parent.needsStopWalk(); return parent != null && parent.needsStopWalk();

+ 9
- 5
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/FileTreeIterator.java Zobrazit soubor

* Working directory iterator for standard Java IO. * Working directory iterator for standard Java IO.
* <p> * <p>
* This iterator uses the standard <code>java.io</code> package to read the * This iterator uses the standard <code>java.io</code> package to read the
* specified working directory as part of a {@link TreeWalk}.
* specified working directory as part of a
* {@link org.eclipse.jgit.treewalk.TreeWalk}.
*/ */
public class FileTreeIterator extends WorkingTreeIterator { public class FileTreeIterator extends WorkingTreeIterator {
/** /**
* @param fileModeStrategy * @param fileModeStrategy
* the strategy to use to determine the FileMode for a FileEntry; * the strategy to use to determine the FileMode for a FileEntry;
* controls gitlinks etc. * controls gitlinks etc.
*
* @since 4.3 * @since 4.3
*/ */
public FileTreeIterator(Repository repo, FileModeStrategy fileModeStrategy) { public FileTreeIterator(Repository repo, FileModeStrategy fileModeStrategy) {
* @param fileModeStrategy * @param fileModeStrategy
* the strategy to use to determine the FileMode for a FileEntry; * the strategy to use to determine the FileMode for a FileEntry;
* controls gitlinks etc. * controls gitlinks etc.
*
* @since 4.3 * @since 4.3
*/ */
public FileTreeIterator(final File root, FS fs, WorkingTreeOptions options, public FileTreeIterator(final File root, FS fs, WorkingTreeOptions options,
* @param fs * @param fs
* the file system abstraction which will be necessary to perform * the file system abstraction which will be necessary to perform
* certain file system operations. * certain file system operations.
*
* @since 4.3 * @since 4.3
*/ */
protected FileTreeIterator(final FileTreeIterator p, final File root, protected FileTreeIterator(final FileTreeIterator p, final File root,
* @param fileModeStrategy * @param fileModeStrategy
* the strategy to use to determine the FileMode for a given * the strategy to use to determine the FileMode for a given
* FileEntry. * FileEntry.
*
* @since 4.3 * @since 4.3
*/ */
protected FileTreeIterator(final WorkingTreeIterator p, final File root, protected FileTreeIterator(final WorkingTreeIterator p, final File root,
init(entries()); init(entries());
} }


/** {@inheritDoc} */
@Override @Override
public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader) public AbstractTreeIterator createSubtreeIterator(final ObjectReader reader)
throws IncorrectObjectTypeException, IOException { throws IncorrectObjectTypeException, IOException {
} }


/** /**
* <p>Getter for the field <code>directory</code>.</p>
*
* @return The root directory of this iterator * @return The root directory of this iterator
*/ */
public File getDirectory() { public File getDirectory() {
} }


/** /**
* Get the location of the working file.
*
* @return The location of the working file. This is the same as {@code new * @return The location of the working file. This is the same as {@code new
* File(getDirectory(), getEntryPath())} but may be faster by * File(getDirectory(), getEntryPath())} but may be faster by
* reusing an internal File instance. * reusing an internal File instance.
return ((FileEntry) current()).getFile(); return ((FileEntry) current()).getFile();
} }


/** {@inheritDoc} */
@Override @Override
protected byte[] idSubmodule(final Entry e) { protected byte[] idSubmodule(final Entry e) {
return idSubmodule(getDirectory(), e); return idSubmodule(getDirectory(), e);
} }


/** {@inheritDoc} */
@Override @Override
protected String readSymlinkTarget(Entry entry) throws IOException { protected String readSymlinkTarget(Entry entry) throws IOException {
return fs.readSymLink(getEntryFile()); return fs.readSymLink(getEntryFile());

+ 12
- 11
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java Zobrazit soubor

import java.io.IOException; import java.io.IOException;


import org.eclipse.jgit.annotations.Nullable; import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
/** /**
* Specialized TreeWalk to detect directory-file (D/F) name conflicts. * Specialized TreeWalk to detect directory-file (D/F) name conflicts.
* <p> * <p>
* Due to the way a Git tree is organized the standard {@link TreeWalk} won't
* easily find a D/F conflict when merging two or more trees together. In the
* standard TreeWalk the file will be returned first, and then much later the
* directory will be returned. This makes it impossible for the application to
* efficiently detect and handle the conflict.
* Due to the way a Git tree is organized the standard
* {@link org.eclipse.jgit.treewalk.TreeWalk} won't easily find a D/F conflict
* when merging two or more trees together. In the standard TreeWalk the file
* will be returned first, and then much later the directory will be returned.
* This makes it impossible for the application to efficiently detect and handle
* the conflict.
* <p> * <p>
* Using this walk implementation causes the directory to report earlier than * Using this walk implementation causes the directory to report earlier than
* usual, at the same time as the non-directory entry. This permits the * usual, at the same time as the non-directory entry. This permits the
* application to handle the D/F conflict in a single step. The directory is * application to handle the D/F conflict in a single step. The directory is
* returned only once, so it does not get returned later in the iteration. * returned only once, so it does not get returned later in the iteration.
* <p> * <p>
* When a D/F conflict is detected {@link TreeWalk#isSubtree()} will return true
* and {@link TreeWalk#enterSubtree()} will recurse into the subtree, no matter
* which iterator originally supplied the subtree.
* When a D/F conflict is detected
* {@link org.eclipse.jgit.treewalk.TreeWalk#isSubtree()} will return true and
* {@link org.eclipse.jgit.treewalk.TreeWalk#enterSubtree()} will recurse into
* the subtree, no matter which iterator originally supplied the subtree.
* <p> * <p>
* Because conflicted directories report early, using this walk implementation * Because conflicted directories report early, using this walk implementation
* to populate a {@link DirCacheBuilder} may cause the automatic resorting to
* run and fix the entry ordering.
* to populate a {@link org.eclipse.jgit.dircache.DirCacheBuilder} may cause the
* automatic resorting to run and fix the entry ordering.
* <p> * <p>
* This walk implementation requires more CPU to implement a look-ahead and a * This walk implementation requires more CPU to implement a look-ahead and a
* look-behind to merge a D/F pair together, or to skip a previously reported * look-behind to merge a D/F pair together, or to skip a previously reported

+ 119
- 72
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java Zobrazit soubor

import org.eclipse.jgit.util.io.EolStreamTypeUtil; import org.eclipse.jgit.util.io.EolStreamTypeUtil;


/** /**
* Walks one or more {@link AbstractTreeIterator}s in parallel.
* Walks one or more {@link org.eclipse.jgit.treewalk.AbstractTreeIterator}s in
* parallel.
* <p> * <p>
* This class can perform n-way differences across as many trees as necessary. * This class can perform n-way differences across as many trees as necessary.
* <p> * <p>
* usage of a TreeWalk instance to a single thread, or implement their own * usage of a TreeWalk instance to a single thread, or implement their own
* synchronization at a higher level. * synchronization at a higher level.
* <p> * <p>
* Multiple simultaneous TreeWalk instances per {@link Repository} are
* permitted, even from concurrent threads.
* Multiple simultaneous TreeWalk instances per
* {@link org.eclipse.jgit.lib.Repository} are permitted, even from concurrent
* threads.
*/ */
public class TreeWalk implements AutoCloseable, AttributesProvider { public class TreeWalk implements AutoCloseable, AttributesProvider {
private static final AbstractTreeIterator[] NO_TREES = {}; private static final AbstractTreeIterator[] NO_TREES = {};
private Map<String, String> filterCommandsByNameDotType = new HashMap<>(); private Map<String, String> filterCommandsByNameDotType = new HashMap<>();


/** /**
* Set the operation type of this walk
*
* @param operationType * @param operationType
* a {@link org.eclipse.jgit.treewalk.TreeWalk.OperationType}
* object.
* @since 4.2 * @since 4.2
*/ */
public void setOperationType(OperationType operationType) { public void setOperationType(OperationType operationType) {
* one or more trees to walk through, all with the same root. * one or more trees to walk through, all with the same root.
* @return a new tree walk configured for exactly this one path; null if no * @return a new tree walk configured for exactly this one path; null if no
* path was found in any of the trees. * path was found in any of the trees.
* @throws IOException
* @throws java.io.IOException
* reading a pack file or loose object failed. * reading a pack file or loose object failed.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* an tree object could not be read as its data stream did not * an tree object could not be read as its data stream did not
* appear to be a tree, or could not be inflated. * appear to be a tree, or could not be inflated.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* an object we expected to be a tree was not a tree. * an object we expected to be a tree was not a tree.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* a tree object was not found. * a tree object was not found.
*/ */
public static TreeWalk forPath(final ObjectReader reader, final String path, public static TreeWalk forPath(final ObjectReader reader, final String path,
* *
* @param repo * @param repo
* repository to read config data and * repository to read config data and
* {@link AttributesNodeProvider} from.
* {@link org.eclipse.jgit.attributes.AttributesNodeProvider}
* from.
* @param reader * @param reader
* the reader the walker will obtain tree data from. * the reader the walker will obtain tree data from.
* @param path * @param path
* one or more trees to walk through, all with the same root. * one or more trees to walk through, all with the same root.
* @return a new tree walk configured for exactly this one path; null if no * @return a new tree walk configured for exactly this one path; null if no
* path was found in any of the trees. * path was found in any of the trees.
* @throws IOException
* @throws java.io.IOException
* reading a pack file or loose object failed. * reading a pack file or loose object failed.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* an tree object could not be read as its data stream did not * an tree object could not be read as its data stream did not
* appear to be a tree, or could not be inflated. * appear to be a tree, or could not be inflated.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* an object we expected to be a tree was not a tree. * an object we expected to be a tree was not a tree.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* a tree object was not found. * a tree object was not found.
* @since 4.3 * @since 4.3
*/ */
* one or more trees to walk through, all with the same root. * one or more trees to walk through, all with the same root.
* @return a new tree walk configured for exactly this one path; null if no * @return a new tree walk configured for exactly this one path; null if no
* path was found in any of the trees. * path was found in any of the trees.
* @throws IOException
* @throws java.io.IOException
* reading a pack file or loose object failed. * reading a pack file or loose object failed.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* an tree object could not be read as its data stream did not * an tree object could not be read as its data stream did not
* appear to be a tree, or could not be inflated. * appear to be a tree, or could not be inflated.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* an object we expected to be a tree was not a tree. * an object we expected to be a tree was not a tree.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* a tree object was not found. * a tree object was not found.
*/ */
public static TreeWalk forPath(final Repository db, final String path, public static TreeWalk forPath(final Repository db, final String path,
* the single tree to walk through. * the single tree to walk through.
* @return a new tree walk configured for exactly this one path; null if no * @return a new tree walk configured for exactly this one path; null if no
* path was found in any of the trees. * path was found in any of the trees.
* @throws IOException
* @throws java.io.IOException
* reading a pack file or loose object failed. * reading a pack file or loose object failed.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* an tree object could not be read as its data stream did not * an tree object could not be read as its data stream did not
* appear to be a tree, or could not be inflated. * appear to be a tree, or could not be inflated.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* an object we expected to be a tree was not a tree. * an object we expected to be a tree was not a tree.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* a tree object was not found. * a tree object was not found.
*/ */
public static TreeWalk forPath(final Repository db, final String path, public static TreeWalk forPath(final Repository db, final String path,
this.closeReader = closeReader; this.closeReader = closeReader;
} }


/** @return the reader this walker is using to load objects. */
/**
* Get the reader this walker is using to load objects.
*
* @return the reader this walker is using to load objects.
*/
public ObjectReader getObjectReader() { public ObjectReader getObjectReader() {
return reader; return reader;
} }


/** /**
* @return the {@link OperationType}
* Get the operation type
*
* @return the {@link org.eclipse.jgit.treewalk.TreeWalk.OperationType}
* @since 4.3 * @since 4.3
*/ */
public OperationType getOperationType() { public OperationType getOperationType() {
} }


/** /**
* {@inheritDoc}
* <p>
* Release any resources used by this walker's reader. * Release any resources used by this walker's reader.
* <p> * <p>
* A walker that has been released can be used again, but may need to be * A walker that has been released can be used again, but may need to be
* Note that filters are not thread-safe and may not be shared by concurrent * Note that filters are not thread-safe and may not be shared by concurrent
* TreeWalk instances. Every TreeWalk must be supplied its own unique * TreeWalk instances. Every TreeWalk must be supplied its own unique
* filter, unless the filter implementation specifically states it is (and * filter, unless the filter implementation specifically states it is (and
* always will be) thread-safe. Callers may use {@link TreeFilter#clone()}
* to create a unique filter tree for this TreeWalk instance.
* always will be) thread-safe. Callers may use
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#clone()} to create a
* unique filter tree for this TreeWalk instance.
* *
* @param newFilter * @param newFilter
* the new filter. If null the special {@link TreeFilter#ALL}
* filter will be used instead, as it matches every entry.
* the new filter. If null the special
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#ALL} filter
* will be used instead, as it matches every entry.
* @see org.eclipse.jgit.treewalk.filter.AndTreeFilter * @see org.eclipse.jgit.treewalk.filter.AndTreeFilter
* @see org.eclipse.jgit.treewalk.filter.OrTreeFilter * @see org.eclipse.jgit.treewalk.filter.OrTreeFilter
*/ */
} }


/** /**
* Sets the {@link AttributesNodeProvider} for this {@link TreeWalk}.
* Sets the {@link org.eclipse.jgit.attributes.AttributesNodeProvider} for
* this {@link org.eclipse.jgit.treewalk.TreeWalk}.
* <p> * <p>
* This is a requirement for a correct computation of the git attributes.
* If this {@link TreeWalk} has been built using
* This is a requirement for a correct computation of the git attributes. If
* this {@link org.eclipse.jgit.treewalk.TreeWalk} has been built using
* {@link #TreeWalk(Repository)} constructor, the * {@link #TreeWalk(Repository)} constructor, the
* {@link AttributesNodeProvider} has already been set. Indeed,the
* {@link Repository} can provide an {@link AttributesNodeProvider} using
* {@link Repository#createAttributesNodeProvider()} method. Otherwise you
* should provide one.
* {@link org.eclipse.jgit.attributes.AttributesNodeProvider} has already
* been set. Indeed,the {@link org.eclipse.jgit.lib.Repository} can provide
* an {@link org.eclipse.jgit.attributes.AttributesNodeProvider} using
* {@link org.eclipse.jgit.lib.Repository#createAttributesNodeProvider()}
* method. Otherwise you should provide one.
* </p> * </p>
* *
* @see Repository#createAttributesNodeProvider() * @see Repository#createAttributesNodeProvider()
* @param provider * @param provider
* a {@link org.eclipse.jgit.attributes.AttributesNodeProvider}
* object.
* @since 4.2 * @since 4.2
*/ */
public void setAttributesNodeProvider(AttributesNodeProvider provider) { public void setAttributesNodeProvider(AttributesNodeProvider provider) {
} }


/** /**
* @return the {@link AttributesNodeProvider} for this {@link TreeWalk}.
* Get the attributes node provider
*
* @return the {@link org.eclipse.jgit.attributes.AttributesNodeProvider}
* for this {@link org.eclipse.jgit.treewalk.TreeWalk}.
* @since 4.3 * @since 4.3
*/ */
public AttributesNodeProvider getAttributesNodeProvider() { public AttributesNodeProvider getAttributesNodeProvider() {
} }


/** /**
* {@inheritDoc}
* <p>
* Retrieve the git attributes for the current entry. * Retrieve the git attributes for the current entry.
* *
* <h4>Git attribute computation</h4> * <h4>Git attribute computation</h4>
* provided it will fallback on the {@link DirCacheIterator}. * provided it will fallback on the {@link DirCacheIterator}.
* </p> * </p>
* *
* @return a {@link Set} of {@link Attribute}s that match the current entry.
* @since 4.2 * @since 4.2
*/ */
@Override @Override
} }


/** /**
* Get the EOL stream type of the current entry using the config and
* {@link #getAttributes()}.
*
* @param opType * @param opType
* the operationtype (checkin/checkout) which should be used * the operationtype (checkin/checkout) which should be used
* @return the EOL stream type of the current entry using the config and * @return the EOL stream type of the current entry using the config and
* {@link #getAttributes()} Note that this method may return null if
* the {@link TreeWalk} is not based on a working tree
* {@link #getAttributes()}. Note that this method may return null
* if the {@link org.eclipse.jgit.treewalk.TreeWalk} is not based on
* a working tree
* @since 4.10 * @since 4.10
*/ */
@Nullable @Nullable
} }


/** /**
* Get the EOL stream type of the current entry using the config and
* {@link #getAttributes()}.
*
* @return the EOL stream type of the current entry using the config and * @return the EOL stream type of the current entry using the config and
* {@link #getAttributes()} Note that this method may return null if
* the {@link TreeWalk} is not based on a working tree
* {@link #getAttributes()}. Note that this method may return null
* if the {@link org.eclipse.jgit.treewalk.TreeWalk} is not based on
* a working tree
* @since 4.3 * @since 4.3
* @deprecated use {@link #getEolStreamType(OperationType)} instead. * @deprecated use {@link #getEolStreamType(OperationType)} instead.
*/ */
return (getEolStreamType(operationType)); return (getEolStreamType(operationType));
} }


/** Reset this walker so new tree iterators can be added to it. */
/**
* Reset this walker so new tree iterators can be added to it.
*/
public void reset() { public void reset() {
attrs = null; attrs = null;
attributesHandler = null; attributesHandler = null;
* @param id * @param id
* the tree we need to parse. The walker will execute over this * the tree we need to parse. The walker will execute over this
* single tree if the reset is successful. * single tree if the reset is successful.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* the given tree object does not exist in this repository. * the given tree object does not exist in this repository.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the given object id does not denote a tree, but instead names * the given object id does not denote a tree, but instead names
* some other non-tree type of object. Note that commits are not * some other non-tree type of object. Note that commits are not
* trees, even if they are sometimes called a "tree-ish". * trees, even if they are sometimes called a "tree-ish".
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the object claimed to be a tree, but its contents did not * the object claimed to be a tree, but its contents did not
* appear to be a tree. The repository may have data corruption. * appear to be a tree. The repository may have data corruption.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public void reset(final AnyObjectId id) throws MissingObjectException, public void reset(final AnyObjectId id) throws MissingObjectException,
* @param ids * @param ids
* the trees we need to parse. The walker will execute over this * the trees we need to parse. The walker will execute over this
* many parallel trees if the reset is successful. * many parallel trees if the reset is successful.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* the given tree object does not exist in this repository. * the given tree object does not exist in this repository.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the given object id does not denote a tree, but instead names * the given object id does not denote a tree, but instead names
* some other non-tree type of object. Note that commits are not * some other non-tree type of object. Note that commits are not
* trees, even if they are sometimes called a "tree-ish". * trees, even if they are sometimes called a "tree-ish".
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the object claimed to be a tree, but its contents did not * the object claimed to be a tree, but its contents did not
* appear to be a tree. The repository may have data corruption. * appear to be a tree. The repository may have data corruption.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public void reset(final AnyObjectId... ids) throws MissingObjectException, public void reset(final AnyObjectId... ids) throws MissingObjectException,
* @param id * @param id
* identity of the tree object the caller wants walked. * identity of the tree object the caller wants walked.
* @return position of this tree within the walker. * @return position of this tree within the walker.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* the given tree object does not exist in this repository. * the given tree object does not exist in this repository.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* the given object id does not denote a tree, but instead names * the given object id does not denote a tree, but instead names
* some other non-tree type of object. Note that commits are not * some other non-tree type of object. Note that commits are not
* trees, even if they are sometimes called a "tree-ish". * trees, even if they are sometimes called a "tree-ish".
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the object claimed to be a tree, but its contents did not * the object claimed to be a tree, but its contents did not
* appear to be a tree. The repository may have data corruption. * appear to be a tree. The repository may have data corruption.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public int addTree(final AnyObjectId id) throws MissingObjectException, public int addTree(final AnyObjectId id) throws MissingObjectException,
* *
* @return true if there is an entry available; false if all entries have * @return true if there is an entry available; false if all entries have
* been walked and the walk of this set of tree iterators is over. * been walked and the walk of this set of tree iterators is over.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* {@link #isRecursive()} was enabled, a subtree was found, but * {@link #isRecursive()} was enabled, a subtree was found, but
* the subtree object does not exist in this repository. The * the subtree object does not exist in this repository. The
* repository may be missing objects. * repository may be missing objects.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* {@link #isRecursive()} was enabled, a subtree was found, and * {@link #isRecursive()} was enabled, a subtree was found, and
* the subtree id does not denote a tree, but instead names some * the subtree id does not denote a tree, but instead names some
* other non-tree type of object. The repository may have data * other non-tree type of object. The repository may have data
* corruption. * corruption.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the contents of a tree did not appear to be a tree. The * the contents of a tree did not appear to be a tree. The
* repository may have data corruption. * repository may have data corruption.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public boolean next() throws MissingObjectException, public boolean next() throws MissingObjectException,
* iterators to manage only one list of items, with the diving handled by * iterators to manage only one list of items, with the diving handled by
* recursive trees. * recursive trees.
* *
* @param <T>
* type of the tree iterator expected by the caller.
* @param nth * @param nth
* tree to obtain the current iterator of. * tree to obtain the current iterator of.
* @param clazz * @param clazz
} }


/** /**
* Obtain the raw {@link FileMode} bits for the current entry.
* Obtain the raw {@link org.eclipse.jgit.lib.FileMode} bits for the current
* entry.
* <p> * <p>
* Every added tree supplies mode bits, even if the tree does not contain * Every added tree supplies mode bits, even if the tree does not contain
* the current entry. In the latter case {@link FileMode#MISSING}'s mode
* bits (0) are returned.
* the current entry. In the latter case
* {@link org.eclipse.jgit.lib.FileMode#MISSING}'s mode bits (0) are
* returned.
* *
* @param nth * @param nth
* tree to obtain the mode bits from. * tree to obtain the mode bits from.
} }


/** /**
* Obtain the {@link FileMode} for the current entry.
* Obtain the {@link org.eclipse.jgit.lib.FileMode} for the current entry.
* <p> * <p>
* Every added tree supplies a mode, even if the tree does not contain the * Every added tree supplies a mode, even if the tree does not contain the
* current entry. In the latter case {@link FileMode#MISSING} is returned.
* current entry. In the latter case
* {@link org.eclipse.jgit.lib.FileMode#MISSING} is returned.
* *
* @param nth * @param nth
* tree to obtain the mode from. * tree to obtain the mode from.
} }


/** /**
* Obtain the {@link FileMode} for the current entry on the currentHead tree
* Obtain the {@link org.eclipse.jgit.lib.FileMode} for the current entry on
* the currentHead tree
* *
* @return mode for the current entry of the currentHead tree. * @return mode for the current entry of the currentHead tree.
* @since 4.3 * @since 4.3
* whenever possible. * whenever possible.
* <p> * <p>
* Every tree supplies an object id, even if the tree does not contain the * Every tree supplies an object id, even if the tree does not contain the
* current entry. In the latter case {@link ObjectId#zeroId()} is returned.
* current entry. In the latter case
* {@link org.eclipse.jgit.lib.ObjectId#zeroId()} is returned.
* *
* @param nth * @param nth
* tree to obtain the object identifier from. * tree to obtain the object identifier from.
* @return object identifier for the current tree entry. * @return object identifier for the current tree entry.
* @see #getObjectId(MutableObjectId, int) * @see #getObjectId(MutableObjectId, int)
* @see #idEqual(int, int) * @see #idEqual(int, int)
* @see #getObjectId(MutableObjectId, int)
* @see #idEqual(int, int)
*/ */
public ObjectId getObjectId(final int nth) { public ObjectId getObjectId(final int nth) {
final AbstractTreeIterator t = trees[nth]; final AbstractTreeIterator t = trees[nth];
* Obtain the ObjectId for the current entry. * Obtain the ObjectId for the current entry.
* <p> * <p>
* Every tree supplies an object id, even if the tree does not contain the * Every tree supplies an object id, even if the tree does not contain the
* current entry. In the latter case {@link ObjectId#zeroId()} is supplied.
* current entry. In the latter case
* {@link org.eclipse.jgit.lib.ObjectId#zeroId()} is supplied.
* <p> * <p>
* Applications should try to use {@link #idEqual(int, int)} when possible * Applications should try to use {@link #idEqual(int, int)} when possible
* as it avoids conversion overheads. * as it avoids conversion overheads.
} }


/** /**
* Get the path length of the current entry.
*
* @return The path length of the current entry. * @return The path length of the current entry.
*/ */
public int getPathLength() { public int getPathLength() {
* If the current entry is a subtree this method arranges for its children * If the current entry is a subtree this method arranges for its children
* to be returned before the next sibling following the subtree is returned. * to be returned before the next sibling following the subtree is returned.
* *
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* a subtree was found, but the subtree object does not exist in * a subtree was found, but the subtree object does not exist in
* this repository. The repository may be missing objects. * this repository. The repository may be missing objects.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* a subtree was found, and the subtree id does not denote a * a subtree was found, and the subtree id does not denote a
* tree, but instead names some other non-tree type of object. * tree, but instead names some other non-tree type of object.
* The repository may have data corruption. * The repository may have data corruption.
* @throws CorruptObjectException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* the contents of a tree did not appear to be a tree. The * the contents of a tree did not appear to be a tree. The
* repository may have data corruption. * repository may have data corruption.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read. * a loose object or pack file could not be read.
*/ */
public void enterSubtree() throws MissingObjectException, public void enterSubtree() throws MissingObjectException,
} }


/** /**
* Get the tree of that type.
*
* @param type * @param type
* of the tree to be queried * of the tree to be queried
* @return the tree of that type or null if none is present
* @return the tree of that type or null if none is present.
* @since 4.3 * @since 4.3
* @param <T>
* a tree type.
*/ */
public <T extends AbstractTreeIterator> T getTree( public <T extends AbstractTreeIterator> T getTree(
Class<T> type) { Class<T> type) {
* which type of filterCommand should be executed. E.g. "clean", * which type of filterCommand should be executed. E.g. "clean",
* "smudge" * "smudge"
* @return a filter command * @return a filter command
* @throws IOException
* @throws java.io.IOException
* @since 4.2 * @since 4.2
*/ */
public String getFilterCommand(String filterCommandType) public String getFilterCommand(String filterCommandType)

+ 55
- 30
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java Zobrazit soubor

import org.eclipse.jgit.attributes.FilterCommand; import org.eclipse.jgit.attributes.FilterCommand;
import org.eclipse.jgit.attributes.FilterCommandRegistry; import org.eclipse.jgit.attributes.FilterCommandRegistry;
import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator; import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.util.sha1.SHA1; import org.eclipse.jgit.util.sha1.SHA1;


/** /**
* Walks a working directory tree as part of a {@link TreeWalk}.
* Walks a working directory tree as part of a
* {@link org.eclipse.jgit.treewalk.TreeWalk}.
* <p> * <p>
* Most applications will want to use the standard implementation of this * Most applications will want to use the standard implementation of this
* iterator, {@link FileTreeIterator}, as that does all IO through the standard
* <code>java.io</code> package. Plugins for a Java based IDE may however wish
* to create their own implementations of this class to allow traversal of the
* IDE's project space, as well as benefit from any caching the IDE may have.
* iterator, {@link org.eclipse.jgit.treewalk.FileTreeIterator}, as that does
* all IO through the standard <code>java.io</code> package. Plugins for a Java
* based IDE may however wish to create their own implementations of this class
* to allow traversal of the IDE's project space, as well as benefit from any
* caching the IDE may have.
* *
* @see FileTreeIterator * @see FileTreeIterator
*/ */
} }


/** /**
* Define the matching {@link DirCacheIterator}, to optimize ObjectIds.
* Define the matching {@link org.eclipse.jgit.dircache.DirCacheIterator},
* to optimize ObjectIds.
* *
* Once the DirCacheIterator has been set this iterator must only be * Once the DirCacheIterator has been set this iterator must only be
* advanced by the TreeWalk that is supplied, as it assumes that itself and * advanced by the TreeWalk that is supplied, as it assumes that itself and
* @param walk * @param walk
* the walk that will be advancing this iterator. * the walk that will be advancing this iterator.
* @param treeId * @param treeId
* index of the matching {@link DirCacheIterator}.
* index of the matching
* {@link org.eclipse.jgit.dircache.DirCacheIterator}.
*/ */
public void setDirCacheIterator(TreeWalk walk, int treeId) { public void setDirCacheIterator(TreeWalk walk, int treeId) {
state.walk = walk; state.walk = walk;
state.dirCacheTree = treeId; state.dirCacheTree = treeId;
} }


/** {@inheritDoc} */
@Override @Override
public boolean hasId() { public boolean hasId() {
if (contentIdFromPtr == ptr) if (contentIdFromPtr == ptr)
return (mode & FileMode.TYPE_MASK) == FileMode.TYPE_FILE; return (mode & FileMode.TYPE_MASK) == FileMode.TYPE_FILE;
} }


/** {@inheritDoc} */
@Override @Override
public byte[] idBuffer() { public byte[] idBuffer() {
if (contentIdFromPtr == ptr) if (contentIdFromPtr == ptr)
return zeroid; return zeroid;
} }


/** {@inheritDoc} */
@Override @Override
public boolean isWorkTree() { public boolean isWorkTree() {
return true; return true;
* Get submodule id for given entry. * Get submodule id for given entry.
* *
* @param e * @param e
* a {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry}
* object.
* @return non-null submodule id * @return non-null submodule id
*/ */
protected byte[] idSubmodule(Entry e) { protected byte[] idSubmodule(Entry e) {
* relative to the directory. * relative to the directory.
* *
* @param directory * @param directory
* a {@link java.io.File} object.
* @param e * @param e
* a {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry}
* object.
* @return non-null submodule id * @return non-null submodule id
*/ */
protected byte[] idSubmodule(File directory, Entry e) { protected byte[] idSubmodule(File directory, Entry e) {
return state.options; return state.options;
} }


/** {@inheritDoc} */
@Override @Override
public int idOffset() { public int idOffset() {
return contentIdOffset; return contentIdOffset;
} }


/** {@inheritDoc} */
@Override @Override
public void reset() { public void reset() {
if (!first()) { if (!first()) {
} }
} }


/** {@inheritDoc} */
@Override @Override
public boolean first() { public boolean first() {
return ptr == 0; return ptr == 0;
} }


/** {@inheritDoc} */
@Override @Override
public boolean eof() { public boolean eof() {
return ptr == entryCnt; return ptr == entryCnt;
} }


/** {@inheritDoc} */
@Override @Override
public void next(final int delta) throws CorruptObjectException { public void next(final int delta) throws CorruptObjectException {
ptr += delta; ptr += delta;
} }
} }


/** {@inheritDoc} */
@Override @Override
public void back(final int delta) throws CorruptObjectException { public void back(final int delta) throws CorruptObjectException {
ptr -= delta; ptr -= delta;
* Get the filtered input length of this entry * Get the filtered input length of this entry
* *
* @return size of the content, in bytes * @return size of the content, in bytes
* @throws IOException
* @throws java.io.IOException
*/ */
public long getEntryContentLength() throws IOException { public long getEntryContentLength() throws IOException {
if (canonLen == -1) { if (canonLen == -1) {
* The caller will close the stream once complete. * The caller will close the stream once complete.
* *
* @return a stream to read from the file. * @return a stream to read from the file.
* @throws IOException
* @throws java.io.IOException
* the file could not be opened for reading. * the file could not be opened for reading.
*/ */
public InputStream openEntryStream() throws IOException { public InputStream openEntryStream() throws IOException {
* Determine if the current entry path is ignored by an ignore rule. * Determine if the current entry path is ignored by an ignore rule.
* *
* @return true if the entry was ignored by an ignore rule file. * @return true if the entry was ignored by an ignore rule file.
* @throws IOException
* @throws java.io.IOException
* a relevant ignore rule file exists but cannot be read. * a relevant ignore rule file exists but cannot be read.
*/ */
public boolean isEntryIgnored() throws IOException { public boolean isEntryIgnored() throws IOException {
* @param pLen * @param pLen
* the length of the path in the path buffer. * the length of the path in the path buffer.
* @return true if the entry is ignored by an ignore rule. * @return true if the entry is ignored by an ignore rule.
* @throws IOException
* @throws java.io.IOException
* a relevant ignore rule file exists but cannot be read. * a relevant ignore rule file exists but cannot be read.
*/ */
protected boolean isEntryIgnored(final int pLen) throws IOException { protected boolean isEntryIgnored(final int pLen) throws IOException {
} }


/** /**
* Retrieves the {@link AttributesNode} for the current entry.
* Retrieves the {@link org.eclipse.jgit.attributes.AttributesNode} for the
* current entry.
* *
* @return {@link AttributesNode} for the current entry.
* @return the {@link org.eclipse.jgit.attributes.AttributesNode} for the
* current entry.
* @throws IOException * @throws IOException
* if an error is raised while parsing the .gitattributes file
* @since 3.7
*/ */
public AttributesNode getEntryAttributesNode() throws IOException { public AttributesNode getEntryAttributesNode() throws IOException {
if (attributesNode instanceof PerDirectoryAttributesNode) if (attributesNode instanceof PerDirectoryAttributesNode)
* Is the file mode of the current entry different than the given raw mode? * Is the file mode of the current entry different than the given raw mode?
* *
* @param rawMode * @param rawMode
* an int.
* @return true if different, false otherwise * @return true if different, false otherwise
*/ */
public boolean isModeDifferent(final int rawMode) { public boolean isModeDifferent(final int rawMode) {


/** /**
* Compare the metadata (mode, length, modification-timestamp) of the * Compare the metadata (mode, length, modification-timestamp) of the
* current entry and a {@link DirCacheEntry}
* current entry and a {@link org.eclipse.jgit.dircache.DirCacheEntry}
* *
* @param entry * @param entry
* the {@link DirCacheEntry} to compare with
* @return a {@link MetadataDiff} which tells whether and how the entries
* metadata differ
* the {@link org.eclipse.jgit.dircache.DirCacheEntry} to compare
* with
* @return a
* {@link org.eclipse.jgit.treewalk.WorkingTreeIterator.MetadataDiff}
* which tells whether and how the entries metadata differ
*/ */
public MetadataDiff compareMetadata(DirCacheEntry entry) { public MetadataDiff compareMetadata(DirCacheEntry entry) {
if (entry.isAssumeValid()) if (entry.isAssumeValid())


/** /**
* Checks whether this entry differs from a given entry from the * Checks whether this entry differs from a given entry from the
* {@link DirCache}.
* {@link org.eclipse.jgit.dircache.DirCache}.
* *
* File status information is used and if status is same we consider the * File status information is used and if status is same we consider the
* file identical to the state in the working directory. Native git uses * file identical to the state in the working directory. Native git uses
* @param reader * @param reader
* access to repository objects if necessary. Should not be null. * access to repository objects if necessary. Should not be null.
* @return true if content is most likely different. * @return true if content is most likely different.
* @throws IOException
* @throws java.io.IOException
* @since 3.3 * @since 3.3
*/ */
public boolean isModified(DirCacheEntry entry, boolean forceContentCheck, public boolean isModified(DirCacheEntry entry, boolean forceContentCheck,
* in the index. * in the index.
* *
* @param indexIter * @param indexIter
* {@link DirCacheIterator} positioned at the same entry as this
* iterator or null if no {@link DirCacheIterator} is available
* at this iterator's current entry
* {@link org.eclipse.jgit.dircache.DirCacheIterator} positioned
* at the same entry as this iterator or null if no
* {@link org.eclipse.jgit.dircache.DirCacheIterator} is
* available at this iterator's current entry
* @return index file mode * @return index file mode
*/ */
public FileMode getIndexFileMode(final DirCacheIterator indexIter) { public FileMode getIndexFileMode(final DirCacheIterator indexIter) {
* @param entry * @param entry
* to read * to read
* @return the entry's content as a normalized string * @return the entry's content as a normalized string
* @throws IOException
* @throws java.io.IOException
* if the entry cannot be read or does not denote a symlink * if the entry cannot be read or does not denote a symlink
* @since 4.6 * @since 4.6
*/ */
} }


/** /**
* Get the clean filter command for the current entry.
*
* @return the clean filter command for the current entry or * @return the clean filter command for the current entry or
* <code>null</code> if no such command is defined * <code>null</code> if no such command is defined
* @throws IOException
* @throws java.io.IOException
* @since 4.2 * @since 4.2
*/ */
public String getCleanFilterCommand() throws IOException { public String getCleanFilterCommand() throws IOException {
} }


/** /**
* Get the eol stream type for the current entry.
*
* @return the eol stream type for the current entry or <code>null</code> if * @return the eol stream type for the current entry or <code>null</code> if
* it cannot be determined. When state or state.walk is null or the * it cannot be determined. When state or state.walk is null or the
* {@link TreeWalk} is not based on a {@link Repository} then null
* is returned.
* @throws IOException
* {@link org.eclipse.jgit.treewalk.TreeWalk} is not based on a
* {@link org.eclipse.jgit.lib.Repository} then null is returned.
* @throws java.io.IOException
* @since 4.3 * @since 4.3
*/ */
public EolStreamType getEolStreamType() throws IOException { public EolStreamType getEolStreamType() throws IOException {

+ 27
- 7
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeOptions.java Zobrazit soubor

import org.eclipse.jgit.lib.CoreConfig.HideDotFiles; import org.eclipse.jgit.lib.CoreConfig.HideDotFiles;
import org.eclipse.jgit.lib.CoreConfig.SymLinks; import org.eclipse.jgit.lib.CoreConfig.SymLinks;


/** Options used by the {@link WorkingTreeIterator}. */
/**
* Options used by the {@link org.eclipse.jgit.treewalk.WorkingTreeIterator}.
*/
public class WorkingTreeOptions { public class WorkingTreeOptions {
/** Key for {@link Config#get(SectionParser)}. */ /** Key for {@link Config#get(SectionParser)}. */
public static final Config.SectionParser<WorkingTreeOptions> KEY = public static final Config.SectionParser<WorkingTreeOptions> KEY =
} }


/** @return true if the execute bit on working files should be trusted. */ /** @return true if the execute bit on working files should be trusted. */
/**
* Whether the execute bit on working files should be trusted.
*
* @return {@code true} if the execute bit on working files should be
* trusted.
*/
public boolean isFileMode() { public boolean isFileMode() {
return fileMode; return fileMode;
} }


/** @return how automatic CRLF conversion has been configured. */
/**
* Get automatic CRLF conversion configuration.
*
* @return how automatic CRLF conversion has been configured.
*/
public AutoCRLF getAutoCRLF() { public AutoCRLF getAutoCRLF() {
return autoCRLF; return autoCRLF;
} }


/** /**
* @return how text line endings should be normalized.
* Get how text line endings should be normalized.
* *
* @return how text line endings should be normalized.
* @since 4.3 * @since 4.3
*/ */
public EOL getEOL() { public EOL getEOL() {
} }


/** /**
* @return how stat data is compared
* Get how stat data is compared.
*
* @return how stat data is compared.
* @since 3.0 * @since 3.0
*/ */
public CheckStat getCheckStat() { public CheckStat getCheckStat() {
} }


/** /**
* Get how we handle symbolic links
*
* @return how we handle symbolic links * @return how we handle symbolic links
* @since 3.3 * @since 3.3
*/ */
} }


/** /**
* Get how we create '.'-files (on Windows)
*
* @return how we create '.'-files (on Windows) * @return how we create '.'-files (on Windows)
* @since 3.5 * @since 3.5
*/ */
} }


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

+ 4
- 3
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/AndTreeFilter.java Zobrazit soubor

* Includes a tree entry only if all subfilters include the same tree entry. * Includes a tree entry only if all subfilters include the same tree entry.
* <p> * <p>
* Classic shortcut behavior is used, so evaluation of the * Classic shortcut behavior is used, so evaluation of the
* {@link TreeFilter#include(TreeWalk)} method stops as soon as a false result
* is obtained. Applications can improve filtering performance by placing faster
* filters that are more likely to reject a result earlier in the list.
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#include(TreeWalk)} method
* stops as soon as a false result is obtained. Applications can improve
* filtering performance by placing faster filters that are more likely to
* reject a result earlier in the list.
*/ */
public abstract class AndTreeFilter extends TreeFilter { public abstract class AndTreeFilter extends TreeFilter {
/** /**

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/ByteArraySet.java Zobrazit soubor

table = new byte[sz][]; table = new byte[sz][];
} }


/** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

+ 40
- 23
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/IndexDiffFilter.java Zobrazit soubor

import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.treewalk.WorkingTreeIterator;


/** /**
* A performance optimized variant of {@link TreeFilter#ANY_DIFF} which should
* be used when among the walked trees there is a {@link DirCacheIterator} and a
* {@link WorkingTreeIterator}. Please see the documentation of
* {@link TreeFilter#ANY_DIFF} for a basic description of the semantics.
* A performance optimized variant of
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#ANY_DIFF} which should be
* used when among the walked trees there is a
* {@link org.eclipse.jgit.dircache.DirCacheIterator} and a
* {@link org.eclipse.jgit.treewalk.WorkingTreeIterator}. Please see the
* documentation of {@link org.eclipse.jgit.treewalk.filter.TreeFilter#ANY_DIFF}
* for a basic description of the semantics.
* <p> * <p>
* This filter tries to avoid computing content ids of the files in the * This filter tries to avoid computing content ids of the files in the
* working-tree. In contrast to {@link TreeFilter#ANY_DIFF} this filter takes
* care to first compare the entry from the {@link DirCacheIterator} with the
* entries from all other iterators besides the {@link WorkingTreeIterator}.
* Since all those entries have fast access to content ids that is very fast. If
* a difference is detected in this step this filter decides to include that
* path before even looking at the working-tree entry.
* working-tree. In contrast to
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#ANY_DIFF} this filter
* takes care to first compare the entry from the
* {@link org.eclipse.jgit.dircache.DirCacheIterator} with the entries from all
* other iterators besides the
* {@link org.eclipse.jgit.treewalk.WorkingTreeIterator}. Since all those
* entries have fast access to content ids that is very fast. If a difference is
* detected in this step this filter decides to include that path before even
* looking at the working-tree entry.
* <p> * <p>
* If no difference is found then we have to compare index and working-tree as * If no difference is found then we have to compare index and working-tree as
* the last step. By making use of * the last step. By making use of
* {@link WorkingTreeIterator#isModified(org.eclipse.jgit.dircache.DirCacheEntry, boolean, ObjectReader)}
* {@link org.eclipse.jgit.treewalk.WorkingTreeIterator#isModified(org.eclipse.jgit.dircache.DirCacheEntry, boolean, ObjectReader)}
* we can avoid the computation of the content id if the file is not dirty. * we can avoid the computation of the content id if the file is not dirty.
* <p> * <p>
* Instances of this filter should not be used for multiple {@link TreeWalk}s.
* Always construct a new instance of this filter for each TreeWalk.
* Instances of this filter should not be used for multiple
* {@link org.eclipse.jgit.treewalk.TreeWalk}s. Always construct a new instance
* of this filter for each TreeWalk.
*/ */
public class IndexDiffFilter extends TreeFilter { public class IndexDiffFilter extends TreeFilter {
private final int dirCache; private final int dirCache;
* filter in multiple treewalks. * filter in multiple treewalks.
* *
* @param dirCacheIndex * @param dirCacheIndex
* the index of the {@link DirCacheIterator} in the associated
* treewalk
* the index of the
* {@link org.eclipse.jgit.dircache.DirCacheIterator} in the
* associated treewalk
* @param workingTreeIndex * @param workingTreeIndex
* the index of the {@link WorkingTreeIterator} in the associated
* treewalk
* the index of the
* {@link org.eclipse.jgit.treewalk.WorkingTreeIterator} in the
* associated treewalk
*/ */
public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex) { public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex) {
this(dirCacheIndex, workingTreeIndex, true /* honor ignores */); this(dirCacheIndex, workingTreeIndex, true /* honor ignores */);
* filter in multiple treewalks. * filter in multiple treewalks.
* *
* @param dirCacheIndex * @param dirCacheIndex
* the index of the {@link DirCacheIterator} in the associated
* treewalk
* the index of the
* {@link org.eclipse.jgit.dircache.DirCacheIterator} in the
* associated treewalk
* @param workingTreeIndex * @param workingTreeIndex
* the index of the {@link WorkingTreeIterator} in the associated
* treewalk
* the index of the
* {@link org.eclipse.jgit.treewalk.WorkingTreeIterator} in the
* associated treewalk
* @param honorIgnores * @param honorIgnores
* true if the filter should skip working tree files that are * true if the filter should skip working tree files that are
* declared as ignored by the standard exclude mechanisms..
* declared as ignored by the standard exclude mechanisms.
*/ */
public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex, public IndexDiffFilter(int dirCacheIndex, int workingTreeIndex,
boolean honorIgnores) { boolean honorIgnores) {
this.honorIgnores = honorIgnores; this.honorIgnores = honorIgnores;
} }


/** {@inheritDoc} */
@Override @Override
public boolean include(TreeWalk tw) throws MissingObjectException, public boolean include(TreeWalk tw) throws MissingObjectException,
IncorrectObjectTypeException, IOException { IncorrectObjectTypeException, IOException {
return tw.getTree(workingTree, WorkingTreeIterator.class); return tw.getTree(workingTree, WorkingTreeIterator.class);
} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
// We cannot compare subtrees in the working tree, so encourage // We cannot compare subtrees in the working tree, so encourage
return true; return true;
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter clone() { public TreeFilter clone() {
return this; return this;
} }


/** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
return "INDEX_DIFF_FILTER"; //$NON-NLS-1$ return "INDEX_DIFF_FILTER"; //$NON-NLS-1$
} }


/** /**
* <p>Getter for the field <code>untrackedFolders</code>.</p>
*
* @return all paths of folders which contain only untracked files/folders. * @return all paths of folders which contain only untracked files/folders.
* If on the associated treewalk postorder traversal was turned on * If on the associated treewalk postorder traversal was turned on
* (see {@link TreeWalk#setPostOrderTraversal(boolean)}) then an
* (see {@link org.eclipse.jgit.treewalk.TreeWalk#setPostOrderTraversal(boolean)}) then an
* empty list will be returned. * empty list will be returned.
*/ */
public List<String> getUntrackedFolders() { public List<String> getUntrackedFolders() {

+ 7
- 2
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilter.java Zobrazit soubor



/** /**
* A filter for extracting changes between two versions of the dircache. In * A filter for extracting changes between two versions of the dircache. In
* addition to what {@link TreeFilter#ANY_DIFF} would do, it also detects
* changes that will affect decorations and show up in an attempt to commit.
* addition to what {@link org.eclipse.jgit.treewalk.filter.TreeFilter#ANY_DIFF}
* would do, it also detects changes that will affect decorations and show up in
* an attempt to commit.
*/ */
public final class InterIndexDiffFilter extends TreeFilter { public final class InterIndexDiffFilter extends TreeFilter {
private static final int baseTree = 0; private static final int baseTree = 0;
*/ */
public static final TreeFilter INSTANCE = new InterIndexDiffFilter(); public static final TreeFilter INSTANCE = new InterIndexDiffFilter();


/** {@inheritDoc} */
@Override @Override
public boolean include(final TreeWalk walker) { public boolean include(final TreeWalk walker) {
final int n = walker.getTreeCount(); final int n = walker.getTreeCount();
return false; return false;
} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
return false; return false;
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter clone() { public TreeFilter clone() {
return this; return this;
} }


/** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
return "INTERINDEX_DIFF"; //$NON-NLS-1$ return "INTERINDEX_DIFF"; //$NON-NLS-1$

+ 6
- 1
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotIgnoredFilter.java Zobrazit soubor

import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.treewalk.WorkingTreeIterator;


/** /**
* Skip {@link WorkingTreeIterator} entries that appear in gitignore files.
* Skip {@link org.eclipse.jgit.treewalk.WorkingTreeIterator} entries that
* appear in gitignore files.
*/ */
public class NotIgnoredFilter extends TreeFilter { public class NotIgnoredFilter extends TreeFilter {
private final int index; private final int index;
this.index = workdirTreeIndex; this.index = workdirTreeIndex;
} }


/** {@inheritDoc} */
@Override @Override
public boolean include(TreeWalk tw) throws MissingObjectException, public boolean include(TreeWalk tw) throws MissingObjectException,
IncorrectObjectTypeException, IOException { IncorrectObjectTypeException, IOException {
return i == null || !i.isEntryIgnored(); return i == null || !i.isEntryIgnored();
} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
return false; return false;
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter clone() { public TreeFilter clone() {
// immutable // immutable
return this; return this;
} }


/** {@inheritDoc} */
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {

+ 9
- 1
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/NotTreeFilter.java Zobrazit soubor

import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;


/** Includes an entry only if the subfilter does not include the entry. */
/**
* Includes an entry only if the subfilter does not include the entry.
*/
public class NotTreeFilter extends TreeFilter { public class NotTreeFilter extends TreeFilter {
/** /**
* Create a filter that negates the result of another filter. * Create a filter that negates the result of another filter.
a = one; a = one;
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter negate() { public TreeFilter negate() {
return a; return a;
} }


/** {@inheritDoc} */
@Override @Override
public boolean include(final TreeWalk walker) public boolean include(final TreeWalk walker)
throws MissingObjectException, IncorrectObjectTypeException, throws MissingObjectException, IncorrectObjectTypeException,
return matchFilter(walker) == 0; return matchFilter(walker) == 0;
} }


/** {@inheritDoc} */
@Override @Override
public int matchFilter(TreeWalk walker) public int matchFilter(TreeWalk walker)
throws MissingObjectException, IncorrectObjectTypeException, throws MissingObjectException, IncorrectObjectTypeException,
return -1; return -1;
} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
return a.shouldBeRecursive(); return a.shouldBeRecursive();
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter clone() { public TreeFilter clone() {
final TreeFilter n = a.clone(); final TreeFilter n = a.clone();
return n == a ? this : new NotTreeFilter(n); return n == a ? this : new NotTreeFilter(n);
} }


/** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
return "NOT " + a.toString(); //$NON-NLS-1$ return "NOT " + a.toString(); //$NON-NLS-1$

+ 4
- 3
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/OrTreeFilter.java Zobrazit soubor

* Includes a tree entry if any subfilters include the same tree entry. * Includes a tree entry if any subfilters include the same tree entry.
* <p> * <p>
* Classic shortcut behavior is used, so evaluation of the * Classic shortcut behavior is used, so evaluation of the
* {@link TreeFilter#include(TreeWalk)} method stops as soon as a true result is
* obtained. Applications can improve filtering performance by placing faster
* filters that are more likely to accept a result earlier in the list.
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#include(TreeWalk)} method
* stops as soon as a true result is obtained. Applications can improve
* filtering performance by placing faster filters that are more likely to
* accept a result earlier in the list.
*/ */
public abstract class OrTreeFilter extends TreeFilter { public abstract class OrTreeFilter extends TreeFilter {
/** /**

+ 18
- 5
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilter.java Zobrazit soubor

/** /**
* Includes tree entries only if they match the configured path. * Includes tree entries only if they match the configured path.
* <p> * <p>
* Applications should use {@link PathFilterGroup} to connect these into a tree
* filter graph, as the group supports breaking out of traversal once it is
* known the path can never match.
* Applications should use
* {@link org.eclipse.jgit.treewalk.filter.PathFilterGroup} to connect these
* into a tree filter graph, as the group supports breaking out of traversal
* once it is known the path can never match.
*/ */
public class PathFilter extends TreeFilter { public class PathFilter extends TreeFilter {
/** /**
* trailing '/' characters will be trimmed before string's length * trailing '/' characters will be trimmed before string's length
* is checked or is used as part of the constructed filter. * is checked or is used as part of the constructed filter.
* @return a new filter for the requested path. * @return a new filter for the requested path.
* @throws IllegalArgumentException
* @throws java.lang.IllegalArgumentException
* the path supplied was the empty string. * the path supplied was the empty string.
*/ */
public static PathFilter create(String path) { public static PathFilter create(String path) {
pathRaw = Constants.encode(pathStr); pathRaw = Constants.encode(pathStr);
} }


/** @return the path this filter matches. */
/**
* Get the path this filter matches.
*
* @return the path this filter matches.
*/
public String getPath() { public String getPath() {
return pathStr; return pathStr;
} }


/** {@inheritDoc} */
@Override @Override
public boolean include(final TreeWalk walker) { public boolean include(final TreeWalk walker) {
return matchFilter(walker) <= 0; return matchFilter(walker) <= 0;
} }


/** {@inheritDoc} */
@Override @Override
public int matchFilter(final TreeWalk walker) { public int matchFilter(final TreeWalk walker) {
return walker.isPathMatch(pathRaw, pathRaw.length); return walker.isPathMatch(pathRaw, pathRaw.length);
} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
for (final byte b : pathRaw) for (final byte b : pathRaw)
return false; return false;
} }


/** {@inheritDoc} */
@Override @Override
public PathFilter clone() { public PathFilter clone() {
return this; return this;
} }


/** {@inheritDoc} */
@Override @Override
@SuppressWarnings("nls") @SuppressWarnings("nls")
public String toString() { public String toString() {
} }


/** /**
* Whether the path length of this filter matches the length of the current
* path of the supplied TreeWalk.
*
* @param walker * @param walker
* The walk to check against. * The walk to check against.
* @return {@code true} if the path length of this filter matches the length * @return {@code true} if the path length of this filter matches the length

+ 5
- 4
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java Zobrazit soubor

/** /**
* Includes tree entries only if they match one or more configured paths. * Includes tree entries only if they match one or more configured paths.
* <p> * <p>
* Operates like {@link PathFilter} but causes the walk to abort as soon as the
* tree can no longer match any of the paths within the group. This may bypass
* the boolean logic of a higher level AND or OR group, but does improve
* performance for the common case of examining one or more modified paths.
* Operates like {@link org.eclipse.jgit.treewalk.filter.PathFilter} but causes
* the walk to abort as soon as the tree can no longer match any of the paths
* within the group. This may bypass the boolean logic of a higher level AND or
* OR group, but does improve performance for the common case of examining one
* or more modified paths.
* <p> * <p>
* This filter is effectively an OR group around paths, with the early abort * This filter is effectively an OR group around paths, with the early abort
* feature described above. * feature described above.

+ 6
- 3
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathSuffixFilter.java Zobrazit soubor

* paths ending in <code>.txt</code>. * paths ending in <code>.txt</code>.
* <p> * <p>
* Using this filter is recommended instead of filtering the entries using * Using this filter is recommended instead of filtering the entries using
* {@link TreeWalk#getPathString()} and <code>endsWith</code> or some other type
* of string match function.
* {@link org.eclipse.jgit.treewalk.TreeWalk#getPathString()} and
* <code>endsWith</code> or some other type of string match function.
*/ */
public class PathSuffixFilter extends TreeFilter { public class PathSuffixFilter extends TreeFilter {


* @param path * @param path
* the path suffix to filter on. Must not be the empty string. * the path suffix to filter on. Must not be the empty string.
* @return a new filter for the requested path. * @return a new filter for the requested path.
* @throws IllegalArgumentException
* @throws java.lang.IllegalArgumentException
* the path supplied was the empty string. * the path supplied was the empty string.
*/ */
public static PathSuffixFilter create(String path) { public static PathSuffixFilter create(String path) {
pathRaw = Constants.encode(pathStr); pathRaw = Constants.encode(pathStr);
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter clone() { public TreeFilter clone() {
return this; return this;
} }


/** {@inheritDoc} */
@Override @Override
public boolean include(TreeWalk walker) throws MissingObjectException, public boolean include(TreeWalk walker) throws MissingObjectException,
IncorrectObjectTypeException, IOException { IncorrectObjectTypeException, IOException {


} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
return true; return true;

+ 4
- 0
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/SkipWorkTreeFilter.java Zobrazit soubor

this.treeIdx = treeIdx; this.treeIdx = treeIdx;
} }


/** {@inheritDoc} */
@Override @Override
public boolean include(TreeWalk walker) { public boolean include(TreeWalk walker) {
DirCacheIterator i = walker.getTree(treeIdx, DirCacheIterator.class); DirCacheIterator i = walker.getTree(treeIdx, DirCacheIterator.class);
return e == null || !e.isSkipWorkTree(); return e == null || !e.isSkipWorkTree();
} }


/** {@inheritDoc} */
@Override @Override
public boolean shouldBeRecursive() { public boolean shouldBeRecursive() {
return false; return false;
} }


/** {@inheritDoc} */
@Override @Override
public TreeFilter clone() { public TreeFilter clone() {
return this; return this;
} }


/** {@inheritDoc} */
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override @Override
public String toString() { public String toString() {

+ 23
- 20
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilter.java Zobrazit soubor

* <p> * <p>
* <b>Path filters:</b> * <b>Path filters:</b>
* <ul> * <ul>
* <li>Matching pathname: {@link PathFilter}</li>
* <li>Matching pathname:
* {@link org.eclipse.jgit.treewalk.filter.PathFilter}</li>
* </ul> * </ul>
* *
* <p> * <p>
* <p> * <p>
* <b>Boolean modifiers:</b> * <b>Boolean modifiers:</b>
* <ul> * <ul>
* <li>AND: {@link AndTreeFilter}</li>
* <li>OR: {@link OrTreeFilter}</li>
* <li>NOT: {@link NotTreeFilter}</li>
* <li>AND: {@link org.eclipse.jgit.treewalk.filter.AndTreeFilter}</li>
* <li>OR: {@link org.eclipse.jgit.treewalk.filter.OrTreeFilter}</li>
* <li>NOT: {@link org.eclipse.jgit.treewalk.filter.NotTreeFilter}</li>
* </ul> * </ul>
*/ */
public abstract class TreeFilter { public abstract class TreeFilter {
* Determine if the current entry is interesting to report. * Determine if the current entry is interesting to report.
* <p> * <p>
* This method is consulted for subtree entries even if * This method is consulted for subtree entries even if
* {@link TreeWalk#isRecursive()} is enabled. The consultation allows the
* filter to bypass subtree recursion on a case-by-case basis, even when
* recursion is enabled at the application level.
* {@link org.eclipse.jgit.treewalk.TreeWalk#isRecursive()} is enabled. The
* consultation allows the filter to bypass subtree recursion on a
* case-by-case basis, even when recursion is enabled at the application
* level.
* *
* @param walker * @param walker
* the walker the filter needs to examine. * the walker the filter needs to examine.
* @return true if the current entry should be seen by the application; * @return true if the current entry should be seen by the application;
* false to hide the entry. * false to hide the entry.
* @throws MissingObjectException
* @throws org.eclipse.jgit.errors.MissingObjectException
* an object the filter needs to consult to determine its answer * an object the filter needs to consult to determine its answer
* does not exist in the Git repository the walker is operating * does not exist in the Git repository the walker is operating
* on. Filtering this current walker entry is impossible without * on. Filtering this current walker entry is impossible without
* the object. * the object.
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* an object the filter needed to consult was not of the * an object the filter needed to consult was not of the
* expected object type. This usually indicates a corrupt * expected object type. This usually indicates a corrupt
* repository, as an object link is referencing the wrong type. * repository, as an object link is referencing the wrong type.
* @throws IOException
* @throws java.io.IOException
* a loose object or pack file could not be read to obtain data * a loose object or pack file could not be read to obtain data
* necessary for the filter to make its decision. * necessary for the filter to make its decision.
*/ */
* <p> * <p>
* This method extends the result returned by {@link #include(TreeWalk)} * This method extends the result returned by {@link #include(TreeWalk)}
* with a third option (-1), splitting the value true. This gives the * with a third option (-1), splitting the value true. This gives the
* application a possibility to distinguish between an exact match
* and the case when a subtree to the current entry might be a match.
* application a possibility to distinguish between an exact match and the
* case when a subtree to the current entry might be a match.
* *
* @param walker * @param walker
* the walker the filter needs to examine. * the walker the filter needs to examine.
* @return -1 if the current entry is a parent of the filter but no
* exact match has been made; 0 if the current entry should
* be seen by the application; 1 if it should be hidden.
* @throws MissingObjectException
* @return -1 if the current entry is a parent of the filter but no exact
* match has been made; 0 if the current entry should be seen by the
* application; 1 if it should be hidden.
* @throws org.eclipse.jgit.errors.MissingObjectException
* as thrown by {@link #include(TreeWalk)} * as thrown by {@link #include(TreeWalk)}
* @throws IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* as thrown by {@link #include(TreeWalk)} * as thrown by {@link #include(TreeWalk)}
* @throws IOException
* @throws java.io.IOException
* as thrown by {@link #include(TreeWalk)} * as thrown by {@link #include(TreeWalk)}
* @since 4.7 * @since 4.7
*/ */
public abstract boolean shouldBeRecursive(); public abstract boolean shouldBeRecursive();


/** /**
* {@inheritDoc}
*
* Clone this tree filter, including its parameters. * Clone this tree filter, including its parameters.
* <p> * <p>
* This is a deep clone. If this filter embeds objects or other filters it * This is a deep clone. If this filter embeds objects or other filters it
* must also clone those, to ensure the instances do not share mutable data. * must also clone those, to ensure the instances do not share mutable data.
*
* @return another copy of this filter, suitable for another thread.
*/ */
@Override @Override
public abstract TreeFilter clone(); public abstract TreeFilter clone();


/** {@inheritDoc} */
@Override @Override
public String toString() { public String toString() {
String n = getClass().getName(); String n = getClass().getName();

+ 16
- 11
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/TreeFilterMarker.java Zobrazit soubor

import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.TreeWalk;


/** /**
* For testing an array of {@link TreeFilter} during a {@link TreeWalk} for each
* entry and returning the result as a bitmask.
* For testing an array of {@link org.eclipse.jgit.treewalk.filter.TreeFilter}
* during a {@link org.eclipse.jgit.treewalk.TreeWalk} for each entry and
* returning the result as a bitmask.
* *
* @since 2.3 * @since 2.3
*/ */
* *
* @param markTreeFilters * @param markTreeFilters
* the filters to use for marking, must not have more elements * the filters to use for marking, must not have more elements
* than {@link Integer#SIZE}.
* @throws IllegalArgumentException
* than {@link java.lang.Integer#SIZE}.
* @throws java.lang.IllegalArgumentException
* if more tree filters are passed than possible * if more tree filters are passed than possible
*/ */
public TreeFilterMarker(TreeFilter[] markTreeFilters) { public TreeFilterMarker(TreeFilter[] markTreeFilters) {


/** /**
* Test the filters against the walk. Returns a bitmask where each bit * Test the filters against the walk. Returns a bitmask where each bit
* represents the result of a call to {@link TreeFilter#include(TreeWalk)},
* represents the result of a call to
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#include(TreeWalk)},
* ordered by the index for which the tree filters were passed in the * ordered by the index for which the tree filters were passed in the
* constructor. * constructor.
* *
* @param walk * @param walk
* the walk from which to test the current entry * the walk from which to test the current entry
* @return the marks bitmask * @return the marks bitmask
* @throws MissingObjectException
* as thrown by {@link TreeFilter#include(TreeWalk)}
* @throws IncorrectObjectTypeException
* as thrown by {@link TreeFilter#include(TreeWalk)}
* @throws IOException
* as thrown by {@link TreeFilter#include(TreeWalk)}
* @throws org.eclipse.jgit.errors.MissingObjectException
* as thrown by
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#include(TreeWalk)}
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* as thrown by
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#include(TreeWalk)}
* @throws java.io.IOException
* as thrown by
* {@link org.eclipse.jgit.treewalk.filter.TreeFilter#include(TreeWalk)}
*/ */
public int getMarks(TreeWalk walk) throws MissingObjectException, public int getMarks(TreeWalk walk) throws MissingObjectException,
IncorrectObjectTypeException, IOException { IncorrectObjectTypeException, IOException {

Načítá se…
Zrušit
Uložit