bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.64.349
by Jelmer Vernooij
Reimport some modules removed from python-fastimport 0.9.2. |
1 |
# Copyright (C) 2008 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 |
"""Routines for saving and loading the id-map file."""
|
|
17 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
18 |
from __future__ import absolute_import |
19 |
||
|
0.64.349
by Jelmer Vernooij
Reimport some modules removed from python-fastimport 0.9.2. |
20 |
import os |
21 |
||
22 |
||
23 |
def save_id_map(filename, revision_ids): |
|
24 |
"""Save the mapping of commit ids to revision ids to a file. |
|
25 |
||
26 |
Throws the usual exceptions if the file cannot be opened,
|
|
27 |
written to or closed.
|
|
28 |
||
29 |
:param filename: name of the file to save the data to
|
|
30 |
:param revision_ids: a dictionary of commit ids to revision ids.
|
|
31 |
"""
|
|
|
6656.1.1
by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers |
32 |
with open(filename, 'wb') as f: |
33 |
for commit_id in revision_ids: |
|
34 |
f.write("%s %s\n" % (commit_id, revision_ids[commit_id])) |
|
|
0.64.349
by Jelmer Vernooij
Reimport some modules removed from python-fastimport 0.9.2. |
35 |
|
36 |
||
37 |
def load_id_map(filename): |
|
38 |
"""Load the mapping of commit ids to revision ids from a file. |
|
39 |
||
40 |
If the file does not exist, an empty result is returned.
|
|
41 |
If the file does exists but cannot be opened, read or closed,
|
|
42 |
the normal exceptions are thrown.
|
|
43 |
||
44 |
NOTE: It is assumed that commit-ids do not have embedded spaces.
|
|
45 |
||
46 |
:param filename: name of the file to save the data to
|
|
47 |
:result: map, count where:
|
|
48 |
map = a dictionary of commit ids to revision ids;
|
|
49 |
count = the number of keys in map
|
|
50 |
"""
|
|
51 |
result = {} |
|
52 |
count = 0 |
|
53 |
if os.path.exists(filename): |
|
54 |
f = open(filename) |
|
55 |
try: |
|
56 |
for line in f: |
|
57 |
parts = line[:-1].split(' ', 1) |
|
58 |
result[parts[0]] = parts[1] |
|
59 |
count += 1 |
|
60 |
finally: |
|
61 |
f.close() |
|
62 |
return result, count |