edgewall/trac

View on GitHub
trac/versioncontrol/cache.py

Summary

Maintainability
D
2 days
Test Coverage

File cache.py has 389 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2023 Edgewall Software
# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
# All rights reserved.
Severity: Minor
Found in trac/versioncontrol/cache.py - About 5 hrs to fix

    Function sync has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def sync(self, feedback=None, clean=False):
            if clean:
                self.remove_cache()
    
            metadata = self.metadata
    Severity: Minor
    Found in trac/versioncontrol/cache.py - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    CachedRepository has 31 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class CachedRepository(Repository):
    
        has_linear_changesets = False
    
        scope = property(lambda self: self.repos.scope)
    Severity: Minor
    Found in trac/versioncontrol/cache.py - About 3 hrs to fix

      Function normalize_rev has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def normalize_rev(self, rev):
              if rev is None or isinstance(rev, str) and \
                     rev.lower() in ('', 'head', 'latest', 'youngest'):
                  return self.rev_db(self.youngest_rev or 0)
              else:
      Severity: Minor
      Found in trac/versioncontrol/cache.py - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _get_changed_revs has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def _get_changed_revs(self, node_infos):
              if not node_infos:
                  return {}
      
              node_infos = [(node, self.normalize_rev(first)) for node, first
      Severity: Minor
      Found in trac/versioncontrol/cache.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function _next_prev_rev has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def _next_prev_rev(self, direction, rev, path=''):
              srev = self.db_rev(rev)
              with self.env.db_query as db:
                  # the changeset revs are sequence of ints:
                  sql = "SELECT %(aggr)s(rev) FROM %(tab)s " \
      Severity: Minor
      Found in trac/versioncontrol/cache.py - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function get_changes has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def get_changes(self, old_path, old_rev, new_path, new_rev,
      Severity: Minor
      Found in trac/versioncontrol/cache.py - About 35 mins to fix

        Function save_metadata has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def save_metadata(self, metadata):
                """Save the repository metadata."""
                with self.env.db_transaction as db:
                    invalidate = False
        
        
        Severity: Minor
        Found in trac/versioncontrol/cache.py - About 35 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            def rev_older_than(self, rev1, rev2):
                return self.repos.rev_older_than(self.normalize_rev(rev1),
                                                 self.normalize_rev(rev2))
        Severity: Minor
        Found in trac/versioncontrol/cache.py and 1 other location - About 30 mins to fix
        tracopt/versioncontrol/git/git_fs.py on lines 661..663

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 32.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status