Yuya Nishihara avatar Yuya Nishihara committed ceb48d6

hg: add support for multiple patch queues, introduced in Mercurial 1.6.

Comments (0)

Files changed (2)

 static size_t get_mq_patchname(char* str, const char* nodeid, size_t n)
 {
     char buf[1024];
+    char status_filename[] = ".hg/patches/status";
+    static const char QQ_STATUS_FILE_PAT[] = ".hg/patches-%s/status";
+    static const size_t MAX_QQ_NAME = sizeof(status_filename)
+        - (sizeof(QQ_STATUS_FILE_PAT) - 2 - 1);  // - "%s" - '\0'
 
-    if (read_last_line(".hg/patches/status", buf, 1024)) {
+    // multiple patch queues, introduced in 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_filename, QQ_STATUS_FILE_PAT, buf);
+    }
+
+    if (read_last_line(status_filename, 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_filename, buf);
         p = strchr(buf, ':');
         if (!p) return 0;
         *p = '\0';

tests/test-simple

     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 ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.