Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revset.py @ 30804:4227f80f72b2
revset: abuse x:y syntax to specify line range of followlines()
This slightly complicates the parsing (see the previous patch), but the
overall result seems not bad.
I keep x:, :y and : for future extension.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 09 Jan 2017 17:58:19 +0900 |
parents | d389f19f14aa |
children | 41e31a6f5296 |
comparison
equal
deleted
inserted
replaced
30803:d389f19f14aa | 30804:4227f80f72b2 |
---|---|
327 return [] | 327 return [] |
328 if x[0] == 'list': | 328 if x[0] == 'list': |
329 return list(x[1:]) | 329 return list(x[1:]) |
330 return [x] | 330 return [x] |
331 | 331 |
332 def getrange(x, err): | |
333 if not x: | |
334 raise error.ParseError(err) | |
335 op = x[0] | |
336 if op == 'range': | |
337 return x[1], x[2] | |
338 elif op == 'rangepre': | |
339 return None, x[1] | |
340 elif op == 'rangepost': | |
341 return x[1], None | |
342 elif op == 'rangeall': | |
343 return None, None | |
344 raise error.ParseError(err) | |
345 | |
332 def getargs(x, min, max, err): | 346 def getargs(x, min, max, err): |
333 l = getlist(x) | 347 l = getlist(x) |
334 if len(l) < min or (max >= 0 and len(l) > max): | 348 if len(l) < min or (max >= 0 and len(l) > max): |
335 raise error.ParseError(err) | 349 raise error.ParseError(err) |
336 return l | 350 return l |
1081 # ``followfirst([pattern[, startrev]])`` | 1095 # ``followfirst([pattern[, startrev]])`` |
1082 # Like ``follow([pattern[, startrev]])`` but follows only the first parent | 1096 # Like ``follow([pattern[, startrev]])`` but follows only the first parent |
1083 # of every revisions or files revisions. | 1097 # of every revisions or files revisions. |
1084 return _follow(repo, subset, x, '_followfirst', followfirst=True) | 1098 return _follow(repo, subset, x, '_followfirst', followfirst=True) |
1085 | 1099 |
1086 @predicate('followlines(file, fromline, toline[, startrev=.])', safe=True) | 1100 @predicate('followlines(file, fromline:toline[, startrev=.])', safe=True) |
1087 def followlines(repo, subset, x): | 1101 def followlines(repo, subset, x): |
1088 """Changesets modifying `file` in line range ('fromline', 'toline'). | 1102 """Changesets modifying `file` in line range ('fromline', 'toline'). |
1089 | 1103 |
1090 Line range corresponds to 'file' content at 'startrev' and should hence be | 1104 Line range corresponds to 'file' content at 'startrev' and should hence be |
1091 consistent with file size. If startrev is not specified, working directory's | 1105 consistent with file size. If startrev is not specified, working directory's |
1092 parent is used. | 1106 parent is used. |
1093 """ | 1107 """ |
1094 from . import context # avoid circular import issues | 1108 from . import context # avoid circular import issues |
1095 | 1109 |
1096 args = getargsdict(x, 'followlines', 'file *lines startrev') | 1110 args = getargsdict(x, 'followlines', 'file *lines startrev') |
1097 if len(args['lines']) != 2: | 1111 if len(args['lines']) != 1: |
1098 raise error.ParseError(_("followlines takes at least three arguments")) | 1112 raise error.ParseError(_("followlines requires a line range")) |
1099 | 1113 |
1100 rev = '.' | 1114 rev = '.' |
1101 if 'startrev' in args: | 1115 if 'startrev' in args: |
1102 revs = getset(repo, fullreposet(repo), args['startrev']) | 1116 revs = getset(repo, fullreposet(repo), args['startrev']) |
1103 if len(revs) != 1: | 1117 if len(revs) != 1: |
1113 files = [f for f in repo[rev] if m(f)] | 1127 files = [f for f in repo[rev] if m(f)] |
1114 if len(files) != 1: | 1128 if len(files) != 1: |
1115 raise error.ParseError(_("followlines expects exactly one file")) | 1129 raise error.ParseError(_("followlines expects exactly one file")) |
1116 fname = files[0] | 1130 fname = files[0] |
1117 | 1131 |
1132 lr = getrange(args['lines'][0], _("followlines expects a line range")) | |
1118 fromline, toline = [getinteger(a, _("line range bounds must be integers")) | 1133 fromline, toline = [getinteger(a, _("line range bounds must be integers")) |
1119 for a in args['lines']] | 1134 for a in lr] |
1120 if toline - fromline < 0: | 1135 if toline - fromline < 0: |
1121 raise error.ParseError(_("line range must be positive")) | 1136 raise error.ParseError(_("line range must be positive")) |
1122 if fromline < 1: | 1137 if fromline < 1: |
1123 raise error.ParseError(_("fromline must be strictly positive")) | 1138 raise error.ParseError(_("fromline must be strictly positive")) |
1124 fromline -= 1 | 1139 fromline -= 1 |