Changeset 225 for trunk


Ignore:
Timestamp:
Mar 11, 2007, 12:41:51 PM (15 years ago)
Author:
Peter Johansson
Message:

copyright based on log is printed to cout refs #36

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/Parameter.h

    r198 r225  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2007 Peter Johansson
    89
    910  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    2526*/
    2627
     28#include <map>
    2729#include <string>
    2830
     
    3537    Parameter(const int argc,const char *argv[]);
    3638    inline bool copyright(void) const { return copyright_; }
     39    /// @todo
     40    inline const std::map<std::string, std::string>
     41    copyright_alias(void) const { return copyright_alias_; }
    3742    inline bool force(void) const { return force_; }
    3843    inline bool revisions(void) const { return revisions_; }
     
    5055
    5156    bool copyright_;
     57    std::map<std::string, std::string> copyright_alias_;
    5258    bool force_;
    5359    bool revisions_;
  • trunk/bin/svndigest.cc

    r223 r225  
    126126    exit(-1);
    127127  }
     128  // Is this line needed?
     129  svn->setup_ra_session(repo);
     130  std::vector<std::string> authors=svn->authors(repo);
    128131
    129132  // remove target if needed
     
    159162  if (option->copyright()){
    160163    try {
    161       tree.print_copyright(commit_dates);
     164      tree.print_copyright(commit_dates, authors);
    162165    }
    163166    catch (const std::runtime_error& x) {
  • trunk/lib/Directory.cc

    r213 r225  
    33/*
    44  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2007 Peter Johansson
    56
    67  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    222223
    223224
    224   void Directory::print_copyright(const std::vector<std::string>& dates) const
     225  void Directory::print_copyright(const std::vector<std::string>& dates,
     226                                  const std::vector<std::string>& authors) const
    225227  {
    226228    if (!ignore()){
    227229      // print daughter nodes, i.e, this function is recursive
    228230      for (NodeConstIterator i = daughters_.begin(); i!=daughters_.end(); ++i)
    229         (*i)->print_copyright(dates);
     231        (*i)->print_copyright(dates, authors);
    230232    }
    231233  }
  • trunk/lib/Directory.h

    r207 r225  
    7979    void print(const bool verbose=false) const;
    8080
    81     void print_copyright(const std::vector<std::string>& dates) const;
    82 
     81    void print_copyright(const std::vector<std::string>& dates,
     82                         const std::vector<std::string>& author) const;
    8383  private:
    8484    ///
  • trunk/lib/File.cc

    r213 r225  
    33/*
    44  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
     5  Copyright (C) 2007 Peter Johansson
    56
    67  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    2526#include "html_utility.h"
    2627#include "Stats.h"
     28#include "SVN.h"
    2729
    2830#include <cassert>
     31#include <ctime>
    2932#include <fstream>
    3033#include <iostream>
     
    150153
    151154
    152   void File::print_copyright(const std::vector<std::string>& dates) const
     155  void File::print_copyright(const std::vector<std::string>& dates,
     156                             const std::vector<std::string>& authors) const
    153157  {
    154158    if (ignore())
    155159      return;
    156     std::cout << "\nCOPYRIGHT " << local_path() << std::endl;
    157     // last rev and 4-chars string for each year
    158     std::vector<std::pair<size_t,std::string> > years;
    159     for (size_t i=1; i<dates.size(); ++i) // ignoring rev 0
    160       if (years.empty() || years.back().second != dates[i].substr(0,4)){
    161         years.push_back(std::pair<size_t,std::string>(i,dates[i].substr(0,4)));
    162       }
    163       else {
    164         years.back() = std::pair<size_t, std::string>(i, dates[i].substr(0,4));
     160    assert(dates.size()==authors.size());
     161    using namespace std;
     162    SVN* svn=SVN::instance();
     163    vector<size_t> rev=svn->revisions(path());
     164
     165    typedef map<int, set<string> > Container;
     166    Container copyright;
     167    for (vector<size_t>::iterator i=rev.begin(); i!=rev.end(); ++i) {
     168      assert(*i<dates.size());
     169      time_t sec = str2time(dates[*i]);
     170      tm* timeinfo = gmtime(&sec);
     171      copyright[timeinfo->tm_year].insert(authors[*i]);
     172    }
     173   
     174    string prefix;
     175
     176    for (Container::const_iterator i=copyright.begin(); i!=copyright.end();) {
     177      cout << prefix << "Copyright (C) "
     178           << 1900+i->first;
     179      Container::const_iterator j = i;
     180      while (++j!=copyright.end() && i->second == j->second){
     181        cout << ", " << 1900+j->first;
    165182      }
     183     
     184      // printing authors
     185      for (set<string>::iterator a=i->second.begin(); a!=i->second.end(); ++a) {
     186        if (a!=i->second.begin())
     187          cout << ",";
     188        cout << " " << *a;
     189      }
     190      cout << "\n";
     191      i = j;
     192    }
    166193
    167     // copyrigt[i] is set of contributors for year 'i'
    168     std::vector<std::set<std::string> > copyright;
    169     copyright.resize(years.size());
    170     for (std::set<std::string>::const_iterator au=stats_.authors().begin();
    171          au!=stats_.authors().end(); ++au){
    172       std::vector<u_int> lines = stats_.total(*au);
    173       assert(!lines.empty());
    174       // insert author for 'year zero'
    175       if (lines[years[0].first]>0 ){
    176         copyright[0].insert(*au);
    177       }
    178       // insert authors for remaining years
    179       for (size_t y=1; y<years.size(); ++y)
    180         if (lines[years[y].first]!=lines[years[y-1].first] ){
    181           copyright[y].insert(*au);
    182         }
    183      
    184     }
    185     // looping over years
    186     for (size_t i = 0; i<copyright.size();++i){
    187       if (copyright[i].empty()){
    188         continue;
    189       }
    190 
    191       std::cout << "Copyright (C) " << years[i].second;
    192       for (size_t j=i+1; j<copyright.size(); ++j){
    193         if (copyright[j].empty())
    194           continue;
    195         else if (copyright[j]==copyright[i]){
    196           std::cout << ", " << years[j].second;
    197           i=j;
    198         }
    199         else
    200           break;
    201       }
    202       std::cout << " ";
    203      
    204       for (std::set<std::string>::const_iterator iter=copyright[i].begin();
    205            iter!=copyright[i].end(); ++iter){
    206         if (iter!=copyright[i].begin())
    207           std::cout << ", ";
    208         std::cout << *iter;
    209        
    210       }
    211       std::cout << std::endl;
    212     }
    213194  }
    214195}} // end of namespace svndigest and namespace theplu
  • trunk/lib/File.h

    r207 r225  
    66/*
    77  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2007 Peter Johansson
    89
    910  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    6970    void print_blame(std::ofstream&, const std::string line_type) const;
    7071
    71     void print_copyright(const std::vector<std::string>&) const;
    72 
     72    void print_copyright(const std::vector<std::string>&,
     73                         const std::vector<std::string>&) const;
    7374  private:
    7475
  • trunk/lib/Node.h

    r213 r225  
    66/*
    77  Copyright (C) 2005, 2006 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2007 Peter Johansson
    89
    910  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    140141    virtual void print(const bool verbose=false) const=0;
    141142
    142     virtual void print_copyright(const std::vector<std::string>& dates) const=0;
     143    virtual void print_copyright(const std::vector<std::string>& dates,
     144                                 const std::vector<std::string>& author) const=0;
    143145
    144146    /**
  • trunk/lib/SVN.cc

    r195 r225  
    33/*
    44  Copyright (C) 2006 Jari Häkkinen
     5  Copyright (C) 2007 Peter Johansson
    56
    67  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    2728#include <string>
    2829#include <vector>
     30
     31#include <iostream>
    2932
    3033#include <apr_allocator.h>
     
    204207    struct log_receiver_baton lb;
    205208    lb.commit_dates.reserve(head.value.number+1); // revision 0 is also stored.
     209    lb.authors.reserve(head.value.number+1); // revision 0 is also stored.
     210    lb.rev.reserve(head.value.number+1); // revision 0 is also stored.
    206211    if ((err=svn_client_log3(apr_path, &peg, &start, &head, 0, false, true,
    207212                             log_message_receiver, static_cast<void*>(&lb),
     
    211216    svn_pool_destroy(subpool);
    212217    return lb.commit_dates;
     218  }
     219
     220
     221  std::vector<std::string> SVN::authors(const std::string& path)
     222  {
     223    // Allocate space in subpool to pool_ for apr_path (here a string).
     224    apr_pool_t *subpool = svn_pool_create(pool_);
     225    apr_array_header_t* apr_path=apr_array_make(subpool,1,4);
     226    // Copy path to apr_path.
     227    (*((const char **) apr_array_push(apr_path))) =
     228      apr_pstrdup(subpool, svn_path_internal_style(path.c_str(),subpool));
     229
     230    // Setup to retrieve all commit logs.
     231    svn_opt_revision_t peg, start, head;
     232    peg.kind=svn_opt_revision_unspecified;
     233    start.kind=svn_opt_revision_number;
     234    start.value.number=0;
     235    head.kind=svn_opt_revision_head;
     236    svn_error_t* err=NULL;
     237    // Retrieving the last revision is only needed for the reserve
     238    // call below, not needed for the functionality here.
     239    if ((err=svn_ra_get_latest_revnum(ra_session_, &(head.value.number),
     240                                      subpool)))
     241      cleanup(err, subpool, "commit_dates: svn_ra_get_latest_revnum failed");
     242    // The struct we want to pass through to all log_message_receiver
     243    // calls, here we only want to push all commit dates into a
     244    // std::vector<std::string>.
     245    struct log_receiver_baton lb;
     246    lb.commit_dates.reserve(head.value.number+1); // revision 0 is also stored.
     247    lb.authors.reserve(head.value.number+1); // revision 0 is also stored.
     248    lb.rev.reserve(head.value.number+1); // revision 0 is also stored.
     249    if ((err=svn_client_log3(apr_path, &peg, &start, &head, 0, false, true,
     250                             log_message_receiver, static_cast<void*>(&lb),
     251                             context_, subpool)))
     252      // cleanupp will throw an exception
     253      cleanup(err, subpool, "commit_dates: svn_client_log3 failed");
     254    svn_pool_destroy(subpool);
     255    return lb.authors;
     256  }
     257
     258
     259  std::vector<size_t> SVN::revisions(const std::string& path)
     260  {
     261    // Allocate space in subpool to pool_ for apr_path (here a string).
     262    apr_pool_t *subpool = svn_pool_create(pool_);
     263    apr_array_header_t* apr_path=apr_array_make(subpool,1,4);
     264    // Copy path to apr_path.
     265    (*((const char **) apr_array_push(apr_path))) =
     266      apr_pstrdup(subpool, svn_path_internal_style(path.c_str(),subpool));
     267
     268    // Setup to retrieve all commit logs.
     269    svn_opt_revision_t peg, start, head;
     270    peg.kind=svn_opt_revision_unspecified;
     271    start.kind=svn_opt_revision_number;
     272    start.value.number=0;
     273    head.kind=svn_opt_revision_head;
     274    svn_error_t* err=NULL;
     275    // Retrieving the last revision is only needed for the reserve
     276    // call below, not needed for the functionality here.
     277    if ((err=svn_ra_get_latest_revnum(ra_session_, &(head.value.number),
     278                                      subpool)))
     279      cleanup(err, subpool, "commit_dates: svn_ra_get_latest_revnum failed");
     280    // The struct we want to pass through to all log_message_receiver
     281    // calls, here we only want to push all commit dates into a
     282    // std::vector<std::string>.
     283    struct log_receiver_baton lb;
     284    lb.commit_dates.reserve(head.value.number+1); // revision 0 is also stored.
     285    lb.authors.reserve(head.value.number+1); // revision 0 is also stored.
     286    lb.rev.reserve(head.value.number+1); // revision 0 is also stored.
     287    if ((err=svn_client_log3(apr_path, &peg, &start, &head, 0, false, true,
     288                             log_message_receiver, static_cast<void*>(&lb),
     289                             context_, subpool)))
     290      // cleanupp will throw an exception
     291      cleanup(err, subpool, "commit_dates: svn_client_log3 failed");
     292    svn_pool_destroy(subpool);
     293    return lb.rev;
    213294  }
    214295
     
    244325    else
    245326      throw SVNException("No date defined for revision: " + rev);
     327    if (author && author[0])
     328      lb->authors.push_back(author);
     329    else
     330      lb->authors.push_back("");
     331    lb->rev.push_back(rev);
     332
    246333    return SVN_NO_ERROR;
    247334  }
  • trunk/lib/SVN.h

    r191 r225  
    66/*
    77  Copyright (C) 2006 Jari Häkkinen
     8  Copyright (C) 2007 Peter Johansson
    89
    910  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
     
    137138
    138139    ///
     140    /// similar to commit_dates
     141    ///
     142    std::vector<std::string> authors(const std::string& path);
     143    std::vector<size_t> revisions(const std::string& path);
     144
     145    ///
    139146    /// @brief Get an instance of SVN.
    140147    ///
     
    212219    // Log message receiver
    213220    struct log_receiver_baton {
     221      std::vector<std::string> authors;
    214222      std::vector<std::string> commit_dates;
     223      std::vector<std::string> msg;
     224      std::vector<size_t> rev;
    215225    };
    216226    static svn_error_t *
  • trunk/lib/html_utility.cc

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
  • trunk/lib/html_utility.h

    r223 r225  
    55
    66/*
    7   Copyright (C) 2006 Peter Johansson
     7  Copyright (C) 2006, 2007 Peter Johansson
    88
    99  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
Note: See TracChangeset for help on using the changeset viewer.