source: trunk/lib/main_utility.cc @ 1234

Last change on this file since 1234 was 1234, checked in by Peter Johansson, 12 years ago

refs #476. Merged visitor branch into trunk. Used 'svn merge /branches/visitor' because --reintegrate did (currently) not work on our repo. Since I could not merge as suggested in subversion manual, I reverted all mergeinfo properties to avoid future confusion by svn-client. This means (I think) that there will be no connection about this commit and the visitor branch, but to svn-client this will look like a large changeset (just like a merge in the old days).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1// $Id: main_utility.cc 1234 2010-10-23 16:41:33Z 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 <cctype>
30#include <cassert>
31#include <fstream>
32#include <iostream>
33#include <string>
34#include <stdexcept>
35
36namespace theplu {
37namespace svndigest {
38
39  void load_config(const std::string& file, bool verbose)
40  {
41    // Reading configuration file
42    Configuration& config = Configuration::instance();
43    if (node_exist(file)) {
44      std::ifstream is(file.c_str());
45      assert(is.good());
46      if (verbose)
47        std::cout << "Reading configuration file: `" << file << "'\n";
48      try { 
49        config.load(is);
50      }
51      catch (std::runtime_error& e) {
52        std::string msg = "invalid config file\n";
53        msg += e.what();
54        throw std::runtime_error(msg);
55      }
56      is.close();
57    }
58  }
59
60
61  void update_copyright(Node& tree, bool verbose, bool ignore_cache)
62  {
63    if (verbose)
64      std::cout << "Updating copyright statements" << std::endl;
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      time_t sec = str2time(i->date());
75      tm* timeinfo = gmtime(&sec);
76      // ignore commits in repository not present in wc
77      year2rev[timeinfo->tm_year] = std::min(i->revision(), 
78                                             tree.last_changed_rev());
79    }
80
81    CopyrightVisitor visitor(alias, verbose, year2rev, ignore_cache);
82    tree.traverse(visitor);
83  }
84
85}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.