fastest way to collect filenames in working dir

Christian Ebert blacktrash at gmx.net
Wed Oct 17 08:32:15 UTC 2007


* Christian Ebert on Tuesday, October 16, 2007 at 17:07:27 +0200
> The code I have at the moment does what I want. But
> repo.walk(node, <args>) "selects" from manifest, which is then
> thrown away; and ATM I can't wrap my head around how to steal
> repo.walk for my purposes.
> 
> My code ATM looks like this:
> 
> def myfunc(ui, repo, expand, *pats, **opts):
>    cmdutil.bail_if_changed(repo)
>    wlock = lock = None
>    try:
>        wlock = repo.wlock()
>        lock = repo.lock()
>        files, match, anypats = cmdutil.matchpats(repo, pats, opts)
>        ctx = repo.changectx()
>        node = ctx.node()
>        man = ctx.manifest()
>        files = [f for src, f
>            in repo.walk(node=node, files=files, match=match)
>            if mymatcher(f) and not man.linkf(f)]
> ...
> 
> So myfunc takes filename(pattern)s and walkopts as arguments to
> "select" from manifest.keys(), matches the remaining filenames
> against mymatcher, and discards symbolic links.

This seems to work (until someone points out the flaws):

def myfunc(ui, repo, expand, *pats, **opts):
    cmdutil.bail_if_changed(repo)
    wlock = lock = None
    try:
        wlock = repo.wlock()
        lock = repo.lock()
        files, match, anypats = cmdutil.matchpats(repo, pats, opts)
        fdict = dict.fromkeys(files)
        fdict.pop('.', None)
        ctx = repo.changectx()
        node = ctx.node()
        man = ctx.manifest()
        mfiles = man.keys()
        mfiles.sort()
        files = []
        for mf in mfiles:
            for ff in fdict:
                if ff == mf or ff.startswith('%s/' % mf):
                    files.append(ff)
                    del fdict[ff]
                    break
            if not mf in files and match(mf):
                files.append(mf)
        files = [f for f in files if mymatcher(f) and not man.linkf(f)]
...

c
-- 
keyword extension for Mercurial (http://selenic.com/mercurial):
<http://www.blacktrash.org/hg/hgkeyword/> (0.9.2 backwards compatible)
Mercurial crew development repository + keyword extension:
<http://www.blacktrash.org/hg/hg-crew-keyword/>



More information about the Mercurial-devel mailing list