svnx 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7703311a03e657be2fb6172c5b3b7de2f5f9434d
4
- data.tar.gz: 80d187db92d50e7a81105cd202649c793b4b1c40
3
+ metadata.gz: c874ec9268528dbc63a6357a0183e9fae50adf52
4
+ data.tar.gz: c58d74793a24e79f12a70e57c3ddd2408e86a8db
5
5
  SHA512:
6
- metadata.gz: 1f26504dbe28a179d7432d6e9ae30a315ab467efd832828b07f3927e7ce7c99815b827ba78df98533dbd67e16c36329da2bc5240d131da412e1d40dda65e8a9b
7
- data.tar.gz: 005c59f2e7702a2832aeb104266773810d0ad8c0fb346ab3e274ac4a13d03586815d5ab7588640aaf2d6d448d60b8fa893fa806fd0c56aa2210bdb36e57888fe
6
+ metadata.gz: 2f55486032214b0bd5dacc429bc7596d37599bd1c0dbd02ee039ac21eab702546663363e0f894c2e75ff8c1dc0239536b75a79516c6c3831008b8edb7ecd8cb7
7
+ data.tar.gz: c6925299e2740810633112b502b6e5bbd6e95048ffe090e14001c58f83051814522eea553d1078d8901c48431cde2f341cb8fdf1d3c5c8358e807caf266fdb05
@@ -2,7 +2,7 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'logue/loggable'
5
- require 'command/cacheable'
5
+ require 'command/cacheable/command'
6
6
  require 'svnx/base/env'
7
7
 
8
8
  module Svnx
@@ -46,7 +46,7 @@ module Svnx::Base
46
46
  end
47
47
 
48
48
  def command_line cmdargs
49
- Command::Cacheable::Command.new cmdargs, caching: @caching, dir: Svnx::Env.instance.cache_dir
49
+ ::Command::Cacheable::Command.new cmdargs, caching: @caching, cachedir: Svnx::Env.instance.cache_dir
50
50
  end
51
51
  end
52
52
  end
@@ -2,8 +2,6 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'logue/loggable'
5
- require 'command/cacheable/command'
6
- # require 'svnx/base/cmdline'
7
5
  require 'svnx/util/classutil'
8
6
  require 'svnx/base/command_factory'
9
7
 
@@ -28,40 +26,35 @@ module Svnx::Base
28
26
  attr_reader :output
29
27
  attr_reader :error
30
28
  attr_reader :status
31
-
32
29
  attr_reader :options
33
30
 
34
- def initialize options, cls: nil, optcls: nil, exec: nil, xml: false, caching: caching?
31
+ def initialize options, cmdlinecls: nil, optcls: nil, xml: false, caching: caching?
35
32
  factory = CommandFactory.new
36
- params = factory.create self.class, cmdlinecls: cls, optcls: optcls
37
33
 
38
- optcls ||= params[:options_class]
34
+ params = factory.create self.class, cmdlinecls: cmdlinecls, optcls: optcls
35
+
36
+ optcls ||= params.options
39
37
 
40
38
  @options = optcls.new options
41
39
  cmdargs = @options.to_args
42
- subcommand = params[:subcommand]
43
40
 
44
- cls ||= params[:command_line_class]
41
+ subcommand = params.subcommand
45
42
 
46
- @cmdline = exec || cls.new(subcommand: subcommand, xml: xml, caching: caching, args: cmdargs)
47
- debug "@cmdline: #{@cmdline}"
43
+ cmdlinecls ||= params.cmdline
48
44
 
49
- @output = @cmdline.execute
50
- debug "@output: #{@output && @output[0 .. 100]}"
45
+ @cmdline = cmdlinecls.new(subcommand: subcommand, xml: xml, caching: caching, args: cmdargs)
51
46
 
47
+ @output = @cmdline.execute
52
48
  @error = @cmdline.error
53
- debug "@error: #{@error}"
54
-
55
49
  @status = @cmdline.status
56
- debug "@status: #{@status}"
57
50
  end
58
51
  end
59
52
 
60
53
  class EntriesCommand < Command
61
54
  attr_reader :entries
62
55
 
