Sha256: 6ac37e60fe29525a0325683d4cf38daf9faf596732ee1decf1d96f7ab919b835

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

module Mercurial  
  class RepositoryNotFound < Error; end
  
  class Repository
    
    def self.create(destination)
      init_repository(destination)      
    end
    
    def self.open(destination)
      if File.exists?(destination)
        new(destination)
      else
        raise Mercurial::RepositoryNotFound.new(destination)
      end
    end
    
    def initialize(source)
      @path = source
    end
    
    def shell
      @_shell ||= Mercurial::Shell.new(self)
    end
    
    def config
      @_config ||= Mercurial::ConfigFile.new(self)
    end
    
    def hooks
      @_hook_factory ||= Mercurial::HookFactory.new(self)
    end
    
    def commits
      @_commits ||= Mercurial::CommitFactory.new(self)
    end
    
    def branches
      @_branches ||= Mercurial::BranchFactory.new(self)
    end
    
    def tags
      @_tags ||= Mercurial::TagFactory.new(self)
    end
    
    def diffs
      @_diffs ||= Mercurial::DiffFactory.new(self)
    end
    
    def nodes
      @_nodes ||= Mercurial::NodeFactory.new(self)
    end
    
    def blames
      @_blames ||= Mercurial::BlameFactory.new(self)
    end
    
    def manifest
      @_manifest ||= Mercurial::Manifest.new(self)
    end
    
    def file_index
      @_file_index ||= Mercurial::FileIndex.new(self)
    end
    
    def node(name, hash_id)
      nodes.find(name, hash_id)
    end
    
    def destroy!
      FileUtils.rm_rf(path)
    end
    
    def path
      File.expand_path(@path)
    end
    
    def dothg_path
      File.join(path, '.hg')
    end
    
    def mtime
      File.mtime(dothg_path).to_i
    end
    
  protected
  
    def self.init_repository(destination)
      Mercurial::Shell.run("mkdir -p #{ destination }")
      open(destination).tap do |repo|
        repo.shell.hg('init', :cache => false)
        repo.shell.hg('update null', :cache => false)
      end
    end
    
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercurial-ruby-0.5.0 lib/mercurial-ruby/repository.rb
mercurial-ruby-0.4.0 lib/mercurial-ruby/repository.rb