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