Class: Mbeditor::GitCommitDetailService

Inherits:
Object
  • Object
show all
Includes:
GitService
Defined in:
app/services/mbeditor/git_commit_detail_service.rb

Constant Summary

Constants included from GitService

Mbeditor::GitService::SAFE_GIT_REF

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GitService

ahead_behind, base_branch?, current_branch, find_branch_base, parse_git_log, parse_git_log_with_parents, parse_name_status, parse_numstat, parse_numstat_z, parse_porcelain_status, resolve_path, run_git, upstream_branch

Constructor Details

#initialize(repo_path:, sha:) ⇒ GitCommitDetailService

Returns a new instance of GitCommitDetailService.



9
10
11
12
# File 'app/services/mbeditor/git_commit_detail_service.rb', line 9

def initialize(repo_path:, sha:)
  @repo_path = repo_path.to_s
  @sha       = sha.to_s
end

Instance Attribute Details

#repo_pathObject (readonly)

Returns the value of attribute repo_path.



7
8
9
# File 'app/services/mbeditor/git_commit_detail_service.rb', line 7

def repo_path
  @repo_path
end

#shaObject (readonly)

Returns the value of attribute sha.



7
8
9
# File 'app/services/mbeditor/git_commit_detail_service.rb', line 7

def sha
  @sha
end

Instance Method Details

#callObject

Two spawns per commit click, not three: git show --name-status prints the pretty header then the raw name-status body. The numstat still needs its own call — asking for --name-status and --numstat together makes git emit only the former. --no-renames keeps a rename as the D+A pair the two-field parse below expects, rather than a three-field R100 record.



22
23
24
25
26
27
28
29
30
31
# File 'app/services/mbeditor/git_commit_detail_service.rb', line 22

def call
  out, status = GitService.run_git(repo_path, "show", "--no-color", "--no-renames", "--name-status",
                                   "--pretty=format:%s%x1f%an%x1f%aI", "--end-of-options", sha)
  return EMPTY.merge("sha" => sha) unless status.success?

  header, body = out.split("\n", 2)
  fields = header.to_s.split("\x1f", 3)
  { "sha" => sha, "title" => fields[0].to_s, "author" => fields[1].to_s, "date" => fields[2].to_s,
    "files" => parse_files(body.to_s) }
end