fastest way to collect filenames in working dir
Christian Ebert
blacktrash at gmx.net
Tue Oct 16 15:07:27 UTC 2007
* Alexis S. L. Carvalho on Tuesday, October 16, 2007 at 10:47:03 -0200
> Thus spake Christian Ebert:
>> What is the recommended way to collect filenames (clean,
>> modified, added) in the working directory if the caller uses
>> walkopts? Via repo.status or repo.walk?
>
> Rule of thumb - use status if you care about the status of the files;
> use walk if you just want a list.
Thought so, thanks for the confirmation.
> Both will walk the working dir in the same way, but status will have a
> slightly higher overhead since it also has to check the status of every
> file.
But only if repo.walk is called with the node argument, according
to my meagre understanding of the code, because otherwise
repo.walk calls dirstate.walk, which in turn calls
dirstate.statwalk. Right?
> Depending on what you want to do, you could also just look at the list
> of files in the dirstate:
>
> files = list(repo.dirstate)
>
> (or maybe files = [f for f in repo.dirstate if repo.dirstate[f] != 'r']
> to avoid removed files)
>
> This will be the fastest, since it won't do any listdir or lstat.
Yes. For my purpose manifest.keys() would do as well, as I need
the manifest flags later on (wwrite etc.). Only I can't wrap my
head around how to apply the *walkopts* on this.
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.
I also tried to prune manifest.copy() but the wrong way, as I
didn't get the desired results, ahem.
Anyway, thanks for coming back on this, at least I seem to stray
in the right direction in general.
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