Rev 3947: Multi-glob rules (Marius Kruger) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jan 20 03:21:40 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3947
revision-id: pqm at pqm.ubuntu.com-20090120032136-alahvfk4g7y8iczn
parent: pqm at pqm.ubuntu.com-20090119130916-zr1sbw0hn7rbip3y
parent: ian.clatworthy at canonical.com-20090120021235-n8bd5kzz3s624aq5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-01-20 03:21:36 +0000
message:
  Multi-glob rules (Marius Kruger)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/help_topics/en/rules.txt rules.txt-20080516063844-ghr5l6pvvrhiycun-1
  bzrlib/rules.py                properties.py-20080506032617-9k06uqalkf09ck0z-1
  bzrlib/tests/test_rules.py     test_properties.py-20080506033501-3p9kmuob25dho8xl-1
    ------------------------------------------------------------
    revno: 3946.1.1
    revision-id: ian.clatworthy at canonical.com-20090120021235-n8bd5kzz3s624aq5
    parent: pqm at pqm.ubuntu.com-20090119130916-zr1sbw0hn7rbip3y
    parent: amanic at gmail.com-20090118014815-hmowk5wx102lwquz
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: ianc-integration
    timestamp: Tue 2009-01-20 12:12:35 +1000
    message:
      Multi-glob rules (Marius Kruger)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/help_topics/en/rules.txt rules.txt-20080516063844-ghr5l6pvvrhiycun-1
      bzrlib/rules.py                properties.py-20080506032617-9k06uqalkf09ck0z-1
      bzrlib/tests/test_rules.py     test_properties.py-20080506033501-3p9kmuob25dho8xl-1
    ------------------------------------------------------------
    revno: 3943.3.4
    revision-id: amanic at gmail.com-20090118014815-hmowk5wx102lwquz
    parent: amanic at gmail.com-20090118011839-qanqndkfqrkek7e1
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.multi-glob-rules
    timestamp: Sun 2009-01-18 03:48:15 +0200
    message:
      add NEWS
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3943.3.3
    revision-id: amanic at gmail.com-20090118011839-qanqndkfqrkek7e1
    parent: amanic at gmail.com-20090118010721-2s62eobbgk51qqn9
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.multi-glob-rules
    timestamp: Sun 2009-01-18 03:18:39 +0200
    message:
      update rules topic
    modified:
      bzrlib/help_topics/en/rules.txt rules.txt-20080516063844-ghr5l6pvvrhiycun-1
    ------------------------------------------------------------
    revno: 3943.3.2
    revision-id: amanic at gmail.com-20090118010721-2s62eobbgk51qqn9
    parent: amanic at gmail.com-20090118004202-nh1b5bpr91ty2rxq
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.multi-glob-rules
    timestamp: Sun 2009-01-18 03:07:21 +0200
    message:
      actually support quoting the patterns as the docs suggest
    modified:
      bzrlib/rules.py                properties.py-20080506032617-9k06uqalkf09ck0z-1
      bzrlib/tests/test_rules.py     test_properties.py-20080506033501-3p9kmuob25dho8xl-1
    ------------------------------------------------------------
    revno: 3943.3.1
    revision-id: amanic at gmail.com-20090118004202-nh1b5bpr91ty2rxq
    parent: pqm at pqm.ubuntu.com-20090115233242-4bxyn4zcj2a0ksfk
    committer: Marius Kruger <amanic at gmail.com>
    branch nick: bzr.multi-glob-rules
    timestamp: Sun 2009-01-18 02:42:02 +0200
    message:
      add test and support for multi-glob rules
    modified:
      bzrlib/rules.py                properties.py-20080506032617-9k06uqalkf09ck0z-1
      bzrlib/tests/test_rules.py     test_properties.py-20080506033501-3p9kmuob25dho8xl-1
=== modified file 'NEWS'
--- a/NEWS	2009-01-15 22:51:27 +0000
+++ b/NEWS	2009-01-18 01:48:15 +0000
@@ -29,6 +29,9 @@
     * ``bzr init`` will now print a little less verbose output.
       (Marius Kruger)
 
+    * Rule-based preferences can now accept multiple patterns for a set of
+      rules.  (Marius Kruger)
+
   BUG FIXES:
 
     * ``bzr log FILE`` now correctly shows mainline revisions merging

