Changeset 18 for trunk/lib


Ignore:
Timestamp:
Dec 30, 2005, 6:41:33 PM (17 years ago)
Author:
Jari Häkkinen
Message:

Directory tree created. Use purge() to remove non subversion controlled entries.

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Directory.cc

    r16 r18  
    77#include <iostream>
    88#include <iterator>
     9#include <list>
    910
    1011#include <errno.h>  // Needed to check error state below.
     
    2425      exit(1);
    2526    }
    26     vector<string> entries;
     27    list<string> entries;
    2728    struct dirent* entry;
    2829    errno=0;  // Global variable used by C to track errors.
     
    3738
    3839    // Jari, change this to some STL algo?
    39     for (vector<string>::iterator i=entries.begin(); i!=entries.end(); i++)
    40       if ((*i)!=string(".") && (*i)!=string("..")) {
     40    for (list<string>::iterator i=entries.begin(); i!=entries.end(); i++)
     41      if ((*i)!=string(".") && (*i)!=string("..") && (*i)!=string(".svn")) {
    4142        /// Jari, should test if directory in some other way
    42         DIR* dirtest=opendir(i->c_str());
     43        string fullpath(path_+'/'+(*i));
     44        DIR* dirtest=opendir(fullpath.c_str());
    4345        if (!dirtest)
    44           daughters_.push_back(new File(*i));
     46          daughters_.push_back(new File(fullpath));
    4547        else
    46           daughters_.push_back(new Directory(*i));
     48          daughters_.push_back(new Directory(fullpath));
    4749      }
    4850  }
     
    5254  {
    5355    // Jari, change this to some STL algo?
    54     for (std::vector<Node*>::iterator i=daughters_.begin();
     56    for (std::list<Node*>::iterator i=daughters_.begin();
    5557         i!=daughters_.end(); i++)
    5658      delete *i;
     
    6264    stats_.reset();
    6365
    64     for (size_t i = 0; i<daughters_.size(); i++)
    65       stats_ += daughters_[i]->parse();
     66    for (std::list<Node*>::iterator i=daughters_.begin();
     67         i!=daughters_.end(); i++)
     68      stats_ += (*i)->parse();
    6669    return stats_;
    6770  }
     
    7073  void Directory::print(void) {
    7174    // Jari, temporary using this to print directory tree
    72     std::cout << "-------------- Directory '" << path_ << "'" << std::endl;
    7375    for_each(daughters_.begin(),daughters_.end(), std::mem_fun(&Node::print));
    7476  }
    7577
     78
     79  void Directory::purge(void) {
     80    for (std::list<Node*>::iterator i=daughters_.begin(); i!=daughters_.end(); )
     81      if (!((*i)->subversion_controlled())) {
     82        delete *i;
     83        i=daughters_.erase(i);
     84      }
     85      else {
     86        (*i)->purge();
     87        i++;
     88      }
     89  }
     90
    7691}} // end of namespace svnstat and namespace theplu
  • trunk/lib/Directory.h

    r14 r18  
    66#include "Node.h"
    77
    8 #include <vector>
     8#include <list>
     9#include <string>
    910
    1011namespace theplu{
     
    2021    /// @brief Constructor
    2122    ///
     23    /// Recursively create a directory tree starting from \a
     24    /// path. Nodes named '.', '..', and '.svn' are ignored and not
     25    /// traversed.
     26    ///
    2227    Directory(const std::string& path);
    2328
     
    3136    void print(void);
    3237
     38    void purge(void);
     39
    3340  private:
    3441    ///
     
    3744    Directory(const Directory&);
    3845
    39     std::vector<Node*> daughters_;
     46    std::list<Node*> daughters_;
    4047  };
    4148
  • trunk/lib/Node.cc

    r16 r18  
    3737  }
    3838
    39  
     39
     40  bool Node::subversion_controlled(void) const {
     41    std::string system_call = "svn proplist " + path_ + ">&/dev/null";
     42    return !system(system_call.c_str());
     43  }
     44
    4045}} // end of namespace svnstat and namespace theplu
  • trunk/lib/Node.h

    r16 r18  
    3737    virtual void print(void)=0;
    3838
     39    inline virtual void purge(void) { /* Nothing to be done */ };
     40
    3941    ///
    40     /// Check if the node is under subversion control. If node
    41     /// is under subversion control, information about node is
    42     /// parsed from the 'svn info' output.
    43     ///
     42    /// Check if the node is under subversion control. This is done by
     43    /// checking the return status of 'svn proplist <Node>.
    4444    ///
    4545    /// @return True if subversion controlled, false otherwise.
    4646    ///
    47     bool subversion_controlled(void);
     47    bool subversion_controlled(void) const;
    4848
    4949  protected:
Note: See TracChangeset for help on using the changeset viewer.