Sha256: c157db121362612c62b6f67fce1730f6db3b15bd7a1144de1d9621c188d4a0f7

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 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)
    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

3 entries across 3 versions & 1 rubygems

Version Path
mercurial-ruby-0.7.0 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.6.1 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.6.0 lib/mercurial-ruby/manifest.rb