Ignore symlinks in _get_affected_files

_get_affected_files has historically returned symlinks but ignored directories,
in keeping with git's design. However, symlinks to directories are returned. If
you then pass a symlink to a function like _get_file_diff or _get_file_content,
it will in some cases return the set of changes in that commit under the
referenced directory. The result is that these functions treat the symlink as
an ordinary file whose contents is mangled git diff output, and will generally
report nonsense errors, e.g. that there's trailing whitespace on some
line for a directory.

As none of the existing checks (such as _check_no_long_lines) are sensible
for symlinks, the fix is to ignore changes to symlinks. This is accomplished
by switching from  a --name-status diff to a raw diff, and parsing the mode
bits (so we look at git's data, not the working tree). There is also a new
unit test.

TEST=pre-upload_unittest.py, plus manual verification of a commit that
     both changes a directory and introduces a symlink to that directory

Change-Id: If252c68d34706dc7d11e0e188148619abc0f66c8
Reviewed-on: https://chromium-review.googlesource.com/203648
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Peter Ammon <pca@chromium.org>
Tested-by: Peter Ammon <pca@chromium.org>
2 files changed