svnx 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e756a5b2625c284861b85b3a7b0543ef044e8ff
4
- data.tar.gz: e49bdcff5e52a538fcbd247da3d609afba5ac105
3
+ metadata.gz: c59030d9c9032d6cde4df27c198fa1b61a20fe23
4
+ data.tar.gz: 1245d9f6e2061ae99acb6c28564fddd183d17826
5
5
  SHA512:
6
- metadata.gz: f062f3d0079b5ef799c366762301782db8251e7efb0cef86d776ca1c46b22d585502b89d97c1619fa14d2b3a7c5c052595a14e9a8a059c67fe4914ddab7ed9d8
7
- data.tar.gz: e5d72e5378080300fd11e988e54283676b0e2d1749725aa4512e51d78563d27d516756db0d91722c886ba6d07802925963412fedefd69ff67f5abc9856ba9fd3
6
+ metadata.gz: f6facfd37a2ef2ff64c4169a196e3cf629f9d2bb8b434e2f552221556f7c985c700d5151c822245388481c796bc720607c196cadac72914f989697f8e5a01e04
7
+ data.tar.gz: 0e99b63b59d841b4abc1a9d081f2380ee2a756cb13f1bb58324832f37801b4fe7799961398190e80e5a4c5188dfb6f6f1fd5c0feaccce617a8c3d82f7673bc55
@@ -2,5 +2,5 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  module SVNx
5
- VERSION = "0.1.0"
5
+ VERSION = "0.4.0"
6
6
  end
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module SVNx; module Revision; end; end
5
+
6
+ module SVNx::Revision
7
+ class ArgumentFactory
8
+ include Logue::Loggable
9
+
10
+ DATE_REGEXP = Regexp.new '^\{(.*?)\}'
11
+ SVN_ARGUMENT_WORDS = %w{ HEAD BASE COMMITTED PREV }
12
+
13
+ def create value, args = Hash.new
14
+ case value
15
+ when Fixnum
16
+ create_for_fixnum value, args
17
+ when String
18
+ create_for_string value, args
19
+ when Symbol
20
+ raise RevisionError.new "symbol not yet handled"
21
+ when Date
22
+ # $$$ this (and Time) will probably have to be converted to svn's format
23
+ raise RevisionError.new "date not yet handled"
24
+ when Time
25
+ raise RevisionError.new "time not yet handled"
26
+ end
27
+ end
28
+
29
+ def create_for_fixnum value, args
30
+ if value < 0
31
+ # these are log entries:
32
+ RelativeArgument.new value, entries: args[:entries]
33
+ else
34
+ IndexArgument.new value
35
+ end
36
+ end
37
+
38
+ def create_for_string value, args
39
+ case
40
+ when SVN_ARGUMENT_WORDS.include?(value)
41
+ StringArgument.new value
42
+ when md = RELATIVE_REVISION_RE.match(value)
43
+ RelativeArgument.new md[0].to_i, entries: args[:entries]
44
+ when DATE_REGEXP.match(value)
45
+ StringArgument.new value
46
+ else
47
+ IndexArgument.new value.to_i
48
+ end
49
+ end
50
+ end
51
+ end
@@ -4,6 +4,7 @@
4
4
  require 'svnx/log/entries'
5
5
  require 'svnx/revision/error'
6
6
  require 'logue/loggable'
7
+ require 'svnx/revision/argfactory'
7
8
 
8
9
  module SVNx; module Revision; end; end
9
10
 
@@ -20,9 +21,6 @@ module SVNx::Revision
20
21
  class Argument
21
22
  include Logue::Loggable, Comparable
22
23
 
23
- DATE_REGEXP = Regexp.new '^\{(.*?)\}'
24
- SVN_ARGUMENT_WORDS = %w{ HEAD BASE COMMITTED PREV }
25
-
26
24
  # these are also valid revisions
27
25
  # :working_copy
28
26
  # :head
@@ -30,41 +28,8 @@ module SVNx::Revision
30
28
  attr_reader :value
31
29
 
32
30
  class << self
33
- alias_method :orig_new, :new
34
-
35
- def new value, args = Hash.new
36
- # these are log entries:
37
- entries = args[:entries]
38
-
39
- case value
40
- when Fixnum
41
- if value < 0
42
- RelativeArgument.orig_new value, entries: entries
43
- else
44
- FixnumArgument.orig_new value
45
- end
46
- when String
47
- if SVN_ARGUMENT_WORDS.include? value
48
- StringArgument.orig_new value
49
- elsif md = RELATIVE_REVISION_RE.match(value)
50
- RelativeArgument.orig_new md[0].to_i, entries: entries
51
- elsif DATE_REGEXP.match value
52
- StringArgument.orig_new value
53
- else
54
- FixnumArgument.orig_new value.to_i
55
- end
56
- when Symbol
57
- raise RevisionError.new "symbol not yet handled"
58
- when Date
59
- # $$$ this (and Time) will probably have to be converted to svn's format
60
- raise RevisionError.new "date not yet handled"
61
- when Time
62
- raise RevisionError.new "time not yet handled"
63
- end
64
- end
65
-
66
- def matches_relative? str
67
- RELATIVE_REVISION_RE.match str
31
+ def create value, args = Hash.new
32
+ ArgumentFactory.new.create value, args
68
33
  end
