-
Notifications
You must be signed in to change notification settings - Fork 0
/
svn_cvs_maps.cpp
152 lines (139 loc) · 4.24 KB
/
svn_cvs_maps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* S V N _ C V S _ M A P S . C P P
* BRL-CAD
*
* Published in 2020 by the United States Government.
* This work is in the public domain.
*
*/
/** @file svn_cvs_maps.cpp
*
* Utility functions
*
*/
#include <iostream>
#include <sstream>
#include <locale>
#include "repowork.h"
int
git_map_svn_committers(git_fi_data *s, std::string &svn_map)
{
// read map
std::ifstream infile(svn_map, std::ifstream::binary);
if (!infile.good()) {
std::cerr << "Could not open svn_map file: " << svn_map << "\n";
exit(-1);
}
// Create mapping of ids to svn committers
std::map<std::string, std::string> svn_committer_map;
std::string line;
while (std::getline(infile, line)) {
// Skip empty lines
if (!line.length()) {
continue;
}
size_t spos = line.find_first_of(" ");
if (spos == std::string::npos) {
std::cerr << "Invalid svn map line!: " << line << "\n";
exit(-1);
}
std::string id = line.substr(0, spos);
std::string committer = line.substr(spos+1, std::string::npos);
svn_committer_map[id] = committer;
}
// Iterate over the commits and assign committers.
for (size_t i = 0; i < s->commits.size(); i++) {
git_commit_data *c = &(s->commits[i]);
if (!c->svn_id.length()) {
continue;
}
if (svn_committer_map.find(c->svn_id) != svn_committer_map.end()) {
std::string svncommitter = svn_committer_map[c->svn_id];
//std::cerr << "Found SVN commit \"" << c->svn_id << "\" with committer \"" << svncommitter << "\"\n";
c->svn_committer = svncommitter;
}
}
return 0;
}
void
read_key_sha1_map(git_fi_data *s, std::string &keysha1file)
{
std::ifstream infile(keysha1file, std::ifstream::binary);
if (!infile.good()) {
std::cerr << "Could not open file: " << keysha1file << "\n";
exit(-1);
}
std::string line;
while (std::getline(infile, line)) {
if (!line.length()) continue;
size_t cpos = line.find_first_of(":");
std::string key = line.substr(0, cpos);
std::string sha1 = line.substr(cpos+1, std::string::npos);
s->sha12key[sha1] = key;
s->key2sha1[key] = sha1;
}
infile.close();
}
void
read_key_cvsbranch_map(
git_fi_data *s,
std::string &branchfile)
{
std::map<std::string, std::string> key2branch;
std::ifstream infile(branchfile, std::ifstream::binary);
if (!infile.good()) {
std::cerr << "Could not open file: " << branchfile << "\n";
exit(-1);
}
std::string line;
while (std::getline(infile, line)) {
if (!line.length()) continue;
size_t cpos = line.find_first_of(":");
std::string key = line.substr(0, cpos);
std::string branch = line.substr(cpos+1, std::string::npos);
if (key2branch.find(key) != key2branch.end()) {
std::string oldbranch = key2branch[key];
if (oldbranch != branch) {
std::cout << "WARNING: non-unique key maps to both branch " << oldbranch << " and branch " << branch << ", overriding\n";
}
}
if (s->key2sha1.find(key) != s->key2sha1.end()) {
s->key2cvsbranch[key] = branch;
}
}
infile.close();
}
void
read_key_cvsauthor_map( git_fi_data *s, std::string &authorfile)
{
std::map<std::string, std::string> key2author;
std::ifstream infile(authorfile, std::ifstream::binary);
if (!infile.good()) {
std::cerr << "Could not open file: " << authorfile << "\n";
exit(-1);
}
std::string line;
while (std::getline(infile, line)) {
if (!line.length()) continue;
size_t cpos = line.find_first_of(":");
std::string key = line.substr(0, cpos);
std::string author = line.substr(cpos+1, std::string::npos);
if (key2author.find(key) != key2author.end()) {
std::string oldauthor = key2author[key];
if (oldauthor != author) {
std::cout << "WARNING: non-unique key maps to both author " << oldauthor << " and author " << author << ", overriding\n";
}
}
if (s->key2sha1.find(key) != s->key2sha1.end()) {
s->key2cvsauthor[key] = author;
}
}
infile.close();
}
// Local Variables:
// tab-width: 8
// mode: C++
// c-basic-offset: 4
// indent-tabs-mode: t
// c-file-style: "stroustrup"
// End:
// ex: shiftwidth=4 tabstop=8