/breezy-svn/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy-svn/trunk
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
62
63
64
65
66
67
# Copyright (C) 2005-2009 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 2 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 __future__ import absolute_import

from breezy.sixish import text_type

from breezy.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("/").decode('utf-8'), 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, text_type) and (branch == u"" or not branch.startswith(u"/"))
    return b"%s:/%s:%d" % (uuid, branch.encode('utf-8'), revnum)


def estimate_svk_ancestors(fileprops):
    return len(fileprops.get(SVN_PROP_SVK_MERGE,"").splitlines())