Merge lp:~jpds/lmirror/fix_542162 into lp:~lmirror/lmirror/trunk

Proposed by Jonathan Davies
Status: Work in progress
Proposed branch: lp:~jpds/lmirror/fix_542162
Merge into: lp:~lmirror/lmirror/trunk
Diff against target: 266 lines (+96/-28)
5 files modified
l_mirror/journals.py (+11/-3)
l_mirror/tests/commands/test_finish_change.py (+17/-4)
l_mirror/tests/commands/test_init.py (+20/-6)
l_mirror/tests/test_journals.py (+25/-9)
l_mirror/tests/test_mirrorset.py (+23/-6)
To merge this branch: bzr merge lp:~jpds/lmirror/fix_542162
Reviewer Review Type Date Requested Status
Robert Collins Needs Resubmitting
lmirror committers code Pending
Review via email: mp+26105@code.launchpad.net

Description of the change

Implemented bz2 compressed changesets and test updates.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

So, this is a good start, but not quite complete. Folk with existing lmirror repos will get broken by this patch.

What you need to do a little differently is this:
 - only compress the content after the first (signature) line in a changeset
 - add a new signature for bz2 changesets
 - make the parser switch based on the signature between decompressing or not decompressing.

review: Needs Resubmitting

Unmerged revisions

64. By Jonathan Davies

Removed print hack attempt to see what was wrong with tests earlier.

63. By Jonathan Davies

Updated init command tests for compressed changesets.

62. By Jonathan Davies

Updated finish_change command tests for compressed changesets.

61. By Jonathan Davies

Updated mirror set tests for compressed changesets.

60. By Jonathan Davies

Updated journal tests for compressed changesets.

59. By Jonathan Davies

