Skip to content
Snippets Groups Projects
Commit 53d82a32 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Cleanup

parent b24f1519
No related branches found
No related tags found
No related merge requests found
== TODO ==
* Add remote branch references (Grit::Remote)
* Add status - what is modified, staged
g.checkout('new_branch')
g.checkout(g.branch('new_branch'))
g.branch(name).merge(branch2)
g.branch(branch2).merge # merges HEAD with branch2
g.branch(name).in_branch(message) { # add files } # auto-commits
g.merge('new_branch')
g.merge('origin/remote_branch')
g.merge(b.branch('master'))
g.merge([branch1, branch2])
r = g.add_remote(name, uri) # Git::Remote
r = g.add_remote(name, Git::Base) # Git::Remote
g.remotes # array of Git::Remotes
g.remote(name).fetch
g.remote(name).remove
g.remote(name).merge
g.remote(name).merge(branch)
g.fetch
g.fetch(g.remotes.first)
g.pull
g.pull(Git::Repo, Git::Branch) # fetch and a merge
g.add_tag('tag_name') # returns Git::Tag
g.repack
g.push
g.push(g.remote('name'))
g.reset # defaults to HEAD
g.reset_hard(Git::Commit)
g.branch('new_branch') # creates new or fetches existing
g.branch('new_branch').checkout
g.branch('new_branch').delete
g.branch('existing_branch').checkout
require 'mojombo-grit'
include Grit
Grit.debug
Grit.use_pure_ruby
repo = Repo.new("/Users/tom/dev/grit")
= Commit Log
repo.commits('mybranch')
repo.commits('40d3057d09a7a4d61059bca9dca5ae698de58cbe')
repo.commits('v0.1')
repo.log('mybranch', 100, 20)
head = repo.commits.first
head.id
# => "e80bbd2ce67651aa18e57fb0b43618ad4baf7750"
head.parents
# => [#<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">]
head.tree
# => #<Grit::Tree "3536eb9abac69c3e4db583ad38f3d30f8db4771f">
head.author
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
head.authored_date
# => Wed Oct 24 22:02:31 -0700 2007
head.committer
# => #<Grit::Actor "Tom Preston-Werner <tom@mojombo.com>">
head.committed_date
# => Wed Oct 24 22:02:31 -0700 2007
head.message
# => "add Actor inspect"
contents = tree.contents
# => [#<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">,
#<Grit::Blob "81d2c27608b352814cbe979a6acd678d30219678">,
#<Grit::Tree "c3d07b0083f01a6e1ac969a0f32b8d06f20c62e5">,
#<Grit::Tree "4d00fe177a8407dbbc64a24dbfc564762c0922d8">]
blob.id
# => "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666"
blob.name
# => "README.txt"
blob.mode
# => "100644"
blob.size
# => 7726
blob.data
repo.blob("4ebc8aea50e0a67e000ba29a30809d0a7b9b2666")
# => #<Grit::Blob "4ebc8aea50e0a67e000ba29a30809d0a7b9b2666">
== 2.6.1
* Security bugfix for Repository#grep
== 2.6.0
* More stable commit parsinga
* Handle filenames with spaces
Loading
Loading
Loading
Loading
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This is a listing of all the places I can find that Grit actually does a
'git' system call. My goal is to add native Ruby versions of all of them.
Completed
===========================
** lib/grit/blob.rb:36: @size ||= @repo.git.cat_file({:s => true}, id).chomp.to_i
** lib/grit/blob.rb:43: @data ||= @repo.git.cat_file({:p => true}, id)
** lib/grit/tree.rb:16: output = repo.git.ls_tree({}, treeish, *paths)
lib/grit/commit.rb:74: repo.git.rev_list({}, ref).strip.split("\n").size
lib/grit/commit.rb:92: output = repo.git.rev_list(actual_options, ref)
lib/grit/commit.rb:94: output = repo.git.rev_list(actual_options.merge(:all => true))
Next to do
===========================
lib/grit/tag.rb:28: output = repo.git.for_each_ref(actual_options, "refs/tags")
lib/grit/head.rb:37: output = repo.git.for_each_ref(actual_options, HEAD_PREFIX)
lib/grit/head.rb:50: self.new($1, repo.git.rev_parse(options, 'HEAD'))
lib/grit/config.rb:9: @repo.git.config({}, key, value)
lib/grit/config.rb:40: @repo.git.config(:list => true).split(/\n/)
May not be fast enough
=============================
lib/grit/blob.rb:58: data = repo.git.blame({:p => true}, commit, '--', file)
More Difficult
===========================
lib/grit/commit.rb:39: @id_abbrev ||= @repo.git.rev_parse({:short => true}, self.id).chomp
lib/grit/commit.rb:150: text = repo.git.diff({:full_index => true}, *paths)
lib/grit/commit.rb:156: diff = @repo.git.show({:full_index => true, :pretty => 'raw'}, @id)
require 'fileutils'
require 'benchmark'
require 'rubygems'
require 'ruby-prof'
require 'memcache'
require 'pp'
#require 'grit'
require 'lib/grit'
def main
@wbare = File.expand_path(File.join('test', 'dot_git'))
in_temp_dir do
#result = RubyProf.profile do
git = Grit::Repo.new('.')
puts Grit::VERSION
Grit::GitRuby.use_commit_db = true
#Grit::GitRuby.cache_client = MemCache.new 'localhost:11211', :namespace => 'grit'
#Grit.debug = true
#pp Grit::GitRuby.cache_client.stats
commit1 = '5e3ee1198672257164ce3fe31dea3e40848e68d5'
commit2 = 'ca8a30f5a7f0f163bbe3b6f0abf18a6c83b0687a'
Benchmark.bm(8) do |x|
run_code(x, 'packobj') do
@commit = git.commit('5e3ee1198672257164ce3fe31dea3e40848e68d5')
@tree = git.tree('cd7422af5a2e0fff3e94d6fb1a8fff03b2841881')
@blob = git.blob('4232d073306f01cf0b895864e5a5cfad7dd76fce')
@commit.parents[0].parents[0].parents[0]
end
run_code(x, 'commits 1') do
git.commits.size
end
run_code(x, 'commits 2') do
log = git.commits('master', 15)
log.size
log.size
log.first
git.commits('testing').map { |c| c.message }
end
run_code(x, 'big revlist') do
c = git.commits('master', 200)
end
run_code(x, 'log') do
log = git.log('master')
log.size
log.size
log.first
end
run_code(x, 'diff') do
c = git.diff(commit1, commit2)
end
run_code(x, 'commit-diff') do
c = git.commit_diff(commit1)
end
run_code(x, 'heads') do
c = git.heads.collect { |b| b.commit.id }
end
# run_code(x, 'config', 100) do
# c = git.config['user.name']
# c = git.config['user.email']
# end
#run_code(x, 'commit count') do
# c = git.commit_count('testing')
#end
end
#end
#printer = RubyProf::FlatPrinter.new(result)
#printer.print(STDOUT, 0)
end
end
def run_code(x, name, times = 30)
x.report(name.ljust(12)) do
for i in 1..times do
yield i
end
end
#end
# Print a graph profile to text
end
def new_file(name, contents)
File.open(name, 'w') do |f|
f.puts contents
end
end
def in_temp_dir(remove_after = true)
filename = 'git_test' + Time.now.to_i.to_s + rand(300).to_s.rjust(3, '0')
tmp_path = File.join("/tmp/", filename)
FileUtils.mkdir(tmp_path)
Dir.chdir tmp_path do
FileUtils.cp_r(@wbare, File.join(tmp_path, '.git'))
yield tmp_path
end
puts tmp_path
#FileUtils.rm_r(tmp_path) if remove_after
end
main()
##pp Grit::GitRuby.cache_client.stats
Grit :
user system total real
packobj 0.030000 0.270000 1.380000 ( 1.507250)
commits 1 0.030000 0.070000 0.390000 ( 0.409931)
commits 2 0.110000 0.170000 0.860000 ( 0.896371)
log 0.350000 0.130000 0.850000 ( 0.875035)
diff 0.190000 0.140000 1.940000 ( 2.031911)
commit-diff 0.540000 0.220000 1.390000 ( 1.463839)
heads 0.010000 0.070000 0.390000 ( 0.413918)
Grit (with GitRuby) :
user system total real
packobj 0.050000 0.010000 0.060000 ( 0.078318)
commits 1 0.150000 0.010000 0.160000 ( 0.174296)
commits 2 0.440000 0.040000 0.480000 ( 0.522310)
log 0.490000 0.040000 0.530000 ( 0.538128)
diff 0.370000 0.230000 2.250000 ( 2.255974)
commit-diff 0.580000 0.260000 1.500000 ( 1.553000)
heads 0.020000 0.100000 0.430000 ( 0.455464)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment