/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/fastimport/helpers.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""Miscellaneous useful stuff."""
17
17
 
 
18
from __future__ import absolute_import
 
19
 
18
20
import stat
19
21
 
20
22
from ... import (
52
54
    """
53
55
    # Based on code from breezy/info.py ...
54
56
    repo_format = repo._format
55
 
    candidates = []
 
57
    candidates  = []
56
58
    non_aliases = set(controldir.format_registry.keys())
57
59
    non_aliases.difference_update(controldir.format_registry.aliases())
58
60
    for key in non_aliases:
94
96
    if os.path.exists(location):
95
97
        contents = os.listdir(location)
96
98
        if contents:
97
 
            errors.CommandError("Destination must have a .bzr directory, "
98
 
                                   " not yet exist or be empty - files found in %s" % (location,))
 
99
            errors.BzrCommandError("Destination must have a .bzr directory, "
 
100
                " not yet exist or be empty - files found in %s" % (location,))
99
101
    else:
100
102
        try:
101
103
            os.mkdir(location)
102
 
        except IOError as ex:
103
 
            raise errors.CommandError(
104
 
                "Unable to create %s: %s" % (location, ex))
 
104
        except IOError, ex:
 
105
            errors.BzrCommandError("Unable to create %s: %s" %
 
106
                (location, ex))
105
107
 
106
108
    # Create a repository for the nominated format.
107
109
    trace.note("Creating destination repository ...")
119
121
 
120
122
def kind_to_mode(kind, executable):
121
123
    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
 
124
        if executable == True:
 
125
            return stat.S_IFREG | 0755
 
126
        elif executable == False:
 
127
            return stat.S_IFREG | 0644
126
128
        else:
127
129
            raise AssertionError("Executable %r invalid" % executable)
128
130
    elif kind == "symlink":
130
132
    elif kind == "directory":
131
133
        return stat.S_IFDIR
132
134
    elif kind == "tree-reference":
133
 
        return 0o160000
 
135
        return 0160000
134
136
    else:
135
137
        raise AssertionError("Unknown file kind '%s'" % kind)
136
138
 
137
139
 
138
140
def mode_to_kind(mode):
139
141
    # Note: Output from git-fast-export slightly different to spec
140
 
    if mode in (0o644, 0o100644):
 
142
    if mode in (0644, 0100644):
141
143
        return 'file', False
142
 
    elif mode in (0o755, 0o100755):
 
144
    elif mode in (0755, 0100755):
143
145
        return 'file', True
144
 
    elif mode == 0o040000:
 
146
    elif mode == 0040000:
145
147
        return 'directory', False
146
 
    elif mode == 0o120000:
 
148
    elif mode == 0120000:
147
149
        return 'symlink', False
148
 
    elif mode == 0o160000:
 
150
    elif mode == 0160000:
149
151
        return 'tree-reference', False
150
152
    else:
151
153
        raise AssertionError("invalid mode %o" % mode)
176
178
        return single
177
179
    else:
178
180
        return plural
 
181
 
 
182
 
 
183
def invert_dictset(d):
 
184
    """Invert a dictionary with keys matching a set of values, turned into lists."""
 
185
    # Based on recipe from ASPN
 
186
    result = {}
 
187
    for k, c in d.items():
 
188
        for v in c:
 
189
            keys = result.setdefault(v, [])
 
190
            keys.append(k)
 
191
    return result
 
192
 
 
193
 
 
194
def invert_dict(d):
 
195
    """Invert a dictionary with keys matching each value turned into a list."""
 
196
    # Based on recipe from ASPN
 
197
    result = {}
 
198
    for k, v in d.items():
 
199
        keys = result.setdefault(v, [])
 
200
        keys.append(k)
 
201
    return result
 
202
 
 
203