/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/mutabletree.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-12 15:55:26 UTC
  • mto: (4679.5.3 2.1-static-tuple-no-use)
  • mto: This revision was merged to the branch mainline in revision 4735.
  • Revision ID: john@arbash-meinel.com-20091012155526-b46tuz5cibebbnct
Change the _lookup function to use Quadratic Probing.

The main strength is that we get a bit of locality (collision resolution
looks quickly close to the location.)
The main weakness is that we don't use the upper bits of the hash to
induce divergence. So while we nicely handle collisions in neighboring
buckets (Quadratic means their resolution chains will diverge), if
two objects hash to the same bucket, their resolution chains are identical.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
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
233
233
        raise NotImplementedError(self._gather_kinds)
234
234
 
235
235
    @needs_read_lock
236
 
    def has_changes(self, _from_tree=None):
237
 
        """Quickly check that the tree contains at least one commitable change.
238
 
 
239
 
        :param _from_tree: tree to compare against to find changes (default to
240
 
            the basis tree and is intended to be used by tests).
 
236
    def has_changes(self, from_tree):
 
237
        """Quickly check that the tree contains at least one change.
241
238
 
242
239
        :return: True if a change is found. False otherwise
243
240
        """
244
 
        # Check pending merges
245
 
        if len(self.get_parent_ids()) > 1:
246
 
            return True
247
 
        if _from_tree is None:
248
 
            _from_tree = self.basis_tree()
249
 
        changes = self.iter_changes(_from_tree)
 
241
        changes = self.iter_changes(from_tree)
250
242
        try:
251
243
            change = changes.next()
252
244
            # Exclude root (talk about black magic... --vila 20090629)
258
250
            return False
259
251
 
260
252
    @needs_read_lock
261
 
    def check_changed_or_out_of_date(self, strict, opt_name,
262
 
                                     more_error, more_warning):
263
 
        """Check the tree for uncommitted changes and branch synchronization.
264
 
 
265
 
        If strict is None and not set in the config files, a warning is issued.
266
 
        If strict is True, an error is raised.
267
 
        If strict is False, no checks are done and no warning is issued.
268
 
 
269
 
        :param strict: True, False or None, searched in branch config if None.
270
 
 
271
 
        :param opt_name: strict option name to search in config file.
272
 
 
273
 
        :param more_error: Details about how to avoid the check.
274
 
 
275
 
        :param more_warning: Details about what is happening.
276
 
        """
277
 
        if strict is None:
278
 
            strict = self.branch.get_config().get_user_option_as_bool(opt_name)
279
 
        if strict is not False:
280
 
            err_class = None
281
 
            if (self.has_changes()):
282
 
                err_class = errors.UncommittedChanges
283
 
            elif self.last_revision() != self.branch.last_revision():
284
 
                # The tree has lost sync with its branch, there is little
285
 
                # chance that the user is aware of it but he can still force
286
 
                # the action with --no-strict
287
 
                err_class = errors.OutOfDateTree
288
 
            if err_class is not None:
289
 
                if strict is None:
290
 
                    err = err_class(self, more=more_warning)
291
 
                    # We don't want to interrupt the user if he expressed no
292
 
                    # preference about strict.
293
 
                    trace.warning('%s', err._format())
294
 
                else:
295
 
                    err = err_class(self, more=more_error)
296
 
                    raise err
297
 
 
298
 
    @needs_read_lock
299
253
    def last_revision(self):
300
254
        """Return the revision id of the last commit performed in this tree.
301
255
 
418
372
 
419
373
        if not file_list:
420
374
            # no paths supplied: add the entire tree.
421
 
            # FIXME: this assumes we are running in a working tree subdir :-/
422
 
            # -- vila 20100208
423
375
            file_list = [u'.']
424
376
        # mutter("smart add of %r")
425
377
        inv = self.inventory
427
379
        ignored = {}
428
380
        dirs_to_add = []
429
381
        user_dirs = set()
430
 
        conflicts_related = set()
431
 
        # Not all mutable trees can have conflicts
432
 
        if getattr(self, 'conflicts', None) is not None:
433
 
            # Collect all related files without checking whether they exist or
434
 
            # are versioned. It's cheaper to do that once for all conflicts
435
 
            # than trying to find the relevant conflict for each added file.
436
 
            for c in self.conflicts():
437
 
                conflicts_related.update(c.associated_filenames())
438
382
 
439
383
        # validate user file paths and convert all paths to tree
440
384
        # relative : it's cheaper to make a tree relative path an abspath
501
445
            if illegalpath_re.search(directory.raw_path):
502
446
                trace.warning("skipping %r (contains \\n or \\r)" % abspath)
503
447
                continue
504
 
            if directory.raw_path in conflicts_related:
505
 
                # If the file looks like one generated for a conflict, don't
506
 
                # add it.
507
 
                trace.warning(
508
 
                    'skipping %s (generated to help resolve conflicts)',
509
 
                    abspath)
510
 
                continue
511
448
 
512
449
            if parent_ie is not None:
513
450
                versioned = directory.base_path in parent_ie.children