Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'sqlite3'
- $authors = {
- "rekkanoryo@cpw.pidgin.im" => "John Bailey",
- "rekkanoryo@pidgin.im" => "John Bailey",
- "rekkanoryo@rekkanoryo.org" => "John Bailey",
- "khc@pidgin.im" => "Ka-Hing CHeung",
- "sadrul@pidgin.im" => "Sadrul Chowdhury",
- "markdoliner@pidgin.im" => "Mark Doliner",
- "seanegan@pidgin.im" => "Sean Egan",
- "charkins@pidgin.im" => "Casey Harkins",
- "grim@pidgin.im" => "Gary Kramlich",
- "rlaager@pidgin.im" => "Richard Laager",
- "siege@pidgin.im" => "Christopher O'Brien",
- "bartosz@pidgin.im" => "Bartoz Oler",
- "deryni@pidgin.im" => "Etan Reisner",
- "marv@pidgin.im" => "Tim Ringerbach",
- "lschiere@pidgin.im" => "Luke Schierer",
- "evands@pidgin.im" => "Evan Schoenberg",
- "evands" => "Evan Schoenberg",
- "resiak@pidgin.im" => "Will Thompson",
- "resiak@soc.pidgin.im" => "Will Thompson",
- "nosnilmot@pidgin.im" => "Stu Tomlinson",
- "stu@nosnilmot.com" => "Stu Tomlinson",
- "datallah@pidgin.im" => "Daniel Atallah",
- "wabz@pidgin.im" => "Richard Nelson",
- "felipe.contreras@gmail.com" => "Felipe Contreras",
- "nix@go-nix.ca" => "Gabriel Schulhof",
- "elb@pidgin.im" => "Ethan Blanton",
- "kstange@pidgin.im" => "Kevin Stange",
- "nwalp@pidgin.im" => "Nathan Walp",
- "hbons@pidgin.im" => "Hylke Bons",
- "aluink@pidgin.im" => "Eric Polino",
- "jeff2@soc.pidgin.im" => "Jeffrey Connelly",
- "mshkutkov@soc.pidgin.im" => "Michael Shkutkov",
- "wehlhard@soc.pidgin.im" => "William Ehlhardt",
- "ecoffey@soc.pidgin.im" => "Eoin Coffey",
- "typ0@pidgin.im" => "Carlos Silva",
- "wtogami" => "Warren Togami",
- "friedel@translate.org.za" => "Friedel Wolff",
- "khaledhosny@eglug.org" => "Khaled Hosny",
- "ihar.hrachyshka@gmail.com" => "Ihar Hrachyshka",
- "josep.puigdemont@gmail.com" => "Josep Puigdemont",
- "toniher@softcatala.org" => "Toni Hermoso",
- "bjoern@cs.tu-berlin.de" => "Björn Voigt",
- "jochenkemnade@web.de" => "Jochen Kemnade",
- "panos@echidna-band.com" => "Bouklis Panos",
- "luke@lukeross.name" => "Luke Ross",
- "jfs@computer.org" => "Javier Fernández-Sanguino Peña",
- "okul@linux.ee" => "Ivar Smolin",
- "timo.jyrinki@iki.fi" => "Timo Jyrinki",
- "zongo_fr@users.sf.net" => "Éric Boumaour",
- "mariamarcp@gmail.com" => "Mar Castro",
- "fjrial@cesga.es" => "Francisco Rial",
- "scraimer@gmail.com" => "Shalom Craimer",
- "kelemeng@gnome.hu" => "Kelemen Gábor",
- "raireg@yahoo.com" => "Rai S. Regawa",
- "satriano@na.infn.it" => "Claudio Satriano",
- "takeshi.aihana@gmail.com" => "Takashi Aihana",
- "anousak@gmail.com" => "Anousak Souphavah",
- "laurynas.biveinis@gmail.com" => "Laurynas Biveinis",
- "arangel@linux.net.mk" => "Arangel Angov",
- "espenas@gmail.com" => "Espen Stefansen",
- "aalam@users.sf.net" => "Amanpreet Singh Alam",
- "mauricioc@gmail.com" => "Maurício Collares",
- "dumol@gnome.ro" => "Mişu Moldovan",
- "miles@filmsi.net" => "Martin Srebotnjak",
- "gpopac@gmail.com" => "Miloš Popović",
- "xake@telia.com" => "Peter Hjalmarsson",
- "rkvsraman@gmail.com" => "RKVS Raman",
- "fundawang@gmail.com" => "Funda Wang",
- "abelindsay@gmail.com" => "Abel Cheung",
- "acli@ada.dhs.org" => "Ambrose C. Li",
- "tulliana@gmail.com" => "Serdar Soytetir",
- "loptosko@gmail.com" => "loptosko",
- "eric.boumaour_pidgin@m4x.org" => "Éric Boumaour",
- "mitr@volny.cz" => "Miloslav Trmac",
- "hallvard.glad@gmail.com" => "Hallvard Glad",
- }
- def shell_escape(text)
- [ "<", ">", "!", "?", "|", "(", ")" ].each{|char| text = text.gsub(char, '\\' + char)}
- return text
- end
- class Commit
- attr_reader :id, :subject
- attr_accessor :body, :date, :author, :parents, :childs
- attr_accessor :counted, :count, :main, :alt, :tail
- attr_accessor :analyzed, :merges, :fork_commits
- attr_accessor :in_master
- def initialize(id)
- @id = id
- @branches = []
- @parents = []
- @childs = []
- @count = 0
- @tail = nil
- @in_master = false
- @merges = []
- @fork_commits = []
- end
- def is_in(branch)
- @branches.member?(branch)
- end
- def git_author()
- real_name = $authors[@author]
- real_name = @author if not real_name
- return "#{real_name} <#{@author}>"
- end
- def git_message()
- tmp = [ @subject, "mtn id: #{@id}" ]
- tmp << @body if @body
- return tmp.join("\n\n");
- end
- def to_s()
- return "commit=#{@id},subject=#{@subject}"
- end
- def []=(name, value)
- case name
- when "branch"
- @branches << value
- when "changelog"
- lines = value.split("\n")
- @subject = lines[0]
- @subject = @subject[0..100] + "..." if @subject.length > 100
- @body = value if lines.length > 0
- when "date"
- @date = value
- when "author"
- @author = value
- end
- end
- end
- class Branch
- def initialize(name)
- @name = name
- @commits = {}
- @master = nil
- @heads = []
- @tails = []
- @authors = {}
- @lost = []
- @lost_levels = {}
- @rebaseable = []
- end
- def filter_commits(commits)
- commits.each do |id,c|
- next if not c.is_in(@name)
- @commits[id] = c
- end
- end
- def check_commits()
- @commits.each do |id,c|
- tmp_parents = []
- rows = $db.execute("select parent,child from revision_ancestry where child='#{id}'")
- rows.each do |e|
- parent, child = e
- c.parents << parent
- tmp_parents << @commits[parent] if @commits[parent]
- end
- @authors[c.author] = 0 if not @authors[c.author]
- @authors[c.author] += 1
- =begin
- tmp = c.body.scan(/patch.* from.([^,\.]*)/i)
- if not tmp.empty?
- p "== found ==", tmp
- end
- =end
- rows = $db.execute("select parent,child from revision_ancestry where parent='#{id}'")
- rows.each do |e|
- parent, child = e
- c.childs << child
- end
- if tmp_parents.empty?
- @tails << c
- end
- if c.childs.empty?
- @heads << c
- end
- end
- end
- def find_master()
- check_commits()
- def travel(c)
- return c if c.counted
- c.counted = true
- c.parents.each do |id|
- parent = @commits[id]
- if parent
- travel(parent)
- if parent.count > c.count
- c.alt = c.main
- c.count = parent.count
- c.main = parent
- if parent.tail
- c.tail = parent.tail
- else
- c.tail = parent
- end
- else
- c.alt = parent
- end
- end
- end
- c.count += 1
- return c
- end
- master_count = 0
- @heads.each do |h|
- travel(h)
- if h.count > master_count
- master_count = h.count
- @master = h
- end
- end
- end
- def analyze()
- find_master()
- def analyze_head(h)
- def travel(c)
- return [], [] if not c or c.analyzed == true
- c.analyzed = true
- merges, fork_commits = travel(c.main)
- merges << c if c.parents.length > 1
- fork_commits << c
- return merges, fork_commits
- end
- h.merges, h.fork_commits = travel(h.main)
- # puts "branch=%s,merges=%d" % [h.id, h.merges.length]
- # puts "branch=%s,commits=%d" % [h.id, h.fork_commits.length]
- h.merges.each do |m|
- analyze_head(m.alt) if m.alt
- end
- end
- @heads.each do |h|
- analyze_head(h)
- end
- def travel(c)
- c.in_master = true
- if c.alt
- @rebaseable << c.alt if c.alt.fork_commits.length == 0
- end
- travel(c.main) if c.main
- end
- travel(@master)
- @commits.each do |id,e|
- next if e.in_master
- @lost << e
- if @lost_levels[e.merges.length]
- ll = @lost_levels[e.merges.length]
- else
- ll = []
- @lost_levels[e.merges.length] = ll
- end
- ll << e
- end
- end
- def print_results
- def travel(c)
- puts c
- travel(c.main) if c.main
- end
- puts "== info =="
- puts "name=#{@name}"
- puts "commit_count=#{@commits.length}"
- puts "author_count=#{@authors.length}"
- puts "tail_count=#{@tails.length}"
- puts "lost_count=#{@lost.length}"
- puts "rebaseable_count=#{@rebaseable.length}"
- puts "== lost levels =="
- @lost_levels.each do |l,a|
- puts "level=#{l}:count=#{a.length}"
- end
- puts "== master =="
- travel(@master)
- puts "== rebaseable =="
- @rebaseable.each do |c|
- puts c
- end
- puts "== tails =="
- @tails.each do |c|
- puts c
- end
- puts "== not in master =="
- @lost_levels.each do |l,a|
- puts "=== level=#{l} ==="
- a.each do |c|
- puts c
- end
- end
- end
- def generate_git
- def export_commit(c)
- puts "try #{c.id}"
- commit_dir = "commit-#{c.id}"
- system("./get-commit.sh #{c.id}")
- base_dir = Dir.pwd
- Dir.chdir(commit_dir)
- system("git add .")
- if c.alt
- c = c.alt if c.alt.fork_commits.length == 0
- end
- puts "generating #{c.id}, #{c.git_author}, #{c.git_message}"
- File.open("/tmp/message", "w") { |f| f.write c.git_message }
- system("git commit --quiet --author '#{c.git_author}' -F /tmp/message")
- Dir.chdir(base_dir)
- system("rm -rf #{commit_dir}")
- end
- def travel(c)
- export_commit(c)
- c.childs.each do |e|
- child = @commits[e]
- travel(child) if child and child.in_master
- end
- end
- git_dir = "#{Dir.pwd}/branches/master/.git"
- ENV['GIT_DIR'] = git_dir
- #system("mkdir -p #{}")
- travel(@master.tail)
- end
- def print_all
- @commits.each do |id,c|
- puts "#{id}: forks=#{c.fork_commits.length}, in_master=#{c.in_master}, alt=#{c.alt}, forks=#{c.fork_commits}"
- end
- end
- def print_authors
- puts "== authors =="
- @authors.each do |id,c|
- puts "author=%s,commit_count=%d" % [id, c]
- # puts id
- end
- end
- end
- @all_commits = {}
- $db = SQLite3::Database.new("mtn/pidgin.mtn")
- rows = $db.execute("select id,name,value from revision_certs")
- rows.each do |e|
- id, name, value = e
- if not @all_commits[id]
- commit = Commit.new(id)
- @all_commits[id] = commit
- else
- commit = @all_commits[id]
- end
- commit[name] = value
- end
- branch = Branch.new("im.pidgin.pidgin")
- branch.filter_commits(@all_commits)
- branch.analyze()
- # branch.print_results()
- # branch.print_authors()
- branch.generate_git()
Add Comment
Please, Sign In to add comment