Rev 3371: Implement xml8 serializer (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Apr 17 08:55:45 BST 2008


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

------------------------------------------------------------
revno: 3371
revision-id:pqm at pqm.ubuntu.com-20080417075535-shpsll72xkrz5l3m
parent: pqm at pqm.ubuntu.com-20080416172809-mq3p3rm6q3vefyyz
parent: aaron at aaronbentley.com-20080417054953-qmgbyq600qjtm3ha
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-04-17 08:55:35 +0100
message:
  Implement xml8 serializer (abentley)
removed:
  bzrlib/xml6.py                 xml6.py-20060823042456-dbaaq4atrche7xy5-1
added:
  bzrlib/xml5.py                 xml5.py-20080328030717-t9guwinq8hom0ar3-1
  bzrlib/xml6.py                 xml6.py-20080327235607-1skmbg4o9cd1o636-1
renamed:
  bzrlib/xml5.py => bzrlib/xml8.py xml5.py-20050907032657-aac8f960815b66b1
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
  bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
  bzrlib/xml8.py                 xml5.py-20050907032657-aac8f960815b66b1
    ------------------------------------------------------------
    revno: 3311.3.8
    revision-id:aaron at aaronbentley.com-20080417054953-qmgbyq600qjtm3ha
    parent: aaron at aaronbentley.com-20080417054209-ows3p4lvlvhzymfg
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Thu 2008-04-17 01:49:53 -0400
    message:
      Updates from review
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/xml8.py                 xml5.py-20050907032657-aac8f960815b66b1
    ------------------------------------------------------------
    revno: 3311.3.7
    revision-id:aaron at aaronbentley.com-20080417054209-ows3p4lvlvhzymfg
    parent: aaron at aaronbentley.com-20080415042944-2o3o664x26507hej
    parent: pqm at pqm.ubuntu.com-20080416172809-mq3p3rm6q3vefyyz
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Thu 2008-04-17 01:42:09 -0400
    message:
      Merge from bzr.dev
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
      bzrlib/progress.py             progress.py-20050610070202-df9faaab791964c0
    ------------------------------------------------------------
    revno: 3311.3.6
    revision-id:aaron at aaronbentley.com-20080415042944-2o3o664x26507hej
    parent: aaron at aaronbentley.com-20080415042822-xl93i5se1kew3tlq
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Tue 2008-04-15 00:29:44 -0400
    message:
      PEP8 fix
    modified:
      bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
    ------------------------------------------------------------
    revno: 3311.3.5
    revision-id:aaron at aaronbentley.com-20080415042822-xl93i5se1kew3tlq
    parent: aaron at aaronbentley.com-20080328030947-57cfqi7to7k401wc
    parent: pqm at pqm.ubuntu.com-20080415030411-eywh0jseeq2mra0v
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Tue 2008-04-15 00:28:22 -0400
    message:
      Merge bzr.dev
    added:
      bzrlib/tests/test_mutabletree.py test_mutabletree.py-20080405014429-2v0cdi3re320p8db-1
      bzrlib/transport/nosmart.py    nosmart.py-20080402095843-6ib17idympwy1zkr-1
      doc/developers/integration.txt integration.txt-20080404022341-2lorxocp1in07zij-1
      doc/developers/plugin-api.txt  pluginapi.txt-20080229110225-q2j5y4agqhlkjn0s-1
      doc/developers/tortoise-strategy.txt tortoisestrategy.txt-20080403024510-2ahdqrvnwqrb5p5t-1
    renamed:
      bzrlib/tests/test_revisionnamespaces.py => bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzr                            bzr.py-20050313053754-5485f144c7006fa6
      bzrlib/annotate.py             annotate.py-20050922133147-7c60541d2614f022
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/bugtracker.py           bugtracker.py-20070410073305-vu1vu1qosjurg8kb-1
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/doc/api/__init__.py     __init__.py-20051224020744-7b87d590843855bc
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/fetch.py                fetch.py-20050818234941-26fea6105696365d
      bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/lockable_files.py       control_files.py-20051111201905-bb88546e799d669f
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/multiparent.py          __init__.py-20070410133617-n1jdhcc1n1mibarp-1
      bzrlib/mutabletree.py          mutabletree.py-20060906023413-4wlkalbdpsxi2r4y-2
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
      bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
      bzrlib/reconcile.py            reweave_inventory.py-20051108164726-1e5e0934febac06e
      bzrlib/reconfigure.py          reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repofmt/knitrepo.py     knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repofmt/weaverepo.py    presplitout.py-20070125045333-wfav3tsh73oxu3zk-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/revision.py             revision.py-20050309040759-e77802c08f3999d5
      bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
      bzrlib/revisiontree.py         revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
      bzrlib/smart/branch.py         branch.py-20061124031907-mzh3pla28r83r97f-1
      bzrlib/smart/bzrdir.py         bzrdir.py-20061122024551-ol0l0o0oofsu9b3t-1
      bzrlib/smart/client.py         client.py-20061116014825-2k6ada6xgulslami-1
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
      bzrlib/smart/protocol.py       protocol.py-20061108035435-ot0lstk2590yqhzr-1
      bzrlib/smart/repository.py     repository.py-20061128022038-vr5wy5bubyb8xttk-1
      bzrlib/smart/request.py        request.py-20061108095550-gunadhxmzkdjfeek-1
      bzrlib/smart/server.py         server.py-20061110062051-chzu10y32vx8gvur-1
      bzrlib/smart/vfs.py            vfs.py-20061108095550-gunadhxmzkdjfeek-2
      bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
      bzrlib/store/revision/knit.py  knit.py-20060303020652-de5fa299e941a3c7
      bzrlib/store/versioned/__init__.py weavestore.py-20050907094258-88262e0434babab9
      bzrlib/tests/TestUtil.py       TestUtil.py-20050824080200-5f70140a2d938694
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_reconfigure.py test_reconfigure.py-20070908173426-khfo5fi2rgzgtwj3-1
      bzrlib/tests/blackbox/test_serve.py test_serve.py-20060913064329-8t2pvmsikl4s3xhl-1
      bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
      bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
      bzrlib/tests/blackbox/test_version.py test_version.py-20070312060045-ol7th9z035r3im3d-1
      bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
      bzrlib/tests/branch_implementations/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
      bzrlib/tests/bzrdir_implementations/__init__.py __init__.py-20060131065642-34c39b54f42dd048
      bzrlib/tests/bzrdir_implementations/test_bzrdir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
      bzrlib/tests/interrepository_implementations/__init__.py __init__.py-20060220054744-baf49a1f88f17b1a
      bzrlib/tests/interrepository_implementations/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
      bzrlib/tests/interversionedfile_implementations/__init__.py __init__.py-20060302012326-981af525594d02ed
      bzrlib/tests/interversionedfile_implementations/test_join.py test_join.py-20060302012326-9b5e9b0f0a03fedc
      bzrlib/tests/repository_implementations/test_check_reconcile.py test_broken.py-20070928125406-62236394w0jpbpd6-2
      bzrlib/tests/repository_implementations/test_fetch.py test_fetch.py-20070814052151-5cxha9slx4c93uog-1
      bzrlib/tests/repository_implementations/test_reconcile.py test_reconcile.py-20060223022332-572ef70a3288e369
      bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
      bzrlib/tests/revisionstore_implementations/test_all.py test_all.py-20060303020702-9b2d4c1d75407f31
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_bugtracker.py test_bugtracker.py-20070410073305-vu1vu1qosjurg8kb-2
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_fetch.py     testfetch.py-20050825090644-f73e07e7dfb1765a
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
      bzrlib/tests/test_lazy_import.py test_lazy_import.py-20060910203832-f77c54gf3n232za0-2
      bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
      bzrlib/tests/test_merge.py     testmerge.py-20050905070950-c1b5aa49ff911024
      bzrlib/tests/test_plugins.py   plugins.py-20050622075746-32002b55e5e943e9
      bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
      bzrlib/tests/test_smart.py     test_smart.py-20061122024551-ol0l0o0oofsu9b3t-2
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
      bzrlib/tests/test_status.py    test_status.py-20060516190614-fbf6432e4a6e8aa5
      bzrlib/tests/test_store.py     teststore.py-20050826022702-f6caadb647395769
      bzrlib/tests/test_subsume.py   test_subsume.py-20060927040024-tsvh4pchajoayymg-1
      bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
      bzrlib/tests/test_versionedfile.py test_versionedfile.py-20060222045249-db45c9ed14a1c2e5
      bzrlib/tests/test_weave.py     testknit.py-20050627023648-9833cc5562ffb785
      bzrlib/tests/test_wsgi.py      test_wsgi.py-20061005091552-rz8pva0olkxv0sd8-1
      bzrlib/tests/workingtree_implementations/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/transport/chroot.py     chroot.py-20061011104729-0us9mgm97z378vnt-1
      bzrlib/transport/ftp.py        ftp.py-20051116161804-58dc9506548c2a53
      bzrlib/transport/http/wsgi.py  wsgi.py-20061005091552-rz8pva0olkxv0sd8-2
      bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
      bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
      bzrlib/transport/ssh.py        ssh.py-20060824042150-0s9787kng6zv1nwq-1
      bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
      bzrlib/weave.py                knit.py-20050627021749-759c29984154256b
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/developers/repository.txt  repository.txt-20070709152006-xkhlek456eclha4u-1
      doc/en/user-guide/annotating_changes.txt annotating_changes.t-20071122141511-0knao2lklsdsvb1q-1
      doc/en/user-guide/bazaar_workflows.txt bazaar_workflows.txt-20071114035000-q36a9h57ps06uvnl-1
      doc/en/user-guide/controlling_registration.txt controlling_registra-20071121073725-0corxykv5irjal00-3
      doc/en/user-guide/core_concepts.txt core_concepts.txt-20071114035000-q36a9h57ps06uvnl-2
      doc/en/user-guide/http_smart_server.txt fastcgi.txt-20061005091552-rz8pva0olkxv0sd8-3
      doc/en/user-guide/installing_bazaar.txt installing_bazaar.tx-20071114035000-q36a9h57ps06uvnl-4
      doc/en/user-guide/introducing_bazaar.txt introducing_bazaar.t-20071114035000-q36a9h57ps06uvnl-5
      bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
    ------------------------------------------------------------
    revno: 3311.3.4
    revision-id:aaron at aaronbentley.com-20080328030947-57cfqi7to7k401wc
    parent: aaron at aaronbentley.com-20080328022852-fa7wsm7g7dhdr7b3
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Thu 2008-03-27 23:09:47 -0400
    message:
      Have xml5 inherit from xml6 from xml8
    removed:
      bzrlib/xml8.py                 xml6.py-20060823042456-dbaaq4atrche7xy5-1
    added:
      bzrlib/xml5.py                 xml5.py-20080328030717-t9guwinq8hom0ar3-1
    renamed:
      bzrlib/xml5.py => bzrlib/xml8.py xml5.py-20050907032657-aac8f960815b66b1
    modified:
      bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
      bzrlib/xml8.py                 xml5.py-20050907032657-aac8f960815b66b1
    ------------------------------------------------------------
    revno: 3311.3.3
    revision-id:aaron at aaronbentley.com-20080328022852-fa7wsm7g7dhdr7b3
    parent: aaron at aaronbentley.com-20080328021023-dc439qj3v30ri5re
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Thu 2008-03-27 22:28:52 -0400
    message:
      Handle format 5 revision
    modified:
      bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
      bzrlib/xml5.py                 xml5.py-20050907032657-aac8f960815b66b1
      bzrlib/xml6.py                 xml6.py-20080327235607-1skmbg4o9cd1o636-1
    ------------------------------------------------------------
    revno: 3311.3.2
    revision-id:aaron at aaronbentley.com-20080328021023-dc439qj3v30ri5re
    parent: aaron at aaronbentley.com-20080327235958-c7avx2qbuev456fx
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Thu 2008-03-27 22:10:23 -0400
    message:
      Implement version numbers for format 8
    modified:
      bzrlib/tests/test_xml.py       test_xml.py-20050905091053-80b45588931a9b35
      bzrlib/xml5.py                 xml5.py-20050907032657-aac8f960815b66b1
      bzrlib/xml_serializer.py       xml.py-20050309040759-57d51586fdec365d
    ------------------------------------------------------------
    revno: 3311.3.1
    revision-id:aaron at aaronbentley.com-20080327235958-c7avx2qbuev456fx
    parent: pqm at pqm.ubuntu.com-20080327163915-wtpepv5kq5hm42zv
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: pack-1.4
    timestamp: Thu 2008-03-27 19:59:58 -0400
    message:
      Make serializer 6 inherit from serializer 8
    added:
      bzrlib/xml6.py                 xml6.py-20080327235607-1skmbg4o9cd1o636-1
    renamed:
      bzrlib/xml6.py => bzrlib/xml8.py xml6.py-20060823042456-dbaaq4atrche7xy5-1
    modified:
      bzrlib/xml8.py                 xml6.py-20060823042456-dbaaq4atrche7xy5-1
=== removed file 'bzrlib/xml6.py'
--- a/bzrlib/xml6.py	2007-10-05 02:41:37 +0000
+++ b/bzrlib/xml6.py	1970-01-01 00:00:00 +0000
@@ -1,71 +0,0 @@
-# Copyright (C) 2005, 2006, 2007 Canonical Ltd
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-from bzrlib import cache_utf8, inventory, errors, xml5
-
-
-class Serializer_v6(xml5.Serializer_v5):
-    """This serialiser adds rich roots."""
-
-    format_num = '6'
-    root_id = None
-
-    def _append_inventory_root(self, append, inv):
-        """Append the inventory root to output."""
-        if inv.revision_id is not None:
-            revid1 = ' revision_id="'
-            revid2 = xml5._encode_and_escape(inv.revision_id)
-        else:
-            revid1 = ""
-            revid2 = ""
-        append('<inventory format="%s"%s%s>\n' % (
-            self.format_num, revid1, revid2))
-        append('<directory file_id="%s name="%s revision="%s />\n' % (
-            xml5._encode_and_escape(inv.root.file_id),
-            xml5._encode_and_escape(inv.root.name),
-            xml5._encode_and_escape(inv.root.revision)))
-
-    def _check_revisions(self, inv):
-        """Extension point for subclasses to check during serialisation.
-
-        By default no checking is done.
-
-        :param inv: An inventory about to be serialised, to be checked.
-        :raises: AssertionError if an error has occured.
-        """
-        assert inv.revision_id is not None
-        assert inv.root.revision is not None
-
-    def _unpack_inventory(self, elt, revision_id=None):
-        """Construct from XML Element"""
-        if elt.tag != 'inventory':
-            raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
-        format = elt.get('format')
-        if format != self.format_num:
-            raise errors.UnexpectedInventoryFormat('Invalid format version %r'
-                                                   % format)
-        revision_id = elt.get('revision_id')
-        if revision_id is not None:
-            revision_id = cache_utf8.encode(revision_id)
-        inv = inventory.Inventory(root_id=None, revision_id=revision_id)
-        for e in elt:
-            ie = self._unpack_entry(e)
-            inv.add(ie)
-        assert inv.root.revision is not None
-        return inv
-
-
-serializer_v6 = Serializer_v6()

=== added file 'bzrlib/xml5.py'
--- a/bzrlib/xml5.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/xml5.py	2008-03-28 03:09:47 +0000
@@ -0,0 +1,84 @@
+# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from bzrlib import (
+    cache_utf8,
+    inventory,
+    xml6,
+    xml8,
+    )
+
+class Serializer_v5(xml6.Serializer_v6):
+    """Version 5 serializer
+
+    Packs objects into XML and vice versa.
+    """
+    format_num = '5'
+    root_id = inventory.ROOT_ID
+
+    def _unpack_inventory(self, elt, revision_id):
+        """Construct from XML Element
+        """
+        assert elt.tag == 'inventory'
+        root_id = elt.get('file_id') or inventory.ROOT_ID
+        root_id = xml8._get_utf8_or_ascii(root_id)
+
+        format = elt.get('format')
+        if format is not None:
+            if format != '5':
+                raise BzrError("invalid format version %r on inventory"
+                                % format)
+        data_revision_id = elt.get('revision_id')
+        if data_revision_id is not None:
+            revision_id = cache_utf8.encode(data_revision_id)
+        inv = inventory.Inventory(root_id, revision_id=revision_id)
+        for e in elt:
+            ie = self._unpack_entry(e)
+            if ie.parent_id is None:
+                ie.parent_id = root_id
+            inv.add(ie)
+        if revision_id is not None:
+            inv.root.revision = revision_id
+        return inv
+
+    def _check_revisions(self, inv):
+        """Extension point for subclasses to check during serialisation.
+
+        In this version, no checking is done.
+
+        :param inv: An inventory about to be serialised, to be checked.
+        :raises: AssertionError if an error has occured.
+        """
+
+    def _append_inventory_root(self, append, inv):
+        """Append the inventory root to output."""
+        if inv.root.file_id not in (None, inventory.ROOT_ID):
+            fileid1 = ' file_id="'
+            fileid2 = xml8._encode_and_escape(inv.root.file_id)
+        else:
+            fileid1 = ""
+            fileid2 = ""
+        if inv.revision_id is not None:
+            revid1 = ' revision_id="'
+            revid2 = xml8._encode_and_escape(inv.revision_id)
+        else:
+            revid1 = ""
+            revid2 = ""
+        append('<inventory%s%s format="5"%s%s>\n' % (
+            fileid1, fileid2, revid1, revid2))
+
+
+serializer_v5 = Serializer_v5()

