forked from mojombo/grit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some simple write ops : add, remove, commit
- Loading branch information
Showing
15 changed files
with
622 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
== 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 <[email protected]>"> | ||
head.authored_date | ||
# => Wed Oct 24 22:02:31 -0700 2007 | ||
head.committer | ||
# => #<Grit::Actor "Tom Preston-Werner <[email protected]>"> | ||
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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
require 'grit/config' | ||
require 'grit/repo' | ||
require 'grit/index' | ||
require 'grit/status' | ||
|
||
|
||
module Grit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
begin | ||
require 'sequel' | ||
|
||
module Grit | ||
|
||
class CommitDb | ||
|
||
SCHEMA_VERSION = 1 | ||
|
||
attr_accessor :db, :git | ||
|
||
def initialize(git_obj, index_location = nil) | ||
@git = git_obj | ||
db_file = File.join(index_location || @git.git_dir, 'commit_db') | ||
if !File.exists?(db_file) | ||
@db = Sequel.open "sqlite:///#{db_file}" | ||
setup_tables | ||
else | ||
@db = Sequel.open "sqlite:///#{db_file}" | ||
end | ||
end | ||
|
||
def rev_list(branch, options) | ||
end | ||
|
||
def update_db(branch = nil) | ||
# find all refs/heads, for each | ||
# add branch if not there | ||
# go though all commits in branch | ||
# add new commit_branches a | ||
# and commit_nodes for each new one | ||
# stop if reach commit that already has branch and node links | ||
end | ||
|
||
def setup_tables | ||
@db << "create table meta (meta_key text, meta_value text)" | ||
@db[:meta] << {:meta_key => 'schema', :meta_value => SCHEMA_VERSION} | ||
|
||
@db << "create table commits (id integer, sha text, author_date integer)" | ||
@db << "create table nodes (id integer, path text, type text)" | ||
@db << "create table branches (id integer, ref text, commit_id integer)" | ||
|
||
@db << "create table commit_branches (commit_id integer, branch_id integer)" | ||
@db << "create table commit_nodes (commit_id integer, node_id integer, node_sha string)" | ||
end | ||
|
||
end | ||
end | ||
|
||
rescue LoadError | ||
# no commit db | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.