diff --git a/getmystuph/backends/repos/git_svn.py b/getmystuph/backends/repos/git_svn.py index 5dfb60c..d22e896 100644 --- a/getmystuph/backends/repos/git_svn.py +++ b/getmystuph/backends/repos/git_svn.py @@ -1,130 +1,136 @@ # -*- coding: utf-8 -*- import os import re import git import svn.remote import logging from ... import colored from ... import color_code from ...utils import get_password from .git import RepoGit __author__ = "Nicolas Richart" __copyright__ = "Copyright (C) 2016, EPFL (Ecole Polytechnique Fédérale " \ "de Lausanne) - SCITAS (Scientific IT and Application " \ "Support)" __credits__ = ["Nicolas Richart"] __license__ = "BSD" __version__ = "0.1" __maintainer__ = "Nicolas Richart" __email__ = "nicolas.richart@epfl.ch" _logger = logging.getLogger(__name__) class RepoGitSvn(RepoGit): """This class handles the git svn""" def __enter__(self): super().__enter__() _logger.info('Getting repo {0} [{1}] from svn server'.format( self._in_repo.color_name(self._name), self._url)) _auth = {} if (re.match('^https://', self._url)): _auth['username'] = self._username _auth['password'] = get_password(self._in_repo.backend_name, self._in_repo.username, keyring=self._keyring) self._svn_client = svn.remote.RemoteClient(self._url, **_auth) return self def clone(self): _svn_logs = self._svn_client.log_default() _svn_authors = set() for l in _svn_logs: _svn_authors.add(l.author) _authors = {} for _a in _svn_authors: _user = self._user_db.user_by_in_login(_a) if _user is not None: _authors[_a] = _user _logger.debug( - 'Matching author {0} with "{name} <{email}>"'.format( + 'Matching author {0} with "{1}"'.format( colored(_a, color_code['user'], attrs=['bold']), - **_user)) + colored("{name} <{email}>".format(**_user), + color_code['user']))) else: _authors[_a] = {'name': _a, 'email': '{0}@{1}'.format( _a, self._in_repo.backend_name)} + _logger.debug( + 'No match found for {0}, replacing with "{1}"'.format( + colored(_a, color_code['user'], attrs=['bold']), + colored("{name} <{email}>".format(**_authors[_a]), + color_code['user']))) _svn_authors_file = os.path.join(self.working_dir, 'getmystuph.authors') with open(_svn_authors_file, 'w') as afh: afh.write( '\n'.join( ['{0} = {name} <{email}>'.format(l, **a) for l, a in _authors.items()])) _list = self._svn_client.list() _branches = False _trunk = False _tags = False for _file in _list: _path = _file.rstrip('/') if re.match(r'^branches$', _path): _branches = True if re.match(r'^trunk$', _path): _trunk = True if re.match(r'^tags$', _path): _tags = True _stdlayout = False if _branches and _tags and _trunk: _logger.debug('Detected svn standard layout for {0}'.format( self._in_repo.color_name(self._name))) _stdlayout = True _logger.info('Cloning repo {0} [{1}] in {2}'.format( self._in_repo.color_name(self._name), self._url, colored(self.working_dir, attrs=['bold']))) if not os.path.isdir(os.path.join(self.working_dir, '.git')): _git = git.Git(self.working_dir) _git.svn('clone', self._url, self.working_dir, preserve_empty_dirs=True, authors_file=_svn_authors_file, stdlayout=_stdlayout) super().clone() _tag_re = re.compile('origin/tags/(.*)') _trunk_re = re.compile('origin/trunk') for _ref in self._repo.refs: if type(_ref) == git.refs.remote.RemoteReference: _match = _tag_re.match(_ref.name) if _match is not None: _tag_name = _match.group(1) _logger.debug('Creating tag {0} from branch {1}'.format( _tag_name, _ref.name)) git.refs.tag.TagReference.create( self._repo, _tag_name, ref=_ref.name) _logger.debug('Deleting remote branch {1}'.format( _tag_name, _ref.name)) git.refs.remote.RemoteReference.delete( self._repo, _ref) elif _trunk_re.match(_ref.name): _logger.debug('Deleting trunk branch') git.refs.remote.RemoteReference.delete( self._repo, _ref)