1 | // $Id: main_utility.cc 1430 2011-12-17 01:48:11Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2010 Peter Johansson |
---|
5 | |
---|
6 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
7 | |
---|
8 | svndigest is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 3 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svndigest is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
20 | */ |
---|
21 | |
---|
22 | #include "main_utility.h" |
---|
23 | |
---|
24 | #include "Configuration.h" |
---|
25 | #include "CopyrightVisitor.h" |
---|
26 | #include "Node.h" |
---|
27 | #include "utility.h" |
---|
28 | |
---|
29 | #include "yat/utility.h" |
---|
30 | |
---|
31 | #include <cctype> |
---|
32 | #include <cassert> |
---|
33 | #include <fstream> |
---|
34 | #include <iostream> |
---|
35 | #include <string> |
---|
36 | #include <stdexcept> |
---|
37 | |
---|
38 | namespace theplu { |
---|
39 | namespace svndigest { |
---|
40 | |
---|
41 | void load_config(const std::string& file, bool verbose) |
---|
42 | { |
---|
43 | // Reading configuration file |
---|
44 | Configuration& config = Configuration::instance(); |
---|
45 | if (node_exist(file)) { |
---|
46 | std::ifstream is(file.c_str()); |
---|
47 | assert(is.good()); |
---|
48 | if (verbose) |
---|
49 | std::cout << "Reading configuration file: `" << file << "'\n"; |
---|
50 | try { |
---|
51 | config.load(is); |
---|
52 | } |
---|
53 | catch (std::runtime_error& e) { |
---|
54 | std::string msg = "invalid config file\n"; |
---|
55 | msg += e.what(); |
---|
56 | throw std::runtime_error(msg); |
---|
57 | } |
---|
58 | is.close(); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | void update_copyright(Node& tree, bool verbose, bool ignore_cache) |
---|
64 | { |
---|
65 | const Configuration& config = Configuration::instance(); |
---|
66 | std::map<std::string, Alias> alias(config.copyright_alias()); |
---|
67 | |
---|
68 | // map with last rev for every year |
---|
69 | std::map<int, svn_revnum_t> year2rev; |
---|
70 | // get log for entire project |
---|
71 | SVNlog log(SVNinfo(tree.path()).repos_root_url()); |
---|
72 | typedef SVNlog::container::const_iterator LogIterator; |
---|
73 | for (LogIterator i=log.commits().begin(); i!=log.commits().end(); ++i){ |
---|
74 | // grep everything prior first '-' |
---|
75 | std::string year = i->date().substr(0,i->date().find('-')); |
---|
76 | using yat::utility::convert; |
---|
77 | // ignore commits in repository not present in wc |
---|
78 | year2rev[convert<int>(year)-1900] = std::min(i->revision(), |
---|
79 | tree.last_changed_rev()); |
---|
80 | } |
---|
81 | |
---|
82 | CopyrightVisitor visitor(alias, verbose, year2rev, ignore_cache); |
---|
83 | tree.traverse(visitor); |
---|
84 | } |
---|
85 | |
---|
86 | }} // end of namespace svndigest and namespace theplu |
---|