mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 01:07:15 +03:00
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.
This commit is contained in:
parent
787d035e21
commit
81fbf8f323
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user