Class: Mercurial::Manifest

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/mercurial-ruby/manifest.rb

Overview

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:

mercurial.selenic.com/wiki/Manifest

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#hg, #hg_to_array, #shell

Constructor Details

#initialize(repository) ⇒ Manifest

Returns a new instance of Manifest.



17
18
19
# File 'lib/mercurial-ruby/manifest.rb', line 17

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Instance of Repository.



15
16
17
# File 'lib/mercurial-ruby/manifest.rb', line 15

def repository
  @repository
end

Instance Method Details

#contents(revision = nil, cmd_options = {}) ⇒ Object

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


27
28
29
30
31
32
33
34
# File 'lib/mercurial-ruby/manifest.rb', line 27

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

#scan_for_path(path, revision = nil) ⇒ Object

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')


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mercurial-ruby/manifest.rb', line 43

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