/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
# Copyright (C) 2011 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/>.

"""Subversion revision graph access."""

from __future__ import absolute_import

from breezy import (
    errors as _mod_errors,
    graph as _mod_graph,
    revision as _mod_revision,
    )


class SubversionGraph(_mod_graph.Graph):

    def __init__(self, repository, parents_provider):
        super(SubversionGraph, self).__init__(parents_provider)
        self._revmeta_provider = repository._revmeta_provider

    def iter_lefthand_ancestry(self, start_key, stop_keys=None):
        """Iterate backwards through revision ids in the lefthand history

        :param start_key: The revision id to start with.  All its lefthand
            ancestors will be traversed.
        """
        if stop_keys is None:
            stop_keys = ()
        if _mod_revision.is_null(start_key):
            return
        try:
            foreign_revid, mapping = self._revmeta_provider.lookup_bzr_revision_id(start_key)
        except _mod_errors.NoSuchRevision:
            for key in super(SubversionGraph, self).iter_lefthand_ancestry(start_key,
                    stop_keys):
                yield key
            return
        (uuid, branch_path, revnum) = foreign_revid
        for revmeta, hidden, mapping in self._revmeta_provider._iter_reverse_revmeta_mapping_history(
                branch_path, revnum, to_revnum=0, mapping=mapping):
            if hidden:
                continue
            key = revmeta.get_revision_id(mapping)
            if key in stop_keys:
                return
            yield key