1 # Copyright (C) 2009 Canonical Ltd
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 """Routines for reading/writing a marks file."""
20 from bzrlib
.trace
import warning
23 def import_marks(filename
):
24 """Read the mapping of marks to revision-ids from a file.
26 :param filename: the file to read from
27 :return: None if an error is encountered or a dictionary with marks
28 as keys and revision-ids as values
30 # Check that the file is readable and in the right format
34 warning("Could not import marks file %s - not importing marks",
38 # Read the revision info
42 if line
== 'format=1\n':
43 # Cope with old-style marks files
44 # Read the branch info
46 for string
in f
.readline().rstrip('\n').split('\0'):
49 name
, integer
= string
.rsplit('.', 1)
50 branch_names
[name
] = int(integer
)
54 line
= line
.rstrip('\n')
55 mark
, revid
= line
.split(' ', 1)
56 mark
= mark
.lstrip(':')
57 revision_ids
[mark
] = revid
63 def export_marks(filename
, revision_ids
):
64 """Save marks to a file.
66 :param filename: filename to save data to
67 :param revision_ids: dictionary mapping marks -> bzr revision-ids
70 f
= file(filename
, 'w')
72 warning("Could not open export-marks file %s - not exporting marks",
76 # Write the revision info
77 for mark
, revid
in revision_ids
.iteritems():
78 f
.write(':%s %s\n' % (str(mark
).lstrip(':'), revid
))