source: trunk/lib/Directory.cc @ 1470

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

merge patch release 0.9.5 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1// $Id: Directory.cc 1470 2012-03-19 07:18:49Z peter $
2
3/*
4  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Jari Häkkinen, Peter Johansson
5  Copyright (C) 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          std::cout << "uptodate\n";
73          struct stat nodestat;                // C api from sys/stat.h
74          lstat(fullpath,&nodestat);   // C api from sys/stat.h
75          if (S_ISDIR(nodestat.st_mode)) {     // C api from sys/stat.h
76            // ignore directory if it is not a daughter of 'path' in repo
77            std::string url = SVNinfo(fullpath).url();
78            if (mother_url != directory_name(url))
79              continue;
80            daughters_.push_back(new Directory(level_+1,fullpath,local_path()));
81          }
82          else
83            daughters_.push_back(new File(level_,fullpath,local_path()));
84          break;
85        case SVN::unresolved:
86          throw NodeException(fullpath+" is not up to date");
87        case SVN::unversioned: ; // do nothing
88        }
89      }
90    }
91    std::sort(daughters_.begin(), daughters_.end(), NodePtrLess());
92  }
93
94
95  Directory::~Directory(void)
96  {
97    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
98      delete *i;
99  }
100
101
102  void Directory::collect_stats(void)
103  {
104    stats_.reset();
105    for (NodeIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
106      if (!(*i)->svndigest_ignore()) {
107        stats_ += (*i)->stats();
108        (*i)->stats().reset();
109      }
110  }
111
112
113  bool Directory::dir(void) const
114  {
115    return true;
116  }
117
118
119  std::string Directory::href(void) const
120  { 
121    return name() + "/index.html";
122  }
123
124
125  svn_revnum_t Directory::last_changed_rev(void) const
126  {
127    svn_revnum_t res = svn_info().last_changed_rev();
128    for (NodeConstIterator i=daughters_.begin(); i!=daughters_.end(); ++i)
129      res = std::max(res, (*i)->last_changed_rev());
130    return res;
131  }
132
133
134  void Directory::log_core(SVNlog& log) const
135  {
136    for (NodeConstIterator i(daughters_.begin()); i != daughters_.end(); ++i)
137      log += (*i)->log();
138  }
139
140  std::string Directory::node_type(void) const
141  {
142    return std::string("directory");
143  }
144
145
146  void Directory::traverse(NodeVisitor& visitor)
147  {
148    if (visitor.enter(*this))
149      for (NodeIterator first=daughters_.begin(), end=daughters_.end();
150           first!=end; ++first)
151        (*first)->traverse(visitor);
152    visitor.leave(*this);
153  }
154
155
156}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.