svnx 1.0.1 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.glarkrc +1 -0
  4. data/Features.txt +7 -0
  5. data/Gemfile +4 -0
  6. data/History.txt +4 -0
  7. data/LICENSE +20 -0
  8. data/Manifest.txt +0 -0
  9. data/README.md +12 -0
  10. data/Rakefile +12 -0
  11. data/lib/svnx/base/action.rb +57 -52
  12. data/lib/svnx/base/cmdline.rb +58 -0
  13. data/lib/svnx/base/command.rb +49 -41
  14. data/lib/svnx/base/entries.rb +46 -45
  15. data/lib/svnx/base/entry.rb +51 -38
  16. data/lib/svnx/base/env.rb +26 -0
  17. data/lib/svnx/base/options.rb +25 -0
  18. data/lib/svnx/cat/command.rb +3 -64
  19. data/lib/svnx/cat/options.rb +28 -0
  20. data/lib/svnx/commit/command.rb +9 -0
  21. data/lib/svnx/commit/options.rb +29 -0
  22. data/lib/svnx/diff/command.rb +17 -0
  23. data/lib/svnx/diff/elements.rb +84 -0
  24. data/lib/svnx/diff/options.rb +35 -0
  25. data/lib/svnx/diff/parser.rb +105 -0
  26. data/lib/svnx/info/command.rb +4 -47
  27. data/lib/svnx/info/entries.rb +6 -8
  28. data/lib/svnx/info/entry.rb +21 -23
  29. data/lib/svnx/info/options.rb +28 -0
  30. data/lib/svnx/io/directory.rb +9 -5
  31. data/lib/svnx/io/element.rb +93 -95
  32. data/lib/svnx/log/command.rb +7 -3
  33. data/lib/svnx/log/entries.rb +17 -14
  34. data/lib/svnx/log/entry.rb +61 -49
  35. data/lib/svnx/log/options.rb +31 -0
  36. data/lib/svnx/merge/command.rb +9 -0
  37. data/lib/svnx/merge/options.rb +34 -0
  38. data/lib/svnx/project.rb +74 -0
  39. data/lib/svnx/propget/command.rb +9 -0
  40. data/lib/svnx/propget/entries.rb +15 -0
  41. data/lib/svnx/propget/entry.rb +23 -0
  42. data/lib/svnx/propget/options.rb +31 -0
  43. data/lib/svnx/propset/command.rb +9 -0
  44. data/lib/svnx/propset/options.rb +33 -0
  45. data/lib/svnx/revision/argfactory.rb +2 -2
  46. data/lib/svnx/revision/argument.rb +7 -3
  47. data/lib/svnx/revision/date.rb +27 -0
  48. data/lib/svnx/revision/error.rb +2 -2
  49. data/lib/svnx/revision/range.rb +5 -2
  50. data/lib/svnx/status/command.rb +4 -42
  51. data/lib/svnx/status/entries.rb +11 -12
  52. data/lib/svnx/status/entry.rb +43 -41
  53. data/lib/svnx/status/options.rb +28 -0
  54. data/lib/svnx/update/command.rb +9 -0
  55. data/lib/svnx/update/options.rb +25 -0
  56. data/lib/svnx/util/dateutil.rb +35 -0
  57. data/lib/svnx/util/objutil.rb +14 -0
  58. data/lib/{svnx.rb → svnx/version.rb} +2 -2
  59. data/lib/system/command/arg.rb +6 -5
  60. data/lib/system/command/cachefile.rb +29 -21
  61. data/lib/system/command/caching.rb +12 -25
  62. data/lib/system/command/line.rb +41 -30
  63. data/svnx.gemspec +34 -0
  64. metadata +85 -61
  65. data/lib/svnx/base/args.rb +0 -24
  66. data/lib/svnx/log/args.rb +0 -57
  67. data/lib/svnx/log/exec.rb +0 -27
  68. data/lib/svnx/log/line.rb +0 -42
  69. data/test/integration/info/info_test.rb +0 -21
  70. data/test/integration/log/log_test.rb +0 -74
  71. data/test/integration/status/status_test.rb +0 -35
  72. data/test/integration/svnx/io/element_test.rb +0 -235
  73. data/test/unit/svnx/base/action_test.rb +0 -49
  74. data/test/unit/svnx/cat/command_test.rb +0 -55
  75. data/test/unit/svnx/info/entries_test.rb +0 -22
  76. data/test/unit/svnx/log/args_test.rb +0 -15
  77. data/test/unit/svnx/log/entries_test.rb +0 -87
  78. data/test/unit/svnx/log/entry_test.rb +0 -15
  79. data/test/unit/svnx/log/exec_test.rb +0 -15
  80. data/test/unit/svnx/log/line_test.rb +0 -14
  81. data/test/unit/svnx/revision/argfactory_test.rb +0 -50
  82. data/test/unit/svnx/revision/argument_test.rb +0 -167
  83. data/test/unit/svnx/revision/range_test.rb +0 -48
  84. data/test/unit/svnx/status/entries_test.rb +0 -20
  85. data/test/unit/system/command/cachefile_test.rb +0 -52
  86. data/test/unit/system/command/caching_test.rb +0 -92
  87. data/test/unit/system/command/line_test.rb +0 -63
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- module SVNx; module Revision; end; end
4
+ module Svnx; module Revision; end; end
5
5
 