69
34
  end
70
35
 
@@ -81,18 +46,15 @@ module SVNx::Revision
81
46
  end
82
47
  end
83
48
 
84
- class FixnumArgument < Argument
49
+ class IndexArgument < Argument
85
50
  end
86
51
 
87
52
  class StringArgument < Argument
88
53
  end
89
54
 
90
- class WorkingCopyArgument < Argument
91
- end
92
-
93
55
  # this is of the form -3, which is revision[-3] (second one from the most
94
56
  # recent; -1 is the most recent).
95
- class RelativeArgument < FixnumArgument
57
+ class RelativeArgument < IndexArgument
96
58
  def initialize value, args
97
59
  entries = args[:entries]
98
60
 
@@ -107,7 +69,7 @@ module SVNx::Revision
107
69
  if value.abs > nentries
108
70
  raise RevisionError.new "ERROR: no entry for revision: #{value.abs}; number of entries: #{nentries}"
109
71
  else
110
- idx = value < 0 ? -1 + value.abs : nentries - value
72
+ idx = value < 0 ? value.abs - 1 : nentries - value
111
73
  log_entry = entries[idx]
112
74
  super log_entry.revision.to_i
113
75
  end
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- module SVNx
5
- module Revision
6
- class RevisionError < RuntimeError
7
- end
4
+ module SVNx; module Revision; end; end
5
+
6
+ module SVNx::Revision
7
+ class RevisionError < RuntimeError
8
8
  end
9
9
  end
@@ -28,7 +28,7 @@ module SVNx::Revision
28
28
  end
29
29
 
30
30
  def to_revision val, entries
31
- val.kind_of?(Argument) || Argument.new(val, entries: entries)
31
+ val.kind_of?(Argument) ? val : Argument.create(val, entries: entries)
32
32
  end
33
33
 
34
34
  def to_s
@@ -40,7 +40,7 @@ module SVNx::Revision
40
40
  end
41
41
 
42
42
  def head?
43
- @to == :head
43
+ @to && @to.value == 'HEAD'
44
44
  end
45
45
 
46
46
  def working_copy?
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'tc'
5
+ require 'svnx/log/entries'
6
+ require 'svnx/revision/argument'
7
+ require 'resources'
8
+
9
+ module SVNx::Revision
10
+ class ArgumentFactoryTestCase < SVNx::TestCase
11
+ def setup
12
+ xmllines = Resources::PT_LOG_R22_13_SECONDFILE_TXT.readlines
13
+ @entries = SVNx::Log::Entries.new :xmllines => xmllines
14
+ end
15
+
16
+ def test_create
17
+ arg = ArgumentFactory.new.create 14, entries: @entries
18
+ assert_not_nil arg
19
+ end
20
+
21
+ def test_index_argument
22
+ arg = ArgumentFactory.new.create 14, entries: @entries
23
+ assert_kind_of IndexArgument, arg
24
+ end
25
+
26
+ def test_string_svn_words
27
+ %w{ HEAD BASE COMMITTED PREV }.each do |word|
28
+ arg = ArgumentFactory.new.create word, entries: @entries
29
+ assert_kind_of StringArgument, arg
30
+ end
31
+ end
32
+
33
+ def test_date
34
+ arg = ArgumentFactory.new.create '{2012-12-10}', entries: @entries
35
+ assert_kind_of StringArgument, arg
36
+ end
37
+
38
+ def test_relative_argument_fixnum
39
+ arg = ArgumentFactory.new.create(-4, entries: @entries)
40
+ assert_kind_of IndexArgument, arg
41
+ assert_equal 15, arg.value
42
+ end
43
+
44
+ def test_relative_argument_string
45
+ arg = ArgumentFactory.new.create('-4', entries: @entries)
46
+ assert_kind_of IndexArgument, arg
47
+ assert_equal 15, arg.value
48
+ end
49
+ end
50
+ end
@@ -16,8 +16,12 @@ module SVNx::Revision
16
16
  @entries = SVNx::Log::Entries.new :xmllines => xmllines
17
17
  end
18
18
 
19
+ def new_argument value
20
+ Argument.new value
21
+ end
22
+
19
23
  def create_argument value
20
- Argument.new value, entries: @entries
24
+ Argument.create value, entries: @entries
21
25
  end
22
26
 
23
27
  def assert_argument_value exp_value, value
@@ -52,6 +56,12 @@ module SVNx::Revision
52
56
  assert_compare :>, expeq, xval, yval
53
57
  end
54
58
 
59
+ def test_new_and_create_same
60
+ x = new_argument 13
61
+ y = create_argument 13
62
+ assert_equal y.value, x.value
63
+ end
64
+
55
65
  def test_absolute_midrange
56
66
  assert_argument_value 19, 19
57
67
  end
@@ -4,22 +4,46 @@
4
4
  require 'tc'
5
5
  require 'svnx/log/entries'
6
6
  require 'svnx/revision/range'
7
+ require 'svnx/revision/argument'
8
+ require 'svnx/revision/argfactory'
7
9
  require 'resources'
