Changeset 91


Ignore:
Timestamp:
Mar 23, 2006, 11:56:17 PM (15 years ago)
Author:
Jari Häkkinen
Message:

Fixes #4, #19, #32, #34: Started to implement subversion API usage.

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r84 r91  
    2222
    2323version 0.x:
     24  - Using subversion API instead of system calls.
    2425  - Added copyright statement to files.
    2526  - Proper version information is displayed using --version option.
  • trunk/bin/Makefile.am

    r84 r91  
    2828noinst_HEADERS = Parameter.h rmdirhier.h
    2929
    30 LDADD = @top_srcdir@/lib/libsvnstat.a
     30LDADD = @top_srcdir@/lib/libsvnstat.a -L/usr/local/apr/lib \
     31  -lsvn_client-1 -lsvn_wc-1 -lsvn_ra-1 -lsvn_subr-1 -lapr-0
    3132
    32 INCLUDES = -I@top_srcdir@/lib
     33INCLUDES = -I@top_srcdir@/lib -I/usr/local/include/subversion-1 -I/usr/local/apr/include/apr-0
     34
     35# Needed to compile svn API stuff
     36svnstat_CXXFLAGS = -Wno-long-long
    3337
    3438clean-local:
  • trunk/bin/svnstat.cc

    r84 r91  
    2323
    2424#include "Parameter.h"
     25
    2526#include "CommitStat.h"
    2627#include "Directory.h"
    2728#include "GnuplotFE.h"
    2829#include "rmdirhier.h"
     30#include "SVN.h"
    2931
    3032#include <stdexcept>
     
    5052  Parameter option(argc,argv);
    5153
     54  SVN* svn=SVN::instance();
     55  try {
     56    svn->setup_wc_adm_access(option.root());
     57  }
     58  catch (SVNException e) {
     59    std::cerr << "\nsvtstat: " << e.what() << "\nsvnstat: " << option.root()
     60              << " is not under subversion control\n" << std::endl;
     61    exit(-1);
     62  }
     63
    5264  if (createdir(option.targetdir(),option.force())) {
    5365    std::cerr << "\nFailed to create target directory '" << option.targetdir()
     
    6375    GnuplotFE::instance()->set_dates(cs.date());
    6476  }
    65  
    66   string prefix("svnstat_");
    67   Directory tree(option.root(),prefix);
    68   tree.purge(option.verbose());
     77
     78  Directory tree(option.root(),"svnstat_");
    6979  tree.parse(option.verbose());
    7080
  • trunk/lib/Directory.cc

    r84 r91  
    2525#include "File.h"
    2626#include "Node.h"
     27#include "SVN.h"
    2728
    2829#include <algorithm>
     
    4041namespace svnstat{
    4142
     43
    4244  Directory::Directory(const std::string& path, const std::string& output)
    4345    : Node(path,output)
     
    4547    using namespace std;
    4648    DIR* directory=opendir(path.c_str());    // C API from dirent.h
    47     if (!directory) {
    48       // Jari, throw exception
    49       cerr << "ERROR: opendir() failed; terminating" << endl;
    50       exit(1);
    51     }
     49    if (!directory)
     50      throw NodeException("ERROR: opendir() failed; " + path +
     51                          " is not a directory");
    5252    list<string> entries;
    5353    struct dirent* entry;
     
    5555    while ((entry=readdir(directory)))       // C API from dirent.h
    5656      entries.push_back(string(entry->d_name));
    57     if (errno) {
    58       // Jari, throw exception
    59       cerr << "ERROR: readdir() failure; terminating" << endl;
    60       exit(1);
    61     }
     57    if (errno)
     58      throw NodeException("ERROR: readdir() failed on " + path);
    6259    closedir(directory);
    6360
    64     // Jari, change this to some STL algo?
     61    SVN* svn=SVN::instance();
    6562    for (list<string>::iterator i=entries.begin(); i!=entries.end(); i++)
    6663      if ((*i)!=string(".") && (*i)!=string("..") && (*i)!=string(".svn")) {
    6764        string fullpath(path_+'/'+(*i));
    68         struct stat nodestat;                // C api from sys/stat.h
    69         lstat(fullpath.c_str(),&nodestat);   // C api from sys/stat.h
    70         if (S_ISDIR(nodestat.st_mode))       // C api from sys/stat.h
    71           daughters_.push_back(new Directory(fullpath, output_name()+"_"));
    72         else
    73           daughters_.push_back(new File(fullpath,output_name()+"_"));
     65        switch (svn->version_controlled(fullpath)) {
     66        case SVN::uptodate:
     67          struct stat nodestat;                // C api from sys/stat.h
     68          lstat(fullpath.c_str(),&nodestat);   // C api from sys/stat.h
     69          if (S_ISDIR(nodestat.st_mode))       // C api from sys/stat.h
     70            daughters_.push_back(new Directory(fullpath, output_name()+"_"));
     71          else
     72            daughters_.push_back(new File(fullpath,output_name()+"_"));
     73          break;
     74        case SVN::unresolved:
     75          throw NodeException(fullpath+" is not up to date");
     76        case SVN::unversioned: ; // do nothing
     77        }
    7478      }
    7579  }
     
    122126  }
    123127
    124   void Directory::purge(const bool verbose)
    125   {
    126     if (verbose)
    127       std::cout << "Purging " << path_ << std::endl;
    128     for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); )
    129       if (!((*i)->subversion_controlled())) {
    130         delete *i;
    131         i=daughters_.erase(i);
    132       }
    133       else {
    134         (*i)->purge(verbose);
    135         i++;
    136       }
    137   }
    138 
    139128}} // end of namespace svnstat and namespace theplu
  • trunk/lib/Directory.h

    r84 r91  
    3939  {
    4040  public:
     41
    4142    ///
    4243    /// @brief Constructor
     
    6263    void print(const bool verbose=false) const;
    6364
    64     void purge(const bool verbose=false);
    65 
    6665  private:
    6766    ///
     
    7069    Directory(const Directory&);
    7170
    72     typedef std::list<Node*>::iterator NodeIterator;
    73     typedef std::list<Node*>::const_iterator NodeConstIter_;
    74     std::list<Node*> daughters_;
     71    typedef std::list<Node*> NodeContainer;
     72    typedef NodeContainer::iterator NodeIterator;
     73    typedef NodeContainer::const_iterator NodeConstIterator;
     74    NodeContainer daughters_;
    7575  };
    7676
  • trunk/lib/Makefile.am

    r84 r91  
    33## $Id$
    44
    5 # Copyright (C) 2005, 2006 Jari Häkkinen
     5# Copyright (C) 2005 Jari Häkkinen
     6# Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    67#
    78# This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat
     
    2526
    2627noinst_HEADERS = CommitStat.h Directory.h File.h Gnuplot.h GnuplotFE.h  \
    27   Node.h Stats.h utility.h
     28  Node.h Stats.h SVN.h utility.h
    2829
    2930libsvnstat_a_SOURCES = CommitStat.cc Directory.cc File.cc Gnuplot.cc  \
    30   GnuplotFE.cc Node.cc Stats.cc utility.cc
     31  GnuplotFE.cc Node.cc Stats.cc SVN.cc utility.cc
     32
     33INCLUDES = -I/usr/local/include/subversion-1 -I/usr/local/apr/include/apr-0
     34
     35# Needed to compile svn API stuff
     36libsvnstat_a_CXXFLAGS = -Wno-long-long
  • trunk/lib/Node.cc

    r84 r91  
    6666
    6767
    68   bool Node::subversion_controlled(void) const
    69   {
    70     std::string system_call = "svn proplist " + path_ + ">&/dev/null";
    71     return !system(system_call.c_str());
    72   }
    73 
    7468}} // end of namespace svnstat and namespace theplu
  • trunk/lib/Node.h

    r84 r91  
    2929#include <ostream>
    3030#include <sstream>
     31#include <stdexcept>
    3132#include <string>
    3233
    3334namespace theplu{
    3435namespace svnstat{
     36
     37  ///
     38  /// If something goes wrong in the use of the Node or its derived
     39  /// classes, a NodeException is thrown.
     40  ///
     41  struct NodeException : public std::runtime_error
     42  { inline NodeException(const std::string& msg) : runtime_error(msg) {} };
    3543
    3644  ///
     
    4048  {
    4149  public:
     50
     51    ///
     52    /// @brief Constructor
     53    ///
     54    //    Node(void) : path_("JARI_trixar"), stats_("JARI_trixar") { };
     55
    4256    ///
    4357    /// @brief Constructor
     
    7387    virtual const Stats& parse(const bool verbose=false)=0;
    7488
     89    inline const std::string& path(void) const { return path_; }
     90
    7591    ///
    7692    /// Function printing HTML in current working directory
    7793    ///
    7894    virtual void print(const bool verbose=false) const=0;
    79 
    80     ///
    81     ///
    82     ///
    83     inline virtual void purge(const bool verbose=false)
    84     { /* Nothing to be done */ };
    85 
    86     ///
    87     /// Check if the node is under subversion control. This is done by
    88     /// checking the return status of 'svn proplist <Node>.
    89     ///
    90     /// @return True if subversion controlled, false otherwise.
    91     ///
    92     bool subversion_controlled(void) const;
    9395
    9496  protected:
Note: See TracChangeset for help on using the changeset viewer.