Class: Mercurial::Node

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

Overview

The class represents Mercurial file or directory. Data obtained by scanning hg manifest output.

The class represents Node object itself, NodeFactory is responsible for assembling instances of Node. For the list of all possible branch-related operations please look documentation for NodeFactory.

Additionally Manifest is responsible for reading and scanning the manifest.

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.



33
34
35
36
37
38
39
40
41
42
# File 'lib/mercurial-ruby/node.rb', line 33

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



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

def executable
  @executable
end

#fmodeObject (readonly)

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



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

def fmode
  @fmode
end

#nodeidObject (readonly)

nodeid value for the node (if file).



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

def nodeid
  @nodeid
end

#parentObject (readonly)

Node’s parent, instance of Node.



31
32
33
# File 'lib/mercurial-ruby/node.rb', line 31

def parent
  @parent
end

#pathObject (readonly)

Absolute path to the node.



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

def path
  @path
end

#repositoryObject (readonly)

Instance of Repository.



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

def repository
  @repository
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


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

def binary?
  false
end

#blameObject



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

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

#contentsObject



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

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

#diff_to(revision_b) ⇒ Object



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

def diff_to(revision_b)
  repository.diffs.for_path(path, revision, revision_b)
end

#directory?Boolean

Returns:

  • (Boolean)


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

def directory?
  not file?
end

#entriesObject



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

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

#file?Boolean

Returns:

  • (Boolean)


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

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

#has_entry?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#nameObject



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

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

#path_without_parentObject



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

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

#revisionObject



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

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

#root?Boolean

Returns:

  • (Boolean)


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

def root?
  false
end

#sizeObject



102
103
104
# File 'lib/mercurial-ruby/node.rb', line 102

def size
  contents.size
end