changeset 27:46908f4b87d5

client: add bookmarks support to incoming and outgoing
author Idan Kamara <idankk86@gmail.com>
date Thu, 11 Aug 2011 22:59:05 +0300
parents b4e5c8745ef3
children 221eeb3693f4
files hglib/client.py tests/test-outgoing-incoming.py
diffstat 2 files changed, 48 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Thu Aug 11 22:58:38 2011 +0300
+++ b/hglib/client.py	Thu Aug 11 22:59:05 2011 +0300
@@ -308,6 +308,12 @@
     def incoming(self, revrange=None, path=None, force=False, newest=False,
                  bundle=None, bookmarks=False, branch=None, limit=None,
                  nomerges=False, subrepos=False):
+        """
+        Return new changesets found in the specified path or the default pull
+        location.
+
+        When bookmarks=True, return a list of (name, node) of incoming bookmarks.
+        """
         args = cmdbuilder('incoming',
                           path,
                           template=templates.changeset, r=revrange,
@@ -322,8 +328,15 @@
         if not out:
             return []
 
-        out = util.eatlines(out, 2).split('\0')[:-1]
-        return self._parserevs(out)
+        out = util.eatlines(out, 2)
+        if bookmarks:
+            bms = []
+            for line in out.splitlines():
+                bms.append(tuple(line.split()))
+            return bms
+        else:
+            out = out.split('\0')[:-1]
+            return self._parserevs(out)
 
     def log(self, revrange=None, files=[], follow=False, followfirst=False,
             date=None, copies=False, keyword=None, removed=False, onlymerges=False,
@@ -343,6 +356,13 @@
     def outgoing(self, revrange=None, path=None, force=False, newest=False,
                  bookmarks=False, branch=None, limit=None, nomerges=False,
                  subrepos=False):
+        """
+        Return changesets not found in the specified path or the default push
+        location.
+
+        When bookmarks=True, return a list of (name, node) of bookmarks that will
+        be pushed.
+        """
         args = cmdbuilder('outgoing',
                           path,
                           template=templates.changeset, r=revrange,
@@ -357,8 +377,15 @@
         if not out:
             return []
 
-        out = util.eatlines(out, 2).split('\0')[:-1]
-        return self._parserevs(out)
+        out = util.eatlines(out, 2)
+        if bookmarks:
+            bms = []
+            for line in out.splitlines():
+                bms.append(tuple(line.split()))
+            return bms
+        else:
+            out = out.split('\0')[:-1]
+            return self._parserevs(out)
 
     def parents(self, rev=None, file=None):
         args = cmdbuilder('parents', file, template=templates.changeset, r=rev)
--- a/tests/test-outgoing-incoming.py	Thu Aug 11 22:58:38 2011 +0300
+++ b/tests/test-outgoing-incoming.py	Thu Aug 11 22:59:05 2011 +0300
@@ -32,3 +32,20 @@
         self.assertEquals(out[0].node, node)
 
         self.assertEquals(out, other.incoming())
+
+    def test_bookmarks(self):
+        self.append('a', 'a')
+        self.client.commit('first', addremove=True)
+        self.append('a', 'a')
+        self.client.commit('second')
+
+        self.client.clone(dest='other')
+        other = hglib.open('other')
+
+        self.client.bookmark('bm1', 1)
+
+        self.assertEquals(other.incoming(bookmarks=True),
+                          [('bm1', self.client.tip().node[:12])])
+
+        self.assertEquals(self.client.outgoing(path='other', bookmarks=True),
+                          [('bm1', self.client.tip().node[:12])])