Skip to content

Instantly share code, notes, and snippets.

@noqisofon
Created November 11, 2010 02:39
Show Gist options
  • Save noqisofon/671890 to your computer and use it in GitHub Desktop.
Save noqisofon/671890 to your computer and use it in GitHub Desktop.
git log とかからログファイルを作る感じのスクリプト。
#!C:/bin/ruby/bin/ruby
# -*- encoding: shift_jis -*-
require 'optparse'
opt = OptionParser.new
OPTS = {}
opt.version = "0.0.3"
opt.on( "-l PATH", "--location=PATH", "ログファイルを置いておくディレクトリを指定します。" ) do |path|
OPTS[:location] = path
end
opt.on( "-f LOGFILENAME", "--file=LOGFILENAME", "チェンジログファイルの名前を指定します。" ) do |log_filename|
OPTS[:filename] = log_filename
end
def write_git_show(path, first = 0, last = 10, suffix = "diff")
git_show = `git show`
s = "commit "
f = git_show.index( s ) + s.length
e = git_show.index( "\n" )
p git_show.encoding
hash_text = git_show.slice( f...e )
name_part = hash_text.slice( first, last )
filename = "#{path}/16r#{name_part}.#{suffix}"
File.open( filename, "w" ) do |input|
git_show.split( /\n/ ).each do |line|
input.puts line
end
end
end
begin
#
# コマンドラインオプションをパースします。
#
opt.parse!( ARGV )
#
# オプションを読み取って変数を初期化します。
#
if OPTS.has_key? :location then
path = File.expand_path( OPTS[:location] )
else
raise "no input path"
end
if OPTS.has_key? :filename then
changelog_name = OPTS[:filename]
else
changelog_name = "changelog"
end
#
# 本文:
# ワケも分からずにスレッド使ってます。
#
Thread.new {
`git log --date=iso > #{path}/#{changelog_name}`
`unix2dos #{path}/#{changelog_name} #{path}/#{changelog_name}.dos`
`mv #{path}/#{changelog_name}.dos #{path}/#{changelog_name}`
#`cat #{path}/#{changelog_name}`
}
t = Thread.new {
`git log --date=iso --stat --summary > #{path}/#{changelog_name}.stat.summary`
`git show-branch > #{path}/#{changelog_name}.branch`
#`sh line-count.sh`
}
write_git_show path
t.join
rescue => e
puts "#{$0}: #{e.to_s}"
exit
end
# shown.rb end here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment