В Втр, 15/12/2009 в 10:39 +0100, Ulrich Mueller пишет:
> bzr.eclass currently uses "bzr export" for copying from
> ${DISTDIR}/bzr-src to ${WORKDIR} in src_unpack. Unfortunately,
> "bzr export" accesses the remote repository for lightweight checkouts
> (which are the eclass's default), so it cannot be used off-line.

After you wrote this I've pinged upstream. Could you try attached patch
(suggested in https://bugs.launchpad.net/bugs/343218 ) and tell us here
or in upstream bug if this fixes the problem? I'm not against eclass
modifications but fixing bzr looks like a better long-term approach.

-- 
Peter.
=== modified file 'bzrlib/export/dir_exporter.py'
--- bzrlib/export/dir_exporter.py	2009-07-29 13:46:55 +0000
+++ bzrlib/export/dir_exporter.py	2009-12-15 16:40:26 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
+# Copyright (C) 2005, 2009 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
@@ -52,21 +52,17 @@
                 raise errors.BzrError("Can't export tree to non-empty directory.")
         else:
             raise
+    # Iterate everything, building up the files we will want to export, and
+    # creating the directories and symlinks that we need.
+    # This tracks (file_id, (destination_path, executable))
+    # This matches the api that tree.iter_files_bytes() wants
+    # Note in the case of revision trees, this does trigger a double inventory
+    # lookup, hopefully it isn't too expensive.
+    to_fetch = []
     for dp, ie in _export_iter_entries(tree, subdir):
         fullpath = osutils.pathjoin(dest, dp)
         if ie.kind == "file":
-            if filtered:
-                chunks = tree.get_file_lines(ie.file_id)
-                filters = tree._content_filter_stack(dp)
-                context = ContentFilterContext(dp, tree, ie)
-                contents = filtered_output_bytes(chunks, filters, context)
-                content = ''.join(contents)
-                fileobj = StringIO.StringIO(content)
-            else:
-                fileobj = tree.get_file(ie.file_id)
-            osutils.pumpfile(fileobj, file(fullpath, 'wb'))
-            if tree.is_executable(ie.file_id):
-                os.chmod(fullpath, 0755)
+            to_fetch.append((ie.file_id, (dp, tree.is_executable(ie.file_id))))
         elif ie.kind == "directory":
             os.mkdir(fullpath)
         elif ie.kind == "symlink":
@@ -80,3 +76,18 @@
         else:
             raise errors.BzrError("don't know how to export {%s} of kind %r" %
                (ie.file_id, ie.kind))
+    # The data returned here can be in any order, but we've already created all
+    # the directories
+    for (relpath, executable), chunks in tree.iter_files_bytes(to_fetch):
+        if filtered:
+            filters = tree._content_filter_stack(relpath)
+            context = ContentFilterContext(relpath, tree, ie)
+            chunks = filtered_output_bytes(chunks, filters, context)
+        fullpath = osutils.pathjoin(dest, relpath)
+        out = open(fullpath, 'wb')
+        try:
+            out.writelines(chunks)
+        finally:
+            out.close()
+        if executable:
+            os.chmod(fullpath, 0755)

Reply via email to