1 | // $Id: SVNproperty.cc 1605 2020-07-13 00:03:58Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006 Jari Häkkinen |
---|
5 | Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson |
---|
6 | Copyright (C) 2010, 2011, 2012, 2020 Peter Johansson |
---|
7 | |
---|
8 | This file is part of svndigest, http://dev.thep.lu.se/svndigest |
---|
9 | |
---|
10 | svndigest is free software; you can redistribute it and/or modify it |
---|
11 | under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 3 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | svndigest is distributed in the hope that it will be useful, but |
---|
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "SVNproperty.h" |
---|
25 | |
---|
26 | #include "Configuration.h" |
---|
27 | #include "SVN.h" |
---|
28 | #include "utility.h" |
---|
29 | |
---|
30 | #include "yat/Exception.h" |
---|
31 | #include "yat/Segment.h" |
---|
32 | #include "yat/utility.h" |
---|
33 | |
---|
34 | #include <limits> |
---|
35 | #include <stdexcept> |
---|
36 | #include <sstream> |
---|
37 | #include <string> |
---|
38 | |
---|
39 | namespace theplu { |
---|
40 | namespace svndigest { |
---|
41 | |
---|
42 | using yat::utility::convert; |
---|
43 | |
---|
44 | SVNproperty::SVNproperty(const std::string& path) |
---|
45 | : binary_(false), svncopyright_ignore_(false), svndigest_ignore_rev_(0) |
---|
46 | { |
---|
47 | typedef std::map<std::string, std::string> str_map; |
---|
48 | str_map property; |
---|
49 | SVN::instance()->client_proplist(path, property); |
---|
50 | add(property.begin(), property.end()); |
---|
51 | const Configuration& config = Configuration::instance(); |
---|
52 | const str_map& props = config.svn_properties(file_name(path)); |
---|
53 | add(props.begin(), props.end()); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | void |
---|
58 | SVNproperty::add(std::map<std::string, std::string>::const_iterator i, |
---|
59 | std::map<std::string, std::string>::const_iterator last) |
---|
60 | { |
---|
61 | for ( ; i!=last ; ++i) { |
---|
62 | try { |
---|
63 | if (i->first == "svndigest:ignore") |
---|
64 | add_svndigest_ignore(i->second); |
---|
65 | else if (i->first == "svncopyright:ignore") |
---|
66 | add_svncopyright_ignore(i->second); |
---|
67 | else |
---|
68 | if ((i->first == "svn:mime-type") && |
---|
69 | (svn_mime_type_is_binary(i->second.c_str()))) |
---|
70 | binary_=true; |
---|
71 | } |
---|
72 | catch (yat::utility::runtime_error& e) { |
---|
73 | std::ostringstream ss; |
---|
74 | ss << "invalid value for property '" << i->first << "': '" |
---|
75 | << i->second << "'"; |
---|
76 | throw std::runtime_error(ss.str()); |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | void SVNproperty::add_svncopyright_ignore(const std::string& value) |
---|
83 | { |
---|
84 | // reset previous settings |
---|
85 | svncopyright_ignore_ = false; |
---|
86 | svncopyright_ignore_rev_.clear(); |
---|
87 | |
---|
88 | if (value.empty()) { |
---|
89 | svncopyright_ignore_ = true; |
---|
90 | return; |
---|
91 | } |
---|
92 | |
---|
93 | std::istringstream ss(value); |
---|
94 | std::string word; |
---|
95 | // entries delimited by ';' |
---|
96 | while (getline(ss, word, ';')) { |
---|
97 | std::istringstream ss2(word); |
---|
98 | std::string first; |
---|
99 | getline(ss2, first, '-'); |
---|
100 | bool found_dash = word.size()>first.size() && word[first.size()]=='-'; |
---|
101 | trim(first); |
---|
102 | std::string second; |
---|
103 | getline(ss2, second); |
---|
104 | trim(second); |
---|
105 | yat::utility::Segment<svn_revnum_t> rev_interval; |
---|
106 | if (!found_dash) { |
---|
107 | rev_interval.begin() = convert<svn_revnum_t>(first); |
---|
108 | rev_interval.end() = rev_interval.begin()+1; |
---|
109 | } |
---|
110 | else { |
---|
111 | if (first.empty()) |
---|
112 | rev_interval.begin() = 0; |
---|
113 | else |
---|
114 | rev_interval.begin() = convert<svn_revnum_t>(first); |
---|
115 | if (second.empty()) |
---|
116 | rev_interval.end() = std::numeric_limits<svn_revnum_t>::max(); |
---|
117 | else |
---|
118 | rev_interval.end() = convert<svn_revnum_t>(second)+1; |
---|
119 | } |
---|
120 | svncopyright_ignore_rev_.insert_merge(rev_interval); |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | void SVNproperty::add_svndigest_ignore(const std::string& value) |
---|
126 | { |
---|
127 | if (value.empty() || value=="*") { |
---|
128 | svndigest_ignore_rev_ = std::numeric_limits<svn_revnum_t>::max(); |
---|
129 | return; |
---|
130 | } |
---|
131 | svndigest_ignore_rev_ = convert<svn_revnum_t>(value); |
---|
132 | } |
---|
133 | |
---|
134 | |
---|
135 | bool SVNproperty::binary(void) const |
---|
136 | { |
---|
137 | return binary_; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | bool SVNproperty::svndigest_ignore(void) const |
---|
142 | { |
---|
143 | return svndigest_ignore_rev_==std::numeric_limits<svn_revnum_t>::max(); |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | svn_revnum_t SVNproperty::svndigest_ignore_rev(void) const |
---|
148 | { |
---|
149 | return svndigest_ignore_rev_; |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | bool SVNproperty::svncopyright_ignore(void) const |
---|
154 | { |
---|
155 | return svncopyright_ignore_; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | const yat::utility::SegmentSet<svn_revnum_t>& |
---|
160 | SVNproperty::svncopyright_ignore_rev(void) const |
---|
161 | { |
---|
162 | return svncopyright_ignore_rev_; |
---|
163 | } |
---|
164 | |
---|
165 | }} // end of namespace svndigest and namespace theplu |
---|