Merge lp:~jelmer/bzr-fastimport/import-helpers into lp:bzr-fastimport

Proposed by Jelmer Vernooij on 2014-05-15
Status: Merged
Approved by: Richard Wilbur on 2014-05-17
Approved revision: 360
Merged at revision: 360
Proposed branch: lp:~jelmer/bzr-fastimport/import-helpers
Merge into: lp:bzr-fastimport
Diff against target: 183 lines (+73/-10)
7 files modified
branch_updater.py (+1/-1)
cache_manager.py (+12/-1)
cmds.py (+4/-2)
exporter.py (+1/-1)
helpers.py (+50/-0)
processors/generic_processor.py (+1/-1)
processors/info_processor.py (+4/-4)
To merge this branch: bzr merge lp:~jelmer/bzr-fastimport/import-helpers
Reviewer Review Type Date Requested Status
Richard Wilbur 2014-05-15 Approve on 2014-05-17
Review via email: mp+219668@code.launchpad.net

Description of the change

Add the bzr-specific helpers that were removed from python-fastimport.

This fixes bzr-fastimport when used with newer versions of python-fastimport (>= 0.9.3).

To post a comment you must log in.
Zygmunt Krynicki (zyga) wrote :

Looks good to me

Richard Wilbur (richard-wilbur) wrote :

