diff options
author | Florian Unglaub <florian.unglaub@nix-wie-weg.de> | 2012-08-24 15:25:52 +0200 |
---|---|---|
committer | Florian Unglaub <florian.unglaub@nix-wie-weg.de> | 2012-08-24 15:25:52 +0200 |
commit | 48443d20ca9aa10323c1b81835e519680b10debc (patch) | |
tree | 7488eeab446a1a01f90450e50028bfcbdc0ad1d0 /lib | |
parent | c5ae1549a1d09599734ccaab27e90a8752f1ede6 (diff) | |
parent | 6d4ae75f544d9819954865c105414a722344336a (diff) | |
download | gitlab-ce-48443d20ca9aa10323c1b81835e519680b10debc.tar.gz |
Merge branch 'master' of git://github.com/gitlabhq/gitlabhq
Diffstat (limited to 'lib')
-rw-r--r-- | lib/color.rb | 31 | ||||
-rw-r--r-- | lib/gitlab/graph_commit.rb | 183 | ||||
-rw-r--r-- | lib/gitlab/markdown.rb | 19 | ||||
-rw-r--r-- | lib/graph_commit.rb | 181 | ||||
-rwxr-xr-x | lib/hooks/post-receive (renamed from lib/post-receive-hook) | 0 | ||||
-rw-r--r-- | lib/tasks/dev/repo.rake | 26 | ||||
-rw-r--r-- | lib/tasks/dev/tests.rake | 10 | ||||
-rwxr-xr-x | lib/tasks/dev/user.sh | 7 | ||||
-rw-r--r-- | lib/tasks/gitlab/setup.rake | 6 | ||||
-rw-r--r-- | lib/tasks/gitlab/status.rake | 20 | ||||
-rw-r--r-- | lib/tasks/gitlab/update_hooks.rake | 19 | ||||
-rw-r--r-- | lib/tasks/gitlab/write_hook.rake | 23 |
12 files changed, 239 insertions, 286 deletions
diff --git a/lib/color.rb b/lib/color.rb deleted file mode 100644 index 4723804e5f8..00000000000 --- a/lib/color.rb +++ /dev/null @@ -1,31 +0,0 @@ -module Color - extend self - - def colorize(text, color_code) - "\033[#{color_code}#{text}\033[0m" - end - - def red(text) - colorize(text, "31m") - end - - def green(text) - colorize(text, "32m") - end - - def yellow(text) - colorize(text, "93m") - end - - def command(string) - `#{string}` - if $?.to_i > 0 - puts red " == #{string} - FAIL" - puts red " == Error during configure" - exit - else - puts green " == #{string} - OK" - end - end -end - diff --git a/lib/gitlab/graph_commit.rb b/lib/gitlab/graph_commit.rb new file mode 100644 index 00000000000..b9859d79274 --- /dev/null +++ b/lib/gitlab/graph_commit.rb @@ -0,0 +1,183 @@ +require "grit" + +module Gitlab + class GraphCommit + attr_accessor :time, :space + attr_accessor :refs + + def self.to_graph(project) + @repo = project.repo + commits = Grit::Commit.find_all(@repo, nil, {max_count: 650}) + + ref_cache = {} + + commits.map! {|c| GraphCommit.new(Commit.new(c))} + commits.each { |commit| commit.add_refs(ref_cache, @repo) } + + days = GraphCommit.index_commits(commits) + @days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json + @commits_json = commits.map(&:to_graph_hash).to_json + + return @days_json, @commits_json + end + + # Method is adding time and space on the + # list of commits. As well as returns date list + # corelated with time set on commits. + # + # @param [Array<GraphCommit>] comits to index + # + # @return [Array<TimeDate>] list of commit dates corelated with time on commits + def self.index_commits(commits) + days, heads = [], [] + map = {} + + commits.reverse.each_with_index do |c,i| + c.time = i + days[i] = c.committed_date + map[c.id] = c + heads += c.refs unless c.refs.nil? + end + + heads.select!{|h| h.is_a? Grit::Head or h.is_a? Grit::Remote} + # sort heads so the master is top and current branches are closer + heads.sort! do |a,b| + if a.name == "master" + -1 + elsif b.name == "master" + 1 + else + b.commit.committed_date <=> a.commit.committed_date + end + end + + @_reserved = {} + days.each_index do |i| + @_reserved[i] = [] + end + + heads.each do |h| + if map.include? h.commit.id then + place_chain(map[h.commit.id], map) + end + end + days + end + + # Add space mark on commit and its parents + # + # @param [GraphCommit] the commit object. + # @param [Hash<String,GraphCommit>] map of commits + def self.place_chain(commit, map, parent_time = nil) + leaves = take_left_leaves(commit, map) + if leaves.empty? then + return + end + space = find_free_space(leaves.last.time..leaves.first.time) + leaves.each{|l| l.space = space} + # and mark it as reserved + min_time = leaves.last.time + parents = leaves.last.parents.collect + parents.each do |p| + if map.include? p.id then + parent = map[p.id] + if parent.time < min_time then + min_time = parent.time + end + end + end + if parent_time.nil? then + max_time = leaves.first.time + else + max_time = parent_time - 1 + end + mark_reserved(min_time..max_time, space) + # Visit branching chains + leaves.each do |l| + parents = l.parents.collect + .select{|p| map.include? p.id and map[p.id].space == 0} + for p in parents + place_chain(map[p.id], map, l.time) + end + end + end + + def self.mark_reserved(time_range, space) + for day in time_range + @_reserved[day].push(space) + end + end + + def self.find_free_space(time_range) + reserved = [] + for day in time_range + reserved += @_reserved[day] + end + space = 1 + while reserved.include? space do + space += 1 + end + space + end + + # Takes most left subtree branch of commits + # which don't have space mark yet. + # + # @param [GraphCommit] the commit object. + # @param [Hash<String,GraphCommit>] map of commits + # + # @return [Array<GraphCommit>] list of branch commits + def self.take_left_leaves(commit, map) + leaves = [] + leaves.push(commit) if commit.space == 0 + while true + parent = commit.parents.collect + .select{|p| map.include? p.id and map[p.id].space == 0} + if parent.count == 0 then + return leaves + else + commit = map[parent.first.id] + leaves.push(commit) + end + end + end + + + def initialize(commit) + @_commit = commit + @time = -1 + @space = 0 + end + + def method_missing(m, *args, &block) + @_commit.send(m, *args, &block) + end + + def to_graph_hash + h = {} + h[:parents] = self.parents.collect do |p| + [p.id,0,0] + end + h[:author] = Gitlab::Encode.utf8(author.name) + h[:time] = time + h[:space] = space + h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? + h[:id] = sha + h[:date] = date + h[:message] = Gitlab::Encode.utf8(message) + h[:login] = author.email + h + end + + def add_refs(ref_cache, repo) + if ref_cache.empty? + repo.refs.each do |ref| + ref_cache[ref.commit.id] ||= [] + ref_cache[ref.commit.id] << ref + end + end + @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) + @refs ||= [] + end + end +end diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index d3daed91c32..75fa835d502 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -1,5 +1,14 @@ module Gitlab - # Custom parsing for Gitlab-flavored Markdown + # Custom parser for Gitlab-flavored Markdown + # + # It replaces references in the text with links to the appropriate items in Gitlab. + # + # Supported reference formats are: + # * @foo for team members + # * #123 for issues + # * !123 for merge requests + # * $123 for snippets + # * 123456 for commits # # Examples # @@ -67,25 +76,25 @@ module Gitlab def reference_user(identifier) if user = @project.users.where(name: identifier).first member = @project.users_projects.where(user_id: user).first - link_to("@#{user.name}", project_team_member_path(@project, member), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}")) if member + link_to("@#{identifier}", project_team_member_path(@project, member), html_options.merge(class: "gfm gfm-team_member #{html_options[:class]}")) if member end end def reference_issue(identifier) if issue = @project.issues.where(id: identifier).first - link_to("##{issue.id}", project_issue_path(@project, issue), html_options.merge(title: "Issue: #{issue.title}", class: "gfm gfm-issue #{html_options[:class]}")) + link_to("##{identifier}", project_issue_path(@project, issue), html_options.merge(title: "Issue: #{issue.title}", class: "gfm gfm-issue #{html_options[:class]}")) end end def reference_merge_request(identifier) if merge_request = @project.merge_requests.where(id: identifier).first - link_to("!#{merge_request.id}", project_merge_request_path(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}")) + link_to("!#{identifier}", project_merge_request_path(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}")) end end def reference_snippet(identifier) if snippet = @project.snippets.where(id: identifier).first - link_to("$#{snippet.id}", project_snippet_path(@project, snippet), html_options.merge(title: "Snippet: #{snippet.title}", class: "gfm gfm-snippet #{html_options[:class]}")) + link_to("$#{identifier}", project_snippet_path(@project, snippet), html_options.merge(title: "Snippet: #{snippet.title}", class: "gfm gfm-snippet #{html_options[:class]}")) end end diff --git a/lib/graph_commit.rb b/lib/graph_commit.rb deleted file mode 100644 index e08a8fad4c1..00000000000 --- a/lib/graph_commit.rb +++ /dev/null @@ -1,181 +0,0 @@ -require "grit" - -class GraphCommit - attr_accessor :time, :space - attr_accessor :refs - - def self.to_graph(project) - @repo = project.repo - commits = Grit::Commit.find_all(@repo, nil, {max_count: 650}) - - ref_cache = {} - - commits.map! {|c| GraphCommit.new(Commit.new(c))} - commits.each { |commit| commit.add_refs(ref_cache, @repo) } - - days = GraphCommit.index_commits(commits) - @days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json - @commits_json = commits.map(&:to_graph_hash).to_json - - return @days_json, @commits_json - end - - # Method is adding time and space on the - # list of commits. As well as returns date list - # corelated with time set on commits. - # - # @param [Array<GraphCommit>] comits to index - # - # @return [Array<TimeDate>] list of commit dates corelated with time on commits - def self.index_commits(commits) - days, heads = [], [] - map = {} - - commits.reverse.each_with_index do |c,i| - c.time = i - days[i] = c.committed_date - map[c.id] = c - heads += c.refs unless c.refs.nil? - end - - heads.select!{|h| h.is_a? Grit::Head or h.is_a? Grit::Remote} - # sort heads so the master is top and current branches are closer - heads.sort! do |a,b| - if a.name == "master" - -1 - elsif b.name == "master" - 1 - else - b.commit.committed_date <=> a.commit.committed_date - end - end - - @_reserved = {} - days.each_index do |i| - @_reserved[i] = [] - end - - heads.each do |h| - if map.include? h.commit.id then - place_chain(map[h.commit.id], map) - end - end - days - end - - # Add space mark on commit and its parents - # - # @param [GraphCommit] the commit object. - # @param [Hash<String,GraphCommit>] map of commits - def self.place_chain(commit, map, parent_time = nil) - leaves = take_left_leaves(commit, map) - if leaves.empty? then - return - end - space = find_free_space(leaves.last.time..leaves.first.time) - leaves.each{|l| l.space = space} - # and mark it as reserved - min_time = leaves.last.time - parents = leaves.last.parents.collect - parents.each do |p| - if map.include? p.id then - parent = map[p.id] - if parent.time < min_time then - min_time = parent.time - end - end - end - if parent_time.nil? then - max_time = leaves.first.time - else - max_time = parent_time - 1 - end - mark_reserved(min_time..max_time, space) - # Visit branching chains - leaves.each do |l| - parents = l.parents.collect - .select{|p| map.include? p.id and map[p.id].space == 0} - for p in parents - place_chain(map[p.id], map, l.time) - end - end - end - - def self.mark_reserved(time_range, space) - for day in time_range - @_reserved[day].push(space) - end - end - - def self.find_free_space(time_range) - reserved = [] - for day in time_range - reserved += @_reserved[day] - end - space = 1 - while reserved.include? space do - space += 1 - end - space - end - - # Takes most left subtree branch of commits - # which don't have space mark yet. - # - # @param [GraphCommit] the commit object. - # @param [Hash<String,GraphCommit>] map of commits - # - # @return [Array<GraphCommit>] list of branch commits - def self.take_left_leaves(commit, map) - leaves = [] - leaves.push(commit) if commit.space == 0 - while true - parent = commit.parents.collect - .select{|p| map.include? p.id and map[p.id].space == 0} - if parent.count == 0 then - return leaves - else - commit = map[parent.first.id] - leaves.push(commit) - end - end - end - - - def initialize(commit) - @_commit = commit - @time = -1 - @space = 0 - end - - def method_missing(m, *args, &block) - @_commit.send(m, *args, &block) - end - - def to_graph_hash - h = {} - h[:parents] = self.parents.collect do |p| - [p.id,0,0] - end - h[:author] = Gitlab::Encode.utf8(author.name) - h[:time] = time - h[:space] = space - h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? - h[:id] = sha - h[:date] = date - h[:message] = Gitlab::Encode.utf8(message) - h[:login] = author.email - h - end - - def add_refs(ref_cache, repo) - if ref_cache.empty? - repo.refs.each do |ref| - ref_cache[ref.commit.id] ||= [] - ref_cache[ref.commit.id] << ref - end - end - @refs = ref_cache[@_commit.id] if ref_cache.include?(@_commit.id) - @refs ||= [] - end -end diff --git a/lib/post-receive-hook b/lib/hooks/post-receive index d38bd13e19d..d38bd13e19d 100755 --- a/lib/post-receive-hook +++ b/lib/hooks/post-receive diff --git a/lib/tasks/dev/repo.rake b/lib/tasks/dev/repo.rake deleted file mode 100644 index 7b389a5535b..00000000000 --- a/lib/tasks/dev/repo.rake +++ /dev/null @@ -1,26 +0,0 @@ -namespace :dev do - desc "Prepare for development (run dev_user.sh first)" - task :repos => :environment do - key = `sudo -u gitlabdev -H cat /home/gitlabdev/.ssh/id_rsa.pub` - raise "\n *** Run ./lib/tasks/dev/user.sh first *** \n" if key.empty? - Key.create(:user_id => User.first, :key => key, :title => "gitlabdev") - - puts "\n *** Clone diaspora from github" - `sudo -u gitlabdev -H sh -c "cd /home/gitlabdev; git clone git://github.com/diaspora/diaspora.git /home/gitlabdev/diaspora"` - - puts "\n *** Push diaspora source to gitlab" - `sudo -u gitlabdev -H sh -c "cd /home/gitlabdev/diaspora; git remote add local git@localhost:diaspora.git; git push local master; git push local --tags; git checkout -b api origin/api; git push local api; git checkout -b heroku origin/heroku; git push local heroku"` - - puts "\n *** Clone rails from github" - `sudo -u gitlabdev -H sh -c "cd /home/gitlabdev; git clone git://github.com/rails/rails.git /home/gitlabdev/rails"` - - puts "\n *** Push rails source to gitlab" - `sudo -u gitlabdev -H sh -c "cd /home/gitlabdev/rails; git remote add local git@localhost:ruby_on_rails.git; git push local master; git push local --tags"` - - puts "\n *** Clone rubinius from github" - `sudo -u gitlabdev -H sh -c "cd /home/gitlabdev; git clone git://github.com/rubinius/rubinius.git /home/gitlabdev/rubinius"` - - puts "\n *** Push rubinius source to gitlab" - `sudo -u gitlabdev -H sh -c "cd /home/gitlabdev/rubinius; git remote add local git@localhost:rubinius.git; git push local master; git push local --tags"` - end -end diff --git a/lib/tasks/dev/tests.rake b/lib/tasks/dev/tests.rake deleted file mode 100644 index f91320ebdd2..00000000000 --- a/lib/tasks/dev/tests.rake +++ /dev/null @@ -1,10 +0,0 @@ -namespace :dev do - desc "DEV | Run cucumber and rspec" - task :tests do - ["cucumber", "rspec spec"].each do |cmd| - puts "Starting to run #{cmd}..." - system("bundle exec #{cmd}") - raise "#{cmd} failed!" unless $?.exitstatus == 0 - end - end -end diff --git a/lib/tasks/dev/user.sh b/lib/tasks/dev/user.sh deleted file mode 100755 index d6b20df2ef2..00000000000 --- a/lib/tasks/dev/user.sh +++ /dev/null @@ -1,7 +0,0 @@ -sudo adduser \ - --gecos 'gitlab dev user' \ - --disabled-password \ - --home /home/gitlabdev \ - gitlabdev - -sudo -i -u gitlabdev -H sh -c "ssh-keygen -t rsa" diff --git a/lib/tasks/gitlab/setup.rake b/lib/tasks/gitlab/setup.rake index d60e73e9ac3..49c86461c0b 100644 --- a/lib/tasks/gitlab/setup.rake +++ b/lib/tasks/gitlab/setup.rake @@ -1,7 +1,11 @@ namespace :gitlab do namespace :app do desc "GITLAB | Setup production application" - task :setup => ['db:setup', 'db:seed_fu', 'gitlab:app:enable_automerge'] + task :setup => [ + 'db:setup', + 'db:seed_fu', + 'gitlab:app:enable_automerge' + ] end end diff --git a/lib/tasks/gitlab/status.rake b/lib/tasks/gitlab/status.rake index bc4e86ea648..02d27d4bbcc 100644 --- a/lib/tasks/gitlab/status.rake +++ b/lib/tasks/gitlab/status.rake @@ -56,6 +56,20 @@ namespace :gitlab do return end + gitolite_hooks_path = File.join("/home", Gitlab.config.ssh_user, "share", "gitolite", "hooks", "common") + gitlab_hook_files = ['post-receive'] + gitlab_hook_files.each do |file_name| + dest = File.join(gitolite_hooks_path, file_name) + print "#{dest} exists? ............" + if File.exists?(dest) + puts "YES".green + else + puts "NO".red + return + end + end + + if Project.count > 0 puts "Validating projects repositories:".yellow Project.find_each(:batch_size => 100) do |project| @@ -67,12 +81,6 @@ namespace :gitlab do next end - - unless File.owned?(hook_file) - puts "post-receive file is not owner by gitlab".red - next - end - puts "post-reveice file ok".green end end diff --git a/lib/tasks/gitlab/update_hooks.rake b/lib/tasks/gitlab/update_hooks.rake deleted file mode 100644 index 44e1617e58f..00000000000 --- a/lib/tasks/gitlab/update_hooks.rake +++ /dev/null @@ -1,19 +0,0 @@ -namespace :gitlab do - namespace :gitolite do - desc "GITLAB | Rewrite hooks for repos" - task :update_hooks => :environment do - puts "Starting Projects" - Project.find_each(:batch_size => 100) do |project| - begin - if project.commit - project.write_hooks - print ".".green - end - rescue Exception => e - print e.message.red - end - end - puts "\nDone with projects" - end - end -end diff --git a/lib/tasks/gitlab/write_hook.rake b/lib/tasks/gitlab/write_hook.rake new file mode 100644 index 00000000000..098331b8cd7 --- /dev/null +++ b/lib/tasks/gitlab/write_hook.rake @@ -0,0 +1,23 @@ +namespace :gitlab do + namespace :gitolite do + desc "GITLAB | Write GITLAB hook for gitolite" + task :write_hooks => :environment do + gitolite_hooks_path = File.join("/home", Gitlab.config.ssh_user, "share", "gitolite", "hooks", "common") + gitlab_hooks_path = Rails.root.join("lib", "hooks") + + gitlab_hook_files = ['post-receive'] + + gitlab_hook_files.each do |file_name| + source = File.join(gitlab_hooks_path, file_name) + dest = File.join(gitolite_hooks_path, file_name) + + puts "sudo -u root cp #{source} #{dest}".yellow + `sudo -u root cp #{source} #{dest}` + + puts "sudo -u root chown git:git #{dest}".yellow + `sudo -u root chown git:git #{dest}` + end + end + end +end + |