[PATCH 8 of 8 hglib] client: add tags command

Idan Kamara idankk86 at gmail.com
Mon Aug 15 14:54:16 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1313437605 -10800
# Node ID ade12d3f5f35ba0d58eff4e8bcb39f63c02bd4df
# Parent  af5a2392bfeb3b09cf64cf8021d020347c25e039
client: add tags command

diff -r af5a2392bfeb -r ade12d3f5f35 hglib/client.py
--- a/hglib/client.py	Mon Aug 15 22:46:45 2011 +0300
+++ b/hglib/client.py	Mon Aug 15 22:46:45 2011 +0300
@@ -623,6 +623,24 @@
 
         self.rawcommand(args)
 
+    def tags(self):
+        """
+        Return a list of repository tags as: (name, rev, node, islocal)
+        """
+        args = cmdbuilder('tags', v=True)
+
+        out = self.rawcommand(args)
+
+        t = []
+        for line in out.splitlines():
+            taglocal = line.endswith(' local')
+            if taglocal:
+                line = line[:-6]
+            name, rev = line.rsplit(' ', 1)
+            rev, node = rev.split(':')
+            t.append((name.rstrip(), int(rev), node, taglocal))
+        return t
+
     def tip(self):
         args = cmdbuilder('tip', template=templates.changeset)
         out = self.rawcommand(args)
diff -r af5a2392bfeb -r ade12d3f5f35 tests/test-tags.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-tags.py	Mon Aug 15 22:46:45 2011 +0300
@@ -0,0 +1,19 @@
+import common
+import hglib
+
+class test_tags(common.basetest):
+    def test_basic(self):
+        self.append('a', 'a')
+        rev, node = self.client.commit('first', addremove=True)
+        self.client.tag('my tag')
+        self.client.tag('local tag', rev=rev, local=True)
+
+        # filecache that was introduced in 2.0 makes us see the local tag, for
+        # now we have to reconnect
+        if self.client.version < (2, 0, 0):
+            self.client = hglib.open()
+
+        tags = self.client.tags()
+        self.assertEquals(tags, [('tip', 1, self.client.tip().node[:12], False),
+                                 ('my tag', 0, node[:12], False),
+                                 ('local tag', 0, node[:12], True)])


More information about the Mercurial-devel mailing list