| #include <string> |
| #include <sstream> |
| #include <iostream> |
| #include <fstream> |
| #include <iomanip> |
| #include <map> |
| #include <list> |
|
|
| using namespace std; |
|
|
| |
| |
| std::string contributor_name(const std::string& line) |
| { |
| string result; |
|
|
| |
| |
| if(line.find("markb@localhost.localdomain") != string::npos) |
| { |
| return "Mark Borgerding"; |
| } |
|
|
| if(line.find("kayhman@contact.intra.cea.fr") != string::npos) |
| { |
| return "Guillaume Saupin"; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| size_t position_of_email_address = line.find_first_of('<'); |
| if(position_of_email_address != string::npos) |
| { |
| |
| |
| |
| if(line.find("hauke.heibel") != string::npos) |
| result = "Hauke Heibel"; |
| else |
| { |
| |
| result = line.substr(0, position_of_email_address); |
| } |
| } |
| else |
| { |
| |
| |
| if(line.find("convert-repo") != string::npos) |
| result = ""; |
| else |
| result = line; |
| } |
|
|
| |
| size_t length = result.length(); |
| while(length >= 1 && result[length-1] == ' ') result.erase(--length); |
|
|
| return result; |
| } |
|
|
| |
| map<string,int> contributors_map_from_churn_output(const char *filename) |
| { |
| map<string,int> contributors_map; |
|
|
| string line; |
| ifstream churn_out; |
| churn_out.open(filename, ios::in); |
| while(!getline(churn_out,line).eof()) |
| { |
| |
| size_t first_star = line.find_first_of('*'); |
| if(first_star != string::npos) line.erase(first_star); |
| |
| |
| size_t length = line.length(); |
| while(length >= 1 && line[length-1] == ' ') line.erase(--length); |
|
|
| |
| size_t last_space = line.find_last_of(' '); |
| |
| |
| int number; |
| istringstream(line.substr(last_space+1)) >> number; |
|
|
| |
| line.erase(last_space); |
| string name = contributor_name(line); |
| |
| map<string,int>::iterator it = contributors_map.find(name); |
| |
| if(it == contributors_map.end()) |
| contributors_map.insert(pair<string,int>(name, number)); |
| |
| else |
| it->second += number; |
| } |
| churn_out.close(); |
|
|
| return contributors_map; |
| } |
|
|
| |
| |
| string lastname(const string& name) |
| { |
| size_t last_space = name.find_last_of(' '); |
| if(last_space >= name.length()-1) return name; |
| else return name.substr(last_space+1); |
| } |
|
|
| struct contributor |
| { |
| string name; |
| int changedlines; |
| int changesets; |
| string url; |
| string misc; |
| |
| contributor() : changedlines(0), changesets(0) {} |
| |
| bool operator < (const contributor& other) |
| { |
| return lastname(name).compare(lastname(other.name)) < 0; |
| } |
| }; |
|
|
| void add_online_info_into_contributors_list(list<contributor>& contributors_list, const char *filename) |
| { |
| string line; |
| ifstream online_info; |
| online_info.open(filename, ios::in); |
| while(!getline(online_info,line).eof()) |
| { |
| string hgname, realname, url, misc; |
| |
| size_t last_bar = line.find_last_of('|'); |
| if(last_bar == string::npos) continue; |
| if(last_bar < line.length()) |
| misc = line.substr(last_bar+1); |
| line.erase(last_bar); |
| |
| last_bar = line.find_last_of('|'); |
| if(last_bar == string::npos) continue; |
| if(last_bar < line.length()) |
| url = line.substr(last_bar+1); |
| line.erase(last_bar); |
|
|
| last_bar = line.find_last_of('|'); |
| if(last_bar == string::npos) continue; |
| if(last_bar < line.length()) |
| realname = line.substr(last_bar+1); |
| line.erase(last_bar); |
|
|
| hgname = line; |
| |
| |
| if(hgname.find("MercurialName") != string::npos) continue; |
| |
| list<contributor>::iterator it; |
| for(it=contributors_list.begin(); it != contributors_list.end() && it->name != hgname; ++it) |
| {} |
| |
| if(it == contributors_list.end()) |
| { |
| contributor c; |
| c.name = realname; |
| c.url = url; |
| c.misc = misc; |
| contributors_list.push_back(c); |
| } |
| else |
| { |
| it->name = realname; |
| it->url = url; |
| it->misc = misc; |
| } |
| } |
| } |
|
|
| int main() |
| { |
| |
| map<string,int> contributors_map_for_changedlines = contributors_map_from_churn_output("churn-changedlines.out"); |
| |
| |
| |
| list<contributor> contributors_list; |
| map<string,int>::iterator it; |
| for(it=contributors_map_for_changedlines.begin(); it != contributors_map_for_changedlines.end(); ++it) |
| { |
| contributor c; |
| c.name = it->first; |
| c.changedlines = it->second; |
| c.changesets = 0; |
| contributors_list.push_back(c); |
| } |
| |
| add_online_info_into_contributors_list(contributors_list, "online-info.out"); |
| |
| contributors_list.sort(); |
| |
| cout << "{| cellpadding=\"5\"\n"; |
| cout << "!\n"; |
| cout << "! Lines changed\n"; |
| cout << "!\n"; |
|
|
| list<contributor>::iterator itc; |
| int i = 0; |
| for(itc=contributors_list.begin(); itc != contributors_list.end(); ++itc) |
| { |
| if(itc->name.length() == 0) continue; |
| if(i%2) cout << "|-\n"; |
| else cout << "|- style=\"background:#FFFFD0\"\n"; |
| if(itc->url.length()) |
| cout << "| [" << itc->url << " " << itc->name << "]\n"; |
| else |
| cout << "| " << itc->name << "\n"; |
| if(itc->changedlines) |
| cout << "| " << itc->changedlines << "\n"; |
| else |
| cout << "| (no information)\n"; |
| cout << "| " << itc->misc << "\n"; |
| i++; |
| } |
| cout << "|}" << endl; |
| } |
|
|