Fix NPE when WorkingTreeIterator does not have a repository set

It's strange that we have that member since it is not so clear
when it it set or not.

Change-Id: I53903a264f46866d249901a3cd9f9295028aa6bd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Robin Rosenberg 2014-02-28 07:15:08 +01:00 committed by Matthias Sohn
parent 2670fd427c
commit 7b01a53692
2 changed files with 9 additions and 6 deletions

View File

@ -114,7 +114,8 @@ public void apply(DirCacheEntry ent) {
assertEquals("link", dci.getEntryPathString());
// test
assertFalse(fti.isModified(dci.getDirCacheEntry(), true));
assertFalse(fti.isModified(dci.getDirCacheEntry(), true,
db.newObjectReader()));
}
/**
@ -195,6 +196,7 @@ public void apply(DirCacheEntry ent) {
assertEquals("link", dci.getEntryPathString());
// test
assertTrue(fti.isModified(dci.getDirCacheEntry(), true));
assertTrue(fti.isModified(dci.getDirCacheEntry(), true,
db.newObjectReader()));
}
}

View File

@ -922,7 +922,8 @@ private boolean contentCheck(DirCacheEntry entry, ObjectReader reader)
} else {
if (mode == FileMode.SYMLINK.getBits())
return !new File(readContentAsNormalizedString(current()))
.equals(new File((readContentAsNormalizedString(entry))));
.equals(new File((readContentAsNormalizedString(entry,
reader))));
// Content differs: that's a real change, perhaps
if (reader == null) // deprecated use, do no further checks
return true;
@ -971,9 +972,9 @@ private boolean contentCheck(DirCacheEntry entry, ObjectReader reader)
}
}
private String readContentAsNormalizedString(DirCacheEntry entry)
throws MissingObjectException, IOException {
ObjectLoader open = repository.open(entry.getObjectId());
private static String readContentAsNormalizedString(DirCacheEntry entry,
ObjectReader reader) throws MissingObjectException, IOException {
ObjectLoader open = reader.open(entry.getObjectId());
byte[] cachedBytes = open.getCachedBytes();
return FS.detect().normalize(RawParseUtils.decode(cachedBytes));
}