~maxb/bzr-svn/fetch-svn-rev-info-progress-bar

« back to all changes in this revision

Viewing changes to mapping3/scheme.py

  • Committer: Max Bowsher
  • Date: 2010-07-30 22:50:54 UTC
  • mfrom: (3324.1.37 trunk)
  • Revision ID: maxb@f2s.com-20100730225054-un1llcngdofg585w
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
class InvalidSvnBranchPath(BzrError):
43
43
    """Error raised when a path was specified that is not a child of or itself
44
44
    a valid branch path in the current branching scheme."""
45
 
    _fmt = """%(path)s is not a valid Subversion branch path in the current 
 
45
    _fmt = """%(path)s is not a valid Subversion branch path in the current
46
46
repository layout. See 'bzr help svn-repository-layout' for details."""
47
47
 
48
48
    def __init__(self, path, layout):
59
59
    """
60
60
    def is_branch(self, path, project=None):
61
61
        """Check whether a location refers to a branch.
62
 
        
 
62
 
63
63
        :param path: Path to check.
64
64
        """
65
65
        raise NotImplementedError
119
119
    def is_branch_parent(self, path, project=None):
120
120
        """Check whether the specified path is the parent directory of branches.
121
121
        The path may not be a branch itself.
122
 
        
 
122
 
123
123
        :param path: path to check
124
124
        :returns: boolean
125
125
        """
128
128
    def is_tag_parent(self, path, project=None):
129
129
        """Check whether the specified path is the parent directory of tags.
130
130
        The path may not be a tag itself.
131
 
        
 
131
 
132
132
        :param path: path to check
133
133
        :returns: boolean
134
134
        """
135
135
        raise NotImplementedError
136
136
 
137
137
    def is_tag(self, path, project=None):
138
 
        """Check whether the specified path is a tag 
 
138
        """Check whether the specified path is a tag
139
139
        according to this branching scheme.
140
140
 
141
141
        :param path: path to check
146
146
    def to_lines(self):
147
147
        """Generate a list of lines for this branching scheme.
148
148
 
149
 
        :return: List of lines representing the data in this branching 
 
149
        :return: List of lines representing the data in this branching
150
150
            scheme.
151
151
        """
152
152
        raise NotImplementedError(self.to_lines)
175
175
 
176
176
 
177
177
class ListBranchingScheme(BranchingScheme):
178
 
    """Branching scheme that keeps a list of branch paths, including 
 
178
    """Branching scheme that keeps a list of branch paths, including
179
179
    wildcards."""
180
180
    def __init__(self, branch_list, tag_list=[]):
181
181
        """Create new ListBranchingScheme instance.
191
191
 
192
192
    def __str__(self):
193
193
        return "list-%s" % prop_name_quote(bz2.compress("".join(map(lambda x:x+"\n", self.branch_list))))
194
 
            
 
194
 
195
195
    def is_tag(self, path, project=None):
196
196
        """See BranchingScheme.is_tag()."""
197
197
        return False
219
219
        parts = path.strip("/").split("/")
220
220
        for pattern in self.split_branch_list:
221
221
            if self._pattern_cmp(parts[:len(pattern)], pattern):