63
- def initialize options, cls: Command::Cacheable::Command, exec: nil, caching: caching?, xml: true, entries_class: nil
64
- super options, cls: cls, exec: exec, xml: xml, caching: caching
56
+ def initialize options, cmdlinecls: CommandLine, caching: caching?, xml: true, entries_class: nil
57
+ super options, cmdlinecls: cmdlinecls, xml: xml, caching: caching
65
58
 
66
59
  if not @output.empty?
67
60
  entries_class ||= begin
@@ -5,10 +5,22 @@ require 'svnx/base/cmdline'
5
5
  require 'svnx/util/classutil'
6
6
 
7
7
  module Svnx::Base
8
+ class CommandParams
9
+ attr_reader :options
10
+ attr_reader :subcommand
11
+ attr_reader :cmdline
12
+
13
+ def initialize options: nil, subcommand: nil, cmdline: nil
14
+ @options = options
15
+ @subcommand = subcommand
16
+ @cmdline = cmdline
17
+ end
18
+ end
19
+
8
20
  class CommandFactory
9
21
  include Logue::Loggable
10
22
 
11
- def create cmdcls, cmdlinecls: nil, optcls: nil
23
+ def create cmdcls, cmdlinecls: CommandLine, optcls: nil
12
24
  melements = ClassUtil.module_elements cmdcls
13
25
 
14
26
  optcls ||= begin
@@ -16,9 +28,7 @@ module Svnx::Base
16
28
  modl::Options
17
29
  end
18
30
 
19
- cmdlinecls ||= CommandLine
20
-
21
- { options_class: optcls, subcommand: melements[-1].downcase, command_line_class: cmdlinecls }
31
+ CommandParams.new options: optcls, subcommand: melements[-1].downcase, cmdline: cmdlinecls
22
32
  end
23
33
  end
24
34
  end
@@ -2,6 +2,7 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'rexml/document'
5
+ require 'nokogiri'
5
6
  require 'logue/loggable'
6
7
 
7
8
  module Svnx
@@ -12,6 +13,8 @@ end
12
13
  # this is a parse/process on-demand list of entries, acting like an
13
14
  # Enumerable.
14
15
 
16
+ $use_nokogiri = true
17
+
15
18
  module Svnx::Base
16
19
  class Entries
17
20
  include Logue::Loggable, Enumerable
@@ -21,7 +24,11 @@ module Svnx::Base
21
24
  def initialize lines
22
25
  # it's a hash, but indexed with integers, for non-sequential access:
23
26
  @entries = Hash.new
24
- doc = REXML::Document.new Array(lines).join
27
+ doc = if $use_nokogiri
28
+ Nokogiri::XML Array(lines).join
29
+ else
30
+ REXML::Document.new Array(lines).join
31
+ end
25
32
  @elements = get_elements doc
26
33
  @size = @elements.size
27
34
  end
@@ -34,24 +41,23 @@ module Svnx::Base
34
41
  raise "create_entry must be implemented for: #{self.class}"
35
42
  end
36
43
 
37
- # this doesn't handle negative indices
38
44
  def [] idx
39
45
  if entry = @entries[idx]
40
46
  return entry
41
47
  end
42
- if idx < 0 || idx >= size
48
+ if idx >= size
43
49
  raise "error: index #{idx} is not in range(0 .. #{size})"
50
+ elsif idx < 0
51
+ idx = size + idx
44
52
  end
45
- @entries[idx] = create_entry @elements[idx + 1]
53
+ @entries[idx] = create_entry @elements[idx]
46
54
  end
47
55
 
48
56
  def each(&blk)
49
57
  # all elements must be processed before each can run:
50
58
  if @elements
51
- # a little confusing here: REXML does each_with_index with idx
52
- # zero-based, but elements[0] is invalid.
53
59
  @elements.each_with_index do |element, idx|
54
- @entries[idx] ||= create_entry(element)
60
+ @entries[idx] ||= create_entry element
55
61
  end
56
62
 
57
63
  @elements = nil
@@ -46,11 +46,11 @@ module Svnx::Base
46
46
  end
47
47
 
48
48
  def attribute_value xmlelement, attrname
49
- xmlelement.attributes[attrname.to_s]
49
+ xmlelement[attrname.to_s]
50
50
  end
