git-meta 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ repos
data/README.md CHANGED
@@ -11,33 +11,45 @@ It is also completely compatible for people wanting to read this metadata direct
11
11
  Syntax
12
12
  ------
13
13
 
14
- In your git commit, you just need a section that looks something like the following:
14
+ In your git commit, you just need a few yaml-like structures like the following:
15
15
 
16
- ---git-meta---
17
- foo:
18
- bar: "baz"
19
- ---git-meta---
16
+ foo: bar
17
+ Signed-Off-By: Me!
20
18
 
21
- This is a YAML formatted block. Currently the only way of setting this metadata is writing the YAML by hand in the commit message.
19
+ Currently the only way of setting this metadata is writing the YAML by hand in the commit message. The Regex that i use (no longer a YAML parser for simplification) will catch all non-whitespace before each colon and the rest of the line afterwards.
20
+
21
+ The change where I have removed YAML means that we can no longer have hierarchal data structures, which both makes it easier to use with small amounts of data but harder to use with larger amounts of data.
22
+
23
+ If you want to re-implement this in another language, I ask that you please use the following regular expression to parse the git messages (we make a call to the `git-cat-file` utility to get the messages):
24
+
25
+ /(\S+):\s*(.+)$/
22
26
 
23
27
  Usage
24
28
  =====
25
29
 
26
- Querying
27
- --------
30
+ Getting
31
+ -------
28
32
 
29
- You can use `git-meta [sha|ref] --get-all` to return just the YAML-block.
33
+ You can use `git-meta get [ sha | ref ]` to return all keys and values. `[ sha | ref ]` can be anything that `git-cat-file` will understand.
30
34
 
31
- You can also use `git-meta [sha|ref] --get foo.bar` to return "baz" from the earlier example. Will return an empty string if nothing is returned for that piece of metadata.
35
+ You can also use `git-meta get [ sha | ref ] --get foo` to return "bar" from the earlier example. Will return an empty string if nothing is returned for that piece of metadata.
32
36
 
33
- If you were to specify just `--get foo` then the underlying YAML would be returned (in this case `bar: "baz"`).
37
+ I am aware that this is open to shenanigans including something like `git-meta get 'HEAD && echo "foo: baz"'` but really, I don't care. I don't foresee this being used anywhere that would be a problem - ie i guess it will mostly be used by a person wanting the data, or a computer processing the data with other values like commit shas or refs that it has deduced itself.
34
38
 
35
- Storing
39
+ Setting
36
40
  -------
37
41
 
38
- I have not yet got this sorted. I need to think a bit more about this.
42
+ I have not yet got this sorted. A solution will be forthcoming in a compatible release, but at the moment i have not yet thought enough about how it's going to be implemented.
43
+
44
+ Installation
45
+ ============
46
+
47
+ As easy as `gem install git-meta` (as long as you have gemcutter as a source)
48
+
49
+ Requirements
50
+ ============
39
51
 
40
- I originally thought i could use `./.git/COMMIT\_EDIT\_MSG` but it turns out that is overwritten just before every commit. Whack me an email or a github message if you want to help with this feature, or have an idea for implementation.
52
+ Only `shoulda` and `mocra` for testing. I have tried to keep this as lean as possible.
41
53
 
42
54
  Copyright
43
55
  ---------
data/Rakefile CHANGED
@@ -1,5 +1,19 @@
1
- require 'rubygems'
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ # meh
5
+ end
2
6
  require 'rake'
7
+ require 'rake/testtask'
8
+
9
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/lib")
10
+ require 'git_meta'
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.libs << 'lib'
14
+ t.pattern = 'test/test_*.rb'
15
+ t.verbose = false
16
+ end
3
17
 
4
18
  begin
5
19
  require 'jeweler'
@@ -14,6 +28,10 @@ This gem allows reading this data.}
14
28
  gem.email = "sam@lenary.co.uk"
15
29
  gem.homepage = "http://github.com/lenary/git-meta"
16
30
  gem.authors = ["Sam Elliott"]
31
+ gem.version = GitMeta::VERSION
32
+ gem.add_development_dependency "shoulda", "~>2.10.2"
33
+ gem.add_development_dependency "mocha", "~>0.9.8"
34
+ # these are the two versions i have been testing with.
17
35
  end
18
36
  Jeweler::GemcutterTasks.new
19
37
  rescue LoadError
@@ -2,19 +2,17 @@
2
2
 
3
3
  require 'optparse'
4
4
 
5
- options = {:all => false, :sha => ARGV.shift}
5
+ $:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
6
+ require 'git_meta'
7
+
8
+ options = {:command => ARGV.shift || "get", :sha => ARGV.shift, :key => nil}
6
9
 
