comparison svnwrap/svn_swig_wrapper.py @ 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 fa26c7ef0180
children 4aba7542f6a9
comparison
equal deleted inserted replaced
297:1611834e39ee 298:32d3f1716e66
31 optrev.value.number = revnum 31 optrev.value.number = revnum
32 return optrev 32 return optrev
33 33
34 svn_config = core.svn_config_get_config(None) 34 svn_config = core.svn_config_get_config(None)
35 class RaCallbacks(ra.Callbacks): 35 class RaCallbacks(ra.Callbacks):
36 def open_tmp_file(self, pool): #pragma: no cover 36 @staticmethod
37 def open_tmp_file(pool): #pragma: no cover
37 (fd, fn) = tempfile.mkstemp() 38 (fd, fn) = tempfile.mkstemp()
38 os.close(fd) 39 os.close(fd)
39 return fn 40 return fn
40 41
41 def get_client_string(self, pool): 42 @staticmethod
43 def get_client_string(pool):
42 return 'hgsubversion' 44 return 'hgsubversion'
43 45
44 46
45 def user_pass_prompt(realm, default_username, ms, pool): #pragma: no cover 47 def user_pass_prompt(realm, default_username, ms, pool): #pragma: no cover
46 creds = core.svn_auth_cred_simple_t() 48 creds = core.svn_auth_cred_simple_t()
90 ] 92 ]
91 93
92 return core.svn_auth_open(providers, pool) 94 return core.svn_auth_open(providers, pool)
93 95
94 96
95 class Revision(object): 97 class Revision(tuple):
96 """Wrapper for a Subversion revision. 98 """Wrapper for a Subversion revision.
99
100 Derives from tuple in an attempt to minimise the memory footprint.
97 """ 101 """
98 def __init__(self, revnum, author, message, date, paths, strip_path=''): 102 def __new__(self, revnum, author, message, date, paths, strip_path=''):
99 self.revnum, self.author, self.message = revnum, author, message 103 _paths = {}
100 # TODO parse this into a datetime
101 self.date = date
102 self.paths = {}
103 if paths: 104 if paths:
104 for p in paths: 105 for p in paths:
105 self.paths[p[len(strip_path):]] = paths[p] 106 _paths[p[len(strip_path):]] = paths[p]
107 return tuple.__new__(self,
108 (revnum, author, message, date, _paths))
109
110 def get_revnum(self):
111 return self[0]
112 revnum = property(get_revnum)
113
114 def get_author(self):
115 return self[1]
116 author = property(get_author)
117
118 def get_message(self):
119 return self[2]
120 message = property(get_message)
121
122 def get_date(self):
123 return self[3]
124 date = property(get_date)
125
126 def get_paths(self):
127 return self[4]
128 paths = property(get_paths)
106 129
107 def __str__(self): 130 def __str__(self):
108 return 'r%d by %s' % (self.revnum, self.author) 131 return 'r%d by %s' % (self.revnum, self.author)
109 132
110 _svntypes = { 133 _svntypes = {