51
51
 
52
52
  def element_text xmlelement, elmtname
53
- elmt = xmlelement.elements[elmtname.to_s]
53
+ elmt = xmlelement.at_xpath elmtname.to_s
54
54
  elmt && elmt.text || ""
55
55
  end
56
56
  end
@@ -8,7 +8,7 @@ module Svnx::Blame
8
8
  class Entries < Svnx::Base::Entries
9
9
  def get_elements doc
10
10
  # blame/target
11
- doc.elements['blame'].elements['target'].elements
11
+ doc.xpath '//blame/target/entry'
12
12
  end
13
13
 
14
14
  def create_entry xmlelement
@@ -21,7 +21,7 @@ module Svnx::Blame
21
21
  def set_from_element elmt
22
22
  set_attr_var elmt, 'line_number', 'line-number'
23
23
 
24
- commit = elmt.elements['commit']
24
+ commit = elmt.at_xpath 'commit'
25
25
  set_attr_var commit, 'revision'
26
26
  set_elmt_vars commit, 'author', 'date'
27
27
  end
@@ -9,8 +9,8 @@ module Svnx::Diff
9
9
  class Command < Svnx::Base::Command
10
10
  attr_reader :entries
11
11
 
12
- def initialize cmdopts, cls: Svnx::Base::CommandLine
13
- super cmdopts, cls: cls, xml: false, caching: true
12
+ def initialize cmdopts, cmdlinecls: Svnx::Base::CommandLine
13
+ super cmdopts, cmdlinecls: cmdlinecls, xml: false, caching: true
14
14
  if @output
15
15
  @entries = Svnx::Diff::Parser.new.parse_all_output @output.dup
16
16
  end
@@ -7,7 +7,7 @@ require 'svnx/base/entries'
7
7
  module Svnx::Info
8
8
  class Entries < Svnx::Base::Entries
9
9
  def get_elements doc
10
- doc.elements['info'].elements
10
+ doc.xpath 'info/entry'
11
11
  end
12
12
 
13
13
  def create_entry xmlelement
@@ -21,16 +21,16 @@ module Svnx::Info
21
21
  def set_from_element elmt
22
22
  set_attr_vars elmt, 'kind', 'path', 'revision'
23
23
  set_elmt_var elmt, 'url'
24
- if relurl = elmt.elements['relative-url']
24
+ if relurl = elmt.at_xpath('relative-url')
25
25
  @relative_url = relurl.text
26
26
  end
27
27
 
28
- repo = elmt.elements['repository']
28
+ repo = elmt.at_xpath 'repository'
29
29
  set_elmt_var repo, 'root'
30
30
 
31
31
  @wc_root = nil
32
- if wcinfo = elmt.elements['wc-info']
33
- if wcroot = wcinfo.elements['wcroot-abspath']
32
+ if wcinfo = elmt.at_xpath('wc-info')
33
+ if wcroot = wcinfo.at_xpath('wcroot-abspath')
34
34
  @wc_root = wcroot.text
35
35
  end
36
36
  end
@@ -7,7 +7,7 @@ require 'svnx/log/entry'
7
7
  module Svnx::Log
8
8
  class Entries < Svnx::Base::Entries
9
9
  def get_elements doc
10
- doc.elements['log'].elements
10
+ doc.xpath '//log/logentry'
11
11
  end
12
12
 
13
13
  def create_entry xmlelement
@@ -16,7 +16,7 @@ module Svnx::Log
16
16
 
17
17
  set_elmt_vars elmt, 'author', 'date', 'msg'
18
18
 
19
- @paths = elmt.elements.to_a('paths/path').collect do |pe|
19
+ @paths = elmt.xpath('paths/path').collect do |pe|
20
20
  kind = attribute_value pe, 'kind'
21
21
  action = attribute_value pe, 'action'
22
22
  name = pe.text
@@ -24,7 +24,7 @@ module Svnx::Log
24
24
  EntryPath.new(kind: kind, action: Svnx::Action.new(action), name: name)
25
25
  end.sort # sorted, because svn is not consistent with order
26
26
 
27
- @entries = elmt.elements.to_a('logentry').collect do |le|
27
+ @entries = elmt.xpath('logentry').collect do |le|
28
28
  Entry.new le
