source: trunk/lib/Directory.cc @ 1435

Last change on this file since 1435 was 1435, checked in by Jari Häkkinen, 10 years ago

Removed unused cassert and cerrno includes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1// $Id: Directory.cc 1435 2011-12-19 22:58:36Z jari $
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://dev.thep.lu.se/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "Directory.h"
23
24#include "Alias.h"
25#include "Configuration.h"
26#include "DirectoryUtil.h"
27#include "File.h"
28#include "html_utility.h"
29#include "Node.h"
30#include "NodeVisitor.h"
31#include "SVN.h"
32#include "SVNlog.h"
33#include "TinyStats.h"
34#include "utility.h"
35
36#include <algorithm>
37#include <fstream>
38#include <functional>
39#include <iostream>
40#include <iterator>
41#include <map>
42#include <sstream>
43#include <vector>
44
45#include <sys/stat.h>
46
47namespace theplu{
48namespace svndigest{
49
50
51  Directory::Directory(const unsigned int level, const std::string& path,
52                       const std::string& output, const std::string& project)
53    : Node(level,path,output,project)
54  {
55    output_dir_=local_path();
56    if (!output_dir_.empty())
57      output_dir_+='/';
58
59    DirectoryUtil dir(path);
60
61    SVN* svn=SVN::instance();
62    for (DirectoryUtil::const_iterator i=dir.begin(); i!=dir.end(); ++i) {
63      std::string fn = file_name(i->path());
64      if (fn!="." && fn!=".." && fn!=".svn") {
65        const std::string& fullpath = i->path();
66        switch(svn->version_controlled(fullpath)) {
67        case SVN::uptodate:
68          struct stat nodestat;                // C api from sys/stat.h
69          lstat(fullpath,&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(level_+1,fullpath,local_path()));
72          else
73            daughters_.push_back(new File(level_,fullpath,local_path()));
74          break;
75        case SVN::unresolved:
76          throw NodeException(fullpath+" is not up to date");
77        case SVN::unversioned: ; // do nothing
78        }
79      }
80    }
81    std::sort(daughters_.begin(), daughters_.end(), NodePtrLess());
82  }
83
84
85  Directory::~Directory(void)
86  {
87    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
88      delete *i;
89  }
90
91
92  void Directory::collect_stats(void)
93  {
94    stats_.reset();
95    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
96      if (!(*i)->ignore()) {
97        stats_ += (*i)->stats();
98        (*i)->stats().reset();
99      }
100  }
101
102
103  bool Directory::dir(void) const
104  {
105    return true;
106  }
107
108
109  std::string Directory::href(void) const
110  { 
111    return name() + "/index.html";
112  }
113
114
115  svn_revnum_t Directory::last_changed_rev(void) const
116  {
117    svn_revnum_t res = svn_info().last_changed_rev();
118    for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
119      res = std::max(res, (*i)->last_changed_rev());
120    return res;
121  }
122
123
124  void Directory::log_core(SVNlog& log) const
125  {
126    for (NodeConstIterator i(daughters_.begin()); i != daughters_.end(); ++i)
127      log += (*i)->log();
128  }
129
130  std::string Directory::node_type(void) const
131  {
132    return std::string("directory");
133  }
134
135
136  void Directory::traverse(NodeVisitor& visitor)
137  {
138    if (visitor.enter(*this))
139      for (NodeIterator first=daughters_.begin(), end=daughters_.end();
140           first!=end; ++first)
141        (*first)->traverse(visitor);
142    visitor.leave(*this);
143  }
144
145
146}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.