Changeset 303 for trunk


Ignore:
Timestamp:
May 11, 2007, 10:13:00 PM (14 years ago)
Author:
Peter Johansson
Message:

Sorting authors in copyright statement in same order as stated in config file. fixes #172

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r297 r303  
    183183      if (option->verbose())
    184184        std::cout << "Updating copyright statements" << std::endl;
    185       std::map<std::string, std::string> alias(config.copyright_alias());
     185      std::map<std::string, Alias> alias(config.copyright_alias());
    186186      tree.print_copyright(alias);
    187187    }
  • trunk/lib/Configuration.cc

    r289 r303  
    3131#include <string>
    3232#include <sstream>
     33#include <stdexcept>
    3334#include <utility>
    3435
     
    4142  Configuration::Configuration(void)
    4243  {
     44  }
     45
     46
     47  const std::map<std::string,Alias>& Configuration::copyright_alias(void) const
     48  {
     49    return copyright_alias_;
    4350  }
    4451
     
    7279        getline(ss, tmp);
    7380        std::string name = trim(tmp);
    74         copyright_alias_[key] = name;
     81        std::map<std::string,Alias>::iterator iter =
     82          copyright_alias_.lower_bound(key);
     83        if (iter!=copyright_alias_.end() && iter->first==key){
     84          std::stringstream mess;
     85          mess << "svndigest: invalid config file: "
     86               << "in copright-alias section" << key + "defined twice.";
     87          throw std::runtime_error(mess.str());
     88        }
     89       
     90        // insert alias
     91        copyright_alias_.insert(iter,std::make_pair(key, Alias(name,copyright_alias_.size())));
    7592      }
    7693      else if (section == "trac"){
     
    126143       << "[copyright-alias]\n"
    127144       << "# jdoe = John Doe\n";
    128    
    129     typedef std::map<std::string, std::string> map;
    130     for (map::const_iterator i=conf.copyright_alias().begin();
    131          i!=conf.copyright_alias().end(); ++i) {
    132       os << i->first << " = " << i->second << " \n";
     145
     146    typedef std::vector<std::pair<std::string, Alias> > vector;
     147    vector vec;
     148    std::back_insert_iterator<vector> back_insert_iterator(vec);
     149    vec.reserve(conf.copyright_alias().size());
     150    std::copy(conf.copyright_alias().begin(), conf.copyright_alias().end(),
     151              back_insert_iterator);
     152    // sort with respect to Alias.id
     153    IdCompare id;
     154    PairSecondCompare<const std::string, Alias, IdCompare> comp(id);
     155    std::sort(vec.begin(),vec.end(), comp);
     156             
     157
     158    for (vector::const_iterator i(vec.begin()); i!=vec.end(); ++i) {
     159      os << i->first << " = " << i->second.name() << " \n";
    133160    }
    134161
  • trunk/lib/Configuration.h

    r289 r303  
    2525*/
    2626
     27#include "Alias.h"
     28
    2729#include <iostream>
    28 #include <map>
     30#include <vector>
    2931#include <string>
    3032#include <utility>
     
    5557    /// @brief Aliases for Copyright
    5658    ///
    57     inline const std::map<std::string, std::string>&
    58     copyright_alias(void) const { return copyright_alias_; }
     59    const std::map<std::string, Alias>& copyright_alias(void) const;
    5960
    6061    ///
     
    8283    static Configuration* instance_;
    8384
    84     std::map<std::string, std::string> copyright_alias_;
     85    std::map<std::string, Alias> copyright_alias_;
    8586
    8687    std::string trac_root_;
  • trunk/lib/Directory.cc

    r274 r303  
    2424
    2525#include "Directory.h"
     26
     27#include "Alias.h"
    2628#include "File.h"
    2729#include "html_utility.h"
     
    220222
    221223
    222   void Directory::print_copyright
    223   (std::map<std::string, std::string>& alias) const {
     224  void Directory::print_copyright(std::map<std::string, Alias>& alias) const {
    224225    if (!ignore()){
    225226      // print daughter nodes, i.e, this function is recursive
  • trunk/lib/Directory.h

    r258 r303  
    7979    const Stats& parse(const bool verbose=false);
    8080
    81     void print_copyright(std::map<std::string, std::string>&) const;
     81    void print_copyright(std::map<std::string, Alias>&) const;
    8282
    8383  private:
  • trunk/lib/File.cc

    r258 r303  
    2424
    2525#include "File.h"
     26
     27#include "Alias.h"
    2628#include "html_utility.h"
    2729#include "Stats.h"
     
    101103
    102104
    103   void File::print_copyright (std::map<std::string,std::string>& alias) const{
     105  void File::print_copyright(std::map<std::string, Alias>& alias) const
     106  {
    104107    if (ignore())
    105108      return;
     
    108111    SVNlog log(path());
    109112
    110     typedef map<int, set<string> > Container;
    111     Container copyright;
    112 
    113    
     113    map<int, set<Alias> > year_authors;
     114
    114115    assert(log.author().size()==log.date().size());
    115116    vector<string>::const_iterator author=log.author().begin();
     
    120121
    121122      // find username in map of aliases
    122       map<string, string>::iterator name = alias.lower_bound(*author);
     123      std::map<string,Alias>::iterator name(alias.lower_bound(*author));
     124
    123125      // if alias exist insert alias
    124126      if (name != alias.end() && name->first==*author)
    125         copyright[timeinfo->tm_year].insert(name->second);
     127        year_authors[timeinfo->tm_year].insert(name->second);
    126128      else {
    127129        // else insert user name
    128         copyright[timeinfo->tm_year].insert(*author);
     130        Alias a(*author,alias.size());
     131        year_authors[timeinfo->tm_year].insert(a);
    129132        std::cerr << "svndigest: warning: no copyright alias found for `"
    130133                  << *author << "`\n";
    131134        // insert alias to avoid multiple warnings.
    132         alias.insert(name, std::make_pair(*author, *author));
     135        alias.insert(name, std::make_pair(*author, a));
    133136      }
    134137    }
     
    176179          found_copyright = true;
    177180          // Printing copyright statement
    178           for (Container::const_iterator i=copyright.begin();
    179                i!=copyright.end();) {
    180             tmp << prefix << "Copyright (C) "
    181                 << 1900+i->first;
    182             Container::const_iterator j = i;
    183             assert(i!=copyright.end());
    184             while (++j!=copyright.end() && i->second == j->second){
    185               tmp << ", " << 1900+(j->first);
    186             }
    187             // printing authors
    188             for (set<string>::iterator a=i->second.begin();
    189                  a!=i->second.end(); ++a){
    190               if (a!=i->second.begin())
    191                 tmp << ",";
    192               tmp << " " << *a;
    193             }
    194             tmp << "\n";
    195             i = j;
     181          for (map<int, set<Alias> >::const_iterator i(year_authors.begin());
     182               i!=year_authors.end();) {
     183          tmp << prefix << "Copyright (C) "
     184              << 1900+i->first;
     185          map<int, set<Alias> >::const_iterator j = i;
     186          assert(i!=year_authors.end());
     187          while (++j!=year_authors.end() &&
     188                 i->second == j->second){
     189            tmp << ", " << 1900+(j->first);
     190          }
     191          // printing authors
     192          std::vector<Alias> vec_alias;
     193          back_insert_iterator<std::vector<Alias> > ii(vec_alias);
     194          std::copy(i->second.begin(), i->second.end(), ii);
     195          // sort with respect to id
     196          std::sort(vec_alias.begin(), vec_alias.end(), IdCompare());
     197          for (std::vector<Alias>::iterator a=vec_alias.begin();
     198               a!=vec_alias.end(); ++a){
     199            if (a!=vec_alias.begin())
     200              tmp << ",";
     201            tmp << " " << a->name();
     202          }
     203          tmp << "\n";
     204          i = j;
    196205          }
    197206        }
     
    203212    // finally move printed temporary file to original file
    204213    rename(tmpname, path().c_str());
     214   
    205215  }
    206216}} // end of namespace svndigest and namespace theplu
  • trunk/lib/File.h

    r259 r303  
    6666    void print_blame(std::ofstream&, const std::string line_type) const;
    6767
    68     void print_copyright(std::map<std::string, std::string>&) const;
     68    void print_copyright(std::map<std::string, Alias>&) const;
    6969
    7070  private:
  • trunk/lib/Makefile.am

    r286 r303  
    2626noinst_LTLIBRARIES = libsvndigest.la
    2727
    28 noinst_HEADERS = ColumnStream.h Commitment.h Configuration.h css.h\
     28noinst_HEADERS = Alias.h ColumnStream.h Commitment.h Configuration.h css.h\
    2929  Date.h Directory.h File.h first_page.h Gnuplot.h GnuplotFE.h \
    3030  HtmlStream.h html_utility.h Node.h Parser.h rmdirhier.h \
     
    3232  SVNinfo.h SVNlog.h SVNproperty.h Trac.h utility.h
    3333
    34 libsvndigest_la_SOURCES = ColumnStream.cc Commitment.cc Configuration.cc \
     34libsvndigest_la_SOURCES = Alias.cc ColumnStream.cc \
     35  Commitment.cc Configuration.cc \
    3536  css.cc Date.cc Directory.cc File.cc first_page.cc\
    3637  Gnuplot.cc GnuplotFE.cc HtmlStream.cc \
  • trunk/lib/Node.h

    r285 r303  
    3939namespace theplu{
    4040namespace svndigest{
     41
     42  class Alias;
    4143
    4244  ///
     
    145147    void print_author_summary(std::ostream&, std::string, const SVNlog&) const;
    146148
    147     virtual void
    148     print_copyright(std::map<std::string, std::string>&) const=0;
     149    virtual void print_copyright(std::map<std::string,Alias>& ) const=0;
    149150
    150151    /**
  • trunk/lib/utility.cc

    r297 r303  
    193193  {}
    194194   
    195 
    196195}} // end of namespace svndigest and namespace theplu
  • trunk/lib/utility.h

    r297 r303  
    222222              (!(y.second<x.second) && (x.first<y.first)));
    223223    }
     224  };
     225
     226  template <class T1,class T2, class T3>
     227  struct PairSecondCompare
     228  {
     229
     230    ///
     231    /// @brief Constructor
     232    ///
     233    explicit PairSecondCompare(const T3& comp)
     234      : compare_(comp) {}
     235
     236    ///
     237    /// @return true if x.second<y.second or (x.second==y.second and
     238    /// x.first<y.first)
     239    ///
     240    inline bool operator()(const std::pair<T1,T2>& x,
     241                           const std::pair<T1,T2>& y) const
     242    { return compare_(x.second,y.second); }
     243
     244  private:
     245    T3 compare_;
     246
    224247  };
    225248
Note: See TracChangeset for help on using the changeset viewer.