Patchwork [2,of,6,py3] diff: slice over bytes to make sure conditions work normally

login
register
mail settings
Submitter Pulkit Goyal
Date March 26, 2017, 3:46 p.m.
Message ID <989c6385adcc3385ab98.1490543201@pulkit-goyal>
Download mbox | patch
Permalink /patch/19689/
State Accepted
Headers show

Comments

Pulkit Goyal - March 26, 2017, 3:46 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1490541771 -19800
#      Sun Mar 26 20:52:51 2017 +0530
# Node ID 989c6385adcc3385ab984a718e09fa5d694563c4
# Parent  2632df096fc0ac7582382b1f94ea4b9ad0bce8f2
diff: slice over bytes to make sure conditions work normally

Both of this are part of generating `hg diff` on python 3.
Yuya Nishihara - March 27, 2017, 12:25 p.m.
On Sun, 26 Mar 2017 21:16:41 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1490541771 -19800
> #      Sun Mar 26 20:52:51 2017 +0530
> # Node ID 989c6385adcc3385ab984a718e09fa5d694563c4
> # Parent  2632df096fc0ac7582382b1f94ea4b9ad0bce8f2
> diff: slice over bytes to make sure conditions work normally
> 
> Both of this are part of generating `hg diff` on python 3.
> 
> diff -r 2632df096fc0 -r 989c6385adcc mercurial/mdiff.py
> --- a/mercurial/mdiff.py	Sun Mar 26 20:49:18 2017 +0530
> +++ b/mercurial/mdiff.py	Sun Mar 26 20:52:51 2017 +0530
> @@ -227,7 +227,7 @@
>  
>      def checknonewline(lines):
>          for text in lines:
> -            if text[-1] != '\n':
> +            if text[-1:len(text)] != '\n':
>                  text += "\n\ No newline at end of file\n"
>              yield text
>  
> diff -r 2632df096fc0 -r 989c6385adcc mercurial/patch.py
> --- a/mercurial/patch.py	Sun Mar 26 20:49:18 2017 +0530
> +++ b/mercurial/patch.py	Sun Mar 26 20:52:51 2017 +0530
> @@ -737,7 +737,7 @@
>          for x in self.rej:
>              for l in x.hunk:
>                  lines.append(l)
> -                if l[-1] != '\n':
> +                if l[-1:len(l)] != '\n':

len(l) isn't needed: l[-1:]

Patch

diff -r 2632df096fc0 -r 989c6385adcc mercurial/mdiff.py
--- a/mercurial/mdiff.py	Sun Mar 26 20:49:18 2017 +0530
+++ b/mercurial/mdiff.py	Sun Mar 26 20:52:51 2017 +0530
@@ -227,7 +227,7 @@ 
 
     def checknonewline(lines):
         for text in lines:
-            if text[-1] != '\n':
+            if text[-1:len(text)] != '\n':
                 text += "\n\ No newline at end of file\n"
             yield text
 
diff -r 2632df096fc0 -r 989c6385adcc mercurial/patch.py
--- a/mercurial/patch.py	Sun Mar 26 20:49:18 2017 +0530
+++ b/mercurial/patch.py	Sun Mar 26 20:52:51 2017 +0530
@@ -737,7 +737,7 @@ 
         for x in self.rej:
             for l in x.hunk:
                 lines.append(l)
-                if l[-1] != '\n':
+                if l[-1:len(l)] != '\n':
                     lines.append("\n\ No newline at end of file\n")
         self.backend.writerej(self.fname, len(self.rej), self.hunks, lines)