svnx 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/svnx.rb +1 -1
- data/lib/svnx/revision/argument.rb +116 -0
- data/lib/svnx/revision/error.rb +9 -0
- data/lib/svnx/revision/range.rb +50 -0
- data/test/unit/svnx/action_test.rb +1 -1
- data/test/unit/svnx/cat/command_test.rb +1 -1
- data/test/unit/svnx/revision/argument_test.rb +157 -0
- data/test/unit/svnx/revision/range_test.rb +25 -0
- data/test/unit/system/command/line_test.rb +1 -1
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e756a5b2625c284861b85b3a7b0543ef044e8ff
|
4
|
+
data.tar.gz: e49bdcff5e52a538fcbd247da3d609afba5ac105
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f062f3d0079b5ef799c366762301782db8251e7efb0cef86d776ca1c46b22d585502b89d97c1619fa14d2b3a7c5c052595a14e9a8a059c67fe4914ddab7ed9d8
|
7
|
+
data.tar.gz: e5d72e5378080300fd11e988e54283676b0e2d1749725aa4512e51d78563d27d516756db0d91722c886ba6d07802925963412fedefd69ff67f5abc9856ba9fd3
|
data/lib/svnx.rb
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'svnx/log/entries'
|
5
|
+
require 'svnx/revision/error'
|
6
|
+
require 'logue/loggable'
|
7
|
+
|
8
|
+
module SVNx; module Revision; end; end
|
9
|
+
|
10
|
+
# We represent what svn calls a revision (-r134:{2010-1-1}) as a Range,
|
11
|
+
# consisting of a from and to (optional) Argument.
|
12
|
+
module SVNx::Revision
|
13
|
+
RELATIVE_REVISION_RE = Regexp.new '^([\+\-])(\d+)$'
|
14
|
+
|
15
|
+
# Returns the Nth revision from the given logging output.
|
16
|
+
|
17
|
+
# -n means to count from the end of the list.
|
18
|
+
# +n means to count from the beginning of the list.
|
19
|
+
# n means the literal revision number.
|
20
|
+
class Argument
|
21
|
+
include Logue::Loggable, Comparable
|
22
|
+
|
23
|
+
DATE_REGEXP = Regexp.new '^\{(.*?)\}'
|
24
|
+
SVN_ARGUMENT_WORDS = %w{ HEAD BASE COMMITTED PREV }
|
25
|
+
|
26
|
+
# these are also valid revisions
|
27
|
+
# :working_copy
|
28
|
+
# :head
|
29
|
+
|
30
|
+
attr_reader :value
|
31
|
+
|
32
|
+
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
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def initialize value
|
72
|
+
@value = value
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_s
|
76
|
+
@value.to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def <=> other
|
80
|
+
@value <=> other.value
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class FixnumArgument < Argument
|
85
|
+
end
|
86
|
+
|
87
|
+
class StringArgument < Argument
|
88
|
+
end
|
89
|
+
|
90
|
+
class WorkingCopyArgument < Argument
|
91
|
+
end
|
92
|
+
|
93
|
+
# this is of the form -3, which is revision[-3] (second one from the most
|
94
|
+
# recent; -1 is the most recent).
|
95
|
+
class RelativeArgument < FixnumArgument
|
96
|
+
def initialize value, args
|
97
|
+
entries = args[:entries]
|
98
|
+
|
99
|
+
unless entries
|
100
|
+
raise RevisionError.new "cannot determine relative revision without entries"
|
101
|
+
end
|
102
|
+
|
103
|
+
nentries = entries.size
|
104
|
+
|
105
|
+
# logentries are in descending order, so the most recent one is index 0
|
106
|
+
|
107
|
+
if value.abs > nentries
|
108
|
+
raise RevisionError.new "ERROR: no entry for revision: #{value.abs}; number of entries: #{nentries}"
|
109
|
+
else
|
110
|
+
idx = value < 0 ? -1 + value.abs : nentries - value
|
111
|
+
log_entry = entries[idx]
|
112
|
+
super log_entry.revision.to_i
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'svnx/log/entries'
|
5
|
+
require 'svnx/revision/argument'
|
6
|
+
require 'logue/loggable'
|
7
|
+
|
8
|
+
module SVNx; module Revision; end; end
|
9
|
+
|
10
|
+
module SVNx::Revision
|
11
|
+
# this is of the form: -r123:456
|
12
|
+
class Range
|
13
|
+
include Logue::Loggable
|
14
|
+
|
15
|
+
attr_reader :from
|
16
|
+
attr_reader :to
|
17
|
+
|
18
|
+
def initialize from, to = nil, entries = nil
|
19
|
+
if to
|
20
|
+
@from = to_revision from, entries
|
21
|
+
@to = to_revision to, entries
|
22
|
+
elsif from.kind_of? String
|
23
|
+
@from, @to = from.split(':').collect { |x| to_revision x, entries }
|
24
|
+
else
|
25
|
+
@from = to_revision from, entries
|
26
|
+
@to = :working_copy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_revision val, entries
|
31
|
+
val.kind_of?(Argument) || Argument.new(val, entries: entries)
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
str = @from.to_s
|
36
|
+
unless working_copy?
|
37
|
+
str << ':' << @to.to_s
|
38
|
+
end
|
39
|
+
str
|
40
|
+
end
|
41
|
+
|
42
|
+
def head?
|
43
|
+
@to == :head
|
44
|
+
end
|
45
|
+
|
46
|
+
def working_copy?
|
47
|
+
@to == nil || @to == :wc || @to == :working_copy
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,157 @@
|
|
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 ArgumentTestCase < SVNx::TestCase
|
11
|
+
def setup
|
12
|
+
# This is the equivalent of "log" at revision 22, when this file was added
|
13
|
+
# at revision 13. Using this instead of just "log" when regenerating the
|
14
|
+
# resource files keeps the revisions from bouncing around.
|
15
|
+
xmllines = Resources::PT_LOG_R22_13_SECONDFILE_TXT.readlines
|
16
|
+
@entries = SVNx::Log::Entries.new :xmllines => xmllines
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_argument value
|
20
|
+
Argument.new value, entries: @entries
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_argument_value exp_value, value
|
24
|
+
arg = create_argument value
|
25
|
+
assert_equal exp_value, arg.value
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_argument_value_raises value
|
29
|
+
assert_raises(SVNx::Revision::RevisionError) do
|
30
|
+
assert_argument_value nil, value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def assert_argument_to_s exp_str, value
|
35
|
+
arg = create_argument value
|
36
|
+
assert_equal exp_str, arg.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def assert_compare op, exp, xval, yval
|
40
|
+
x = create_argument xval
|
41
|
+
y = create_argument yval
|
42
|
+
msg = "xval: #{xval}; yval: #{yval}"
|
43
|
+
assert_equal exp, x.send(op, y), msg
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_argument_eq expeq, xval, yval
|
47
|
+
# it's the emoticon programming language
|
48
|
+
assert_compare :==, expeq, xval, yval
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_argument_gt expeq, xval, yval
|
52
|
+
assert_compare :>, expeq, xval, yval
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_absolute_midrange
|
56
|
+
assert_argument_value 19, 19
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_absolute_most_recent
|
60
|
+
assert_argument_value 22, 22
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_absolute_least_recent
|
64
|
+
assert_argument_value 13, 13
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_absolute_midrange_as_string
|
68
|
+
assert_argument_value 19, '19'
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_absolute_most_recent_as_string
|
72
|
+
assert_argument_value 22, '22'
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_absolute_least_recent_as_string
|
76
|
+
assert_argument_value 13, '13'
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_svn_word
|
80
|
+
%w{ HEAD BASE COMMITTED PREV }.each do |word|
|
81
|
+
assert_argument_value word, word
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_negative_most_recent
|
86
|
+
assert_argument_value 22, -1
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_negative_second_most_recent
|
90
|
+
assert_argument_value 20, -2
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_negative_least_recent
|
94
|
+
assert_argument_value 13, -5
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_negative_too_far_back
|
98
|
+
assert_argument_value_raises(-6)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_negative_most_recent_as_string
|
102
|
+
assert_argument_value 22, '-1'
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_negative_second_most_recent_as_string
|
106
|
+
assert_argument_value 20, '-2'
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_negative_least_recent_as_string
|
110
|
+
assert_argument_value 13, '-5'
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_negative_too_far_back_as_string
|
114
|
+
assert_argument_value_raises '-6'
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_positive_most_recent
|
118
|
+
assert_argument_value 22, '+5'
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_positive_second_most_recent
|
122
|
+
assert_argument_value 20, '+4'
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_positive_least_recent
|
126
|
+
assert_argument_value 13, '+1'
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_positive_too_far_forward
|
130
|
+
assert_argument_value_raises '+6'
|
131
|
+
end
|
132
|
+
|
133
|
+
def xxxtest_range_svn_word_to_number
|
134
|
+
assert_argument_value 'BASE:1', 'BASE:1'
|
135
|
+
end
|
136
|
+
|
137
|
+
def xxxtest_date
|
138
|
+
assert_argument_to_s '1967-12-10', '1967-12-10'
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_to_s
|
142
|
+
assert_argument_to_s '5', '5'
|
143
|
+
assert_argument_to_s 'HEAD', 'HEAD'
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_eq
|
147
|
+
assert_argument_eq true, '5', '5'
|
148
|
+
assert_argument_eq false, '4', '5'
|
149
|
+
assert_argument_eq false, '5', '4'
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_gt
|
153
|
+
assert_argument_gt true, '17', '16'
|
154
|
+
assert_argument_gt false, '13', '14'
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'tc'
|
5
|
+
require 'svnx/log/entries'
|
6
|
+
require 'svnx/revision/range'
|
7
|
+
require 'resources'
|
8
|
+
|
9
|
+
module SVNx::Revision
|
10
|
+
class RangeTestCase < SVNx::TestCase
|
11
|
+
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
|
16
|
+
end
|
17
|
+
|
18
|
+
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
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svnx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Pace
|
@@ -58,6 +58,9 @@ files:
|
|
58
58
|
- lib/svnx/log/command.rb
|
59
59
|
- lib/svnx/log/entries.rb
|
60
60
|
- lib/svnx/log/entry.rb
|
61
|
+
- lib/svnx/revision/argument.rb
|
62
|
+
- lib/svnx/revision/error.rb
|
63
|
+
- lib/svnx/revision/range.rb
|
61
64
|
- lib/svnx/status/command.rb
|
62
65
|
- lib/svnx/status/entries.rb
|
63
66
|
- lib/svnx/status/entry.rb
|
@@ -73,6 +76,8 @@ files:
|
|
73
76
|
- test/unit/svnx/info/entries_test.rb
|
74
77
|
- test/unit/svnx/log/entries_test.rb
|
75
78
|
- test/unit/svnx/log/entry_test.rb
|
79
|
+
- test/unit/svnx/revision/argument_test.rb
|
80
|
+
- test/unit/svnx/revision/range_test.rb
|
76
81
|
- test/unit/svnx/status/entries_test.rb
|
77
82
|
- test/unit/system/command/cachefile_test.rb
|
78
83
|
- test/unit/system/command/caching_test.rb
|
@@ -110,6 +115,8 @@ test_files:
|
|
110
115
|
- test/unit/svnx/info/entries_test.rb
|
111
116
|
- test/unit/svnx/log/entries_test.rb
|
112
117
|
- test/unit/svnx/log/entry_test.rb
|
118
|
+
- test/unit/svnx/revision/argument_test.rb
|
119
|
+
- test/unit/svnx/revision/range_test.rb
|
113
120
|
- test/unit/svnx/status/entries_test.rb
|
114
121
|
- test/unit/system/command/cachefile_test.rb
|
115
122
|
- test/unit/system/command/caching_test.rb
|