comparison mercurial/revset.py @ 23765:537a2669a113

revset: use '%' as an operator for 'only' With this patch, we can make it much easier to specify 'only(A,B)' -> A%B. Similarly, 'only(A)' -> A%. On Windows, '%' is a semi-reserved symbol in the following way: using non-bash shells (e.g. cmd.exe but NOT PowerShell, ConEmu, and cmder), %var% is only expanded when 'var' exists and is surrounded by '%'. That only leaves batch scripts which could prove to be problematic. I posit that this isn't a big issue because any developer of batch scripts already knows that to use '%' one needs to escape it by using a double '%%'. Alternatives to '%' could be '=' but that might be limiting our future if we ever decide to use temporary assignments in a revset.
author Sean Farley <sean.michael.farley@gmail.com>
date Thu, 06 Nov 2014 14:55:18 -0800
parents 3a4d8a6ce432
children 678f53865c68
comparison
equal deleted inserted replaced
23764:d486e52352e8 23765:537a2669a113
114 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)), 114 ":": (15, ("rangepre", 15), ("range", 15), ("rangepost", 15)),
115 "not": (10, ("not", 10)), 115 "not": (10, ("not", 10)),
116 "!": (10, ("not", 10)), 116 "!": (10, ("not", 10)),
117 "and": (5, None, ("and", 5)), 117 "and": (5, None, ("and", 5)),
118 "&": (5, None, ("and", 5)), 118 "&": (5, None, ("and", 5)),
119 "%": (5, None, ("only", 5), ("onlypost", 5)),
119 "or": (4, None, ("or", 4)), 120 "or": (4, None, ("or", 4)),
120 "|": (4, None, ("or", 4)), 121 "|": (4, None, ("or", 4)),
121 "+": (4, None, ("or", 4)), 122 "+": (4, None, ("or", 4)),
122 ",": (2, None, ("list", 2)), 123 ",": (2, None, ("list", 2)),
123 ")": (0, None, None), 124 ")": (0, None, None),
150 yield ('..', None, pos) 151 yield ('..', None, pos)
151 pos += 1 # skip ahead 152 pos += 1 # skip ahead
152 elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully 153 elif c == '#' and program[pos:pos + 2] == '##': # look ahead carefully
153 yield ('##', None, pos) 154 yield ('##', None, pos)
154 pos += 1 # skip ahead 155 pos += 1 # skip ahead
155 elif c in "():,-|&+!~^": # handle simple operators 156 elif c in "():,-|&+!~^%": # handle simple operators
156 yield (c, None, pos) 157 yield (c, None, pos)
157 elif (c in '"\'' or c == 'r' and 158 elif (c in '"\'' or c == 'r' and
158 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings 159 program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
159 if c == 'r': 160 if c == 'r':
160 pos += 1 161 pos += 1
1920 "list": listset, 1921 "list": listset,
1921 "func": func, 1922 "func": func,
1922 "ancestor": ancestorspec, 1923 "ancestor": ancestorspec,
1923 "parent": parentspec, 1924 "parent": parentspec,
1924 "parentpost": p1, 1925 "parentpost": p1,
1926 "only": only,
1927 "onlypost": only,
1925 } 1928 }
1926 1929
1927 def optimize(x, small): 1930 def optimize(x, small):
1928 if x is None: 1931 if x is None:
1929 return 0, x 1932 return 0, x
1933 smallbonus = .5 1936 smallbonus = .5
1934 1937
1935 op = x[0] 1938 op = x[0]
1936 if op == 'minus': 1939 if op == 'minus':
1937 return optimize(('and', x[1], ('not', x[2])), small) 1940 return optimize(('and', x[1], ('not', x[2])), small)
1941 elif op == 'only':
1942 return optimize(('func', ('symbol', 'only'),
1943 ('list', x[1], x[2])), small)
1938 elif op == 'dagrangepre': 1944 elif op == 'dagrangepre':
1939 return optimize(('func', ('symbol', 'ancestors'), x[1]), small) 1945 return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
1940 elif op == 'dagrangepost': 1946 elif op == 'dagrangepost':
1941 return optimize(('func', ('symbol', 'descendants'), x[1]), small) 1947 return optimize(('func', ('symbol', 'descendants'), x[1]), small)
1942 elif op == 'rangepre': 1948 elif op == 'rangepre':