Skip to content

Commit

Permalink
CommitLog を外部化
Browse files Browse the repository at this point in the history
  • Loading branch information
onk committed May 1, 2012
1 parent 7b24e5b commit c5119a4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 48 deletions.
49 changes: 1 addition & 48 deletions lib/brahman.rb
@@ -1,6 +1,7 @@
require "time"
require "rexml/document"
require "brahman/version"
require "brahman/commit_log"

module Brahman
CASHE_DIR = ".svn_cache"
Expand Down Expand Up @@ -41,53 +42,5 @@ def self.run(args)
end
end

class CommitLog
MAX_AUTHOR_LENGTH = 18

def initialize(rev)
xml_str = CommitLog.svn_log(rev)

logentry = REXML::Document.new(xml_str).elements["/log/logentry"]
@revision = logentry.attributes["revision"]
@author = logentry.elements["author"].text
@commit_at = Time.parse(logentry.elements["date"].text).localtime
@message = logentry.elements["msg"].text
end

def to_s
"* #{revision} | #{commit_at} | #{author} | #{message}"
end

def self.svn_log(rev)
cache_path = File.join(CASHE_DIR, rev)
if File.exists?(cache_path)
log = File.read(cache_path)
else
log = `svn log -c #{rev} --xml #{TRUNK_PATH}`

File.open(cache_path, "w") {|f| f.puts(log)}
end
log
end

private
def revision
"r" + @revision
end

def author
@author + " " * (MAX_AUTHOR_LENGTH - @author.length)
end

def message
if @message
@message.split("\n").first
end
end

def commit_at
@commit_at.strftime("%Y-%m-%d %H:%M:%S")
end
end
end

51 changes: 51 additions & 0 deletions lib/brahman/commit_log.rb
@@ -0,0 +1,51 @@
module Brahman
class CommitLog
MAX_AUTHOR_LENGTH = 18

def initialize(rev)
xml_str = CommitLog.svn_log(rev)

logentry = REXML::Document.new(xml_str).elements["/log/logentry"]
@revision = logentry.attributes["revision"]
@author = logentry.elements["author"].text
@commit_at = Time.parse(logentry.elements["date"].text).localtime
@message = logentry.elements["msg"].text
end

def to_s
"* #{revision} | #{commit_at} | #{author} | #{message}"
end

def self.svn_log(rev)
cache_path = File.join(Brahman::CASHE_DIR, rev)
if File.exists?(cache_path)
log = File.read(cache_path)
else
log = `svn log -c #{rev} --xml #{Brahman::TRUNK_PATH}`

File.open(cache_path, "w") {|f| f.puts(log)}
end
log
end

private
def revision
"r" + @revision
end

def author
@author + " " * (MAX_AUTHOR_LENGTH - @author.length)
end

def message
if @message
@message.split("\n").first
end
end

def commit_at
@commit_at.strftime("%Y-%m-%d %H:%M:%S")
end
end
end

0 comments on commit c5119a4

Please sign in to comment.