=== added file 'bzrlib/xml6.py'
--- a/bzrlib/xml6.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/xml6.py	2008-03-28 02:28:52 +0000
@@ -0,0 +1,33 @@
+# Copyright (C) 2008 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from bzrlib import xml8
+
+
+class Serializer_v6(xml8.Serializer_v8):
+    """This serialiser supports rich roots.
+
+    While its inventory format number is 6, its revision format is 5.
+    Its inventory_sha1 may be inaccurate-- the inventory may have been
+    converted from format 5 or 7 without updating the sha1.
+    """
+
+    format_num = '6'
+    # Format 6 & 7 reported their revision format as 5.
+    revision_format_num = '5'
+
+
+serializer_v6 = Serializer_v6()

=== renamed file 'bzrlib/xml5.py' => 'bzrlib/xml8.py'
--- a/bzrlib/xml5.py	2007-10-19 17:14:33 +0000
+++ b/bzrlib/xml8.py	2008-04-17 05:49:53 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005, 2006, 2007 Canonical Ltd
+# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -138,30 +138,31 @@
     _to_escaped_map.clear()
 
 
-class Serializer_v5(Serializer):
-    """Version 5 serializer
+class Serializer_v8(Serializer):
+    """This serialiser adds rich roots.
 
-    Packs objects into XML and vice versa.
+    Its revision format number matches its inventory number.
     """
-    
+
     __slots__ = []
 
-    root_id = ROOT_ID
+    root_id = None
     support_altered_by_hack = True
     # This format supports the altered-by hack that reads file ids directly out
     # of the versionedfile, without doing XML parsing.
 
     supported_kinds = set(['file', 'directory', 'symlink'])
-    format_num = '5'
+    format_num = '8'
+    revision_format_num = None
 
     def _check_revisions(self, inv):
         """Extension point for subclasses to check during serialisation.
 