Write and read compresed changeset files with bz2.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l_mirror/journals.py'
2--- l_mirror/journals.py 2010-04-11 13:20:39 +0000
3+++ l_mirror/journals.py 2010-05-27 15:06:27 +0000
4@@ -45,6 +45,7 @@
5 'FilterCombiner', 'ProcessFilter',
6 ]
7
8+import bz2
9 import errno
10 import os
11 from hashlib import sha1 as sha
12@@ -588,7 +589,11 @@
13 output.extend(kind_data[1].as_tokens())
14 else:
15 output.extend(kind_data.as_tokens())
16- return 'l-mirror-journal-2\n' + '\0'.join(output)
17+
18+ compressed_output = bz2.compress(
19+ 'l-mirror-journal-2\n' + '\0'.join(output))
20+
21+ return compressed_output
22
23 def as_groups(self):
24 """Create a series of groups that can be acted on to apply the journal.
25@@ -624,13 +629,16 @@
26 return [adds, replaces, deletes]
27
28
29-def parse(a_bytestring):
30- """Parse a_bytestring into a journal.
31+def parse(compressed_data):
32+ """Parse a_bytestring from compressed_data into a journal.
33
34 :return: A Journal.
35 """
36 header1 = 'l-mirror-journal-1\n'
37 header2 = 'l-mirror-journal-2\n'
38+
39+ a_bytestring = bz2.decompress(compressed_data)
40+
41 if not a_bytestring.startswith(header1):
42 if not a_bytestring.startswith(header2):
43 raise ValueError('Not a journal: missing header %r' % (
44
45=== modified file 'l_mirror/tests/commands/test_finish_change.py'
46--- l_mirror/tests/commands/test_finish_change.py 2010-03-31 10:11:17 +0000
47+++ l_mirror/tests/commands/test_finish_change.py 2010-05-27 15:06:27 +0000
48@@ -19,6 +19,8 @@
49
50 """Tests for the finish-change command."""
51
52+import bz2
53+
54 from doctest import ELLIPSIS
55
56 from bzrlib.transport import get_transport
57@@ -77,7 +79,18 @@
58 updating = False
59
60 """, ELLIPSIS))
61- self.assertThat(t.get_bytes('journals/0'), DocTestMatches("""l-mirror-journal-2
62-"""))
63- self.assertThat(t.get_bytes('journals/1'), DocTestMatches("""l-mirror-journal-2
64-.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir1\x00new\x00dir\x00dir1/def\x00new\x00file\x001f8ac10f23c5b5bc1167bda84b833e5c057a77d2\x006\x000.000000\x00dir2\x00new\x00dir"""))
65+
66+ journal_data_set0 = "l-mirror-journal-2\n"
67+
68+ compressed_journal_data_set0 = bz2.compress(journal_data_set0)
69+
70+ self.assertThat(t.get_bytes('journals/0'),
71+ DocTestMatches(compressed_journal_data_set0))
72+
73+ journal_data_set1 = """l-mirror-journal-2
74+.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir1\x00new\x00dir\x00dir1/def\x00new\x00file\x001f8ac10f23c5b5bc1167bda84b833e5c057a77d2\x006\x000.000000\x00dir2\x00new\x00dir"""
75+
76+ compressed_journal_data_set1 = bz2.compress(journal_data_set1)
77+
78+ self.assertThat(t.get_bytes('journals/1'),
79+ DocTestMatches(compressed_journal_data_set1))
80
81=== modified file 'l_mirror/tests/commands/test_init.py'
82--- l_mirror/tests/commands/test_init.py 2010-03-31 10:11:17 +0000
83+++ l_mirror/tests/commands/test_init.py 2010-05-27 15:06:27 +0000
84@@ -19,6 +19,8 @@
85
86 """Tests for the init command."""
87
88+import bz2
89+
90 from doctest import ELLIPSIS
91
92 from bzrlib.transport import get_transport
93@@ -82,8 +84,12 @@
94 timestamp = ...
95 updating = True
96 """, ELLIPSIS))
97- self.assertThat(t.get_bytes('journals/0'), DocTestMatches("""l-mirror-journal-2
98-"""))
99+
100+ journal_data = "l-mirror-journal-2\n"
101+ compressed_journal_data = bz2.compress(journal_data)
102+
103+ self.assertThat(t.get_bytes('journals/0'),
104+ DocTestMatches(compressed_journal_data))
105
106 def test_scans_content_root(self):
107 base = self.setup_memory()
108@@ -106,7 +112,15 @@
109 updating = False
110
111 """, ELLIPSIS))
112- self.assertThat(t.get_bytes('journals/0'), DocTestMatches("""l-mirror-journal-2
113-"""))
114- self.assertThat(t.get_bytes('journals/1'), DocTestMatches("""l-mirror-journal-2
115-.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir1\x00new\x00dir\x00dir1/def\x00new\x00file\x001f8ac10f23c5b5bc1167bda84b833e5c057a77d2\x006\x000.000000\x00dir2\x00new\x00dir"""))
116+
117+ journal_data_set0 = "l-mirror-journal-2\n"
118+ compressed_journal_data_set0 = bz2.compress(journal_data_set0)
119+ self.assertThat(t.get_bytes('journals/0'),
120+ DocTestMatches(compressed_journal_data_set0))
121+
122+ journal_data_set1 = """l-mirror-journal-2
123+.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir1\x00new\x00dir\x00dir1/def\x00new\x00file\x001f8ac10f23c5b5bc1167bda84b833e5c057a77d2\x006\x000.000000\x00dir2\x00new\x00dir"""
124+ compressed_journal_data_set1 = bz2.compress(journal_data_set1)
125+
126+ self.assertThat(t.get_bytes('journals/1'),
127+ DocTestMatches(compressed_journal_data_set1))
128
129=== modified file 'l_mirror/tests/test_journals.py'
130--- l_mirror/tests/test_journals.py 2010-04-08 11:01:39 +0000
131+++ l_mirror/tests/test_journals.py 2010-05-27 15:06:27 +0000
132@@ -19,6 +19,7 @@
133
134 """Tests for the journals module."""
135
136+import bz2
137 from doctest import ELLIPSIS
138 from StringIO import StringIO
139 import time
140@@ -324,8 +325,13 @@
141 j1.add('1234', 'replace', (
142 journals.SymlinkContent('foo bar/baz'),
143 journals.FileContent('e935b6eefc78846802e12039d6dd9a7e27622301', 0, 1.5)))
144- self.assertEqual("""l-mirror-journal-2
145-1234\0replace\0symlink\0foo bar/baz\0file\0e935b6eefc78846802e12039d6dd9a7e27622301\0000\x001.500000\x00abc\0new\0file\00012039d6dd9a7e27622301e935b6eefc78846802e\00011\x000.000000\x00abc/def\0del\0dir""", j1.as_bytes())
146+
147+ expected_result = """l-mirror-journal-2
148+1234\0replace\0symlink\0foo bar/baz\0file\0e935b6eefc78846802e12039d6dd9a7e27622301\0000\x001.500000\x00abc\0new\0file\00012039d6dd9a7e27622301e935b6eefc78846802e\00011\x000.000000\x00abc/def\0del\0dir"""
149+
150+ compressed_result = bz2.compress(expected_result)
151+
152+ self.assertEqual(compressed_result, j1.as_bytes())
153
154
155 class TestTransportReplay(ResourcedTestCase):
156@@ -387,9 +393,11 @@
157 class TestParser(ResourcedTestCase):
158
159 def test_parse_v1(self):
160- journal = journals.parse("""l-mirror-journal-1
161-1234\0replace\0symlink\0foo bar/baz\0file\0e935b6eefc78846802e12039d6dd9a7e27622301\0000\x00abc\0new\0file\00012039d6dd9a7e27622301e935b6eefc78846802e\00011\0abc/def\0del\0dir""")
162+ journal_data = """l-mirror-journal-1
163+1234\0replace\0symlink\0foo bar/baz\0file\0e935b6eefc78846802e12039d6dd9a7e27622301\0000\x00abc\0new\0file\00012039d6dd9a7e27622301e935b6eefc78846802e\00011\0abc/def\0del\0dir"""
164+ compressed_journal_data = bz2.compress(journal_data)
165 expected = journals.Journal()
166+ journal = journals.parse(compressed_journal_data)
167 expected.add('abc', 'new',
168 journals.FileContent('12039d6dd9a7e27622301e935b6eefc78846802e', 11, None))
169 expected.add('abc/def', 'del', journals.DirContent())
170@@ -399,9 +407,12 @@
171 self.assertEqual(expected.paths, journal.paths)
172
173 def test_parse_v2(self):
174- journal = journals.parse("""l-mirror-journal-2
175-1234\0replace\0symlink\0foo bar/baz\0file\0e935b6eefc78846802e12039d6dd9a7e27622301\0000\x000\x00abc\0new\0file\00012039d6dd9a7e27622301e935b6eefc78846802e\00011\x002\0abc/def\0del\0dir""")
176+ journal_data = """l-mirror-journal-2
177+1234\0replace\0symlink\0foo bar/baz\0file\0e935b6eefc78846802e12039d6dd9a7e27622301\0000\x000\x00abc\0new\0file\00012039d6dd9a7e27622301e935b6eefc78846802e\00011\x002\0abc/def\0del\0dir"""
178+ compressed_journal_data = bz2.compress(journal_data)
179 expected = journals.Journal()
180+
181+ journal = journals.parse(compressed_journal_data)
182 expected.add('abc', 'new',
183 journals.FileContent('12039d6dd9a7e27622301e935b6eefc78846802e', 11, 2.0))
184 expected.add('abc/def', 'del', journals.DirContent())
185@@ -411,12 +422,17 @@
186 self.assertEqual(expected.paths, journal.paths)
187
188 def test_parse_empty(self):
189- journal = journals.parse('l-mirror-journal-1\n')
190+ compressed_data = bz2.compress('l-mirror-journal-1\n')
191+
192+ journal = journals.parse(compressed_data)
193 self.assertEqual({}, journal.paths)
194
195 def test_parse_wrong_header(self):
196- self.assertRaises(ValueError, journals.parse, 'l-mirror-journal-1')
197- self.assertRaises(ValueError, journals.parse, 'l-mirror-journal-3\n')
198+ compressed_header_v1 = bz2.compress('l-mirror-journal-1')
199+ compressed_header_v3 = bz2.compress('l-mirror-journal-3\n')
200+
201+ self.assertRaises(ValueError, journals.parse, compressed_header_v1)
202+ self.assertRaises(ValueError, journals.parse, compressed_header_v3)
203
204
205 class TestDiskUpdater(ResourcedTestCase):
206
207=== modified file 'l_mirror/tests/test_mirrorset.py'
208--- l_mirror/tests/test_mirrorset.py 2010-04-11 13:20:39 +0000
209+++ l_mirror/tests/test_mirrorset.py 2010-05-27 15:06:27 +0000
210@@ -19,6 +19,8 @@
211
212 """Tests for the mirrorset module."""
213
214+import bz2
215+
216 from doctest import ELLIPSIS
217
218 from bzrlib import gpg as bzrgpg
219@@ -97,8 +99,11 @@
220 timestamp = 0
221 updating = True
222 """, ELLIPSIS))
223- self.assertThat(t.get_bytes('journals/0'), DocTestMatches("""l-mirror-journal-2
224-"""))
225+
226+ compressed_journal = bz2.compress("l-mirror-journal-2\n")
227+
228+ self.assertThat(t.get_bytes('journals/0'),
229+ DocTestMatches(compressed_journal))
230
231 def test_open_set(self):
232 basedir = get_transport(self.setup_memory()).clone('path')
233@@ -213,8 +218,14 @@
234 updating = False
235
236 """, ELLIPSIS))
237- self.assertThat(t.get_bytes('journals/1'), DocTestMatches("""l-mirror-journal-2
238-.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir1\x00new\x00dir\x00dir1/def\x00new\x00file\x001f8ac10f23c5b5bc1167bda84b833e5c057a77d2\x006\x000.000000\x00dir2\x00new\x00dir"""))
239+
240+ expected_journal_data = """l-mirror-journal-2
241+.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir1\x00new\x00dir\x00dir1/def\x00new\x00file\x001f8ac10f23c5b5bc1167bda84b833e5c057a77d2\x006\x000.000000\x00dir2\x00new\x00dir"""
242+
243+ compressed_journal_data = bz2.compress(expected_journal_data)
244+
245+ self.assertThat(t.get_bytes('journals/1'),
246+ DocTestMatches(compressed_journal_data))
247
248 def test_include_excludes_honoured(self):
249 basedir = get_transport(self.setup_memory()).clone('path')
250@@ -239,8 +250,14 @@
251 updating = False
252
253 """, ELLIPSIS))
254- self.assertThat(t.get_bytes('journals/1'), DocTestMatches("""l-mirror-journal-2
255-.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir2\x00new\x00dir\x00dir2/included\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000"""))
256+
257+ journal_data = """l-mirror-journal-2
258+.lmirror\x00new\x00dir\x00.lmirror/sets\x00new\x00dir\x00.lmirror/sets/myname\x00new\x00dir\x00.lmirror/sets/myname/format\x00new\x00file\x00e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e\x002\x000.000000\x00.lmirror/sets/myname/set.conf\x00new\x00file\x00061df21cf828bb333660621c3743cfc3a3b2bd23\x0023\x000.000000\x00abc\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000\x00dir2\x00new\x00dir\x00dir2/included\x00new\x00file\x0012039d6dd9a7e27622301e935b6eefc78846802e\x0011\x000.000000"""
259+
260+ compressed_journal_data = bz2.compress(journal_data)
261+
262+ self.assertThat(t.get_bytes('journals/1'),
263+ DocTestMatches(compressed_journal_data))
264
265 def test_signs_when_there_is_a_keyring(self):
266 basedir = get_transport(self.setup_memory()).clone('path')

Subscribers

People subscribed via source and target branches