222
 
                return ("/".join(parts[:len(pattern)]), 
223
 
                        "/".join(parts[:len(pattern)]), 
 
222
                return ("/".join(parts[:len(pattern)]),
 
223
                        "/".join(parts[:len(pattern)]),
224
224
                        "/".join(parts[len(pattern):]))
225
225
        raise InvalidSvnBranchPath(path, self)
226
226
 
249
249
 
250
250
 
251
251
class NoBranchingScheme(ListBranchingScheme):
252
 
    """Describes a scheme where there is just one branch, the 
 
252
    """Describes a scheme where there is just one branch, the
253
253
    root of the repository."""
254
254
    def __init__(self):
255
255
        ListBranchingScheme.__init__(self, [""])
282
282
 
283
283
 
284
284
class TrunkBranchingScheme(ListBranchingScheme):
285
 
    """Standard Subversion repository layout. 
286
 
    
287
 
    Each project contains three directories `trunk`, `tags` and `branches`. 
 
285
    """Standard Subversion repository layout.
 
286
 
 
287
    Each project contains three directories `trunk`, `tags` and `branches`.
288
288
    """
289
289
    def __init__(self, level=0):
290
290
        self.level = level
349
349
 
350
350
        if parts[self.level] == "trunk" or parts[self.level] == "hooks":
351
351
            return ("/".join(parts[0:self.level]).strip("/"),
352
 
                    "/".join(parts[0:self.level+1]).strip("/"), 
 
352
                    "/".join(parts[0:self.level+1]).strip("/"),
353
353
                    "/".join(parts[self.level+1:]).strip("/"))
354
 
        elif ((parts[self.level] == "tags" or parts[self.level] == "branches") and 
 
354
        elif ((parts[self.level] == "tags" or parts[self.level] == "branches") and
355
355
              len(parts) >= self.level+2):
356
356
            return ("/".join(parts[0:self.level]).strip("/"),
357
 
                    "/".join(parts[0:self.level+2]).strip("/"), 
 
357
                    "/".join(parts[0:self.level+2]).strip("/"),
358
358
                    "/".join(parts[self.level+2:]).strip("/"))
359
359
        else:
360
360
            raise InvalidSvnBranchPath(path, self)
410
410
        if not path.startswith(self.path):
411
411
            raise InvalidSvnBranchPath(path, self)
412
412
 
413
 
        return (self.path, 
414
 
                path[0:len(self.path)].strip("/"), 
 
413
        return (self.path,
 
414
                path[0:len(self.path)].strip("/"),
415
415
                path[len(self.path):].strip("/"))
416
416
 
417
417
    def __str__(self):
461
461
 
462
462
 
463
463
def guess_scheme_from_path(relpath):
464
 
    """Try to guess the branching scheme from a path in the repository, 
 
464
    """Try to guess the branching scheme from a path in the repository,
465
465
    not necessarily a branch path.
466
466
 
467
467
    :param relpath: Relative path in repository
477
477
    return NoBranchingScheme()
478
478
 
479
479
 
480
 
def guess_scheme_from_history(changed_paths, last_revnum, 
 
480
def guess_scheme_from_history(changed_paths, last_revnum,
481
481
                              relpath=None):
482
482
    """Try to determine the best fitting branching scheme.
483
483
 
484
484
    :param changed_paths: Iterator over (branch_path, changes, revnum, revprops)
485
485
        as returned from LogWalker.iter_changes().
486
486
    :param last_revnum: Number of entries in changed_paths.
487
 
    :param relpath: Branch path that should be accepted by the branching 
 
487
    :param relpath: Branch path that should be accepted by the branching
488
488
                    scheme as a branch.
489
 
    :return: Tuple with branching scheme that best matches history and 
 
489
    :return: Tuple with branching scheme that best matches history and
490
490
             branching scheme instance that best matches but also considers
491
491
             relpath a valid branch path.
492
492
    """
496
496
    try:
497
497
        for (revpaths, revnum, revprops) in changed_paths:
498
498
            assert isinstance(revpaths, dict)
499
 
            pb.update("analyzing repository layout", last_revnum-revnum, 
 
499
            pb.update("analyzing repository layout", last_revnum-revnum,
500
500
                      last_revnum)
501
501
            if revpaths == {}:
502
502
                continue
508
508
                scheme_cache[str(scheme)] = scheme
509
509
    finally:
510
510
        pb.finished()
511
 
    
 
511
 
512
512
    entries = potentials.items()
513
513
    entries.sort(lambda (a, b), (c, d): d - b)
514
514
 
542
542
        return NoBranchingScheme()
543
543
    if branch_list == TrunkBranchingScheme(0).branch_list:
544
544
        return TrunkBranchingScheme(0)
545
 
    return ListBranchingScheme(branch_list) 
 
545
    return ListBranchingScheme(branch_list)
546
546
 
547
547
 
548
548
def scheme_from_layout(layout):
564
564
            repository._log.iter_changes(None, last_revnum, max(0, last_revnum-GUESS_SAMPLE_SIZE)), last_revnum, branch_path)
565
565
    finally:
566
566
        pb.finished()
567
 
    mutter("Guessed branching scheme: %r, guess scheme to use: %r" % 
 
567
    mutter("Guessed branching scheme: %r, guess scheme to use: %r" %
568
568
            (guessed_scheme, scheme))
569
569
    return (guessed_scheme, scheme)
570
570