~bzr/ubuntu/intrepid/bzr-svn/bzr-ppa

« back to all changes in this revision

Viewing changes to mapping3/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-25 21:07:15 UTC
  • mfrom: (309.1.2 debian)
  • Revision ID: john@arbash-meinel.com-20080825210715-gjow5e72oo981g23
Merge in Jelmer's latest updates to bzr-svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
                             guess_scheme_from_history, ListBranchingScheme, 
26
26
                             parse_list_scheme_text, NoBranchingScheme,
27
27
                             TrunkBranchingScheme, ListBranchingScheme)
 
28
from bzrlib.plugins.svn.ra import DIRENT_KIND
28
29
import sha
29
30
 
30
31
SVN_PROP_BZR_BRANCHING_SCHEME = 'bzr:branching-scheme'
32
33
# Number of revisions to evaluate when guessing the branching scheme
33
34
SCHEME_GUESS_SAMPLE_SIZE = 2000
34
35
 
35
 
def expand_branch_pattern(begin, todo, check_path, get_children):
 
36
def expand_branch_pattern(begin, todo, check_path, get_children, project=None):
36
37
    """Find the paths in the repository that match the expected branch pattern.
37
38
 
38
39
    :param begin: List of path elements currently opened.
42
43
    """
43
44
    mutter('expand branches: %r, %r', begin, todo)
44
45
    path = "/".join(begin)
 
46
    if (project is not None and 
 
47
        not project.startswith(path) and 
 
48
        not path.startswith(project)):
 
49
        return []
45
50
    # If all elements have already been handled, just check the path exists
46
51
    if len(todo) == 0:
47
52
        if check_path(path):
50
55
            return []
51
56
    # Not a wildcard? Just expand next bits
52
57
    if todo[0] != "*":
53
 
        return expand_branch_pattern(begin+[todo[0]], todo[1:], check_path, get_children)
 
58
        return expand_branch_pattern(begin+[todo[0]], todo[1:], check_path, 
 
59
                                     get_children, project)
54
60
    children = get_children(path)
55
61
    if children is None:
56
62
        return []
63
69
                # Last path element, so return directly
64
70
                ret.append("/".join(begin+[c]))
65
71
            else:
66
 
                ret += expand_branch_pattern(begin+[c], todo[1:], check_path, get_children)
 
72
                ret += expand_branch_pattern(begin+[c], todo[1:], check_path, 
 
73
                                             get_children, project)
67
74
    finally:
68
75
        pb.finished()
69
76
    return ret
82
89
            type = "branch"
83
90
        return (type, proj, bp, rp)
84
91
 
85
 
    def _get_root_paths(self, revnum, verify_fn, project="", pb=None):
 
92
    def _get_root_paths(self, itemlist, revnum, verify_fn, project=None, pb=None):
86
93
        def check_path(path):
87
94
            return self.repository.transport.check_path(path, revnum) == NODE_DIR
88
95
        def find_children(path):
89
96
            try:
90
97
                assert not path.startswith("/")
91
 
                dirents = self.repository.transport.get_dir(path, revnum)[0]
 
98
                dirents = self.repository.transport.get_dir(path, revnum, DIRENT_KIND)[0]
92
99
            except SubversionException, (msg, num):
93
100
                if num in (ERR_FS_NOT_DIRECTORY, ERR_FS_NOT_FOUND, ERR_RA_DAV_PATH_NOT_FOUND):
94
101
                    return None
95
102
                raise
96
 
            return dirents.keys()
 
103
            return [d for d in dirents if dirents[d]['kind'] == NODE_DIR]
97
104
 
98
 
        for idx, pattern in enumerate(self.scheme.branch_list):
 
105
        for idx, pattern in enumerate(itemlist):
99
106
            if pb is not None:
100
 
                pb.update("finding branches", idx, len(self.scheme.branch_list))
 
107
                pb.update("finding branches", idx, len(itemlist))