6
- module SVNx::Revision
6
+ module Svnx::Revision
7
7
  class ArgumentFactory
8
8
  include Logue::Loggable
9
9
 
@@ -6,11 +6,11 @@ require 'svnx/revision/error'
6
6
  require 'logue/loggable'
7
7
  require 'svnx/revision/argfactory'
8
8
 
9
- module SVNx; module Revision; end; end
9
+ module Svnx; module Revision; end; end
10
10
 
11
11
  # We represent what svn calls a revision (-r134:{2010-1-1}) as a Range,
12
12
  # consisting of a from and to (optional) Argument.
13
- module SVNx::Revision
13
+ module Svnx::Revision
14
14
  RELATIVE_REVISION_RE = Regexp.new '^([\+\-])(\d+)$'
15
15
 
16
16
  # Returns the Nth revision from the given logging output.
@@ -42,7 +42,11 @@ module SVNx::Revision
42
42
  end
43
43
 
44
44
  def <=> other
45
- @value <=> other.value
45
+ if other.kind_of? Argument
46
+ @value <=> other.value
47
+ else
48
+ @value <=> other
49
+ end
46
50
  end
47
51
  end
48
52
 
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'pathname'
5
+
6
+ module Svnx
7
+ module Revision
8
+ end
9
+ end
10
+
11
+ class Svnx::Revision::DateToDate
12
+ attr_reader :from
13
+ attr_reader :to
14
+
15
+ def initialize from, to
16
+ @from = from
17
+ @to = to
18
+ end
19
+
20
+ def to_svn_str
21
+ [ @from, @to ].collect { |dt| "{" + to_svn_date(dt) + "}" }.join(":")
22
+ end
23
+
24
+ def to_svn_date date
25
+ date.strftime "%Y-%m-%d"
26
+ end
27
+ end
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- module SVNx; module Revision; end; end
4
+ module Svnx; module Revision; end; end
5
5
 
6
- module SVNx::Revision
6
+ module Svnx::Revision
7
7
  class RevisionError < RuntimeError
8
8
  end
9
9
  end
@@ -5,9 +5,12 @@ require 'svnx/log/entries'
5
5
  require 'svnx/revision/argument'
6
6
  require 'logue/loggable'
7
7
 
8
- module SVNx; module Revision; end; end
8
+ module Svnx
9
+ module Revision
10
+ end
11
+ end
9
12
 
10
- module SVNx::Revision
13
+ module Svnx::Revision
11
14
  # this is of the form: -r123:456
12
15
  class Range
13
16
  include Logue::Loggable
@@ -2,47 +2,9 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  require 'svnx/base/command'
5
- require 'svnx/info/command'
5
+ require 'svnx/status/options'
6
+ require 'svnx/status/entries'
6
7
 
7
- module SVNx
8
- class StatusCommandLine < CommandLine
9
- def initialize args
10
- super "status", args.to_a
11
- end
12
- end
13
-
14
- class StatusCommandArgs < CommandArgs
15
- def to_a
16
- [ @path ].compact
17
- end
18
- end
19
-
20
- class StatusCommand < Command
21
- def command_line
22
- StatusCommandLine.new @args
23
- end
24
- end
25
-
26
- class StatusExec
27
- attr_reader :entries
28
-
29
- def initialize args
30
- path = args[:path]
31
- rootpath = nil
32
-
33
- while true
34
- begin
35
- inf = InfoExec.new(path: path).entry
36
- rootpath = inf.wc_root
37
- break
38
- rescue
39
- path = Pathname.new(path).dirname.to_s
40
- break if path == '/'
41
- end
42
- end
43
-
44
- cmd = StatusCommand.new StatusCommandArgs.new(args)
45
- @entries = SVNx::Status::Entries.new(xmllines: cmd.execute, rootpath: rootpath)
46
- end
47
- end
8
+ class Svnx::Status::Command < Svnx::Base::EntriesCommand
9
+ noncaching
48
10
  end
@@ -4,19 +4,18 @@
4
4
  require 'svnx/status/entry'
5
5
  require 'svnx/base/entries'
6
6
 