-        By default no checking is done.
-
         :param inv: An inventory about to be serialised, to be checked.
         :raises: AssertionError if an error has occured.
         """
+        assert inv.revision_id is not None
+        assert inv.root.revision is not None
 
     def write_inventory_to_lines(self, inv):
         """Return a list of lines with the encoded inventory."""
@@ -273,21 +274,19 @@
 
     def _append_inventory_root(self, append, inv):
         """Append the inventory root to output."""
-        if inv.root.file_id not in (None, ROOT_ID):
-            fileid1 = ' file_id="'
-            fileid2 = _encode_and_escape(inv.root.file_id)
-        else:
-            fileid1 = ""
-            fileid2 = ""
         if inv.revision_id is not None:
             revid1 = ' revision_id="'
             revid2 = _encode_and_escape(inv.revision_id)
         else:
             revid1 = ""
             revid2 = ""
-        append('<inventory%s%s format="5"%s%s>\n' % (
-            fileid1, fileid2, revid1, revid2))
-        
+        append('<inventory format="%s"%s%s>\n' % (
+            self.format_num, revid1, revid2))
+        append('<directory file_id="%s name="%s revision="%s />\n' % (
+            _encode_and_escape(inv.root.file_id),
+            _encode_and_escape(inv.root.name),
+            _encode_and_escape(inv.root.revision)))
+
     def _pack_revision(self, rev):
         """Revision object -> xml tree"""
         # For the XML format, we need to write them as Unicode rather than as
@@ -297,12 +296,15 @@
         revision_id = rev.revision_id
         if isinstance(revision_id, str):
             revision_id = decode_utf8(revision_id)
+        format_num = self.format_num
+        if self.revision_format_num is not None:
+            format_num = self.revision_format_num
         root = Element('revision',
                        committer = rev.committer,
                        timestamp = '%.3f' % rev.timestamp,
                        revision_id = revision_id,
                        inventory_sha1 = rev.inventory_sha1,
-                       format='5',
+                       format=format_num,
                        )
         if rev.timezone is not None:
             root.set('timezone', str(rev.timezone))
@@ -336,29 +338,22 @@
             prop_elt.tail = '\n'
         top_elt.tail = '\n'
 
-    def _unpack_inventory(self, elt, revision_id):
-        """Construct from XML Element
-        """
-        assert elt.tag == 'inventory'
-        root_id = elt.get('file_id') or ROOT_ID
-        root_id = _get_utf8_or_ascii(root_id)
-
+    def _unpack_inventory(self, elt, revision_id=None):
+        """Construct from XML Element"""
+        if elt.tag != 'inventory':
+            raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
         format = elt.get('format')
-        if format is not None:
-            if format != '5':
-                raise BzrError("invalid format version %r on inventory"
-                                % format)
-        data_revision_id = elt.get('revision_id')
-        if data_revision_id is not None:
-            revision_id = cache_utf8.encode(data_revision_id)
-        inv = Inventory(root_id, revision_id=revision_id)
+        if format != self.format_num:
+            raise errors.UnexpectedInventoryFormat('Invalid format version %r'
+                                                   % format)
+        revision_id = elt.get('revision_id')
+        if revision_id is not None:
+            revision_id = cache_utf8.encode(revision_id)
+        inv = inventory.Inventory(root_id=None, revision_id=revision_id)
         for e in elt:
             ie = self._unpack_entry(e)
-            if ie.parent_id is None:
-                ie.parent_id = root_id
             inv.add(ie)
-        if revision_id is not None:
-            inv.root.revision = revision_id
+        assert inv.root.revision is not None
         return inv
 
     def _unpack_entry(self, elt):
@@ -404,9 +399,12 @@
         """XML Element -> Revision object"""
         assert elt.tag == 'revision'
         format = elt.get('format')
+        format_num = self.format_num
+        if self.revision_format_num is not None:
+            format_num = self.revision_format_num
         if format is not None:
-            if format != '5':
-                raise BzrError("invalid format version %r on inventory"
+            if format != format_num:
+                raise BzrError("invalid format version %r on revision"
                                 % format)
         get_cached = _get_utf8_or_ascii
         rev = Revision(committer = elt.get('committer'),
@@ -449,4 +447,4 @@
             rev.properties[name] = value
 
 
-serializer_v5 = Serializer_v5()
+serializer_v8 = Serializer_v8()

=== modified file 'NEWS'
--- a/NEWS	2008-04-16 14:44:53 +0000
+++ b/NEWS	2008-04-17 05:49:53 +0000
@@ -38,6 +38,8 @@
 
   INTERNALS:
 
+    * Implement xml8 serializer.  (Aaron Bentley)
+
   API BREAKS:
 
 

=== modified file 'bzrlib/tests/test_xml.py'
--- a/bzrlib/tests/test_xml.py	2007-10-19 17:14:33 +0000
+++ b/bzrlib/tests/test_xml.py	2008-04-15 04:29:44 +0000
@@ -20,6 +20,7 @@
     errors, 
     inventory, 
     xml7,
+    xml8,
     xml_serializer,
     )
 from bzrlib.tests import TestCase
@@ -147,6 +148,24 @@
 </inventory>
 """
 
