Patchwork [1,of,4,STABLE] mq: report correct numbers for changing "number of guarded, applied patches"

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 11, 2014, 5:48 p.m.
Message ID <c3c55db74344b03f4d31.1410457721@feefifofum>
Download mbox | patch
Permalink /patch/5800/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Sept. 11, 2014, 5:48 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1410456559 -32400
#      Fri Sep 12 02:29:19 2014 +0900
# Branch stable
# Node ID c3c55db74344b03f4d314361bced15067144d0a5
# Parent  f98abe3146b24a1e50e1c554850fbe5a8994d4fc
mq: report correct numbers for changing "number of guarded, applied patches"

Before this patch, "hg qselect" may report incorrect numbers for
"number of guarded, applied patches has changed", because it examines
"pushable" of patches by the index not in "the series" but in "applied
patches", even though "mq.pushable()" expects the former.

To report correct numbers for changing "number of guarded, applied
patches", this patch uses the name of applied patch to examine
pushable-ness of it.

This patch also changes the result of existing "hg qselect" tests,
because they doesn't change pushable-ness of already applied patches.

This patch assumes that "hg qselect" focuses on changing pushable-ness
only of already applied patches, because:

  - the report message uses not "previous" (in the series) but
    "applied"

  - the logic to pop patches for --pop/--reapply examines
    pushable-ness only of already applied ones (in fact, there are
    some incorrect code paths)

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2969,18 +2969,17 @@ 
 
     q = repo.mq
     guards = q.active()
+    pushable = lambda i: q.pushable(q.applied[i].name)[0]
     if args or opts.get('none'):
         old_unapplied = q.unapplied(repo)
-        old_guarded = [i for i in xrange(len(q.applied)) if
-                       not q.pushable(i)[0]]
+        old_guarded = [i for i in xrange(len(q.applied)) if not pushable(i)]
         q.setactive(args)
         q.savedirty()
         if not args:
             ui.status(_('guards deactivated\n'))
         if not opts.get('pop') and not opts.get('reapply'):
             unapplied = q.unapplied(repo)
-            guarded = [i for i in xrange(len(q.applied))
-                       if not q.pushable(i)[0]]
+            guarded = [i for i in xrange(len(q.applied)) if not pushable(i)]
             if len(unapplied) != len(old_unapplied):
                 ui.status(_('number of unguarded, unapplied patches has '
                             'changed from %d to %d\n') %
diff --git a/tests/test-mq-guards.t b/tests/test-mq-guards.t
--- a/tests/test-mq-guards.t
+++ b/tests/test-mq-guards.t
@@ -388,7 +388,6 @@ 
   3 G d.patch
   $ hg qselect 2
   number of unguarded, unapplied patches has changed from 0 to 1
-  number of guarded, applied patches has changed from 1 to 0
   $ qappunappv
   % hg qapplied
   new.patch
@@ -507,3 +506,31 @@ 
   0 G new.patch
   1 A c.patch
   2 A d.patch
+
+test that qselect shows "number of guarded, applied patches" correctly
+
+  $ hg qimport -q -e b.patch
+  adding b.patch to series file
+  $ hg qguard -- b.patch -not-b
+  $ hg qpop -a -q
+  patch queue now empty
+  $ hg qunapplied -v
+  0 G new.patch
+  1 U c.patch
+  2 U d.patch
+  3 U b.patch
+  $ hg qselect not-new not-c
+  number of unguarded, unapplied patches has changed from 3 to 2
+  $ hg qpush -q -a
+  patch d.patch is empty
+  now at: b.patch
+
+  $ hg qapplied -v
+  0 G new.patch
+  1 G c.patch
+  2 A d.patch
+  3 A b.patch
+  $ hg qselect --none
+  guards deactivated
+  $ hg qselect not-new not-c not-d
+  number of guarded, applied patches has changed from 0 to 1
diff --git a/tests/test-mq-qpush-fail.t b/tests/test-mq-qpush-fail.t
--- a/tests/test-mq-qpush-fail.t
+++ b/tests/test-mq-qpush-fail.t
@@ -131,8 +131,12 @@ 
   now at: c
 
 now try it when a is unguarded, and we're at the top of the queue
+
+  $ hg qapplied -v
+  0 G a
+  1 A b
+  2 A c
   $ hg qsel block
-  number of guarded, applied patches has changed from 1 to 0
   $ hg qpush b
   abort: cannot push to a previous patch: b
   [255]