Rev 6509: Add news entry and cleanup in file:///home/vila/src/bzr/bugs/832042-shared-stores/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Aug 3 12:22:26 UTC 2012


At file:///home/vila/src/bzr/bugs/832042-shared-stores/

------------------------------------------------------------
revno: 6509
revision-id: v.ladeuil+lp at free.fr-20120803122225-mkqsnkvppsotdbm9
parent: v.ladeuil+lp at free.fr-20120803112355-3fh78wck6i12vv1h
fixes bug: https://launchpad.net/bugs/832042
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 832042-shared-stores
timestamp: Fri 2012-08-03 14:22:25 +0200
message:
  Add news entry and cleanup
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2012-07-31 13:01:03 +0000
+++ b/bzrlib/config.py	2012-08-03 12:22:25 +0000
@@ -3418,45 +3418,6 @@
         self.id = 'control'
 
 
-# FIXME: _shared_stores should be an attribute of a library state once a
-# library_state object is always available.
-_shared_stores = {}
-_once = True
-def get_shared_store(store, state=None):
-    """Get a known shared store.
-
-    Store urls uniquely identify them and are used to ensure a single copy is
-    shared across all users.
-
-    :param store: The store known to the caller.
-
-    :param state: The library state where the known stores are kept.
-
-    :returns: The store received if it's not a known one, an already known
-        otherwise.
-    """
-    if state is None:
-        global _once
-        stores = _shared_stores
-        def save_config_changes():
-            for k, store in stores.iteritems():
-                store.save_changes()
-        if _once:
-            # FIXME: Ugly hack waiting for library_state to always be
-            # available. -- vila 20120731
-            import atexit
-            atexit.register(save_config_changes)
-            _once = False
-    else:
-        stores = states.config_stores
-    url = store.external_url()
-    try:
-        return stores[url]
-    except KeyError:
-        stores[url] = store
-        return store
-
-
 class SectionMatcher(object):
     """Select sections into a given Store.
 
@@ -3662,6 +3623,10 @@
         yield is_ref, chunk
         is_ref = not is_ref
 
+# FIXME: _shared_stores should be an attribute of a library state once a
+# library_state object is always available.
+_shared_stores = {}
+_shared_stores_at_exit_installed = False
 
 class Stack(object):
     """A stack of configurations where an option can be defined"""
@@ -3861,6 +3826,42 @@
             return bzrlib.global_state.cmdline_overrides.get_sections()
         return []
 
+    def get_shared_store(self, store, state=None):
+        """Get a known shared store.
+
+        Store urls uniquely identify them and are used to ensure a single copy
+        is shared across all users.
+
+        :param store: The store known to the caller.
+
+        :param state: The library state where the known stores are kept.
+
+        :returns: The store received if it's not a known one, an already known
+            otherwise.
+        """
+        if state is None:
+            state = bzrlib.global_state
+        if state is None:
+            global _shared_stores_at_exit_installed
+            stores = _shared_stores
+            def save_config_changes():
+                for k, store in stores.iteritems():
+                    store.save_changes()
+            if not _shared_stores_at_exit_installed:
+                # FIXME: Ugly hack waiting for library_state to always be
+                # available. -- vila 20120731
+                import atexit
+                atexit.register(save_config_changes)
+                _shared_stores_at_exit_installed = True
+        else:
+            stores = state.config_stores
+        url = store.external_url()
+        try:
+            return stores[url]
+        except KeyError:
+            stores[url] = store
+            return store
+
 
 class MemoryStack(Stack):
     """A configuration stack defined from a string.
@@ -3930,7 +3931,7 @@
     """
 
     def __init__(self):
-        gstore = get_shared_store(GlobalStore())
+        gstore = self.get_shared_store(GlobalStore())
         super(GlobalStack, self).__init__(
             [self._get_overrides,
              NameMatcher(gstore, 'DEFAULT').get_sections],
@@ -3959,11 +3960,10 @@
         """Make a new stack for a location and global configuration.
 
         :param location: A URL prefix to """
-        # FIXME: self._get_shared_store ?
-        lstore = get_shared_store(LocationStore())
+        lstore = self.get_shared_store(LocationStore())
         if location.startswith('file://'):
             location = urlutils.local_path_from_url(location)
-        gstore = get_shared_store(GlobalStore())
+        gstore = self.get_shared_store(GlobalStore())
         super(LocationStack, self).__init__(
             [self._get_overrides,
              LocationMatcher(lstore, location).get_sections,
@@ -3991,9 +3991,9 @@
     """
 
     def __init__(self, branch):
-        lstore = get_shared_store(LocationStore())
+        lstore = self.get_shared_store(LocationStore())
         bstore = branch._get_config_store()
-        gstore = get_shared_store(GlobalStore())
+        gstore = self.get_shared_store(GlobalStore())
         super(BranchStack, self).__init__(
             [self._get_overrides,
              LocationMatcher(lstore, branch.base).get_sections,

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-07-28 20:20:38 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-08-03 12:22:25 +0000
@@ -28,13 +28,17 @@
 Improvements
 ************
 
-``bzr lp-find-proposal`` now only cares about the revision-id that is
-specified, not the branch you use.  This was enabled by a new API call in
-Launchpad's web service.  (Aaron Bentley)
+* ``bzr lp-find-proposal`` now only cares about the revision-id that is
+  specified, not the branch you use.  This was enabled by a new API call in
+  Launchpad's web service.  (Aaron Bentley)
 
 * Implement authentication.conf password obfuscation, the password_encoding
   option can now be set to base64. (Florian Dorn)
 
+* Local configurations files (i.e. accessed on the local file system like
+  ``bazaar.conf`` and ``locations.conf``) are now shared, reducing the
+  number of IOs when querying a configuation option. (Vincent Ladeuil, #832042)
+
 Bug Fixes
 *********
 



More information about the bazaar-commits mailing list