51
49
:return: the BzrDirFormat or None if no matches were found.
53
51
# Based on code from breezy/info.py ...
52
from ... import bzrdir
54
53
repo_format = repo._format
56
55
non_aliases = set(controldir.format_registry.keys())
57
56
non_aliases.difference_update(controldir.format_registry.aliases())
58
57
for key in non_aliases:
59
format = controldir.format_registry.make_controldir(key)
58
format = controldir.format_registry.make_bzrdir(key)
60
59
# LocalGitBzrDirFormat has no repository_format
61
60
if hasattr(format, "repository_format"):
62
61
if format.repository_format == repo_format:
94
93
if os.path.exists(location):
95
94
contents = os.listdir(location)
97
errors.CommandError("Destination must have a .bzr directory, "
98
" not yet exist or be empty - files found in %s" % (location,))
96
errors.BzrCommandError("Destination must have a .bzr directory, "
97
" not yet exist or be empty - files found in %s" % (location,))
101
100
os.mkdir(location)
102
except IOError as ex:
103
raise errors.CommandError(
104
"Unable to create %s: %s" % (location, ex))
102
errors.BzrCommandError("Unable to create %s: %s" %
106
105
# Create a repository for the nominated format.
107
106
trace.note("Creating destination repository ...")
108
107
if format is None:
109
format = controldir.format_registry.make_controldir('default')
108
format = controldir.format_registry.make_bzrdir('default')
110
109
to_transport = transport.get_transport(location)
111
110
to_transport.ensure_base()
112
111
control = format.initialize_on_transport(to_transport)
113
112
repo = control.create_repository(shared=True)
115
114
from ...info import show_bzrdir_info
116
show_bzrdir_info(repo.controldir, verbose=0)
115
show_bzrdir_info(repo.bzrdir, verbose=0)
120
119
def kind_to_mode(kind, executable):
121
120
if kind == "file":
122
if executable is True:
123
return stat.S_IFREG | 0o755
124
elif executable is False:
125
return stat.S_IFREG | 0o644
121
if executable == True:
122
return stat.S_IFREG | 0755
123
elif executable == False:
124
return stat.S_IFREG | 0644
127
126
raise AssertionError("Executable %r invalid" % executable)
128
127
elif kind == "symlink":
130
129
elif kind == "directory":
131
130
return stat.S_IFDIR
132
131
elif kind == "tree-reference":
135
134
raise AssertionError("Unknown file kind '%s'" % kind)
138
137
def mode_to_kind(mode):
139
138
# Note: Output from git-fast-export slightly different to spec
140
if mode in (0o644, 0o100644):
139
if mode in (0644, 0100644):
141
140
return 'file', False
142
elif mode in (0o755, 0o100755):
141
elif mode in (0755, 0100755):
143
142
return 'file', True
144
elif mode == 0o040000:
143
elif mode == 0040000:
145
144
return 'directory', False
146
elif mode == 0o120000:
145
elif mode == 0120000:
147
146
return 'symlink', False
148
elif mode == 0o160000:
147
elif mode == 0160000:
149
148
return 'tree-reference', False
151
150
raise AssertionError("invalid mode %o" % mode)
180
def invert_dictset(d):
181
"""Invert a dictionary with keys matching a set of values, turned into lists."""
182
# Based on recipe from ASPN
184
for k, c in d.items():
186
keys = result.setdefault(v, [])
192
"""Invert a dictionary with keys matching each value turned into a list."""
193
# Based on recipe from ASPN
195
for k, v in d.items():
196
keys = result.setdefault(v, [])