D4477: merge: move purge logic from extension

Yuya Nishihara yuya at tcha.org
Thu Sep 6 08:46:57 EDT 2018


> +def purge(repo, dirs=None, ignored=False, removeemptydirs=True,
> +          removefiles=True, abortonerror=False, include=None, exclude=None,
> +          noop=False):

Nit: can't we pass in matcher instead of (dirs, include, exclude)?

> +    if removefiles:
> +        for f in sorted(status.unknown + status.ignored):
> +            if not noop:
> +                repo.ui.note(_('removing file %s\n') % f)
> +                remove(util.unlink, f)
> +            yield f
> +
> +    if removeemptydirs:
> +        for f in sorted(directories, reverse=True):
> +            if match(f) and not os.listdir(repo.wvfs.join(f)):
> +                if not noop:
> +                    repo.ui.note(_('removing directory %s\n') % f)
> +                    remove(os.rmdir, f)
> +                yield f

This means `mergemod.purge()` itself does nothing unless the return value
is fully consumed. That's IMHO a bad API.

> +    paths = mergemod.purge(
> +        repo, dirs, ignored=opts.get('all', False),
> +        removeemptydirs=removedirs, removefiles=removefiles,
> +        abortonerror=opts.get('abort_on_err'),
> +        include=opts.get('include'), exclude=opts.get('exclude'),
> +        noop=opts.get('print') or opts.get('print0'))

Nit: perhaps `noop=not act`?


More information about the Mercurial-devel mailing list