source: trunk/lib/SVNproperty.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: 4.1 KB
Line 
1// $Id: SVNproperty.cc 1515 2012-09-26 00:35:10Z 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 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
39namespace theplu {
40namespace 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      trim(first);
101      std::string second;
102      bool found_dash = getline(ss2, second);
103      trim(second);
104      yat::utility::Segment<svn_revnum_t> rev_interval;
105      if (!found_dash) {
106        rev_interval.begin() = convert<svn_revnum_t>(first);
107        rev_interval.end() = rev_interval.begin()+1;
108      }
109      else {
110        if (first.empty())
111          rev_interval.begin() = 0;
112        else
113          rev_interval.begin() = convert<svn_revnum_t>(first);
114        if (second.empty())
115          rev_interval.end() = std::numeric_limits<svn_revnum_t>::max();
116        else
117          rev_interval.end() = convert<svn_revnum_t>(second)+1;
118      }
119      svncopyright_ignore_rev_.insert_merge(rev_interval);
120    }
121  }
122
123
124  void SVNproperty::add_svndigest_ignore(const std::string& value)
125  {
126    if (value.empty() || value=="*") {
127      svndigest_ignore_rev_ = std::numeric_limits<svn_revnum_t>::max();
128      return;
129    }
130    svndigest_ignore_rev_ = convert<svn_revnum_t>(value);
131  }
132
133
134  bool SVNproperty::binary(void) const
135  {
136    return binary_;
137  }
138
139
140  bool SVNproperty::svndigest_ignore(void) const
141  {
142    return svndigest_ignore_rev_==std::numeric_limits<svn_revnum_t>::max();
143  }
144
145
146  svn_revnum_t SVNproperty::svndigest_ignore_rev(void) const
147  {
148    return svndigest_ignore_rev_;
149  }
150
151
152  bool SVNproperty::svncopyright_ignore(void) const
153  {
154    return svncopyright_ignore_;
155  }
156
157
158  const yat::utility::SegmentSet<svn_revnum_t>&
159  SVNproperty::svncopyright_ignore_rev(void) const
160  {
161    return svncopyright_ignore_rev_;
162  }
163
164}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.