pvn 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/pvn/app.rb CHANGED
@@ -9,13 +9,11 @@ require 'pvn/io/element'
9
9
  require 'svnx/log/entries'
10
10
 
11
11
  require 'pvn/subcommands/log/command'
12
-
13
- # not yet supported:
14
- # require 'pvn/subcommands/pct/command'
12
+ require 'pvn/subcommands/pct/command'
15
13
 
16
14
  # the old ones:
17
15
  require 'pvn/diff/diffcmd'
18
- require 'pvn/pct/pctcmd'
16
+ # require 'pvn/pct/pctcmd'
19
17
  require 'pvn/describe'
20
18
  require 'pvn/upp/uppcmd'
21
19
  require 'pvn/wherecmd'
@@ -46,8 +44,7 @@ module PVN::App
46
44
  when "log"
47
45
  run_command PVN::Subcommands::Log::Command, args
48
46
  when "pct"
49
- $stderr.puts "subcommand 'pct' is not yet supported"
50
- exit(-1)
47
+ run_command PVN::Subcommands::Pct::Command, args
51
48
  else
52
49
  $stderr.puts "ERROR: subcommand not valid: #{arg}"
53
50
  exit(-1)
@@ -62,7 +59,7 @@ module PVN::App
62
59
  cmdcls.new args
63
60
  exit(0)
64
61
  rescue => e
65
- # puts e.backtrace
62
+ puts e.backtrace
66
63
  $stderr.puts e
67
64
  exit(-1)
68
65
  end
@@ -84,6 +81,7 @@ module PVN::App
84
81
  end
85
82
 
