blob: 207818b6ecfd98fc669e02f7e56f12febe0af7c6 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17"""
18Class to hold revisions, latest revision, etc., for a config node, used
19for the active committed revisions or revisions part of a transaction.
20"""
21
22from collections import OrderedDict
23from weakref import WeakValueDictionary
24
25
26class ConfigBranch(object):
27
28 __slots__ = (
29 '_node', # ref to node
30 '_txid', # txid for this branch (None for the committed branch)
31 '_origin', # _latest at time of branching on default branch
32 '_revs', # dict of rev-hash to ref of ConfigRevision
33 '_latest', # ref to latest committed ConfigRevision
34 '__weakref__'
35 )
36
37 def __init__(self, node, txid=None, origin=None, auto_prune=True):
38 self._node = node
39 self._txid = txid
40 self._origin = origin
41 self._revs = WeakValueDictionary() if auto_prune else OrderedDict()
42 self._latest = origin
43
44 def __getitem__(self, hash):
45 return self._revs[hash]
46
47 @property
48 def latest(self):
49 return self._latest
50
51 @property
52 def origin(self):
53 return self._origin