101
108
            for bp in expand_branch_pattern([], pattern.split("/"), check_path,
102
 
                    find_children):
103
 
                if verify_fn(bp):
 
109
                    find_children, project):
 
110
                if verify_fn(bp, project):
104
111
                    yield "", bp, bp.split("/")[-1]
105
112
 
106
 
    def get_branches(self, revnum, project="", pb=None):
107
 
        return self._get_root_paths(revnum, self.scheme.is_branch, project, pb)
 
113
    def get_branches(self, revnum, project=None, pb=None):
 
114
        return self._get_root_paths(self.scheme.branch_list, revnum, self.scheme.is_branch, project, pb)
108
115
 
109
 
    def get_tags(self, revnum, project="", pb=None):
110
 
        return self._get_root_paths(revnum, self.scheme.is_tag, project, pb)
 
116
    def get_tags(self, revnum, project=None, pb=None):
 
117
        return self._get_root_paths(self.scheme.tag_list, revnum, self.scheme.is_tag, project, pb)
111
118
 
112
119
    def get_tag_path(self, name, project=""):
113
120
        return self.scheme.get_tag_path(name, project)
118
125
    def get_branch_path(self, name, project=""):
119
126
        return self.scheme.get_branch_path(name, project)
120
127
 
121
 
    def is_branch_parent(self, path):
 
128
    def is_branch_parent(self, path, project=None):
122
129
        # Na, na, na...
123
 
        return self.scheme.is_branch_parent(path)
 
130
        return self.scheme.is_branch_parent(path, project)
124
131
 
125
 
    def is_tag_parent(self, path):
 
132
    def is_tag_parent(self, path, project=None):
126
133
        # Na, na, na...
127
 
        return self.scheme.is_tag_parent(path)
 
134
        return self.scheme.is_tag_parent(path, project)
128
135
 
129
136
    def push_merged_revisions(self, project=""):
130
137
        try:
295
302
        return (uuid, branch_path, srevnum, cls(scheme))
296
303
 
297
304
    def is_branch(self, branch_path):
298
 
        return (self.scheme.is_branch(branch_path) or 
299
 
                self.scheme.is_tag(branch_path))
 
305
        return self.scheme.is_branch(branch_path)
300
306
 
301
307
    def is_tag(self, tag_path):
302
308
        return self.scheme.is_tag(tag_path)
324
330
 
325
331
 
326
332
class BzrSvnMappingv3FileProps(mapping.BzrSvnMappingFileProps, BzrSvnMappingv3):
327
 
    pass
 
333
 
 
334
    def __init__(self, scheme, guessed_scheme=None):
 
335
        mapping.BzrSvnMappingFileProps.__init__(self, scheme, guessed_scheme)
 
336
        BzrSvnMappingv3.__init__(self, scheme, guessed_scheme)
 
337
        self.revprop_map = mapping.BzrSvnMappingRevProps()
 
338
 
 
339
    def export_text_parents(self, can_use_custom_revprops, text_parents, svn_revprops, fileprops):
 
340
        mapping.BzrSvnMappingFileProps.export_text_parents(self, can_use_custom_revprops, text_parents, svn_revprops, fileprops)
 
341
        if can_use_custom_revprops:
 
342
            self.revprop_map.export_text_parents(can_use_custom_revprops, text_parents, svn_revprops, fileprops)
 
343
 
 
344
    def export_revision(self, can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, revision_id, revno, merges, old_fileprops):
 
345
        (_, fileprops) = mapping.BzrSvnMappingFileProps.export_revision(self, can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, revision_id, revno, merges, old_fileprops)
 
346
        if can_use_custom_revprops:
 
347
            (revprops, _) = self.revprop_map.export_revision(can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, None, revno, merges, old_fileprops)
 
348
        return (revprops, fileprops)
 
349
 
 
350
    def export_fileid_map(self, can_use_custom_revprops, fileids, revprops, fileprops):
 
