Details
Details
- Reviewers
indygreg - Group Reviewers
hg-reviewers - Commits
- rHG9c55bbc29dcf: narrowspec: document constraints when validating patterns
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
| indygreg |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | hgext/narrow/narrowspec.py (6 lines) |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 | ||
| Closed | durin42 |
| def _numlines(s): | def _numlines(s): | ||||
| """Returns the number of lines in s, including ending empty lines.""" | """Returns the number of lines in s, including ending empty lines.""" | ||||
| # We use splitlines because it is Unicode-friendly and thus Python 3 | # We use splitlines because it is Unicode-friendly and thus Python 3 | ||||
| # compatible. However, it does not count empty lines at the end, so trick | # compatible. However, it does not count empty lines at the end, so trick | ||||
| # it by adding a character at the end. | # it by adding a character at the end. | ||||
| return len((s + 'x').splitlines()) | return len((s + 'x').splitlines()) | ||||
| def _validatepattern(pat): | def _validatepattern(pat): | ||||
| """Validates the pattern and aborts if it is invalid.""" | """Validates the pattern and aborts if it is invalid. | ||||
| Patterns are stored in the narrowspec as newline-separated | |||||
| POSIX-style bytestring paths. There's no escaping. | |||||
| """ | |||||
| # We use newlines as separators in the narrowspec file, so don't allow them | # We use newlines as separators in the narrowspec file, so don't allow them | ||||
| # in patterns. | # in patterns. | ||||
| if _numlines(pat) > 1: | if _numlines(pat) > 1: | ||||
| raise error.Abort('newlines are not allowed in narrowspec paths') | raise error.Abort('newlines are not allowed in narrowspec paths') | ||||
| components = pat.split('/') | components = pat.split('/') | ||||
| if '.' in components or '..' in components: | if '.' in components or '..' in components: | ||||