37 |
13 Jan 06 |
peter |
// $Id$ |
37 |
13 Jan 06 |
peter |
2 |
|
84 |
13 Mar 06 |
jari |
3 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2009, 2010 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 |
|
960 |
07 Dec 09 |
peter |
23 |
#include <config.h> // this header file is created by configure |
960 |
07 Dec 09 |
peter |
24 |
|
37 |
13 Jan 06 |
peter |
25 |
#include "Parameter.h" |
234 |
09 Apr 07 |
peter |
26 |
|
1513 |
23 Sep 12 |
peter |
27 |
#include "lib/utility.h" |
795 |
30 Jun 09 |
peter |
28 |
|
795 |
30 Jun 09 |
peter |
29 |
#include "yat/ColumnStream.h" |
795 |
30 Jun 09 |
peter |
30 |
#include "yat/Exception.h" |
795 |
30 Jun 09 |
peter |
31 |
#include "yat/OptionArg.h" |
795 |
30 Jun 09 |
peter |
32 |
#include "yat/OptionHelp.h" |
795 |
30 Jun 09 |
peter |
33 |
#include "yat/OptionSwitch.h" |
795 |
30 Jun 09 |
peter |
34 |
|
540 |
29 Dec 07 |
peter |
35 |
#include <cstddef> |
727 |
11 Dec 08 |
jari |
36 |
#include <cstring> |
226 |
11 Mar 07 |
peter |
37 |
#include <fstream> |
37 |
13 Jan 06 |
peter |
38 |
#include <iostream> |
226 |
11 Mar 07 |
peter |
39 |
#include <sstream> |
49 |
14 Jan 06 |
jari |
40 |
#include <stdexcept> |
37 |
13 Jan 06 |
peter |
41 |
#include <string> |
104 |
27 Jun 06 |
peter |
42 |
#include <sys/stat.h> |
37 |
13 Jan 06 |
peter |
43 |
|
37 |
13 Jan 06 |
peter |
44 |
namespace theplu { |
149 |
12 Aug 06 |
jari |
45 |
namespace svndigest { |
37 |
13 Jan 06 |
peter |
46 |
|
1060 |
02 Jun 10 |
peter |
47 |
Parameter::Parameter(void) |
1513 |
23 Sep 12 |
peter |
48 |
: config_file_(cmd_, "config-file", |
820 |
12 Sep 09 |
peter |
49 |
"configuration file [<ROOT>/.svndigest/config]"), |
1513 |
23 Sep 12 |
peter |
50 |
generate_config_(cmd_, "g,generate-config", |
820 |
12 Sep 09 |
peter |
51 |
"write configuration to standard output"), |
1513 |
23 Sep 12 |
peter |
52 |
ignore_cache_(cmd_, "ignore-cache", |
820 |
12 Sep 09 |
peter |
53 |
std::string("ignore cache files and analyze ") + |
1293 |
14 Nov 10 |
peter |
54 |
std::string("everything from repository")) |
37 |
13 Jan 06 |
peter |
55 |
{ |
1060 |
02 Jun 10 |
peter |
56 |
} |
1060 |
02 Jun 10 |
peter |
57 |
|
1241 |
24 Oct 10 |
peter |
58 |
|
705 |
25 Nov 08 |
peter |
59 |
Parameter::~Parameter(void) |
705 |
25 Nov 08 |
peter |
60 |
{ |
705 |
25 Nov 08 |
peter |
61 |
} |
705 |
25 Nov 08 |
peter |
62 |
|
705 |
25 Nov 08 |
peter |
63 |
|
1293 |
14 Nov 10 |
peter |
64 |
void Parameter::analyse1(void) |
705 |
25 Nov 08 |
peter |
65 |
{ |
705 |
25 Nov 08 |
peter |
66 |
std::string save_wd = pwd(); |
705 |
25 Nov 08 |
peter |
67 |
|
705 |
25 Nov 08 |
peter |
// check root but not if -g option given |
705 |
25 Nov 08 |
peter |
69 |
if (!generate_config()) { |
1293 |
14 Nov 10 |
peter |
70 |
analyse_root(root_.value()); |
705 |
25 Nov 08 |
peter |
71 |
} |
705 |
25 Nov 08 |
peter |
72 |
|
705 |
25 Nov 08 |
peter |
// check config file |
708 |
26 Nov 08 |
peter |
74 |
struct stat nodestat; |
708 |
26 Nov 08 |
peter |
// true also if there is a broken symlink named... |
820 |
12 Sep 09 |
peter |
76 |
bool config_exists = !lstat(config_file_.value().c_str(), &nodestat); |
708 |
26 Nov 08 |
peter |
// the latter case in order to catch broken symlink |
820 |
12 Sep 09 |
peter |
78 |
if (config_file_.present() || config_exists) |
708 |
26 Nov 08 |
peter |
// throws if file does not exists |
820 |
12 Sep 09 |
peter |
80 |
check_existence(config_file_.value()); |
708 |
26 Nov 08 |
peter |
81 |
if (config_exists) { |
708 |
26 Nov 08 |
peter |
// throws if file is not readable |
820 |
12 Sep 09 |
peter |
83 |
check_readable(config_file_.value()); |
820 |
12 Sep 09 |
peter |
84 |
stat(config_file_.value().c_str(), &nodestat); |
1091 |
12 Jun 10 |
peter |
85 |
if (S_ISDIR(nodestat.st_mode)) { |
705 |
25 Nov 08 |
peter |
86 |
std::stringstream ss; |
1513 |
23 Sep 12 |
peter |
87 |
ss << cmd_.program_name() << ": '" << config_file_.value() |
1091 |
12 Jun 10 |
peter |
88 |
<< "' is a directory"; |
795 |
30 Jun 09 |
peter |
89 |
throw yat::utility::cmd_error(ss.str()); |
423 |
29 Jun 07 |
peter |
90 |
} |
705 |
25 Nov 08 |
peter |
91 |
} |
1060 |
02 Jun 10 |
peter |
92 |
analyse2(); |
626 |
23 Apr 08 |
peter |
93 |
} |
37 |
13 Jan 06 |
peter |
94 |
|
705 |
25 Nov 08 |
peter |
95 |
|
705 |
25 Nov 08 |
peter |
96 |
std::string Parameter::config_file(void) const |
37 |
13 Jan 06 |
peter |
97 |
{ |
820 |
12 Sep 09 |
peter |
98 |
return config_file_.value(); |
705 |
25 Nov 08 |
peter |
99 |
} |
151 |
13 Aug 06 |
jari |
100 |
|
151 |
13 Aug 06 |
jari |
101 |
|
705 |
25 Nov 08 |
peter |
102 |
bool Parameter::generate_config(void) const |
705 |
25 Nov 08 |
peter |
103 |
{ |
820 |
12 Sep 09 |
peter |
104 |
return generate_config_.present(); |
705 |
25 Nov 08 |
peter |
105 |
} |
116 |
30 Jun 06 |
peter |
106 |
|
229 |
25 Mar 07 |
peter |
107 |
|
705 |
25 Nov 08 |
peter |
108 |
bool Parameter::ignore_cache(void) const |
705 |
25 Nov 08 |
peter |
109 |
{ |
820 |
12 Sep 09 |
peter |
110 |
return ignore_cache_.present(); |
240 |
28 Apr 07 |
peter |
111 |
} |
229 |
25 Mar 07 |
peter |
112 |
|
240 |
28 Apr 07 |
peter |
113 |
|
1293 |
14 Nov 10 |
peter |
114 |
void Parameter::init1(void) |
240 |
28 Apr 07 |
peter |
115 |
{ |
820 |
12 Sep 09 |
peter |
116 |
config_file_.print_arg("=FILE"); |
1060 |
02 Jun 10 |
peter |
117 |
init2(); |
37 |
13 Jan 06 |
peter |
118 |
} |
37 |
13 Jan 06 |
peter |
119 |
|
37 |
13 Jan 06 |
peter |
120 |
|
1293 |
14 Nov 10 |
peter |
121 |
void Parameter::set_default1(void) |
73 |
04 Mar 06 |
jari |
122 |
{ |
1060 |
02 Jun 10 |
peter |
123 |
if (!config_file_.present()) |
1060 |
02 Jun 10 |
peter |
124 |
config_file_.value(concatenate_path(root_.value(),".svndigest/config")); |
280 |
06 May 07 |
peter |
125 |
|
1060 |
02 Jun 10 |
peter |
126 |
set_default2(); |
37 |
13 Jan 06 |
peter |
127 |
} |
37 |
13 Jan 06 |
peter |
128 |
|
626 |
23 Apr 08 |
peter |
129 |
|
442 |
16 Aug 07 |
peter |
130 |
}} // of namespace svndigest and namespace theplu |