Commit df6f410f5e3b5402a969cb87b96859f029a64014

New Piston::WorkingCopy#log. Required renaming Piston::SubversionClient#log to #debug.

git-svn-id: svn+ssh://rubyforge.org/var/svn/piston/trunk@130 d6c2ea82-c31b-0410-8381-e9c44f9824c5

Commit diff

lib/piston/repository.rb

 
8080 # Uses svnadmin to create a repository if this repository's is a file: URL.
8181 def create!
8282 raise NoCreateOnRemoteRepositoryUrl.new(self.url) unless self.url =~ %r{\Afile://}
83 log {"Want to create repository at #{self.local_path.inspect}"}
83 debug {"Want to create repository at #{self.local_path.inspect}"}
8484 repos_parent_dir = File.expand_path(self.local_path + "/..")
8585
8686 FileUtils.mkdir_p(repos_parent_dir)
toggle raw diff

lib/piston/subversion_client.rb

 
1515 run_cmd :svn, *args
1616 end
1717
18 def log(&block)
18 def debug(&block)
1919 @logger.debug(&block) if logger
2020 end
2121
2424 args.collect! {|arg| arg =~ /\s|\*|\?|"|\n|\r/ ? %Q('#{arg}') : arg}
2525 args.collect! {|arg| arg ? arg : '""'}
2626 cmd = %Q|#{executable} #{args.join(' ')}|
27 log {cmd}
27 debug {cmd}
2828 ENV["LANGUAGE"] = "C"
2929 value = run_real(cmd)
30 log {value} unless (value || "").strip.empty?
30 debug {value} unless (value || "").strip.empty?
3131 value
3232 end
3333
toggle raw diff

lib/piston/working_copy.rb

 
22require "fileutils"
33require "pathname"
44require "yaml"
5require "rexml/document"
6require "rexml/xpath"
57
68module Piston
79 # Represents a Subversion working copy.
7373 props = Hash.new
7474 propname = nil
7575 svn(:proplist, "--verbose", wc_path(target)).each_line do |line|
76 log {"==> #{line.inspect}"}
76 debug {"==> #{line.inspect}"}
7777 case line
7878 when /\AProperties on/
7979 # NOP, skip
80 log {"\tProperties on..."}
80 debug {"\tProperties on..."}
8181 when /\A\s\s(.+?)\s:\s(.*)\Z/
8282 props[propname = $1] = $2
83 log {"\tNew property"}
83 debug {"\tNew property"}
8484 when /\A(.*)\Z/
8585 props[propname] += "\n" + $1
86 log {"\tAppend"}
86 debug {"\tAppend"}
8787 end
8888 end
8989
9090 props
9191 end
9292
93 def log(revision)
94 revision = "#{revision.first}:#{revision.last}" if revision.respond_to?(:last)
95 xml = svn(:log, "--verbose", "--revision", revision, "--xml", self.path)
96 doc = REXML::Document.new(xml)
97 changes = {}
98 REXML::XPath.each(doc.root, "/log/logentry/paths/path") do |path|
99 debug {changes.to_yaml}
100 debug {path.inspect}
101
102 file = path.text[1..-1]
103 case path.attributes["action"]
104 when "A"
105 if path.attributes["copyfrom-path"] then
106 copy_file = path.attributes["copyfrom-path"][1..-1]
107 if changes[copy_file] == :delete then
108 changes[copy_file] = [:move, file]
109 else
110 changes[copy_file] = [:copy, file]
111 end
112 else
113 changes[file] = :add
114 end
115 when "M"
116 changes[file] = :modify unless changes[file]
117 when "D"
118 changes[file] = :delete
119 end
120 end
121
122 debug {changes.to_yaml}
123 changes.map do |file, op|
124 case op
125 when Array
126 [op.first, {file => op.last}]
127 else
128 [op, file]
129 end
130 end
131 end
132
93133 def add(*targets)
94134 svn :add, *targets.flatten.map {|file| wc_path(file)}
95135 end
148148 svn :move, wc_path(from), wc_path(to)
149149 end
150150
151 def copy(from, to)
151 def copy(from, to, options={})
152152 svn :copy, wc_path(from), wc_path(to)
153153 end
154154
205205
206206 # Replaces the contents of the named file with +content+.
207207 def edit!(filename, content=nil) #:nodoc:
208 log {"Editing #{filename} with #{(content || '').size} bytes"}
208 debug {"Editing #{filename} with #{(content || '').size} bytes"}
209209 File.open(wc_path(filename), "wb") {|file| file.print content}
210210 end
211211
toggle raw diff

spec/spec_helper.rb

 
11require "spec"
22require "logger"
3require "piston"
34require "piston/repository"
45require "piston/working_copy"
56
67$logger = Logger.new($stderr)
7$logger.level = Logger::INFO unless $DEBUG
8#$logger.level = Logger::INFO unless $DEBUG
89
910module Piston
1011 module SpecHelpers
toggle raw diff

spec/working_copy_spec.rb

 
1919 end
2020end
2121
22describe Piston::WorkingCopy, "#log" do
23 it_should_behave_like "A working copy against a local repository"
24
25 before do
26 @wc.checkout(@repos.url)
27 @wc.create!("main.c", "")
28 @wc.commit
29 @wc.edit!("main.c", "one line")
30 @wc.commit
31 @wc.delete("main.c")
32 @wc.commit
33 @wc.create!("main.c", "")
34 @wc.commit
35 @wc.copy("main.c", "calc.c")
36 @wc.commit
37 @wc.move("calc.c", "libcalc.c")
38 @wc.commit
39 end
40
41 it "should report adding main.c in r1" do
42 @wc.log(1).should == [[:add, "main.c"]]
43 end
44
45 it "should report modifying main.c in r2" do
46 @wc.log(2).should == [[:modify, "main.c"]]
47 end
48
49 it "should report deleting main.c in r3" do
50 @wc.log(3).should == [[:delete, "main.c"]]
51 end
52
53 it "should report copying main.c to calc.c in r5" do
54 @wc.log(5).should == [[:copy, {"main.c" => "calc.c"}]]
55 end
56
57 it "should report moving calc.c to libcalc.c in r6" do
58 @wc.log(6).should == [[:move, {"calc.c" => "libcalc.c"}]]
59 end
60
61 it "should report only an add for A+M in revision range" do
62 @wc.log(0..2).should == [[:add, "main.c"]]
63 end
64
65 it "should report only a delete from M+D in revision range" do
66 @wc.log(1..3).should == [[:delete, "main.c"]]
67 end
68
69 it "should report only a delete from A+M+D in revision range" do
70 @wc.log(0..3).should == [[:delete, "main.c"]]
71 end
72
73 it "should report only a delete from A+M+D in revision range" do
74 @wc.log(4..6).should == [[:add, "main.c"], [:copy, {"main.c"=>"calc.c"}], [:move, {"calc.c"=>"libcalc.c"}]]
75 end
76
77 it "should report paths relative to the current working copy, not absolute from the repository's root"
78end
79
2280describe Piston::WorkingCopy do
2381 it_should_behave_like "A working copy against a local repository"
2482
198198
199199 before do
200200 @wc.checkout @repos.url
201 File.open(File.join(@wc.dir, "main.c"), "wb") {|f| f.puts "int main(int argc, char** argv) {\n return 0;\n\n}"}
202 @wc.add "main.c"
201 @wc.create!("main.c", "int main(int argc, char** argv) {\n return 0;\n\n}")
203202 @wc.commit
204203 end
205204
toggle raw diff