~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

(jelmer) Add support for feature flags. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    )
75
75
 
76
76
 
 
77
def extract_format_string(text):
 
78
    """Read a format string from a file.
 
79
 
 
80
    The first line is returned. The other lines can contain
 
81
    optional features. An exception is raised when a
 
82
    required feature is present.
 
83
    """
 
84
    lines = text.splitlines(True)
 
85
    try:
 
86
        firstline = lines.pop(0)
 
87
    except IndexError:
 
88
        raise errors.UnknownFormatError(format=text, kind='')
 
89
    for lineno, line in enumerate(lines):
 
90
        try:
 
91
            (necessity, feature) = line.split(" ", 1)
 
92
        except ValueError:
 
93
            raise errors.ParseFormatError(lineno=lineno+2,
 
94
                line=line, text=text)
 
95
        else:
 
96
            if necessity == "optional":
 
97
                mutter("Ignoring optional feature %s", feature)
 
98
            else:
 
99
                raise errors.MissingFeature(feature)
 
100
    return firstline
 
101
 
 
102
 
77
103
class BzrDir(controldir.ControlDir):
78
104
    """A .bzr control diretory.
79
105
 
1344
1370
            format_string = transport.get_bytes(".bzr/branch-format")
1345
1371
        except errors.NoSuchFile:
1346
1372
            raise errors.NotBranchError(path=transport.base)
 
1373
        format_string = extract_format_string(format_string)
1347
1374
        try:
1348
1375
            return klass.formats.get(format_string)
1349
1376
        except KeyError: