Sha256: 78b362413ada06c7db83bc09f667560298f477100b299c50df0e5da4065a1cc4

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

module Mercurial
  
  #
  # Represents Mercurial manifest file. Use this class to get manifest's contents
  # and scan it for file paths at specific revisions.
  #
  # Read more about Mercurial manifest:
  #
  # http://mercurial.selenic.com/wiki/Manifest
  #
  class Manifest
    include Mercurial::Helper
    
    # Instance of {Mercurial::Repository Repository}.
    attr_reader :repository
    
    def initialize(repository)
      @repository = repository
    end
    
    # Returns contents of the manifest as a String at a specified revision.
    # Latest version of the manifest is used if +revision+ is ommitted.
    #
    # === Example:
    #  repository.manifest.contents
    #
    def contents(revision=nil, cmd_options={})
      revision ||= 'tip'
      hg(manifest_cmd(revision), cmd_options).tap do |res|
        if RUBY_VERSION >= '1.9.1'
          res.force_encoding('utf-8')
        end
      end
    end
    
    # Returns an array of file paths from manifest that start with the specified +path+ at a specified +revision+.
    # Latest version of the manifest is used if +revision+ is ommitted.
    #
    # === Example:
    #  repository.manifest.scan_for_path('/')
    #  repository.manifest.scan_for_path('some-interesting-directory/', '2d32410d9629')
    #
    def scan_for_path(path, revision=nil)
      revision ||= 'tip'
      path = path.without_trailing_slash
      if path == '/' || path == ''
        search_for = ".*"
      else
        path_re = Regexp.escape(path)
        search_for = "#{ path_re }$|#{ path_re }\/.*"
      end
      contents(revision).scan(/^(\w{40}) (\d{3}) (\*?) +(#{ search_for })/)
    end
    
  private
  
    def manifest_cmd(revision)
      ["manifest -r ? --debug", revision]
    end
  end
    
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mercurial-ruby-0.7.12 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.7.11 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.7.10 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.7.9 lib/mercurial-ruby/manifest.rb