src/main.cpp

changeset 4
82680ce258d6
parent 3
c87bde92805f
child 5
60c2588b4455
equal deleted inserted replaced
3:c87bde92805f 4:82680ce258d6
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "settings.h" 25 #include "settings.h"
26 #include "repositories.h" 26 #include "repositories.h"
27 #include "process.h"
27 28
28 #include <cstdlib> 29 #include <cstdlib>
29 #include <cstdio> 30 #include <cstdio>
30 #include <cstring> 31 #include <cstring>
31 #include <cerrno> 32 #include <cerrno>
129 static void print_html_footer() { 130 static void print_html_footer() {
130 puts("\t</body>\n</html>"); 131 puts("\t</body>\n</html>");
131 } 132 }
132 133
133 int main(int argc, char *argv[]) { 134 int main(int argc, char *argv[]) {
135 // parse settings
134 fm::settings settings; 136 fm::settings settings;
135
136 if (parse_args(settings, argc, argv)) { 137 if (parse_args(settings, argc, argv)) {
137 return EXIT_FAILURE; 138 return EXIT_FAILURE;
138 } 139 }
139 140
141 // check hg and git
142 fm::process proc;
143 proc.setbin(settings.hg);
144 if (proc.exec({"--version"})) {
145 fprintf(stderr, "Testing hg binary '%s' failed!\n", settings.hg.c_str());
146 return EXIT_FAILURE;
147 }
148 proc.setbin(settings.git);
149 if (proc.exec({"--version"})) {
150 fprintf(stderr, "Testing git binary '%s' failed!\n", settings.git.c_str());
151 return EXIT_FAILURE;
152 }
153
154 // scan for repos
140 fm::repositories repos; 155 fm::repositories repos;
141 for (auto &&path: settings.paths) { 156 for (auto &&path: settings.paths) {
142 repos.scan(path, settings.depth); 157 repos.scan(path, settings.depth);
143 } 158 }
144 if (!settings.update_repos) { 159
145 // TODO: update repositories 160 // update repos, if not disabled
161 if (settings.update_repos) {
162 for (auto &&repo : repos.list()) {
163 proc.chdir(repo.path);
164 if (repo.type == fm::HG) {
165 proc.setbin(settings.hg);
166 if (proc.exec({"pull"})) {
167 fprintf(stderr, "Pulling repo '%s' failed!\nMaybe there is no remote?\n", repo.path.c_str());
168 } else if (proc.exec({"update"})) {
169 fprintf(stderr, "Updating repo '%s' failed!\nMaybe there are local changes?\n", repo.path.c_str());
170 }
171 } else {
172 proc.setbin(settings.git);
173 if (proc.exec({"pull"})) {
174 fprintf(stderr, "Pulling repo '%s' failed!\nMaybe there is no remote or there are local changes?\n", repo.path.c_str());
175 }
176 }
177 }
146 } 178 }
147 // TODO: calculate the heat maps 179 // TODO: calculate the heat maps
148 180
149 print_html_header(); 181 print_html_header();
150 // TODO: output the heat maps here 182 // TODO: output the heat maps here

mercurial