Changeset 1152
- Timestamp:
- Aug 7, 2010, 4:31:18 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Configuration.cc
r1144 r1152 26 26 #include "Colors.h" 27 27 #include "Functor.h" 28 29 #include "yat/split.h" 28 30 29 31 #include <algorithm> … … 311 313 } 312 314 } 315 else if (section == "svn_props") { 316 svn_props_.push_back(std::make_pair(lhs, empty_str_map_)); 317 std::vector<std::string> vec; 318 yat::utility::split(vec, rhs, ';'); 319 for (size_t i=0; i<vec.size(); ++i) { 320 std::vector<std::string> vec2; 321 yat::utility::split(vec2, vec[i], '='); 322 std::string key = trim(vec2[0]); 323 std::string value(""); 324 if (vec2.size() >= 2) 325 value = trim(vec2[1]); 326 svn_props_.back().second[key] = value; 327 } 328 } 313 329 else if (section == "image") { 314 330 if (lhs == "format") { … … 370 386 instance_ = new Configuration; 371 387 instance_->load(); 388 std::cerr << "construct config\n"; 372 389 } 373 390 return *instance_; … … 507 524 output_blame_information_ = true; 508 525 output_file_ = true; 526 509 527 } 510 528 … … 522 540 523 541 524 const std::map<std::string, std::string>* 525 Configuration::svn_properties(const std::string&) const 526 { 527 return NULL; 542 const std::map<std::string, std::string>& 543 Configuration::svn_properties(const std::string& filename) const 544 { 545 // reverse backwards as we prefer to to pick properties defined later 546 std::vector<props>::const_reverse_iterator iter = 547 find_fn(svn_props_.rbegin(), svn_props_.rend(), filename); 548 if (iter==svn_props_.rend()) 549 return empty_str_map_; 550 return iter->second; 528 551 } 529 552 … … 612 635 << "[author-color]\n" 613 636 << "# jdoe = 000000\n"; 614 typedef std::map<std::string,std::string>str_map;637 typedef Configuration::str_map str_map; 615 638 for (str_map::const_iterator i(conf.author_color_.begin()); 616 639 i!=conf.author_color_.end(); ++i) { … … 618 641 } 619 642 643 typedef Configuration::props props; 620 644 os << "\n" 621 << "### Section for setting trac environment\n" 645 << "### Section for overriding svn properties.\n" 646 << "### The format is the same as for section auto-props in subversion\n" 647 << "### config file\n" 648 << "[svn-props]\n"; 649 os << "# COPYING = svndigest:ignore\n"; 650 std::vector<props>::const_iterator p=conf.svn_props_.begin(); 651 for ( ; p!=conf.svn_props_.end(); ++p) { 652 os << p->first << " = "; 653 const str_map& map = p->second; 654 str_map::const_iterator end = map.end(); 655 for (str_map::const_iterator i=map.begin(); i!=end; ++i) { 656 if (i != map.begin()) 657 os << ";"; 658 os << i->first << "=" << i->second; 659 } 660 os << "\n"; 661 } 662 663 664 os << "\n" 665 << "### Section for setting trac environment.\n" 622 666 << "[trac]\n" 623 667 << "# If trac-root is set, svndigest will create anchors to " … … 626 670 if (!conf.trac_root().empty()) 627 671 os << "trac-root = " << conf.trac_root() << "\n"; 672 673 os << "\n" 674 << "### Section for setting dictionary for file names.\n" 675 << "### Prior looking for file name pattern in section " 676 << "[parsing-codons],\n" 677 << "### the file name may be translated according to the rules \n" 678 << "### in this section. In default setting there is, for example,\n" 679 << "### a rule to translate `<FILENAME>.in' to `<FILENAME>'.\n" 680 << "### The format of the entries is:\n" 681 << "### file-name-pattern = new-name\n" 682 << "### Left hand side may contain wildcards (such as '*' and '?').\n" 683 << "### Right hand side may contain \"$i\", which will be replaced \n" 684 << "### with the ith wild card in lhs string.\n"; 628 685 629 686 if (!conf.dictionary_.empty()) { -
trunk/lib/Configuration.h
r1144 r1152 121 121 \return NULL if there is no prop for \a filename in config 122 122 */ 123 const std::map<std::string, std::string> *123 const std::map<std::string, std::string>& 124 124 svn_properties(const std::string& filename) const; 125 125 … … 152 152 bool equal_false(std::string) const; 153 153 bool equal_true(std::string) const; 154 155 /** 156 find first element in range, [first, last) for which 157 element->first matches filename. 158 159 Iterator->first must return string, i.e., [first, last) is 160 often a range of pair<string, T> 161 162 If no match is found, last is returned. 163 */ 164 template<typename Iterator> 165 Iterator find_fn(Iterator first, Iterator last, 166 const std::string& filename) const; 167 154 168 /// 155 169 /// @brief load deafult configuration … … 190 204 std::string trac_root_; 191 205 192 std::vector<std::map<std::string, std::string> > svn_props_; 206 typedef std::map<std::string, std::string> str_map; 207 typedef std::pair<std::string, str_map> props; 208 std::vector<props> svn_props_; 209 const str_map empty_str_map_; 193 210 }; 194 211 … … 226 243 }; 227 244 245 // template implementation 246 247 template<typename Iterator> 248 Iterator Configuration::find_fn(Iterator first, Iterator last, 249 const std::string& filename) const 250 { 251 for( ; first!=last; ++first) { 252 if (fnmatch(first->first.c_str(), filename.c_str())) 253 return first; 254 } 255 return last; 256 } 257 258 228 259 }} // end of namespace svndigest and namespace theplu 229 260 -
trunk/lib/SVNproperty.cc
r1144 r1152 40 40 const Configuration& config = Configuration::instance(); 41 41 typedef std::map<std::string, std::string> str_map; 42 const str_map* props = config.svn_properties(file_name(path)); 43 std::map<std::string, std::string>::const_iterator i; 44 std::map<std::string, std::string>::const_iterator e; 45 if (props) { 46 i = props->begin(); 47 e = props->end(); 48 // we can not use map::insert because we want config to have precedence 49 for ( ; i!=e; ++i) 50 property_[i->first] = i->second; 51 } 42 const str_map& props = config.svn_properties(file_name(path)); 43 std::map<std::string, std::string>::const_iterator i = props.begin(); 44 std::map<std::string, std::string>::const_iterator e = props.end(); 45 // we can not use map::insert because we want config to have precedence 46 for ( ; i!=e; ++i) 47 property_[i->first] = i->second; 52 48 53 49 i = property_.begin(); -
trunk/test/config_test.cc
r1119 r1152 29 29 void test_codon(test::Suite&); 30 30 void test_read_write(test::Suite&); 31 void test_props(test::Suite&); 31 32 }} // end of namespace svndigest and theplu 32 33 … … 39 40 test_codon(suite); 40 41 test_read_write(suite); 42 test_props(suite); 41 43 42 44 if (suite.ok()) { … … 54 56 void test_codon(test::Suite& suite) 55 57 { 58 suite.out() << "test codons" << std::endl; 56 59 const Configuration& c(Configuration::instance()); 57 60 if (!c.codon("foo.h")){ … … 69 72 } 70 73 74 void test_props(test::Suite& suite) 75 { 76 suite.out() << "test props" << std::endl; 77 Configuration& conf(Configuration::instance()); 78 std::stringstream ss; 79 ss << "[svn_props]\n" 80 << "foo* = svndigest:ignore\n" 81 << "bar* = svn:eol-style=native;svncopyright:ignore\n"; 82 conf.load(ss); 83 const std::map<std::string, std::string>& props = 84 conf.svn_properties("foo_bla_bla"); 85 if (props.find("svndigest:ignore")==props.end()) { 86 suite.out() << "property svndigest:ignore not set for foo_bla_bla\n"; 87 suite.add(false); 88 } 89 const std::map<std::string, std::string>& props2 = 90 conf.svn_properties("bar_bla_bla"); 91 std::map<std::string, std::string>::const_iterator it = 92 props2.find("svn:eol-style"); 93 if (!suite.add(it != props2.end())) 94 suite.out() <<"expected property 'svn:eol-style' set for bar_bla_bla\n"; 95 else if (!suite.add(it->second == "native")) 96 suite.out() << "expected 'svn:eol-style' set to 'native' " 97 << "for bar_bla_bla\n"; 98 // checking that we return empty map for files not mentioned in config 99 suite.out() << "props3" << std::endl; 100 const std::map<std::string, std::string>& props3 = 101 conf.svn_properties("nothing-nothing"); 102 suite.add(props3.empty()); 103 } 104 71 105 void test_read_write(test::Suite& suite) 72 106 { -
trunk/yat/Makefile.am
r1090 r1152 36 36 noinst_HEADERS += OptionHelp.h 37 37 noinst_HEADERS += OptionSwitch.h 38 noinst_HEADERS += split.h 38 39 noinst_HEADERS += utility.h 39 40 … … 46 47 libyat_a_SOURCES += OptionHelp.cc 47 48 libyat_a_SOURCES += OptionSwitch.cc 49 libyat_a_SOURCES += split.cc 48 50 49 51
Note: See TracChangeset
for help on using the changeset viewer.