Commits

Greg Ward  committed 22018ed

hg: simplify %r so it just shows revision number or changeset ID.

Cluttering it up with MQ patch name and "[tip]" was just ugly and
messy. Those should be separate format specifiers.

Revision number depends on parsing both .hg/dirstate and
.hg/changelog, which should work ... but the changeset ID is there as
a fallback if we only succeed in parsing dirstate.

  • Participants
  • Parent commits ef4179b

Comments (0)

Files changed (4)

 put_nodeid(char *str, const char *nodeid)
 {
     const size_t SHORT_NODEID_LEN = 6;  // size in binary repr
-    char buf[512], *p = str;
-    size_t n;
+    char *p = str;
 
     csinfo_t csinfo = get_csinfo(nodeid);
-
-    if (csinfo.rev >= 0) p += sprintf(p, "%d:", csinfo.rev);
-
-    dump_hex(nodeid, p, SHORT_NODEID_LEN);
-    p += SHORT_NODEID_LEN * 2;
-
-    n = get_mq_patchname(buf, nodeid, sizeof(buf));
-    if (n) {
-        *p = '['; ++p;
-        memcpy(p, buf, n); p += n;
-        *p = ']'; ++p;
-        *p = '\0';
-    } else {
-        if (csinfo.istip) {
-            strcpy(p, "[tip]");
-            p += 5;
-        }
+    if (csinfo.rev >= 0) {
+        p += sprintf(p, "%d", csinfo.rev);
     }
-
+    else {
+        dump_hex(nodeid, p, SHORT_NODEID_LEN);
+        p += SHORT_NODEID_LEN * 2;
+    }
     return p - str;
 }
 

File tests/test-hg

 {
     pretest
     assert_vcprompt "show branch 1" "default" "%b"
+    assert_vcprompt "show rev 1" "[1]" "[%r]"
+
     hg -q update stable
     assert_vcprompt "show branch 2" "stable" "%b"
+    assert_vcprompt "show rev 2" "[2]" "[%r]"
 
     # not implemented yet
     #echo foo >> b
     #assert_vcprompt "show modified" "+" "%m"
     #assert_vcprompt "show unknown" "?" "%u"
 
+    hg -q update default
+    hg -q merge --tool internal:other stable
+    assert_vcprompt "show branch 3" "default" "%b"
+    assert_vcprompt "show rev 3" "[1,2]" "[%r]"
+
     posttest
 }
 

File tests/test-simple

     printf '0123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
         > .hg/dirstate
     echo '303132333435363738396162636465666768696a:bar.diff' >> .hg/patches/status
-    assert_vcprompt "hg_mq applied 1" "hg:303132333435[bar.diff]/foo" "%n:%r/%b"
+    assert_vcprompt "hg_mq applied 1" "hg:303132333435/foo" "%n:%r/%b"
 
     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"
+    assert_vcprompt "hg_mq applied 2" "hg:613132333435/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:qux.diff' >> .hg/patches-foo/status
     echo 'foo' > .hg/patches.queue  # named queue
-    assert_vcprompt "hg_mq applied named mq" "hg:613132333435[qux.diff]/foo" "%n:%r/%b"
+    assert_vcprompt "hg_mq applied named mq" "hg:613132333435/foo" "%n:%r/%b"
 }
 
 test_simple_hg_revlog ()
 
     printf '0123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
         > .hg/dirstate
-    assert_vcprompt "hg_revlog notip" "hg:0:303132333435" "%n:%r"
+    assert_vcprompt "hg_revlog notip" "hg:0" "%n:%r"
 
     printf 'a123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
         > .hg/dirstate
-    assert_vcprompt "hg_revlog tip" "hg:1:613132333435[tip]" "%n:%r"
+    assert_vcprompt "hg_revlog tip" "hg:1" "%n:%r"
 
     # inlined
     (
 
     printf '0123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
         > .hg/dirstate
-    assert_vcprompt "hg_revlog inlined notip" "hg:0:303132333435" "%n:%r"
+    assert_vcprompt "hg_revlog inlined notip" "hg:0" "%n:%r"
 
     printf 'a123456789abcdefghij\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0' \
         > .hg/dirstate
-    assert_vcprompt "hg_revlog inlined tip" "hg:1:613132333435[tip]" "%n:%r"
+    assert_vcprompt "hg_revlog inlined tip" "hg:1" "%n:%r"
 }
 
 test_simple_svn()
 .I .hg/branch
 ) if no bookmark is current.
 
+Format specifier
+.B %r
+(revision) expands to the revision number of the parent of the working
+dir, or a comma-separated pair of revision numbers if a merge is
+active (the working dir has two parents). If
+.B vcprompt
+fails to parse some of Mercurial's internal data, it might print a
+short changeset ID instead of a revision number. If that happens,
+please report a bug in
+.B vcprompt
+!
+
 Format specifiers
 .B %m
 and