From d85a19b9e65213ca5c91ec8982cf97eeee96061f Mon Sep 17 00:00:00 2001
From: jim <jim@62d5b8a3-27da-0310-9561-8e5933582275>
Date: Mon, 10 Jul 2006 10:25:29 +0000
Subject: [PATCH] Fixed bug in handling saved option values with a single
 leading or trailing newline.

git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@69068 62d5b8a3-27da-0310-9561-8e5933582275
---
 src/zc/buildout/buildout.py | 25 ++++++++++++++++++++++---
 src/zc/buildout/tests.py    |  9 +++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/zc/buildout/buildout.py b/src/zc/buildout/buildout.py
index b147818..b56d1e6 100644
--- a/src/zc/buildout/buildout.py
+++ b/src/zc/buildout/buildout.py
@@ -242,8 +242,22 @@ class Buildout(dict):
                 if part in install_parts:
                     old_options = installed_part_options[part].copy()
                     old_options.pop('__buildout_installed__')
-                    if old_options == self.get(part):
+                    new_options = self.get(part)
+                    if old_options == new_options:
                         continue
+                    for k in old_options:
+                        if k not in new_options:
+                            self._logger.debug("Part: %s, dropped option %s",
+                                               part, k)
+                        elif old_options[k] != new_options[k]:
+                            self._logger.debug(
+                                "Part: %s, option %s, %r != %r",
+                                part, k, new_options[k], old_options[k],
+                                )
+                    for k in new_options:
+                        if k not in old_options:
+                            self._logger.debug("Part: %s, new option %s",
+                                               part, k)
                 elif not uninstall_missing:
                     continue
 
@@ -462,8 +476,9 @@ class Buildout(dict):
                 _save_options(section, self[section], sys.stdout)
             print    
 
-_spacey_nl = re.compile('^[ \t\r\f\v]+'
-                        '|''[ \t\r\f\v]*\n[ \t\r\f\v\n]*'
+_spacey_nl = re.compile('[ \t\r\f\v]*\n[ \t\r\f\v\n]*'
+                        '|'
+                        '^[ \t\r\f\v]+'
                         '|'
                         '[ \t\r\f\v]+$'
                         )
@@ -497,6 +512,10 @@ def _save_options(section, options, f):
     for option, value in items:
         value = value.replace('%', '%%')
         value = _spacey_nl.sub(_quote_spacey_nl, value)
+        if value.startswith('\n\t'):
+            value = '%(__buildout_space_n__)s' + value[2:]
+        if value.endswith('\n\t'):
+            value = value[:-2] + '%(__buildout_space_n__)s'
         print >>f, option, '=', value
             
     
diff --git a/src/zc/buildout/tests.py b/src/zc/buildout/tests.py
index 5c0260e..534eaf7 100644
--- a/src/zc/buildout/tests.py
+++ b/src/zc/buildout/tests.py
@@ -80,6 +80,15 @@ def test_comparing_saved_options_with_funny_characters():
     ...
     ... </zodb>  
     ...      \"\"\"
+    ...         options['debug1'] = \"\"\"
+    ... <zodb>
+    ...
+    ...   <filestorage>
+    ...     path foo
+    ...   </filestorage>
+    ...
+    ... </zodb>  
+    ... \"\"\"
     ...         options['debug2'] = '  x  '
     ...         options['debug3'] = '42'
     ...         options['format'] = '%3d'
-- 
2.30.9