~bzr/ubuntu/maverick/bzr-svn/bzr-ppa

« back to all changes in this revision

Viewing changes to changes.py

  • Committer: Jelmer Vernooij
  • Date: 2008-05-11 19:29:26 UTC
  • mfrom: (220.36.144 0.4)
  • Revision ID: jelmer@samba.org-20080511192926-7mh02j45r25qmzkz
Merge 0.4 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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/>.
 
15
 
 
16
"""Utility functions for dealing with changes dictionaries as return by Subversions' log functions."""
 
17
 
 
18
def path_is_child(branch_path, path):
 
19
    return (branch_path == "" or 
 
20
            branch_path == path or 
 
21
            path.startswith(branch_path+"/"))
 
22
 
 
23
 
 
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)
 
28
    if revnum == 0:
 
29
        assert branch_path == ""
 
30
        return None
 
31
    # If there are no special cases, just go try the 
 
32
    # next revnum in history
 
33
    revnum -= 1
 
34
 
 
35
    if branch_path == "":
 
36
        return (branch_path, revnum)
 
37
 
 
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)
 
47
    
 
48
    # Make sure we get the right location for the next time if 
 
49
    # one of the parents changed
 
50
 
 
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':
 
55
            continue
 
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)
 
60
 
 
61
            revnum = paths[p][2]
 
62
            branch_path = paths[p][1].encode("utf-8") + branch_path[len(p):]
 
63
            return (branch_path, revnum)
 
64
 
 
65
    return (branch_path, revnum)
 
66
 
 
67
 
 
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.
 
71
 
 
72
    :param parents: Whether to consider a parent moving a change.
 
73
    """
 
74
    for p in changes:
 
75
        assert isinstance(p, str)
 
76
        if path_is_child(path, p):
 
77
            return True
 
78
        if parents and path.startswith(p+"/") and changes[p][0] in ('R', 'A'):
 
79
            return True
 
80
    return False
 
81
 
 
82