1. Yuya Nishihara
  2. vcprompt-mq

Source

vcprompt-mq / multi-mq.diff

# HG changeset patch
# Parent d2bc4f950765e2e655bdbdc9abfa2641c00dc7eb
hg: add support for multiple patch queues, introduced at Mercurial 1.6

 % hg qqueue -c foo
 % cat .hg/patches.queue
 foo
 % hg qnew bar
 % ls .hg/patches-foo
 bar  series  status

diff --git a/src/hg.c b/src/hg.c
--- a/src/hg.c
+++ b/src/hg.c
@@ -113,12 +113,22 @@ static csinfo_t get_csinfo(const char* n
 static size_t get_mq_patchname(char* str, const char* nodeid, size_t n)
 {
     char buf[1024];
+    char status_file_name[256] = ".hg/patches/status";
+    static const char QQ_STATUS_FILE_PAT[] = ".hg/patches-%s/status";
+    static const size_t MAX_QQ_NAME = sizeof(status_file_name)
+        - (sizeof(QQ_STATUS_FILE_PAT) - 2 - 1);  // - "%s" - '\0'
 
-    if (read_last_line(".hg/patches/status", buf, 1024)) {
+    // multiple patch queues, introduced at mercurial 1.6
+    if (read_first_line(".hg/patches.queue", buf, MAX_QQ_NAME) && buf[0]) {
+        debug("read first line from .hg/patches.queue: '%s'", buf);
+        sprintf(status_file_name, QQ_STATUS_FILE_PAT, buf);
+    }
+
+    if (read_last_line(status_file_name, buf, 1024)) {
         char nodeid_s[NODEID_LEN * 2 + 1], *p, *patch, *patch_nodeid_s;
         dump_hex(nodeid, nodeid_s, NODEID_LEN);
 
-        debug("read last line from .hg/patches/status: '%s'", buf);
+        debug("read last line from %s: '%s'", status_file_name, buf);
         p = strchr(buf, ':');
         if (!p) return 0;
         *p = '\0';
diff --git a/tests/test-simple b/tests/test-simple
--- a/tests/test-simple
+++ b/tests/test-simple
@@ -130,7 +130,15 @@ test_simple_hg_mq ()
     printf 'a123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
         > .hg/dirstate
     echo '613132333435363738396162636465666768696a:baz.diff' >> .hg/patches/status
+    echo > .hg/patches.queue  # default queue
     assert_vcprompt "hg_mq applied 2" "hg:613132333435[baz.diff]/foo" "%n:%r/%b"
+
+    mkdir .hg/patches-foo
+    printf 'a123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
+        > .hg/dirstate
+    echo '613132333435363738396162636465666768696a:baz.diff' >> .hg/patches-foo/status
+    echo 'foo' > .hg/patches.queue  # named queue
+    assert_vcprompt "hg_mq applied named mq" "hg:613132333435[baz.diff]/foo" "%n:%r/%b"
 }
 
 test_simple_hg_revlog ()