Commit Graph

76 Commits

Author SHA1 Message Date
Siddharth Agarwal
712df54e55 match: use util.re.escape instead of re.escape
For a pathological .hgignore with over 2500 glob lines and over 200000 calls to
re.escape, and with re2 available, this speeds up parsing the .hgignore from
0.75 seconds to 0.20 seconds. This causes e.g. 'hg status' with hgwatchman
enabled to go from 1.02 seconds to 0.47 seconds.
2014-07-15 15:34:50 -07:00
Siddharth Agarwal
5e38818cf4 match: use util.re.compile instead of util.compilere 2014-07-15 14:49:45 -07:00
Siddharth Agarwal
1aa951751f match: make glob '**/' match the empty string
Previously, a glob pattern of the form 'foo/**/bar' would match 'foo/a/bar' but
not 'foo/bar'. That was because the '**' in 'foo/**/bar' would be translated to
'.*', making the final regex pattern 'foo/.*/bar'. That pattern doesn't match
the string 'foo/bar'.

This is a bug because the '**/' glob matches the empty string in standard Unix
shells like bash and zsh.

Fix that by making the ending '/' optional if an empty string can be matched.
2014-06-25 14:50:48 -07:00
Yuya Nishihara
2e030eb020 match: fix NameError 'pat' on overflow of regex pattern length
'pat' was renamed to 'regex' in 25907f42ff54.
2014-04-29 11:02:40 +09:00
Mads Kiilerich
3bb35d5e35 match: remove last traces of unused .missing callback 2013-10-03 18:01:21 +02:00
Mads Kiilerich
3811c637be match: _globre doctests 2014-04-13 22:00:08 +02:00
Mads Kiilerich
df98b5168a match: improve documentation - docstrings and more descriptive variable naming
No real changes.

pattern: 'kind:pat' as specified on the command line
patterns, pats: list of patterns
kind: 'path', 'glob' or 're' or ...
pat: string in the corresponding 'kind' format
kindpats: list of (kind, pat) tuples
2013-10-03 18:01:21 +02:00
Mads Kiilerich
f171464010 match: make it more clear what _roots do and that it ends up in match()._files 2013-10-03 18:01:21 +02:00
Augie Fackler
edc98c0164 match: use ctx.getfileset() instead of fileset.getfileset()
Resolves an import cycle involving match and merge.
2014-02-04 14:54:42 -05:00
Augie Fackler
213fff305a pathutil: tease out a new library to break an import cycle from canonpath use 2013-11-06 18:19:04 -05:00
Mads Kiilerich
1e900bb145 check-code: check for spaces around = for named parameters 2013-10-03 14:50:47 +02:00
Siddharth Agarwal
be89af772f match: add comments to explain explicitdir and traversedir 2013-05-03 15:36:18 -07:00
Siddharth Agarwal
8e7066e5f2 match: make explicitdir and traversedir None by default
With this, extensions can easily tell when traversedir and/or explicitdir don't
need to be called.
2013-05-03 14:41:58 -07:00
Siddharth Agarwal
ded9770198 match: drop dir callback
dir has been subsumed by explicitdir and traversedir.
2013-04-28 21:29:32 -07:00
Siddharth Agarwal
3c72b73e1f match: introduce explicitdir and traversedir
match.dir is currently called in two different places:
(1) noting when a directory specified explicitly is visited.
(2) noting when a directory is visited during a recursive walk.

purge cares about both, but commit only cares about the first.

Upcoming patches will split the two cases into two different callbacks. Why
bother? Consider a hypothetical extension that can provide more efficient walk
results, via e.g. watching the filesystem. That extension will need to
fall back to a full recursive walk if a callback is set for (2), but not if a
callback is only set for (1).
2013-04-28 21:24:09 -07:00
Mads Kiilerich
2fc7d0133f match: fix root calculation for combining regexps with simple paths
The fall-back root for walking is the repo root, not no root.

The "roots" do however also end up in m.files() which is used in various ways,
for instance to indicate whether matches are exact. The change could thus have
other impacts.
2013-04-30 01:04:35 +02:00
Bryan O'Sullivan
905d64bf45 match: more accurately report when we're always going to match
This improves the performance of log --patch and --stat by about
20% for moderately large manifests (e.g. mozilla-central) for the
common case of no -I/-X patterns.
2013-02-21 12:55:39 -08:00
Mads Kiilerich
2372d51b68 fix wording and not-completely-trivial spelling errors and bad docstrings 2012-08-15 22:39:18 +02:00
Bryan O'Sullivan
3f45806d34 matcher: use re2 bindings if available
There are two sets of Python re2 bindings available on the internet;
this code works with both.

Using re2 can greatly improve "hg status" performance when a .hgignore
file becomes even modestly complex.

Example: "hg status" on a clean tree with 134K files, where "hg
debugignore" reports a regexp 4256 bytes in size.

  no .hgignore: 1.76 sec
  Python re:    2.79
  re2:          1.82

The overhead of regexp matching drops from 1.03 seconds with stock
re to 0.06 with re2.

(For comparison, a git repo with the same contents and .gitignore
file runs "git status -s" in 1.71 seconds, i.e. only slightly faster
than hg with re2.)
2012-06-01 15:26:20 -07:00
Matt Mackall
bfe92722a0 merge with stable 2012-05-30 14:21:58 -05:00
FUJIWARA Katsunori
abfb6c35d4 match: make 'match.files()' return list object always
'exact' match objects are sometimes created with a non-list 'pattern'
argument:

  - using 'set' in queue.refresh():hgext/mq.py
        match = scmutil.matchfiles(repo, set(c[0] + c[1] + c[2] + inclsubs))

  - using 'dict' in revert():mercurial/cmdutil.py (names = {})
        m = scmutil.matchfiles(repo, names)

