[PATCH] dirstate: make subrepos an optional arg to status() and walk()

Augie Fackler durin42 at gmail.com
Mon Feb 15 09:51:46 CST 2010


On Feb 15, 2010, at 9:25 AM, Greg Ward wrote:

> # HG changeset patch
> # User Greg Ward <greg-hg at gerg.ca>
> # Date 1266244676 18000
> # Node ID a69774706574b6f88cf1d695a2b3485d959ca9f9
> # Parent  ed4de30e16c5b6efb67a2a5edabb424cd4deda7d
> dirstate: make subrepos an optional arg to status() and walk().
> 
> This should make the incompatible API change in 24ce8f0c0a39 much less
> annoying for third-party extension authors who need to maintain
> compatibility with Mercurial 1.4 and 1.5.
> 
> diff --git a/contrib/perf.py b/contrib/perf.py
> --- a/contrib/perf.py
> +++ b/contrib/perf.py
> @@ -32,7 +32,7 @@
> def perfwalk(ui, repo, *pats):
>     try:
>         m = cmdutil.match(repo, pats, {})
> -        timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
> +        timer(lambda: len(list(repo.dirstate.walk(m, True, False))))
>     except:
>         try:
>             m = cmdutil.match(repo, pats, {})
> diff --git a/hgext/inotify/__init__.py b/hgext/inotify/__init__.py
> --- a/hgext/inotify/__init__.py
> +++ b/hgext/inotify/__init__.py
> @@ -41,7 +41,7 @@
>         # to start an inotify server if it won't start.
>         _inotifyon = True
> 
> -        def status(self, match, subrepos, ignored, clean, unknown=True):
> +        def status(self, match, ignored, clean, unknown=True, subrepos=None):

FWIW, I originally had it like this, and (if I remember properly) mpm explicitly wanted it moved.

>             files = match.files()
>             if '.' in files:
>                 files = []
> @@ -69,7 +69,7 @@
>                         result = r2
>                     return result
>             return super(inotifydirstate, self).status(
> -                match, subrepos, ignored, clean, unknown)
> +                match, ignored, clean, unknown, subrepos=subrepos)
> 
>     repo.dirstate.__class__ = inotifydirstate
> 
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -692,8 +692,8 @@
>         return self._parents[0].ancestor(c2) # punt on two parents for now
> 
>     def walk(self, match):
> -        return sorted(self._repo.dirstate.walk(match, self.substate.keys(),
> -                                               True, False))
> +        return sorted(self._repo.dirstate.walk(
> +            match, True, False, subrepos=self.substate.keys()))
> 
>     def dirty(self, missing=False):
>         "check whether a working directory is modified"
> diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> --- a/mercurial/dirstate.py
> +++ b/mercurial/dirstate.py
> @@ -430,7 +430,7 @@
>                 return True
>         return False
> 
> -    def walk(self, match, subrepos, unknown, ignored):
> +    def walk(self, match, unknown, ignored, subrepos=None):
>         '''
>         Walk recursively through the directory tree, finding all files
>         matched by match.
> @@ -496,8 +496,9 @@
>         files = set(match.files())
>         if not files or '.' in files:
>             files = ['']
> -        results = dict.fromkeys(subrepos)
> -        results['.hg'] = None
> +        results = {'.hg': None}
> +        if subrepos is not None:
> +            results.update(dict.fromkeys(subrepos))
> 
>         # step 1: find all explicit files
>         for ff in sorted(files):
> @@ -575,12 +576,13 @@
>                 if not st is None and not getkind(st.st_mode) in (regkind, lnkkind):
>                     st = None
>                 results[nf] = st
> -        for s in subrepos:
> -            del results[s]
> +        if subrepos is not None:
> +            for s in subrepos:
> +                del results[s]
>         del results['.hg']
>         return results
> 
> -    def status(self, match, subrepos, ignored, clean, unknown):
> +    def status(self, match, ignored, clean, unknown, subrepos=None):
>         '''Determine the status of the working copy relative to the
>         dirstate and return a tuple of lists (unsure, modified, added,
>         removed, deleted, unknown, ignored, clean), where:
> @@ -621,8 +623,9 @@
>         dadd = deleted.append
>         cadd = clean.append
> 
> -        for fn, st in self.walk(match, subrepos, listunknown,
> -                                listignored).iteritems():
> +        statusmap = self.walk(match, listunknown, listignored,
> +                              subrepos=subrepos)
> +        for fn, st in statusmap.iteritems():
>             if fn not in dmap:
>                 if (listignored or match.exact(fn)) and self._dirignore(fn):
>                     if listignored:
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1007,8 +1007,8 @@
> 
>         if working: # we need to scan the working dir
>             subrepos = ctx1.substate.keys()
> -            s = self.dirstate.status(match, subrepos, listignored,
> -                                     listclean, listunknown)
> +            s = self.dirstate.status(match, listignored, listclean, listunknown,
> +                                     subrepos=subrepos)
>             cmp, modified, added, removed, deleted, unknown, ignored, clean = s
> 
>             # check for any possibly clean files
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list