351
        mapping.BzrSvnMappingFileProps.export_fileid_map(self, can_use_custom_revprops, fileids, revprops, fileprops)
 
352
        if can_use_custom_revprops:
 
353
            self.revprop_map.export_fileid_map(can_use_custom_revprops, fileids, revprops, fileprops)
 
354
 
 
355
    def export_message(self, can_use_custom_revprops, log, revprops, fileprops):
 
356
        mapping.BzrSvnMappingFileProps.export_message(self, can_use_custom_revprops, log, revprops, fileprops)
 
357
        if can_use_custom_revprops:
 
358
            self.revprop_map.export_message(can_use_custom_revprops, log, revprops, fileprops)
328
359
 
329
360
 
330
361
class BzrSvnMappingv3RevProps(mapping.BzrSvnMappingRevProps, BzrSvnMappingv3):
331
 
    pass
 
362
    def export_revision(self, can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, revision_id, revno, merges, fileprops):
 
363
        (revprops, fileprops) = mapping.BzrSvnMappingRevProps.export_revision(self, can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, revision_id, revno, merges, fileprops)
 
364
        revprops[mapping.SVN_REVPROP_BZR_MAPPING_VERSION] = "3"
 
365
        return (revprops, fileprops)
332
366
 
333
367
 
334
368
class BzrSvnMappingv3Hybrid(BzrSvnMappingv3):
361
395
        else:
362
396
            return self.fileprops.import_fileid_map(svn_revprops, fileprops)
363
397
 
364
 
    def export_revision(self, branch_root, timestamp, timezone, committer, revprops, revision_id, 
 
398
    def export_revision(self, can_use_custom_revprops, branch_root, timestamp, timezone, committer, revprops, revision_id, 
365
399
                        revno, merges, fileprops):
366
 
        (_, fileprops) = self.fileprops.export_revision(branch_root, timestamp, timezone, committer, 
 
400
        (_, fileprops) = self.fileprops.export_revision(can_use_custom_revprops, branch_root, timestamp, timezone, committer, 
367
401
                                      revprops, revision_id, revno, merges, fileprops)
368
 
        (revprops, _) = self.revprops.export_revision(branch_root, timestamp, timezone, committer, 
 
402
        (revprops, _) = self.revprops.export_revision(can_use_custom_revprops, branch_root, timestamp, timezone, committer, 
369
403
                                      revprops, revision_id, revno, merges, fileprops)
370
404
        return (revprops, fileprops)
371
405
 
372
 
    def export_fileid_map(self, fileids, revprops, fileprops):
373
 
        self.fileprops.export_fileid_map(fileids, revprops, fileprops)
374
 
        self.revprops.export_fileid_map(fileids, revprops, fileprops)
 
406
    def export_fileid_map(self, can_use_custom_revprops, fileids, revprops, fileprops):
 
407
        self.fileprops.export_fileid_map(can_use_custom_revprops, fileids, revprops, fileprops)
 
408
        self.revprops.export_fileid_map(can_use_custom_revprops, fileids, revprops, fileprops)
375
409
 
376
 
    def export_text_parents(self, text_parents, revprops, fileprops):
377
 
        self.fileprops.export_text_parents(text_parents, revprops, fileprops)
378
 
        self.revprops.export_text_parents(text_parents, revprops, fileprops)
 
410
    def export_text_parents(self, can_use_custom_revprops, text_parents, revprops, fileprops):
 
411
        self.fileprops.export_text_parents(can_use_custom_revprops, text_parents, revprops, fileprops)
 
412
        self.revprops.export_text_parents(can_use_custom_revprops, text_parents, revprops, fileprops)
379
413
 
380
414
    def import_revision(self, svn_revprops, fileprops, uuid, branch, revnum, rev):
381
415
        self.fileprops.import_revision(svn_revprops, fileprops, uuid, branch, revnum, rev)