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

« back to all changes in this revision

Viewing changes to mapping3/scheme.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:
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
 
5
# the Free Software Foundation; either version 3 of the License, or
6
6
# (at your option) any later version.
7
7
 
8
8
# This program is distributed in the hope that it will be useful,
19
19
from bzrlib.errors import BzrError
20
20
from bzrlib.trace import mutter
21
21
 
 
22
from bzrlib.errors import NotBranchError
 
23
 
 
24
from base64 import urlsafe_b64decode, urlsafe_b64encode
22
25
from errors import InvalidSvnBranchPath
23
 
 
24
 
from base64 import urlsafe_b64decode, urlsafe_b64encode
 
26
import util
25
27
import bz2
26
 
 
27
 
def is_valid_property_name(prop):
28
 
    if not prop[0].isalnum() and not prop[0] in ":_":
29
 
        return False
30
 
    for c in prop[1:]:
31
 
        if not c.isalnum() and not c in "-:._":
32
 
            return False
33
 
    return True
34
 
 
35
 
 
36
 
 
37
 
 
38
 
class BranchingScheme:
 
28
import urllib
 
29
 
 
30
class BranchingScheme(object):
39
31
    """ Divides SVN repository data up into branches. Since there
40
32
    is no proper way to do this, there are several subclasses of this class
41
33
    each of which handles a particular convention that may be in use.
42
34
    """
43
 
    def __init__(self):
44
 
        pass
45
 
 
46
35
    def is_branch(self, path):
47
36
        """Check whether a location refers to a branch.
48
37
        
192
181
            if self._pattern_cmp(parts[:len(pattern)], pattern):
193
182
                return ("/".join(parts[:len(pattern)]), 
194
183
                        "/".join(parts[len(pattern):]))
195
 
        raise InvalidSvnBranchPath(path=path, scheme=self)
 
184
        raise InvalidSvnBranchPath(path, self)
196
185
 
197
186
    def __eq__(self, other):
198
187
        return self.branch_list == other.branch_list
282
271
        assert isinstance(path, str)
283
272
        parts = path.strip("/").split("/")
284
273
        if len(parts) == 0 or self.level >= len(parts):
285
 
            raise InvalidSvnBranchPath(path=path, scheme=self)
 
274
            raise InvalidSvnBranchPath(path, self)
286
275
 
287
276
        if parts[self.level] == "trunk" or parts[self.level] == "hooks":
288
277
            return ("/".join(parts[0:self.level+1]).strip("/"), 
292
281
            return ("/".join(parts[0:self.level+2]).strip("/"), 
293
282
                    "/".join(parts[self.level+2:]).strip("/"))
294
283
        else:
295
 
            raise InvalidSvnBranchPath(path=path, scheme=self)
 
284
            raise InvalidSvnBranchPath(path, self)
296
285
 
297
286
    def __str__(self):
298
287
        return "trunk%d" % self.level
343
332
        assert isinstance(path, str)
344
333
        path = path.strip("/")
345
334
        if not path.startswith(self.path):
346
 
            raise InvalidSvnBranchPath(path=path, scheme=self)
 
335
            raise InvalidSvnBranchPath(path, self)
347
336
 
348
337
        return (path[0:len(self.path)].strip("/"), 
349
338
                path[len(self.path):].strip("/"))
350
339
 
351
340
    def __str__(self):
352
 
        if is_valid_property_name(self.path):
 
341
        if util.is_valid_property_name(self.path):
353
342
            return "single-%s" % self.path
354
343
        else:
355
344
            return "single1-%s" % prop_name_quote(self.path)
437
426
                              relpath=None):
438
427
    """Try to determine the best fitting branching scheme.
439
428
 
440
 
    :param changed_paths: Iterator over (branch_path, changes, revnum)
441
 
        as returned from LogWalker.follow_path().
 
429
    :param changed_paths: Iterator over (branch_path, changes, revnum, revprops)
 
430
        as returned from LogWalker.iter_changes().
442
431
    :param last_revnum: Number of entries in changed_paths.
443
432
    :param relpath: Branch path that should be accepted by the branching 
444
433
                    scheme as a branch.
448
437
    pb = ui.ui_factory.nested_progress_bar()
449
438
    scheme_cache = {}
450
439
    try:
451
 
        for (bp, revpaths, revnum) in changed_paths:
 
440
        for (revpaths, revnum, revprops) in changed_paths:
452
441
            assert isinstance(revpaths, dict)
453
442
            pb.update("analyzing repository layout", last_revnum-revnum, 
454
443
                      last_revnum)