import java.util.Collections;
import java.util.Comparator;
+import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.ignore.IgnoreNode;
import org.eclipse.jgit.ignore.IgnoreRule;
import org.eclipse.jgit.submodule.SubmoduleWalk;
import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO;
+import org.eclipse.jgit.util.RawParseUtils;
import org.eclipse.jgit.util.io.EolCanonicalizingInputStream;
/**
* @deprecated Use {@link #isModified(DirCacheEntry, boolean, ObjectReader)}
*/
public boolean isModified(DirCacheEntry entry, boolean forceContentCheck) {
- return isModified(entry, forceContentCheck, null);
+ try {
+ return isModified(entry, forceContentCheck, null);
+ } catch (IOException e) {
+ throw new JGitInternalException(e.getMessage(), e);
+ }
}
/**
* @param reader
* access to repository objects if necessary. Should not be null.
* @return true if content is most likely different.
+ * @throws IOException
* @since 3.3
*/
public boolean isModified(DirCacheEntry entry, boolean forceContentCheck,
- ObjectReader reader) {
+ ObjectReader reader) throws IOException {
MetadataDiff diff = compareMetadata(entry);
switch (diff) {
case DIFFER_BY_TIMESTAMP:
case EQUAL:
return false;
case DIFFER_BY_METADATA:
+ if (mode == FileMode.SYMLINK.getBits())
+ return contentCheck(entry, reader);
return true;
default:
throw new IllegalStateException(MessageFormat.format(
* acccess to repository data if necessary
* @return <code>true</code> if the content doesn't match,
* <code>false</code> if it matches
+ * @throws IOException
*/
- private boolean contentCheck(DirCacheEntry entry, ObjectReader reader) {
+ private boolean contentCheck(DirCacheEntry entry, ObjectReader reader)
+ throws IOException {
if (getEntryObjectId().equals(entry.getObjectId())) {
// Content has not changed
return false;
} else {
+ if (mode == FileMode.SYMLINK.getBits())
+ return !new File(readContentAsString(current()))
+ .equals(new File(readContentAsString(entry)));
// Content differs: that's a real change, perhaps
if (reader == null) // deprecated use, do no further checks
return true;
}
}
+ private String readContentAsString(DirCacheEntry entry)
+ throws MissingObjectException, IOException {
+ ObjectLoader open = repository.open(entry.getObjectId());
+ byte[] cachedBytes = open.getCachedBytes();
+ return RawParseUtils.decode(cachedBytes);
+ }
+
+ private static String readContentAsString(Entry entry) throws IOException {
+ long length = entry.getLength();
+ byte[] content = new byte[(int) length];
+ InputStream is = entry.openInputStream();
+ IO.readFully(is, content, 0, (int) length);
+ return RawParseUtils.decode(content);
+ }
+
private long computeLength(InputStream in) throws IOException {
// Since we only care about the length, use skip. The stream
// may be able to more efficiently wade through its data.