~gagern/bzr-svn/bug242321

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright (C) 2005-2008 Jelmer Vernooij <jelmer@samba.org>
 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Utility functions for dealing with SVK properties."""

from bzrlib.plugins.svn import errors

SVN_PROP_SVK_MERGE = 'svk:merge'

# Some previous versions of svk occasionally recorded a merge ticket which
# contained a line containing only two colons. This is used to filter them out
filter_svk_merge_ticket = lambda line: line != '::'

parse_svk_features = lambda text: set(filter(filter_svk_merge_ticket, text.splitlines()))

serialize_svk_features = lambda features: "".join([x+"\n" for x in sorted(features)])

def svk_features_merged_since(new_text, old_text=""):
    return parse_svk_features(new_text).difference(parse_svk_features(old_text))


def parse_svk_feature(feature):
    """Parse a svk feature identifier.

    :param feature: The feature identifier as string.
    :return: tuple with uuid, branch path and revnum
    """
    try:
        (uuid, branch, revnum) = feature.split(":", 3)
    except ValueError:
        raise errors.InvalidPropertyValue(SVN_PROP_SVK_MERGE, 
                "not enough colons")
    return (uuid, branch.strip("/"), int(revnum))


def generate_svk_feature(uuid, branch, revnum):
    """Create a SVK feature identifier.

    :param uuid: Subversion repository UUID
    :param branch: Branch path
    :param revnum: Revision number
    :return: Matching SVK feature identifier.
    """
    assert isinstance(revnum, int)
    assert isinstance(uuid, str)
    assert isinstance(branch, str) and (branch == "" or branch[0] != "/")
    return "%s:/%s:%d" % (uuid, branch, revnum)