Mercurial > hgsubversion
changeset 298:32d3f1716e66
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.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 27 Mar 2009 02:50:01 +0100 |
parents | 1611834e39ee |
children | 3e27514d575c |
files | svnwrap/svn_swig_wrapper.py |
diffstat | 1 files changed, 32 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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)