Sha256: e92385436389c634914231ceea56f283f7838f4325a343c0e096844c6b7e1b32

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 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)
      revision ||= 'tip'
      hg(manifest_cmd(revision))
    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.5.0 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.4.0 lib/mercurial-ruby/manifest.rb
mercurial-ruby-0.3.0 lib/mercurial-ruby/manifest.rb