Class: PVN::IO::Element

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/pvn/io/element.rb

Overview

An element unites an svn element and a file/directory (at least one of which should exist).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = Hash.new) ⇒ Element

Returns a new instance of Element.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pvn/io/element.rb', line 32

def initialize args = Hash.new
  info "args: #{args}"
  
  svnurl = args[:svnurl]
  fname  = args[:filename] || args[:file] # legacy
  # $$$ todo: map svnurl to SVNElement, and fname to FSElement

  @svn   = args[:svn] || (args[:file] && SVNElement.new(:filename => args[:file]))
  @local = args[:local] && PVN::FSElement.new(args[:local] || args[:file])
  @path  = args[:path]
  
  info "local: #{@local}"
end

Instance Attribute Details

#localObject (readonly)

Returns the value of attribute local.



30
31
32
# File 'lib/pvn/io/element.rb', line 30

def local
  @local
end

#svnObject (readonly)

Returns the value of attribute svn.



29
30
31
# File 'lib/pvn/io/element.rb', line 29

def svn
  @svn
end

Instance Method Details

#<=>(other) ⇒ Object

def line_counts

[ @svnelement && @svnelement.line_count, @fselement && @fselement.line_count ]

end



202
203
204
# File 'lib/pvn/io/element.rb', line 202

def <=> other
  @svn <=> other.svn
end

#cat(revision, use_cache = false) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/pvn/io/element.rb', line 135

def cat revision, use_cache = false
  path = (@local || @path || @svn).dup
  if revision && revision != :working_copy
    path << '@' << revision.to_s
  end
  info "path: #{path}"
  catargs = SVNx::CatCommandArgs.new :path => path, :use_cache => use_cache
  cmd = SVNx::CatCommand.new catargs
  cmd.execute
end

#directory?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
# File 'lib/pvn/io/element.rb', line 50

def directory?
  if exist?
    @local.directory?
  else
    # look it up with svn info
    false
  end
end

#exist?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/pvn/io/element.rb', line 46

def exist?
  @local && @local.exist?
end

#file?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/pvn/io/element.rb', line 59

def file?
  if exist?
    @local.file?
  else
    raise "need this"
  end
end

#find_filesObject

returns a set of local files that are in the given status



147
148
# File 'lib/pvn/io/element.rb', line 147

def find_files
end

#find_files_by_status(status = nil) ⇒ Object

returns a set of local files that are in the given status



151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/pvn/io/element.rb', line 151

def find_files_by_status status = nil
  cmdargs = SVNx::StatusCommandArgs.new :path => @local, :use_cache => false
  cmd = SVNx::StatusCommand.new cmdargs
  xmllines = cmd.execute
  entries = SVNx::Status::Entries.new :xmllines => xmllines
  
  if status
    entries.select do |entry|
      entry.status == status
    end
  else
    entries
  end
end

#find_modified_entries(revision) ⇒ Object

returns a set of entries modified over the given revision



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/pvn/io/element.rb', line 93

def find_modified_entries revision
  cmdargs = Hash.new

  svninfo = get_info

  filter = svninfo.url.dup
  filter.slice! svninfo.root

  cmdargs[:path] = @local
  
  # we can't cache this, because we don't know if there has been an svn
  # update since the previous run:
  cmdargs[:use_cache] = false
  cmdargs[:limit] = nil
  cmdargs[:verbose] = true
  cmdargs[:revision] = revision

  logargs = SVNx::LogCommandArgs.new cmdargs
  entries = log(logargs).entries

  modified = Set.new

  entries.each do |entry|
    entry.paths.each do |epath|
      if epath.action == 'M' && epath.name.start_with?(filter)
        modified << epath
      end
    end
  end

  modified
end

#find_modified_filesObject

returns a set of local files that are in modified status



167
168
169
# File 'lib/pvn/io/element.rb', line 167

def find_modified_files
  find_files_by_status 'modified'
end

#get_info(revision = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/pvn/io/element.rb', line 67

def get_info revision = nil
  usepath = @local || @path
  cmdargs = SVNx::InfoCommandArgs.new :path => usepath, :revision => revision
  infcmd  = SVNx::InfoCommand.new cmdargs
  output  = infcmd.execute
  
  infentries = SVNx::Info::Entries.new :xmllines => output
  infentries[0]
end

#has_revision?(rev) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
84
85
86
87
88
89
90
# File 'lib/pvn/io/element.rb', line 81

def has_revision? rev
  # was there a revision then?
  begin
    svninfo = get_info rev
    true
  rescue => e
    # skip it
    false
  end
end

#log(cmdargs = SVNx::LogCommandArgs.new) ⇒ Object

returns log entries



172
173
174
175
176
177
# File 'lib/pvn/io/element.rb', line 172

def log cmdargs = SVNx::LogCommandArgs.new
  # $$$ todo: this should be either @local if set, otherwise @svn (url)
  # cmdargs.path = @local
  cmd = SVNx::LogCommand.new cmdargs
  SVNx::Log::Entries.new :xmllines => cmd.execute
end

#logentries(revision) ⇒ Object

returns log entries



180
181
182
183
184
185
186
# File 'lib/pvn/io/element.rb', line 180

def logentries revision
  # use_cache should be conditional on revision:
  # cmdargs[:use_cache] = false
  cmdargs = SVNx::LogCommandArgs.new :path => @local, :revision => revision.to_s, :use_cache => false, :verbose => true
  cmd = SVNx::LogCommand.new cmdargs
  SVNx::Log::Entries.new :xmllines => cmd.execute
end

#repo_rootObject



77
78
79
# File 'lib/pvn/io/element.rb', line 77

def repo_root
  get_info.root
end

#statusObject

returns :added, :deleted, “modified”



189
190
191
192
193
194
195
196
# File 'lib/pvn/io/element.rb', line 189

def status
  cmdargs = SVNx::StatusCommandArgs.new :path => @local
  cmd = SVNx::StatusCommand.new :cmdargs => cmdargs
  xmllines = cmd.execute
  entries = SVNx::Status::Entries.new :xmllines => xmllines
  entry = entries[0]
  entry.status
end

#to_sObject



206
207
208
# File 'lib/pvn/io/element.rb', line 206

def to_s
  "svn => " + @svn.to_s + "; local => " + @local.to_s
end

#xxxcat_remote(rev = nil) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/pvn/io/element.rb', line 126

def xxxcat_remote rev = nil
  path = @local || @svn
  info "path: #{path}".blue
  info "rev: #{rev}; #{rev.class}".blue
  catargs = SVNx::CatCommandArgs.new :path => path, :use_cache => false, :revision => rev
  cmd = SVNx::CatCommand.new catargs
  cmd.execute
end