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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Richard Wilbur
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 Approve
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.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Looks good to me

Revision history for this message
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
1=== modified file 'branch_updater.py'
2--- branch_updater.py 2012-12-03 11:01:51 +0000
3+++ branch_updater.py 2014-05-15 09:40:01 +0000
4@@ -22,6 +22,7 @@
5
6 from bzrlib.plugins.fastimport.helpers import (
7 best_format_for_objects_in_a_repository,
8+ single_plural,
9 )
10
11
12@@ -149,7 +150,6 @@
13
14 :return: whether the branch was changed or not
15 """
16- from fastimport.helpers import single_plural
17 last_rev_id = self.cache_mgr.lookup_committish(last_mark)
18 self.repo.lock_read()
19 try:
20
21=== modified file 'cache_manager.py'
22--- cache_manager.py 2012-02-28 14:00:56 +0000
23+++ cache_manager.py 2014-05-15 09:40:01 +0000
24@@ -28,7 +28,7 @@
25 from bzrlib.plugins.fastimport.reftracker import (
26 RefTracker,
27 )
28-from fastimport.helpers import (
29+from bzrlib.plugins.fastimport.helpers import (
30 single_plural,
31 )
32
33@@ -275,3 +275,14 @@
34 return content
35
36
37+def invert_dictset(d):
38+ """Invert a dictionary with keys matching a set of values, turned into lists."""
39+ # Based on recipe from ASPN
40+ result = {}
41+ for k, c in d.iteritems():
42+ for v in c:
43+ keys = result.setdefault(v, [])
44+ keys.append(k)
45+ return result
46+
47+
48
49=== modified file 'cmds.py'
50--- cmds.py 2014-04-16 05:59:09 +0000
51+++ cmds.py 2014-05-15 09:40:01 +0000
52@@ -19,7 +19,10 @@
53 from bzrlib.commands import Command
54 from bzrlib.option import Option, ListOption, RegistryOption
55
56-from bzrlib.plugins.fastimport import load_fastimport
57+from bzrlib.plugins.fastimport import (
58+ helpers,
59+ load_fastimport,
60+ )
61
62
63 def _run(source, processor_factory, verbose=False, user_map=None, **kwargs):
64@@ -47,7 +50,6 @@
65 def _get_source_stream(source):
66 if source == '-' or source is None:
67 import sys
68- from fastimport import helpers
69 stream = helpers.binary_stream(sys.stdin)
70 elif source.endswith('.gz'):
71 import gzip
72
73=== modified file 'exporter.py'
74--- exporter.py 2012-08-21 10:08:53 +0000
75+++ exporter.py 2014-05-15 09:40:01 +0000
76@@ -64,7 +64,7 @@
77 )
78
79 from fastimport import commands
80-from fastimport.helpers import (
81+from bzrlib.plugins.fastimport.helpers import (
82 binary_stream,
83 single_plural,
84 )
85
86=== modified file 'helpers.py'
87--- helpers.py 2011-10-06 00:11:52 +0000
88+++ helpers.py 2014-05-15 09:40:01 +0000
89@@ -146,3 +146,53 @@
90 return 'tree-reference', False
91 else:
92 raise AssertionError("invalid mode %o" % mode)
93+
94+
95+def binary_stream(stream):
96+ """Ensure a stream is binary on Windows.
97+
98+ :return: the stream
99+ """
100+ try:
101+ import os
102+ if os.name == 'nt':
103+ fileno = getattr(stream, 'fileno', None)
104+ if fileno:
105+ no = fileno()
106+ if no >= 0: # -1 means we're working as subprocess
107+ import msvcrt
108+ msvcrt.setmode(no, os.O_BINARY)
109+ except ImportError:
110+ pass
111+ return stream
112+
113+
114+def single_plural(n, single, plural):
115+ """Return a single or plural form of a noun based on number."""
116+ if n == 1:
117+ return single
118+ else:
119+ return plural
120+
121+
122+def invert_dictset(d):
123+ """Invert a dictionary with keys matching a set of values, turned into lists."""
124+ # Based on recipe from ASPN
125+ result = {}
126+ for k, c in d.iteritems():
127+ for v in c:
128+ keys = result.setdefault(v, [])
129+ keys.append(k)
130+ return result
131+
132+
133+def invert_dict(d):
134+ """Invert a dictionary with keys matching each value turned into a list."""
135+ # Based on recipe from ASPN
136+ result = {}
137+ for k, v in d.iteritems():
138+ keys = result.setdefault(v, [])
139+ keys.append(k)
140+ return result
141+
142+
143
144=== modified file 'processors/generic_processor.py'
145--- processors/generic_processor.py 2012-02-28 14:00:56 +0000
146+++ processors/generic_processor.py 2014-05-15 09:40:01 +0000
147@@ -40,6 +40,7 @@
148 from bzrlib.plugins.fastimport import (
149 branch_updater,
150 cache_manager,
151+ helpers,
152 idmapfile,
153 marks_file,
154 revision_store,
155@@ -47,7 +48,6 @@
156 from fastimport import (
157 commands,
158 errors as plugin_errors,
159- helpers,
160 processor,
161 )
162
163
164=== modified file 'processors/info_processor.py'
165--- processors/info_processor.py 2012-02-28 14:00:56 +0000
166+++ processors/info_processor.py 2014-05-15 09:40:01 +0000
167@@ -18,14 +18,14 @@
168 from bzrlib.plugins.fastimport import (
169 reftracker,
170 )
171+from bzrlib.plugins.fastimport.helpers import (
172+ invert_dict,
173+ invert_dictset,
174+ )
175 from fastimport import (
176 commands,
177 processor,
178 )
179-from fastimport.helpers import (
180- invert_dict,
181- invert_dictset,
182- )
183 import stat
184
185

Subscribers

People subscribed via source and target branches