edgewall/trac

View on GitHub
tracopt/versioncontrol/git/git_fs.py

Summary

Maintainability
F
5 days
Test Coverage

File git_fs.py has 746 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Copyright (C) 2012-2023 Edgewall Software
# Copyright (C) 2006-2011, Herbert Valerio Riedel <hvr@gnu.org>
# All rights reserved.
Severity: Major
Found in tracopt/versioncontrol/git/git_fs.py - About 1 day to fix

    Function sync has a Cognitive Complexity of 54 (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 tracopt/versioncontrol/git/git_fs.py - About 1 day 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_repository has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_repository(self, type, dir, params):
            """GitRepository factory method"""
            assert type == 'git'
    
            if not (4 <= self.shortrev_len <= 40):
    Severity: Minor
    Found in tracopt/versioncontrol/git/git_fs.py - About 3 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

    GitRepository has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class GitRepository(Repository):
        """Git repository"""
    
        def __init__(self, env, path, params, log,
                     persistent_cache=False,
    Severity: Minor
    Found in tracopt/versioncontrol/git/git_fs.py - About 3 hrs to fix

      Function __init__ has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def __init__(self, repos, path, rev, log, ls_tree_info=None,
                       historian=None):
              self.log = log
              self.repos = repos
              self.fs_sha = None # points to either tree or blobs
      Severity: Minor
      Found in tracopt/versioncontrol/git/git_fs.py - About 2 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

      Function __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, env, path, params, log,
      Severity: Major
      Found in tracopt/versioncontrol/git/git_fs.py - About 1 hr to fix

        Function get_repositories has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_repositories(self):
                """Retrieve repositories specified in a `projects_list` file."""
                if not self.projects_list:
                    return
        
        
        Severity: Minor
        Found in tracopt/versioncontrol/git/git_fs.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 render_property has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def render_property(self, name, mode, context, props):
        
                def sha_link(sha, label=None):
                    # sha is assumed to be a non-abbreviated 40-chars sha id
                    try:
        Severity: Minor
        Found in tracopt/versioncontrol/git/git_fs.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 __init__ has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, repos, sha):
                if sha is None:
                    raise NoSuchChangeset(sha)
        
                try:
        Severity: Minor
        Found in tracopt/versioncontrol/git/git_fs.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_changes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_changes(self, old_path, old_rev, new_path, new_rev,
                            ignore_ancestry=0):
                # TODO: handle renames/copies, ignore_ancestry
                old_path = self.normalize_path(old_path)
                new_path = self.normalize_path(new_path)
        Severity: Minor
        Found in tracopt/versioncontrol/git/git_fs.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 get_changesets has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_changesets(self, start, stop):
                for key, csets in itertools.groupby(
                        CachedRepository.get_changesets(self, start, stop),
                        key=lambda cset: cset.date):
                    csets = list(csets)
        Severity: Minor
        Found in tracopt/versioncontrol/git/git_fs.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def __init__(self, repos, path, rev, log, ls_tree_info=None,
        Severity: Minor
        Found in tracopt/versioncontrol/git/git_fs.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  with open(description_path, 'r',
                                            encoding='utf-8') as fd:
                                      info['description'] = fd.read().strip()
                              if self.projects_url:
          Severity: Major
          Found in tracopt/versioncontrol/git/git_fs.py - About 45 mins to fix

            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 tracopt/versioncontrol/git/git_fs.py - About 35 mins to fix

              Function get_changes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_changes(self):
                      # Returns the differences against the first parent
                      parent = self.props.get('parent')
                      parent = parent[0] if parent else None
              
              
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py - About 25 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 sync has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def sync(self, rev_callback=None, clean=None):
                      if rev_callback:
                          revs = set(self.git.all_revs())
              
                      if self.persistent_cache:
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py - About 25 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 _last_iterable(iterable):
                  """helper for detecting last iteration in for-loop"""
                  i = iter(iterable)
                  try:
                      v = next(i)
              Severity: Major
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 2 hrs to fix
              trac/util/presentation.py on lines 437..463

              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 57.

              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

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

                          return tag.a(label, class_='changeset',
                                       title=shorten_line(changeset.message),
                                       href=formatter.href.changeset(sha, repos.reponame))
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 50 mins to fix
              tracopt/versioncontrol/git/git_fs.py on lines 440..442

              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 36.

              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

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

                              return tag.a(label, class_='changeset',
                                           title=shorten_line(cset.message),
                                           href=context.href.changeset(sha, repos.reponame))
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 50 mins to fix
              tracopt/versioncontrol/git/git_fs.py on lines 286..288

              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 36.

              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

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

                                  old_node = self._get_node(path, old_rev,
                                                            old_tree.get(path, False),
                                                            old_historian) \
                                             if change != Changeset.ADD else None
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 45 mins to fix
              tracopt/versioncontrol/git/git_fs.py on lines 642..645

              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 35.

              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

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

                                  new_node = self._get_node(path, new_rev,
                                                            new_tree.get(path, False),
                                                            new_historian) \
                                             if change != Changeset.DELETE else None
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 45 mins to fix
              tracopt/versioncontrol/git/git_fs.py on lines 638..641

              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 35.

              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

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

                      if not (4 <= self.shortrev_len <= 40):
                          raise TracError(_("%(option)s must be in the range [4..40]",
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 35 mins to fix
              tracopt/versioncontrol/git/git_fs.py on lines 358..359

              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 33.

              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

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

                      if not (4 <= self.wiki_shortrev_len <= 40):
                          raise TracError(_("%(option)s must be in the range [4..40]",
              Severity: Minor
              Found in tracopt/versioncontrol/git/git_fs.py and 1 other location - About 35 mins to fix
              tracopt/versioncontrol/git/git_fs.py on lines 354..355

              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 33.

              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

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

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

              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