7
- module SVNx::Status
8
- class Entries < SVNx::Entries
9
- def initialize args = Hash.new
10
- @rootpath = args[:rootpath]
11
- super
12
- end
7
+ class Svnx::Status::Entries < Svnx::Base::Entries
8
+ def initialize args = Hash.new
9
+ @rootpath = args[:rootpath]
10
+ super
11
+ end
13
12
 
14
- def get_elements doc
15
- doc.elements['status'].elements['target'].elements
16
- end
13
+ def get_elements doc
14
+ # status/target
15
+ doc.elements['status'].elements['target'].elements
16
+ end
17
17
 
18
- def create_entry xmlelement
19
- Entry.new xmlelement: xmlelement, rootpath: @rootpath
20
- end
18
+ def create_entry xmlelement
19
+ Svnx::Status::Entry.new xmlelement: xmlelement, rootpath: @rootpath
21
20
  end
22
21
  end
@@ -4,52 +4,54 @@
4
4
  require 'svnx/base/entry'
5
5
  require 'svnx/base/action'
6
6
 
7
- module SVNx; module Status; end; end
7
+ module Svnx
8
+ module Status
9
+ end
10
+ end
11
+
12
+ class Svnx::Status::Entry < Svnx::Base::Entry
13
+ include Comparable, Logue::Loggable
14
+
15
+ attr_reader :status
16
+ attr_reader :path
17
+ attr_reader :status_revision
18
+ attr_reader :action
19
+ attr_reader :commit_revision
20
+ attr_reader :name
21
+
22
+ def initialize xmlelement: nil, rootpath: nil
23
+ @rootpath = rootpath
24
+ super xmlelement: xmlelement
25
+ # @status is an Svnx::Action
26
+ @action = @status
27
+ end
28
+
29
+ def set_from_element elmt
30
+ set_attr_var elmt, 'path'
8
31
 
9
- module SVNx::Status
10
- class Entry < SVNx::Entry
11
- include Comparable, Logue::Loggable
32
+ wcstatus = elmt.elements['wc-status']
33
+ @status = Svnx::Action.new(wcstatus.attributes['item'])
34
+ @status_revision = wcstatus.attributes['revision']
12
35
 
13
- attr_reader :status
14
- attr_reader :path
15
- attr_reader :status_revision
16
- attr_reader :action
17
- attr_reader :commit_revision
18
- attr_reader :name
19
-
20
- def initialize args
21
- @rootpath = args[:rootpath]
22
- super
23
- @action = SVNx::Action.new @status
24
- end
36
+ commit = wcstatus.elements['commit']
37
+ @commit_revision = commit && commit.attributes['revision']
38
+ @name = @path.dup
25
39
 
26
- def set_from_element elmt
27
- set_attr_var elmt, 'path'
28
-
29
- wcstatus = elmt.elements['wc-status']
30
- @status = SVNx::Action.new(wcstatus.attributes['item'])
31
- @status_revision = wcstatus.attributes['revision']
32
-
33
- commit = wcstatus.elements['commit']
34
- @commit_revision = commit && commit.attributes['revision']
35
- @name = @path.dup
36
-
37
- info "@name: #{@name}"
38
- info "@path: #{@path}"
39
- info "@rootpath: #{@rootpath}"
40
-
41
- if @rootpath
42
- # name is prefixed with directory unless '.' is used as the argument
43
- @name.sub! Regexp.new('^' + @rootpath), ''
44
- end
45
- end
40
+ info "@name: #{@name}"
41
+ info "@path: #{@path}"
42
+ info "@rootpath: #{@rootpath}"
46
43
 
47
- def to_s
48
- "path: #{@path}; status: #{@status}"
44
+ if @rootpath
45
+ # name is prefixed with directory unless '.' is used as the argument
46
+ @name.sub! Regexp.new('^' + @rootpath), ''
49
47
  end
48
+ end
50
49
 
51
- def <=> other
52
- path <=> other.path
53
- end
50
+ def to_s
51
+ "path: #{@path}; status: #{@status}"
52
+ end
53
+
54
+ def <=> other
55
+ path <=> other.path
54
56
  end
55
57
  end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/util/objutil'
