bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
1 |
# Copyright (C) 2009 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
|
0.64.334
by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan. |
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
15 |
|
|
0.112.2
by Max Bowsher
Remove unused and unimplemented BranchMapper.bzr_to_git, and update docstring. |
16 |
"""An object that maps git ref names to bzr branch names. Note that it is not
|
17 |
used to map git ref names to bzr tag names."""
|
|
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
18 |
|
|
0.112.1
by Max Bowsher
Avoid spurious 'git-' being prefixed on branches whose names happen to end with 'trunk', |
19 |
import re |
20 |
||
21 |
||
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
22 |
class BranchMapper(object): |
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
23 |
_GIT_TRUNK_RE = re.compile(b'(?:git-)*trunk') |
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
24 |
|
|
0.112.3
by Max Bowsher
Make BranchMapper just map one name per call. |
25 |
def git_to_bzr(self, ref_name): |
26 |
"""Map a git reference name to a Bazaar branch name. |
|
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
27 |
"""
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
28 |
parts = ref_name.split(b'/') |
29 |
if parts[0] == b'refs': |
|
|
0.112.3
by Max Bowsher
Make BranchMapper just map one name per call. |
30 |
parts.pop(0) |
31 |
category = parts.pop(0) |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
32 |
if category == b'heads': |
33 |
git_name = b'/'.join(parts) |
|
|
0.112.3
by Max Bowsher
Make BranchMapper just map one name per call. |
34 |
bazaar_name = self._git_to_bzr_name(git_name) |
35 |
else: |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
36 |
if category == b'remotes' and parts[0] == b'origin': |
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
37 |
parts.pop(0) |
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
38 |
git_name = b'/'.join(parts) |
39 |
if category.endswith(b's'): |
|
|
0.112.3
by Max Bowsher
Make BranchMapper just map one name per call. |
40 |
category = category[:-1] |
41 |
name_no_ext = self._git_to_bzr_name(git_name) |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
42 |
bazaar_name = "%s.%s" % (name_no_ext, category.decode('ascii')) |
|
0.112.3
by Max Bowsher
Make BranchMapper just map one name per call. |
43 |
return bazaar_name |
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
44 |
|
45 |
def _git_to_bzr_name(self, git_name): |
|
|
0.112.1
by Max Bowsher
Avoid spurious 'git-' being prefixed on branches whose names happen to end with 'trunk', |
46 |
# Make a simple name more bzr-like, by mapping git 'master' to bzr 'trunk'.
|
47 |
# To avoid collision, map git 'trunk' to bzr 'git-trunk'. Likewise
|
|
48 |
# 'git-trunk' to 'git-git-trunk' and so on, such that the mapping is
|
|
49 |
# one-to-one in both directions.
|
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
50 |
if git_name == b'master': |
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
51 |
bazaar_name = 'trunk' |
|
0.112.1
by Max Bowsher
Avoid spurious 'git-' being prefixed on branches whose names happen to end with 'trunk', |
52 |
elif self._GIT_TRUNK_RE.match(git_name): |
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
53 |
bazaar_name = 'git-%s' % (git_name.decode('utf-8'),) |
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
54 |
else: |
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
55 |
bazaar_name = git_name.decode('utf-8') |
|
0.82.1
by Ian Clatworthy
nicer and round-trippable mapping of git ref names to bzr branch names |
56 |
return bazaar_name |