ruby-changes:6774
From: nobu <ko1@a...>
Date: Thu, 31 Jul 2008 14:11:19 +0900 (JST)
Subject: [ruby-changes:6774] Ruby:r18290 (mvm): * tool/resolve_changelog.rb: extracted from tool/merge_from_trunk.rb.
nobu 2008-07-31 14:11:03 +0900 (Thu, 31 Jul 2008) New Revision: 18290 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18290 Log: * tool/resolve_changelog.rb: extracted from tool/merge_from_trunk.rb. Added files: branches/mvm/tool/resolve_changelog.rb Modified files: branches/mvm/ChangeLog branches/mvm/tool/merge_from_trunk.rb Index: mvm/ChangeLog =================================================================== --- mvm/ChangeLog (revision 18289) +++ mvm/ChangeLog (revision 18290) @@ -1,3 +1,7 @@ +Thu Jul 31 14:11:00 2008 Nobuyoshi Nakada <nobu@r...> + + * tool/resolve_changelog.rb: extracted from tool/merge_from_trunk.rb. + Thu Jul 31 12:23:53 2008 Nobuyoshi Nakada <nobu@r...> * pack.c (pack_unpack): upper half of hexdigits has never been used. Index: mvm/tool/merge_from_trunk.rb =================================================================== --- mvm/tool/merge_from_trunk.rb (revision 18289) +++ mvm/tool/merge_from_trunk.rb (revision 18290) @@ -20,62 +20,9 @@ File.open(".merged-trunk-revision", "wb") {|f| f.puts new_revision} end if conflicts.include?(ChangeLog) - require 'date' - puts "resolving #{ChangeLog}" - CONFLICT_BEGIN = "\n<<<<<<<" - CONFLICT_SEP = "\n=======" - CONFLICT_END = "\n>>>>>>>" - LOGENTRY_PAT = /([A-Z][a-z]{2} [A-Z][a-z]{2} [ 1-9]\d \d\d:\d\d:\d\d \d{4}) .*>(?:\n(?:\t.*)?)+\n\n/ - newlog = ChangeLog + ".new" - if open(ChangeLog) do |fi| - class << fi - def split_entry(ents) - results = [] - unless ents.empty? - ents.scan(/\G(#{LOGENTRY_PAT}|[.\n]+\z)/o) do |ent, time| - time or return - results << [(time and DateTime.parse(time)), ent] - end - end - results - end - def each_hunk - while line = self.gets - if /^<<<<<<</ =~ line - before = "" - else - before = self.gets(CONFLICT_BEGIN) - before[0, 0] = line - unless before.chomp!(CONFLICT_BEGIN) - yield before, nil, nil - break - end - self.gets - end - working = self.gets(CONFLICT_SEP) or return - working.chomp!(CONFLICT_SEP[1..-1]) and self.gets - working = split_entry(working) or return - merged = self.gets(CONFLICT_END) or return - merged.chomp!(CONFLICT_END[1..-1]) and self.gets - merged = split_entry(merged) or return - yield before, working, merged - end - true - end - end - open(newlog, "wb") do |fo| - fi.each_hunk do |before, working, merged| - fo.print before - if working - until working.empty? or merged.empty? - fo.print((merged.first[0] > working.first[0] ? merged : working).shift[1]) - end - working.each {|i| fo.print i[1]} - merged.each {|i| fo.print i[1]} - end - end - end - end + $:.unshift(File.dirname(__FILE__)) + require "resolve_changelog" + if newlog = ChangeLog.resolve File.rename(newlog, ChangeLog) if system("svn", "resolved", ChangeLog) conflicts.delete(ChangeLog) Index: mvm/tool/resolve_changelog.rb =================================================================== --- mvm/tool/resolve_changelog.rb (revision 0) +++ mvm/tool/resolve_changelog.rb (revision 18290) @@ -0,0 +1,79 @@ +#! /usr/bin/ruby + +ChangeLog ||= "ChangeLog" +class << ChangeLog + require 'date' + + module Reader + CONFLICT_BEGIN = "\n<<<<<<<".frozen + CONFLICT_SEP = "\n=======".frozen + CONFLICT_END = "\n>>>>>>>".frozen + LOGENTRY_PAT = /([A-Z][a-z]{2} [A-Z][a-z]{2} [ 1-9]\d \d\d:\d\d:\d\d \d{4}) .*>(?:\n(?:\t.*)?)+\n\n/ + + def split_entry(ents) + results = [] + unless ents.empty? + ents.scan(/\G(#{LOGENTRY_PAT}|[.\n]+\z)/o) do |ent, time| + time or return + results << [(time and DateTime.parse(time)), ent] + end + end + results + end + + def each_hunk + while line = self.gets + if /^<<<<<<</ =~ line + before = "" + else + before = self.gets(CONFLICT_BEGIN) + before[0, 0] = line + unless before.chomp!(CONFLICT_BEGIN) + yield before, nil, nil + break + end + self.gets + end + working = self.gets(CONFLICT_SEP) or return + working.chomp!(CONFLICT_SEP[1..-1]) and self.gets + working = split_entry(working) or return + merged = self.gets(CONFLICT_END) or return + merged.chomp!(CONFLICT_END[1..-1]) and self.gets + merged = split_entry(merged) or return + yield before, working, merged + end + true + end + end + + module Writer + def merge(working, merged) + until working.empty? or merged.empty? + later = merged.first[0] > working.first[0] ? merged : working + self.print(later.shift[1]) + end + working.each {|i| self.print i[1]} + merged.each {|i| self.print i[1]} + end + end + + def resolve + puts "resolving #{self}" + newlog = self + ".new" + open(self) do |fi| + fi.extend(Reader) + open(newlog, "wb") do |fo| + fo.extend(Writer) + fi.each_hunk do |before, working, merged| + fo.print before + fo.merge(working, merged) if working + end and newlog + end + end + end +end + +if $0 == __FILE__ + newlog = ChangeLog.resolve or abort + puts "resolved, see #{newlog}" +end Property changes on: mvm/tool/resolve_changelog.rb ___________________________________________________________________ Name: svn:eol-style + LF Name: svn:executable + * Name: svn:keywords + Author Id Revision -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/