8
10
 
9
11
  module SVNx::Revision
10
12
  class RangeTestCase < SVNx::TestCase
13
+ def setup
14
+ xmllines = Resources::PT_LOG_R22_13_SECONDFILE_TXT.readlines
15
+ @entries = SVNx::Log::Entries.new :xmllines => xmllines
16
+ end
17
+
18
+ def assert_range expstr, expfrom, expto, argfrom, argto = nil
19
+ rg = Range.new argfrom, argto
20
+ msg = "from: #{argfrom}; to: #{argto}"
21
+
22
+ assert_equal expfrom, rg.from.to_s, msg
23
+ assert_equal expto, rg.to.to_s, msg
24
+ assert_equal expstr, rg.to_s, msg
25
+ rg
26
+ end
27
+
11
28
  def test_init
12
- rr = Range.new '143:199'
13
- assert_equal '143', rr.from.to_s
14
- assert_equal '199', rr.to.to_s
15
- assert_equal '143:199', rr.to_s
29
+ assert_range '143:199', '143', '199', '143:199'
16
30
  end
17
31
 
18
32
  def test_to_working_copy
19
- rr = Range.new '143'
20
- assert_equal '143', rr.from.to_s
21
- assert_nil rr.to
22
- assert_equal '143', rr.to_s
33
+ rr = assert_range '143', '143', '', '143'
34
+ assert rr.working_copy?
35
+ end
36
+
37
+ def test_init_takes_arguments
38
+ fa = Argument.new 143
39
+ ta = Argument.new 199
40
+ rr = Range.new fa, ta
41
+ assert_range '143:199', '143', '199', fa, ta
42
+ end
43
+
44
+ def test_to_head
45
+ rr = assert_range '143:HEAD', '143', 'HEAD', '143', 'HEAD'
46
+ assert rr.head?
23
47
  end
24
48
  end
25
49
  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: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Pace
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-24 00:00:00.000000000 Z
11
+ date: 2013-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logue
@@ -51,13 +51,13 @@ files:
51
51
  - lib/svnx/command.rb
52
52
  - lib/svnx/entries.rb
53
53
  - lib/svnx/entry.rb
54
- - lib/svnx/exec.rb
55
54
  - lib/svnx/info/command.rb
56
55
  - lib/svnx/info/entries.rb
57
56
  - lib/svnx/info/entry.rb
58
57
  - lib/svnx/log/command.rb
59
58
  - lib/svnx/log/entries.rb
60
59
  - lib/svnx/log/entry.rb
60
+ - lib/svnx/revision/argfactory.rb
61
61
  - lib/svnx/revision/argument.rb
62
62
  - lib/svnx/revision/error.rb
63
63
  - lib/svnx/revision/range.rb
@@ -76,6 +76,7 @@ files:
76
76
  - test/unit/svnx/info/entries_test.rb
77
77
  - test/unit/svnx/log/entries_test.rb
78
78
  - test/unit/svnx/log/entry_test.rb
79
+ - test/unit/svnx/revision/argfactory_test.rb
79
80
  - test/unit/svnx/revision/argument_test.rb
80
81
  - test/unit/svnx/revision/range_test.rb
81
82
  - test/unit/svnx/status/entries_test.rb
@@ -115,6 +116,7 @@ test_files:
115
116
  - test/unit/svnx/info/entries_test.rb
116
117
  - test/unit/svnx/log/entries_test.rb
117
118
  - test/unit/svnx/log/entry_test.rb
119
+ - test/unit/svnx/revision/argfactory_test.rb
118
120
  - test/unit/svnx/revision/argument_test.rb
119
121
  - test/unit/svnx/revision/range_test.rb
120
122
  - test/unit/svnx/status/entries_test.rb
@@ -1,39 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # -*- ruby -*-
3
-
4
- require 'svnx/cat/command'
5
- require 'svnx/log/command'
6
- require 'svnx/info/command'
7
- require 'svnx/status/command'
8
-
9
- # executes 'svn <command>' and returns the output as XML lines (by default,
10
- # according to the underlying option).
11
- module SVNx
12
- class Exec
13
- def cat path, revision, use_cache
14
- cmdargs = CatCommandArgs.new :path => path, :revision => revision, :use_cache => use_cache
15
- run_command CatCommand, cmdargs
16
- end
17
-
18
- def log path, revision, limit, verbose, use_cache
19
- cmdargs = LogCommandArgs.new :path => path, :revision => revision, :limit => limit, :verbose => verbose, :use_cache => use_cache
20
- run_command LogCommand, cmdargs
21
- end
22
-
23
- def info path, revision
24
- cmdargs = InfoCommandArgs.new :path => path, :revision => revision
25
- run_command InfoCommand, cmdargs
26
- end
27
-
28
- def status path, use_cache
29
- cmdargs = StatusCommandArgs.new :path => path, :use_cache => use_cache
30
- run_command StatusCommand, cmdargs
31
- end
32
-
33
- private
34
- def run_command cmdcls, args
35
- cmd = cmdcls.new args
36
- cmd.execute
37
- end
38
- end
39
- end