~bzr-pqm/bzr/2.2

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Patch Queue Manager
  • Date: 2012-03-28 01:54:43 UTC
  • mfrom: (4797.85.12 2.2-feature-flags)
  • Revision ID: pqm@pqm.ubuntu.com-20120328015443-eyed372ro7kc7yl6
(jelmer) Add basic support for feature flags. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    registry,
87
87
    symbol_versioning,
88
88
    )
89
 
    
90
 
    
 
89
 
 
90
 
 
91
def extract_format_string(text):
 
92
    """Read a format string from a file.
 
93
 
 
94
    The first line is returned. The other lines can contain
 
95
    optional features. An exception is raised when a
 
96
    required feature is present.
 
97
    """
 
98
    lines = text.splitlines(True)
 
99
    try:
 
100
        firstline = lines.pop(0)
 
101
    except IndexError:
 
102
        raise errors.UnknownFormatError(format=text, kind='')
 
103
    for lineno, line in enumerate(lines):
 
104
        try:
 
105
            (necessity, feature) = line.split(" ", 1)
 
106
        except ValueError:
 
107
            raise errors.ParseFormatError(lineno=lineno+2,
 
108
                line=line, text=text)
 
109
        else:
 
110
            if necessity == "optional":
 
111
                mutter("Ignoring optional feature %s", feature)
 
112
            else:
 
113
                raise errors.MissingFeature(feature)
 
114
    return firstline
 
115
 
 
116
 
91
117
class ControlComponent(object):
92
118
    """Abstract base class for control directory components.
93
119
    
1959
1985
            format_string = transport.get_bytes(".bzr/branch-format")
1960
1986
        except errors.NoSuchFile:
1961
1987
            raise errors.NotBranchError(path=transport.base)
 
1988
        format_string = extract_format_string(format_string)
 
1989
 
1962
1990
        try:
1963
1991
            return klass._formats[format_string]
1964
1992
        except KeyError: