<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/git_shelve/replicated_shelve.rb</filename>
    </added>
    <added>
      <filename>lib/git_shelve/shelve.rb</filename>
    </added>
    <added>
      <filename>spec/all_git_shelves.rb</filename>
    </added>
    <added>
      <filename>spec/spec_helper.rb</filename>
    </added>
    <added>
      <filename>spec/unit/gitshelve_spec.rb</filename>
    </added>
    <added>
      <filename>spec/unit/replicated_shelve_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,208 +1,5 @@
-# ==== GitShelve
-# GitShelve makes it possible to store arbitrary data in a separate branch
-# of a git repository
-# This class was inspired and is loosely based upon John Wiegley's 
-# git_shelve.py and git-issues python scripts (http://github.com/jwiegley/git-issues/tree/master)
-#
-# === Example Usage
-#
-#   shelve = GitShelve.new(&quot;mybranch&quot;, &quot;/path/to/repository.git&quot;)
-#   sha1 = shelve.put(&quot;some data&quot;)
-#
-#   shelve.get(sha1)
-#   #-&gt; &quot;some data&quot;
-#
-#   sha1 = shelve.put do |f|
-#     # f is an IO object streaming directly into git!
-#     f.write(&quot;i can &quot;)
-#     f.write(&quot;stream my data &quot;)
-#     f.write(&quot;in chunks!&quot;)
-#   end
-#
-#   shelve.get(sha1)
-#   #-&gt; &quot;i can stream my data in chunks!&quot;
-#
-#   shelve.get(sha1) do |f|
-#     # this works the same with get!
-#     data = f.read
-#   end
-#
-#   data
-#   #-&gt; &quot;i can stream my data in chunks!&quot;
-#
-# === Author
-# Michael Siebert &lt;siebertm85@googlemail.com&gt;
-#
-# This piece of software wouldn't be possible without Git. Thanks
-# go out to the people who invented git!
-class GitShelve
-  
-  # Creates and initilializes a new Gitshelve object
-  # 
-  # ==== Parameters
-  #   branch&lt;String&gt;:: the name of the branch to store objects in
-  #   repo&lt;String&gt;:: the path to the git repository to work on. Defaults to the current directory
-  def initialize(branch, repo = &quot;.&quot;)
-    @branch = branch
-    @repository = File.expand_path(repo)
-    @head = nil
-  end
-  
-  # get a file from the repository
-  #
-  # ==== Parameters
-  #   sha1&lt;String&gt;:: the SHA1 of the object to retrieve
-  #   &amp;block:: if you supply a block, it gets yield with the IO object so you can read data directly from that stream
-  #
-  # ==== Returns
-  #   String:: the object's data if you didn't supply a block, otherwise nothing
-  def get(sha1, &amp;block)
-    git('cat-file', 'blob', sha1, :strip =&gt; false, &amp;block)
-  end
-  
-  # saves data to the repository
-  #
-  # ==== Parameters
-  #   data&lt;String&gt;:: the data to store
-  #   &amp;block:: if you supply a block, it gets yield with the IO object so you can write data directly to that stream
-  #
-  # ==== Returns
-  #   String:: the SHA1 of the saved data (keep this!)
-  def put(data = nil, &amp;block)
-    # write blob into repo
-    sha1 = git('hash-object', '-w', &quot;--stdin&quot;, :input =&gt; data, &amp;block)
-    sha1_first = sha1[0..1]
-    sha1_last = sha1[2..-1]
-    
-    # Merge this blob with existing issue blobs that share the same
-    # first two hash digits
-    ls_tree = git('ls-tree', '-r', current_head, '--', sha1_first)
-    ls_tree.gsub!(/\t#{sha1_first}\//, &quot;\t&quot;)
-    ls_tree.gsub!(/100644 blob #{sha1}\t#{sha1_last}/, '')
-    ls_tree += &quot;\n&quot; unless ls_tree.empty?
-    
-    tree = git('mktree', :input =&gt; &quot;#{ls_tree}100644 blob #{sha1}\t#{sha1_last}\n&quot;)
-    
-    # Merge it into the tree of issues overall
-    ls_tree = git('ls-tree', current_head)
-    ls_tree.gsub!(/040000 tree [0-9a-f]{40}\t#{sha1_first}\n/, '')
-    ls_tree += &quot;\n&quot; unless ls_tree.empty?
-    
-
-    tree = git('mktree', :input =&gt; &quot;#{ls_tree}040000 tree #{tree}\t#{sha1_first}\n&quot;)
-
-    # Commit the merged tree (though at this moment it's a dangling commit)
-    commit = git('commit-tree', tree, '-p', current_head, :input =&gt; &quot;Added #{sha1}&quot;)
-
-    # Update the HEAD of the branch to point to the commit we
-    # just made.
-    update_head(commit)
-    
-    sha1
-  end
-  
-  protected
-  
-  # returns the sha1 of the branch
-  # ==== Returns
-  #   String:: SHA1-Hash
-  def current_head
-    git(&quot;rev-parse&quot;, @branch, &quot;2&gt;&amp;1&quot;)
-  rescue GitError
-    create_branch
-  end
-  
-  # Make the current branch point to the new head
-  # ==== Parameters
-  #   new_head&lt;SHA1&gt;
-  #
-  # ==== Returns
-  #   SHA1:: new_head
-  def update_head(new_head)
-    if @head
-      git('update-ref', 'refs/heads/%s' % @branch, new_head, @head)
-    else
-      git('update-ref', 'refs/heads/%s' % @branch, new_head)
-    end
-
-    @head = new_head
-  end
-  
-  # try smart when creating the branch.
-  # first checks if there is a remote branch and uses this if there is.
-  # otherwise, creates a commit and from there the branch
-  #
-  # ==== Returns
-  #   String:: the SHA1 hash of the branches HEAD
-  def create_branch
-    begin
-      hash = git('rev-parse', &quot;origin/#{@branch}&quot;, &quot;2&gt;&amp;1&quot;)
-    rescue GitError
-      hash = git('hash-object', '-w', '--stdin', :input =&gt; &quot;Created #{@branch} branch\n&quot;)
-      hash = git('mktree', :input =&gt; &quot;100644 blob #{hash}\tproject\n&quot;)
-      hash = git('commit-tree', hash, :input =&gt; &quot;created #{@branch} branch&quot;)
-    end
-
-    git('branch', @branch, hash)
-    hash
-  end
-  
-  # passes the command over to git
-  # 
-  # ==== Parameters
-  #   cmd&lt;String&gt;:: the git command to execute
-  #   *rest:: any number of String arguments to the command, followed by an options hash
-  #   &amp;block:: if you supply a block, you can communicate with git throught a pipe. NEVER even think about closing the stream!
-  #
-  # ==== Options
-  #   :strip&lt;Boolean&gt;:: true to strip the output String#strip, false not to to it
-  #
-  # ==== Raises
-  #   GitError:: if git returns non-null, an Exception is raised
-  #
-  # ==== Returns
-  #   String:: if you didn't supply a block, the things git said on STDOUT, otherwise noting
-  def git(cmd, *rest, &amp;block)
-    if rest.last.kind_of?(Hash)
-      options = rest.last
-      args = rest[0..-2]
-    else
-      options = {}
-      args = rest
-    end
-    
-    options[:strip] = true unless options.key?(:strip)
-    
-    ENV[&quot;GIT_DIR&quot;] = @repository
-    cmd = &quot;git-#{cmd} #{args.join(' ')}&quot;
-
-    result = &quot;&quot;
-    IO.popen(cmd, &quot;w+&quot;) do |f|
-      if input = options.delete(:input)
-        f.write(input)
-        f.close_write
-      elsif block_given?
-        yield f
-        f.close_write
-      end
-      
-      result = &quot;&quot;
-      
-      while !f.eof
-        result &lt;&lt; f.read
-      end
-    end
-    status = $?
-    
-    result.strip! if options[:strip] == true
-    
-    if status != 0
-      raise GitError.new(&quot;Error: #{cmd} returned #{status}. Result: #{result}&quot;)
-    end
-    
-    result
-  end
+module GitShelve
 end
 
-class GitError &lt; Exception
-end
\ No newline at end of file
+require File.join(File.dirname(__FILE__), &quot;git_shelve&quot;, &quot;shelve&quot;)
+require File.join(File.dirname(__FILE__), &quot;git_shelve&quot;, &quot;replicated_shelve&quot;)</diff>
      <filename>lib/git_shelve.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>spec/gitshelve_spec.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>e30b41f7fbe195d45e702f3cafd0f48ab8d62a50</id>
    </parent>
  </parents>
  <author>
    <name>Michael Siebert</name>
    <email>siebertm85@googlemail.com</email>
  </author>
  <url>http://github.com/siebertm/git-shelve/commit/37295dbe4bb6d980d2d8ce2dc16bfc29ab56526e</url>
  <id>37295dbe4bb6d980d2d8ce2dc16bfc29ab56526e</id>
  <committed-date>2008-05-18T05:06:39-07:00</committed-date>
  <authored-date>2008-05-18T05:06:39-07:00</authored-date>
  <message>A big update:
* reorganized directory structure for both lib and spec directories
* improved and refactored specs
* added ReplicatedGitShelve to be able to replicate changes between repositories</message>
  <tree>06c117f04ee0f2a90ce9c9675fbb9c70ee02b468</tree>
  <committer>
    <name>Michael Siebert</name>
    <email>siebertm85@googlemail.com</email>
  </committer>
</commit>
