This is an archive of the discontinued Mercurial Phabricator instance.

merge: move purge logic from extension
ClosedPublic

Authored by indygreg on Sep 4 2018, 6:56 PM.

Details

Summary

Working directory purging feels like functionality that should be
in core rather than in an extension.

This commit effectively moves the core purging logic from the
purge extension to merge.py.

Code was refactored slightly. Rather than deal with printing in
this function, the function is a generator of paths and the caller
can worry about printing.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

indygreg created this revision.Sep 4 2018, 6:56 PM
yuja added a subscriber: yuja.Sep 6 2018, 8:47 AM

+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?

indygreg updated this revision to Diff 10825.Sep 6 2018, 9:33 PM
yuja added a comment.Sep 7 2018, 8:05 AM

Queued the series, thanks.

+ matcher = scmutil.match(repo[None], dirs or (), {
+ 'include': opts.get('include'),
+ 'exclude': opts.get('exclude')})

  • match = scmutil.match(repo[None], dirs, opts)

Restored the original match construction, which looks simpler.

This revision was automatically updated to reflect the committed changes.