+_expected_rev_v8 = """<revision committer="Martin Pool &lt;mbp at sourcefrog.net&gt;" format="8" inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41" revision_id="mbp at sourcefrog.net-20050905080035-e0439293f8b6b9f9" timestamp="1125907235.212" timezone="36000">
+<message>- start splitting code for xml (de)serialization away from objects
+  preparatory to supporting multiple formats by a single library
+</message>
+<parents>
+<revision_ref revision_id="mbp at sourcefrog.net-20050905063503-43948f59fa127d92" />
+</parents>
+</revision>
+"""
+
+_expected_inv_v8 = """<inventory format="8" revision_id="rev_outer">
+<directory file_id="tree-root-321" name="" revision="rev_outer" />
+<directory file_id="dir-id" name="dir" parent_id="tree-root-321" revision="rev_outer" />
+<file file_id="file-id" name="file" parent_id="tree-root-321" revision="rev_outer" text_sha1="A" text_size="1" />
+<symlink file_id="link-id" name="link" parent_id="tree-root-321" revision="rev_outer" symlink_target="a" />
+</inventory>
+"""
+
 _revision_utf8_v5 = """<revision committer="Erik B&#229;gfors &lt;erik at foo.net&gt;"
     inventory_sha1="e79c31c1deb64c163cf660fdedd476dd579ffd41"
     revision_id="erik at b&#229;gfors-02"
@@ -330,10 +349,8 @@
         new_rev = s_v5.read_revision_from_string(txt)
         self.assertEqual(props, new_rev.properties)
 
-    def test_roundtrip_inventory_v7(self):
+    def get_sample_inventory(self):
         inv = Inventory('tree-root-321', revision_id='rev_outer')
-        inv.add(inventory.TreeReference('nested-id', 'nested', 'tree-root-321',
-                                        'rev_outer', 'rev_inner'))
         inv.add(inventory.InventoryFile('file-id', 'file', 'tree-root-321'))
         inv.add(inventory.InventoryDirectory('dir-id', 'dir', 
                                              'tree-root-321'))
@@ -345,6 +362,12 @@
         inv['file-id'].text_size = 1
         inv['link-id'].revision = 'rev_outer'
         inv['link-id'].symlink_target = 'a'
+        return inv
+
+    def test_roundtrip_inventory_v7(self):
+        inv = self.get_sample_inventory()
+        inv.add(inventory.TreeReference('nested-id', 'nested', 'tree-root-321',
+                                        'rev_outer', 'rev_inner'))
         txt = xml7.serializer_v7.write_inventory_to_string(inv)
         lines = xml7.serializer_v7.write_inventory_to_lines(inv)
         self.assertEqual(bzrlib.osutils.split_lines(txt), lines)
@@ -389,6 +412,42 @@
                           s_v5.read_inventory_from_string,
                           txt.replace('format="7"', 'format="5"'))
 
+    def test_roundtrip_inventory_v8(self):
+        inv = self.get_sample_inventory()
+        txt = xml8.serializer_v8.write_inventory_to_string(inv)
+        inv2 = xml8.serializer_v8.read_inventory_from_string(txt)
+        self.assertEqual(4, len(inv2))
+        for path, ie in inv.iter_entries():
+            self.assertEqual(ie, inv2[ie.file_id])
+
+    def test_inventory_text_v8(self):
+        inv = self.get_sample_inventory()
+        txt = xml8.serializer_v8.write_inventory_to_string(inv)
+        lines = xml8.serializer_v8.write_inventory_to_lines(inv)
+        self.assertEqual(bzrlib.osutils.split_lines(txt), lines)
+        self.assertEqualDiff(_expected_inv_v8, txt)
+
+    def test_revision_text_v6(self):
+        """Pack revision to XML v6"""
+        rev = bzrlib.xml6.serializer_v6.read_revision_from_string(
+            _expected_rev_v5)
+        serialized = bzrlib.xml6.serializer_v6.write_revision_to_string(rev)
+        self.assertEqualDiff(serialized, _expected_rev_v5)
+
+    def test_revision_text_v7(self):
+        """Pack revision to XML v7"""
+        rev = bzrlib.xml7.serializer_v7.read_revision_from_string(
+            _expected_rev_v5)
+        serialized = bzrlib.xml7.serializer_v7.write_revision_to_string(rev)
+        self.assertEqualDiff(serialized, _expected_rev_v5)
+
+    def test_revision_text_v8(self):
+        """Pack revision to XML v8"""
+        rev = bzrlib.xml8.serializer_v8.read_revision_from_string(
+            _expected_rev_v8)
+        serialized = bzrlib.xml8.serializer_v8.write_revision_to_string(rev)
+        self.assertEqualDiff(serialized, _expected_rev_v8)
+
     def test_revision_ids_are_utf8(self):
         """Parsed revision_ids should all be utf-8 strings, not unicode."""
         s_v5 = bzrlib.xml5.serializer_v5
@@ -442,6 +501,8 @@
                       xml_serializer.format_registry.get('6'))
         self.assertIs(bzrlib.xml7.serializer_v7,
                       xml_serializer.format_registry.get('7'))
+        self.assertIs(bzrlib.xml8.serializer_v8,
+                      xml_serializer.format_registry.get('8'))
 
 
 class TestEncodeAndEscape(TestCase):
@@ -449,31 +510,31 @@
 
     def setUp(self):
         # Keep the cache clear before and after the test
-        bzrlib.xml5._ensure_utf8_re()
-        bzrlib.xml5._clear_cache()
-        self.addCleanup(bzrlib.xml5._clear_cache)
+        bzrlib.xml8._ensure_utf8_re()
+        bzrlib.xml8._clear_cache()
+        self.addCleanup(bzrlib.xml8._clear_cache)
 
     def test_simple_ascii(self):
         # _encode_and_escape always appends a final ", because these parameters
         # are being used in xml attributes, and by returning it now, we have to
         # do fewer string operations later.
-        val = bzrlib.xml5._encode_and_escape('foo bar')
+        val = bzrlib.xml8._encode_and_escape('foo bar')
         self.assertEqual('foo bar"', val)
         # The second time should be cached
-        val2 = bzrlib.xml5._encode_and_escape('foo bar')
+        val2 = bzrlib.xml8._encode_and_escape('foo bar')
         self.assertIs(val2, val)
 
     def test_ascii_with_xml(self):
         self.assertEqual('&amp;&apos;&quot;&lt;&gt;"',
-                         bzrlib.xml5._encode_and_escape('&\'"<>'))
+                         bzrlib.xml8._encode_and_escape('&\'"<>'))
 
     def test_utf8_with_xml(self):
         # u'\xb5\xe5&\u062c'
         utf8_str = '\xc2\xb5\xc3\xa5&\xd8\xac'
         self.assertEqual('&#181;&#229;&amp;&#1580;"',
-                         bzrlib.xml5._encode_and_escape(utf8_str))
+                         bzrlib.xml8._encode_and_escape(utf8_str))
 
     def test_unicode(self):
         uni_str = u'\xb5\xe5&\u062c'
         self.assertEqual('&#181;&#229;&amp;&#1580;"',
-                         bzrlib.xml5._encode_and_escape(uni_str))
+                         bzrlib.xml8._encode_and_escape(uni_str))

=== modified file 'bzrlib/xml_serializer.py'
--- a/bzrlib/xml_serializer.py	2008-01-09 00:51:01 +0000
+++ b/bzrlib/xml_serializer.py	2008-03-28 02:10:23 +0000
@@ -179,3 +179,4 @@
 format_registry.register_lazy('5', 'bzrlib.xml5', 'serializer_v5')
 format_registry.register_lazy('6', 'bzrlib.xml6', 'serializer_v6')
 format_registry.register_lazy('7', 'bzrlib.xml7', 'serializer_v7')
+format_registry.register_lazy('8', 'bzrlib.xml8', 'serializer_v8')




More information about the bazaar-commits mailing list