[Frugalware-devel] Have you ever thought of changing the Frugalware SCM?

Csaba Henk csaba-ml at creo.hu
Fri Jun 29 01:10:35 CEST 2007


On Wed, Jun 20, 2007 at 02:15:41AM +0200, VMiklos wrote:
> Na Mon, Jun 18, 2007 at 03:41:31PM +0200, VMiklos <vmiklos at frugalware.org> pisal(a):
> > if this is not the situation at you, could you please send your ruby
> > script?
> 
> nevermind, written a working version in the meantime

I'm sorry for switching to Sleeping Beauty mode. Came back.

I attach the script anyway, maybe still you/someone can see some use of
it.

Csaba
-------------- next part --------------
#!/usr/bin/env ruby

require 'digest/sha1'
require 'zlib'
require 'fileutils'

class DarcsSplitter

  Darcs = "darcs"
  DarcsMeta = "_darcs"

  # pmap argument is [xmlp, inv2].transpose,
  # where xmlp is the patch list extracted from "darcs chan --xml" output,
  # and inv2 is as in darcssplit.rb

  def self.compile_pmap d="."
    [
     Dir.chdir(d) {
       open("|#{Darcs} chan --xml --reverse"){ |f| f.read}
     }. # XXX XML data should be properly parsed
       scan(/\shash='([^']+)'/).flatten,
     Dir.chdir(File.join(d, DarcsMeta)) {
       "".instance_eval {
         (Dir["inventories/*"] << "inventory").each { |f|
           self << IO.read(f) << "\n"
         }
         self
       }.scan(/^\[.*?\] $/m)
     }
    ].transpose
  end
      
  def initialize repo
    @pmap = self.class.compile_pmap(repo)
    @repo = repo
  end

  def makebundle pfile, ctx
    patch = Zlib::GzipReader.open(File.join(@repo, DarcsMeta, "patches", pfile)) { |f| f.read }
    ctx = ctx.rstrip
<<EOS.instance_eval { class << self; attr_reader :pfile; end; @pfile = pfile; self }
New patches:

#{patch}
Context:

#{ctx}
Patch bundle hash:
#{Digest::SHA1.new << patch}
EOS
  end

  def transform_pmap fpat = //
    pmap = @pmap
    pmaps=[[]].instance_eval {
      pmap.each { |pa, i|
        i =~ /TAG/ and self << []
        last << [pa, i]
      }
      self
    }

    pmaps.each_with_index { |e,i|
      e.each_with_index { |pap, j|
        pa, inv = pap
        pa =~ fpat or next
        yield makebundle(
          pa, 
          if i == 0 && j == 0
            ""
          elsif i > 0 && j == 0
            pmaps[i-1].transpose[1].reverse.join("\n")      
          else
            e[0...j].transpose[1].reverse.join("\n") 
          end
        )
      }
    }
  end

  def dump bdir, kw = {:verbose => true, :filter => //, :create => true}
    i = 0
    kw[:create] and FileUtils.mkpath bdir
    transform_pmap(kw[:filter]) { |b|
      kw[:verbose] and STDERR.puts i
      open(File.join(bdir, b.pfile), "w") { |f|
        f << b
      }
      i += 1
    }
  end

  def self.main *args
    new(args[0] || ".").dump(args[1] || "bundles")
  end

end

if __FILE__ == $0:
  DarcsSplitter.main *$*
end


More information about the Frugalware-devel mailing list