1
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
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 3 of the License, or
6
# (at your option) any later version.
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.
13
# You should have received a copy of the GNU General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
"""Utility functions for dealing with changes dictionaries as return by Subversions' log functions."""
18
def path_is_child(branch_path, path):
19
return (branch_path == "" or
20
branch_path == path or
21
path.startswith(branch_path+"/"))
24
def find_prev_location(paths, branch_path, revnum):
25
assert isinstance(paths, dict)
26
assert isinstance(branch_path, str)
27
assert isinstance(revnum, int)
29
assert branch_path == ""
31
# If there are no special cases, just go try the
32
# next revnum in history
36
return (branch_path, revnum)
38
# Make sure we get the right location for next time, if
39
# the branch itself was copied
40
if (paths.has_key(branch_path) and
41
paths[branch_path][0] in ('R', 'A')):
42
if paths[branch_path][1] is None:
43
return None # Was added here
44
revnum = paths[branch_path][2]
45
branch_path = paths[branch_path][1].encode("utf-8")
46
return (branch_path, revnum)
48
# Make sure we get the right location for the next time if
49
# one of the parents changed
51
# Path names need to be sorted so the longer paths
52
# override the shorter ones
53
for p in sorted(paths.keys(), reverse=True):
54
if paths[p][0] == 'M':
56
if branch_path.startswith(p+"/"):
57
assert paths[p][0] in ('A', 'R'), "Parent %r wasn't added" % p
58
assert paths[p][1] is not None, \
59
"Empty parent %r added, but child %r wasn't added !?" % (p, branch_path)
62
branch_path = paths[p][1].encode("utf-8") + branch_path[len(p):]
63
return (branch_path, revnum)
65
return (branch_path, revnum)
68
def changes_path(changes, path, parents=False):
69
"""Check if one of the specified changes applies
70
to path or one of its children.
72
:param parents: Whether to consider a parent moving a change.
75
assert isinstance(p, str)
76
if path_is_child(path, p):
78
if parents and path.startswith(p+"/") and changes[p][0] in ('R', 'A'):