source: trunk/lib/Directory.cc @ 1515

Last change on this file since 1515 was 1515, checked in by Peter Johansson, 9 years ago

update copyright years

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