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 assert isinstance(paths[branch_path][1], str)
46 branch_path = paths[branch_path][1]
47 return (branch_path, revnum)
49 # Make sure we get the right location for the next time if
50 # one of the parents changed
52 # Path names need to be sorted so the longer paths
53 # override the shorter ones
54 for p in sorted(paths.keys(), reverse=True):
55 if paths[p][0] == 'M':
57 if branch_path.startswith(p+"/"):
58 assert paths[p][0] in ('A', 'R'), "Parent %r wasn't added" % p
59 assert paths[p][1] is not None, \
60 "Empty parent %r added, but child %r wasn't added !?" % (p, branch_path)
63 branch_path = paths[p][1].encode("utf-8") + branch_path[len(p):]
64 return (branch_path, revnum)
66 return (branch_path, revnum)
69 def changes_path(changes, path, parents=False):
70 """Check if one of the specified changes applies
71 to path or one of its children.
73 :param parents: Whether to consider a parent moving a change.
76 assert isinstance(p, str)
77 if path_is_child(path, p):
79 if parents and path.startswith(p+"/") and changes[p][0] in ('R', 'A'):