MCPcopy Create free account
hub / github.com/build-cpp/cmkr / generate_gitfile

Function generate_gitfile

src/cmake_generator.cpp:190–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190static void generate_gitfile(const char *gitfile, const std::vector<std::string> &desired_lines) {
191 // Reference: https://github.com/github/linguist/blob/master/docs/overrides.md#summary
192 auto lines = desired_lines;
193 auto generate = [&lines](const char *newline) {
194 std::string generated;
195 generated += "# cmkr";
196 generated += newline;
197 for (const auto &line : lines) {
198 generated += line;
199 generated += newline;
200 }
201 return generated;
202 };
203 if (!fs::exists(gitfile)) {
204 create_file(gitfile, generate("\n"));
205 } else {
206 auto contents = read_file(gitfile);
207 std::string line;
208 auto cr = 0, lf = 0;
209 auto flush_line = [&line, &lines]() {
210 auto itr = std::find(lines.begin(), lines.end(), line);
211 if (itr != lines.end()) {
212 lines.erase(itr);
213 }
214 line.clear();
215 };
216 for (size_t i = 0; i < contents.length(); i++) {
217 if (contents[i] == '\r') {
218 cr++;
219 continue;
220 }
221 if (contents[i] == '\n') {
222 lf++;
223 flush_line();
224 } else {
225 line += contents[i];
226 }
227 }
228 if (!line.empty()) {
229 flush_line();
230 }
231
232 if (!lines.empty()) {
233 // Append the cmkr .gitattributes using the detected newline
234 auto newline = cr == lf ? "\r\n" : "\n";
235 if (!contents.empty() && contents.back() != '\n') {
236 contents += newline;
237 }
238 contents += newline;
239 contents += generate(newline);
240 create_file(gitfile, contents);
241 }
242 }
243}
244
245void generate_project(const std::string &type) {
246 const auto name = escape_project_name(fs::current_path().stem().string());

Callers 1

generate_projectFunction · 0.85

Calls 3

create_fileFunction · 0.85
read_fileFunction · 0.85
emptyMethod · 0.80

Tested by

no test coverage detected