[PATCH hglib] hglib: Eliminate named tuples for Python 2.4 and 2.5 compatibility

Jeff Laughlin jmlaughlin at integrated-informatics.com
Mon Nov 28 10:06:48 CST 2011


# HG changeset patch
# User Jeff Laughlin <jmlaughlin at integrated-informatics.com>
# Date 1321987954 18000
# Node ID 317a25e6c619ed59c94d583f96d3763ccc8b47e4
# Parent  3bbf6a3266f44ce822b19b0a857dd3a3cea1d515
hglib: Eliminate named tuples for Python 2.4 and 2.5 compatibility.

Named tuples were not introduced until Python 2.6. Since Mercurial advertises compatibility
backwards with Python 2.4, it seems as though hglib ought to be compatible as well. This
patch replaces usage of the revision named tuple in client.py with a Revision class. It passes all
tests.

diff -r 3bbf6a3266f4 -r 317a25e6c619 hglib/client.py
--- a/hglib/client.py	Fri Nov 18 00:49:47 2011 +0200
+++ b/hglib/client.py	Tue Nov 22 13:52:34 2011 -0500
@@ -1,17 +1,37 @@
-import subprocess, os, struct, cStringIO, collections, re
+import subprocess, os, struct, cStringIO, re
 import hglib, error, util, templates, merge
 
 from util import cmdbuilder
 
+class Revision(object):
+    def __init__(self, rev, node, tags, branch, author, desc):
+        self.rev = rev
+        self.node = node
+        self.tags = tags
+        self.branch = branch
+        self.author = author
+        self.desc = desc
+
+    def __cmp__(self, other):
+        if (
+            self.rev == other.rev and
+            self.node == other.node and
+            self.tags == other.tags and
+            self.branch == other.branch and
+            self.author == other.author and
+            self.desc == other.desc
+        ):
+            return 0
+        else:
+            return 1
+
+
 class hgclient(object):
     inputfmt = '>I'
     outputfmt = '>cI'
     outputfmtsize = struct.calcsize(outputfmt)
     retfmt = '>i'
 
-    revision = collections.namedtuple('revision', 'rev, node, tags, '
-                                                  'branch, author, desc')
-
     def __init__(self, path, encoding, configs):
         args = [hglib.HGPATH, 'serve', '--cmdserver', 'pipe',
                 '--config', 'ui.interactive=True']
@@ -62,7 +82,7 @@
     def _parserevs(self, splitted):
         ''' splitted is a list of fields according to our rev.style, where each 6
         fields compose one revision. '''
-        return [self.revision._make(rev) for rev in util.grouper(6, splitted)]
+        return [Revision(*rev) for rev in util.grouper(6, splitted)]
 
     def runcommand(self, args, inchannels, outchannels):
         def writeblock(data):


More information about the Mercurial-devel mailing list