29
29
  end
30
30
  end
data/lib/svnx/project.rb CHANGED
@@ -10,10 +10,10 @@ end
10
10
  class Svnx::Project
11
11
  attr_reader :dir
12
12
 
13
- def initialize dir: nil, url: nil, cls: nil
13
+ def initialize dir: nil, url: nil, cmdlinecls: nil
14
14
  @dir = dir
15
15
  @url = url
16
- @cls = cls
16
+ @cmdlinecls = cmdlinecls
17
17
  end
18
18
 
19
19
  def where
@@ -43,8 +43,8 @@ class Svnx::Project
43
43
  cmdargs = fields.collect { |key| key.to_s + ": " + key.to_s }.join ", "
44
44
 
45
45
  src = Array.new.tap do |a|
46
- a << "def #{cmd} #{params}, cls: @cls"
47
- a << " cmd = Svnx::#{cmd.to_s.capitalize}::Command.new({ #{cmdargs} }, cls: cls)"
46
+ a << "def #{cmd} #{params}, cmdlinecls: @cmdlinecls"
47
+ a << " cmd = Svnx::#{cmd.to_s.capitalize}::Command.new({ #{cmdargs} }, cmdlinecls: cmdlinecls)"
48
48
  a << " cmd.respond_to?(:entries) ? cmd.entries : cmd.output"
49
49
  a << "end"
50
50
  end.join "\n"
@@ -7,7 +7,7 @@ require 'svnx/base/entries'
7
7
  module Svnx::Propget
8
8
  class Entries < Svnx::Base::Entries
9
9
  def get_elements doc
10
- doc.elements['properties'].elements
10
+ doc.xpath '//properties/target'
11
11
  end
12
12
 
13
13
  def create_entry xmlelement
@@ -17,7 +17,7 @@ module Svnx::Propget
17
17
  def set_from_element elmt
18
18
  set_attr_vars elmt, :path
19
19
 
20
- prop = elmt.elements["property"]
20
+ prop = elmt.at_xpath "property"
21
21
  set_attr_vars prop, :name
22
22
  @value = prop.text
23
23
  end
@@ -12,8 +12,12 @@ module Svnx::Status
12
12
  end
13
13
 
14
14
  def get_elements doc
15
- # status/target
16
- doc.elements['status'].elements['target'].elements
15
+ if $use_nokogiri
16
+ doc.xpath '//status/target/entry'
17
+ else
18
+ # status/target
19
+ doc.elements['status'].elements['target'].elements
20
+ end
17
21
  end
18
22
 
19
23
  def create_entry xmlelement
@@ -30,11 +30,11 @@ module Svnx::Status
30
30
  def set_from_element elmt
31
31
  set_attr_var elmt, 'path'
32
32
 
33
- wcstatus = elmt.elements['wc-status']
34
- @status = Svnx::Action.new(wcstatus.attributes['item'])
33
+ wcstatus = elmt.at_xpath 'wc-status'
34
+ @status = Svnx::Action.new(wcstatus['item'])
35
35
  set_attr_var wcstatus, 'status_revision', 'revision'
36
36
 
37
- commit = wcstatus.elements['commit']
37
+ commit = wcstatus.at_xpath 'commit'
38
38
  set_attr_var commit, 'commit_revision', 'revision'
39
39
  @name = @path.dup
40
40
 
@@ -2,30 +2,16 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'time'
5
+ require 'svnx/util/englishtime'
5
6
 
6
7
  class DateUtil
7
8
  class << self
8
- def relative_full datetime, reltime = Time.now
9
- secs = (reltime - datetime).to_i
10
- if ago = to_time_units(secs)
11
- ago + " ago (" + fmt_mmdd_hhmm(datetime) + ")"
9
+ def relative_full datetime, reltime = nil
10
+ et = EnglishTime.new datetime
11
+ if reltime
12
+ et.since reltime, "earlier"
12
13
  else
