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