Rev 5559: We need to iterate until all refs are resolved. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Feb 4 15:53:08 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5559
revision-id: v.ladeuil+lp at free.fr-20110204155308-f2casopj3orsxn48
parent: v.ladeuil+lp at free.fr-20110204154832-l0d43q84i15fg32x
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: interpolate
timestamp: Fri 2011-02-04 16:53:08 +0100
message:
  We need to iterate until all refs are resolved.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-02-04 15:48:32 +0000
+++ b/bzrlib/config.py	2011-02-04 15:53:08 +0000
@@ -156,24 +156,30 @@
             # for '{bar{baz}}' we will get '{baz}'
             self.option_ref_re = re.compile('({[^{}]+})')
         result = string
-        is_ref = False
-        chunks = []
-        import pdb; pdb.set_trace()
-        # Split will isolate refs so that every other chunk is a ref
-        for chunk in self.option_ref_re.split(result):
-            if not is_ref:
-                chunks.append(chunk)
-                is_ref = True
-            else:
-                name = chunk[1:-1]
-                if name in ref_stack:
-                    raise errors.InterpolationLoop(string, ref_stack)
-                ref_stack.append(name)
-                value = self._interpolate_option(name, env, ref_stack)
-                raw_chunks.append(value)
-                ref_stack.pop()
-                is_ref = False
-        result = ''.join(chunks)
+        # We need to iterate until no more refs appear ({{foo}} will need two
+        # iterations for example).
+        while True:
+            is_ref = False
+            raw_chunks = self.option_ref_re.split(result)
+            if len(raw_chunks) == 1:
+                # Shorcut the trivial case: no refs
+                return result
+            chunks = []
+            # Split will isolate refs so that every other chunk is a ref
+            for chunk in raw_chunks:
+                if not is_ref:
+                    chunks.append(chunk)
+                    is_ref = True
+                else:
+                    name = chunk[1:-1]
+                    if name in ref_stack:
+                        raise errors.InterpolationLoop(string, ref_stack)
+                    ref_stack.append(name)
+                    value = self._interpolate_option(name, env, ref_stack)
+                    chunks.append(value)
+                    ref_stack.pop()
+                    is_ref = False
+            result = ''.join(chunks)
         return result
 
     def _interpolate_option(self, name, env, ref_stack):



More information about the bazaar-commits mailing list