Patchwork [1,of,9,standalone-strip] mq: simplifies the refresh hint in checklocalchanges

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 25, 2013, 9:26 p.m.
Message ID <9c5cdf575aad77dd2e4f.1380144404@vulgaris>
Download mbox | patch
Permalink /patch/2630/
State Accepted
Commit 5d6cfdc38a3d48e8c95cc1031dcb68ee9b01246b
Headers show

Comments

Pierre-Yves David - Sept. 25, 2013, 9:26 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1380104920 -7200
#      Wed Sep 25 12:28:40 2013 +0200
# Node ID 9c5cdf575aad77dd2e4f0ba155abecfeae85de51
# Parent  50d721553198cea51c30f53b76d41dc919280097
mq: simplifies the refresh hint in checklocalchanges

The `checklocalchanges` function in the `mq.queue` class takes a `refresh` argument that
changes the error message of raised exception. When refresh is
`True` the exception message is "local changes found, refresh first" otherwise,
the message is just "local changes found".

This changeset is the first of a series that extract `strip` into a standalone
extension (as discussed in issue3824). This `checklocalchanges` function is
indirectly used by the strip command. But in a standalone strip extension the
concept of "refresh first" has no sense. In practice, When used in the context
of the strip commands `refresh`'s value is always `False`.

So my final goal is a be able to extract the `checklocalchanges` logic in a
standalone extension but to keep the part related to "refresh first" in the mq
extension. However the refresh handling is deeply entangled into the
`checklocalchanges` code. It is handled as low a possible at the point we raise
the exception.

So we moves handling of refresh upper in the `checklocalchanges` code. This will
allow the extraction of a simple version in the strip extension while mq can
still inject its logic when needed.

Two helper functions `localchangesfound` and `localchangedsubreposfound` died in
the process they are replaced by simple raise lines.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -972,30 +972,26 @@  class queue(object):
         elif substatestate in 'r':
             changes[2].append('.hgsubstate')
         else: # modified
             changes[0].append('.hgsubstate')
 
-    def localchangesfound(self, refresh=True):
+    def checklocalchanges(self, repo, force=False, refresh=True):
+        excsuffix = ''
         if refresh:
-            raise util.Abort(_("local changes found, refresh first"))
-        else:
-            raise util.Abort(_("local changes found"))
-
-    def localchangedsubreposfound(self, refresh=True):
-        if refresh:
-            raise util.Abort(_("local changed subrepos found, refresh first"))
-        else:
-            raise util.Abort(_("local changed subrepos found"))
-
-    def checklocalchanges(self, repo, force=False, refresh=True):
+            excsuffix = ', refresh first'
+            # plain versions for i18n tool to detect them
+            _("local changes found, refresh first")
+            _("local changed subrepos found, refresh first")
         cmdutil.checkunfinished(repo)
         m, a, r, d = repo.status()[:4]
         if not force:
             if (m or a or r or d):
-                self.localchangesfound(refresh)
+                _("local changes found") # i18n tool detection
+                raise util.Abort(_("local changes found" + excsuffix))
             if self.checksubstate(repo):
-                self.localchangedsubreposfound(refresh)
+                _("local changed subrepos found") # i18n tool detection
+                raise util.Abort(_("local changed subrepos found" + excsuffix))
         return m, a, r, d
 
     _reserved = ('series', 'status', 'guards', '.', '..')
     def checkreservedname(self, name):
         if name in self._reserved:
@@ -1447,11 +1443,11 @@  class queue(object):
                 if d:
                     raise util.Abort(_("deletions found between repo revs"))
 
                 tobackup = set(a + m + r) & tobackup
                 if keepchanges and tobackup:
-                    self.localchangesfound()
+                    raise util.Abort(_("local changes found, refresh first"))
                 self.backup(repo, tobackup)
 
                 for f in a:
                     util.unlinkpath(repo.wjoin(f), ignoremissing=True)
                     repo.dirstate.drop(f)