Rev 526: Some initial work converting svn:ignore to a .bzrignore file. in file:///data/jelmer/bzr-svn/ignore/

Jelmer Vernooij jelmer at samba.org
Thu Jul 12 15:23:30 BST 2007


At file:///data/jelmer/bzr-svn/ignore/

------------------------------------------------------------
revno: 526
revision-id: jelmer at samba.org-20070712142329-jc848i9bkgg8eq9x
parent: jelmer at samba.org-20070712130714-yeyc40asj743ygci
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: ignore
timestamp: Thu 2007-07-12 17:23:29 +0300
message:
  Some initial work converting svn:ignore to a .bzrignore file.
modified:
  mapping.txt                    mapping.txt-20060625151311-9ghaqrm71ajq593n-1
  tests/test_workingtree.py      test_workingtree.py-20060622191524-0di7bc3q1ckdbybb-1
  workingtree.py                 workingtree.py-20060306120941-b083cb0fdd4a69de
=== modified file 'mapping.txt'
--- a/mapping.txt	2007-07-08 14:13:53 +0000
+++ b/mapping.txt	2007-07-12 14:23:29 +0000
@@ -7,6 +7,7 @@
 Updated January 2007.
 Updated February 2007.
 Updated June 2007.
+Updated July 2007.
 
 ============
 Branch paths
@@ -150,7 +151,14 @@
 
 "svn:executable" is mapped to bzr's executable bit. 
 
-"svn:ignore" is currently ignored.
+A fake .bzrignore file is generated containing the contents of the "svn:ignore"
+properties. If a .bzrignore file already exists in the tree, 
+the file already in the tree is used. 
+
+The .bzrignore file contains the directories in which the ignores are 
+set, ordered alphabetically by directory path. 
+
+Ignores are only recognized on directories.
 
 "svn:mime-type" is currently ignored.
 

=== modified file 'tests/test_workingtree.py'
--- a/tests/test_workingtree.py	2007-07-12 10:08:27 +0000
+++ b/tests/test_workingtree.py	2007-07-12 14:23:29 +0000
@@ -19,6 +19,7 @@
 from bzrlib.bzrdir import BzrDir
 from bzrlib.errors import NoSuchFile
 from bzrlib.inventory import Inventory
+from bzrlib.tests import TestCase
 from bzrlib.trace import mutter
 from bzrlib.workingtree import WorkingTree
 
@@ -31,6 +32,7 @@
 from repository import MAPPING_VERSION
 from transport import svn_config
 from tests import TestCaseWithSubversionRepository, RENAMES
+from workingtree import generate_ignore_list
 
 class TestWorkingTree(TestCaseWithSubversionRepository):
     def test_add_duplicate(self):
@@ -612,3 +614,19 @@
         tree.commit("message")
         self.assertEqual(None, tree.branch.nick)
 
+
+class IgnoreListTests(TestCase):
+    def test_empty(self):
+        self.assertEquals([], generate_ignore_list({}))
+
+    def test_simple(self):
+        self.assertEquals(["./twin/peaks"], 
+                generate_ignore_list({"twin": "peaks"}))
+
+    def test_toplevel(self):
+        self.assertEquals(["./twin*"], 
+                generate_ignore_list({"": "twin*"}))
+
+    def test_multiple(self):
+        self.assertEquals(["./twin*", "./twin/peaks"], 
+                generate_ignore_list({"twin": "peaks", "": "twin*"}))

=== modified file 'workingtree.py'
--- a/workingtree.py	2007-07-12 10:08:27 +0000
+++ b/workingtree.py	2007-07-12 14:23:29 +0000
@@ -53,6 +53,20 @@
 from errors import NoCheckoutSupport
 from format import get_rich_root_format
 
+def generate_ignore_list(ignore_map):
+    """Create a list of ignores, ordered by directory.
+    
+    :param ignore_map: Dictionary with paths as keys, patterns as values.
+    :return: list of ignores
+    """
+    ignores = []
+    keys = ignore_map.keys()
+    keys.sort()
+    for k in keys:
+        ignores.append("./" + os.path.join(k.strip("/"), ignore_map[k].strip("/")))
+    return ignores
+
+
 class WorkingTreeInconsistent(BzrError):
     _fmt = """Working copy is in inconsistent state (%(min_revnum)d:%(max_revnum)d)"""
 
@@ -108,18 +122,21 @@
         ignores = set([svn.wc.get_adm_dir()])
         ignores.update(svn.wc.get_default_ignores(svn_config))
 
+        ignore_map = {}
+
         def dir_add(wc, prefix):
             ignorestr = svn.wc.prop_get(svn.core.SVN_PROP_IGNORE, 
                                         self.abspath(prefix).rstrip("/"), wc)
             if ignorestr is not None:
-                for pat in ignorestr.splitlines():
-                    ignores.add("./"+os.path.join(prefix, pat))
+                assert not ignore_map.has_key(prefix)
+                ignore_map[prefix] = ignorestr
 
             entries = svn.wc.entries_read(wc, False)
             for entry in entries:
                 if entry == "":
                     continue
 
+                # Ignore ignores on things that aren't directories
                 if entries[entry].kind != svn.core.svn_node_dir:
                     continue
 
@@ -138,6 +155,8 @@
         finally:
             svn.wc.adm_close(wc)
 
+        set.extend(generate_ignore_list(ignore_map))
+
         return ignores
 
     def _write_inventory(self, inv):




More information about the bazaar-commits mailing list