Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 30754:26209cb7184e
revset: parse variable-length arguments of followlines() by getargsdict()
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 09 Jan 2017 16:02:56 +0900 |
parents | c3a3896a9fa8 |
children | b1012cb1bec3 |
comparison
equal
deleted
inserted
replaced
30753:c3a3896a9fa8 | 30754:26209cb7184e |
---|---|
1076 consistent with file size. If rev is not specified, working directory's | 1076 consistent with file size. If rev is not specified, working directory's |
1077 parent is used. | 1077 parent is used. |
1078 """ | 1078 """ |
1079 from . import context # avoid circular import issues | 1079 from . import context # avoid circular import issues |
1080 | 1080 |
1081 args = getargs(x, 3, 4, _("followlines takes at least three arguments")) | 1081 args = getargsdict(x, 'followlines', 'file *lines rev') |
1082 if len(args['lines']) != 2: | |
1083 raise error.ParseError(_("followlines takes at least three arguments")) | |
1082 | 1084 |
1083 rev = '.' | 1085 rev = '.' |
1084 if len(args) == 4: | 1086 if 'rev' in args: |
1085 revarg = getargsdict(args[3], 'followlines', 'rev') | 1087 revs = getset(repo, fullreposet(repo), args['rev']) |
1086 if 'rev' in revarg: | 1088 if len(revs) != 1: |
1087 revs = getset(repo, fullreposet(repo), revarg['rev']) | 1089 raise error.ParseError( |
1088 if len(revs) != 1: | 1090 _("followlines expects exactly one revision")) |
1089 raise error.ParseError( | 1091 rev = revs.last() |
1090 _("followlines expects exactly one revision")) | 1092 |
1091 rev = revs.last() | 1093 pat = getstring(args['file'], _("followlines requires a pattern")) |
1092 | |
1093 pat = getstring(args[0], _("followlines requires a pattern")) | |
1094 if not matchmod.patkind(pat): | 1094 if not matchmod.patkind(pat): |
1095 fname = pathutil.canonpath(repo.root, repo.getcwd(), pat) | 1095 fname = pathutil.canonpath(repo.root, repo.getcwd(), pat) |
1096 else: | 1096 else: |
1097 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev]) | 1097 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=repo[rev]) |
1098 files = [f for f in repo[rev] if m(f)] | 1098 files = [f for f in repo[rev] if m(f)] |
1099 if len(files) != 1: | 1099 if len(files) != 1: |
1100 raise error.ParseError(_("followlines expects exactly one file")) | 1100 raise error.ParseError(_("followlines expects exactly one file")) |
1101 fname = files[0] | 1101 fname = files[0] |
1102 | 1102 |
1103 try: | 1103 try: |
1104 fromline, toline = [int(getsymbol(a)) for a in args[1:3]] | 1104 fromline, toline = [int(getsymbol(a)) for a in args['lines']] |
1105 except ValueError: | 1105 except ValueError: |
1106 raise error.ParseError(_("line range bounds must be integers")) | 1106 raise error.ParseError(_("line range bounds must be integers")) |
1107 if toline - fromline < 0: | 1107 if toline - fromline < 0: |
1108 raise error.ParseError(_("line range must be positive")) | 1108 raise error.ParseError(_("line range must be positive")) |
1109 if fromline < 1: | 1109 if fromline < 1: |