Flush NewContents cache in CheckPatchFormatted

Prior to https://crrev.com/c/5740609, NewContents never flushed cache
so the second NewContents() would always produce the same contents
post-yapf as as pre-yapf. Flush cache on second NewContents() call to
get updated file contents. Also fix the formatting a bit.

Bug: b/333744051
Change-Id: Ic627dd72675d7d3694b1978635ae047b38f06596
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/357960
Auto-Submit: Gavin Mak <gavinmak@google.com>
Commit-Queue: Jeremy Leconte <jleconte@webrtc.org>
Reviewed-by: Jeremy Leconte <jleconte@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42677}
diff --git a/infra/specs/PRESUBMIT.py b/infra/specs/PRESUBMIT.py
index 0886ee6..a38bc8d 100644
--- a/infra/specs/PRESUBMIT.py
+++ b/infra/specs/PRESUBMIT.py
@@ -34,17 +34,18 @@
           output_api.PresubmitError('Error calling "' + shlex.join(cmd) + '"')
       )
 
-    new_content = f.NewContents()
+    # Make sure NewContents reads the updated files from disk and not cache.
+    new_content = f.NewContents(flush_cache=True)
     if new_content != prev_content:
       path = f.LocalPath()
-      diff = difflib.unified_diff(prev_content, new_content, path, path)
-      diffs.append(''.join(diff))
+      diff = difflib.unified_diff(prev_content, new_content, path, path, lineterm='')
+      diffs.append('\n'.join(diff))
 
   if diffs:
     combined_diffs = '\n'.join(diffs)
     msg = (
-        'Diff found after running "yapf -i" on modified .pyl files:\n'
-        f'{combined_diffs}\n'
+        'Diff found after running "yapf -i" on modified .pyl files:\n\n'
+        f'{combined_diffs}\n\n'
         'Please commit or discard the new changes.'
     )
     results.append(output_api.PresubmitError(msg))