pax_global_header 0000666 0000000 0000000 00000000064 12203622411 0014503 g ustar 00root root 0000000 0000000 52 comment=6db4fdcad851eeaff6382a9eb6748455c3818c3e ruby-git-1.2.6/ 0000775 0000000 0000000 00000000000 12203622411 0013253 5 ustar 00root root 0000000 0000000 ruby-git-1.2.6/.gitignore 0000664 0000000 0000000 00000000073 12203622411 0015243 0 ustar 00root root 0000000 0000000 *.gem *.kpf *.sw? .DS_Store coverage pkg rdoc Gemfile.lock ruby-git-1.2.6/.jrubyrc 0000664 0000000 0000000 00000000022 12203622411 0014726 0 ustar 00root root 0000000 0000000 cext.enabled=true ruby-git-1.2.6/.travis.yml 0000664 0000000 0000000 00000000242 12203622411 0015362 0 ustar 00root root 0000000 0000000 language: ruby rvm: - 1.8.7 - 1.9.2 - 1.9.3 - 2.0.0 - jruby-18mode - jruby-19mode - jruby-head - rbx-18mode - rbx-19mode - ree # - ruby-head ruby-git-1.2.6/Gemfile 0000664 0000000 0000000 00000000066 12203622411 0014550 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org' gemspec :name => 'git' ruby-git-1.2.6/History.txt 0000664 0000000 0000000 00000001632 12203622411 0015457 0 ustar 00root root 0000000 0000000 == 1.2.6 * Ruby 1.9.X/2.0 fully supported * JRuby 1.8/1.9 support * Rubinius support * Git.clone - supporting --recursive and --config * Git.log - supporting last and [] over the results * Git.add_remote - supporting -f and -t * Git.add - supporting --fore * Git.init - supporting --bare * Git.commit - supporting --all and --amend * Added Git.remote_remote, Git.revert and Git.clean * Added Bundler to the formula * Travis configuration * Licence included with the gem == 1.0.4 * added camping/gitweb.rb frontend * added a number of speed-ups == 1.0.3 * Sped up most of the operations * Added some predicate functions (commit?, tree?, etc) * Added a number of lower level operations (read-tree, write-tree, checkout-index, etc) * Fixed a bug with using bare repositories * Updated a good amount of the documentation == 1.0.2 * Added methods to the git objects that might be helpful == 1.0.1 * Initial version ruby-git-1.2.6/LICENSE 0000664 0000000 0000000 00000002061 12203622411 0014257 0 ustar 00root root 0000000 0000000 The MIT License Copyright (c) 2008 Scott Chacon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 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. ruby-git-1.2.6/README.md 0000664 0000000 0000000 00000016370 12203622411 0014541 0 ustar 00root root 0000000 0000000 # Git Library for Ruby Library for using Git in Ruby. ## Homepage Git public hosting of the project source code is at: http://github.com/schacon/ruby-git ## Install You can install Ruby/Git like this: $ sudo gem install git ## Code Status * [](https://travis-ci.org/schacon/ruby-git) * [](https://codeclimate.com/github/schacon/ruby-git) * [](https://gemnasium.com/schacon/ruby-git) ## Major Objects **Git::Base** - The object returned from a `Git.open` or `Git.clone`. Most major actions are called from this object. **Git::Object** - The base object for your tree, blob and commit objects, returned from `@git.gtree` or `@git.object` calls. the `Git::AbstractObject` will have most of the calls in common for all those objects. **Git::Diff** - returns from a `@git.diff` command. It is an Enumerable that returns `Git::Diff:DiffFile` objects from which you can get per file patches and insertion/deletion statistics. You can also get total statistics from the Git::Diff object directly. **Git::Status** - returns from a `@git.status` command. It is an Enumerable that returns `Git:Status::StatusFile` objects for each object in git, which includes files in the working directory, in the index and in the repository. Similar to running 'git status' on the command line to determine untracked and changed files. **Git::Branches** - Enumerable object that holds `Git::Branch objects`. You can call .local or .remote on it to filter to just your local or remote branches. **Git::Remote**- A reference to a remote repository that is tracked by this repository. **Git::Log** - An Enumerable object that references all the `Git::Object::Commit` objects that encompass your log query, which can be constructed through methods on the `Git::Log object`, like: `@git.log(20).object("some_file").since("2 weeks ago").between('v2.6', 'v2.7').each { |commit| [block] }` ## Examples Here are a bunch of examples of how to use the Ruby/Git package. Ruby < 1.9 will require rubygems to be loaded. ```ruby require 'rubygems' ``` Require the 'git' gem. ```ruby require 'git' ``` Here are the operations that need read permission only. ```ruby g = Git.open(working_dir, :log => Logger.new(STDOUT)) g.index g.index.readable? g.index.writable? g.repo g.dir g.log # returns array of Git::Commit objects g.log.since('2 weeks ago') g.log.between('v2.5', 'v2.6') g.log.each {|l| puts l.sha } g.gblob('v2.5:Makefile').log.since('2 weeks ago') g.object('HEAD^').to_s # git show / git rev-parse g.object('HEAD^').contents g.object('v2.5:Makefile').size g.object('v2.5:Makefile').sha g.gtree(treeish) g.gblob(treeish) g.gcommit(treeish) commit = g.gcommit('1cc8667014381') commit.gtree commit.parent.sha commit.parents.size commit.author.name commit.author.email commit.author.date.strftime("%m-%d-%y") commit.committer.name commit.date.strftime("%m-%d-%y") commit.message tree = g.gtree("HEAD^{tree}") tree.blobs tree.subtrees tree.children # blobs and subtrees g.revparse('v2.5:Makefile') g.branches # returns Git::Branch objects g.branches.local g.branches.remote g.branches[:master].gcommit g.branches['origin/master'].gcommit g.grep('hello') # implies HEAD g.blob('v2.5:Makefile').grep('hello') g.tag('v2.5').grep('hello', 'docs/') g.diff(commit1, commit2).size g.diff(commit1, commit2).stats g.gtree('v2.5').diff('v2.6').insertions g.diff('gitsearch1', 'v2.5').path('lib/') g.diff('gitsearch1', @git.gtree('v2.5')) g.diff('gitsearch1', 'v2.5').path('docs/').patch g.gtree('v2.5').diff('v2.6').patch g.gtree('v2.5').diff('v2.6').each do |file_diff| puts file_diff.path puts file_diff.patch puts file_diff.blob(:src).contents end g.config('user.name') # returns 'Scott Chacon' g.config # returns whole config hash g.tag # returns array of Git::Tag objects ``` And here are the operations that will need to write to your git repository. ```ruby g = Git.init Git.init('project') Git.init('/home/schacon/proj', { :git_dir => '/opt/git/proj.git', :index_file => '/tmp/index'} ) g = Git.clone(URI, NAME, :path => '/tmp/checkout') g.config('user.name', 'Scott Chacon') g.config('user.email', 'email@email.com') g.add # git add -- "." g.add(:all=>true) # git add --all -- "." g.add('file_path') # git add -- "file_path" g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2" g.remove('file.txt') g.remove(['file.txt', 'file2.txt']) g.commit('message') g.commit_all('message') g = Git.clone(repo, 'myrepo') g.chdir do new_file('test-file', 'blahblahblah') g.status.changed.each do |file| puts file.blob(:index).contents end end 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 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(g.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')) ``` Some examples of more low-level index and tree operations ```ruby g.with_temp_index do g.read_tree(tree3) # calls self.index.read_tree g.read_tree(tree1, :prefix => 'hi/') c = g.commit_tree('message') # or # t = g.write_tree c = g.commit_tree(t, :message => 'message', :parents => [sha1, sha2]) g.branch('branch_name').update_ref(c) g.update_ref(branch, c) g.with_temp_working do # new blank working directory g.checkout g.checkout(another_index) g.commit # commits to temp_index end end g.set_index('/path/to/index') g.with_index(path) do # calls set_index, then switches back after end g.with_working(dir) do # calls set_working, then switches back after end g.with_temp_working(dir) do g.checkout_index(:prefix => dir, :path_limiter => path) # do file work g.commit # commits to index end ``` ## License licensed under MIT License Copyright (c) 2008 Scott Chacon. See LICENSE for further details. ruby-git-1.2.6/Rakefile 0000664 0000000 0000000 00000001343 12203622411 0014721 0 ustar 00root root 0000000 0000000 require 'rdoc/task' require 'rubygems' require "#{File.expand_path(File.dirname(__FILE__))}/lib/git/version" task :default => :test desc "Upload Docs" task :upload_docs do |t| system('rsync -rv --delete doc/ git.rubyforge.org:/var/www/gforge-projects/git') end desc "Run Unit Tests" task :test do |t| sh 'git config --global user.email "git@example.com"' if `git config user.email`.empty? sh 'git config --global user.name "GitExample"' if `git config user.name`.empty? $VERBOSE = true require File.dirname(__FILE__) + '/tests/all_tests.rb' end Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = "ruby-git #{Git::VERSION}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end ruby-git-1.2.6/TODO 0000664 0000000 0000000 00000000627 12203622411 0013750 0 ustar 00root root 0000000 0000000 * more documentation * git rebase * diff additions - annotate, blame * submodule support * repository admin - prune, fsck, pack-refs, count-objects, unpack-objects * email/patch integration - request-pull(email_address), git-am, git-apply * compatible with git 1.4 * More Error Examples * More Git::Status methods * Speed up through pure ruby * Speed up through C bindings to libgit-thin ruby-git-1.2.6/VERSION 0000664 0000000 0000000 00000000006 12203622411 0014317 0 ustar 00root root 0000000 0000000 1.2.6 ruby-git-1.2.6/benchmark.rb 0000664 0000000 0000000 00000007243 12203622411 0015540 0 ustar 00root root 0000000 0000000 require 'fileutils' require 'benchmark' require 'rubygems' require 'ruby-prof' #require_gem 'git', '1.0.3' require 'lib/git' def main @wbare = File.expand_path(File.join('tests', 'files', 'working.git')) in_temp_dir do g = Git.clone(@wbare, 'test') g.chdir do n = 40 result = RubyProf.profile do puts "
" Benchmark.bm(8) do |x| run_code(x, 'objects') do @commit = g.gcommit('1cc8667014381') @tree = g.gtree('1cc8667014381^{tree}') @blob = g.gblob('v2.5:example.txt') @obj = g.object('v2.5:example.txt') end x.report('config ') do n.times do c = g.config c = g.config('user.email') c = g.config('user.email', 'schacon@gmail.com') end end x.report('diff ') do n.times do g.diff('gitsearch1', 'v2.5').lines g.diff('gitsearch1', 'v2.5').stats g.diff('gitsearch1', 'v2.5').patch end end x.report('path ') do n.times do g.dir.readable? g.index.readable? g.repo.readable? end end #------------------ x.report('status ') do n.times do g.status['example.txt'].mode_index s = g.status s.added s.added end end #------------------ x.report('log ') do n.times do log = g.log.between('v2.5').object('example.txt') log.size log.size log.first g.log.between('v2.5').object('example.txt').map { |c| c.message } g.log.since("2 years ago").map { |c| c.message } end end #------------------ x.report('branch ') do for i in 1..10 do g.checkout('master') g.branch('new_branch' + i.to_s).in_branch('test') do g.current_branch new_file('new_file_' + i.to_s, 'hello') g.add true end g.branch('new_branch').merge('new_branch' + i.to_s) g.checkout('new_branch') end end #------------------ x.report('tree ') do for i in 1..10 do tr = g.with_temp_index do g.read_tree('new_branch' + i.to_s) index = g.ls_files g.write_tree end end end rescue nil x.report('archive ') do n.times do f = g.gcommit('v2.6').archive # returns path to temp file end end rescue nil end end # Print a graph profile to text puts "" printer = RubyProf::GraphHtmlPrinter.new(result) printer.print(STDOUT, 1) printer = RubyProf::FlatPrinter.new(result) puts "
" printer.print(STDOUT, 1) puts "" end end end def run_code(x, name, times = 30) #result = RubyProf.profile do x.report(name) do for i in 1..times do yield i end end #end # Print a graph profile to text #printer = RubyProf::FlatPrinter.new(result) #printer.print(STDOUT, 0) 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 yield tmp_path end FileUtils.rm_r(tmp_path) if remove_after end main() ruby-git-1.2.6/camping/ 0000775 0000000 0000000 00000000000 12203622411 0014671 5 ustar 00root root 0000000 0000000 ruby-git-1.2.6/camping/gitweb.rb 0000664 0000000 0000000 00000104102 12203622411 0016475 0 ustar 00root root 0000000 0000000 require 'rubygems' require 'camping' require 'lib/git' # # gitweb is a web frontend on git # there is no user auth, so don't run this anywhere that anyone can use it # it's read only, but anyone can remove or add references to your repos # # everything but the archive and diff functions are now in pure ruby # # install dependencies # sudo gem install camping-omnibus --source http://code.whytheluckystiff.net # # todo # - diff/patch between any two objects # - expand patch to entire file # - set title properly # - grep / search function # - prettify : http://projects.wh.techno-weenie.net/changesets/3030 # - add user model (add/remove repos) # - implement http-push for authenticated users # # author : scott chacon # Camping.goes :GitWeb module GitWeb::Models class Repository < Base; end class CreateGitWeb < V 0.1 def self.up create_table :gitweb_repositories, :force => true do |t| t.column :name, :string t.column :path, :string t.column :bare, :boolean end end end end module GitWeb::Helpers def inline_data(identifier) section = "__#{identifier.to_s.upcase}__" @@inline_data ||= File.read(__FILE__).gsub(/.*__END__/m, '') data = @@inline_data.match(/(#{section}.)(.*?)((__)|(\Z))/m) data ? data[2] : nil # return nil if no second found end end module GitWeb::Controllers class Stylesheet < R '/css/highlight.css' def get @headers['Content-Type'] = 'text/css' inline_data(:css) end end class JsHighlight < R '/js/highlight.js' def get @headers['Content-Type'] = 'text/javascript' inline_data(:js) end end class Index < R '/' def get @repos = Repository.find :all render :index end end class Add < R '/add' def get @repo = Repository.new render :add end def post if Git.bare(input.repository_path) repo = Repository.create :name => input.repo_name, :path => input.repo_path, :bare => input.repo_bare redirect View, repo else redirect Index end end end class RemoveRepo < R '/remove/(\d+)' def get repo_id @repo = Repository.find repo_id @repo.destroy @repos = Repository.find :all render :index end end class View < R '/view/(\d+)' def get repo_id @repo = Repository.find repo_id @git = Git.bare(@repo.path) render :view end end class Fetch < R '/git/(\d+)/(.*)' def get repo_id, path @repo = Repository.find repo_id @git = Git.bare(@repo.path) File.read(File.join(@git.repo.path, path)) end end class Commit < R '/commit/(\d+)/(\w+)' def get repo_id, sha @repo = Repository.find repo_id @git = Git.bare(@repo.path) @commit = @git.gcommit(sha) render :commit end end class Tree < R '/tree/(\d+)/(\w+)' def get repo_id, sha @repo = Repository.find repo_id @git = Git.bare(@repo.path) @tree = @git.gtree(sha) render :tree end end class Blob < R '/blob/(\d+)/(.*?)/(\w+)' def get repo_id, file, sha @repo = Repository.find repo_id #logger = Logger.new('/tmp/git.log') #logger.level = Logger::INFO #@git = Git.bare(@repo.path, :log => logger) @git = Git.bare(@repo.path) @blob = @git.gblob(sha) @file = file render :blob end end class BlobRaw < R '/blob/(\d+)/(\w+)' def get repo_id, sha @repo = Repository.find repo_id @git = Git.bare(@repo.path) @blob = @git.gblob(sha) @blob.contents end end class Archive < R '/archive/(\d+)/(\w+)' def get repo_id, sha @repo = Repository.find repo_id @git = Git.bare(@repo.path) file = @git.gtree(sha).archive @headers['Content-Type'] = 'application/zip' @headers["Content-Disposition"] = "attachment; filename=archive.zip" File.new(file).read end end class Download < R '/download/(\d+)/(.*?)/(\w+)' def get repo_id, file, sha @repo = Repository.find repo_id @git = Git.bare(@repo.path) @headers["Content-Disposition"] = "attachment; filename=#{file}" @git.gblob(sha).contents end end class Diff < R '/diff/(\d+)/(\w+)/(\w+)' def get repo_id, tree1, tree2 @repo = Repository.find repo_id @git = Git.bare(@repo.path) @tree1 = tree1 @tree2 = tree2 @diff = @git.diff(tree2, tree1) render :diff end end class Patch < R '/patch/(\d+)/(\w+)/(\w+)' def get repo_id, tree1, tree2 @repo = Repository.find repo_id @git = Git.bare(@repo.path) @diff = @git.diff(tree1, tree2).patch end end end module GitWeb::Views def layout html do head do title 'test' link :href=>R(Stylesheet), :rel=>'stylesheet', :type=>'text/css' script '', :type => "text/javascript", :language => "JavaScript", :src => R(JsHighlight) end style <<-END, :type => 'text/css' body { font-family: verdana, arial, helvetica, sans-serif; color: #333; font-size: 13px; line-height: 18px;} h1 { background: #cce; padding: 10px; margin: 3px; } h3 { background: #aea; padding: 5px; margin: 3px; } .options { float: right; margin: 10px; } p { padding: 5px; } .odd { background: #eee; } .tag { margin: 5px; padding: 1px 3px; border: 1px solid #8a8; background: #afa;} .indent { padding: 0px 15px;} table tr td { font-size: 13px; } table.shortlog { width: 100%; } .timer { color: #666; padding: 10px; margin-top: 10px; } END body :onload => "sh_highlightDocument();" do before = Time.now().usec self << yield self << '