py3: use bytestr wrapper in revsetlang.tokenize()
authorYuya Nishihara <yuya@tcha.org>
Thu, 16 Mar 2017 21:36:21 +0900
changeset 31441 80c8a6db450d
parent 31440 f784ba187089
child 31442 d3a56bb268ee
py3: use bytestr wrapper in revsetlang.tokenize() This backs out 77270ec0cdd9 and wraps program by bytestr() instead.
mercurial/revsetlang.py
--- a/mercurial/revsetlang.py	Thu Mar 16 21:33:25 2017 +0900
+++ b/mercurial/revsetlang.py	Thu Mar 16 21:36:21 2017 +0900
@@ -78,6 +78,7 @@
     [('symbol', '@', 0), ('::', None, 1), ('end', None, 3)]
 
     '''
+    program = pycompat.bytestr(program)
     if syminitletters is None:
         syminitletters = _syminitletters
     if symletters is None:
@@ -100,7 +101,7 @@
 
     pos, l = 0, len(program)
     while pos < l:
-        c = program[pos:pos + 1]
+        c = program[pos]
         if c.isspace(): # skip inter-token whitespace
             pass
         elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
@@ -118,14 +119,14 @@
               program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
             if c == 'r':
                 pos += 1
-                c = program[pos:pos + 1]
+                c = program[pos]
                 decode = lambda x: x
             else:
                 decode = parser.unescapestr
             pos += 1
             s = pos
             while pos < l: # find closing quote
-                d = program[pos:pos + 1]
+                d = program[pos]
                 if d == '\\': # skip over escaped characters
                     pos += 2
                     continue
@@ -140,11 +141,10 @@
             s = pos
             pos += 1
             while pos < l: # find end of symbol
-                d = program[pos:pos + 1]
+                d = program[pos]
                 if d not in symletters:
                     break
-                if (d == '.'
-                    and program[pos - 1:pos] == '.'): # special case for ..
+                if d == '.' and program[pos - 1] == '.': # special case for ..
                     pos -= 1
                     break
                 pos += 1