Changeset 129


Ignore:
Timestamp:
Aug 2, 2006, 7:56:18 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses ticket:23. Changed usage of 'svn info' to API calls.

Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svnstat.cc

    r123 r129  
    2828#include "rmdirhier.h"
    2929#include "SVN.h"
    30 #include "utility.h"
     30#include "SVNinfo.h"
    3131
    3232#include <iostream>
     33#include <fstream>
    3334#include <stdexcept>
    3435#include <string>
     
    6465  std::string repo;
    6566  try {
    66     repo=svn->repository(option->root());
     67    repo=SVNinfo(option->root()).repos_root_url();
    6768  }
    6869  catch (SVNException e) {
  • trunk/lib/Directory.cc

    r126 r129  
    9090  }
    9191
    92   std::string Directory::author(void) const
    93   {
    94     std::string a;
    95     u_int max_rev=0;
    96     for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); i++)
    97       if ((*i)->last_changed_rev()>max_rev){
    98         max_rev = (*i)->last_changed_rev();
    99         a = (*i)->author();
    100       }
    101     return a;
    102   }
    103 
    10492  bool Directory::dir(void) const
    10593  {
     
    112100  }
    113101
    114   u_int Directory::last_changed_rev(void) const
    115   {
    116     u_int max_rev=0;
    117     for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); i++)
    118       if ((*i)->last_changed_rev()>max_rev)
    119         max_rev = (*i)->last_changed_rev();
    120     return max_rev;
    121   }
    122 
    123102  const Stats& Directory::parse(const bool verbose)
    124103  {
    125     stats_.reset();
     104    stats_.reset();
    126105
    127106    // Directories give no contribution to statistics.
    128107    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); i++)
    129       stats_ += (*i)->parse(verbose);
    130     return stats_;
     108      stats_ += (*i)->parse(verbose);
     109    return stats_;
    131110  }
    132111
  • trunk/lib/Directory.h

    r125 r129  
    6161
    6262    ///
    63     /// @return author of last commit.
    64     ///
    65     std::string author(void) const;
    66 
    67     ///
    6863    /// @return true
    6964    ///
     
    7469    ///
    7570    std::string html_link(void) const;
    76    
    77     ///
    78     ///
    79     ///
    80     u_int last_changed_rev(void) const;
    8171
    8272    const Stats& parse(const bool verbose=false);
  • trunk/lib/File.cc

    r118 r129  
    2323
    2424#include "File.h"
    25 #include "Node.h"
    2625#include "Stats.h"
    27 #include "utility.h"
    2826
    2927#include <fstream>
    3028#include <iostream>
    31 #include <map>
    32 #include <sstream>
    3329#include <string>
    3430
     
    4743      std::cout << "Parsing " << path_ << std::endl;
    4844    stats_.reset();
    49 
    50     std::map<std::string,std::string> svn_info = info(path_);
    51     author_ = svn_info["Last Changed Author"];
    52     std::stringstream ss(svn_info["Last Changed Rev"]);
    53     ss >> revision_;
    54 
    5545    binary_ = stats_.parse(path_);
    56     return stats_;
     46    return stats_;
    5747  }
    5848
  • trunk/lib/File.h

    r112 r129  
    3232namespace svnstat{
    3333
    34   class File : public Node
    35   {
    36   public:
    37     ///
    38     /// @brief Default Constructor
    39     ///
     34  class File : public Node
     35  {
     36  public:
     37    ///
     38    /// @brief Default Constructor
     39    ///
    4040    File(const u_int level, const std::string& path,
    4141         const std::string& output="")
    4242      : Node(level,path,output), binary_(false), ignore_(false) {}
    43 
    44     ///
    45     ///
    46     ///
    47     std::string author(void) const { return author_; }
    4843
    4944    ///
     
    5348
    5449    ///
     50    /// @brief Parsing out information from svn repository
    5551    ///
     52    /// @return true if succesful
    5653    ///
    57     u_int last_changed_rev(void) const { return revision_; }
    58 
    59     ///
    60     /// Parsing out information from svn repository
    61     ///
    62     /// @return true if succesful
    63     ///
    64     const Stats& parse(const bool verbose=false);
     54    const Stats& parse(const bool verbose=false);
    6555
    6656    ///
     
    6959    void print(const bool verbose=false) const;
    7060
    71   private:
    72     ///
    73     /// @brief Parsing svn blame output
    74     ///
    75     /// @return true if parsing is succesful
    76     ///
    77     bool blame(void) const;
    78    
     61  private:
     62    ///
     63    /// @brief Parsing svn blame output
     64    ///
     65    /// @return true if parsing is succesful
     66    ///
     67    bool blame(void) const;
     68
    7969    ///
    8070    /// @brief Copy Constructor, not implemented
     
    8272    File(const File&);
    8373
    84     std::string author_;
    85     bool binary_;
     74    bool binary_;
    8675    bool ignore_;
    87     u_int revision_;
    88  
    89   };
     76  };
    9077
    9178}} // end of namespace svnstat and namespace theplu
  • trunk/lib/Makefile.am

    r123 r129  
    2626
    2727noinst_HEADERS = Directory.h File.h Gnuplot.h GnuplotFE.h Node.h  \
    28   Parser.h rmdirhier.h Stats.h SVN.h utility.h
     28  Parser.h rmdirhier.h Stats.h SVN.h SVNinfo.h utility.h
    2929
    3030libsvnstat_a_SOURCES = Directory.cc File.cc Gnuplot.cc GnuplotFE.cc \
    31   Node.cc Parser.cc rmdirhier.cc Stats.cc SVN.cc utility.cc
     31  Node.cc Parser.cc rmdirhier.cc Stats.cc SVN.cc SVNinfo.cc utility.cc
    3232
    3333INCLUDES = -I$(SVN_PATH)/include/subversion-1 -I$(APR_PATH)/include/apr-0
  • trunk/lib/Node.cc

    r120 r129  
    3636  Node::Node(const u_int level, const std::string& path,
    3737             const std::string& output="")
    38     : level_(level), path_(path), stats_(path)
     38    : level_(level), path_(path), stats_(path), svninfo_(path)
    3939  {
    4040    output_name_ = output+file_name(path_);
  • trunk/lib/Node.h

    r112 r129  
    2626
    2727#include "Stats.h"
     28#include "SVNinfo.h"
    2829#include "utility.h"
    2930
     
    6162
    6263    ///
     64    /// @brief Get the author of the latest commit.
    6365    ///
    64     ///
    65     virtual std::string author(void) const=0;
     66    std::string author(void) const { return svninfo_.last_changed_author(); }
    6667
    6768    ///
     
    8182
    8283    ///
     84    /// @brief Get the revision number of the latest commit.
    8385    ///
    84     ///
    85     virtual u_int last_changed_rev(void) const=0;
     86    svn_revnum_t last_changed_rev(void) const
     87    { return svninfo_.last_changed_rev(); }
    8688
    8789    ///
     
    9092    inline const std::string& output_name(void) const { return output_name_; }
    9193
    92     ///
    93     /// @brief parsing file using svn blame.
    94     ///
    95     virtual const Stats& parse(const bool verbose=false)=0;
     94    ///
     95    /// @brief parsing file using svn blame.
     96    ///
     97    virtual const Stats& parse(const bool verbose=false)=0;
    9698
    9799    inline const std::string& path(void) const { return path_; }
     
    102104    virtual void print(const bool verbose=false) const=0;
    103105
    104   protected:
     106  protected:
    105107
    106108    ///
     
    123125    u_int level_;
    124126    std::string output_name_; //without suffix
    125     std::string path_;
    126     Stats stats_;
     127    std::string path_;
     128    Stats stats_;
    127129
    128130  private:
     
    132134    Node(const Node&);
    133135
     136    SVNinfo svninfo_;
    134137  };
    135138
  • trunk/lib/SVN.cc

    r123 r129  
    155155
    156156  svn_error_t *
    157   SVN::info_receiver(void *baton, const char *, const svn_info_t *info,
    158                      apr_pool_t *)
    159   {
    160     if (!info || !info->repos_root_URL)
    161       throw SVNException("Failed to acquire repository root URL");
    162     static_cast<struct info_receiver_baton*>(baton)->repos_root_url=
    163       info->repos_root_URL;
    164     return SVN_NO_ERROR;
    165   }
    166 
    167 
    168   svn_error_t *
    169157  SVN::log_message_receiver(void *baton, apr_hash_t *changed_paths,
    170158                            svn_revnum_t rev, const char *author,
     
    177165      throw SVNException("No date defined for revision: " + rev);
    178166    return SVN_NO_ERROR;
    179   }
    180 
    181 
    182   std::string SVN::repository(const std::string& path)
    183   {
    184     struct info_receiver_baton ib;
    185     if (svn_client_info(path.c_str(), NULL, NULL, info_receiver,
    186                         static_cast<void*>(&ib), false, context_, pool_))
    187       throw SVNException("repository: svn_client_info failed");
    188     return ib.repos_root_url;
    189167  }
    190168
  • trunk/lib/SVN.h

    r123 r129  
    3838namespace svnstat {
    3939
    40   class Directory;
    41 
    4240  ///
    4341  /// If something goes wrong in the use of the SVN class, a
     
    7068    ///
    7169    ~SVN(void);
     70
     71    ///
     72    /// @Brief Call the underlying svn_client_info for \a path with \a
     73    /// receiver and \a baton.
     74    ///
     75    /// This function is called from SVNinfo to do 'svn info' on an
     76    /// item. The \a receiver and \a baton is defined in SVNinfo and
     77    /// the \a receiver is called by the underlying subversion API if
     78    /// \a path is under subversion control. The \a baton is used to
     79    /// communicate anonymous information through the API to the
     80    /// \a receiver.
     81    ///
     82    /// @see Subversion API documentation, SVNinfo
     83    ///
     84    inline void client_info(const std::string& path,
     85                            svn_info_receiver_t receiver, void *baton)
     86    {
     87      if (svn_client_info(path.c_str(), NULL, NULL, receiver, baton, false,
     88                          context_, pool_))
     89        throw SVNException("repository: svn_client_info failed");
     90    }
    7291
    7392    ///
     
    104123
    105124    ///
    106     /// @brief Determine the repository root URL for \a path.
    107     ///
    108     /// @throws SVNException if repository location cannot be
    109     /// determined.
    110     ///
    111     /// @return The repository root URL.
    112     ///
    113     std::string repository(const std::string& path);
    114 
    115     ///
    116125    /// @throws SVNException if session setup fails.
    117126    ///
     
    130139    ///
    131140    vc_status version_controlled(const std::string& path);
     141
    132142
    133143  private:
     
    152162    // Subversion API stuff
    153163
    154     // Info receiver
    155     struct info_receiver_baton {
    156       std::string repos_root_url;
    157     };
    158     static svn_error_t * info_receiver(void *baton, const char *path,
    159                                        const svn_info_t *info, apr_pool_t *pool);
    160 
    161164    // Log message receiver
    162165    struct log_receiver_baton {
  • trunk/lib/Stats.cc

    r118 r129  
    2424
    2525#include "Stats.h"
     26
    2627#include "GnuplotFE.h"
     28#include "SVNinfo.h"
    2729#include "utility.h"
    2830
     
    3436#include <map>
    3537#include <numeric>
    36 #include <sstream>
    3738#include <string>
    3839#include <unistd.h>
     
    4849  {
    4950    // Make sure latest revision is set properly
    50     std::map<std::string,std::string> svn_info = info(path);
    51     std::stringstream ss;
    52     ss << (svn_info.count("Revision") ? svn_info["Revision"] : "0");
    53     ss >> revision_;
    54     ss.clear();
    55     ss << (svn_info.count("Last Changed Rev") ? svn_info["Last Changed Rev"] : "0");
    56     ss >> last_changed_rev_;
     51    SVNinfo svn_info(path);
     52    revision_=svn_info.rev();
     53    last_changed_rev_=svn_info.last_changed_rev();
    5754  }
    5855
  • trunk/lib/Stats.h

    r118 r129  
    2828#include "Parser.h"
    2929
    30 #include <iostream>
     30#include <svn_types.h>
     31
    3132#include <map>
    32 #include <ostream>
    3333#include <set>
    3434#include <string>
     
    147147
    148148
    149     u_int revision_; // Should be the latest revision for whole project
    150     u_int last_changed_rev_; // Should be the latest revision for file
     149    svn_revnum_t revision_; // Should be the latest revision for whole project
     150    svn_revnum_t last_changed_rev_; // Should be the latest revision for file
    151151
    152152    std::set<std::string> authors_;
  • trunk/lib/utility.cc

    r126 r129  
    2323
    2424#include "utility.h"
    25 #include "rmdirhier.h"
    2625
    2726#include <fstream>
    28 #include <iostream>
    29 #include <map>
     27#include <iostream> // remove this when 'blame' is removed
    3028#include <sstream>
    3129#include <string>
     
    5452    return name;
    5553  }
    56 
    57   std::map<std::string, std::string> info(const std::string& path)
    58   {
    59     std::string mod_path=mod_str(path);
    60     std::string system_call="svn info " + mod_path +
    61       " 1> /tmp/svnstat.tmp 2> /dev/null";
    62     int system_return = system(system_call.c_str());
    63     if (system_return)
    64       return std::map<std::string, std::string>();
    65 
    66     std::ifstream is("/tmp/svnstat.tmp");
    67     std::string line;
    68     std::map<std::string, std::string> svn_info;
    69     while (getline(is,line)){
    70       std::stringstream ss(line);
    71       std::string tag;
    72       getline(ss,tag,':');
    73       ss >> svn_info[tag];
    74     }
    75     return svn_info;
    76   }
    7754
    7855  std::string mod_str(const std::string& str)
  • trunk/lib/utility.h

    r127 r129  
    2626
    2727#include <algorithm>
    28 #include <fstream>
    2928#include <functional>
    30 #include <map>
     29#include <iosfwd>
    3130#include <string>
    3231#include <utility>
     
    5352  ///
    5453  std::string file_name(const std::string&);
    55 
    56   ///
    57   /// Extracts information from 'svn info <node>'
    58   ///
    59   /// @note <node> must be in subversion control.
    60   ///
    61   std::map<std::string, std::string> info(const std::string&);
    6254
    6355  ///
Note: See TracChangeset for help on using the changeset viewer.