svp 0.1.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.
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ [REVISION 20061015]
2
+
3
+ [NEW] Initial revision.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ README for svp
2
+ ==============
3
+
data/Rakefile ADDED
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/packagetask'
5
+ require 'rake/gempackagetask'
6
+ require 'rake/rdoctask'
7
+ require 'rake/contrib/rubyforgepublisher'
8
+ require 'fileutils'
9
+ include FileUtils
10
+ require File.join(File.dirname(__FILE__), 'lib', 'svp', 'version')
11
+
12
+ AUTHOR = "Simon Harris"
13
+ EMAIL = "support@redhillconsulting.com.au"
14
+ DESCRIPTION = "description of gem"
15
+ HOMEPATH = 'http://svp.rubyforge.org'
16
+ BIN_FILES = %w( svp )
17
+
18
+
19
+ NAME = "svp"
20
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
21
+ VERS = ENV['VERSION'] || (Svp::VERSION::STRING + (REV ? ".#{REV}" : ""))
22
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
23
+ RDOC_OPTS = ['--quiet', '--title', "svp documentation",
24
+ "--opname", "index.html",
25
+ "--line-numbers",
26
+ "--main", "README",
27
+ "--inline-source"]
28
+
29
+ desc "Packages up svp gem."
30
+ task :default => [:test]
31
+ task :package => [:clean]
32
+
33
+ task :test do
34
+ require File.dirname(__FILE__) + '/test/all_tests.rb'
35
+ end
36
+
37
+ spec =
38
+ Gem::Specification.new do |s|
39
+ s.name = NAME
40
+ s.version = VERS
41
+ s.platform = Gem::Platform::RUBY
42
+ s.has_rdoc = true
43
+ s.extra_rdoc_files = ["README", "CHANGELOG"]
44
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
45
+ s.summary = DESCRIPTION
46
+ s.description = DESCRIPTION
47
+ s.author = AUTHOR
48
+ s.email = EMAIL
49
+ s.homepage = HOMEPATH
50
+ s.executables = BIN_FILES
51
+ s.bindir = "bin"
52
+ s.require_path = "lib"
53
+
54
+ #s.add_dependency('activesupport', '>=1.3.1')
55
+ #s.required_ruby_version = '>= 1.8.2'
56
+
57
+ s.files = %w(README CHANGELOG Rakefile) +
58
+ Dir.glob("{bin,doc,test,lib,templates,extras,website,script}/**/*") +
59
+ Dir.glob("ext/**/*.{h,c,rb}") +
60
+ Dir.glob("examples/**/*.rb") +
61
+ Dir.glob("tools/*.rb")
62
+
63
+ # s.extensions = FileList["ext/**/extconf.rb"].to_a
64
+ end
65
+
66
+ Rake::GemPackageTask.new(spec) do |p|
67
+ p.need_tar = true
68
+ p.gem_spec = spec
69
+ end
70
+
71
+ task :install do
72
+ name = "#{NAME}-#{VERS}.gem"
73
+ sh %{rake package}
74
+ sh %{sudo gem install pkg/#{name}}
75
+ end
76
+
77
+ task :uninstall => [:clean] do
78
+ sh %{sudo gem uninstall #{NAME}}
79
+ end
data/bin/svp ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'svp/cli'
4
+
5
+ Svp::CLI.execute!
data/lib/svp/add.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+ require 'svp/change'
3
+
4
+ module Svp
5
+ class Add < Change
6
+ def revert
7
+ FileUtils.rm_rf(@work_file)
8
+ super
9
+ end
10
+
11
+ def prepare_to_commit(p4)
12
+ super
13
+ p4.add(@work_file)
14
+ end
15
+
16
+ def commit(p4)
17
+ FileUtils.mkdir_p(File.dirname(@base_file))
18
+ FileUtils.cp(@work_file, @base_file)
19
+ end
20
+ end
21
+ end
data/lib/svp/change.rb ADDED
@@ -0,0 +1,27 @@
1
+ module Svp
2
+ class Change
3
+ def initialize(work_file, base_file)
4
+ @work_file, @base_file = work_file, base_file
5
+ end
6
+
7
+ def diff
8
+ system("diff -Nu #{@base_file} #{@work_file}")
9
+ end
10
+
11
+ def status
12
+ puts "#{self.class.name[5..5]}\t#{@work_file}"
13
+ end
14
+
15
+ def revert
16
+ puts "Reverted\t#{@work_file}"
17
+ end
18
+
19
+ def prepare_to_commit(p4, action = "Sending")
20
+ puts "#{action}\t#{@work_file}"
21
+ end
22
+
23
+ def rollback(p4)
24
+ p4.revert("-k #{@work_file}")
25
+ end
26
+ end
27
+ end
data/lib/svp/cli.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'fileutils'
2
+ require 'uri'
3
+ require 'yaml'
4
+ require 'svp/workspace'
5
+
6
+ module Svp
7
+ module CLI
8
+ def self.execute!
9
+ work_dir = ENV["PWD"]
10
+ command = ARGV.first
11
+ args = ARGV[1..-1]
12
+ config = nil
13
+
14
+ if command == "checkout"
15
+ depot_uri = args[0]
16
+ work_dir = File.join(work_dir, args[1] || File.basename(depot_uri))
17
+ config = { "revision" => 0, "depot_uri" => depot_uri }
18
+ command = "update"
19
+ end
20
+
21
+ svp_dir = File.join(work_dir, ".svp")
22
+ config_file = File.join(svp_dir, "config.yml")
23
+
24
+ config = YAML::load(IO.read(config_file)) unless config
25
+
26
+ workspace = Workspace.new(URI.parse(config["depot_uri"]), work_dir, svp_dir, config["revision"])
27
+ workspace.send(command.to_sym, args)
28
+ config["revision"] = workspace.revision
29
+
30
+ File.open(config_file, "w") { |io| YAML::dump(config, io) }
31
+ end
32
+ end
33
+ end
data/lib/svp/delete.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+ require 'svp/change'
3
+
4
+ module Svp
5
+ class Delete < Change
6
+ def revert
7
+ FileUtils.cp(@base_file, @work_file)
8
+ super
9
+ end
10
+
11
+ def prepare_to_commit(p4)
12
+ super(p4, "Deleting")
13
+ p4.delete(@work_file)
14
+ end
15
+
16
+ def commit(p4)
17
+ FileUtils.rm_rf(@base_file)
18
+ end
19
+ end
20
+ end
data/lib/svp/modify.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+ require 'svp/change'
3
+
4
+ module Svp
5
+ class Modify < Change
6
+ def revert
7
+ FileUtils.cp(@base_file, @work_file)
8
+ super
9
+ end
10
+
11
+ def prepare_to_commit(p4)
12
+ super
13
+ p4.edit(@work_file)
14
+ end
15
+
16
+ def commit(p4)
17
+ FileUtils.cp(@work_file, @base_file)
18
+ end
19
+ end
20
+ end
data/lib/svp/p4.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'socket'
2
+
3
+ module Svp
4
+ class P4
5
+ def self.execute(depot_uri, local_dir, &block)
6
+ p4 = P4.new(depot_uri, local_dir)
7
+ p4.create_client
8
+ begin
9
+ yield p4
10
+ ensure
11
+ p4.delete_client
12
+ end
13
+ end
14
+
15
+ def initialize(depot_uri, local_dir)
16
+ @depot_uri, @local_dir = depot_uri, local_dir
17
+ @client_name = "tmp_#{Socket.gethostname}"
18
+ end
19
+
20
+ def success?
21
+ @success
22
+ end
23
+
24
+ def create_client
25
+ execute("client -i", <<-EOS)
26
+ Client: #{@client_name}
27
+ Owner: #{@depot_uri.user}
28
+ Root: #{@local_dir}
29
+ Options: allwrite noclobber compress unlocked nomodtime rmdir
30
+ LineEnd: share
31
+ View:
32
+ #{@depot_uri.path}/... //#{@client_name}/...
33
+ EOS
34
+ end
35
+
36
+ def delete_client
37
+ execute("client -d #{@client_name}")
38
+ end
39
+
40
+ def method_missing(name, *args, &block)
41
+ execute("#{name.to_s} #{args.join(' ')}")
42
+ end
43
+
44
+ private
45
+
46
+ def execute(command, input = nil)
47
+ @success = false
48
+ begin
49
+ if input
50
+ print command
51
+ print "<"
52
+ print input
53
+ IO.popen(command_line(command), 'r+') { |io| io.puts input; io.close_write; io.read }
54
+ else
55
+ puts command
56
+ IO.popen(command_line(command)) { |io| io.read }
57
+ end
58
+ ensure
59
+ @success = $?.success?
60
+ end
61
+ end
62
+
63
+ def command_line(args)
64
+ "p4 -u #{@depot_uri.user} -H #{@depot_uri.host} -p #{@depot_uri.port} -c #{@client_name} #{args}"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,9 @@
1
+ module Svp #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,116 @@
1
+ require 'fileutils'
2
+ require 'svp/add'
3
+ require 'svp/delete'
4
+ require 'svp/modify'
5
+ require 'svp/p4'
6
+
7
+ module Svp
8
+ class Workspace
9
+ attr_reader :revision
10
+
11
+ def initialize(depot_uri, work_dir, svp_dir, revision)
12
+ @depot_uri = depot_uri
13
+ @work_dir = work_dir
14
+ @svp_dir = svp_dir
15
+ @revision = revision
16
+ @base_dir = File.join(@svp_dir, "base")
17
+
18
+ FileUtils.mkdir_p(@work_dir)
19
+ FileUtils.mkdir_p(@base_dir)
20
+ end
21
+
22
+ def commit(*paths)
23
+ changes = changes(paths)
24
+ remote_exec do |p4|
25
+ changes.each { |change| change.prepare_to_commit(p4) }
26
+ p4.submit
27
+ method = p4.success ? :commit : :rollback
28
+ changes.each { |change| change.send(method, p4) }
29
+ end
30
+ end
31
+
32
+ def delete(*files)
33
+ files.each do |file|
34
+ puts "D\t#{file}"
35
+ FileUtils.rm_rf(file)
36
+ end
37
+ end
38
+
39
+ def diff(*paths)
40
+ changes(paths).each { |change| change.diff }
41
+ end
42
+
43
+ def info(*remove_me)
44
+ puts "Depot URL: #{@depot_uri}"
45
+ puts "Working Directory: #{@work_dir}"
46
+ puts "Working Revision: #{@revision}"
47
+ end
48
+
49
+ def revert(*paths)
50
+ changes(paths).each { |change| change.revert }
51
+ end
52
+
53
+ def status(*paths)
54
+ changes(paths).each do |change|
55
+ change.status
56
+ end
57
+ puts "At revision #{@revision}."
58
+ end
59
+
60
+ def update(*remove_me)
61
+ # raise "Local changes may cause conflicts" if !changes.empty?
62
+
63
+ remote_exec do |p4|
64
+ p4.changes("-m 1").scan(/^Change (\d+) on/) do |revision|
65
+ revision = revision.first.to_i
66
+ if @revision < revision
67
+ puts "Updating changes from revision #{@revision} to #{revision}"
68
+ p4.sync("@#{@revision.next},@#{revision}")
69
+ changes.each { |change| change.commit(p4) }
70
+ @revision = revision
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def remote_exec(&block)
79
+ P4.execute(@depot_uri, @work_dir) { |p4| yield p4 }
80
+ end
81
+
82
+ def changes(paths = [""])
83
+ changes = []
84
+
85
+ paths.each do |path|
86
+ base_path = File.expand_path(File.join(@base_dir, path))
87
+ work_path = File.expand_path(File.join(@work_dir, path))
88
+
89
+ `diff -Nqr #{base_path} #{work_path}`.each_line do |line|
90
+ next unless line =~ /^Files (.*?) and (.*?) differ$/
91
+
92
+ base_file = $1
93
+ work_file = $2
94
+
95
+ next if ignored?(work_file)
96
+
97
+ change = if !File.exist?(base_file)
98
+ Add
99
+ elsif !File.exist?(work_file)
100
+ Delete
101
+ else
102
+ Modify
103
+ end
104
+
105
+ changes << change.new(work_file, base_file)
106
+ end
107
+ end
108
+
109
+ changes
110
+ end
111
+
112
+ def ignored?(file)
113
+ file =~ /^#{@svp_dir}/
114
+ end
115
+ end
116
+ end
data/test/all_tests.rb ADDED
@@ -0,0 +1 @@
1
+ Dir['**/*_test.rb'].each { |test_case| require test_case }
data/test/svp_test.rb ADDED
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class SvpTest < Test::Unit::TestCase
4
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/svp'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: svp
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2006-10-18 00:00:00 +10:00
8
+ summary: description of gem
9
+ require_paths:
10
+ - lib
11
+ email: support@redhillconsulting.com.au
12
+ homepage: http://svp.rubyforge.org
13
+ rubyforge_project:
14
+ description: description of gem
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Simon Harris
31
+ files:
32
+ - README
33
+ - CHANGELOG
34
+ - Rakefile
35
+ - bin/svp
36
+ - test/all_tests.rb
37
+ - test/svp_test.rb
38
+ - test/test_helper.rb
39
+ - lib/svp
40
+ - lib/svp/add.rb
41
+ - lib/svp/change.rb
42
+ - lib/svp/cli.rb
43
+ - lib/svp/delete.rb
44
+ - lib/svp/modify.rb
45
+ - lib/svp/p4.rb
46
+ - lib/svp/version.rb
47
+ - lib/svp/workspace.rb
48
+ test_files: []
49
+
50
+ rdoc_options:
51
+ - --quiet
52
+ - --title
53
+ - svp documentation
54
+ - --opname
55
+ - index.html
56
+ - --line-numbers
57
+ - --main
58
+ - README
59
+ - --inline-source
60
+ - --exclude
61
+ - ^(examples|extras)/
62
+ extra_rdoc_files:
63
+ - README
64
+ - CHANGELOG
65
+ executables:
66
+ - svp
67
+ extensions: []
68
+
69
+ requirements: []
70
+
71
+ dependencies: []
72
+