summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.(none)>2007-11-20 08:54:45 -0800
committerscott Chacon <schacon@agadorsparticus.(none)>2007-11-20 08:54:45 -0800
commit13f7daaf27656fefe4c266e9b53a53010caf4177 (patch)
tree722629d1402ade29dd19e705ee05cf326e1526ee
parent2cee414891f2c47c3ee9b7751149f1e0317d9deb (diff)
downloadthird_party-ruby-git-13f7daaf27656fefe4c266e9b53a53010caf4177.zip
third_party-ruby-git-13f7daaf27656fefe4c266e9b53a53010caf4177.tar.gz
third_party-ruby-git-13f7daaf27656fefe4c266e9b53a53010caf4177.tar.xz
i now have the gitweb view page running off only 2 git calls
-rw-r--r--README3
-rw-r--r--TODO4
-rw-r--r--camping/gitweb.rb11
-rw-r--r--lib/git/base.rb1
-rw-r--r--lib/git/lib.rb72
5 files changed, 75 insertions, 16 deletions
diff --git a/README b/README
index 816e955..e71ec68 100644
--- a/README
+++ b/README
@@ -59,8 +59,7 @@ First you have to remember to require rubygems if it's not. Then include the 'g
Here are the operations that need read permission only.
- g = Git.open (working_dir = '.')
- (git_dir, index_file)
+ g = Git.open (working_dir, :log => Logger.new(STDOUT))
g.index
g.index.readable?
diff --git a/TODO b/TODO
index 3394996..c39db6b 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
* more documentation
-* logging (Git.open(:log => Logger.new))
-
* git revert, stash, rebase
@@ -15,7 +13,7 @@
- prune, fsck, pack-refs, gc, count-objects, unpack-objects
* email/patch integration
- - request-pull(email_address), git-am, git-apply, cherry-pick
+ - request-pull(email_address), git-am, git-apply
* compatible with git 1.4
diff --git a/camping/gitweb.rb b/camping/gitweb.rb
index bf8cf24..b346824 100644
--- a/camping/gitweb.rb
+++ b/camping/gitweb.rb
@@ -12,6 +12,7 @@ require 'lib/git'
#
# todo
# - diff/patch between any two objects
+# - expand patch to entire file
# - grep / search function
# - prettify : http://projects.wh.techno-weenie.net/changesets/3030
# - add user model (add/remove repos)
@@ -89,7 +90,10 @@ module GitWeb::Controllers
class View < R '/view/(\d+)'
def get repo_id
@repo = Repository.find repo_id
- @git = Git.bare(@repo.path)
+ logger = Logger.new('/tmp/git.log')
+ logger.level = Logger::INFO
+
+ @git = Git.bare(@repo.path, :log => logger)
render :view
end
end
@@ -214,7 +218,7 @@ module GitWeb::Views
gtags = @git.tags
@tags = {}
gtags.each { |tag| @tags[tag.sha] ||= []; @tags[tag.sha] << tag.name }
-
+
url = 'http:' + URL(Fetch, @repo.id, '').to_s
h3 'info'
@@ -321,6 +325,9 @@ module GitWeb::Views
case ext
when 'rb' : classnm = 'sh_ruby'
+ when 'js' : classnm = 'sh_javascript'
+ when 'html' : classnm = 'sh_html'
+ when 'css' : classnm = 'sh_css'
end
a.options 'repo', :href => R(View, @repo)
diff --git a/lib/git/base.rb b/lib/git/base.rb
index fe0b2e7..1820ee2 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -73,6 +73,7 @@ module Git
end
if options[:log]
@logger = options[:log]
+ @logger.info("Starting Git")
end
@working_directory = Git::WorkingDirectory.new(options[:working_directory]) if options[:working_directory]
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 293e00b..256d4b6 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -90,6 +90,13 @@ module Git
if /\w{40}/.match(string) # passing in a sha - just no-op it
return string
end
+
+ head = File.join(@git_dir, 'refs', 'heads', string)
+ return File.read(head) if File.file?(head)
+
+ head = File.join(@git_dir, 'refs', 'remotes', string)
+ return File.read(head) if File.file?(head)
+
command('rev-parse', string)
end
@@ -170,15 +177,31 @@ module Git
end
def branches_all
+ head = File.read(File.join(@git_dir, 'HEAD'))
arr = []
- command_lines('branch', '-a').each do |b|
- current = false
- current = true if b[0, 2] == '* '
- arr << [b.gsub('* ', '').strip, current]
+
+ if m = /ref: refs\/heads\/(.*)/.match(head)
+ current = m[1]
end
+ arr += list_files('heads').map { |f| [f, f == current] }
+ arr += list_files('remotes').map { |f| [f, false] }
+
+ #command_lines('branch', '-a').each do |b|
+ # current = false
+ # current = true if b[0, 2] == '* '
+ # arr << [b.gsub('* ', '').strip, current]
+ #end
+
arr
end
+ def list_files(ref_dir)
+ dir = File.join(@git_dir, 'refs', ref_dir)
+ files = nil
+ Dir.chdir(dir) { files = Dir.glob('**/*').select { |f| File.file?(f) } }
+ files
+ end
+
def branch_current
branches_all.select { |b| b[1] }.first[0] rescue nil
end
@@ -280,14 +303,38 @@ module Git
end
def config_get(name)
- command('config', ['--get', name])
+ c = config_list
+ c[name]
+ #command('config', ['--get', name])
end
def config_list
+ config = {}
+ config.merge!(parse_config('~/.gitconfig'))
+ config.merge!(parse_config(File.join(@git_dir, 'config')))
+ #hsh = {}
+ #command_lines('config', ['--list']).each do |line|
+ # (key, value) = line.split('=')
+ # hsh[key] = value
+ #end
+ #hsh
+ end
+
+ def parse_config(file)
hsh = {}
- command_lines('config', ['--list']).each do |line|
- (key, value) = line.split('=')
- hsh[key] = value
+ file = File.expand_path(file)
+ if File.file?(file)
+ current_section = nil
+ File.readlines(file).each do |line|
+ if m = /\[(\w+)\]/.match(line)
+ current_section = m[1]
+ elsif m = /\[(\w+?) "(.*?)"\]/.match(line)
+ current_section = "#{m[1]}.#{m[2]}"
+ elsif m = /(\w+?) = (.*)/.match(line)
+ key = "#{current_section}.#{m[1]}"
+ hsh[key] = m[2]
+ end
+ end
end
hsh
end
@@ -370,7 +417,11 @@ module Git
end
def tags
- command_lines('tag')
+ tag_dir = File.join(@git_dir, 'refs', 'tags')
+ tags = []
+ Dir.chdir(tag_dir) { tags = Dir.glob('*') }
+ return tags
+ #command_lines('tag')
end
def tag(tag)
@@ -387,6 +438,9 @@ module Git
end
def tag_sha(tag_name)
+ head = File.join(@git_dir, 'refs', 'tags', tag_name)
+ return File.read(head).chomp if File.exists?(head)
+
command('show-ref', ['--tags', '-s', tag_name])
end