esvien 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +13 -0
- data/README.md +25 -0
- data/Rakefile +9 -0
- data/lib/esvien.rb +12 -0
- data/lib/esvien/commit.rb +40 -0
- data/lib/esvien/errors.rb +29 -0
- data/lib/esvien/repo.rb +84 -0
- metadata +70 -0
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2007 Brian Donovan, Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Esvien
|
2
|
+
======
|
3
|
+
Esvien is a simple Ruby interface to Subversion.
|
4
|
+
|
5
|
+
http://github.com/eventualbuddha/esvien
|
6
|
+
|
7
|
+
Example
|
8
|
+
-------
|
9
|
+
|
10
|
+
>> head = Esvien::Repo.new("http://svn.collab.net/repos/svn/trunk/").head
|
11
|
+
=> #<Esvien::Commit id=36632, repo=#<Esvien::Repo uri="http://svn.collab.net/repos/svn/trunk/", uuid="612f8ebc-c883-4be0-9ee0-a4e9ef946e3a">>
|
12
|
+
>> head.author
|
13
|
+
=> "gstein"
|
14
|
+
>> head.date
|
15
|
+
=> Tue Mar 17 17:37:56 UTC 2009
|
16
|
+
|
17
|
+
Install
|
18
|
+
-------
|
19
|
+
|
20
|
+
sudo gem install esvien
|
21
|
+
|
22
|
+
Requirements
|
23
|
+
------------
|
24
|
+
|
25
|
+
Depends on Hpricot.
|
data/Rakefile
ADDED
data/lib/esvien.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Esvien
|
2
|
+
class Commit
|
3
|
+
attr_reader :id
|
4
|
+
attr_reader :repo
|
5
|
+
attr_accessor :author
|
6
|
+
attr_accessor :date
|
7
|
+
|
8
|
+
include Comparable
|
9
|
+
|
10
|
+
def initialize(id, repo)
|
11
|
+
@id = id
|
12
|
+
@repo = repo
|
13
|
+
end
|
14
|
+
|
15
|
+
def <=>(other)
|
16
|
+
if other.is_a?(Commit)
|
17
|
+
if self.repo == other.repo
|
18
|
+
return id <=> other.id
|
19
|
+
else
|
20
|
+
raise Esvien::RepositoryMismatch
|
21
|
+
end
|
22
|
+
else
|
23
|
+
raise ArgumentError, "Cannot compare #{self.class} with #{other.class}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def pretty_print(pp)
|
28
|
+
pp.group(1, %{#<#{self.class}}, %{>}) do
|
29
|
+
pp.breakable
|
30
|
+
pp.seplist(%w[id repo], lambda { pp.comma_breakable }) do |attr|
|
31
|
+
pp.text(attr)
|
32
|
+
pp.text("=")
|
33
|
+
pp.pp(send(attr))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :inspect, :pretty_print_inspect
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Esvien
|
2
|
+
class Error < RuntimeError
|
3
|
+
end
|
4
|
+
|
5
|
+
class BadRepository < Error
|
6
|
+
attr_reader :repo
|
7
|
+
|
8
|
+
def initialize(repo)
|
9
|
+
@repo = repo
|
10
|
+
end
|
11
|
+
|
12
|
+
def message
|
13
|
+
"No repository found at #{repo.uri}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class CLIError < Error
|
18
|
+
def initialize(command, output)
|
19
|
+
@command, @output = command, output
|
20
|
+
end
|
21
|
+
|
22
|
+
def message
|
23
|
+
"Error while executing Subversion command:\n\n #{@command}\n\nOutput:\n\n#{@output.to_a.map{|line|" #{line}"}}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class RepositoryMismatch < Error
|
28
|
+
end
|
29
|
+
end
|
data/lib/esvien/repo.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Esvien
|
2
|
+
class Repo
|
3
|
+
attr_reader :uri
|
4
|
+
attr_reader :uuid
|
5
|
+
|
6
|
+
def initialize(uri)
|
7
|
+
@uri = uri
|
8
|
+
get_repository_info
|
9
|
+
end
|
10
|
+
|
11
|
+
def commits(range=nil)
|
12
|
+
return [] if @revision == 0
|
13
|
+
|
14
|
+
doc = svnxml(:log, '-r', svn_range_string(range) || '1:HEAD', uri)
|
15
|
+
elems = doc.search('/log/logentry')
|
16
|
+
elems.map do |elem|
|
17
|
+
commit = Commit.new(elem.attributes['revision'].to_i, self)
|
18
|
+
commit.author = elem.children_of_type('author').first.inner_text
|
19
|
+
commit.date = Time.parse(elem.children_of_type('date').first.inner_text)
|
20
|
+
commit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def head
|
25
|
+
commits('HEAD').first
|
26
|
+
end
|
27
|
+
|
28
|
+
def ==(other)
|
29
|
+
uuid == other.uuid
|
30
|
+
end
|
31
|
+
|
32
|
+
def pretty_print(pp)
|
33
|
+
pp.group(1, %{#<#{self.class}}, %{>}) do
|
34
|
+
pp.breakable
|
35
|
+
pp.seplist(%w[uri uuid], lambda { pp.comma_breakable }) do |attr|
|
36
|
+
pp.text(attr)
|
37
|
+
pp.text("=")
|
38
|
+
pp.pp(send(attr))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :inspect, :pretty_print_inspect
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get_repository_info
|
48
|
+
begin
|
49
|
+
doc = svnxml(:info, uri)
|
50
|
+
entry = doc.at('/info/entry')
|
51
|
+
@revision = entry.attributes['revision'].to_i
|
52
|
+
repo = entry.children_of_type('repository').first
|
53
|
+
@uuid = repo.children_of_type('uuid').first.inner_text
|
54
|
+
rescue Esvien::CLIError
|
55
|
+
raise Esvien::BadRepository, self
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def svn_range_string(range)
|
60
|
+
case range
|
61
|
+
when nil
|
62
|
+
return nil
|
63
|
+
when Range
|
64
|
+
"#{range.first}:#{range.last}"
|
65
|
+
else
|
66
|
+
range.to_s
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def svnxml(operation, *args)
|
71
|
+
Hpricot.XML(svn(operation, '--xml', *args))
|
72
|
+
end
|
73
|
+
|
74
|
+
def svn(operation, *args)
|
75
|
+
command = %{svn #{operation} #{args.map{|arg| %{"#{arg.to_s.gsub('"', '\"')}"}}.join(' ')} 2>&1}
|
76
|
+
output = %x{#{command}}
|
77
|
+
if $?.exitstatus == 0
|
78
|
+
return output
|
79
|
+
else
|
80
|
+
raise Esvien::CLIError.new(command, output)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esvien
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Donovan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hpricot
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.6"
|
24
|
+
version:
|
25
|
+
description: A simple Subversion client for Ruby
|
26
|
+
email: brian.donovan@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.md
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- README.md
|
36
|
+
- LICENSE
|
37
|
+
- Rakefile
|
38
|
+
- lib/esvien
|
39
|
+
- lib/esvien/commit.rb
|
40
|
+
- lib/esvien/errors.rb
|
41
|
+
- lib/esvien/repo.rb
|
42
|
+
- lib/esvien.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/eventualbuddha/esvien
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: esvien
|
65
|
+
rubygems_version: 1.3.1
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: A simple Subversion client for Ruby
|
69
|
+
test_files: []
|
70
|
+
|