Obtain the list of commits and process them. */
| 1130 | /** Obtain the list of commits and process them. |
| 1131 | */ |
| 1132 | void processLog(const Options & options) |
| 1133 | { |
| 1134 | ResultWriter result; |
| 1135 | |
| 1136 | std::string command = "git log --reverse --no-merges --pretty=%H"; |
| 1137 | fmt::print("{}\n", command); |
| 1138 | auto git_log = ShellCommand::execute(command); |
| 1139 | |
| 1140 | /// Collect hashes in memory. This is inefficient but allows to display beautiful progress. |
| 1141 | /// The number of commits is in order of single millions for the largest repositories, |
| 1142 | /// so don't care about potential waste of ~100 MB of memory. |
| 1143 | |
| 1144 | std::vector<std::string> hashes; |
| 1145 | |
| 1146 | auto & in = git_log->out; |
| 1147 | while (!in.eof()) |
| 1148 | { |
| 1149 | std::string hash; |
| 1150 | readString(hash, in); |
| 1151 | assertChar('\n', in); |
| 1152 | |
| 1153 | if (!options.skip_commits.count(hash)) |
| 1154 | hashes.emplace_back(std::move(hash)); |
| 1155 | } |
| 1156 | |
| 1157 | size_t num_commits = hashes.size(); |
| 1158 | fmt::print("Total {} commits to process.\n", num_commits); |
| 1159 | |
| 1160 | /// Will run multiple processes in parallel |
| 1161 | size_t num_threads = options.threads; |
| 1162 | if (num_threads == 0) |
| 1163 | throw Exception("num-threads cannot be zero", ErrorCodes::INCORRECT_DATA); |
| 1164 | |
| 1165 | std::vector<std::unique_ptr<ShellCommand>> show_commands(num_threads); |
| 1166 | for (size_t i = 0; i < num_commits && i < num_threads; ++i) |
| 1167 | show_commands[i] = gitShow(hashes[i]); |
| 1168 | |
| 1169 | Snapshot snapshot; |
| 1170 | DiffHashes diff_hashes; |
| 1171 | |
| 1172 | for (size_t i = 0; i < num_commits; ++i) |
| 1173 | { |
| 1174 | processCommit(show_commands[i % num_threads]->out, options, i, num_commits, hashes[i], snapshot, diff_hashes, result); |
| 1175 | |
| 1176 | if (!options.stop_after_commit.empty() && hashes[i] == options.stop_after_commit) |
| 1177 | break; |
| 1178 | |
| 1179 | if (i + num_threads < num_commits) |
| 1180 | show_commands[i % num_threads] = gitShow(hashes[i + num_threads]); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | } |
no test coverage detected