13
- datetime.strftime "%Y/%m/%d %H:%M"
14
- end
15
- end
16
-
17
- # returns the value in seconds, minutes, hours, or days, if within a week
18
- def to_time_units seconds
19
- secs = seconds.to_i
20
-
21
- if secs < 120
22
- "#{secs} seconds"
23
- elsif (min = secs / 60) < 120
24
- "#{min} minutes"
25
- elsif (hour = min / 60) < 72
26
- "#{hour} hours"
27
- elsif (day = hour / 24) < 7
28
- "#{day} days"
14
+ et.ago
29
15
  end
30
16
  end
31
17
 
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'time'
5
+ require 'svnx/util/timeutil'
6
+
7
+ class EnglishTime
8
+ attr_reader :time
9
+
10
+ def initialize time
11
+ @time = time
12
+ end
13
+
14
+ def ago
15
+ since Time.new, "ago"
16
+ end
17
+
18
+ def earlier totime
19
+ since totime, "earlier"
20
+ end
21
+
22
+ def since totime, name
23
+ diff = totime - @time
24
+ seconds = diff.to_i
25
+ if units = TimeUtil.new.to_units(seconds)
26
+ sprintf "%s %s %s (%s)", units.first, units.last, name, @time.strftime("%m/%d %H:%M")
27
+ else
28
+ @time.strftime "%Y/%m/%d %H:%M"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'time'
5
+
6
+ class TimeUtil
7
+ attr_reader :intervals
8
+
9
+ def initialize
10
+ @intervals = Hash.new.tap do |h|
11
+ h[:seconds] = 60
12
+ h[:minutes] = 60
13
+ h[:hours] = 24
14
+ h[:days] = 7
15
+ end
16
+ end
17
+
18
+ # returns the value in seconds, minutes, hours, days, etc.
19
+ def to_units seconds
20
+ secs = seconds.to_i
21
+
22
+ max = Hash.new.tap do |h|
23
+ h[:seconds] = 120
24
+ h[:minutes] = 120
25
+ h[:hours] = 72
26
+ h[:days] = 18
27
+ h[:weeks] = 4
28
+ end
29
+
30
+ num = secs
31
+ max.each do |field, value|
32
+ if num < value
33
+ return [ num, field ]
34
+ elsif ival = @intervals[field]
35
+ num /= ival
36
+ end
37
+ end
38
+ nil
39
+ end
40
+ end
data/lib/svnx/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  module Svnx
5
5
  NAME = 'svnx'
6
- VERSION = '2.4.1'
6
+ VERSION = '2.5.0'
7
7
  end
data/svnx.gemspec CHANGED
@@ -28,9 +28,10 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_runtime_dependency "command-cacheable", "~> 0.2"
31
+ spec.add_runtime_dependency "logue", "~> 1.0.16"
32
+
31
33
  spec.add_development_dependency "bundler", "~> 1.12"
32
34
  spec.add_development_dependency "rake", "~> 10.0"
33
- spec.add_development_dependency "logue", "~> 1.0.16"
34
35
  spec.add_development_dependency "test-unit", "~> 3.1.5"
35
36
  spec.add_development_dependency "paramesan", "~> 0.1.1"
36
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svnx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Pace
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-11 00:00:00.000000000 Z
11
+ date: 2019-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: command-cacheable
@@ -25,47 +25,47 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: logue
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.12'
34
- type: :development
33
+ version: 1.0.16
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.12'
40
+ version: 1.0.16
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '1.12'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '1.12'
55
55
  - !ruby/object:Gem::Dependency
56
- name: logue
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.0.16
61
+ version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.0.16
68
+ version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: test-unit
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +164,9 @@ files:
164
164
  - lib/svnx/update/options.rb
165
165
  - lib/svnx/util/classutil.rb
166
166
  - lib/svnx/util/dateutil.rb
167
+ - lib/svnx/util/englishtime.rb
167
168
  - lib/svnx/util/objutil.rb
169
+ - lib/svnx/util/timeutil.rb
168
170
  - lib/svnx/version.rb
169
171
  - repackage
170
172
  - svnx.gemspec
@@ -189,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
191
  version: '0'
190
192
  requirements: []
191
193
  rubyforge_project:
192
- rubygems_version: 2.6.3
194
+ rubygems_version: 2.5.2.1
193
195
  signing_key:
194
196
  specification_version: 4
195
197
  summary: Ruby objects from the Subversion command line