[PATCH] mq:qpush and qpop with serial index

Xiaofeng Ling xiaofeng.ling at intel.com
Mon Sep 12 22:22:35 CDT 2005


Chris
     This patch made I can use both index number and patch name. Using
index number is so much convient for me. The index number can be gotten 
by hg series -v

hg qpush 4
hg qpop  3

diff -r 2031b0e8d6e6 contrib/mq
--- a/contrib/mq	Sun Sep 11 18:08:20 2005
+++ b/contrib/mq	Tue Sep 13 11:16:23 2005
@@ -287,6 +287,13 @@
          return None

      def push(self, repo, patch=None, force=False, list=False):
+        if patch and re.match("\d", patch):
+            sno = int(patch)
+            if sno >= len(self.series):
+                self.ui.warn("This number %s is out of range\n" % sno)
+                sys.exit(1)
+            patch = self.series[sno]
+            self.ui.write("push to %s ...\n" % patch)
          if patch and self.isapplied(patch):
              self.ui.warn("patch %s is already applied\n" % patch)
              sys.exit(1)
@@ -321,6 +328,14 @@
              except IOError:
                  os.makedirs(os.path.dirname(repo.wjoin(f)))
                  repo.wfile(f, "w").write(t)
+
+        if patch and re.match("\d", patch):
+            sno = int(patch)
+            if sno >= len(self.series):
+                self.ui.warn("This number %s is out of range\n" % sno)
+                sys.exit(1)
+            patch = self.series[sno]
+            self.ui.write("pop to %s ...\n" % patch)
          if patch:
              # index, rev, patch
              info = self.isapplied(patch)
@@ -512,8 +527,15 @@
              self.ui.write("%s\n" % p)

      def qseries(self, repo):
-        for p in self.series:
+        start = len(self.applied)
+        for p in self.series[:start]:
+            if self.ui.verbose:
+                self.ui.write("%02d A " % self.series.index(p))
              self.ui.write("%s\n" % p)
+        for p in self.series[start:]:
+            if self.ui.verbose:
+                self.ui.write("%02d A " % self.series.index(p))
+            self.ui.write("%s\n" %  p)

      def issaveline(self, l):
          name = l.split(':')[1]
@@ -732,11 +754,11 @@
      "qprev": (prev, [], "hg qprev"),
      "^qpop": (pop, [('a', 'all', None, 'pop all patches'),
                     ('f', 'force', None, 'forget any local changes')],
-            'hg qpop [options] [patch]'),
+            'hg qpop [options] [patch/index]'),
      "^qpush": (push, [('f', 'force', None, 'apply if the patch has 
rejects'),
                       ('l', 'list', None, 'list patch name in commit 
text'),
                       ('a', 'all', None, 'apply all patches')],
-             'hg qpush [options] [patch]'),
+             'hg qpush [options] [patch/index]'),
      "^qrefresh": (refresh, [('s', 'short', None, 'short refresh')],"hg 
qrefresh"),
      "qrestore": (restore, [('d', 'delete', None, 'delete save entry'),
                             ('u', 'update', None, 'update queue working 
dir')],




If you think it is ok, I also like to implement like hg qpush +3


More information about the Mercurial mailing list