SlHelpers
PatchesAuthors.h
1 // SPDX-License-Identifier: GPL-2.0-only
2 
3 #pragma once
4 
5 #include <filesystem>
6 #include <functional>
7 #include <map>
8 #include <optional>
9 #include <string>
10 #include <string_view>
11 #include <vector>
12 
13 namespace SlGit {
14 class Commit;
15 class Repo;
16 }
17 
18 namespace SlKernCVS {
19 
27 public:
29  using InsertUser = std::function<bool (const std::string &email)>;
31  using InsertUFMap = std::function<bool (const std::string &email,
32  std::filesystem::path &&file,
33  unsigned fixes, unsigned realFixes)>;
34 
41  PatchesAuthors(const SlGit::Repo &repo, bool dumpRefs, bool reportUnhandled) :
42  repo(&repo), dumpRefs(dumpRefs), reportUnhandled(reportUnhandled)
43  {}
44 
52  bool processAuthors(const SlGit::Commit &commit, const InsertUser &insertUser,
53  const InsertUFMap &insertUFMap);
54 private:
55  struct Counts {
56  unsigned fixes = 0;
57  unsigned realFixes = 0;
58  };
60  using Map = std::map<std::string, std::map<std::string, Counts>>;
62  using RefMap = std::map<std::string, std::map<std::string, unsigned int>>;
63 
64  PatchesAuthors() : repo(nullptr), dumpRefs(false), reportUnhandled(false) {}
65  friend void testProcessPatch();
66 
67  static constexpr std::string_view parseEmail(std::string_view line, std::size_t atSignPos);
68  static constexpr std::optional<std::string_view> isInterestingLine(std::string_view line);
69  static constexpr bool isGitFixes(std::string_view line);
70  static constexpr bool isReallyEmail(std::string_view line);
71  static constexpr bool isValidRef(std::string_view ref);
72  void storeParens(const char *&parenStart, std::string_view ref,
73  const std::vector<std::string> &patchEmails);
74  bool consumeParens(std::string_view ref, const char *&parenStart,
75  const std::vector<std::string> &patchEmails);
76 
77  int processPatch(const std::filesystem::path &file, const std::string &content);
78 
79  const SlGit::Repo *repo;
80  const bool dumpRefs;
81  const bool reportUnhandled;
82  Map m_emailFileCountMap;
83  RefMap m_emailRefCountMap;
84 };
85 
86 }
Definition: Blob.h:11
std::function< bool(const std::string &email, std::filesystem::path &&file, unsigned fixes, unsigned realFixes)> InsertUFMap
A callback invoked for e-mail, file, and counts of fixes and non-git-fixes.
Definition: PatchesAuthors.h:33
PatchesAuthors parses all patches in all ("build") branches in the kernel-source tree and reports who...
Definition: PatchesAuthors.h:26
The most important Git class.
Definition: Repo.h:45
Commit is a representation of a git commit.
Definition: Commit.h:21
PatchesAuthors(const SlGit::Repo &repo, bool dumpRefs, bool reportUnhandled)
PatchesAuthors constructor.
Definition: PatchesAuthors.h:41
Definition: Branches.h:15
bool processAuthors(const SlGit::Commit &commit, const InsertUser &insertUser, const InsertUFMap &insertUFMap)
The real work function of this class.
std::function< bool(const std::string &email)> InsertUser
A callback invoked for e-mail.
Definition: PatchesAuthors.h:29