I get what this method is doing.  Its a short-cut to try and skip through a chain of commits which haven't modified the file.  But its implementation is obtuse.  I wonder if we can't just leverage RevWalk to do it for us:

  rw.markStart(origin.commit);
  rw.setTreeFilter(TreeFilter.ANY_DIFF);
  RevCommit r = rw.next();
  rw.reset();
  return r;

If that isn't fast enough to skip through the chain, we should try to fix RevWalk.