Rev 3803: Make get_file_text and get_file_lines official (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Oct 28 09:48:34 GMT 2008


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

------------------------------------------------------------
revno: 3803
revision-id: pqm at pqm.ubuntu.com-20081028094831-81he4yysmaobxb41
parent: pqm at pqm.ubuntu.com-20081028014737-guqhitm3jy5ehuxm
parent: aaron at aaronbentley.com-20081028091622-miko3pr4fwpscj1t
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-10-28 09:48:31 +0000
message:
  Make get_file_text and get_file_lines official (abentley)
modified:
  bzrlib/revisiontree.py         revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
  bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
  bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
  bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 3774.1.4
    revision-id: aaron at aaronbentley.com-20081028091622-miko3pr4fwpscj1t
    parent: aaron at aaronbentley.com-20081028090203-84flugri50b3daco
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: tree-api-updates
    timestamp: Tue 2008-10-28 09:16:22 +0000
    message:
      Use file.readlines on working trees.
    modified:
      bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
      bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
    ------------------------------------------------------------
    revno: 3774.1.3
    revision-id: aaron at aaronbentley.com-20081028090203-84flugri50b3daco
    parent: aaron at aaronbentley.com-20081012153800-8ff72bdslnbknfdi
    parent: pqm at pqm.ubuntu.com-20081028014737-guqhitm3jy5ehuxm
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: tree-api-updates
    timestamp: Tue 2008-10-28 09:02:03 +0000
    message:
      Merge with bzr.dev
    added:
      bzrlib/tests/fake_command.py   fake_command.py-20081021195002-r9v65tgxx63c25v9-1
      doc/developers/cycle.txt       cycle.txt-20081017031739-rw24r0cywm2ok3xu-1
      tools/packaging/lp-upload-release lpuploadrelease-20081020075647-56zdf9z6yav1bx81-1
    modified:
      Makefile                       Makefile-20050805140406-d96e3498bb61c5bb
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/_walkdirs_win32.pyx     _walkdirs_win32.pyx-20080716220454-kweh3tgxez5dvw2l-2
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/btree_index.py          index.py-20080624222253-p0x5f92uyh5hw734-7
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/chunk_writer.py         chunk_writer.py-20080630234519-6ggn4id17nipovny-1
      bzrlib/commands.py             bzr.py-20050309040720-d10f4714595cf8c3
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/merge.py                merge.py-20050513021216-953b65a438527106
      bzrlib/patches.py              patches.py-20050727183609-378c1cc5972ce908
      bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
      bzrlib/plugins/launchpad/account.py account.py-20071011033320-50y6vfftywf4yllw-1
      bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
      bzrlib/plugins/launchpad/test_account.py test_account.py-20071011033320-50y6vfftywf4yllw-2
      bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
      bzrlib/python-compat.h         pythoncompat.h-20080924041409-9kvi0fgtuuqp743j-1
      bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_command_encoding.py test_command_encoding.py-20060106032110-45431fd2ce9ff21f
      bzrlib/tests/blackbox/test_missing.py test_missing.py-20051211212735-a2cf4c1840bb84c4
      bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
      bzrlib/tests/test_branch.py    test_branch.py-20060116013032-97819aa07b8ab3b5
      bzrlib/tests/test_btree_index.py test_index.py-20080624222253-p0x5f92uyh5hw734-13
      bzrlib/tests/test_chunk_writer.py test_chunk_writer.py-20080630234519-6ggn4id17nipovny-2
      bzrlib/tests/test_commands.py  test_command.py-20051019190109-3b17be0f52eaa7a8
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_index.py     test_index.py-20070712131115-lolkarso50vjr64s-2
      bzrlib/tests/test_knit.py      test_knit.py-20051212171302-95d4c00dd5f11f2b
      bzrlib/tests/test_patches.py   test_patches.py-20051231203844-f4974d20f6aea09c
      bzrlib/tests/test_plugins.py   plugins.py-20050622075746-32002b55e5e943e9
      bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
      bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
      bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
      bzrlib/tests/test_store.py     teststore.py-20050826022702-f6caadb647395769
      bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
      bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
      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/tree.py                 tree.py-20050309040759-9d5f2496be663e77
      bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
      doc/developers/index.txt       index.txt-20070508041241-qznziunkg0nffhiw-1
      doc/developers/ppa.txt         ppa.txt-20080722055539-606u7t2z32t3ae4w-1
      doc/developers/releasing.txt   releasing.txt-20080502015919-fnrcav8fwy8ccibu-1
      doc/en/user-guide/branching_a_project.txt branching_a_project.-20071122141511-0knao2lklsdsvb1q-2
      doc/en/user-guide/core_concepts.txt core_concepts.txt-20071114035000-q36a9h57ps06uvnl-2
      doc/en/user-guide/using_checkouts.txt using_checkouts.txt-20071123055134-k5x4ekduci2lbn36-4
      setup.py                       setup.py-20050314065409-02f8a0a6e3f9bc70
    ------------------------------------------------------------
    revno: 3774.1.2
    revision-id: aaron at aaronbentley.com-20081012153800-8ff72bdslnbknfdi
    parent: aaron at aaronbentley.com-20081012152650-urs9hisrqa3qj3bk
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: tree-api-updates
    timestamp: Sun 2008-10-12 11:38:00 -0400
    message:
      Test Tree.get_file_lines, provide a default implementation
    modified:
      bzrlib/revisiontree.py         revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
      bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
      bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
    ------------------------------------------------------------
    revno: 3774.1.1
    revision-id: aaron at aaronbentley.com-20081012152650-urs9hisrqa3qj3bk
    parent: pqm at pqm.ubuntu.com-20081010205404-cdqffky0apwxkk1d
    committer: Aaron Bentley <aaron at aaronbentley.com>
    branch nick: tree-api-updates
    timestamp: Sun 2008-10-12 11:26:50 -0400
    message:
      Test Tree.get_file_text() and supply default implementation.
    modified:
      bzrlib/revisiontree.py         revisiontree.py-20060724012533-bg8xyryhxd0o0i0h-1
      bzrlib/tests/tree_implementations/test_tree.py test_tree.py-20061215160206-usu7lwcj8aq2n3br-1
      bzrlib/transform.py            transform.py-20060105172343-dd99e54394d91687
      bzrlib/tree.py                 tree.py-20050309040759-9d5f2496be663e77
      bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
      bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/revisiontree.py'
--- a/bzrlib/revisiontree.py	2008-07-02 01:40:02 +0000
+++ b/bzrlib/revisiontree.py	2008-10-12 15:38:00 +0000
@@ -63,10 +63,7 @@
         """Return the revision id associated with this tree."""
         return self._revision_id
 
-    def get_file_lines(self, file_id):
-        return osutils.split_lines(self.get_file_text(file_id))
-
-    def get_file_text(self, file_id):
+    def get_file_text(self, file_id, path=None):
         return list(self.iter_files_bytes([(file_id, None)]))[0][1]
 
     def get_file(self, file_id, path=None):

=== modified file 'bzrlib/tests/tree_implementations/test_tree.py'
--- a/bzrlib/tests/tree_implementations/test_tree.py	2008-10-10 11:55:03 +0000
+++ b/bzrlib/tests/tree_implementations/test_tree.py	2008-10-28 09:16:22 +0000
@@ -163,6 +163,36 @@
         finally:
             tree.unlock()
 
+    def test_get_file_text(self):
+        work_tree = self.make_branch_and_tree('wt')
+        tree = self.get_tree_no_parents_abc_content_2(work_tree)
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        # test read by file-id
+        self.assertEqual('foobar\n', tree.get_file_text('a-id'))
+        # test read by path
+        self.assertEqual('foobar\n', tree.get_file_text('a-id', path='a'))
+
+    def test_get_file_lines(self):
+        work_tree = self.make_branch_and_tree('wt')
+        tree = self.get_tree_no_parents_abc_content_2(work_tree)
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        # test read by file-id
+        self.assertEqual(['foobar\n'], tree.get_file_lines('a-id'))
+        # test read by path
+        self.assertEqual(['foobar\n'], tree.get_file_lines('a-id', path='a'))
+
+    def test_get_file_lines_multi_line_breaks(self):
+        work_tree = self.make_branch_and_tree('wt')
+        self.build_tree_contents([('wt/foobar', 'a\rb\nc\r\nd')])
+        work_tree.add('foobar', 'foobar-id')
+        tree = self._convert_tree(work_tree)
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        self.assertEqual(['a\rb\n', 'c\r\n', 'd'],
+                         tree.get_file_lines('foobar-id'))
+
 
 class TestExtractFilesBytes(TestCaseWithTree):
 

=== modified file 'bzrlib/transform.py'
--- a/bzrlib/transform.py	2008-10-14 02:50:56 +0000
+++ b/bzrlib/transform.py	2008-10-28 09:02:03 +0000
@@ -1777,13 +1777,6 @@
         name = self._transform._limbo_name(trans_id)
         return open(name, 'rb')
 
-    def get_file_text(self, file_id):
-        text_file = self.get_file(file_id)
-        try:
-            return text_file.read()
-        finally:
-            text_file.close()
-
     def annotate_iter(self, file_id,
                       default_revision=_mod_revision.CURRENT_REVISION):
         changes = self._changes(file_id)

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2008-10-14 02:44:42 +0000
+++ b/bzrlib/tree.py	2008-10-28 09:16:22 +0000
@@ -264,6 +264,30 @@
         """
         raise NotImplementedError(self.get_file)
 
+    def get_file_text(self, file_id, path=None):
+        """Return the byte content of a file.
+
+        :param file_id: The file_id of the file.
+        :param path: The path of the file.
+        If both file_id and path are supplied, an implementation may use
+        either one.
+        """
+        my_file = self.get_file(file_id, path)
+        try:
+            return my_file.read()
+        finally:
+            my_file.close()
+
+    def get_file_lines(self, file_id, path=None):
+        """Return the content of a file, as lines.
+
+        :param file_id: The file_id of the file.
+        :param path: The path of the file.
+        If both file_id and path are supplied, an implementation may use
+        either one.
+        """
+        return osutils.split_lines(self.get_file_text(file_id, path))
+
     def get_file_mtime(self, file_id, path=None):
         """Return the modification time for a file.
 

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2008-09-30 20:30:04 +0000
+++ b/bzrlib/workingtree.py	2008-10-28 09:16:22 +0000
@@ -433,12 +433,17 @@
         file_obj = self.get_file_byname(path)
         return (file_obj, _fstat(file_obj.fileno()))
 
-    def get_file_text(self, file_id):
-        return self.get_file(file_id).read()
-
     def get_file_byname(self, filename):
         return file(self.abspath(filename), 'rb')
 
+    def get_file_lines(self, file_id, path=None):
+        """See Tree.get_file_lines()"""
+        file = self.get_file(file_id, path)
+        try:
+            return file.readlines()
+        finally:
+            file.close()
+
     @needs_read_lock
     def annotate_iter(self, file_id, default_revision=CURRENT_REVISION):
         """See Tree.annotate_iter

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2008-09-25 01:54:42 +0000
+++ b/bzrlib/workingtree_4.py	2008-10-12 15:38:00 +0000
@@ -1625,14 +1625,11 @@
     def get_file(self, file_id, path=None):
         return StringIO(self.get_file_text(file_id))
 
-    def get_file_lines(self, file_id):
-        return osutils.split_lines(self.get_file_text(file_id))
-
     def get_file_size(self, file_id):
         """See Tree.get_file_size"""
         return self.inventory[file_id].text_size
 
-    def get_file_text(self, file_id):
+    def get_file_text(self, file_id, path=None):
         return list(self.iter_files_bytes([(file_id, None)]))[0][1]
 
     def get_reference_revision(self, file_id, path=None):




More information about the bazaar-commits mailing list