Permalink
Browse files

First commit

  • Loading branch information...
1 parent 5e2dd99 commit edac1e44310c90915e855babf570b8760afeaab1 @winton committed Jul 1, 2012
View
@@ -15,4 +15,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,36 +1,47 @@
-GemTemplate
-===========
+Change
+======
-A gem template for new projects.
+What files changed since last time?
+
+With dependency management and super fast hashing ([Murmur3](https://github.com/PeterScott/murmur3)).
Requirements
------------
-<pre>
-gem install stencil
-</pre>
+ gem install change
+
+Changed?
+--------
+
+ @change = Change.new("/absolute/path")
+ @change.d?("relative/path")
-Setup the template
-------------------
+`Change` uses a YAML file stored in the root directory called `.change.yml` to maintain state.
-You only have to do this once.
+Calling `@change.d?` does the following:
+
+* Check if there is an entry for path in `.change.yml`
+ * If yes, read file size and compare with entry
+ * If file size matches, compare Murmur hash
+ * If no, record file size and Murmur hash
+* Look up path in dependency tree
+ * If found, also mark all dependency parent paths as changed
+
+Dependencies
+------------
-<pre>
-git clone git@github.com:winton/gem_template.git
-cd gem_template
-stencil
-</pre>
+Sometimes you want to say "if this file changes, then these other files should change as well".
-Setup a new project
--------------------
+ @change = Change.new("/absolute/path")
+ @change.d(:some_id) # set id (must be symbol)
+ @change.d("relative/path") # add dependency
+ @change.d(null) # unset id (must run this when finished)
-Do this for every new project.
+If you use `@change.d?` after an id is set, it will return true if any dependencies from the last execution changed.
-<pre>
-mkdir my_project
-git init
-stencil gem_template
-rake rename
-</pre>
+Tell `Change` to record which files were modified while an id was set during last execution:
-The last command does a find-replace (gem\_template -> my\_project) on files and filenames.
+ @change = Change.new("/absolute/path", :record => true)
+ @change.d(:some_id) # set id (must be symbol)
+ @change.d # modified files from last session (hash)
+ @change.d(null) # unset id (must run this when finished)
View
@@ -1,27 +1 @@
-require 'bundler/gem_tasks'
-
-# DELETE AFTER USING
-desc "Rename project"
-task :rename do
- name = ENV['NAME'] || File.basename(Dir.pwd)
- camelize = lambda do |str|
- str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
- end
- dir = Dir['**/gem_template*']
- begin
- from = dir.pop
- if from
- to = from.split('/')
- to[-1].gsub!('gem_template', name)
- FileUtils.mv(from, to.join('/'))
- end
- end while dir.length > 0
- Dir["**/*"].each do |path|
- if File.file?(path)
- `sed -i '' 's/gem_template/#{name}/g' #{path}`
- `sed -i '' 's/GemTemplate/#{camelize.call(name)}/g' #{path}`
- no_space = File.read(path).gsub(/\s+\z/, '')
- File.open(path, 'w') { |f| f.write(no_space) }
- end
- end
-end
+require 'bundler/gem_tasks'
View
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+require File.expand_path("../../lib/change", __FILE__)
View
@@ -1,3 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.expand_path("../../lib/gem_template", __FILE__)
@@ -5,7 +5,7 @@ lib = "#{root}/lib"
$:.unshift lib unless $:.include?(lib)
Gem::Specification.new do |s|
- s.name = "gem_template"
+ s.name = "change"
s.version = '0.1.0'
s.platform = Gem::Platform::RUBY
s.authors = []
@@ -15,9 +15,11 @@ Gem::Specification.new do |s|
s.description = %q{}
s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
+ s.extensions = [ 'ext/change/extconf.rb' ]
s.files = `cd #{root} && git ls-files`.split("\n")
s.require_paths = %w(lib)
s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
+ s.add_development_dependency "rake"
s.add_development_dependency "rspec", "~> 1.0"
end
View
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include "murmur3.h"
+
+int main(int argc, char **argv) {
+ uint32_t hash[4]; /* Output for the hash */
+ uint32_t seed = 42; /* Seed value for hash */
+ char *buffer;
+
+ if (argc != 2) {
+ printf("usage: %s \"path\"\n", argv[0]);
+ exit(1);
+ }
+
+ FILE *fh = fopen(argv[1], "rb");
+
+ if (fh != NULL) {
+ fseek(fh, 0L, SEEK_END);
+ long s = ftell(fh);
+ buffer = malloc(s);
+
+ rewind(fh);
+
+ if (buffer != NULL) {
+ fread(buffer, s, 1, fh);
+ fclose(fh); fh = NULL;
+
+ MurmurHash3_x86_32(buffer, strlen(buffer), seed, hash);
+ printf("%08u\n", hash[0]);
+
+ free(buffer);
+ }
+ if (fh != NULL) fclose(fh);
+ }
+
+ return 0;
+}
View
@@ -0,0 +1,4 @@
+CFLAGS = -O2 -Wall
+
+all: change
+change: change.o murmur3.o
Oops, something went wrong.

0 comments on commit edac1e4

Please sign in to comment.