minecraft-merge 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ gem "nbtfile", ">= 0.2.0"
14
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 MenTaLguY <mental@rydia.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = minecraft-merge
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to minecraft-merge
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 MenTaLguY. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "minecraft-merge"
16
+ gem.homepage = "http://github.com/mental/minecraft-merge"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A git merge driver for minecraft worlds}
19
+ gem.description = %Q{A git merge driver for minecraft worlds}
20
+ gem.email = "mental@rydia.net"
21
+ gem.authors = ["MenTaLguY"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_runtime_dependency 'nbtfile', '>= 0.2.0'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "minecraft-merge #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'minecraft-merge'
4
+
5
+ exit(MinecraftMerge.main(*ARGV))
@@ -0,0 +1,153 @@
1
+ # minecraft-merge
2
+ #
3
+ # Copyright (c) 2011 MenTaLguY <mental@rydia.net>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ require 'optparse'
25
+ require 'fileutils'
26
+ require 'nbtfile'
27
+ require 'stringio'
28
+ require 'zlib'
29
+
30
+ module MinecraftMerge
31
+
32
+ module Main
33
+ extend self
34
+
35
+ GZIP_MAGIC = "\x1f\x8b"
36
+
37
+ def main(*args)
38
+ parser = OptionParser.new do |opts|
39
+ end
40
+ parser.banner = "Usage: #{parser.program_name} merge ORIG OURS THEIRS\n" +
41
+ " #{parser.program_name} setup [REPOSITORY]\n"
42
+ parser.parse!(args)
43
+
44
+ if args.empty?
45
+ parser.warn("No subcommand given")
46
+ return 1
47
+ end
48
+ subcommand = args.shift
49
+
50
+ case subcommand
51
+ when 'merge'
52
+ if args.length != 3
53
+ parser.warn("Wrong number of arguments for merge (3 required)")
54
+ return 1
55
+ end
56
+ do_merge(*args)
57
+
58
+ when 'install'
59
+ if args.length > 0
60
+ parser.warn("Wrong number of arguments for install (0 needed)")
61
+ return 1
62
+ end
63
+
64
+ unless system "git", "config", "--global", "merge.minecraft.name", "Minecraft merge driver" and
65
+ system "git", "config", "--global", "merge.minecraft.driver", "minecraft-merge merge %O %A %B" and
66
+ system "git", "config", "--global", "filter.minecraft.clean", "minecraft-merge decompress" and
67
+ system "git", "config", "--global", "filter.minecraft.smudge", "minecraft-merge compress"
68
+ return 1
69
+ end
70
+
71
+ when 'setup'
72
+ if args.length > 1
73
+ parser.warn("Wrong number of arguments for setup (1 optional)")
74
+ return 1
75
+ end
76
+
77
+ work_dir = args[0] || Dir.pwd
78
+ Dir.chdir work_dir
79
+
80
+ File.open(".gitignore", "w+") do |s|
81
+ s.puts "session.lock"
82
+ s.puts "level.dat_old"
83
+ end
84
+
85
+ File.open(".gitattributes", "w+") do |s|
86
+ s.puts "*.dat binary -delta merge=minecraft"
87
+ end
88
+
89
+ unless system "git", "add", ".gitignore", ".gitattributes" and
90
+ system "git", "commit", "-m", "set up attributes"
91
+ return 1
92
+ end
93
+
94
+ when 'compress'
95
+ data = $stdin.read
96
+ if data[0, GZIP_MAGIC.length] == GZIP_MAGIC
97
+ $stdout.write data
98
+ $stdout.flush
99
+ else
100
+ writer = Zlib::GzipWriter.new($stdout)
101
+ writer.write data
102
+ writer.close
103
+ end
104
+
105
+ when 'decompress'
106
+ data = $stdin.read
107
+ if data[0, GZIP_MAGIC.length] == GZIP_MAGIC
108
+ reader = Zlib::GzipReader.new(StringIO.new(data))
109
+ $stdout.write reader.read
110
+ reader.close
111
+ $stdout.flush
112
+ else
113
+ $stdout.write data
114
+ $stdout.flush
115
+ end
116
+
117
+ else
118
+ parser.warn("Unknown subcommand #{subcommand}")
119
+ return 1
120
+ end
121
+ return 0
122
+ end
123
+
124
+ def do_merge(orig, ours, theirs)
125
+ dats = [orig, ours, theirs].map { |filename|
126
+ if File.stat(filename).size.nonzero?
127
+ File.open(filename, 'rb') { |s| NBTFile.read(s) }
128
+ else
129
+ ["", NBTFile::Types::Compound.new]
130
+ end
131
+ }
132
+
133
+ orig_data, our_data, their_data = dats.map { |(label, root)|
134
+ chunk_data = root["Level"] || {}
135
+ {'Blocks' => chunk_data["Blocks"]}
136
+ }
137
+
138
+ ours_changed = our_data != orig_data
139
+ theirs_changed = their_data != orig_data
140
+
141
+ # do a stupid merge for now; keep our stuff in case of a conflict
142
+ if theirs_changed and not ours_changed
143
+ FileUtils.cp(theirs, ours)
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ def self.main(*args)
150
+ Main.main(*args)
151
+ end
152
+
153
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'minecraft-merge'
3
+
4
+ describe "MinecraftMerge" do
5
+ it "exists" do
6
+ MinecraftMerge
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'minecraft-merge'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minecraft-merge
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - MenTaLguY
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-15 00:00:00 -08:00
19
+ default_executable: minecraft-merge
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: rspec
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 0
34
+ version: 2.3.0
35
+ requirement: *id001
36
+ type: :development
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ name: bundler
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 23
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 0
50
+ version: 1.0.0
51
+ requirement: *id002
52
+ type: :development
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ name: jeweler
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 7
62
+ segments:
63
+ - 1
64
+ - 5
65
+ - 2
66
+ version: 1.5.2
67
+ requirement: *id003
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ prerelease: false
71
+ name: rcov
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirement: *id004
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ prerelease: false
85
+ name: nbtfile
86
+ version_requirements: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 23
92
+ segments:
93
+ - 0
94
+ - 2
95
+ - 0
96
+ version: 0.2.0
97
+ requirement: *id005
98
+ type: :development
99
+ - !ruby/object:Gem::Dependency
100
+ prerelease: false
101
+ name: nbtfile
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 23
108
+ segments:
109
+ - 0
110
+ - 2
111
+ - 0
112
+ version: 0.2.0
113
+ requirement: *id006
114
+ type: :runtime
115
+ description: A git merge driver for minecraft worlds
116
+ email: mental@rydia.net
117
+ executables:
118
+ - minecraft-merge
119
+ extensions: []
120
+
121
+ extra_rdoc_files:
122
+ - LICENSE.txt
123
+ - README.rdoc
124
+ files:
125
+ - .document
126
+ - .rspec
127
+ - Gemfile
128
+ - LICENSE.txt
129
+ - README.rdoc
130
+ - Rakefile
131
+ - VERSION
132
+ - bin/minecraft-merge
133
+ - lib/minecraft-merge.rb
134
+ - spec/minecraft-merge_spec.rb
135
+ - spec/spec_helper.rb
136
+ has_rdoc: true
137
+ homepage: http://github.com/mental/minecraft-merge
138
+ licenses:
139
+ - MIT
140
+ post_install_message:
141
+ rdoc_options: []
142
+
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 3
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
162
+ version: "0"
163
+ requirements: []
164
+
165
+ rubyforge_project:
166
+ rubygems_version: 1.3.7
167
+ signing_key:
168
+ specification_version: 3
169
+ summary: A git merge driver for minecraft worlds
170
+ test_files:
171
+ - spec/minecraft-merge_spec.rb
172
+ - spec/spec_helper.rb