IMHO, the length and lastModified should be captured *before* you write the object out to the object database.  That way if a change occurs to the file while we are saving it to the database, the index entry will appear dirty again, which it should be.

Also, the length, lastModified and FileMode should be available off the FileTreeIterator if the file exists.  Which means you can actually kill that getRawMode(1) test I suggested above, and rely on the cached stat information that was pulled up during the TreeWalk's traversal:

  FileTreeIterator f = tw.getTree(1, FileTreeIterator.class);
  if (f != null) { // the file exists
    entry.setLength(f.getEntryLength());
    entry.setLastModified(f.getEntryLastModified());
    entry.setFileMode(f.getEntryFileMode());
    entry.setObjectId(ow.writeBlob(file));