D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-08 Thread valentin.gatienbaron (Valentin Gatien-Baron)
valentin.gatienbaron created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  It's convenient for deleting build artifacts. Using --all instead
  would delete other things too.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

AFFECTED FILES
  hgext/purge.py
  mercurial/merge.py
  tests/test-purge.t

CHANGE DETAILS

diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -120,19 +120,32 @@
   directory/untracked_file
   $ rm directory/untracked_file
 
-skip ignored files if --all not specified
+skip ignored files if -i or --all not specified
 
   $ touch ignored
   $ hg purge -p
   $ hg purge -v
+  $ touch untracked_file
   $ ls
   directory
   ignored
   r1
+  untracked_file
+  $ hg purge -p -i
+  ignored
+  $ hg purge -v -i
+  removing file ignored
+  $ ls
+  directory
+  r1
+  untracked_file
+  $ touch ignored
   $ hg purge -p --all
   ignored
+  untracked_file
   $ hg purge -v --all
   removing file ignored
+  removing file untracked_file
   $ ls
   directory
   r1
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2698,6 +2698,7 @@
 def purge(
 repo,
 matcher,
+unknown=True,
 ignored=False,
 removeemptydirs=True,
 removefiles=True,
@@ -2709,7 +2710,9 @@
 ``matcher`` is a matcher configured to scan the working directory -
 potentially a subset.
 
-``ignored`` controls whether ignored files should also be purged.
+``unknown`` controls whether unknown files should be purged.
+
+``ignored`` controls whether ignored files should be purged.
 
 ``removeemptydirs`` controls whether empty directories should be removed.
 
@@ -2746,7 +2749,7 @@
 directories = []
 matcher.traversedir = directories.append
 
-status = repo.status(match=matcher, ignored=ignored, unknown=True)
+status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
 
 if removefiles:
 for f in sorted(status.unknown + status.ignored):
diff --git a/hgext/purge.py b/hgext/purge.py
--- a/hgext/purge.py
+++ b/hgext/purge.py
@@ -48,6 +48,7 @@
 [
 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
 (b'', b'all', None, _(b'purge ignored files too')),
+(b'i', b'ignored', None, _(b'purge only ignored files')),
 (b'', b'dirs', None, _(b'purge empty directories')),
 (b'', b'files', None, _(b'purge files')),
 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
@@ -80,7 +81,7 @@
 But it will leave untouched:
 
 - Modified and unmodified tracked files
-- Ignored files (unless --all is specified)
+- Ignored files (unless -i or --all is specified)
 - New files added to the repository (with :hg:`add`)
 
 The --files and --dirs options can be used to direct purge to delete
@@ -102,6 +103,13 @@
 if opts.get(b'print0'):
 eol = b'\0'
 act = False  # --print0 implies --print
+if opts.get(b'all', False):
+ignored = True
+unknown = True
+else:
+ignored = opts.get(b'ignored', False)
+unknown = not ignored
+cmdutil.check_incompatible_arguments(opts, b'all', b'ignored')
 
 removefiles = opts.get(b'files')
 removedirs = opts.get(b'dirs')
@@ -115,7 +123,8 @@
 paths = mergemod.purge(
 repo,
 match,
-ignored=opts.get(b'all', False),
+unknown=unknown,
+ignored=ignored,
 removeemptydirs=removedirs,
 removefiles=removefiles,
 abortonerror=opts.get(b'abort_on_err'),



To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-08 Thread marmoute (Pierre-Yves David)
marmoute added a comment.
marmoute accepted this revision.


  The feature is great (I actually needs it from time to time) and the code 
looks good.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

To: valentin.gatienbaron, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-08 Thread valentin.gatienbaron (Valentin Gatien-Baron)
valentin.gatienbaron updated this revision to Diff 20031.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8096?vs=20023&id=20031

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

AFFECTED FILES
  hgext/purge.py
  mercurial/merge.py
  tests/test-purge.t

CHANGE DETAILS

diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -120,19 +120,32 @@
   directory/untracked_file
   $ rm directory/untracked_file
 
-skip ignored files if --all not specified
+skip ignored files if -i or --all not specified
 
   $ touch ignored
   $ hg purge -p
   $ hg purge -v
+  $ touch untracked_file
   $ ls
   directory
   ignored
   r1
+  untracked_file
+  $ hg purge -p -i
+  ignored
+  $ hg purge -v -i
+  removing file ignored
+  $ ls
+  directory
+  r1
+  untracked_file
+  $ touch ignored
   $ hg purge -p --all
   ignored
+  untracked_file
   $ hg purge -v --all
   removing file ignored
+  removing file untracked_file
   $ ls
   directory
   r1
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2698,6 +2698,7 @@
 def purge(
 repo,
 matcher,
+unknown=True,
 ignored=False,
 removeemptydirs=True,
 removefiles=True,
@@ -2709,7 +2710,9 @@
 ``matcher`` is a matcher configured to scan the working directory -
 potentially a subset.
 
-``ignored`` controls whether ignored files should also be purged.
+``unknown`` controls whether unknown files should be purged.
+
+``ignored`` controls whether ignored files should be purged.
 
 ``removeemptydirs`` controls whether empty directories should be removed.
 
@@ -2746,7 +2749,7 @@
 directories = []
 matcher.traversedir = directories.append
 
-status = repo.status(match=matcher, ignored=ignored, unknown=True)
+status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
 
 if removefiles:
 for f in sorted(status.unknown + status.ignored):
diff --git a/hgext/purge.py b/hgext/purge.py
--- a/hgext/purge.py
+++ b/hgext/purge.py
@@ -48,6 +48,7 @@
 [
 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
 (b'', b'all', None, _(b'purge ignored files too')),
+(b'i', b'ignored', None, _(b'purge only ignored files')),
 (b'', b'dirs', None, _(b'purge empty directories')),
 (b'', b'files', None, _(b'purge files')),
 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
@@ -80,7 +81,7 @@
 But it will leave untouched:
 
 - Modified and unmodified tracked files
-- Ignored files (unless --all is specified)
+- Ignored files (unless -i or --all is specified)
 - New files added to the repository (with :hg:`add`)
 
 The --files and --dirs options can be used to direct purge to delete
@@ -102,6 +103,13 @@
 if opts.get(b'print0'):
 eol = b'\0'
 act = False  # --print0 implies --print
+if opts.get(b'all', False):
+ignored = True
+unknown = True
+else:
+ignored = opts.get(b'ignored', False)
+unknown = not ignored
+cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
 
 removefiles = opts.get(b'files')
 removedirs = opts.get(b'dirs')
@@ -115,7 +123,8 @@
 paths = mergemod.purge(
 repo,
 match,
-ignored=opts.get(b'all', False),
+unknown=unknown,
+ignored=ignored,
 removeemptydirs=removedirs,
 removefiles=removefiles,
 abortonerror=opts.get(b'abort_on_err'),



To: valentin.gatienbaron, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-10 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  Nice! Looks good to me. Can you add a releasenotes entry in `relnotes/next`?

INLINE COMMENTS

> purge.py:51
>  (b'', b'all', None, _(b'purge ignored files too')),
> +(b'i', b'ignored', None, _(b'purge only ignored files')),
>  (b'', b'dirs', None, _(b'purge empty directories')),

nit: Here instead of `None`, `False` can be used to prevent passing default 
value later in line 110.

> purge.py:112
> +unknown = not ignored
> +cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
>  

nit: it's better to have the check earlier, i.e. after line 99 on this side.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

To: valentin.gatienbaron, #hg-reviewers, marmoute
Cc: pulkit, marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-10 Thread valentin.gatienbaron (Valentin Gatien-Baron)
valentin.gatienbaron updated this revision to Diff 20050.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8096?vs=20031&id=20050

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

AFFECTED FILES
  hgext/purge.py
  mercurial/merge.py
  relnotes/next
  tests/test-purge.t

CHANGE DETAILS

diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -120,19 +120,32 @@
   directory/untracked_file
   $ rm directory/untracked_file
 
-skip ignored files if --all not specified
+skip ignored files if -i or --all not specified
 
   $ touch ignored
   $ hg purge -p
   $ hg purge -v
+  $ touch untracked_file
   $ ls
   directory
   ignored
   r1
+  untracked_file
+  $ hg purge -p -i
+  ignored
+  $ hg purge -v -i
+  removing file ignored
+  $ ls
+  directory
+  r1
+  untracked_file
+  $ touch ignored
   $ hg purge -p --all
   ignored
+  untracked_file
   $ hg purge -v --all
   removing file ignored
+  removing file untracked_file
   $ ls
   directory
   r1
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -1,5 +1,7 @@
 == New Features ==
 
+ * `hg purge`/`hg clean` can now delete ignored files instead of
+   untracked files, with the new -i flag.
 
 == New Experimental Features ==
 
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2698,6 +2698,7 @@
 def purge(
 repo,
 matcher,
+unknown=True,
 ignored=False,
 removeemptydirs=True,
 removefiles=True,
@@ -2709,7 +2710,9 @@
 ``matcher`` is a matcher configured to scan the working directory -
 potentially a subset.
 
-``ignored`` controls whether ignored files should also be purged.
+``unknown`` controls whether unknown files should be purged.
+
+``ignored`` controls whether ignored files should be purged.
 
 ``removeemptydirs`` controls whether empty directories should be removed.
 
@@ -2746,7 +2749,7 @@
 directories = []
 matcher.traversedir = directories.append
 
-status = repo.status(match=matcher, ignored=ignored, unknown=True)
+status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
 
 if removefiles:
 for f in sorted(status.unknown + status.ignored):
diff --git a/hgext/purge.py b/hgext/purge.py
--- a/hgext/purge.py
+++ b/hgext/purge.py
@@ -48,6 +48,7 @@
 [
 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
 (b'', b'all', None, _(b'purge ignored files too')),
+(b'i', b'ignored', None, _(b'purge only ignored files')),
 (b'', b'dirs', None, _(b'purge empty directories')),
 (b'', b'files', None, _(b'purge files')),
 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
@@ -80,7 +81,7 @@
 But it will leave untouched:
 
 - Modified and unmodified tracked files
-- Ignored files (unless --all is specified)
+- Ignored files (unless -i or --all is specified)
 - New files added to the repository (with :hg:`add`)
 
 The --files and --dirs options can be used to direct purge to delete
@@ -96,12 +97,19 @@
 option.
 '''
 opts = pycompat.byteskwargs(opts)
+cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
 
 act = not opts.get(b'print')
 eol = b'\n'
 if opts.get(b'print0'):
 eol = b'\0'
 act = False  # --print0 implies --print
+if opts.get(b'all', False):
+ignored = True
+unknown = True
+else:
+ignored = opts.get(b'ignored', False)
+unknown = not ignored
 
 removefiles = opts.get(b'files')
 removedirs = opts.get(b'dirs')
@@ -115,7 +123,8 @@
 paths = mergemod.purge(
 repo,
 match,
-ignored=opts.get(b'all', False),
+unknown=unknown,
+ignored=ignored,
 removeemptydirs=removedirs,
 removefiles=removefiles,
 abortonerror=opts.get(b'abort_on_err'),



To: valentin.gatienbaron, #hg-reviewers, marmoute
Cc: pulkit, marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-10 Thread valentin.gatienbaron (Valentin Gatien-Baron)
valentin.gatienbaron added a comment.


  I thought it was generally preferred to have the `False` in the code, for 
extensions that want to call the function?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

To: valentin.gatienbaron, #hg-reviewers, marmoute
Cc: pulkit, marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-10 Thread pulkit (Pulkit Goyal)
This revision is now accepted and ready to land.
pulkit added a comment.
pulkit accepted this revision.


  In D8096#120082 , 
@valentin.gatienbaron wrote:
  
  > I thought it was generally preferred to have the `False` in the code, for 
extensions that want to call the function?
  
  Ah, I see. Not sure we have an existing preference here.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

To: valentin.gatienbaron, #hg-reviewers, marmoute, pulkit
Cc: pulkit, marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D8096: purge: add -i flag to delete ignored files instead of untracked files

2020-02-10 Thread valentin.gatienbaron (Valentin Gatien-Baron)
Closed by commit rHG9f8eddd2723f: purge: add -i flag to delete ignored files 
instead of untracked files (authored by valentin.gatienbaron).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8096?vs=20050&id=20053

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8096/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8096

AFFECTED FILES
  hgext/purge.py
  mercurial/merge.py
  relnotes/next
  tests/test-purge.t

CHANGE DETAILS

diff --git a/tests/test-purge.t b/tests/test-purge.t
--- a/tests/test-purge.t
+++ b/tests/test-purge.t
@@ -120,19 +120,32 @@
   directory/untracked_file
   $ rm directory/untracked_file
 
-skip ignored files if --all not specified
+skip ignored files if -i or --all not specified
 
   $ touch ignored
   $ hg purge -p
   $ hg purge -v
+  $ touch untracked_file
   $ ls
   directory
   ignored
   r1
+  untracked_file
+  $ hg purge -p -i
+  ignored
+  $ hg purge -v -i
+  removing file ignored
+  $ ls
+  directory
+  r1
+  untracked_file
+  $ touch ignored
   $ hg purge -p --all
   ignored
+  untracked_file
   $ hg purge -v --all
   removing file ignored
+  removing file untracked_file
   $ ls
   directory
   r1
diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -1,5 +1,7 @@
 == New Features ==
 
+ * `hg purge`/`hg clean` can now delete ignored files instead of
+   untracked files, with the new -i flag.
 
 == New Experimental Features ==
 
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2698,6 +2698,7 @@
 def purge(
 repo,
 matcher,
+unknown=True,
 ignored=False,
 removeemptydirs=True,
 removefiles=True,
@@ -2709,7 +2710,9 @@
 ``matcher`` is a matcher configured to scan the working directory -
 potentially a subset.
 
-``ignored`` controls whether ignored files should also be purged.
+``unknown`` controls whether unknown files should be purged.
+
+``ignored`` controls whether ignored files should be purged.
 
 ``removeemptydirs`` controls whether empty directories should be removed.
 
@@ -2746,7 +2749,7 @@
 directories = []
 matcher.traversedir = directories.append
 
-status = repo.status(match=matcher, ignored=ignored, unknown=True)
+status = repo.status(match=matcher, ignored=ignored, unknown=unknown)
 
 if removefiles:
 for f in sorted(status.unknown + status.ignored):
diff --git a/hgext/purge.py b/hgext/purge.py
--- a/hgext/purge.py
+++ b/hgext/purge.py
@@ -48,6 +48,7 @@
 [
 (b'a', b'abort-on-err', None, _(b'abort if an error occurs')),
 (b'', b'all', None, _(b'purge ignored files too')),
+(b'i', b'ignored', None, _(b'purge only ignored files')),
 (b'', b'dirs', None, _(b'purge empty directories')),
 (b'', b'files', None, _(b'purge files')),
 (b'p', b'print', None, _(b'print filenames instead of deleting them')),
@@ -80,7 +81,7 @@
 But it will leave untouched:
 
 - Modified and unmodified tracked files
-- Ignored files (unless --all is specified)
+- Ignored files (unless -i or --all is specified)
 - New files added to the repository (with :hg:`add`)
 
 The --files and --dirs options can be used to direct purge to delete
@@ -96,12 +97,19 @@
 option.
 '''
 opts = pycompat.byteskwargs(opts)
+cmdutil.check_at_most_one_arg(opts, b'all', b'ignored')
 
 act = not opts.get(b'print')
 eol = b'\n'
 if opts.get(b'print0'):
 eol = b'\0'
 act = False  # --print0 implies --print
+if opts.get(b'all', False):
+ignored = True
+unknown = True
+else:
+ignored = opts.get(b'ignored', False)
+unknown = not ignored
 
 removefiles = opts.get(b'files')
 removedirs = opts.get(b'dirs')
@@ -115,7 +123,8 @@
 paths = mergemod.purge(
 repo,
 match,
-ignored=opts.get(b'all', False),
+unknown=unknown,
+ignored=ignored,
 removeemptydirs=removedirs,
 removefiles=removefiles,
 abortonerror=opts.get(b'abort_on_err'),



To: valentin.gatienbaron, #hg-reviewers, marmoute, pulkit
Cc: pulkit, marmoute, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel