~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/file_names.py

  • Committer: Robert Collins
  • Date: 2007-08-06 05:47:32 UTC
  • mto: (2592.3.81 repository)
  • mto: This revision was merged to the branch mainline in revision 2933.
  • Revision ID: robertc@robertcollins.net-20070806054732-0w8j16bf4upvt2nu
Change file_names allocation to be done by the user, not the FileNames class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    The save method must be called to cause the state to be saved to the
41
41
    transport.
42
42
 
43
 
    Finally, load is used to obtain a previously saved set.
 
43
    The load method is used to obtain a previously saved set.
 
44
 
 
45
    There is a cap in the _cap method which will error if more names are
 
46
    added than the names collection can sensibly manage. Currently this
 
47
    cap is 10000.
44
48
    """
45
49
 
46
50
    def __init__(self, transport, index_name):
50
54
        self._names = None
51
55
        self._cap = 10000
52
56
 
53
 
    def allocate(self):
54
 
        for number in xrange(self._cap):
55
 
            if str(number) not in self._names:
56
 
                self._names.add(str(number))
57
 
                return str(number)
58
 
        raise errors.BzrError('too many files')
 
57
    def allocate(self, name=None):
 
58
        """Allocate name in the names collection.
 
59
 
 
60
        :param name: The name to allocate.
 
61
        """
 
62
        if name is not None:
 
63
            if len(self._names) >= self._cap:
 
64
                raise errors.BzrError('too many files')
 
65
            self._names.add(name)
 
66
            return name
59
67
 
60
68
    def initialise(self):
61
69
        """Initialise the collection."""