diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2010-09-03 23:09:05 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2010-09-03 23:09:05 +0200 |
commit | 844a4f35d6ab0dc1542c40b03cef19a87b9dda08 (patch) | |
tree | 8f13f492b839d5fa3fd9689c3ce674b9c5770c62 | |
parent | bb709e9dabb929d07d9f5424da262bdfd99d8b2d (diff) | |
download | python-fastimport-844a4f35d6ab0dc1542c40b03cef19a87b9dda08.tar.gz |
Move pure-fastimport code into its own directory, in preparation of splitting it into a separate package.
23 files changed, 176 insertions, 141 deletions
diff --git a/__init__.py b/__init__.py index 46866f8..94acacf 100644 --- a/__init__.py +++ b/__init__.py @@ -348,7 +348,7 @@ class cmd_fast_import(Command): user_map=None): from bzrlib.errors import BzrCommandError, NotBranchError from bzrlib.plugins.fastimport.processors import generic_processor - from bzrlib.plugins.fastimport.helpers import ( + from bzrlib.plugins.fastimport.fastimport.helpers import ( open_destination_directory, ) # If no format is given and the user is running a release diff --git a/branch_updater.py b/branch_updater.py index c19cfef..6ec7154 100644 --- a/branch_updater.py +++ b/branch_updater.py @@ -21,7 +21,12 @@ from operator import itemgetter from bzrlib import bzrdir, errors, osutils, transport from bzrlib.trace import error, note -import helpers +from bzrlib.plugins.fastimport.fastimport.helpers import ( + single_plural, + ) +from bzrlib.plugins.fastimport.helpers import ( + best_format_for_objects_in_a_repository, + ) class BranchUpdater(object): @@ -40,7 +45,7 @@ class BranchUpdater(object): self.last_ref = last_ref self.tags = tags self._branch_format = \ - helpers.best_format_for_objects_in_a_repository(repo) + best_format_for_objects_in_a_repository(repo) def update(self): """Update the Bazaar branches and tips matching the heads. @@ -169,6 +174,6 @@ class BranchUpdater(object): if changed: tagno = len(my_tags) note("\t branch %s now has %d %s and %d %s", br.nick, - revno, helpers.single_plural(revno, "revision", "revisions"), - tagno, helpers.single_plural(tagno, "tag", "tags")) + revno, single_plural(revno, "revision", "revisions"), + tagno, single_plural(tagno, "tag", "tags")) return changed diff --git a/bzr_commit_handler.py b/bzr_commit_handler.py index 3226179..bd206bf 100644 --- a/bzr_commit_handler.py +++ b/bzr_commit_handler.py @@ -25,7 +25,11 @@ from bzrlib import ( revision, serializer, ) -from bzrlib.plugins.fastimport import commands, helpers, processor +from bzrlib.plugins.fastimport.fastimport import ( + commands, + helpers, + processor, + ) _serializer_handles_escaping = hasattr(serializer.Serializer, diff --git a/cache_manager.py b/cache_manager.py index 464403f..5a31a00 100644 --- a/cache_manager.py +++ b/cache_manager.py @@ -20,7 +20,6 @@ import atexit import os import shutil import tempfile -import time import weakref from bzrlib import lru_cache, trace @@ -51,8 +50,7 @@ class _Cleanup(object): self.small_blobs.close() self.small_blobs = None if self.tempdir is not None: - shutils.rmtree(self.tempdir) - + shutil.rmtree(self.tempdir) class _Cleanup(object): diff --git a/fastimport/__init__.py b/fastimport/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/fastimport/__init__.py diff --git a/commands.py b/fastimport/commands.py index 7368070..7368070 100644 --- a/commands.py +++ b/fastimport/commands.py diff --git a/dates.py b/fastimport/dates.py index 209d069..510ab85 100644 --- a/dates.py +++ b/fastimport/dates.py @@ -25,7 +25,7 @@ Each routine returns timestamp,timezone where import time -from bzrlib.plugins.fastimport import errors +from bzrlib.plugins.fastimport.fastimport import errors def parse_raw(s, lineno=0): diff --git a/errors.py b/fastimport/errors.py index 9a71d77..9a71d77 100644 --- a/errors.py +++ b/fastimport/errors.py diff --git a/fastimport/helpers.py b/fastimport/helpers.py new file mode 100644 index 0000000..05cce6f --- /dev/null +++ b/fastimport/helpers.py @@ -0,0 +1,95 @@ +# 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 + +"""Miscellaneous useful stuff.""" + + +def single_plural(n, single, plural): + """Return a single or plural form of a noun based on number.""" + if n == 1: + return single + else: + return plural + + +def defines_to_dict(defines): + """Convert a list of definition strings to a dictionary.""" + if defines is None: + return None + result = {} + for define in defines: + kv = define.split('=', 1) + if len(kv) == 1: + result[define.strip()] = 1 + else: + result[kv[0].strip()] = kv[1].strip() + return result + + +def invert_dict(d): + """Invert a dictionary with keys matching each value turned into a list.""" + # Based on recipe from ASPN + result = {} + for k, v in d.iteritems(): + keys = result.setdefault(v, []) + keys.append(k) + return result + + +def invert_dictset(d): + """Invert a dictionary with keys matching a set of values, turned into lists.""" + # Based on recipe from ASPN + result = {} + for k, c in d.iteritems(): + for v in c: + keys = result.setdefault(v, []) + keys.append(k) + return result + + +def _common_path_and_rest(l1, l2, common=[]): + # From http://code.activestate.com/recipes/208993/ + if len(l1) < 1: return (common, l1, l2) + if len(l2) < 1: return (common, l1, l2) + if l1[0] != l2[0]: return (common, l1, l2) + return _common_path_and_rest(l1[1:], l2[1:], common+[l1[0]]) + + +def common_path(path1, path2): + """Find the common bit of 2 paths.""" + return ''.join(_common_path_and_rest(path1, path2)[0]) + + +def binary_stream(stream): + """Ensure a stream is binary on Windows. + + :return: the stream + """ + try: + import os + if os.name == 'nt': + fileno = getattr(stream, 'fileno', None) + if fileno: + no = fileno() + if no >= 0: # -1 means we're working as subprocess + import msvcrt + msvcrt.setmode(no, os.O_BINARY) + except ImportError: + pass + return stream + + + diff --git a/idmapfile.py b/fastimport/idmapfile.py index 7b4ccf4..7b4ccf4 100644 --- a/idmapfile.py +++ b/fastimport/idmapfile.py diff --git a/parser.py b/fastimport/parser.py index ab6efb6..ab6efb6 100644 --- a/parser.py +++ b/fastimport/parser.py diff --git a/processor.py b/fastimport/processor.py index 74f7183..74f7183 100644 --- a/processor.py +++ b/fastimport/processor.py diff --git a/fastimport/tests/__init__.py b/fastimport/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/fastimport/tests/__init__.py diff --git a/tests/test_commands.py b/fastimport/tests/test_commands.py index 3e185b0..6efa4ce 100644 --- a/tests/test_commands.py +++ b/fastimport/tests/test_commands.py @@ -16,14 +16,14 @@ """Test how Commands are displayed""" -from bzrlib import tests +from testtools import TestCase -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( commands, ) -class TestBlobDisplay(tests.TestCase): +class TestBlobDisplay(TestCase): def test_blob(self): c = commands.BlobCommand("1", "hello world") @@ -34,21 +34,21 @@ class TestBlobDisplay(tests.TestCase): self.assertEqual("blob\ndata 11\nhello world", repr(c)) -class TestCheckpointDisplay(tests.TestCase): +class TestCheckpointDisplay(TestCase): def test_checkpoint(self): c = commands.CheckpointCommand() self.assertEqual("checkpoint", repr(c)) -class TestCommitDisplay(tests.TestCase): +class TestCommitDisplay(TestCase): def test_commit(self): # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc) committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, "release v1.0", ":aaa", None, None) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "committer Joe Wong <joe@example.com> 1234567890 -0600\n" @@ -64,7 +64,7 @@ class TestCommitDisplay(tests.TestCase): committer = (name, 'test@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, "release v1.0", ":aaa", None, None) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "committer %s <test@example.com> 1234567890 -0600\n" @@ -78,7 +78,7 @@ class TestCommitDisplay(tests.TestCase): committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", None, None, committer, "release v1.0", ":aaa", None, None) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "committer Joe Wong <joe@example.com> 1234567890 -0600\n" "data 12\n" @@ -91,7 +91,7 @@ class TestCommitDisplay(tests.TestCase): committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, "release v1.0", None, None, None) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "committer Joe Wong <joe@example.com> 1234567890 -0600\n" @@ -105,7 +105,7 @@ class TestCommitDisplay(tests.TestCase): committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", "bbb", author, committer, "release v1.0", ":aaa", None, None) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "author Sue Wong <sue@example.com> 1234565432 -0600\n" @@ -120,7 +120,7 @@ class TestCommitDisplay(tests.TestCase): committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", "ddd", None, committer, "release v1.0", ":aaa", [':bbb', ':ccc'], None) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :ddd\n" "committer Joe Wong <joe@example.com> 1234567890 -0600\n" @@ -141,7 +141,7 @@ class TestCommitDisplay(tests.TestCase): committer = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, "release v1.0", ":aaa", None, file_cmds) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "committer Joe Wong <joe@example.com> 1234567890 -0600\n" @@ -165,7 +165,7 @@ class TestCommitDisplay(tests.TestCase): c = commands.CommitCommand("refs/heads/master", "bbb", author, committer, "release v1.0", ":aaa", None, None, more_authors=more_authors) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "author Sue Wong <sue@example.com> 1234565432 -0600\n" @@ -187,7 +187,7 @@ class TestCommitDisplay(tests.TestCase): c = commands.CommitCommand("refs/heads/master", "bbb", None, committer, "release v1.0", ":aaa", None, None, properties=properties) - self.assertEqualDiff( + self.assertEqual( "commit refs/heads/master\n" "mark :bbb\n" "committer Joe Wong <joe@example.com> 1234567890 -0600\n" @@ -199,7 +199,7 @@ class TestCommitDisplay(tests.TestCase): repr(c)) -class TestFeatureDisplay(tests.TestCase): +class TestFeatureDisplay(TestCase): def test_feature(self): c = commands.FeatureCommand("dwim") @@ -210,14 +210,14 @@ class TestFeatureDisplay(tests.TestCase): self.assertEqual("feature dwim=please", repr(c)) -class TestProgressDisplay(tests.TestCase): +class TestProgressDisplay(TestCase): def test_progress(self): c = commands.ProgressCommand("doing foo") self.assertEqual("progress doing foo", repr(c)) -class TestResetDisplay(tests.TestCase): +class TestResetDisplay(TestCase): def test_reset(self): c = commands.ResetCommand("refs/tags/v1.0", ":xxx") @@ -228,7 +228,7 @@ class TestResetDisplay(tests.TestCase): self.assertEqual("reset refs/remotes/origin/master", repr(c)) -class TestTagDisplay(tests.TestCase): +class TestTagDisplay(TestCase): def test_tag(self): # tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc) @@ -245,7 +245,7 @@ class TestTagDisplay(tests.TestCase): def test_tag_no_from(self): tagger = ('Joe Wong', 'joe@example.com', 1234567890, -6 * 3600) c = commands.TagCommand("refs/tags/v1.0", None, tagger, "create v1.0") - self.assertEqualDiff( + self.assertEqual( "tag refs/tags/v1.0\n" "tagger Joe Wong <joe@example.com> 1234567890 -0600\n" "data 11\n" @@ -253,7 +253,7 @@ class TestTagDisplay(tests.TestCase): repr(c)) -class TestFileModifyDisplay(tests.TestCase): +class TestFileModifyDisplay(TestCase): def test_filemodify_file(self): c = commands.FileModifyCommand("foo/bar", "file", False, ":23", None) @@ -278,14 +278,14 @@ class TestFileModifyDisplay(tests.TestCase): self.assertEqual("M 160000 revision-id-info tree-info", repr(c)) -class TestFileDeleteDisplay(tests.TestCase): +class TestFileDeleteDisplay(TestCase): def test_filedelete(self): c = commands.FileDeleteCommand("foo/bar") self.assertEqual("D foo/bar", repr(c)) -class TestFileCopyDisplay(tests.TestCase): +class TestFileCopyDisplay(TestCase): def test_filecopy(self): c = commands.FileCopyCommand("foo/bar", "foo/baz") @@ -297,7 +297,7 @@ class TestFileCopyDisplay(tests.TestCase): self.assertEqual('C "foo/b a r" foo/b a z', repr(c)) -class TestFileRenameDisplay(tests.TestCase): +class TestFileRenameDisplay(TestCase): def test_filerename(self): c = commands.FileRenameCommand("foo/bar", "foo/baz") @@ -309,14 +309,14 @@ class TestFileRenameDisplay(tests.TestCase): self.assertEqual('R "foo/b a r" foo/b a z', repr(c)) -class TestFileDeleteAllDisplay(tests.TestCase): +class TestFileDeleteAllDisplay(TestCase): def test_filedeleteall(self): c = commands.FileDeleteAllCommand() self.assertEqual("deleteall", repr(c)) -class TestPathChecking(tests.TestCase): +class TestPathChecking(TestCase): def test_filemodify_path_checking(self): self.assertRaises(ValueError, commands.FileModifyCommand, "", diff --git a/tests/test_errors.py b/fastimport/tests/test_errors.py index 8f483a8..e3b807c 100644 --- a/tests/test_errors.py +++ b/fastimport/tests/test_errors.py @@ -16,14 +16,14 @@ """Test the Import errors""" -from bzrlib import tests +from testtools import TestCase -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( errors, ) -class TestErrors(tests.TestCase): +class TestErrors(TestCase): def test_MissingBytes(self): e = errors.MissingBytes(99, 10, 8) @@ -16,66 +16,14 @@ """Miscellaneous useful stuff.""" - -def single_plural(n, single, plural): - """Return a single or plural form of a noun based on number.""" - if n == 1: - return single - else: - return plural - - -def defines_to_dict(defines): - """Convert a list of definition strings to a dictionary.""" - if defines is None: - return None - result = {} - for define in defines: - kv = define.split('=', 1) - if len(kv) == 1: - result[define.strip()] = 1 - else: - result[kv[0].strip()] = kv[1].strip() - return result - - -def invert_dict(d): - """Invert a dictionary with keys matching each value turned into a list.""" - # Based on recipe from ASPN - result = {} - for k, v in d.iteritems(): - keys = result.setdefault(v, []) - keys.append(k) - return result - - -def invert_dictset(d): - """Invert a dictionary with keys matching a set of values, turned into lists.""" - # Based on recipe from ASPN - result = {} - for k, c in d.iteritems(): - for v in c: - keys = result.setdefault(v, []) - keys.append(k) - return result - - -def _common_path_and_rest(l1, l2, common=[]): - # From http://code.activestate.com/recipes/208993/ - if len(l1) < 1: return (common, l1, l2) - if len(l2) < 1: return (common, l1, l2) - if l1[0] != l2[0]: return (common, l1, l2) - return _common_path_and_rest(l1[1:], l2[1:], common+[l1[0]]) - - -def common_path(path1, path2): - """Find the common bit of 2 paths.""" - return ''.join(_common_path_and_rest(path1, path2)[0]) +from bzrlib.plugins.fastimport.fastimport.helpers import ( + common_path, + ) def common_directory(paths): """Find the deepest common directory of a list of paths. - + :return: if no paths are provided, None is returned; if there is no common directory, '' is returned; otherwise the common directory with a trailing / is returned. @@ -106,7 +54,7 @@ def escape_commit_message(message): """Replace xml-incompatible control characters.""" # This really ought to be provided by bzrlib. # Code copied from bzrlib.commit. - + # Python strings can include characters that can't be # represented in well-formed XML; escape characters that # aren't listed in the XML specification @@ -119,25 +67,6 @@ def escape_commit_message(message): return message -def binary_stream(stream): - """Ensure a stream is binary on Windows. - - :return: the stream - """ - try: - import os - if os.name == 'nt': - fileno = getattr(stream, 'fileno', None) - if fileno: - no = fileno() - if no >= 0: # -1 means we're working as subprocess - import msvcrt - msvcrt.setmode(no, os.O_BINARY) - except ImportError: - pass - return stream - - def best_format_for_objects_in_a_repository(repo): """Find the high-level format for branches and trees given a repository. diff --git a/processors/filter_processor.py b/processors/filter_processor.py index 8dc2df8..ebec5af 100644 --- a/processors/filter_processor.py +++ b/processors/filter_processor.py @@ -21,11 +21,13 @@ from bzrlib import osutils from bzrlib.trace import ( warning, ) -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( commands, - helpers, processor, ) +from bzrlib.plugins.fastimport import ( + helpers, + ) class FilterProcessor(processor.ImportProcessor): diff --git a/processors/generic_processor.py b/processors/generic_processor.py index 65b3d4e..e9006c1 100644 --- a/processors/generic_processor.py +++ b/processors/generic_processor.py @@ -19,14 +19,13 @@ import time from bzrlib import ( - bzrdir, delta, errors, osutils, progress, ) from bzrlib.repofmt import pack_repo -from bzrlib.trace import note, mutter +from bzrlib.trace import note try: import bzrlib.util.configobj.configobj as configobj except ImportError: @@ -35,13 +34,15 @@ from bzrlib.plugins.fastimport import ( branch_updater, bzr_commit_handler, cache_manager, + marks_file, + revision_store, + ) +from bzrlib.plugins.fastimport.fastimport import ( commands, errors as plugin_errors, helpers, idmapfile, - marks_file, processor, - revision_store, ) diff --git a/tests/__init__.py b/tests/__init__.py index cda5705..549cf3e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -21,16 +21,16 @@ from bzrlib.tests.TestUtil import TestLoader, TestSuite def test_suite(): - module_names = [__name__ + '.' + x for x in [ - 'test_branch_mapper', - 'test_commands', - 'test_errors', - 'test_filter_processor', - 'test_generic_processor', - 'test_head_tracking', - 'test_helpers', - 'test_parser', - 'test_revision_store', + module_names = ['bzrlib.plugins.fastimport.' + x for x in [ + 'fastimport.tests.test_commands', + 'fastimport.tests.test_errors', + 'tests.test_branch_mapper', + 'tests.test_filter_processor', + 'tests.test_generic_processor', + 'tests.test_head_tracking', + 'tests.test_helpers', + 'tests.test_parser', + 'tests.test_revision_store', ]] loader = TestLoader() return loader.loadTestsFromModuleNames(module_names) diff --git a/tests/test_filter_processor.py b/tests/test_filter_processor.py index ff8a09f..da5fdf2 100644 --- a/tests/test_filter_processor.py +++ b/tests/test_filter_processor.py @@ -18,13 +18,14 @@ from cStringIO import StringIO -from bzrlib import tests +from testtools import TestCase -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( parser, ) -from bzrlib.plugins.fastimport.processors.filter_processor import ( - FilterProcessor, + +from bzrlib.plugins.fastimport.processors import ( + filter_processor, ) @@ -103,17 +104,18 @@ M 644 :4 doc/index.txt """ -class TestCaseWithFiltering(tests.TestCase): +class TestCaseWithFiltering(TestCase): def assertFiltering(self, input, params, expected): outf = StringIO() - proc = FilterProcessor(None, params=params) + proc = filter_processor.FilterProcessor( + None, params=params) proc.outf = outf s = StringIO(input) p = parser.ImportParser(s) proc.process(p.iter_commands) out = outf.getvalue() - self.assertEqualDiff(expected, out) + self.assertEquals(expected, out) class TestNoFiltering(TestCaseWithFiltering): diff --git a/tests/test_generic_processor.py b/tests/test_generic_processor.py index 778a4aa..d479d09 100644 --- a/tests/test_generic_processor.py +++ b/tests/test_generic_processor.py @@ -21,9 +21,8 @@ from bzrlib import ( tests, ) -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( commands, - errors, ) from bzrlib.plugins.fastimport.processors import ( diff --git a/tests/test_head_tracking.py b/tests/test_head_tracking.py index 63712e0..e88e366 100644 --- a/tests/test_head_tracking.py +++ b/tests/test_head_tracking.py @@ -20,7 +20,7 @@ from cStringIO import StringIO from bzrlib import tests -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( commands, parser, ) diff --git a/tests/test_parser.py b/tests/test_parser.py index 4e1a1cd..18475e6 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -20,7 +20,7 @@ import StringIO from bzrlib import tests -from bzrlib.plugins.fastimport import ( +from bzrlib.plugins.fastimport.fastimport import ( errors, parser, ) |