bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.252.1
by Jelmer Vernooij
Support storing revision id data. |
1 |
# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
|
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, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Roundtripping support."""
|
|
18 |
||
19 |
||
20 |
from cStringIO import StringIO |
|
21 |
||
22 |
||
23 |
class BzrGitRevisionMetadata(object): |
|
24 |
"""Metadata for a Bazaar revision roundtripped into Git. |
|
25 |
|
|
26 |
:ivar revision_id: Revision id, as string
|
|
27 |
:ivar properties: Revision properties, as dictionary
|
|
28 |
:ivar file_ids: File ids, as map from path -> file id
|
|
29 |
"""
|
|
30 |
||
31 |
revision_id = None |
|
32 |
||
33 |
file_ids = {} |
|
34 |
||
35 |
properties = {} |
|
36 |
||
|
0.252.2
by Jelmer Vernooij
Add functions for adding metadata to revision messages. |
37 |
def __nonzero__(self): |
38 |
return (self.revision_id is None or self.file_ids or self.properties) |
|
39 |
||
|
0.252.1
by Jelmer Vernooij
Support storing revision id data. |
40 |
|
41 |
def parse_roundtripping_metadata(text): |
|
42 |
"""Parse Bazaar roundtripping metadata.""" |
|
43 |
ret = BzrGitRevisionMetadata() |
|
44 |
f = StringIO(text) |
|
45 |
for l in f.readlines(): |
|
46 |
(key, value) = l.split(":", 1) |
|
47 |
if key == "revision-id": |
|
48 |
ret.revision_id = value.strip() |
|
49 |
else: |
|
50 |
raise ValueError |
|
51 |
return ret |
|
|
0.252.2
by Jelmer Vernooij
Add functions for adding metadata to revision messages. |
52 |
|
53 |
||
54 |
def generate_roundtripping_metadata(metadata): |
|
55 |
"""Serialize the roundtripping metadata. |
|
56 |
||
57 |
:param metadata: A `BzrGitRevisionMetadata` instance
|
|
58 |
:return: String with revision metadata
|
|
59 |
"""
|
|
60 |
return "revision-id: %s\n" % metadata.revision_id |
|
61 |
||
62 |
||
63 |
def extract_bzr_metadata(message): |
|
64 |
"""Extract Bazaar metadata from a commit message. |
|
65 |
||
66 |
:param message: Commit message to extract from
|
|
67 |
:return: Tuple with original commit message and metadata object
|
|
68 |
"""
|
|
69 |
split = message.split("\n--BZR--\n", 1) |
|
70 |
if len(split) != 2: |
|
71 |
return message, None |
|
72 |
return split[0], parse_roundtripping_metadata(split[1]) |
|
73 |
||
74 |
||
75 |
def inject_bzr_metadata(message, metadata): |
|
76 |
if metadata is None: |
|
77 |
return message |
|
78 |
return message + "\n--BZR--\n" + generate_roundtripping_metadata(metadata) |