'exact' match objects return specified 'pattern' to callers of
'match.files()' as it is, so it is a non-list object.

but almost all implementations expect 'match.files()' to return a list
object, so this may causes problems: e.g. exception for "+" with
another list object.

this patch ensures that '_files' of 'exact' match objects is a list
object.

for non 'exact' match objects, parsing specified 'pattern' already
ensures that it it a list one.
2012-05-23 00:25:29 +09:00
Brodie Rao
92158e04de cleanup: "raise SomeException()" -> "raise SomeException" 2012-05-12 16:00:58 +02:00
Jesse Glick
17675847fa localrepo: optimize internode status calls using match.always
Introduce match.always() to check if a match object always says yes, i.e.
None was passed in. If so, mfmatches should not bother iterating every file in
the repository.
2012-05-04 15:54:55 -04:00
Patrick Mezard
8d52be3d10 match: consider filesets as "anypats"
Matt suggested this on IRC, I do not think the choice is obvious, but this one
makes things simpler because while filesets are turned into a list of files
into the match objects, it would more be difficult to tell invalid files passed
in pats from those expanded from filesets.
2012-02-26 17:10:55 +01:00
Martin Geisler
543f0688d9 match: remove unused assignment
The field is assigned again below with the constructor argument.
2011-08-09 11:05:13 +02:00
Peter Arrenbrecht
aa36fb062f match: fix bug caused by refactoring in fb457d08da0b 2011-06-23 14:40:57 +02:00
Matt Mackall
1dc7f878ce match: introduce basic fileset support 2011-06-18 16:53:44 -05:00
Matt Mackall
b662345d91 match: allow passing a context object to match core 2011-06-18 16:52:51 -05:00
Patrick Mezard
37e2e503d6 match: make 'listfile:' split on LF and CRLF
We want util.readfile() to operate in binary mode, so EOLs have to be handled
correctly depending on the platform. It seems both easier and more convenient
to treat LF and CRLF the same way on all platforms.
2011-05-07 21:12:30 +02:00
Dan Villiom Podlaski Christiansen
511c941422 prevent transient leaks of file handle by using new helper functions
These leaks may occur in environments that don't employ a reference
counting GC, i.e. PyPy.

This implies:
 - changing opener(...).read() calls to opener.read(...)
 - changing opener(...).write() calls to opener.write(...)
 - changing open(...).read(...) to util.readfile(...)
 - changing open(...).write(...) to util.writefile(...)
2011-05-02 10:11:18 +02:00
Adrian Buehlmann
f3e8eae526 move canonpath from util to scmutil 2011-04-20 21:41:41 +02:00
Steve Borho
909958e650 match: fix subtle error in _buildmatch
The trailing comma was causing a ValueError.  See
https://bitbucket.org/tortoisehg/thg/issue/132
2011-02-18 10:28:20 -06:00
jfh
76026ecba1 add debugignore which yields the combined ignore patten of the .hgignore files
For GUI clients its sometimes important to know which files will be ignored and
which files will be important. This allows the GUI client to skipping redoing a
'hg status' when the files are ignored but have changed. (For instance, a
typical case is that the "build" directory inside some project is ignored but
files in it frequently change.)
2011-01-15 16:02:03 +01:00
Steve Borho
5d527f9378 match: support reading pattern lists from files 2010-12-23 15:12:24 -06:00
Martin Geisler
ca9cbd61a1 narrowmatcher: propagate bad method
The full path is propagated to the original match object since this is
often used directly for printing an error to the user.
2010-09-13 13:09:09 +02:00
Martin Geisler
3dafdd42e0 narrowmatcher: fix broken rel method 2010-09-13 13:08:18 +02:00
Martin Geisler
e0e3bf4835 match: add narrowmatcher class
This class can be used to adapt an existing match object to a new
match object that only cares about paths within a certain
subdirectory.
2010-09-03 12:58:51 +02:00
Martin Geisler
34c8204207 match: accept auditor argument
This is used when normalizing filenames and patterns.
2010-09-03 12:58:51 +02:00
Martin Geisler
b9c719086c match: mark error messages for translation 2010-08-30 17:11:51 +02:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Alejandro Santos
ebe339890f split local and stdlib module imports (eases migration issues) 2009-07-05 11:06:09 +02:00
timeless
fb33de67af Generally replace "file name" with "filename" in help and comments. 2009-06-09 09:25:17 -04:00
Matt Mackall
e802acf0e9 match: remove match.never
Only one user, can be translated to match.exact()
2009-05-31 17:54:18 -05:00
Matt Mackall
37eaadf540 match: ignore return of match.bad
All users returned false, return can now be dropped
2009-05-31 17:54:18 -05:00
Matt Mackall
2940d96bce match: document bad callback semantics 2009-05-31 17:54:18 -05:00
Matt Mackall
bd7c2104ff match: fix _patsplit breakage with drive letters 2009-05-24 16:37:34 -05:00
Matt Mackall
f1416e098e match: fold match into _match base class 2009-05-24 02:56:22 -05:00
Matt Mackall
50be99f7cb match: add exact flag to match() to unify all match forms 2009-05-24 02:56:20 -05:00
Matt Mackall
e8c6616c42 match: redefine always and never in terms of match and exact 2009-05-24 02:56:14 -05:00