Merge lp:~jelmer/brz/marks-export into lp:brz/3.1

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/marks-export
Merge into: lp:brz/3.1
Diff against target: 181 lines (+66/-22)
4 files modified
breezy/plugins/fastimport/exporter.py (+9/-10)
breezy/plugins/fastimport/marks_file.py (+11/-12)
breezy/plugins/fastimport/tests/__init__.py (+1/-0)
breezy/plugins/fastimport/tests/test_marks_file.py (+45/-0)
To merge this branch: bzr merge lp:~jelmer/brz/marks-export
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+386706@code.launchpad.net

Commit message

Fix marks file handling on Python 3.

Description of the change

Fix marks file handling on Python 3.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/plugins/fastimport/exporter.py'
--- breezy/plugins/fastimport/exporter.py 2020-01-26 04:41:46 +0000
+++ breezy/plugins/fastimport/exporter.py 2020-07-01 23:30:53 +0000
@@ -353,7 +353,7 @@
353 def emit_baseline(self, revobj, ref):353 def emit_baseline(self, revobj, ref):
354 # Emit a full source tree of the first commit's parent354 # Emit a full source tree of the first commit's parent
355 mark = 1355 mark = 1
356 self.revid_to_mark[revobj.revision_id] = mark356 self.revid_to_mark[revobj.revision_id] = b"%d" % mark
357 tree_old = self.branch.repository.revision_tree(357 tree_old = self.branch.repository.revision_tree(
358 breezy.revision.NULL_REVISION)358 breezy.revision.NULL_REVISION)
359 [tree_new] = list(self._get_revision_trees([revobj.revision_id]))359 [tree_new] = list(self._get_revision_trees([revobj.revision_id]))
@@ -362,12 +362,12 @@
362 self.print_cmd(self._get_commit_command(ref, mark, revobj, file_cmds))362 self.print_cmd(self._get_commit_command(ref, mark, revobj, file_cmds))
363363
364 def preprocess_commit(self, revid, revobj, ref):364 def preprocess_commit(self, revid, revobj, ref):
365 if revid in self.revid_to_mark or revid in self.excluded_revisions:365 if self.revid_to_mark.get(revid) or revid in self.excluded_revisions:
366 return366 return []
367 if revobj is None:367 if revobj is None:
368 # This is a ghost revision. Mark it as not found and next!368 # This is a ghost revision. Mark it as not found and next!
369 self.revid_to_mark[revid] = -1369 self.revid_to_mark[revid] = None
370 return370 return []
371 # Get the primary parent371 # Get the primary parent
372 # TODO: Consider the excluded revisions when deciding the parents.372 # TODO: Consider the excluded revisions when deciding the parents.
373 # Currently, a commit with parents that are excluded ought to be373 # Currently, a commit with parents that are excluded ought to be
@@ -379,9 +379,8 @@
379 parent = revobj.parent_ids[0]379 parent = revobj.parent_ids[0]
380380
381 # Print the commit381 # Print the commit
382 mark = len(self.revid_to_mark) + 1382 self.revid_to_mark[revobj.revision_id] = b"%d" % (
383 self.revid_to_mark[revobj.revision_id] = mark383 len(self.revid_to_mark) + 1)
384
385 return [parent, revobj.revision_id]384 return [parent, revobj.revision_id]
386385
387 def emit_commit(self, revobj, ref, tree_old, tree_new):386 def emit_commit(self, revobj, ref, tree_old, tree_new):
@@ -449,7 +448,7 @@
449 continue448 continue
450 try:449 try:
451 parent_mark = self.revid_to_mark[p]450 parent_mark = self.revid_to_mark[p]
452 non_ghost_parents.append(b":%d" % parent_mark)451 non_ghost_parents.append(b":%s" % parent_mark)
453 except KeyError:452 except KeyError:
454 # ghost - ignore453 # ghost - ignore
455 continue454 continue
@@ -669,4 +668,4 @@
669 self.warning('not creating tag %r as its name would not be '668 self.warning('not creating tag %r as its name would not be '
670 'valid in git.', git_ref)669 'valid in git.', git_ref)
671 continue670 continue
672 self.print_cmd(commands.ResetCommand(git_ref, b":%d" % mark))671 self.print_cmd(commands.ResetCommand(git_ref, b":%s" % mark))
673672
=== modified file 'breezy/plugins/fastimport/marks_file.py'
--- breezy/plugins/fastimport/marks_file.py 2018-11-11 04:08:32 +0000
+++ breezy/plugins/fastimport/marks_file.py 2020-07-01 23:30:53 +0000
@@ -29,7 +29,7 @@
29 """29 """
30 # Check that the file is readable and in the right format30 # Check that the file is readable and in the right format
31 try:31 try:
32 f = open(filename, 'r')32 f = open(filename, 'rb')
33 except IOError:33 except IOError:
34 warning("Could not import marks file %s - not importing marks",34 warning("Could not import marks file %s - not importing marks",
35 filename)35 filename)
@@ -40,22 +40,22 @@
40 revision_ids = {}40 revision_ids = {}
4141
42 line = f.readline()42 line = f.readline()
43 if line == 'format=1\n':43 if line == b'format=1\n':
44 # Cope with old-style marks files44 # Cope with old-style marks files
45 # Read the branch info45 # Read the branch info
46 branch_names = {}46 branch_names = {}
47 for string in f.readline().rstrip('\n').split('\0'):47 for string in f.readline().rstrip(b'\n').split(b'\0'):
48 if not string:48 if not string:
49 continue49 continue
50 name, integer = string.rsplit('.', 1)50 name, integer = string.rsplit(b'.', 1)
51 branch_names[name] = int(integer)51 branch_names[name] = int(integer)
52 line = f.readline()52 line = f.readline()
5353
54 while line:54 while line:
55 line = line.rstrip('\n')55 line = line.rstrip(b'\n')
56 mark, revid = line.split(' ', 1)56 mark, revid = line.split(b' ', 1)
57 mark = mark.lstrip(':')57 mark = mark.lstrip(b':')
58 revision_ids[mark] = revid.encode('utf-8')58 revision_ids[mark] = revid
59 line = f.readline()59 line = f.readline()
60 finally:60 finally:
61 f.close()61 f.close()
@@ -69,7 +69,7 @@
69 :param revision_ids: dictionary mapping marks -> bzr revision-ids69 :param revision_ids: dictionary mapping marks -> bzr revision-ids
70 """70 """
71 try:71 try:
72 f = open(filename, 'w')72 f = open(filename, 'wb')
73 except IOError:73 except IOError:
74 warning("Could not open export-marks file %s - not exporting marks",74 warning("Could not open export-marks file %s - not exporting marks",
75 filename)75 filename)
@@ -77,8 +77,7 @@
7777
78 try:78 try:
79 # Write the revision info79 # Write the revision info
80 for mark in revision_ids:80 for mark, revid in sorted(revision_ids.items()):
81 f.write(':%s %s\n' % (mark.lstrip(b':').decode('utf-8'),81 f.write(b':%s %s\n' % (mark.lstrip(b':'), revid))
82 revision_ids[mark].decode('utf-8')))
83 finally:82 finally:
84 f.close()83 f.close()
8584
=== modified file 'breezy/plugins/fastimport/tests/__init__.py'
--- breezy/plugins/fastimport/tests/__init__.py 2018-11-11 04:08:32 +0000
+++ breezy/plugins/fastimport/tests/__init__.py 2020-07-01 23:30:53 +0000
@@ -46,6 +46,7 @@
46 'test_exporter',46 'test_exporter',
47 'test_branch_mapper',47 'test_branch_mapper',
48 'test_generic_processor',48 'test_generic_processor',
49 'test_marks_file',
49 'test_revision_store',50 'test_revision_store',
50 ]]51 ]]
51 loader = TestLoader()52 loader = TestLoader()
5253
=== added file 'breezy/plugins/fastimport/tests/test_marks_file.py'
--- breezy/plugins/fastimport/tests/test_marks_file.py 1970-01-01 00:00:00 +0000
+++ breezy/plugins/fastimport/tests/test_marks_file.py 2020-07-01 23:30:53 +0000
@@ -0,0 +1,45 @@
1# Copyright (C) 2020 Canonical Ltd
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16"""Test the marks file methods."""
17
18from __future__ import absolute_import
19
20from .... import tests
21
22from .. import marks_file
23
24
25class TestMarksFile(tests.TestCaseWithTransport):
26
27 def test_read(self):
28 self.build_tree_contents([('marks', """\
29:1 jelmer@jelmer-rev1
30:2 joe@example.com-rev2
31""")])
32 self.assertEqual({
33 b'1': b'jelmer@jelmer-rev1',
34 b'2': b'joe@example.com-rev2',
35 }, marks_file.import_marks('marks'))
36
37 def test_write(self):
38 marks_file.export_marks('marks', {
39 b'1': b'jelmer@jelmer-rev1',
40 b'2': b'joe@example.com-rev2',
41 })
42 self.assertFileEqual("""\
43:1 jelmer@jelmer-rev1
44:2 joe@example.com-rev2
45""", 'marks')

Subscribers

People subscribed via source and target branches