# HG changeset patch # User Dan Villiom Podlaski Christiansen # Date 1238118601 -3600 # Node ID 32d3f1716e668c9dec0102f0ef9c2edbb4ca17e5 # Parent 1611834e39ee5e61e26156613282362eb6b1be6f Two minor optimisations/cleanups for svn_swig_wrapper: - 'self' is not used in 'RaCallbacks', so use the @staticmethod decorator syntax introduced in Python 2.4. - Make 'Revision' derive from 'tuple' and use property getters to obtain the individual values. In N+1 years, we can use the NamedRecord introduced in Python 2.6. diff --git a/svnwrap/svn_swig_wrapper.py b/svnwrap/svn_swig_wrapper.py --- a/svnwrap/svn_swig_wrapper.py +++ b/svnwrap/svn_swig_wrapper.py @@ -33,12 +33,14 @@ def optrev(revnum): svn_config = core.svn_config_get_config(None) class RaCallbacks(ra.Callbacks): - def open_tmp_file(self, pool): #pragma: no cover + @staticmethod + def open_tmp_file(pool): #pragma: no cover (fd, fn) = tempfile.mkstemp() os.close(fd) return fn - def get_client_string(self, pool): + @staticmethod + def get_client_string(pool): return 'hgsubversion' @@ -92,17 +94,38 @@ def _create_auth_baton(pool): return core.svn_auth_open(providers, pool) -class Revision(object): +class Revision(tuple): """Wrapper for a Subversion revision. + + Derives from tuple in an attempt to minimise the memory footprint. """ - def __init__(self, revnum, author, message, date, paths, strip_path=''): - self.revnum, self.author, self.message = revnum, author, message - # TODO parse this into a datetime - self.date = date - self.paths = {} + def __new__(self, revnum, author, message, date, paths, strip_path=''): + _paths = {} if paths: for p in paths: - self.paths[p[len(strip_path):]] = paths[p] + _paths[p[len(strip_path):]] = paths[p] + return tuple.__new__(self, + (revnum, author, message, date, _paths)) + + def get_revnum(self): + return self[0] + revnum = property(get_revnum) + + def get_author(self): + return self[1] + author = property(get_author) + + def get_message(self): + return self[2] + message = property(get_message) + + def get_date(self): + return self[3] + date = property(get_date) + + def get_paths(self): + return self[4] + paths = property(get_paths) def __str__(self): return 'r%d by %s' % (self.revnum, self.author)