~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 16:28:30 UTC
  • mto: This revision was merged to the branch mainline in revision 6512.
  • Revision ID: v.ladeuil+lp@free.fr-20120313162830-83ekrd4ghqru0whh
Save branch config options only during the final unlock

Show diffs side-by-side

added added

removed removed

Lines of Context:
2965
2965
            # Report concurrent updates in an ad-hoc way. This should only
2966
2966
            # occurs when different processes try to update the same option
2967
2967
            # which is not supported (as in: the config framework is not meant
2968
 
            # to be used a sharing mechanism).
 
2968
            # to be used as a sharing mechanism).
2969
2969
            if expected != reloaded:
2970
2970
                if actual is _DeletedOption:
2971
2971
                    actual = '<DELETED>'
2991
2991
    mutable_section_class = MutableSection
2992
2992
 
2993
2993
    def __init__(self):
2994
 
        # Which sections need to be saved
2995
 
        self.dirty_sections = []
 
2994
        # Which sections need to be saved (by section id)
 
2995
        self.dirty_sections = {}
2996
2996
 
2997
2997
    def is_loaded(self):
2998
2998
        """Returns True if the Store has been loaded.
3041
3041
        raise NotImplementedError(self.save)
3042
3042
 
3043
3043
    def _need_saving(self):
3044
 
        for s in self.dirty_sections:
 
3044
        for s in self.dirty_sections.values():
3045
3045
            if s.orig:
3046
3046
                # At least one dirty section contains a modification
3047
3047
                return True
3061
3061
        # get_mutable_section() call below.
3062
3062
        self.unload()
3063
3063
        # Apply the changes from the preserved dirty sections
3064
 
        for dirty in dirty_sections:
3065
 
            clean = self.get_mutable_section(dirty.id)
 
3064
        for section_id, dirty in dirty_sections.iteritems():
 
3065
            clean = self.get_mutable_section(section_id)
3066
3066
            clean.apply_changes(dirty, self)
3067
3067
        # Everything is clean now
3068
 
        self.dirty_sections = []
 
3068
        self.dirty_sections = {}
3069
3069
 
3070
3070
    def save_changes(self):
3071
3071
        """Saves the Store to persistent storage if changes occurred.
3151
3151
 
3152
3152
    def unload(self):
3153
3153
        self._config_obj = None
3154
 
        self.dirty_sections = []
 
3154
        self.dirty_sections = {}
3155
3155
 
3156
3156
    def _load_content(self):
3157
3157
        """Load the config file bytes.
3205
3205
        if not self._need_saving():
3206
3206
            return
3207
3207
        # Preserve the current version
3208
 
        current = self._config_obj
3209
 
        dirty_sections = list(self.dirty_sections)
 
3208
        dirty_sections = dict(self.dirty_sections.items())
3210
3209
        self.apply_changes(dirty_sections)
3211
3210
        # Save to the persistent storage
3212
3211
        self.save()
3247
3246
        except errors.NoSuchFile:
3248
3247
            # The file doesn't exist, let's pretend it was empty
3249
3248
            self._load_from_string('')
 
3249
        if section_id in self.dirty_sections:
 
3250
            # We already created a mutable section for this id
 
3251
            return self.dirty_sections[section_id]
3250
3252
        if section_id is None:
3251
3253
            section = self._config_obj
3252
3254
        else:
3253
3255
            section = self._config_obj.setdefault(section_id, {})
3254
3256
        mutable_section = self.mutable_section_class(section_id, section)
3255
3257
        # All mutable sections can become dirty
3256
 
        self.dirty_sections.append(mutable_section)
 
3258
        self.dirty_sections[section_id] = mutable_section
3257
3259
        return mutable_section
3258
3260
 
3259
3261
    def quote(self, value):