86
83
  SUBCOMMANDS = [ PVN::Subcommands::Log::Command,
84
+ PVN::Subcommands::Pct::Command,
87
85
  # DiffCommand,
88
86
  # DescribeCommand,
89
87
  # PctCommand,
@@ -62,7 +62,67 @@ module PVN::IO
62
62
  end
63
63
  end
64
64
 
65
- def svninfo
65
+ def get_info
66
+ cmdargs = SVNx::InfoCommandArgs.new :path => @local
67
+ infcmd = SVNx::InfoCommand.new cmdargs
68
+ output = infcmd.execute
69
+
70
+ infentries = SVNx::Info::Entries.new :xmllines => output
71
+ infentries[0]
72
+ end
73
+
74
+ def repo_root
75
+ get_info.root
76
+ end
77
+
78
+ # returns a set of entries modified over the given revision
79
+ def find_modified_entries revision
80
+ cmdargs = Hash.new
81
+
82
+ cmdargs[:path] = @local
83
+
84
+ info "cmdargs[:revision]: #{cmdargs[:revision]}"
85
+
86
+ # we can't cache this, because we don't know if there has been an svn
87
+ # update since the previous run:
88
+ cmdargs[:use_cache] = false
89
+ cmdargs[:limit] = nil
90
+ cmdargs[:verbose] = true
91
+ cmdargs[:revision] = revision
92
+
93
+ logargs = SVNx::LogCommandArgs.new cmdargs
94
+ entries = log(logargs).entries
95
+
96
+ modified = Set.new
97
+
98
+ info "entries: #{entries}"
99
+ entries.each do |entry|
100
+ info "entry: #{entry}".on_blue
101
+ info entry.paths
102
+ entry.paths.each do |epath|
103
+ modified << epath if epath.action == 'M'
104
+ end
105
+ end
106
+
107
+ modified
108
+ end
109
+
110
+ # returns a set of local files that are in the given status
111
+ def find_files_by_status status
112
+ cmdargs = SVNx::StatusCommandArgs.new :path => @local, :use_cache => false
113
+
114
+ cmd = SVNx::StatusCommand.new cmdargs
115
+ xml = cmd.execute
116
+ entries = SVNx::Status::Entries.new :xmllines => xml
117
+
118
+ entries.select do |entry|
119
+ entry.status == status
120
+ end
121
+ end
122
+
123
+ # returns a set of local files that are in modified status
124
+ def find_modified_files
125
+ find_files_by_status 'modified'
66
126
  end
67
127
 
68
128
  # returns log entries
@@ -3,6 +3,9 @@
3
3
 
4
4
  require 'svnx/log/entries'
5
5
 
6
+ # This is an abuse of all the element/entry nonsense in this code. This will
7
+ # replace lib/pvn/revision.rb as PVN::Revision.
8
+
6
9
  module PVN::Revision
7
10
  DATE_REGEXP = Regexp.new '^\{(.*?)\}'
8
11
  SVN_REVISION_WORDS = %w{ HEAD BASE COMMITTED PREV }
@@ -9,11 +9,9 @@ require 'pvn/subcommands/base/command'
9
9
 
10
10
  module PVN::Subcommands::Log
11
11
  class Command < PVN::Subcommands::Base::Command
12
- include Loggable
13
12
 
14
13
  DEFAULT_LIMIT = 15
15
14
 
16
- description "this is a description of log"
17
15
  subcommands [ "log" ]
18
16
  description "Print log messages for the given files."
19
17
  usage "[OPTIONS] FILE..."
@@ -1,15 +1,188 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- module PVN; module App; end; end
4
+ require 'pvn/io/element'
5
+ require 'pvn/subcommands/pct/options'
6
+ require 'pvn/subcommands/base/command'
7
+ require 'svnx/info/command'
8
+ require 'svnx/status/command'
9
+ require 'svnx/cat/command'
10
+ require 'set'
5
11
 
6
- module PVN::App::Pct
7
- class Command
8
- include Loggable
12
+ module PVN::Subcommands::Pct
13
+ class DiffCount
14
+ attr_reader :from
15
+ attr_reader :to
9
16
 
17
+ def initialize from = 0, to = 0
18
+ @from = from
19
+ @to = to
20
+ end
21
+
22
+ def print name
23
+ diff = to - from
24
+ diffpct = diff == 0 ? 0 : 100.0 * diff / from
25
+
26
+ printf "%8d %8d %8d %8.1f%% %s\n", from, to, diff, diffpct, name
27
+ end
28
+
29
+ def << diff
30
+ @from += diff.from
31
+ @to += diff.to
32
+ end
33
+ end
34
+
35
+ class Command < PVN::Subcommands::Base::Command
36
+
37
+ DEFAULT_LIMIT = 15
38
+
39
+ subcommands [ "pct" ]
40
+ description "Compares revisions as a percentage of lines modified."
41
+ usage "[OPTIONS] FILE..."
42
+ summary [ "Compares to revisions, showing the changes in the size (length)",
43
+ "of files that have been modified in the latter revision, to",
44
+ "show the extent to which they have increased or decreased.",
45
+ "The columns are:",
46
+ " - length in svn repository",
47
+ " - length in local version",
48
+ " - difference",
49
+ " - percentage change",
50
+ " - file name",
51
+ "The total numbers are displayed as the last line.",
52
+ "Added and deleted files are not included." ]
53
+
54
+ optscls
55
+
56
+ example "pvn pct foo.rb", "Prints the changes in foo.rb, working copy against BASE."
57
+ example "pvn pct -r114:121", "Prints the changes for all files, revision 114 against 121. (not yet supported)"
58
+ example "pvn pct -rHEAD", "Prints the changes, working copy against HEAD. (not yet supported)"
59
+ example "pvn pct -r117", "Prints the changes between revision 117 and the previous revision. (not yet supported)"
60
+ example "pvn pct -7", "Prints the changes between relative revision -7 and the previous revision. (not yet supported)"
61
+ example "pvn pct -r31 -4", "Prints the changes between revision 31 and relative revision -4. (not yet supported)"
62
+
10
63
  def initialize args
11
- clargs = PVN::App::Pct::CmdLineArgs.new args
12
- info "clargs: #{clargs}"
64
+ options = PVN::Subcommands::Pct::OptionSet.new
65
+ options.process args
66
+
67
+ return show_help if options.help
68
+
69
+ info "options: #{options}"
70
+
71
+ path = options.paths[0] || "."
72
+ cmdargs = Hash.new
73
+
74
+ cmdargs[:path] = path
75
+
76
+ if options.revision && !options.revision.empty?
77
+ compare_by_revisions options
78
+ else
79
+ compare_local_to_base options
80
+ end
81
+ end
82
+
83
+ ### $$$ this belongs in Revision
84
+ def get_from_to_revisions rev
85
+ if rev.kind_of? Array
86
+ if rev.size == 1
87
+ if md = Regexp.new('(.+):(.+)').match(rev[0])
88
+ return [ md[1], md[2] ]
89
+ else
90
+ return [ (rev[0].to_i - 1).to_s, rev[0] ]
91
+ end
92
+ else
93
+ return [ rev[0], rev[1] ]
94
+ end
95
+ else
96
+ info "rev: #{rev}".bold.white.on_red
97
+ end
98
+ end
99
+
100
+ def compare_by_revisions options
101
+ # what was modified between the revisions?
102
+
103
+ path = options.paths[0] || "."
104
+
105
+ elmt = PVN::IO::Element.new :local => path || '.'
106
+ modified = elmt.find_modified_entries options.revision
107
+
108
+ modnames = modified.collect { |m| m.name }
109
+
110
+ info "modnames: #{modnames.inspect}".yellow
111
+
112
+ rev = options.revision
113
+
114
+ info "rev: #{rev}; #{rev.class}".blue.on_yellow
115
+ info "rev: #{rev.inspect}; #{rev.class}".blue.on_yellow
116
+
117
+ fromrev, torev = get_from_to_revisions options.revision
118
+
119
+ info "fromrev: #{fromrev}; torev: #{torev}".black.on_green
120
+ info "fromrev: #{fromrev.class}; torev: #{torev.class}".black.on_green
121
+
122
+ total = DiffCount.new
123
+
124
+ reporoot = elmt.repo_root
125
+
126
+ modnames.each do |mod|
127
+ info "mod: #{mod}"
128
+
129
+ fullpath = reporoot + mod
130
+
131
+ from_count = get_line_count fullpath, fromrev
132
+ info "from_count: #{from_count}".red
133
+
134
+ to_count = get_line_count fullpath, torev
135
+ info "to_count: #{to_count}".red
136
+
137
+ dc = DiffCount.new from_count, to_count
138
+ total << dc
139
+ dc.print mod
140
+ end
141
+
142
+ total.print 'total'
143
+ end
144
+
145
+ def get_line_count path, revision
146
+ cmdargs = SVNx::CatCommandArgs.new :path => path, :revision => revision
147
+ catcmd = SVNx::CatCommand.new cmdargs
148
+ info "catcmd: #{catcmd}"
149
+
150
+ count = catcmd.execute.size
151
+ info "count: #{count}"
152
+
153
+ count
154
+ end
155
+
156
+ def compare_local_to_base options
157
+ # do we support multiple paths?
158
+ path = options.paths[0] || '.'
159
+
160
+ elmt = PVN::IO::Element.new :local => path || '.'
161
+ modified = elmt.find_modified_files
162
+
163
+ total = DiffCount.new
164
+
165
+ modified.each do |entry|
166
+ catcmd = SVNx::CatCommand.new entry.path
167
+ info "catcmd: #{catcmd}"
168
+
169
+ svn_count = catcmd.execute.size
170
+ info "svn_count: #{svn_count}"
171
+
172
+ local_count = Pathname.new(entry.path).readlines.size
173
+ info "local_count: #{local_count}"
174
+
175
+ dc = DiffCount.new svn_count, local_count
176
+ total << dc
177
+ dc.print entry.path
178
+ end
179
+
180
+ total.print 'total'
181
+ end
182
+ end
183
+ end
184
+
185
+ __END__
13
186
 
14
187
  elmt = PVN::IO::Element.new :local => clargs.path || '.'
15
188
  info "elmt: #{elmt}".red
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'pvn/subcommands/revision/multiple_revisions_option'
5
+ require 'pvn/subcommands/base/options'
6
+
7
+ module PVN::Subcommands::Pct
8
+ class OptionSet < PVN::Subcommands::Base::OptionSet
9
+ has_option :revision, PVN::MultipleRevisionsRegexpOption
10
+ has_option :help, PVN::Subcommands::Base::HelpOption
11
+
12
+ def paths
13
+ unprocessed
14
+ end
15
+ end
16
+ end
@@ -6,13 +6,7 @@ require 'pvn/subcommands/revision/revision_regexp_option'
6
6
  module PVN
7
7
  # A revision option with multiple values.
8
8
  class MultipleRevisionsRegexpOption < RevisionRegexpOption
9
- REVISION_DESCRIPTION = [ "revision to apply.",
10
- "ARG can be relative, of the form:",
11
- " +N : N revisions from the BASE",
12
- " -N : N revisions from the HEAD,",
13
- " when -1 is the previous revision" ,
14
- "Multiple revisions can be specified." ,
15
- ]
9
+ REVISION_DESCRIPTION = RevisionRegexpOption::REVISION_DESCRIPTION + [ "Multiple revisions can be specified." ]
16
10
 
17
11
  def set_value val
18
12
  currval = value
@@ -72,5 +72,8 @@ module PVN
72
72
  revval = reventry.value.to_s
73
73
  revval
74
74
  end
75
+
76
+ def entry
77
+ end
75
78
  end
76
79
  end
@@ -6,7 +6,7 @@ require 'pvn/subcommands/revision/revision_option'
6
6
  module PVN
7
7
  # A revision that is also set by -N and +N.
8
8
  class RevisionRegexpOption < PVN::RevisionOption
9
- TAG_RE = Regexp.new('^(?:([\-\+]\d+)|(-r(.+)))$')
9
+ TAG_RE = Regexp.new '^(?:([\-\+]\d+)|(-r(.+)))$'
10
10
 
11
11
  REVISION_DESCRIPTION = [ "revision to apply.",
12
12
  "ARG can be relative, of the form:",
@@ -16,20 +16,15 @@ module PVN
16
16
  ]
17
17
 
18
18
  def initialize revargs = Hash.new
19
- # info "revargs: #{revargs}"
20
19
  revargs[:regexp] = TAG_RE
21
20
  super
22
21
  end
23
22
 
24
23
  def resolve_value optset, unprocessed
25
24
  val = value
26
- # info "val: #{val}"
27
-
28
- md = TAG_RE.match val
29
- # info "md: #{md.inspect}"
25
+ md = TAG_RE.match val
30
26
 
31
27
  if md && md[3]
32
- # info "md[3]: #{md[3]}"
33
28
  @value = md[3]
34
29
  end
35
30
 
data/lib/pvn.rb CHANGED
@@ -4,5 +4,5 @@ $:.unshift(fdirname) unless
4
4
  $:.include?(fdirname) || $:.include?(File.expand_path(fdirname))
5
5
 
6
6
  module PVN
7
- VERSION = '0.0.1'
7
+ VERSION = '0.0.4'
8
8
  end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/command'
5
+
6
+ module SVNx
7
+ class CatCommandLine < CommandLine
8
+ def initialize args = Array.new
9
+ super "cat", args.to_a
10
+ end
11
+
12
+ def uses_xml?
13
+ false
14
+ end
15
+ end
16
+
17
+ class CatCommandArgs < CommandArgs
18
+ attr_reader :revision
19
+ attr_reader :use_cache
20
+
21
+ def initialize args = Hash.new
22
+ @use_cache = args[:use_cache].nil? || args[:use_cache]
23
+ @revision = args[:revision]
24
+ super
25
+ end
26
+
27
+ def to_a
28
+ ary = Array.new
29
+ if @revision
30
+ @revision.each do |rev|
31
+ ary << "-r#{rev}"
32
+ end
33
+ end
34
+
35
+ if @path
36
+ ary << @path
37
+ end
38
+ end
39
+ end
40
+
41
+ class CatCommand < Command
42
+ def command_line
43
+ CatCommandLine.new @args
44
+ end
45
+ end
46
+ end
data/lib/svnx/command.rb CHANGED
@@ -11,22 +11,35 @@ module SVNx
11
11
  class CommandLine < System::CommandLine
12
12
  def initialize subcmd, args = Array.new
13
13
  info "args: #{args}"
14
- cmdargs = [ 'svn', subcmd, '--xml' ].concat args
14
+ cmdargs = [ 'svn', subcmd ]
15
+ cmdargs << '--xml' if uses_xml?
16
+ cmdargs.concat args
15
17
  info "cmdargs: #{cmdargs}"
16
18
  super cmdargs
17
19
  end
20
+
21
+ def uses_xml?
22
+ true
23
+ end
18
24
  end
19
25
 
20
26
  class CachingCommandLine < System::CachingCommandLine
21
27
  def initialize subcmd, args = Array.new
22
28
  info "args: #{args}"
23
- cmdargs = [ 'svn', subcmd, '--xml' ].concat args
29
+ cmdargs << '--xml' if uses_xml?
30
+ cmdargs.concat args
24
31
  info "cmdargs: #{cmdargs}"
25
32
  super cmdargs
26
33
  end
34
+
35
+ def uses_xml?
36
+ true
37
+ end
27
38
  end
28
39
 
29
40
  class CommandArgs
41
+ include Loggable
42
+
30
43
  attr_accessor :path
31
44
 
32
45
  def initialize args = Hash.new
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rexml/document'
5
+
6
+ module SVNx
7
+ # this is a parse/process on-demand list of entries, acting like an
8
+ # Enumerable.
9
+
10
+ class Entries
11
+ include Loggable, Enumerable
12
+
13
+ attr_reader :size
14
+
15
+ def initialize args = Hash.new
16
+ # it's a hash, but indexed with integers.
17
+ @entries = Hash.new
18
+
19
+ if xmllines = args[:xmllines]
20
+ # this is preferred
21
+
22
+ if xmllines.kind_of? Array
23
+ xmllines = xmllines.join ''
24
+ end
25
+
26
+ doc = REXML::Document.new xmllines
27
+
28
+ @elements = get_elements doc
29
+ @size = @elements.size
30
+ elsif xmlentries = args[:xmlentries]
31
+ raise "argument xmlentries is no longer supported"
32
+ end
33
+ end
34
+
35
+ def get_elements doc
36
+ end
37
+
38
+ def create_entry xmlelement
39
+ end
40
+
41
+ def [] idx
42
+ @entries[idx] ||= create_entry(@elements[idx + 1])
43
+ end
44
+
45
+ def each(&blk)
46
+ # all elements must be processed before this can happen:
47
+ if @elements
48
+ # a little confusing here: REXML does each_with_index with idx
49
+ # zero-based, but elements[0] is invalid.
50
+ @elements.each_with_index do |element, idx|
51
+ @entries[idx] ||= create_entry(element)
52
+ end
53
+
54
+ @elements = nil
55
+ end
56
+
57
+ @entries.keys.sort.collect { |idx| @entries[idx] }.each(&blk)
58
+ end
59
+ end
60
+ end
data/lib/svnx/entry.rb CHANGED
@@ -9,6 +9,30 @@ module SVNx
9
9
  class Entry
10
10
  include Loggable
11
11
 
12
+ def initialize args = Hash.new
13
+ if xmllines = args[:xmllines]
14
+ if xmllines.kind_of? Array
15
+ xmllines = xmllines.join ''
16
+ end
17
+
18
+ doc = REXML::Document.new xmllines
19
+
20
+ set_from_xml doc
21
+ elsif elmt = args[:xmlelement]
22
+ set_from_element elmt
23
+ else
24
+ raise "must be initialized with xmllines or xmlelement"
25
+ end
26
+ end
27
+
28
+ def set_from_xml xmldoc
29
+ raise "must be implemented"
30
+ end
31
+
32
+ def set_from_element elmt
33
+ raise "must be implemented"
34
+ end
35
+
12
36
  def get_attribute xmlelement, attrname
13
37
  xmlelement.attributes[attrname]
14
38
  end
@@ -6,16 +6,23 @@ require 'svnx/command'
6
6
  module SVNx
7
7
  class InfoCommandLine < CommandLine
8
8
  def initialize args = Array.new
9
- super "info", args
9
+ super "info", args.to_a
10
10
  end
11
11
  end
12
12
 
13
13
  class InfoCommandArgs < CommandArgs
14
+ def to_a
15
+ ary = Array.new
16
+ if @path
17
+ ary << @path
18
+ end
19
+ ary
20
+ end
14
21
  end
15
22
 
16
23
  class InfoCommand < Command
17
24
  def command_line
18
- InfoCommandLine.new @cmdargs
25
+ InfoCommandLine.new @args
19
26
  end
20
27
  end
21
28
  end
@@ -1,27 +1,19 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- # require 'svnx/info/entry'
5
-
6
- module SVNx; module Info; end; end
4
+ require 'svnx/info/entry'
5
+ require 'svnx/entries'
7
6
 
8
7
  module SVNx::Info
9
- class Entries < Array
8
+ class Entries < SVNx::Entries
10
9
  include Loggable
11
10
 
12
- def initialize args = Hash.new
13
- if xmllines = args[:xmllines]
14
- doc = REXML::Document.new xmllines
11
+ def get_elements doc
12
+ doc.elements['info'].elements
13
+ end
15
14
 
16
- # xxx
17
- doc.elements.each('xxx') do |entryelement|
18
- self << Entry.new(:xmlelement => entryelement)
19
- end
20
- elsif xml = args[:xml]
21
- xml.xmlentries.each do |xmlentry|
22
- self << Entry.new(:xmlentry => xmlentry)
23
- end
24
- end
15
+ def create_entry xmlelement
16
+ Entry.new :xmlelement => xmlelement
25
17
  end
26
18
  end
27
19
  end
@@ -11,24 +11,25 @@ module SVNx::Info
11
11
  attr_reader :root
12
12
  attr_reader :kind
13
13
  attr_reader :path
14
-
15
- def initialize args = Hash.new
16
- if xmllines = args[:xmllines]
17
- doc = REXML::Document.new xmllines
18
- entry = doc.elements['info/entry']
19
14
 
20
- set_attr_var entry, 'kind'
21
- set_attr_var entry, 'path'
22
- set_elmt_var entry, 'url'
23
-
24
- repo = entry.elements['repository']
25
- # set_elmt_var doc, 'info/entry/repository/root'
26
- set_elmt_var repo, 'root'
27
- else
28
- raise "must be initialized with xmllines"
29
- end
15
+ def set_from_xml xmldoc
16
+ entry = xmldoc.elements['info/entry']
30
17
 
31
- info "self: #{self.inspect}"
18
+ set_attr_var entry, 'kind'
19
+ set_attr_var entry, 'path'
20
+ set_elmt_var entry, 'url'
21
+
22
+ repo = entry.elements['repository']
23
+ set_elmt_var repo, 'root'
24
+ end
25
+
26
+ def set_from_element elmt
27
+ set_attr_var elmt, 'kind'
28
+ set_attr_var elmt, 'path'
29
+ set_elmt_var elmt, 'url'
30
+
31
+ repo = elmt.elements['repository']
32
+ set_elmt_var repo, 'root'
32
33
  end
33
34
  end
34
35
  end
@@ -11,10 +11,6 @@ require 'svnx/command'
11
11
  module SVNx
12
12
  CACHE_DIR = "/tmp/cache_dir_for_log_command"
13
13
 
14
- class LogOptions
15
- attr_reader :revision
16
- end
17
-
18
14
  class LogCommandLine < CommandLine
19
15
  def initialize args = Array.new
20
16
  info "args: #{args}"
@@ -1,57 +1,18 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
+ require 'svnx/entries'
4
5
  require 'svnx/log/entry'
5
- require 'rexml/document'
6
6
 
7
7
  module SVNx::Log
8
- class Entries
9
- include Loggable, Enumerable
8
+ class Entries < SVNx::Entries
10
9
 
11
- def initialize args = Hash.new
12
- @entries = Hash.new
13
-
14
- if xmllines = args[:xmllines]
15
- # this is preferred
16
-
17
- if xmllines.kind_of? Array
18
- xmllines = xmllines.join ''
19
- end
20
-
21
- doc = REXML::Document.new xmllines
22
-
23
- @logelements = doc.elements['log'].elements
24
- @size = @logelements.size
25
- elsif xmlentries = args[:xmlentries]
26
- # this is legacy:
27
-
28
- xmlentries.each do |xmlentry|
29
- @entries[@entries.size] = Entry.new(:xmlentry => xmlentry)
30
- end
31
- end
10
+ def get_elements doc
11
+ doc.elements['log'].elements
32
12
  end
33
13
 
34
- def [] idx
35
- @entries[idx] ||= Entry.new(:xmlelement => @logelements[idx + 1])
36
- end
37
-
38
- def size
39
- @size
40
- end
41
-
42
- def each(&blk)
43
- # all elements must be processed before this can happen:
44
- if @logelements
45
- @logelements.each_with_index do |logelement, idx|
46
- # info "logelement: #{logelement}"
47
- # info "idx: #{idx}"
48
- @entries[idx] ||= Entry.new(:xmlelement => logelement)
49
- end
50
-
51
- @logelements = nil
52
- end
53
-
54
- @entries.keys.sort.collect { |idx| @entries[idx] }.each(&blk)
14
+ def create_entry xmlelement
15
+ Entry.new :xmlelement => xmlelement
55
16
  end
56
17
  end
57
18
  end
@@ -9,31 +9,22 @@ module SVNx::Log
9
9
  class Entry < SVNx::Entry
10
10
 
11
11
  attr_reader :revision, :author, :date, :paths, :msg
12
-
13
- def initialize args = Hash.new
14
- # this is log/logentry from "svn log --xml"
15
- if xmlelement = args[:xmlelement]
16
- set_attr_var xmlelement, 'revision'
17
-
18
- %w{ author date msg }.each do |field|
19
- set_elmt_var xmlelement, field
20
- end
21
-
22
- @paths = Array.new
23
-
24
- xmlelement.elements.each('paths/path') do |pe|
25
- kind = get_attribute pe, 'kind'
26
- action = get_attribute pe, 'action'
27
- name = pe.text
28
-
29
- @paths << LogEntryPath.new(:kind => kind, :action => action, :name => name)
30
- end
31
- else
32
- @revision = args[:revision]
33
- @author = args[:author]
34
- @date = args[:date]
35
- @paths = args[:paths]
36
- @message = args[:message]
12
+
13
+ def set_from_element elmt
14
+ set_attr_var elmt, 'revision'
15
+
16
+ %w{ author date msg }.each do |field|
17
+ set_elmt_var elmt, field
18
+ end
19
+
20
+ @paths = Array.new
21
+
22
+ elmt.elements.each('paths/path') do |pe|
23
+ kind = get_attribute pe, 'kind'
24
+ action = get_attribute pe, 'action'
25
+ name = pe.text
26
+
27
+ @paths << LogEntryPath.new(:kind => kind, :action => action, :name => name)
37
28
  end
38
29
  end
39
30
 
@@ -50,5 +41,9 @@ module SVNx::Log
50
41
  @action = args[:action]
51
42
  @name = args[:name]
52
43
  end
44
+
45
+ def to_s
46
+ @name
47
+ end
53
48
  end
54
49
  end
@@ -6,16 +6,23 @@ require 'svnx/command'
6
6
  module SVNx
7
7
  class StatusCommandLine < CommandLine
8
8
  def initialize args = Array.new
9
- super "status", args
9
+ super "status", args.to_a
10
10
  end
11
11
  end
12
12
 
13
13
  class StatusCommandArgs < CommandArgs
14
+ def to_a
15
+ ary = Array.new
16
+ if @path
17
+ ary << @path
18
+ end
19
+ ary
20
+ end
14
21
  end
15
22
 
16
23
  class StatusCommand < Command
17
24
  def command_line
18
- StatusCommandLine.new @cmdargs
25
+ StatusCommandLine.new @args
19
26
  end
20
27
  end
21
28
  end
@@ -2,21 +2,16 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'svnx/status/entry'
5
+ require 'svnx/entries'
5
6
 
6
7
  module SVNx::Status
7
- class Entries < Array
8
- include Loggable
9
-
10
- def initialize args = Hash.new
11
- super()
12
-
13
- raise "not implemented"
8
+ class Entries < SVNx::Entries
9
+ def get_elements doc
10
+ doc.elements['status'].elements['target'].elements
11
+ end
14
12
 
15
- if xmlentries = args[:xml]
16
- xmlentries.each do |xmlentry|
17
- self << Entry.new(:xml => xmlentry)
18
- end
19
- end
13
+ def create_entry xmlelement
14
+ Entry.new :xmlelement => xmlelement
20
15
  end
21
16
  end
22
17
  end
@@ -10,24 +10,27 @@ module SVNx::Status
10
10
 
11
11
  attr_reader :status
12
12
  attr_reader :path
13
-
14
- def initialize args = Hash.new
15
- if xmllines = args[:xmllines]
16
- doc = REXML::Document.new xmllines
17
- stelmt = doc.elements['status']
18
- tgt = stelmt.elements['target']
19
13
 
20
- set_attr_var tgt, 'path'
21
-
22
- if entry = tgt.elements['entry']
23
- wcstatus = entry.elements['wc-status']
24
- @status = wcstatus.attributes['item']
25
- else
26
- @status = "unchanged"
27
- end
28
- else
29
- raise "must be initialized with xmllines"
30
- end
14
+ def set_from_xml xmldoc
15
+ stelmt = xmldoc.elements['status']
16
+ tgt = stelmt.elements['target']
17
+
18
+ set_attr_var tgt, 'path'
19
+ @status = if entry = tgt.elements['entry']
20
+ wcstatus = entry.elements['wc-status']
21
+ wcstatus.attributes['item']
22
+ else
23
+ "unchanged"
24
+ end
25
+ end
26
+
27
+ def set_from_element elmt
28
+ set_attr_var elmt, 'path'
29
+ @status = if wcstatus = elmt.elements['wc-status']
30
+ wcstatus.attributes['item']
31
+ else
32
+ "unchanged"
33
+ end
31
34
  end
32
35
  end
33
36
  end
@@ -24,8 +24,8 @@ module SVNx::Log
24
24
  end
25
25
 
26
26
  def test_entry_from_command
27
- lcargs = LogCommandArgs.new :limit => 2, :verbose => false, :use_cache => false
28
- lc = LogCommand.new lcargs
27
+ lcargs = SVNx::LogCommandArgs.new :limit => 2, :verbose => false, :use_cache => false
28
+ lc = SVNx::LogCommand.new lcargs
29
29
 
30
30
  lc.execute
31
31
  output = lc.output
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/info/tc'
5
+ require 'svnx/info/entries'
6
+
7
+ module SVNx::Info
8
+ class EntriesTestCase < SVNx::Info::TestCase
9
+
10
+ def test_create_from_xml
11
+ entries = Entries.new :xmllines => get_test_lines_two_entries
12
+ info "entries: #{entries}"
13
+
14
+ assert_equal 2, entries.size
15
+
16
+ exproot = 'file:///home/jpace/Programs/Subversion/Repositories/wiquery'
17
+
18
+ assert_entry_equals entries[0], :path => 'pom.xml', :kind => 'file', :url => exproot + '/trunk/pom.xml', :root => exproot
19
+ assert_entry_equals entries[1], :path => 'Orig.java', :kind => 'file', :url => exproot + '/trunk/Orig.java', :root => exproot
20
+ end
21
+ end
22
+ end
@@ -7,36 +7,8 @@ require 'svnx/info/entry'
7
7
  module SVNx::Info
8
8
  class EntryTestCase < SVNx::Info::TestCase
9
9
  include Loggable
10
-
11
10
  def test_entry_from_xml
12
- # svn info --xml ./wiquery-core/pom.xml
13
- xml = Array.new
14
- xml << '<?xml version="1.0"?>'
15
- xml << '<info>'
16
- xml << '<entry'
17
- xml << ' kind="file"'
18
- xml << ' path="wiquery-core/pom.xml"'
19
- xml << ' revision="1950">'
20
- xml << '<url>file:///home/jpace/Programs/Subversion/Repositories/wiquery/trunk/wiquery-core/pom.xml</url>'
21
- xml << '<repository>'
22
- xml << '<root>file:///home/jpace/Programs/Subversion/Repositories/wiquery</root>'
23
- xml << '<uuid>9d44104b-4b85-4781-9eca-83ed02b512a0</uuid>'
24
- xml << '</repository>'
25
- xml << '<wc-info>'
26
- xml << '<schedule>normal</schedule>'
27
- xml << '<depth>infinity</depth>'
28
- xml << '<text-updated>2011-11-28T11:26:07.772551Z</text-updated>'
29
- xml << '<checksum>3b2a51d21a9517a4d3dc5865c4b56db9</checksum>'
30
- xml << '</wc-info>'
31
- xml << '<commit'
32
- xml << ' revision="1907">'
33
- xml << '<author>hielke.hoeve@gmail.com</author>'
34
- xml << '<date>2011-11-14T10:50:38.389281Z</date>'
35
- xml << '</commit>'
36
- xml << '</entry>'
37
- xml << '</info>'
38
-
39
- xmllines = xml.collect { |line| line + "\n" }
11
+ xmllines = get_test_lines_one_entry
40
12
 
41
13
  expdata = {
42
14
  :url => 'file:///home/jpace/Programs/Subversion/Repositories/wiquery/trunk/wiquery-core/pom.xml',
@@ -45,7 +17,7 @@ module SVNx::Info
45
17
  :root => 'file:///home/jpace/Programs/Subversion/Repositories/wiquery'
46
18
  }
47
19
 
48
- entry = Entry.new :xmllines => xmllines.join('')
20
+ entry = Entry.new :xmllines => xmllines
49
21
  assert_entry_equals entry, expdata
50
22
  end
51
23
  end
@@ -13,19 +13,22 @@ module SVNx::Log
13
13
  assert entry.message
14
14
  assert entry.author
15
15
  end
16
-
17
- def test_create_from_xml
16
+
17
+ def assert_log_entry_1947 entry
18
18
  expdata = '1947', 'reiern70', '2011-11-14T12:24:45.757124Z', 'added a convenience method to set the range'
19
19
  expdata << { :kind => 'file',
20
20
  :action => 'M',
21
21
  :name => '/trunk/wiquery-jquery-ui/src/test/java/org/odlabs/wiquery/ui/slider/SliderTestCase.java'
22
22
  }
23
23
 
24
+ assert_log_entry_equals entry, expdata
25
+ end
26
+
27
+ def test_create_from_xml
24
28
  entries = Entries.new :xmllines => get_test_lines_limit_15
25
-
26
- assert_log_entry_equals entries[2], expdata
29
+ assert_log_entry_1947 entries[2]
27
30
  end
28
-
31
+
29
32
  def test_no_author_field
30
33
  entries = Entries.new :xmllines => get_test_lines_no_author
31
34
  nentries = entries.size
@@ -69,5 +72,17 @@ module SVNx::Log
69
72
  assert_nil real_entries[16]
70
73
  assert_nil real_entries[18]
71
74
  end
75
+
76
+ def test_each
77
+ idx = 0
78
+
79
+ entries = Entries.new :xmllines => get_test_lines_limit_15
80
+ entries.each do |entry|
81
+ if idx == 2
82
+ assert_log_entry_1947 entry
83
+ end
84
+ idx += 1
85
+ end
86
+ end
72
87
  end
73
88
  end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/status/tc'
5
+ require 'svnx/status/entries'
6
+
7
+ module SVNx::Status
8
+ class EntriesTestCase < SVNx::Status::TestCase
9
+
10
+ def test_create_from_xml
11
+ entries = Entries.new :xmllines => get_test_lines_all
12
+
13
+ assert_equal 4, entries.size
14
+ assert_status_entry_equals 'added', 'Orig.java', entries[0]
15
+ assert_status_entry_equals 'deleted', 'LICENSE', entries[1]
16
+ assert_status_entry_equals 'modified', 'pom.xml', entries[2]
17
+ assert_status_entry_equals 'modified', 'wiquery-core/src/main/java/org/odlabs/wiquery/core/effects/EffectBehavior.java', entries[3]
18
+ end
19
+ end
20
+ end
@@ -30,10 +30,8 @@ module SVNx::Status
30
30
  xml << "</target>\n"
31
31
  xml << "</status>\n"
32
32
 
33
- expdata = { :path => 'LICENSE', :status => 'deleted' }
34
-
35
33
  entry = Entry.new :xmllines => xml.join('')
36
- assert_entry_equals entry, expdata
34
+ assert_status_entry_equals 'deleted', 'LICENSE', entry
37
35
  end
38
36
  end
39
37
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvn
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Pace
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-01 00:00:00 -04:00
18
+ date: 2012-09-04 00:00:00 -04:00
19
19
  default_executable: pvn
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -61,10 +61,12 @@ files:
61
61
  - lib/system/command.rb
62
62
  - lib/system/cachecmd.rb
63
63
  - lib/system/cmdexec.rb
64
+ - lib/svnx/cat/command.rb
64
65
  - lib/svnx/status/command.rb
65
66
  - lib/svnx/status/entries.rb
66
67
  - lib/svnx/status/entry.rb
67
68
  - lib/svnx/command.rb
69
+ - lib/svnx/entries.rb
68
70
  - lib/svnx/info/command.rb
69
71
  - lib/svnx/info/entries.rb
70
72
  - lib/svnx/info/entry.rb
@@ -76,6 +78,7 @@ files:
76
78
  - lib/pvn/subcommands/base/clargs.rb
77
79
  - lib/pvn/subcommands/base/command.rb
78
80
  - lib/pvn/subcommands/base/doc.rb
81
+ - lib/pvn/subcommands/pct/options.rb
79
82
  - lib/pvn/subcommands/pct/clargs.rb
80
83
  - lib/pvn/subcommands/pct/command.rb
81
84
  - lib/pvn/subcommands/log/options.rb
@@ -125,7 +128,9 @@ files:
125
128
  - test/unit/synoption/option_test.rb
126
129
  - test/unit/system/command/caching_test.rb
127
130
  - test/unit/system/command/line_test.rb
131
+ - test/unit/svnx/status/entries_test.rb
128
132
  - test/unit/svnx/status/entry_test.rb
133
+ - test/unit/svnx/info/entries_test.rb
129
134
  - test/unit/svnx/info/entry_test.rb
130
135
  - test/unit/svnx/log/entries_test.rb
131
136
  - test/unit/svnx/log/entry_test.rb
@@ -182,7 +187,9 @@ test_files:
182
187
  - test/unit/synoption/option_test.rb
183
188
  - test/unit/system/command/caching_test.rb
184
189
  - test/unit/system/command/line_test.rb
190
+ - test/unit/svnx/status/entries_test.rb
185
191
  - test/unit/svnx/status/entry_test.rb
192
+ - test/unit/svnx/info/entries_test.rb
186
193
  - test/unit/svnx/info/entry_test.rb
187
194
  - test/unit/svnx/log/entries_test.rb
188
195
  - test/unit/svnx/log/entry_test.rb