Tue, 04 Nov 2025 22:26:27 +0100
update uwproj (fixes configure on solaris)
| 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 | ||
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
33 | void fm::heatmap::add(const settings &settings, const std::string &log) { |
| 5 | 34 | using std::string_view_literals::operator ""sv; |
|
56
3d2720f95cfb
fix that commits were not listed per repository in the combined view
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
35 | const std::string repo_key = m_separate ? m_current_repo : "All Repositories"; |
| 5 | 36 | |
|
51
49fdc2eb7cd4
fix critical bug in string iteration
Mike Becker <universe@uap-core.de>
parents:
44
diff
changeset
|
37 | for (auto line: std::views::split(log, "\n"sv)) { |
| 5 | 38 | if (line.empty()) continue; |
|
55
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
39 | |
|
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
40 | // find all delimiters |
|
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
41 | const auto line_view = std::string_view{line}; |
|
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
42 | const auto pos_delim1 = line_view.find('#', 0); |
|
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
43 | const auto pos_delim2 = line_view.find('#', pos_delim1 + 1); |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
44 | const auto pos_delim3 = line_view.find('#', pos_delim2 + 1); |
|
55
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
45 | |
|
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
46 | std::string author{settings.map_author(line_view.substr(0, pos_delim1))}; |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
47 | std::string_view date_view{line_view.substr(pos_delim1+1, pos_delim2 - pos_delim1 - 1)}; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
48 | std::string_view tags_view{line_view.substr(pos_delim2+1, pos_delim3 - pos_delim2 - 1)}; |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
49 | std::string_view summary_view{line_view.substr(pos_delim3+1)}; |
| 5 | 50 | |
| 51 | int year = 0; | |
| 52 | unsigned int month = 0, day = 0; | |
|
55
3541b2c77dfd
fix accidental split of commit messages - relates to #644
Mike Becker <universe@uap-core.de>
parents:
54
diff
changeset
|
53 | auto date_parts = std::views::split(date_view, "-"sv) |
|
10
bf159cf9f4b6
improve heatmap::add() by using C++23 ranges-v3
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
54 | | std::views::transform([](auto r) { return std::string_view(r); }) |
|
bf159cf9f4b6
improve heatmap::add() by using C++23 ranges-v3
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
55 | | std::ranges::to<std::vector>(); |
|
bf159cf9f4b6
improve heatmap::add() by using C++23 ranges-v3
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
56 | std::from_chars(date_parts[0].begin(), date_parts[0].end(), year); |
|
bf159cf9f4b6
improve heatmap::add() by using C++23 ranges-v3
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
57 | std::from_chars(date_parts[1].begin(), date_parts[1].end(), month); |
|
bf159cf9f4b6
improve heatmap::add() by using C++23 ranges-v3
Mike Becker <universe@uap-core.de>
parents:
5
diff
changeset
|
58 | std::from_chars(date_parts[2].begin(), date_parts[2].end(), day); |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
59 | auto &[summaries, tags] = |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
60 | m_heatmap[repo_key][author][chrono::year_month_day{ |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
61 | chrono::year{year}, chrono::month{month}, chrono::day{day} |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
62 | }]; |
| 57 | 63 | summaries[m_current_repo].emplace_back(summary_view); |
|
64
cfaddbb6caab
exclude the "tip" tag from the report
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
64 | // special case: if the (only) tag is "tip", we do not add it |
|
cfaddbb6caab
exclude the "tip" tag from the report
Mike Becker <universe@uap-core.de>
parents:
61
diff
changeset
|
65 | if (!tags_view.empty() && tags_view != "tip") { |
|
61
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
66 | tags[m_current_repo].emplace_back(tags_view); |
|
d77763d2fdda
highlight days with tags - resolves #672
Mike Becker <universe@uap-core.de>
parents:
57
diff
changeset
|
67 | } |
| 5 | 68 | } |
| 69 | } | |
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
70 | |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
71 | std::array<unsigned int, 12> fm::heatmap::commits_per_month( |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
72 | const std::string& repo, |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
73 | const std::string& author, |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
74 | chrono::year year |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
75 | ) const { |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
76 | std::array<unsigned int, 12> result{}; |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
77 | for (auto&& [ymd, commits] : m_heatmap.at(repo).at(author)) { |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
78 | if (ymd.year() != year) continue; |
|
54
586dcd606e47
add popups with commit summaries - resolves #644
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
79 | result[static_cast<unsigned int>(ymd.month())-1] += commits.count(); |
|
44
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
80 | } |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
81 | return result; |
|
de22ded6d50a
add total commits counters
Mike Becker <universe@uap-core.de>
parents:
16
diff
changeset
|
82 | } |