ruby Gitorious存储库托管服务,您可以在自己的服务器上安装,哈希Git存储库,这使得链接很难

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Gitorious存储库托管服务,您可以在自己的服务器上安装,哈希Git存储库,这使得链接很难相关的知识,希望对你有一定的参考价值。

#!/usr/bin/ruby -d

####
#
#  create_unhashed_links.rb
#
#  Creates links that are unhashed to the Gitorious repositories.
#  Helps link the repositories to Redmine.
#
#  Spaces in project names are replaced with underscores.
#
#  Most stuff is hardcoded, including gitorious repository location.
#
#  History
#    01.10.2009/MEP ; Initial revision
#    05.10.2009/MEP ; Rewrote: optimized database handling, more Ruby-like code.
#    09.10.2009/MEP ; Changed db_pw to production server's.
#    14.10.2009/MEP ; Fixed bug : gitorious rep path was not added to link.
#    14.10.2009/MEP ; Git db pw has to be given as a parameter now.
####

require "mysql"

gitorious_host = 'localhost'
db_user = 'git'
db_name = 'gitorious_production'

hashed_repository_path = '/var/www/gitorious/repositories'
pt_repository_path = '/git'

# Database object
class GitoriousDb

  def initialize(host, user, pw, name)
    @dbConn = Mysql::new(host, user, pw, name)
  end

  # Opens the recordset containing the repository info required
  def get_repos
    @rs = @dbConn.query("select projects.title as proj_name, repositories.name as repo_name, repositories.hashed_path from repositories, projects where repositories.project_id = projects.id")
    puts "Repositories: " + @rs.num_rows.to_s if $DEBUG
    return @rs
  end
  
  # Returns next row in recordset
  def get_next_repo
    retval = @rs.fetch_hash
    return retval
  end
  
end

class RepoLinker
  
  def initialize(gitorious_dir, link_dir, git_db)
    @gitorious_dir = gitorious_dir
    @link_dir = link_dir
    @git_db = git_db
  end
 
  def create_links(repo)
    link_name = create_link_name(repo)
    full_repo_path = create_repo_path(repo['hashed_path'])
    create_link(full_repo_path, link_name)
  end

  # Creates the full path and name for the link to be created. Currently it looks like
  # <base_dir>/<project_name>/<repository_name>.git
  def create_link_name(fields)
    return "#{@link_dir}/#{fields['proj_name']}/#{fields['repo_name']}.git".gsub(/ /, '_')
  end

  def create_repo_path(rel_path)
    return "#{@gitorious_dir}/#{rel_path}.git"
  end
    
  # Creates the link from the gitorious repo to the plain text link and also creates missing directories.
  # Checks that the directories and the link do not exist before attempting to create them.
  # *Parameters:*
  #  _source_ : Full path and file name to gitorious repository
  #  _link_   : Full path and link name for the plain text link
  def create_link(source, link)
    path = ''
    link.each('/') do |dir|
      path << dir
      if dir !~ /.git$/
	puts "Path: #{path}" if $DEBUG
        Dir.mkdir(path) unless File.exists?(path)
      else
	puts "Link: #{path}" if $DEBUG
        File.symlink(source, path) unless File.symlink?(path)
      end
    end
  end
  
end

db_pw = ARGV[0]

db = GitoriousDb.new(gitorious_host, db_user, db_pw, db_name)
rl = RepoLinker.new(hashed_repository_path, pt_repository_path, db)

db.get_repos

repo = db.get_next_repo

while repo
  rl.create_links(repo)
  repo.each_pair {|key, value| puts "#{key} is #{value}" } if $DEBUG
  repo = db.get_next_repo
end

以上是关于ruby Gitorious存储库托管服务,您可以在自己的服务器上安装,哈希Git存储库,这使得链接很难的主要内容,如果未能解决你的问题,请参考以下文章

您可以为您的组织托管一个私有存储库以与 npm 一起使用吗?

各种GIT代码托管工具比较

是否存在 ruby​​ rack 应用程序的托管? [关闭]

ruby 优化和缩小您的GIT存储库(Ruby脚本)。来自Jeff Smith @ rallydev.com。

我如何自己为多个用户托管 Mercurial 存储库?

Ruby DSL(领域特定语言)存储库,示例