Patchwork [5,of,8,shelve-ext,v2] shelve: move 'nothing changed' messaging to a separate function

login
register
mail settings
Submitter Kostia Balytskyi
Date Nov. 10, 2016, 11:37 a.m.
Message ID <455f00c4d332ae42498a.1478777849@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17438/
State Accepted
Headers show

Comments

Kostia Balytskyi - Nov. 10, 2016, 11:37 a.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1478777581 28800
#      Thu Nov 10 03:33:01 2016 -0800
# Node ID 455f00c4d332ae42498a4089aa4a54f135c802ed
# Parent  5e827a6196fe903c16123068ce8b312e5840ae57
shelve: move 'nothing changed' messaging to a separate function

This has nothing to do with the future obsshelve implementation, I just
thought that moving this messaging to a separate function will improve
shelve code readability.
Yuya Nishihara - Nov. 13, 2016, 11:10 a.m.
On Thu, 10 Nov 2016 03:37:29 -0800, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia@fb.com>
> # Date 1478777581 28800
> #      Thu Nov 10 03:33:01 2016 -0800
> # Node ID 455f00c4d332ae42498a4089aa4a54f135c802ed
> # Parent  5e827a6196fe903c16123068ce8b312e5840ae57
> shelve: move 'nothing changed' messaging to a separate function
> 
> This has nothing to do with the future obsshelve implementation, I just
> thought that moving this messaging to a separate function will improve
> shelve code readability.
> 
> diff --git a/hgext/shelve.py b/hgext/shelve.py
> --- a/hgext/shelve.py
> +++ b/hgext/shelve.py
> @@ -320,6 +320,14 @@ def getcommitfunc(extra, interactive, ed
>  
>      return interactivecommitfunc if interactive else commitfunc
>  
> +def _nothingtoshelvemessaging(ui, repo, pats, opts):
> +    stat = repo.status(match=scmutil.match(repo[None], pats, opts))
> +    if stat.deleted:
> +        ui.status(_("nothing changed (%d missing files, see "
> +                    "'hg status')\n") % len(stat.deleted))
> +    else:
> +        ui.status(_("nothing changed\n"))

Perhaps we can move this to cmdutil so commands._docommit() can reuse it.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -320,6 +320,14 @@  def getcommitfunc(extra, interactive, ed
 
     return interactivecommitfunc if interactive else commitfunc
 
+def _nothingtoshelvemessaging(ui, repo, pats, opts):
+    stat = repo.status(match=scmutil.match(repo[None], pats, opts))
+    if stat.deleted:
+        ui.status(_("nothing changed (%d missing files, see "
+                    "'hg status')\n") % len(stat.deleted))
+    else:
+        ui.status(_("nothing changed\n"))
+
 def _docreatecmd(ui, repo, pats, opts):
     wctx = repo[None]
     parents = wctx.parents()
@@ -369,12 +377,7 @@  def _docreatecmd(ui, repo, pats, opts):
             node = cmdutil.dorecord(ui, repo, commitfunc, None,
                                     False, cmdutil.recordfilter, *pats, **opts)
         if not node:
-            stat = repo.status(match=scmutil.match(repo[None], pats, opts))
-            if stat.deleted:
-                ui.status(_("nothing changed (%d missing files, see "
-                            "'hg status')\n") % len(stat.deleted))
-            else:
-                ui.status(_("nothing changed\n"))
+            _nothingtoshelvemessaging(ui, repo, pats, opts)
             return 1
 
         bases = list(mutableancestors(repo[node]))