5
+ require 'svnx/base/options'
6
+
7
+ module Svnx
8
+ module Status
9
+ end
10
+ end
11
+
12
+ class Svnx::Status::Options < Svnx::Base::Options
13
+ attr_reader :revision
14
+ attr_reader :url
15
+ attr_reader :paths
16
+
17
+ def initialize args
18
+ assign args, :revision, :url, :paths
19
+ end
20
+
21
+ def options_to_args
22
+ Array.new.tap do |optargs|
23
+ optargs << [ :revision, [ "-r", @revision ] ]
24
+ optargs << [ :url, @url ]
25
+ optargs << [ :paths, @paths ]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/base/command'
5
+ require 'svnx/update/options'
6
+
7
+ class Svnx::Update::Command < Svnx::Base::Command
8
+ noncaching
9
+ end
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'svnx/base/options'
5
+
6
+ module Svnx
7
+ module Update
8
+ end
9
+ end
10
+
11
+ class Svnx::Update::Options < Svnx::Base::Options
12
+ attr_reader :revision
13
+ attr_reader :paths
14
+
15
+ def initialize args = Hash.new
16
+ assign args, :revision, :paths
17
+ end
18
+
19
+ def options_to_args
20
+ Array.new.tap do |optargs|
21
+ optargs << [ :revision, [ "-r", revision ] ]
22
+ optargs << [ :paths, paths ]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ require 'time'
5
+
6
+ class DateUtil
7
+ 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) + ")"
12
+ else
13
+ datetime.strftime "%Y/%m/%d %H:%M"
14
+ end
15
+ end
16
+
17
+ def to_time_units seconds
18
+ secs = seconds.to_i
19
+
20
+ if secs < 120
21
+ "#{secs} seconds"
22
+ elsif (min = secs / 60) < 120
23
+ "#{min} minutes"
24
+ elsif (hour = min / 60) < 72
25
+ "#{hour} hours"
26
+ elsif (day = hour / 24) < 7
27
+ "#{day} days"
28
+ end
29
+ end
30
+
31
+ def fmt_mmdd_hhmm date
32
+ date.strftime "%m/%d %H:%M"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/ruby -w
2
+ # -*- ruby -*-
3
+
4
+ module Svnx
5
+ end
6
+
7
+ module Svnx::ObjectUtil
8
+ # shortcut for "@var = args[:var]", for multiple variable names, which are symbols.
9
+ def assign args, *symbols
10
+ symbols.each do |symbol|
11
+ instance_variable_set "@" + symbol.to_s, args[symbol]
12
+ end
13
+ end
14
+ end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- module SVNx
4
+ module Svnx
5
5
  NAME = 'svnx'
6
- VERSION = '1.0.1'
6
+ VERSION = '2.0.6'
7
7
  end
@@ -2,11 +2,12 @@
2
2
  # -*- ruby -*-
3
3
 
4
4
  module System
5
- class Argument < String
6
- # just a string, but quotes itself
5
+ end
6
+
7
+ class System::Argument < String
8
+ # just a string, but quotes itself
7
9
 
8
- def to_s
9
- '"' + super + '"'
10
- end
10
+ def to_s
11
+ '"' + super + '"'
11
12
  end
12
13
  end
@@ -6,45 +6,53 @@ require 'zlib'
6
6
  require 'logue/loggable'
7
7
 
8
8
  module System
9
- class CacheFile
9
+ class GzipPathname < Pathname
10
10
  include Logue::Loggable
11
-
12
- attr_reader :output
13
11
 
14
- def initialize cache_dir, args
15
- @args = args
16
- @pn = Pathname.new(cache_dir) + (args.join('-').gsub('/', '_slash_') + '.gz')
17
- @output = nil
18
- end
19
-
20
- def save_file
21
- @pn.parent.mkpath unless @pn.parent.exist?
22
- @pn.unlink if @pn.exist?
23
- Zlib::GzipWriter.open(@pn.to_s) do |gz|
24
- gz.puts @output
12
+ def save_file content
13
+ parent.mkpath unless parent.exist?
14
+ unlink if exist?
15
+ Zlib::GzipWriter.open(to_s) do |gz|
16
+ gz.puts content
25
17
  end
26
18
  end
27
19
 
28
20
  def read_file
29
- Zlib::GzipReader.open(@pn.to_s) do |gz|
30
- @output = gz.readlines
21
+ Array.new.tap do |content|
22
+ Zlib::GzipReader.open(to_s) do |gz|
23
+ content.concat gz.readlines
24
+ end
31
25
  end
32
- @output
33
26
  end
27
+ end
34
28
 
29
+ class CacheFile
30
+ include Logue::Loggable
31
+
32
+ attr_reader :output
33
+ attr_reader :pathname
34
+
35
+ def initialize cache_dir, args
36
+ @args = args
37
+ basename = args.join('-').gsub('/', '_slash_') + '.gz'
38
+ fullname = Pathname(cache_dir) + basename
39
+ @pathname = GzipPathname.new fullname
40
+ @output = nil
41
+ end
42
+
35
43
  def readlines
36
- if @pn.exist?
37
- read_file
44
+ if @pathname.exist?
45
+ @output = @pathname.read_file
38
46
  else
39
47
  cl = CommandLine.new @args
40
48
  @output = cl.execute
41
- save_file
49
+ @pathname.save_file @output
42
50
  @output
43
51
  end
44
52
  end
45
53
 
46
54
  def to_s
47
- @pn.to_s
55
+ @pathname.to_s
48
56
  end
49
57
  end
50
58
  end