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 |
||
18 |
import os |
|
19 |
||
20 |
||
21 |
def save_id_map(filename, revision_ids): |
|
22 |
"""Save the mapping of commit ids to revision ids to a file. |
|
23 |
||
24 |
Throws the usual exceptions if the file cannot be opened,
|
|
25 |
written to or closed.
|
|
26 |
||
27 |
:param filename: name of the file to save the data to
|
|
28 |
:param revision_ids: a dictionary of commit ids to revision ids.
|
|
29 |
"""
|
|
|
6656.1.1
by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers |
30 |
with open(filename, 'wb') as f: |
31 |
for commit_id in revision_ids: |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
32 |
f.write(b"%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. |
33 |
|
34 |
||
35 |
def load_id_map(filename): |
|
36 |
"""Load the mapping of commit ids to revision ids from a file. |
|
37 |
||
38 |
If the file does not exist, an empty result is returned.
|
|
39 |
If the file does exists but cannot be opened, read or closed,
|
|
40 |
the normal exceptions are thrown.
|
|
41 |
||
42 |
NOTE: It is assumed that commit-ids do not have embedded spaces.
|
|
43 |
||
44 |
:param filename: name of the file to save the data to
|
|
45 |
:result: map, count where:
|
|
46 |
map = a dictionary of commit ids to revision ids;
|
|
47 |
count = the number of keys in map
|
|
48 |
"""
|
|
49 |
result = {} |
|
50 |
count = 0 |
|
51 |
if os.path.exists(filename): |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
52 |
with open(filename) as f: |
|
0.64.349
by Jelmer Vernooij
Reimport some modules removed from python-fastimport 0.9.2. |
53 |
for line in f: |
54 |
parts = line[:-1].split(' ', 1) |
|
55 |
result[parts[0]] = parts[1] |
|
56 |
count += 1 |
|
57 |
return result, count |