Fri, 31 Jan 2025 23:20:20 +0100
skip authorization requests when pulling
5 | 1 | /* Copyright 2025 Mike Becker. All rights reserved. |
2 | * | |
3 | * Redistribution and use in source and binary forms, with or without | |
4 | * modification, are permitted provided that the following conditions are met: | |
5 | * | |
6 | * 1. Redistributions of source code must retain the above copyright | |
7 | * notice, this list of conditions and the following disclaimer. | |
8 | * | |
9 | * 2. Redistributions in binary form must reproduce the above copyright | |
10 | * notice, this list of conditions and the following disclaimer in the | |
11 | * documentation and/or other materials provided with the distribution. | |
12 | * | |
13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
19 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
20 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
21 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
23 | */ | |
24 | ||
25 | #include "heatmap.h" | |
26 | ||
27 | #include <charconv> | |
28 | #include <ranges> | |
29 | #include <chrono> | |
30 | ||
31 | namespace chrono = std::chrono; | |
32 | ||
33 | void fm::heatmap::add(const std::string &log) { | |
34 | using std::string_view_literals::operator ""sv; | |
35 | ||
36 | for (auto &&line: std::views::split(log, "\n"sv)) { | |
37 | if (line.empty()) continue; | |
38 | auto parts = std::views::split(line, "#"sv).begin(); | |
39 | auto author_range = *parts; | |
40 | std::string author{author_range.begin(), author_range.end()}; | |
41 | ||
42 | int year = 0; | |
43 | unsigned int month = 0, day = 0; | |
44 | unsigned part = 0; | |
45 | for (auto &&date_part: std::views::split(*++parts, "-"sv)) { | |
46 | std::string_view dp{date_part.begin(), date_part.end()}; | |
47 | int val; | |
48 | // no error handling, we trust hg and git | |
49 | std::from_chars(dp.begin(), dp.end(), val); | |
50 | switch (part++) { | |
51 | case 0: year = val; break; | |
52 | case 1: month = val; break; | |
53 | default: day = val; break; | |
54 | } | |
55 | } | |
56 | m_heatmap[m_current_repo][author][chrono::year_month_day{chrono::year{year}, chrono::month{month}, chrono::day{day}}]++; | |
57 | } | |
58 | } |