]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix --diff output when encountering EOF (#1328)
authorRémi Verschelde <rverschelde@gmail.com>
Sun, 5 Apr 2020 05:02:57 +0000 (07:02 +0200)
committerGitHub <noreply@github.com>
Sun, 5 Apr 2020 05:02:57 +0000 (22:02 -0700)
`split("\n")` includes a final empty element `""` if the final line
ends with `\n` (as it should for POSIX-compliant text files), which
then became an extra `"\n"`.

`splitlines()` solves that, but there's a caveat, as it will split
on other types of line breaks too (like `\r`), which may not be
desired.

Fixes #526.

black.py
tests/data/blackd_diff.diff
tests/data/expression.diff

index 31859d1a499411d60d027e4b71feb208def8a7e9..c9c20dfd5e79812eca59b3f03227c20df1583024 100644 (file)
--- a/black.py
+++ b/black.py
@@ -3876,8 +3876,8 @@ def diff(a: str, b: str, a_name: str, b_name: str) -> str:
     """Return a unified diff string between strings `a` and `b`."""
     import difflib
 
-    a_lines = [line + "\n" for line in a.split("\n")]
-    b_lines = [line + "\n" for line in b.split("\n")]
+    a_lines = [line + "\n" for line in a.splitlines()]
+    b_lines = [line + "\n" for line in b.splitlines()]
     return "".join(
         difflib.unified_diff(a_lines, b_lines, fromfile=a_name, tofile=b_name, n=5)
     )
index c1aa52e6a1be7e36b53340145439dcb0cff18e7c..6226858a157b4dba40a478c42e890dd2a9a53dcd 100644 (file)
@@ -1,6 +1,6 @@
 --- [Deterministic header]
 +++ [Deterministic header]
-@@ -1,7 +1,6 @@
+@@ -1,6 +1,5 @@
 -def abc ():
 -    return ["hello", "world",
 -            "!"]
@@ -9,6 +9,5 @@
  
 -print(   "Incorrect formatting"    
 -)
++
 +print("Incorrect formatting")
-+
\ No newline at end of file
index 629e1012f87fda20c44a82c1d58c0e2ed3c86192..8c9e8a7005dc5f94743b8e26b4c65fdd7291b6ed 100644 (file)
  slice[0:1:2]
  slice[:]
  slice[:-1]
-@@ -134,113 +169,171 @@
+@@ -134,112 +169,170 @@
  numpy[-(c + 1) :, d]
  numpy[:, l[-2]]
  numpy[:, ::-1]
      return True
  last_call()
  # standalone comment at ENDMARKER