Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 820:89985a1b3427
Clean up walk and changes code to use normalised names properly.
New function: commands.pathto returns the relative path from one path
to another. For example, given foo/bar and baz/quux, it will return
../../baz/quux. This new function is used by the walk and status code
to print relative paths correctly.
New command: debugwalk exercises the walk code without doing anything
more.
hg.dirstate.walk now yields normalised names. For example, if you're
in the baz directory and you ask it to walk ../foo/bar/.., it will yield
names starting with foo/.
As a result of this change, all of the other walk and changes methods
in this module also return normalised names.
The util.matcher function now normalises globs and path names, so that
it will match normalised names properly.
Finally, util.matcher uses the non-glob prefix of a glob to tell walk
which directories to scan. Perviously, a glob like foo/* would scan
everything, but only return matches for foo/*. Now, foo/* only scans
under foo (using the globprefix function), which is much faster.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun, 31 Jul 2005 17:42:46 -0800 |
parents | 0902ffece4b4 |
children | 72d9bd4841f3 |
comparison
equal
deleted
inserted
replaced
819:77e121a0d870 | 820:89985a1b3427 |
---|---|
444 for f in util.unique(files): | 444 for f in util.unique(files): |
445 f = os.path.join(self.root, f) | 445 f = os.path.join(self.root, f) |
446 if os.path.isdir(f): | 446 if os.path.isdir(f): |
447 for dir, subdirs, fl in os.walk(f): | 447 for dir, subdirs, fl in os.walk(f): |
448 d = dir[len(self.root) + 1:] | 448 d = dir[len(self.root) + 1:] |
449 if d == '.hg': | 449 nd = os.path.normpath(d) |
450 if nd == '.hg': | |
450 subdirs[:] = [] | 451 subdirs[:] = [] |
451 continue | 452 continue |
452 for sd in subdirs: | 453 for sd in subdirs: |
453 ds = os.path.join(d, sd +'/') | 454 ds = os.path.join(nd, sd +'/') |
454 if self.ignore(ds) or not match(ds): | 455 if self.ignore(ds) or not match(ds): |
455 subdirs.remove(sd) | 456 subdirs.remove(sd) |
456 for fn in fl: | 457 for fn in fl: |
457 fn = util.pconvert(os.path.join(d, fn)) | 458 fn = util.pconvert(os.path.join(d, fn)) |
458 yield 'f', fn | 459 yield 'f', fn |
464 | 465 |
465 # yield only files that match: all in dirstate, others only if | 466 # yield only files that match: all in dirstate, others only if |
466 # not in .hgignore | 467 # not in .hgignore |
467 | 468 |
468 for src, fn in util.unique(traverse()): | 469 for src, fn in util.unique(traverse()): |
470 fn = os.path.normpath(fn) | |
469 if fn in dc: | 471 if fn in dc: |
470 del dc[fn] | 472 del dc[fn] |
471 elif self.ignore(fn): | 473 elif self.ignore(fn): |
472 continue | 474 continue |
473 if match(fn): | 475 if match(fn): |
866 return 1 | 868 return 1 |
867 | 869 |
868 def walk(self, node = None, files = [], match = util.always): | 870 def walk(self, node = None, files = [], match = util.always): |
869 if node: | 871 if node: |
870 for fn in self.manifest.read(self.changelog.read(node)[0]): | 872 for fn in self.manifest.read(self.changelog.read(node)[0]): |
871 yield 'm', fn | 873 if match(fn): yield 'm', fn |
872 else: | 874 else: |
873 for src, fn in self.dirstate.walk(files, match): | 875 for src, fn in self.dirstate.walk(files, match): |
874 yield src, fn | 876 yield src, fn |
875 | 877 |
876 def changes(self, node1 = None, node2 = None, files = [], | 878 def changes(self, node1 = None, node2 = None, files = [], |