=== modified file 'bzrlib/help_topics/en/rules.txt'
--- a/bzrlib/help_topics/en/rules.txt	2008-08-14 17:25:43 +0000
+++ b/bzrlib/help_topics/en/rules.txt	2009-01-20 02:12:35 +0000
@@ -6,12 +6,12 @@
 
 Rules are defined in ini file format where the sections are file glob
 patterns and the contents of each section are the preferences for files
-matching that pattern. For example::
+matching that pattern(s). For example::
 
     [name *.bat]
     eol = dos
 
-    [name *.html]
+    [name *.html *.xml]
     keywords = escape
 
 Preferences like these are useful for commands and plugins wishing to
@@ -32,5 +32,5 @@
 the top of the file. Rule patterns use exactly the same conventions
 as ignore patterns. See ``bzr help patterns`` for details.
 
-Note: Patterns containing square brackets should be surrounded in
-quotes to ensure they are corrected parsed.
+Note: Patterns containing square brackets or spaces should be
+surrounded in quotes to ensure they are corrected parsed.

=== modified file 'bzrlib/rules.py'
--- a/bzrlib/rules.py	2008-07-18 08:40:57 +0000
+++ b/bzrlib/rules.py	2009-01-20 02:12:35 +0000
@@ -21,6 +21,7 @@
 
 from bzrlib import (
     config,
+    commands,
     errors,
     globbing,
     osutils,
@@ -73,8 +74,15 @@
         options = {'encoding': 'utf-8'}
         self._cfg = configobj.ConfigObj(inifile, options=options)
         sections = self._cfg.keys()
-        patterns = [s[FILE_PREFS_PREFIX_LEN:] for s in sections
-            if s.startswith(FILE_PREFS_PREFIX)]
+        patterns = []
+        self.pattern_to_section = {}
+        for s in sections:
+            if s.startswith(FILE_PREFS_PREFIX):
+                file_patterns = commands.shlex_split_unicode(
+                    s[FILE_PREFS_PREFIX_LEN:])
+                patterns.extend(file_patterns)
+                for fp in file_patterns:
+                    self.pattern_to_section[fp] = s
         if len(patterns) < len(sections):
             unknowns = [s for s in sections
                 if not s.startswith(FILE_PREFS_PREFIX)]
@@ -92,7 +100,7 @@
         if pat is None:
             return ()
         else:
-            all = self._cfg[FILE_PREFS_PREFIX + pat]
+            all = self._cfg[self.pattern_to_section[pat]]
             return tuple(all.items())
 
     def get_selected_items(self, path, names):
@@ -103,7 +111,7 @@
         if pat is None:
             return ()
         else:
-            all = self._cfg[FILE_PREFS_PREFIX + pat]
+            all = self._cfg[self.pattern_to_section[pat]]
             return tuple((k, all.get(k)) for k in names)
 
 

=== modified file 'bzrlib/tests/test_rules.py'
--- a/bzrlib/tests/test_rules.py	2008-07-18 08:40:57 +0000
+++ b/bzrlib/tests/test_rules.py	2009-01-18 01:07:21 +0000
@@ -62,6 +62,19 @@
         self.assertEquals((('foo', 'bar'),),
             rs.get_selected_items('a.txt', ['foo']))
 
+    def test_get_items_from_multiple_glob_match(self):
+        rs = self.make_searcher(
+            "[name *.txt *.py 'x x' \"y y\"]\nfoo=bar\na=True\n")
+        self.assertEquals((), rs.get_items('NEWS'))
+        self.assertEquals((('foo', 'bar'), ('a', 'True')),
+            rs.get_items('a.py'))
+        self.assertEquals((('foo', 'bar'), ('a', 'True')),
+            rs.get_items('a.txt'))
+        self.assertEquals((('foo', 'bar'), ('a', 'True')),
+            rs.get_items('x x'))
+        self.assertEquals((('foo', 'bar'), ('a', 'True')),
+            rs.get_items('y y'))
+
     def test_get_items_pathname_match(self):
         rs = self.make_searcher("[name ./a.txt]\nfoo=baz\n")
         self.assertEquals((('foo', 'baz'),),




More information about the bazaar-commits mailing list