Patchwork remove: add dry-run functionality

login
register
mail settings
Submitter sushil khanchi
Date March 21, 2018, 6:26 p.m.
Message ID <35c57ba0cf288af7c232.1521656815@workspace>
Download mbox | patch
Permalink /patch/29714/
State Superseded
Headers show

Comments

sushil khanchi - March 21, 2018, 6:26 p.m.
# HG changeset patch
# User Sushil khanchi <sushilkhanchi97@gmail.com>
# Date 1521655571 -19800
#      Wed Mar 21 23:36:11 2018 +0530
# Node ID 35c57ba0cf288af7c232d0bf17ea8dcb01644d09
# Parent  b6a4881cec1937a8d9cd2e9bbbdf5ca31cfa73dd
remove: add dry-run functionality
Yuya Nishihara - March 22, 2018, 2:19 p.m.
On Wed, 21 Mar 2018 23:56:55 +0530, Sushil khanchi wrote:
> # HG changeset patch
> # User Sushil khanchi <sushilkhanchi97@gmail.com>
> # Date 1521655571 -19800
> #      Wed Mar 21 23:36:11 2018 +0530
> # Node ID 35c57ba0cf288af7c232d0bf17ea8dcb01644d09
> # Parent  b6a4881cec1937a8d9cd2e9bbbdf5ca31cfa73dd
> remove: add dry-run functionality

> +def remove(ui, repo, m, prefix, after, force, subrepos, dryrun, warnings=None):
>      join = lambda f: os.path.join(prefix, f)
>      ret = 0
>      s = repo.status(match=m, clean=True)
> @@ -2181,13 +2181,14 @@

Need to pass dryrun to sub.removefiles()

>      opts = pycompat.byteskwargs(opts)
> -    after, force = opts.get('after'), opts.get('force')
> +    after, force = opts.get(r'after'), opts.get(r'force')
> +    dryrun = opts.get(r'dry_run')

No r'' because here opts is {bytes: any}.

>      @annotatesubrepoerror
> -    def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
> +    def removefiles(self, matcher, prefix, after, force, subrepos,
> +                    dryrun, warnings):
>          return cmdutil.remove(self.ui, self._repo, matcher,
>                                self.wvfs.reljoin(prefix, self._path),
> -                              after, force, subrepos)
> +                              after, force, subrepos, dryrun)

Need to update the base class too.

% grep 'def removefiles' mercurial/subrepo.py
    def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
    def removefiles(self, matcher, prefix, after, force, subrepos,
Anton Shestakov - March 22, 2018, 3:25 p.m.
On Wed, 21 Mar 2018 23:56:55 +0530
Sushil khanchi <sushilkhanchi97@gmail.com> wrote:

> diff -r b6a4881cec19 -r 35c57ba0cf28 mercurial/commands.py
> --- a/mercurial/commands.py	Sun Mar 18 15:32:49 2018 -0400
> +++ b/mercurial/commands.py	Wed Mar 21 23:36:11 2018 +0530
> @@ -4207,7 +4207,7 @@
>      [('A', 'after', None, _('record delete for missing files')),
>      ('f', 'force', None,
>       _('forget added files, delete modified files')),
> -    ] + subrepoopts + walkopts,
> +    ] + subrepoopts + walkopts + dryrunopts,

Judging by this, test-completion.t also needs to be updated.

Patch

diff -r b6a4881cec19 -r 35c57ba0cf28 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/cmdutil.py	Wed Mar 21 23:36:11 2018 +0530
@@ -2076,7 +2076,7 @@ 
 
     return ret
 
-def remove(ui, repo, m, prefix, after, force, subrepos, warnings=None):
+def remove(ui, repo, m, prefix, after, force, subrepos, dryrun, warnings=None):
     join = lambda f: os.path.join(prefix, f)
     ret = 0
     s = repo.status(match=m, clean=True)
@@ -2181,13 +2181,14 @@ 
             ui.status(_('removing %s\n') % m.rel(f))
     ui.progress(_('deleting'), None)
 
-    with repo.wlock():
-        if not after:
-            for f in list:
-                if f in added:
-                    continue # we never unlink added files on remove
-                repo.wvfs.unlinkpath(f, ignoremissing=True)
-        repo[None].forget(list)
+    if not dryrun:
+        with repo.wlock():
+            if not after:
+                for f in list:
+                    if f in added:
+                        continue # we never unlink added files on remove
+                    repo.wvfs.unlinkpath(f, ignoremissing=True)
+            repo[None].forget(list)
 
     if warn:
         for warning in warnings:
diff -r b6a4881cec19 -r 35c57ba0cf28 mercurial/commands.py
--- a/mercurial/commands.py	Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/commands.py	Wed Mar 21 23:36:11 2018 +0530
@@ -4207,7 +4207,7 @@ 
     [('A', 'after', None, _('record delete for missing files')),
     ('f', 'force', None,
      _('forget added files, delete modified files')),
-    ] + subrepoopts + walkopts,
+    ] + subrepoopts + walkopts + dryrunopts,
     _('[OPTION]... FILE...'),
     inferrepo=True)
 def remove(ui, repo, *pats, **opts):
@@ -4250,13 +4250,15 @@ 
     """
 
     opts = pycompat.byteskwargs(opts)
-    after, force = opts.get('after'), opts.get('force')
+    after, force = opts.get(r'after'), opts.get(r'force')
+    dryrun = opts.get(r'dry_run')
     if not pats and not after:
         raise error.Abort(_('no files specified'))
 
     m = scmutil.match(repo[None], pats, opts)
     subrepos = opts.get('subrepos')
-    return cmdutil.remove(ui, repo, m, "", after, force, subrepos)
+    return cmdutil.remove(ui, repo, m, "", after, force, subrepos,
+                          dryrun=dryrun)
 
 @command('rename|move|mv',
     [('A', 'after', None, _('record a rename that has already occurred')),
diff -r b6a4881cec19 -r 35c57ba0cf28 mercurial/subrepo.py
--- a/mercurial/subrepo.py	Sun Mar 18 15:32:49 2018 -0400
+++ b/mercurial/subrepo.py	Wed Mar 21 23:36:11 2018 +0530
@@ -817,10 +817,11 @@ 
                               True, dryrun=dryrun)
 
     @annotatesubrepoerror
-    def removefiles(self, matcher, prefix, after, force, subrepos, warnings):
+    def removefiles(self, matcher, prefix, after, force, subrepos,
+                    dryrun, warnings):
         return cmdutil.remove(self.ui, self._repo, matcher,
                               self.wvfs.reljoin(prefix, self._path),
-                              after, force, subrepos)
+                              after, force, subrepos, dryrun)
 
     @annotatesubrepoerror
     def revert(self, substate, *pats, **opts):
diff -r b6a4881cec19 -r 35c57ba0cf28 tests/test-remove.t
--- a/tests/test-remove.t	Sun Mar 18 15:32:49 2018 -0400
+++ b/tests/test-remove.t	Wed Mar 21 23:36:11 2018 +0530
@@ -505,3 +505,20 @@ 
   deleting [===========================================>] 1/1\r (no-eol) (esc)
                                                               \r (no-eol) (esc)
   [1]
+
+test dry-run for remove
+
+  $ hg init testdryrun
+  $ cd testdryrun
+  $ echo a>a
+  $ hg ci -qAm1
+  $ hg remove a -nv
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  \r (no-eol) (esc)
+  deleting [===========================================>] 1/1\r (no-eol) (esc)
+                                                              \r (no-eol) (esc)
+  removing a
+  $ hg diff
+  $ cd ..