svnx 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7568851539f67dc7fd63364ea9f321cbd2778eb2
4
+ data.tar.gz: 250ae23ce41faca126887be909434539400b30df
5
+ SHA512:
6
+ metadata.gz: 7349591f27fcaf6c89152c07cef03928814eb5bceaee3efcf49421396734604f57e8c580927d8ead613321857afa981b999a5b774e592ce0047e8415e49c49e6
7
+ data.tar.gz: b25d5d269537dc85b929a135a34f0aa49db11ad9c2721a39255b68eb9172a083f9e37ea93f79c89fa0a86fe4c05c3afd56850f334b8f9967f58908550a6b4d4a
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module SVNx
5
+ VERSION = "0.0.2"
6
+ end
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'riel'
6
+ require 'logue/loggable'
7
+
8
+ module SVNx
9
+ class Action
10
+ include Logue::Loggable, Comparable
11
+
12
+ attr_reader :type
13
+
14
+ STATUS_TO_TYPE = Hash.new
15
+
16
+ def self.add_type sym, str, char
17
+ [ sym, str, char ].each do |key|
18
+ STATUS_TO_TYPE[key] = sym
19
+ end
20
+ end
21
+
22
+ add_type :added, 'added', 'A'
23
+ add_type :deleted, 'deleted', 'D'
24
+ add_type :modified, 'modified', 'M'
25
+ add_type :unversioned, 'unversioned', '?'
26
+
27
+ STATUS_TO_TYPE.values.uniq.each do |val|
28
+ methname = val.to_s + '?'
29
+ define_method methname do
30
+ instance_eval do
31
+ @type == STATUS_TO_TYPE[val]
32
+ end
33
+ end
34
+ end
35
+
36
+ def initialize str
37
+ @type = STATUS_TO_TYPE[str]
38
+ end
39
+
40
+ def <=> other
41
+ @type.to_s <=> other.type.to_s
42
+ end
43
+
44
+ def to_s
45
+ @type.to_s
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/command'
5
+ require 'system/command/caching'
6
+
7
+ module SVNx
8
+ module CatCmdLine
9
+ # this can be either an Array (for which to_a returns itself), or a
10
+ # CommandArgs, which also has to_a.
11
+ def initialize args = Array.new
12
+ super "cat", args.to_a
13
+ end
14
+
15
+ def uses_xml?
16
+ false
17
+ end
18
+ end
19
+
20
+ class CatCommandLine < CommandLine
21
+ include CatCmdLine
22
+ end
23
+
24
+ class CatCommandLineCaching < CachingCommandLine
25
+ include CatCmdLine
26
+ end
27
+
28
+ class CatCommandArgs < CommandArgs
29
+ attr_reader :revision
30
+ attr_reader :use_cache
31
+
32
+ def initialize args = Hash.new
33
+ @use_cache = args[:use_cache].nil? || args[:use_cache]
34
+ @revision = args[:revision]
35
+ super
36
+ end
37
+
38
+ def to_a
39
+ ary = Array.new
40
+ if @revision
41
+ ary << "-r#{@revision}"
42
+ end
43
+
44
+ if @path
45
+ ary << @path
46
+ end
47
+ end
48
+ end
49
+
50
+ class CatCommand < Command
51
+ def initialize args
52
+ @use_cache = args.use_cache
53
+ super
54
+ end
55
+
56
+ def command_line
57
+ cls = @use_cache ? CatCommandLineCaching : CatCommandLine
58
+ cls.new @args
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'riel'
6
+ require 'system/command/line'
7
+ require 'logue/loggable'
8
+ require 'system/command/caching'
9
+
10
+ # this replaces svnx/lib/command/svncommand.
11
+
12
+ module SVNx
13
+ DEFAULT_CACHE_DIR = '/tmp/svnx'
14
+ TMP_DIR_ENV_VARNAME = 'SVNX_TMP_DIR'
15
+
16
+ module CmdLine
17
+ include Logue::Loggable
18
+
19
+ def initialize subcmd, args
20
+ # info "args: #{args}"
21
+ cmdargs = [ 'svn', subcmd ]
22
+ cmdargs << '--xml' if uses_xml?
23
+ # info "cmdargs: #{cmdargs}"
24
+ cmdargs.concat args
25
+ # info "cmdargs: #{cmdargs}"
26
+ super cmdargs
27
+ end
28
+
29
+ def uses_xml?
30
+ true
31
+ end
32
+
33
+ def cache_dir
34
+ ENV[TMP_DIR_ENV_VARNAME] || DEFAULT_CACHE_DIR
35
+ end
36
+ end
37
+
38
+ class CommandLine < System::CommandLine
39
+ include CmdLine
40
+ end
41
+
42
+ class CachingCommandLine < System::CachingCommandLine
43
+ include CmdLine
44
+ end
45
+
46
+ class CommandArgs
47
+ include Logue::Loggable
48
+
49
+ attr_accessor :path
50
+
51
+ def initialize args = Hash.new
52
+ @path = args[:path]
53
+ end
54
+
55
+ def to_a
56
+ [ @path ].compact
57
+ end
58
+ end
59
+
60
+ class Command
61
+ include Logue::Loggable
62
+
63
+ attr_reader :output
64
+
65
+ def initialize args
66
+ @args = args
67
+ end
68
+
69
+ def command_line
70
+ raise "must be implemented"
71
+ end
72
+
73
+ def execute
74
+ cmdline = command_line
75
+ cmdline.execute
76
+ @output = cmdline.output
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rexml/document'
5
+ require 'logue/loggable'
6
+
7
+ module SVNx
8
+ # this is a parse/process on-demand list of entries, acting like an
9
+ # Enumerable.
10
+
11
+ class Entries
12
+ include Logue::Loggable, Enumerable
13
+
14
+ attr_reader :size
15
+
16
+ def initialize args = Hash.new
17
+ # it's a hash, but indexed with integers, for non-sequential access:
18
+ @entries = Hash.new
19
+
20
+ if xmllines = args[:xmllines]
21
+ if xmllines.kind_of? Array
22
+ xmllines = xmllines.join ''
23
+ end
24
+
25
+ doc = REXML::Document.new xmllines
26
+
27
+ @elements = get_elements doc
28
+ @size = @elements.size
29
+ elsif args[:xmlentries]
30
+ raise "argument xmlentries is no longer supported"
31
+ end
32
+ end
33
+
34
+ def get_elements doc
35
+ raise "get_elements must be implemented for: #{self.class}"
36
+ end
37
+
38
+ def create_entry xmlelement
39
+ raise "create_entry must be implemented for: #{self.class}"
40
+ end
41
+
42
+ # this doesn't handle negative indices
43
+ def [] idx
44
+ if entry = @entries[idx]
45
+ return entry
46
+ end
47
+ if idx < 0 && idx >= size
48
+ raise "error: index #{idx} is not in range(0 .. #{size})"
49
+ end
50
+ @entries[idx] = create_entry(@elements[idx + 1])
51
+ end
52
+
53
+ def each(&blk)
54
+ # all elements must be processed before each can run:
55
+ if @elements
56
+ # a little confusing here: REXML does each_with_index with idx
57
+ # zero-based, but elements[0] is invalid.
58
+ @elements.each_with_index do |element, idx|
59
+ @entries[idx] ||= create_entry(element)
60
+ end
61
+
62
+ @elements = nil
63
+ end
64
+
65
+ @entries.keys.sort.collect { |idx| @entries[idx] }.each(&blk)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'riel'
6
+ require 'rexml/document'
7
+ require 'logue/loggable'
8
+
9
+ module SVNx
10
+ class Entry
11
+ include Logue::Loggable
12
+
13
+ def initialize args = Hash.new
14
+ if xmllines = args[:xmllines]
15
+ if xmllines.kind_of? Array
16
+ xmllines = xmllines.join ''
17
+ end
18
+
19
+ doc = REXML::Document.new xmllines
20
+
21
+ set_from_xml doc
22
+ elsif elmt = args[:xmlelement]
23
+ set_from_element elmt
24
+ else
25
+ raise "must be initialized with xmllines or xmlelement"
26
+ end
27
+ end
28
+
29
+ def set_from_xml xmldoc
30
+ raise "must be implemented"
31
+ end
32
+
33
+ def set_from_element elmt
34
+ raise "must be implemented"
35
+ end
36
+
37
+ def get_attribute xmlelement, attrname
38
+ xmlelement.attributes[attrname]
39
+ end
40
+
41
+ def get_element_text xmlelement, elmtname
42
+ elmt = xmlelement.elements[elmtname]
43
+ # in my test svn repository, revision 1 doesn't have an author element:
44
+ (elmt && elmt.text) || ""
45
+ end
46
+
47
+ def set_attr_var xmlelement, varname
48
+ set_var varname, get_attribute(xmlelement, varname)
49
+ end
50
+
51
+ def set_elmt_var xmlelement, varname
52
+ set_var varname, get_element_text(xmlelement, varname)
53
+ end
54
+
55
+ def set_var varname, value
56
+ instance_variable_set '@' + varname, value
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'riel'
6
+ require 'svnx/cat/command'
7
+ require 'svnx/log/command'
8
+ require 'svnx/info/command'
9
+ require 'svnx/status/command'
10
+
11
+ # executes 'svn <command>' and returns the output as XML lines (by default,
12
+ # according to the underlying option).
13
+ module SVNx
14
+ class Exec
15
+ def cat path, revision, use_cache
16
+ cmdargs = CatCommandArgs.new :path => path, :revision => revision, :use_cache => use_cache
17
+ run_command CatCommand, cmdargs
18
+ end
19
+
20
+ def log path, revision, limit, verbose, use_cache
21
+ cmdargs = LogCommandArgs.new :path => path, :revision => revision, :limit => limit, :verbose => verbose, :use_cache => use_cache
22
+ run_command LogCommand, cmdargs
23
+ end
24
+
25
+ def info path, revision
26
+ cmdargs = InfoCommandArgs.new :path => path, :revision => revision
27
+ run_command InfoCommand, cmdargs
28
+ end
29
+
30
+ def status path, use_cache
31
+ cmdargs = StatusCommandArgs.new :path => path, :use_cache => use_cache
32
+ run_command StatusCommand, cmdargs
33
+ end
34
+
35
+ private
36
+ def run_command cmdcls, args
37
+ cmd = cmdcls.new args
38
+ cmd.execute
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/command'
5
+ require 'rainbow'
6
+
7
+ module SVNx
8
+ class InfoCommandLine < CommandLine
9
+ def initialize args = Array.new
10
+ info "args.to_a: #{args.to_a}".color(:blue)
11
+ super "info", args.to_a
12
+ end
13
+ end
14
+
15
+ class InfoCommandArgs < CommandArgs
16
+ attr_reader :revision
17
+
18
+ def initialize args = Hash.new
19
+ @revision = args[:revision]
20
+ super
21
+ end
22
+
23
+ def to_a
24
+ ary = Array.new
25
+
26
+ if @revision
27
+ [ @revision ].flatten.each do |rev|
28
+ ary << "-r#{rev}"
29
+ end
30
+ end
31
+
32
+ if @path
33
+ ary << @path
34
+ end
35
+ ary
36
+ end
37
+ end
38
+
39
+ class InfoCommand < Command
40
+ def command_line
41
+ InfoCommandLine.new @args
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/info/entry'
5
+ require 'svnx/entries'
6
+
7
+ module SVNx::Info
8
+ class Entries < SVNx::Entries
9
+ def get_elements doc
10
+ doc.elements['info'].elements
11
+ end
12
+
13
+ def create_entry xmlelement
14
+ Entry.new :xmlelement => xmlelement
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/entry'
5
+
6
+ module SVNx; module Info; end; end
7
+
8
+ module SVNx::Info
9
+ class Entry < SVNx::Entry
10
+ attr_reader :url
11
+ attr_reader :root
12
+ attr_reader :kind
13
+ attr_reader :path
14
+ attr_reader :revision
15
+
16
+ def set_from_xml xmldoc
17
+ entry = xmldoc.elements['info/entry']
18
+ set_from_element entry
19
+ end
20
+
21
+ def set_from_element elmt
22
+ set_attr_var elmt, 'kind'
23
+ set_attr_var elmt, 'path'
24
+ set_attr_var elmt, 'revision'
25
+ set_elmt_var elmt, 'url'
26
+
27
+ repo = elmt.elements['repository']
28
+ set_elmt_var repo, 'root'
29
+ end
30
+ end
31
+ end