Class: Mercurial::Node

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

Overview

This class represents a file or a directory stored inside a repository. The data is provided by Manifest.

To see how Node instances are assembled, check the NodeFactory.

Direct Known Subclasses

RootNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#hg, #hg_to_array, #shell

Constructor Details

#initialize(opts = {}) ⇒ Node

Returns a new instance of Node.



29
30
31
32
33
34
35
36
37
38
# File 'lib/mercurial-ruby/node.rb', line 29

def initialize(opts={})
  @repository = opts[:repository]
  @path       = opts[:path]
  @parent     = opts[:parent]
  @name       = opts[:name]
  @fmode      = opts[:fmode]
  @executable = opts[:executable] == '*' ? true : false
  @revision   = opts[:revision]
  @nodeid     = opts[:nodeid]
end

Instance Attribute Details

#executableObject (readonly)

Executable flag of the node (if file).



21
22
23
# File 'lib/mercurial-ruby/node.rb', line 21

def executable
  @executable
end

#fmodeObject (readonly)

File mode of the node in Octal notation (if file).



18
19
20
# File 'lib/mercurial-ruby/node.rb', line 18

def fmode
  @fmode
end

#nodeidObject (readonly)

nodeid value for the node (if file).



24
25
26
# File 'lib/mercurial-ruby/node.rb', line 24

def nodeid
  @nodeid
end

#parentObject (readonly)

Node’s parent, instance of Node.



27
28
29
# File 'lib/mercurial-ruby/node.rb', line 27

def parent
  @parent
end

#pathObject (readonly)

Absolute path to the node.



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

def path
  @path
end

#repositoryObject (readonly)

Instance of Repository.



12
13
14
# File 'lib/mercurial-ruby/node.rb', line 12

def repository
  @repository
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/mercurial-ruby/node.rb', line 90

def binary?
  false
end

#blameObject



68
69
70
# File 'lib/mercurial-ruby/node.rb', line 68

def blame
  repository.blames.for_path(path, revision)
end

#contentsObject



94
95
96
# File 'lib/mercurial-ruby/node.rb', line 94

def contents
  hg(["cat ? -r ?", path, revision])
end

#diff_to(revision_b, options = {}) ⇒ Object



64
65
66
# File 'lib/mercurial-ruby/node.rb', line 64

def diff_to(revision_b, options={})
  repository.diffs.for_path(path, revision, revision_b, options)
end

#directory?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/mercurial-ruby/node.rb', line 78

def directory?
  not file?
end

#entriesObject



60
61
62
# File 'lib/mercurial-ruby/node.rb', line 60

def entries
  @_entries ||= repository.nodes.entries_for(path, revision, self)
end

#file?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/mercurial-ruby/node.rb', line 82

def file?
  (name =~ /\/$/).nil?
end

#has_entry?(name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
# File 'lib/mercurial-ruby/node.rb', line 72

def has_entry?(name)
  entries.find do |e|
    e.name == name
  end
end

#nameObject



40
41
42
43
44
45
46
# File 'lib/mercurial-ruby/node.rb', line 40

def name
  @name ||= begin
    n = path.split('/').last
    n << '/' if path =~ /\/$/
    n
  end
end

#path_without_parentObject



52
53
54
55
56
57
58
# File 'lib/mercurial-ruby/node.rb', line 52

def path_without_parent
  if parent
    path.gsub(/^#{ Regexp.escape(parent.path) }/, '')
  else
    path
  end
end

#revisionObject



48
49
50
# File 'lib/mercurial-ruby/node.rb', line 48

def revision
  @revision || (parent ? parent.revision : nil) || 'tip'
end

#root?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/mercurial-ruby/node.rb', line 86

def root?
  false
end

#sizeObject



98
99
100
# File 'lib/mercurial-ruby/node.rb', line 98

def size
  contents.size
end