On Mon, Sep 28, 2020 at 09:02:48PM +0800, Li Ping wrote:
lib/git.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/lib/git.rb b/lib/git.rb index db97c47..a181ec9 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -3,8 +3,34 @@ # wrap common git commands class GitCommit def initialize(repo, commit)
- @git_prefix = "git -C /srv/git/#{repo}.git"
- @repo = repo @commit = commit
- @git_prefix = cd_repo_path
- end
- def check_repo
- fork_name = @repo.split('/')[0]
- project = @repo.split('/')[1]
You don't need to do @repo.split('/') twice, do it once can cost less.
Thanks, Yuanchao
first_letter = project[0]
fork_name = 'linus' if project == 'linux'
path_a = find_path("/srv/git/#{first_letter}/#{project}/#{project}.git")
path_b = find_path("/srv/git/#{first_letter}/#{project}/#{fork_name}.git")
path_c = find_path("/srv/git/#{project}/#{fork_name}.git")
path_d = find_path("/srv/git/#{project}/#{project}.git")
path_a || path_b || path_c || path_d
end
def find_path(path)
return false if Dir.glob(path).empty?
Dir.glob(path).first
end
def cd_repo_path
find_repo = check_repo
return unless find_repo
"git -C #{find_repo}" end
def author_name
-- 2.23.0