summaryrefslogtreecommitdiff
path: root/rake_tasks
diff options
context:
space:
mode:
authormurphy <murphy@rubychan.de>2008-08-11 12:29:56 +0000
committermurphy <murphy@rubychan.de>2008-08-11 12:29:56 +0000
commitaaa083a84614e229021a4f75e5707077816dd5f9 (patch)
treea7a3eea4a688a4cc4ed157daa503843aaae64a11 /rake_tasks
parent13fba921998464920d06fc7f014a7e6589d83d6c (diff)
downloadcoderay-aaa083a84614e229021a4f75e5707077816dd5f9.tar.gz
Added diff task and a Redmine TODO.
Diffstat (limited to 'rake_tasks')
-rw-r--r--rake_tasks/diff.rake86
1 files changed, 86 insertions, 0 deletions
diff --git a/rake_tasks/diff.rake b/rake_tasks/diff.rake
new file mode 100644
index 0000000..9cd67b9
--- /dev/null
+++ b/rake_tasks/diff.rake
@@ -0,0 +1,86 @@
+# A simple differ using svn. Handles externals.
+class Differ < Hash
+
+ def initialize path
+ @path = path
+ super 0
+ end
+
+ def count key, value
+ self[key] += value
+ value
+ end
+
+ FORMAT = ' %-30s %8d lines, %3d changes in %2d files'
+
+ def scan(path = @path)
+ Dir.chdir path do
+ system 'svn diff > diff'
+ if File.size? 'diff'
+ puts FORMAT %
+ [
+ path,
+ count(:LOC, `wc -l diff`.to_i),
+ count(:changes, `grep ^@@ diff | wc -l`.to_i),
+ count(:files, `grep ^Index diff | wc -l`.to_i),
+ ]
+ else
+ rm 'diff'
+ end
+ end
+ end
+
+ def scan_with_externals(path = @path)
+ scan path
+ `svn status`.scan(/^X\s*(.*)/) do |external,|
+ scan external
+ end
+ end
+
+ def clean(path = @path)
+ Dir.chdir path do
+ rm 'diff' if File.exist? 'diff'
+ end
+ end
+
+ def clean_with_externals(path = @path)
+ clean path
+ `svn status`.scan(/^X\s*(.*)/) do |external,|
+ clean external
+ end
+ end
+
+ def differences?
+ self[:LOC] > 0
+ end
+
+ def inspect
+ FORMAT %
+ [ 'Total', self[:LOC], self[:changes], self[:files] ]
+ end
+
+end
+
+namespace :diff do
+
+ desc 'Make a diff and print a summary'
+ task :summary do
+ differ = Differ.new '.'
+ differ.scan_with_externals
+ if differ.empty?
+ puts 'No differences found.'
+ else
+ p differ
+ end
+ end
+
+ desc 'Remove all diffs'
+ task :clean do
+ differ = Differ.new '.'
+ differ.clean_with_externals
+ end
+
+end
+
+desc 'Make a diff and print a summary'
+task :diff => 'diff:summary'