Code forensics
0.1
Generate historical information about code changes
|
Go to the documentation of this file.
4 #ifndef PROGRAM_STATE_HPP
5 #define PROGRAM_STATE_HPP
7 #include <unordered_set>
11 #include <boost/log/trivial.hpp>
12 #include <boost/date_time/gregorian/gregorian.hpp>
13 #include <boost/date_time/posix_time/posix_time.hpp>
14 #include <boost/describe.hpp>
15 #include <boost/mp11.hpp>
21 using Logger = boost::log::sources::severity_logger<
22 boost::log::trivial::severity_level>;
24 using Date = boost::gregorian::date;
25 using PTime = boost::posix_time::ptime;
27 namespace stime = std::chrono;
28 namespace bd = boost::describe;
31 struct fmt::formatter<
35 boost::describe::has_describe_bases<T>::value &&
36 boost::describe::has_describe_members<T>::value &&
37 !std::is_union<T>::value>> {
38 constexpr
auto parse(format_parse_context& ctx) {
39 auto it = ctx.begin(), end = ctx.end();
41 if (it != end && *it !=
'}') {
42 ctx.error_handler().on_error(
"invalid format");
48 auto format(T
const& t, format_context& ctx)
const {
49 using namespace boost::describe;
51 using Bd = describe_bases<T, mod_any_access>;
52 using Md = describe_members<T, mod_any_access>;
60 boost::mp11::mp_for_each<Bd>([&](
auto D) {
61 if (!first) { *out++ =
','; }
66 out,
" {}", (
typename decltype(D)::type
const&)t);
69 boost::mp11::mp_for_each<Md>([&](
auto D) {
70 if (!first) { *out++ =
','; }
74 out = fmt::format_to(out,
" .{}={}", D.name, t.*D.pointer);
77 if (!first) { *out++ =
' '; }
91 struct fmt::formatter<
95 boost::describe::has_describe_enumerators<T>::value>> {
97 using U = std::underlying_type_t<T>;
99 fmt::formatter<fmt::string_view, char>
sf_;
100 fmt::formatter<U, char>
nf_;
103 constexpr
auto parse(format_parse_context& ctx) {
104 auto i1 = sf_.parse(ctx);
105 auto i2 = nf_.parse(ctx);
107 if (i1 != i2) { ctx.error_handler().on_error(
"invalid format"); }
112 auto format(T
const& t, format_context& ctx)
const {
113 char const* s = boost::describe::enum_to_string(t, 0);
116 return sf_.format(s, ctx);
118 return nf_.format(
static_cast<U>(t), ctx);
138 template <
typename E>
143 struct fmt::formatter<
Date> : fmt::formatter<Str> {
144 auto format(CR<Date> date, fmt::format_context& ctx)
const {
145 return fmt::formatter<Str>::format(
146 boost::gregorian::to_iso_extended_string(date), ctx);
153 struct fmt::formatter<
PTime> : fmt::formatter<Str> {
154 auto format(CR<PTime> time, fmt::format_context& ctx)
const {
155 return fmt::formatter<Str>::format(
156 boost::posix_time::to_iso_extended_string(time), ctx);
164 bool use_subprocess =
true;
188 return analytics.empty() ||
189 std::find(analytics.begin(), analytics.end(), which) !=
195 using TimePoint = stime::time_point<stime::system_clock>;
222 rev_index.insert({oid, full_commits.size()});
223 rev_periods.insert({oid, period});
224 full_commits.push_back(oid);
228 commit_ids.insert({oid,
id});
231 ir::CommitId
get_id(CR<git_oid> oid) {
return commit_ids.at(oid); }
240 auto found = rev_periods.find(commit);
241 if (found != rev_periods.end()) {
242 return Opt<int>{found->second};
250 int get_period(CR<git_oid> commit, CR<git_oid> line)
const noexcept {
251 auto lp = get_period(line);
252 auto cp = get_period(commit);
253 return lp.value_or(cp.value());
263 CR<git_oid> line_change_id)
const ->
bool {
265 auto line = get_period(line_change_id);
267 return line.value() == commit.value();
283 #endif // PROGRAM_STATE_HPP
SPtr< Logger > logger
main application logger entry
Definition: program_state.hpp:280
Str heads
Which repository branch to use.
Definition: program_state.hpp:172
Func< bool(CR< Str >)> allow_path
Allow processing of a specific path in the repository.
Definition: program_state.hpp:180
Func< int(CR< PTime >)> get_sampled_period
Definition: program_state.hpp:183
bool log_progress_bars
Definition: program_state.hpp:177
ir::CommitId get_id(CR< git_oid > oid)
Definition: program_state.hpp:231
BOOST_DESCRIBE_ENUM(Analytics, BlameBurndown, Commits, CommitDiffInfo)
std::unordered_map< git_oid, int > rev_periods
Mapping from the commits to the analysis periods they are in.
Definition: program_state.hpp:213
std::unordered_map< git_oid, ir::CommitId > sampled_commits
List of commits that were selected for the processing run.
Definition: program_state.hpp:274
Str db_path
Definition: program_state.hpp:175
std::unordered_map< git_oid, ir::CommitId > commit_ids
Definition: program_state.hpp:208
Func< int(CR< PTime >)> get_commit_period
Get integer index of the period for Date.
Definition: program_state.hpp:182
Str repo
Current project root path (absolute path)
Definition: program_state.hpp:170
@ Commits
Only information about commits.
Func< bool(CR< PTime >, CR< Str >, CR< Str >)> allow_sample
Check whether commits at the specified date should be analysed.
Definition: program_state.hpp:185
stime::time_point< stime::system_clock > TimePoint
stdlib time point alias
Definition: program_state.hpp:195
Vec< git_oid > full_commits
Ordered list of commits that were considered for the processing run.
Definition: program_state.hpp:207
bool use_analytics(Analytics which) const
Definition: program_state.hpp:187
boost::posix_time::ptime PTime
Definition: program_state.hpp:25
ir::content_manager * content
Definition: program_state.hpp:278
void add_id_mapping(CR< git_oid > oid, ir::CommitId id)
Definition: program_state.hpp:227
CP< walker_config > config
Definition: program_state.hpp:200
Opt< int > get_period(CR< git_oid > commit) const noexcept
Definition: program_state.hpp:237
auto consider_changed(CR< git_oid > commit_id, CR< git_oid > line_change_id) const -> bool
Definition: program_state.hpp:261
runtime configuration state object
Definition: program_state.hpp:161
Analytics
Different modes of repository analytics enabled in the application. Mapped to the --analytics command...
Definition: program_state.hpp:125
Mutable state passed around walker configurations.
Definition: program_state.hpp:199
int get_period(CR< git_oid > commit, CR< git_oid > line) const noexcept
get period the line was attributed to, otherwise fall back to the commit period
Definition: program_state.hpp:250
Definition: git_interface.hpp:165
logging::sources::severity_logger< logging::trivial::severity_level > Logger
Definition: logging.hpp:100
std::unordered_map< git_oid, int > rev_index
Definition: program_state.hpp:211
git_repository * repo
Current git repository.
Definition: program_state.hpp:204
threading_mode
Definition: program_state.hpp:167
Main store for repository analysis.
Definition: git_ir.hpp:238
const git_oid * commit_id(const git_commit *commit)
Definition: gitwrap.hpp:3841
concept IsDescribedEnum
Convenience concept for interfacing with 'described' enumeration types.
Definition: program_state.hpp:139
Vec< Analytics > analytics
Definition: program_state.hpp:173
std::mutex m
common mutex for synchronizing content manager mutations
Definition: program_state.hpp:277
boost::gregorian::date Date
Definition: program_state.hpp:24
void add_full_commit(CR< git_oid > oid, int period)
Definition: program_state.hpp:218
git_revwalk * walker
Definition: program_state.hpp:202
bool try_incremental
Definition: program_state.hpp:176
boost::posix_time::time_duration TimeDuration
Definition: program_state.hpp:26