1 # Copyright (C) 2009 Canonical Ltd
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 """An object that maps bzr branch names <-> git ref names."""
20 class BranchMapper(object):
22 def git_to_bzr(self, ref_names):
23 """Get the mapping from git reference names to Bazaar branch names.
25 :return: a dictionary with git reference names as keys and
26 the Bazaar branch names as values.
29 for ref_name in sorted(ref_names):
30 parts = ref_name.split('/')
31 if parts[0] == 'refs':
33 category = parts.pop(0)
34 if category == 'heads':
35 bazaar_name = self._git_to_bzr_name(parts[-1])
37 if category.endswith('s'):
38 category = category[:-1]
39 name_no_ext = self._git_to_bzr_name(parts[-1])
40 bazaar_name = "%s.%s" % (name_no_ext, category)
41 bazaar_names[ref_name] = bazaar_name
44 def _git_to_bzr_name(self, git_name):
45 if git_name == 'master':
47 elif git_name.endswith('trunk'):
48 bazaar_name = 'git-%s' % (git_name,)
50 bazaar_name = git_name
53 def bzr_to_git(self, branch_names):
54 """Get the mapping from Bazaar branch names to git reference names.
56 :return: a dictionary with Bazaar branch names as keys and
57 the git reference names as values.
59 raise NotImplementedError(self.bzr_to_git)