7
10
  optparser = OptionParser.new do |parser|
8
- parser.banner = "Usage: git-meta [sha|ref] [ --get | --get-all ]"
9
-
10
- parser.on('-a', '--get-all',
11
- "Retrieves all the keys as YAML data.") do |all|
12
- options[:all] = all
13
- end
11
+ parser.banner = "Usage: git-meta get [ sha | ref ] [ --get KEY ]"
14
12
 
15
13
  parser.on('-g', '--get KEY',
16
14
  "Retrives a certain KEY from the git commit object") do |key|
17
- options[:keys] = key.split(".")
15
+ options[:key] = key
18
16
  end
19
17
 
20
18
  parser.on('-h', '--help',
@@ -32,20 +30,5 @@ end
32
30
 
33
31
  optparser.parse(ARGV)
34
32
 
35
- git_commit_info, data, output = nil, nil, nil
36
-
37
- IO.popen("git-cat-file -p #{options[:sha]}", 'r') do |git_cat_file|
38
- git_commit_info = git_cat_file.read
39
- end
40
-
41
- if git_commit_info =~ /^(---git-meta---\s*\n)(.*\n)(^---git-meta---.*\n)/m
42
- if options[:keys]
43
- data = YAML.load($2)
44
- options[:keys].each do |key|
45
- data = data.fetch(key, Hash.new(""))
46
- end
47
- puts data.to_yaml.gsub(/^--- \n?/, '')
48
- elsif options[:all]
49
- puts $2
50
- end
51
- end
33
+ @getter = GitMeta::Get.new(options[:sha], options[:key])
34
+ puts @getter
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{git-meta}
8
+ s.version = "2.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sam Elliott"]
12
+ s.date = %q{2010-02-13}
13
+ s.default_executable = %q{git-meta}
14
+ s.description = %q{It's a way to store data along with a git commit object that is less freeform than something like "Close gh-11" but more freeform than having to add extra data structures to the git commit object.
15
+
16
+ It is also completely compatible for people wanting to read this metadata directly from an interface like git-log or github.
17
+
18
+ This gem allows reading this data.}
19
+ s.email = %q{sam@lenary.co.uk}
20
+ s.executables = ["git-meta"]
21
+ s.extra_rdoc_files = [
22
+ "LICENSE",
23
+ "README.md"
24
+ ]
25
+ s.files = [
26
+ ".gitignore",
27
+ "LICENSE",
28
+ "README.md",
29
+ "Rakefile",
30
+ "bin/git-meta",
31
+ "git-meta.gemspec",
32
+ "lib/git_meta.rb",
33
+ "test/test_git_meta.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/lenary/git-meta}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{A less than freeform way of storing some metadata in git commit objects.}
40
+ s.test_files = [
41
+ "test/test_git_meta.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<shoulda>, ["~> 2.10.2"])
50
+ s.add_development_dependency(%q<mocha>, ["~> 0.9.8"])
51
+ else
52
+ s.add_dependency(%q<shoulda>, ["~> 2.10.2"])
53
+ s.add_dependency(%q<mocha>, ["~> 0.9.8"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<shoulda>, ["~> 2.10.2"])
57
+ s.add_dependency(%q<mocha>, ["~> 0.9.8"])
58
+ end
59
+ end
60
+
@@ -0,0 +1,51 @@
1
+ module GitMeta
2
+
3
+ VERSION = "2.0.0"
4
+
5
+ class Scanner
6
+
7
+ attr_accessor :info
8
+
9
+ REGEX = /(\S+):\s*(.+)$/
10
+
11
+ def initialize(text)
12
+ self.info = Hash.new("")
13
+ text.scan(REGEX) do |k,v|
14
+ self.info[k] = v
15
+ end
16
+ end
17
+
18
+ def ==(comrade)
19
+ info == comrade.info
20
+ end
21
+
22
+ end
23
+
24
+ class Hash < ::Hash
25
+
26
+ def to_s
27
+ inject("") do |result, hash|
28
+ result += "#{hash[0]}: #{hash[1]}\n"
29
+ # hash is an array of schema [key, value]
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ class Get
36
+ attr_accessor :scanner, :key
37
+ def initialize(sha, key=nil)
38
+ output = IO.popen("git-cat-file -p #{sha}", 'r') do |git_cat_file|
39
+ git_cat_file.read
40
+ end
41
+ self.scanner = Scanner.new(output)
42
+ self.key = key
43
+ end
44
+
45
+ def to_s
46
+ key ? @scanner.info[key] : @scanner.info.to_s
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,82 @@
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ # meh
5
+ end
6
+ require 'shoulda'
7
+ require 'mocha'
8
+ require 'git_meta'
9
+
10
+ class GitMetaTest < Test::Unit::TestCase
11
+ context "A Scanner instance" do
12
+ should "parse the data" do
13
+ scanner = GitMeta::Scanner.new("\nfoo: bar\nfuzz: bazz\n")
14
+ expected = {"foo"=> "bar", "fuzz"=> "bazz"}
15
+ assert_equal expected, scanner.info
16
+ end
17
+
18
+ should "accept hypens in the keys" do
19
+ scanner = GitMeta::Scanner.new("\nhi-there: you\nfoo: bar\n")
20
+ expected = {"hi-there" => "you", "foo" => "bar"}
21
+ assert_equal expected, scanner.info
22
+ end
23
+
24
+ should "accept whitespace in the values" do
25
+ scanner = GitMeta::Scanner.new("\nSigned-off-by: José Valim <jose.valim@gmail.com>\nfoo: bear\n")
26
+ expected = {"Signed-off-by" => "José Valim <jose.valim@gmail.com>", "foo" => "bear"}
27
+ assert_equal expected, scanner.info
28
+ end
29
+
30
+ should "play nice with comrades" do
31
+ scanner = GitMeta::Scanner.new("\nhi-there: you\nfoo: bar\n")
32
+ other_scanner = GitMeta::Scanner.new("\nhi-there: you\nfoo: bar\n")
33
+ assert_equal scanner, other_scanner
34
+ end
35
+ end
36
+
37
+ context "A Get instance" do
38
+ setup do
39
+ @cat_file = <<-FOO
40
+ tree 0b31db52b0f96659a93dee8c5c7a1f8a95f0bb2b
41
+ parent e033a2271fa3c59ae2c8b30f4b5ef8eb83e739db
42
+ author Sam Elliott <sam@lenary.co.uk> 1266027667 +0100
43
+ committer Sam Elliott <sam@lenary.co.uk> 1266027667 +0100
44
+
45
+ foo: bar
46
+ Signed-Off-By: Me!
47
+ FOO
48
+ IO.expects(:popen).with("git-cat-file -p HEAD", 'r').returns(@cat_file).at_least_once
49
+ end
50
+
51
+ should "initialize correctly without key" do
52
+ @getter = GitMeta::Get.new("HEAD", nil)
53
+ assert_nil @getter.key
54
+ assert_equal @getter.scanner, GitMeta::Scanner.new(@cat_file)
55
+ end
56
+
57
+ should "initialize correctly with a key" do
58
+ @getter = GitMeta::Get.new("HEAD", "foo")
59
+ assert_equal @getter.key, "foo"
60
+ assert_equal @getter.scanner, GitMeta::Scanner.new(@cat_file)
61
+ end
62
+
63
+ should "display itself nicely" do
64
+ @getter = GitMeta::Get.new("HEAD", "foo")
65
+ assert_equal @getter.to_s, "bar"
66
+ long_expectation = "foo: bar\nSigned-Off-By: Me!\n"
67
+ @getter = GitMeta::Get.new("HEAD", nil)
68
+ assert_equal @getter.to_s, long_expectation
69
+ end
70
+ end
71
+
72
+ context "A Hash instance" do
73
+ should "print correctly" do
74
+ hash = GitMeta::Hash.new
75
+ hash["foo"] = "bar"
76
+ hash["fuzz"] = "bazz"
77
+
78
+ expected = "foo: bar\nfuzz: bazz\n"
79
+ assert_equal expected, hash.to_s
80
+ end
81
+ end
82
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Elliott
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-15 00:00:00 +01:00
12
+ date: 2010-02-13 00:00:00 +01:00
13
13
  default_executable: git-meta
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.10.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.8
34
+ version:
16
35
  description: |-
17
36
  It's a way to store data along with a git commit object that is less freeform than something like "Close gh-11" but more freeform than having to add extra data structures to the git commit object.
18
37
 
@@ -32,8 +51,10 @@ files:
32
51
  - LICENSE
33
52
  - README.md
34
53
  - Rakefile
35
- - VERSION
36
54
  - bin/git-meta
55
+ - git-meta.gemspec
56
+ - lib/git_meta.rb
57
+ - test/test_git_meta.rb
37
58
  has_rdoc: true
38
59
  homepage: http://github.com/lenary/git-meta
39
60
  licenses: []
@@ -62,5 +83,5 @@ rubygems_version: 1.3.5
62
83
  signing_key:
63
84
  specification_version: 3
64
85
  summary: A less than freeform way of storing some metadata in git commit objects.
65
- test_files: []
66
-
86
+ test_files:
87
+ - test/test_git_meta.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.0