Patchwork [1,of,6] byteify-strings: handle multi-line strings in _ensuresysstr

login
register
mail settings
Submitter Raphaël Gomès
Date Aug. 2, 2019, 8:22 a.m.
Message ID <623f86cf8834b154cc2b.1564734132@alphare-carbon.lan>
Download mbox | patch
Permalink /patch/41121/
State Accepted
Headers show

Comments

Raphaël Gomès - Aug. 2, 2019, 8:22 a.m.
# HG changeset patch
# User Raphaël Gomès <rgomes@octobus.net>
# Date 1564731851 -7200
#      Fri Aug 02 09:44:11 2019 +0200
# Node ID 623f86cf8834b154cc2b7c88b6dd8378ff9481c6
# Parent  4b04244f2d5fdc6221c29d6ae8074a81fe352c5e
# EXP-Topic byteify-strings
byteify-strings: handle multi-line strings in _ensuresysstr

The current implementation did not handle calls like

`repo.ui.log("first line"
             "other line")`

correctly.

Patch

diff -r 4b04244f2d5f -r 623f86cf8834 contrib/byteify-strings.py
--- a/contrib/byteify-strings.py	Fri Jul 26 10:47:06 2019 -0700
+++ b/contrib/byteify-strings.py	Fri Aug 02 09:44:11 2019 +0200
@@ -78,9 +78,19 @@ 
         already been done.
 
         """
-        st = tokens[j]
-        if st.type == token.STRING and st.string.startswith(("'", '"')):
-            sysstrtokens.add(st)
+        k = j
+        currtoken = tokens[k]
+        while currtoken.type in (token.STRING, token.NEWLINE, tokenize.NL):
+            k += 1
+            if (
+                currtoken.type == token.STRING
+                and currtoken.string.startswith(("'", '"'))
+            ):
+                sysstrtokens.add(currtoken)
+            try:
+                currtoken = tokens[k]
+            except IndexError:
+                break
 
     coldelta = 0  # column increment for new opening parens
     coloffset = -1  # column offset for the current line (-1: TBD)