Thanks, Jelmer, for putting the pieces back together.
+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'branch_updater.py'
--- branch_updater.py 2012-12-03 11:01:51 +0000
+++ branch_updater.py 2014-05-15 09:40:01 +0000
@@ -22,6 +22,7 @@
2222
23from bzrlib.plugins.fastimport.helpers import (23from bzrlib.plugins.fastimport.helpers import (
24 best_format_for_objects_in_a_repository,24 best_format_for_objects_in_a_repository,
25 single_plural,
25 )26 )
2627
2728
@@ -149,7 +150,6 @@
149150
150 :return: whether the branch was changed or not151 :return: whether the branch was changed or not
151 """152 """
152 from fastimport.helpers import single_plural
153 last_rev_id = self.cache_mgr.lookup_committish(last_mark)153 last_rev_id = self.cache_mgr.lookup_committish(last_mark)
154 self.repo.lock_read()154 self.repo.lock_read()
155 try:155 try:
156156
=== modified file 'cache_manager.py'
--- cache_manager.py 2012-02-28 14:00:56 +0000
+++ cache_manager.py 2014-05-15 09:40:01 +0000
@@ -28,7 +28,7 @@
28from bzrlib.plugins.fastimport.reftracker import (28from bzrlib.plugins.fastimport.reftracker import (
29 RefTracker,29 RefTracker,
30 )30 )
31from fastimport.helpers import (31from bzrlib.plugins.fastimport.helpers import (
32 single_plural,32 single_plural,
33 )33 )
3434
@@ -275,3 +275,14 @@
275 return content275 return content
276276
277277
278def invert_dictset(d):
279 """Invert a dictionary with keys matching a set of values, turned into lists."""
280 # Based on recipe from ASPN
281 result = {}
282 for k, c in d.iteritems():
283 for v in c:
284 keys = result.setdefault(v, [])
285 keys.append(k)
286 return result
287
288
278289
=== modified file 'cmds.py'
--- cmds.py 2014-04-16 05:59:09 +0000
+++ cmds.py 2014-05-15 09:40:01 +0000
@@ -19,7 +19,10 @@
19from bzrlib.commands import Command19from bzrlib.commands import Command
20from bzrlib.option import Option, ListOption, RegistryOption20from bzrlib.option import Option, ListOption, RegistryOption
2121
22from bzrlib.plugins.fastimport import load_fastimport22from bzrlib.plugins.fastimport import (
23 helpers,
24 load_fastimport,
25 )
2326
2427
25def _run(source, processor_factory, verbose=False, user_map=None, **kwargs):28def _run(source, processor_factory, verbose=False, user_map=None, **kwargs):
@@ -47,7 +50,6 @@
47def _get_source_stream(source):50def _get_source_stream(source):
48 if source == '-' or source is None:51 if source == '-' or source is None:
49 import sys52 import sys
50 from fastimport import helpers
51 stream = helpers.binary_stream(sys.stdin)53 stream = helpers.binary_stream(sys.stdin)
52 elif source.endswith('.gz'):54 elif source.endswith('.gz'):
53 import gzip55 import gzip
5456
=== modified file 'exporter.py'
--- exporter.py 2012-08-21 10:08:53 +0000
+++ exporter.py 2014-05-15 09:40:01 +0000
@@ -64,7 +64,7 @@
64 )64 )
6565
66from fastimport import commands66from fastimport import commands
67from fastimport.helpers import (67from bzrlib.plugins.fastimport.helpers import (
68 binary_stream,68 binary_stream,
69 single_plural,69 single_plural,
70 )70 )
7171
=== modified file 'helpers.py'
--- helpers.py 2011-10-06 00:11:52 +0000
+++ helpers.py 2014-05-15 09:40:01 +0000
@@ -146,3 +146,53 @@
146 return 'tree-reference', False146 return 'tree-reference', False
147 else:147 else:
148 raise AssertionError("invalid mode %o" % mode)148 raise AssertionError("invalid mode %o" % mode)
149
150
151def binary_stream(stream):
152 """Ensure a stream is binary on Windows.
153
154 :return: the stream
155 """
156 try:
157 import os
158 if os.name == 'nt':
159 fileno = getattr(stream, 'fileno', None)
160 if fileno:
161 no = fileno()
162 if no >= 0: # -1 means we're working as subprocess
163 import msvcrt
164 msvcrt.setmode(no, os.O_BINARY)
165 except ImportError:
166 pass
167 return stream
168
169
170def single_plural(n, single, plural):
171 """Return a single or plural form of a noun based on number."""
172 if n == 1:
173 return single
174 else:
175 return plural
176
177
178def invert_dictset(d):
179 """Invert a dictionary with keys matching a set of values, turned into lists."""
180 # Based on recipe from ASPN
181 result = {}
182 for k, c in d.iteritems():
183 for v in c:
184 keys = result.setdefault(v, [])
185 keys.append(k)
186 return result
187
188
189def invert_dict(d):
190 """Invert a dictionary with keys matching each value turned into a list."""
191 # Based on recipe from ASPN
192 result = {}
193 for k, v in d.iteritems():
194 keys = result.setdefault(v, [])
195 keys.append(k)
196 return result
197
198
149199
=== modified file 'processors/generic_processor.py'
--- processors/generic_processor.py 2012-02-28 14:00:56 +0000
+++ processors/generic_processor.py 2014-05-15 09:40:01 +0000
@@ -40,6 +40,7 @@
40from bzrlib.plugins.fastimport import (40from bzrlib.plugins.fastimport import (
41 branch_updater,41 branch_updater,
42 cache_manager,42 cache_manager,
43 helpers,
43 idmapfile,44 idmapfile,
44 marks_file,45 marks_file,
45 revision_store,46 revision_store,
@@ -47,7 +48,6 @@
47from fastimport import (48from fastimport import (
48 commands,49 commands,
49 errors as plugin_errors,50 errors as plugin_errors,
50 helpers,
51 processor,51 processor,
52 )52 )
5353
5454
=== modified file 'processors/info_processor.py'
--- processors/info_processor.py 2012-02-28 14:00:56 +0000
+++ processors/info_processor.py 2014-05-15 09:40:01 +0000
@@ -18,14 +18,14 @@
18from bzrlib.plugins.fastimport import (18from bzrlib.plugins.fastimport import (
19 reftracker,19 reftracker,
20 )20 )
21from bzrlib.plugins.fastimport.helpers import (
22 invert_dict,
23 invert_dictset,
24 )
21from fastimport import (25from fastimport import (
22 commands,26 commands,
23 processor,27 processor,
24 )28 )
25from fastimport.helpers import (
26 invert_dict,
27 invert_dictset,
28 )
29import stat29import stat
3030
3131

Subscribers

People subscribed via source and target branches