gitlabhq/grit

View on GitHub
lib/grit/git-ruby/repository.rb

Summary

Maintainability
F
1 wk
Test Coverage

File repository.rb has 589 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'grit/git-ruby/internal/raw_object'
require 'grit/git-ruby/internal/pack'
require 'grit/git-ruby/internal/loose'
require 'grit/git-ruby/git_object'

Severity: Major
Found in lib/grit/git-ruby/repository.rb - About 1 day to fix

    Method diff has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

          def diff(commit1, commit2, options = {})
            patch = ''
    
            commit_obj1 = get_object_by_sha1(commit1)
            tree1 = commit_obj1.tree
    Severity: Minor
    Found in lib/grit/git-ruby/repository.rb - About 7 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

    Method walk_log has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

          def walk_log(sha, opts, total_size = 0)
            return [] if @already_searched[sha] # to prevent rechecking branches
            @already_searched[sha] = true
    
            array = []
    Severity: Minor
    Found in lib/grit/git-ruby/repository.rb - About 6 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

    Method ls_tree_path has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

          def ls_tree_path(sha, path, append = nil)
            tree = get_raw_tree(sha)
            if path =~ /\//
              paths = path.split('/')
              last = path[path.size - 1, 1]
    Severity: Minor
    Found in lib/grit/git-ruby/repository.rb - About 5 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

    Class Repository has 42 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Repository
    
          class NoSuchShaFound < StandardError
          end
    
    
    Severity: Minor
    Found in lib/grit/git-ruby/repository.rb - About 5 hrs to fix

      Method quick_diff has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

            def quick_diff(tree1, tree2, path = '.', recurse = true)
              # handle empty trees
              return changed if tree1 == tree2
      
              t1 = list_tree(tree1) if tree1
      Severity: Minor
      Found in lib/grit/git-ruby/repository.rb - About 5 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

      Method diff has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def diff(commit1, commit2, options = {})
              patch = ''
      
              commit_obj1 = get_object_by_sha1(commit1)
              tree1 = commit_obj1.tree
      Severity: Major
      Found in lib/grit/git-ruby/repository.rb - About 2 hrs to fix

        Method ls_tree_path has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def ls_tree_path(sha, path, append = nil)
                tree = get_raw_tree(sha)
                if path =~ /\//
                  paths = path.split('/')
                  last = path[path.size - 1, 1]
        Severity: Minor
        Found in lib/grit/git-ruby/repository.rb - About 1 hr to fix

          Method walk_log has 49 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def walk_log(sha, opts, total_size = 0)
                  return [] if @already_searched[sha] # to prevent rechecking branches
                  @already_searched[sha] = true
          
                  array = []
          Severity: Minor
          Found in lib/grit/git-ruby/repository.rb - About 1 hr to fix

            Method quick_what_changed has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def quick_what_changed(t1, t2, path, type)
                    changed = []
            
                    t1[type].each do |file, hsh|
                      t2_file = t2[type][file] rescue nil
            Severity: Minor
            Found in lib/grit/git-ruby/repository.rb - 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

            Method look_for_commits has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def look_for_commits(commit_sha, path, looking_for, options = {})
                    return [] if @already_searched[commit_sha] # to prevent rechecking branches
            
                    @already_searched[commit_sha] = true
            
            
            Severity: Minor
            Found in lib/grit/git-ruby/repository.rb - 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

            Method quick_diff has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  def quick_diff(tree1, tree2, path = '.', recurse = true)
                    # handle empty trees
                    return changed if tree1 == tree2
            
                    t1 = list_tree(tree1) if tree1
            Severity: Minor
            Found in lib/grit/git-ruby/repository.rb - About 1 hr to fix

              Method get_subtree has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                    def get_subtree(commit_sha, path)
                      tree_sha = get_object_by_sha1(commit_sha).tree
              
                      if path && !(path == '' || path == '.' || path == './')
                        paths = path.split('/')
              Severity: Minor
              Found in lib/grit/git-ruby/repository.rb - 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

              Method look_for_commits has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                    def look_for_commits(commit_sha, path, looking_for, options = {})
                      return [] if @already_searched[commit_sha] # to prevent rechecking branches
              
                      @already_searched[commit_sha] = true
              
              
              Severity: Minor
              Found in lib/grit/git-ruby/repository.rb - About 1 hr to fix

                Method init has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                      def self.init(dir, bare = true)
                
                        FileUtils.mkdir_p(dir) if !File.exists?(dir)
                
                        FileUtils.cd(dir) do
                Severity: Minor
                Found in lib/grit/git-ruby/repository.rb - About 1 hr to fix

                  Method get_raw_trees has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def get_raw_trees(sha, path = '')
                          out = ''
                          cat_file(sha).split("\n").each do |line|
                            mode, type, sha, name = line.split(/\s/)
                  
                  
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb - 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

                  Method get_raw_object_by_sha1 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def get_raw_object_by_sha1(sha1o)
                          raise NoSuchShaFound if sha1o.nil? || sha1o.empty? || !sha1o.is_a?(String)
                  
                          sha1 = [sha1o.chomp].pack("H*")
                          # try packs
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb - 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

                  Method load_packs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def load_packs(path)
                            @loaded_packs << path
                            return if !File.exists?(path)
                             Dir.open(path) do |dir|
                              dir.each do |entry|
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb - 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

                  Method load_alternate_loose has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                          def load_alternate_loose(pathname)
                            # load alternate loose, too
                            each_alternate_path pathname do |path|
                              next if @loaded.include?(path)
                              next if !File.exist?(path)
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb - 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

                  Method rev_list has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def rev_list(sha, options)
                          if sha.is_a? Array
                            (end_sha, sha) = sha
                          end
                  
                  
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb - 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

                  Method get_raw_tree has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                        def get_raw_tree(sha, recursive = false)
                          o = get_raw_object_by_sha1(sha)
                          if o.type == :commit
                            tree = get_object_by_sha1(sha).tree
                          elsif o.type == :tag
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb - 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

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

                            if append
                              mod_tree = []
                              tree.each do |ent|
                                (info, fpath) = ent.split("\t")
                                mod_tree << [info, File.join(append, fpath)].join("\t")
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb and 1 other location - About 25 mins to fix
                  lib/grit/git-ruby/repository.rb on lines 236..244

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

                  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

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

                              if append
                                mod_tree = []
                                tree.each do |ent|
                                  (info, fpath) = ent.split("\t")
                                  mod_tree << [info, File.join(append, fpath)].join("\t")
                  Severity: Minor
                  Found in lib/grit/git-ruby/repository.rb and 1 other location - About 25 mins to fix
                  lib/grit/git-ruby/repository.rb on lines 263..271

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

                  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