37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/minecraft-merge.rb', line 37
def main(*args)
parser = OptionParser.new do |opts|
end
parser.banner = "Usage: #{parser.program_name} merge ORIG OURS THEIRS\n" +
" #{parser.program_name} setup [REPOSITORY]\n"
parser.parse!(args)
if args.empty?
parser.warn("No subcommand given")
return 1
end
subcommand = args.shift
case subcommand
when 'merge'
if args.length != 3
parser.warn("Wrong number of arguments for merge (3 required)")
return 1
end
do_merge(*args)
when 'install'
if args.length > 0
parser.warn("Wrong number of arguments for install (0 needed)")
return 1
end
unless system "git", "config", "--global", "merge.minecraft.name", "Minecraft merge driver" and
system "git", "config", "--global", "merge.minecraft.driver", "minecraft-merge merge %O %A %B" and
system "git", "config", "--global", "filter.minecraft.clean", "minecraft-merge decompress" and
system "git", "config", "--global", "filter.minecraft.smudge", "minecraft-merge compress"
return 1
end
when 'setup'
if args.length > 1
parser.warn("Wrong number of arguments for setup (1 optional)")
return 1
end
work_dir = args[0] || Dir.pwd
Dir.chdir work_dir
File.open(".gitignore", "w+") do |s|
s.puts "session.lock"
s.puts "level.dat_old"
end
File.open(".gitattributes", "w+") do |s|
s.puts "*.dat binary -delta merge=minecraft"
end
unless system "git", "add", ".gitignore", ".gitattributes" and
system "git", "commit", "-m", "set up attributes"
return 1
end
when 'compress'
data = $stdin.read
if data[0, GZIP_MAGIC.length] == GZIP_MAGIC
$stdout.write data
$stdout.flush
else
writer = Zlib::GzipWriter.new($stdout)
writer.write data
writer.close
end
when 'decompress'
data = $stdin.read
if data[0, GZIP_MAGIC.length] == GZIP_MAGIC
reader = Zlib::GzipReader.new(StringIO.new(data))
$stdout.write reader.read
reader.close
$stdout.flush
else
$stdout.write data
$stdout.flush
end
else
parser.warn("Unknown subcommand #{subcommand}")
return 1
end
return 0
end
|