changeset 10:fce3102c19e5

client: sort commands by name
author Idan Kamara <idankk86@gmail.com>
date Tue, 09 Aug 2011 23:24:40 +0300
parents 5882a698ad5c
children 0549d00a617d
files hglib/client.py
diffstat 1 files changed, 91 insertions(+), 90 deletions(-) [+]
line wrap: on
line diff
--- a/hglib/client.py	Wed Aug 10 01:48:38 2011 +0300
+++ b/hglib/client.py	Tue Aug 09 23:24:40 2011 +0300
@@ -141,17 +141,38 @@
         self.server = None
         return ret
 
-    @property
-    def encoding(self):
-        """ get the servers encoding """
-        if not 'getencoding' in self.capabilities:
-            raise CapabilityError('getencoding')
+    def branch(self, name=None):
+        if not name:
+            return self.rawcommand(['branch']).rstrip()
+
+    def branches(self):
+        out = self.rawcommand(['branches'])
+        branches = {}
+        for line in out.rstrip().split('\n'):
+            branch, revnode = line.split()
+            branches[branch] = self.log(revrange=[revnode.split(':')[0]])[0]
+
+        return branches
 
-        if not self._encoding:
-            self.server.stdin.write('getencoding\n')
-            self._encoding = self._readfromchannel('r')
+    def cat(self, files, rev=None, output=None):
+        args = cmdbuilder('cat', *files, r=rev, o=output)
+        out = self.rawcommand(args)
+
+        if not output:
+            return out
 
-        return self._encoding
+    def clone(self, source='.', dest=None, branch=None, updaterev=None,
+              revrange=None):
+        args = cmdbuilder('clone', source, dest, b=branch, u=updaterev, r=revrange)
+        self.rawcommand(args)
+
+    def commit(self, message, addremove=False):
+        args = cmdbuilder('commit', m=message, A=addremove)
+
+        self.rawcommand(args)
+
+        # hope the tip hasn't changed since we committed
+        return self.tip()
 
     def config(self, refresh=False):
         if not self._config or refresh:
@@ -166,64 +187,17 @@
 
         return self._config
 
-    def status(self):
-        out = self.rawcommand(['status', '-0'])
-
-        d = dict((c, []) for c in 'MARC!?I')
-
-        for entry in out.split('\0'):
-            if entry:
-                t, f = entry.split(' ', 1)
-                d[t].append(f)
-
-        return d
-
-    def log(self, revrange=None):
-        args = cmdbuilder('log', template=templates.changeset, rev=revrange)
-
-        out = self.rawcommand(args)
-        out = out.split('\0')[:-1]
-
-        return self._parserevs(out)
-
-    def incoming(self, revrange=None, path=None):
-        args = cmdbuilder('incoming',
-                          path,
-                          template=templates.changeset, rev=revrange)
-
-        def eh(ret, out, err):
-            if ret != 1:
-                raise error.CommandError(args, ret, out, err)
+    @property
+    def encoding(self):
+        """ get the servers encoding """
+        if not 'getencoding' in self.capabilities:
+            raise CapabilityError('getencoding')
 
-        out = self.rawcommand(args, eh=eh)
-        if not out:
-            return []
-
-        out = util.eatlines(out, 2).split('\0')[:-1]
-        return self._parserevs(out)
-
-    def outgoing(self, revrange=None, path=None):
-        args = cmdbuilder('outgoing',
-                          path, template=templates.changeset, rev=revrange)
-
-        def eh(ret, out, err):
-            if ret != 1:
-                raise error.CommandError(args, ret, out, err)
+        if not self._encoding:
+            self.server.stdin.write('getencoding\n')
+            self._encoding = self._readfromchannel('r')
 
-        out = self.rawcommand(args, eh=eh)
-        if not out:
-            return []
-
-        out = util.eatlines(out, 2).split('\0')[:-1]
-        return self._parserevs(out)
-
-    def commit(self, message, addremove=False):
-        args = cmdbuilder('commit', m=message, A=addremove)
-
-        self.rawcommand(args)
-
-        # hope the tip hasn't changed since we committed
-        return self.tip()
+        return self._encoding
 
     def import_(self, patch):
         if isinstance(patch, str):
@@ -244,33 +218,44 @@
             if fp != patch:
                 fp.close()
 
-    def root(self):
-        return self.rawcommand(['root']).rstrip()
+    def incoming(self, revrange=None, path=None):
+        args = cmdbuilder('incoming',
+                          path,
+                          template=templates.changeset, rev=revrange)
+
+        def eh(ret, out, err):
+            if ret != 1:
+                raise error.CommandError(args, ret, out, err)
 
-    def clone(self, source='.', dest=None, branch=None, updaterev=None,
-              revrange=None):
-        args = cmdbuilder('clone', source, dest, b=branch, u=updaterev, r=revrange)
-        self.rawcommand(args)
+        out = self.rawcommand(args, eh=eh)
+        if not out:
+            return []
 
-    def tip(self):
-        args = cmdbuilder('tip', template=templates.changeset)
-        out = self.rawcommand(args)
-        out = out.split('\0')
+        out = util.eatlines(out, 2).split('\0')[:-1]
+        return self._parserevs(out)
+
+    def log(self, revrange=None):
+        args = cmdbuilder('log', template=templates.changeset, rev=revrange)
 
-        return self._parserevs(out)[0]
+        out = self.rawcommand(args)
+        out = out.split('\0')[:-1]
 
-    def branch(self, name=None):
-        if not name:
-            return self.rawcommand(['branch']).rstrip()
+        return self._parserevs(out)
+
+    def outgoing(self, revrange=None, path=None):
+        args = cmdbuilder('outgoing',
+                          path, template=templates.changeset, rev=revrange)
 
-    def branches(self):
-        out = self.rawcommand(['branches'])
-        branches = {}
-        for line in out.rstrip().split('\n'):
-            branch, revnode = line.split()
-            branches[branch] = self.log(revrange=[revnode.split(':')[0]])[0]
+        def eh(ret, out, err):
+            if ret != 1:
+                raise error.CommandError(args, ret, out, err)
 
-        return branches
+        out = self.rawcommand(args, eh=eh)
+        if not out:
+            return []
+
+        out = util.eatlines(out, 2).split('\0')[:-1]
+        return self._parserevs(out)
 
     def paths(self, name=None):
         if not name:
@@ -284,9 +269,25 @@
             out = self.rawcommand(args)
             return out.rstrip()
 
-    def cat(self, files, rev=None, output=None):
-        args = cmdbuilder('cat', *files, r=rev, o=output)
+    def root(self):
+        return self.rawcommand(['root']).rstrip()
+
+    def status(self):
+        out = self.rawcommand(['status', '-0'])
+
+        d = dict((c, []) for c in 'MARC!?I')
+
+        for entry in out.split('\0'):
+            if entry:
+                t, f = entry.split(' ', 1)
+                d[t].append(f)
+
+        return d
+
+    def tip(self):
+        args = cmdbuilder('tip', template=templates.changeset)
         out = self.rawcommand(args)
+        out = out.split('\0')
 
-        if not output:
-            return out
+        return self._parserevs(out)[0]
+