Mercurial > hg
changeset 36100:8fd0a9e2d7e9
narrow: make restrictpatterns a little more idiomatic
I'm not sure why invalid_includes was an out-param, but it doesn't
look like there's any reason for it to be now.
Differential Revision: https://phab.mercurial-scm.org/D2192
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 12 Feb 2018 14:42:47 -0500 |
parents | b8bbe589fd47 |
children | 22ed16caa596 |
files | hgext/narrow/narrowbundle2.py hgext/narrow/narrowcommands.py hgext/narrow/narrowspec.py |
diffstat | 3 files changed, 15 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/narrow/narrowbundle2.py Mon Feb 12 14:37:10 2018 -0500 +++ b/hgext/narrow/narrowbundle2.py Mon Feb 12 14:42:47 2018 -0500 @@ -346,10 +346,8 @@ req_includes = set(kwargs.get('includepats', [])) req_excludes = set(kwargs.get('excludepats', [])) - invalid_includes = [] - req_includes, req_excludes = narrowspec.restrictpatterns( - req_includes, req_excludes, - user_includes, user_excludes, invalid_includes) + req_includes, req_excludes, invalid_includes = narrowspec.restrictpatterns( + req_includes, req_excludes, user_includes, user_excludes) if invalid_includes: raise error.Abort(
--- a/hgext/narrow/narrowcommands.py Mon Feb 12 14:37:10 2018 -0500 +++ b/hgext/narrow/narrowcommands.py Mon Feb 12 14:42:47 2018 -0500 @@ -134,7 +134,7 @@ repo_includes, repo_excludes = repo.narrowpats includes = set(opts.get('include', [])) excludes = set(opts.get('exclude', [])) - includes, excludes = narrowspec.restrictpatterns( + includes, excludes, unused_invalid = narrowspec.restrictpatterns( includes, excludes, repo_includes, repo_excludes) if includes: opts['include'] = includes
--- a/hgext/narrow/narrowspec.py Mon Feb 12 14:37:10 2018 -0500 +++ b/hgext/narrow/narrowspec.py Mon Feb 12 14:42:47 2018 -0500 @@ -153,8 +153,7 @@ repo = share._getsrcrepo(repo) repo.vfs.write(FILENAME, spec) -def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes, - invalid_includes=None): +def restrictpatterns(req_includes, req_excludes, repo_includes, repo_excludes): r""" Restricts the patterns according to repo settings, results in a logical AND operation @@ -162,26 +161,26 @@ :param req_excludes: requested excludes :param repo_includes: repo includes :param repo_excludes: repo excludes - :param invalid_includes: an array to collect invalid includes - :return: include and exclude patterns + :return: include patterns, exclude patterns, and invalid include patterns. >>> restrictpatterns({'f1','f2'}, {}, ['f1'], []) - (set(['f1']), {}) + (set(['f1']), {}, []) >>> restrictpatterns({'f1'}, {}, ['f1','f2'], []) - (set(['f1']), {}) + (set(['f1']), {}, []) >>> restrictpatterns({'f1/fc1', 'f3/fc3'}, {}, ['f1','f2'], []) - (set(['f1/fc1']), {}) + (set(['f1/fc1']), {}, []) >>> restrictpatterns({'f1_fc1'}, {}, ['f1','f2'], []) - ([], set(['path:.'])) + ([], set(['path:.']), []) >>> restrictpatterns({'f1/../f2/fc2'}, {}, ['f1','f2'], []) - (set(['f2/fc2']), {}) + (set(['f2/fc2']), {}, []) >>> restrictpatterns({'f1/../f3/fc3'}, {}, ['f1','f2'], []) - ([], set(['path:.'])) + ([], set(['path:.']), []) >>> restrictpatterns({'f1/$non_exitent_var'}, {}, ['f1','f2'], []) - (set(['f1/$non_exitent_var']), {}) + (set(['f1/$non_exitent_var']), {}, []) """ res_excludes = set(req_excludes) res_excludes.update(repo_excludes) + invalid_includes = [] if not req_includes: res_includes = set(repo_includes) elif 'path:.' not in repo_includes: @@ -197,7 +196,7 @@ valid = True res_includes.append(req_include) break - if not valid and invalid_includes is not None: + if not valid: invalid_includes.append(req_include) if len(res_includes) == 0: res_excludes = {'path:.'} @@ -205,4 +204,4 @@ res_includes = set(res_includes) else: res_includes = set(req_includes) - return res_includes, res_excludes + return res_includes, res_excludes, invalid_includes