Changeset 1551
- Timestamp:
- Nov 3, 2012, 6:03:36 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NEWS
r1523 r1551 4 4 5 5 Version 0.11 (released NOT YET) 6 - svncopyright now works on characters rather than lines (ticket #518) 6 7 7 8 A complete list of closed tickets can be found here [[br]] -
trunk/doc/readme.txt
r1373 r1551 3 3 Copyright (C) 2005 Jari Häkkinen 4 4 Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson 5 Copyright (C) 2009, 2010, 2011 Peter Johansson5 Copyright (C) 2009, 2010, 2011, 2012 Peter Johansson 6 6 7 7 This file is part of svndigest, http://dev.thep.lu.se/svndigest … … 202 202 svncopyright updates the copyright statement in subversion controlled 203 203 files. The program detects the copyright statement and replaces it 204 with a copyright statement calculated from repository statistics. 204 with a copyright statement calculated from repository statistics. 205 205 206 206 The copyright statement is detected as the first line containing the … … 211 211 statement block is replaced with a new copyright statement generated 212 212 from analyzing `svn blame output`. An author is considered to have 213 copyright of the file if (s)he has added a line of code or comment213 copyright of the file if (s)he has added a non-whitespace character 214 214 (excluding copyright statements). For an example of the format of the 215 215 generated copyright statement, please have a look at the top of this 216 file. 216 file. 217 217 218 218 By default the `svn user name` of the author is printed in the -
trunk/lib/CopyrightStats.cc
r1515 r1551 25 25 #include "Configuration.h" 26 26 #include "LineTypeParser.h" 27 #include "S VNblame.h"27 #include "SkipWhiteSpaceIterator.h" 28 28 #include "SVNinfo.h" 29 29 #include "SVNlog.h" 30 #include "SVNcat.h" 30 31 #include "utility.h" 31 32 … … 92 93 std::string line; 93 94 getline(is, line); 94 if (line!="SVNCOPYRIGHT CACHE VERSION 1")95 if (line!="SVNCOPYRIGHT CACHE VERSION 2") 95 96 return 0; 96 97 getline(is, line); … … 149 150 assert(commit->revision() >= first_rev); 150 151 log_iterator end = log.commits().end(); 152 151 153 // loop over all commits 152 154 for ( ; commit!=end; ++commit) { … … 170 172 continue; 171 173 172 SVNblame svn_blame(path_, commit->revision()); 173 LineTypeParser parser(path_); 174 175 // loop over lines 176 while (svn_blame.valid()) { 177 int lt = parser.parse(svn_blame.line()); 178 if ((lt==LineTypeParser::code || lt==LineTypeParser::comment) && 179 svn_blame.revision()==commit->revision()) { 180 year2user_[yearrev->first].insert(name); 181 break; 182 } 183 svn_blame.next_line(); 184 } 185 } 186 } 174 SVNcat previous(path_, commit->revision()-1); 175 std::string previous_content; 176 remove_copyright_lines(previous.str(), previous_content); 177 178 SVNcat current(path_, commit->revision()); 179 std::string current_content; 180 remove_copyright_lines(current.str(), current_content); 181 182 // if any character added between previous and current add 183 // author to set of authors 184 if (!subseq(current_content, previous_content)) { 185 year2user_[yearrev->first].insert(name); 186 } 187 } 188 } 189 190 191 void CopyrightStats::remove_copyright_lines(const std::string& src, 192 std::string& result) const 193 { 194 LineTypeParser ltp(path_); 195 std::istringstream is(src); 196 std::string line; 197 while (getline(is, line)) { 198 if (ltp.parse(line) != LineTypeParser::copyright) { 199 result += line; 200 result += '\n'; 201 } 202 } 203 } 187 204 188 205 … … 190 207 { 191 208 year2user_.clear(); 209 } 210 211 212 bool 213 CopyrightStats::subseq(const std::string& sub, const std::string& seq) const 214 { 215 SkipWhiteSpaceIterator iter1(sub.begin(), sub.end()); 216 SkipWhiteSpaceIterator end1(sub.end(), sub.end()); 217 SkipWhiteSpaceIterator iter2(seq.begin(), seq.end()); 218 SkipWhiteSpaceIterator end2(seq.end(), seq.end()); 219 220 for ( ; iter1!=end1; ++iter1) { 221 iter2 = std::find(iter2, end2, *iter1); 222 if (iter2 == end2) { 223 return false; 224 } 225 } 226 return true; 192 227 } 193 228 … … 199 234 assert(os.good()); 200 235 201 os << "SVNCOPYRIGHT CACHE VERSION 1\n";236 os << "SVNCOPYRIGHT CACHE VERSION 2\n"; 202 237 os << config_ << "\n"; 203 238 os << year2user_.size() << "\n"; -
trunk/lib/CopyrightStats.h
r1453 r1551 60 60 61 61 void parse(svn_revnum_t rev, const std::map<int, svn_revnum_t>& year2rev); 62 void remove_copyright_lines(const std::string& src, 63 std::string& result) const; 62 64 void reset(void); 65 66 /** 67 sub is subsequence of seq if sub can be created from seq by 68 removing element in seq. 69 70 \return true if \a sub is subsequence of \a seq 71 */ 72 bool subseq(const std::string& sub, const std::string& seq) const; 73 63 74 void write_cache(void); 64 75 -
trunk/test/copyright.cc
r1515 r1551 66 66 suite.add(false); 67 67 } 68 suite.out() << "File contains 1 copyright line.\n"; 68 suite.out() << "File contains 1 copyright line.\n"; 69 69 70 // warn about missing Copyright statement only in verbose mode 71 if (suite.verbose()){ 72 std::stringstream ss; 73 ss << "[copyright]\n" 74 << "missing-copyright-warning=yes\n" 75 << "[copyright-alias]\n" 76 << "jari = jh\n" 77 << "peter = pj\n"; 78 Configuration& config = Configuration::instance(); 79 config.load(ss); 80 } 70 std::stringstream ss; 71 ss << "[copyright]\n" 72 << "missing-copyright-warning=yes\n" 73 << "[copyright-alias]\n" 74 << "jari = jh\n" 75 << "peter = pj\n"; 76 Configuration& config = Configuration::instance(); 77 config.load(ss); 81 78 82 79 suite.out() << "Create SVN instance" << std::endl; … … 90 87 suite.out() << "Create File object" << std::endl; 91 88 File file(0,filename,""); 92 93 update_copyright(file, suite.verbose(), false);89 90 update_copyright(file, true, true); 94 91 95 92 is.open(filename.c_str()); … … 100 97 std::vector<std::string> copyright_correct; 101 98 copyright_correct.push_back("Copyright (C) 2006 jh"); 102 copyright_correct.push_back("Copyright (C) 200 7, 2008 pj");99 copyright_correct.push_back("Copyright (C) 2008 pj"); 103 100 if (copyrights.size()!=copyright_correct.size()) { 104 101 suite.add(false); -
trunk/test/copyright_cache_test.sh
r1532 r1551 43 43 test -s stderr && exit_fail 44 44 test -r $cache_file || exit_fail 45 cat $cache_file 45 46 # check that we cache user name not alias 46 47 grep peter $cache_file || exit_fail -
trunk/test/ignore_revs_test.sh
r1525 r1551 31 31 cat >> config << _EOF 32 32 [svn-props] 33 README= svncopyright:ignore=$ignore33 Node.h = svncopyright:ignore=$ignore 34 34 _EOF 35 35 cat config … … 38 38 } 39 39 40 # log for AUTHORS 41 # r4 jari 2006 42 # r21 jari 2006 43 # r22 jari 2006 44 # r23 jari 2006 45 # r41 peter 2007 46 # r42 peter 2007 only updated copyright 47 # r44 peter 2007 only copyright 48 # r47 peter 2007 only copyright 49 # r67 peter 2009 only copyright 50 40 51 # no ignore 41 52 SVNCOPYRIGHT_run 0 -v --ignore-cache --root toy_project 42 $GREP "2006 Jari" toy_project/ README|| exit_fail43 $GREP "2007 , 2008 Peter" toy_project/README|| exit_fail53 $GREP "2006 Jari" toy_project/lib/Node.h || exit_fail 54 $GREP "2007 Peter" toy_project/lib/Node.h || exit_fail 44 55 45 run_svncopyright_with_ignore 4246 $GREP "2006 Jari" toy_project/ README|| exit_fail47 $GREP " Copyright (C) 2008 Peter" toy_project/README|| exit_fail56 run_svncopyright_with_ignore 21 57 $GREP "2006 Jari" toy_project/lib/Node.h || exit_fail 58 $GREP "2007 Peter" toy_project/lib/Node.h || exit_fail 48 59 49 run_svncopyright_with_ignore "- 42"50 $GREP "2006 Jari" toy_project/ README&& exit_fail51 $GREP " Copyright (C) 2008 Peter" toy_project/README|| exit_fail60 run_svncopyright_with_ignore "-30" 61 $GREP "2006 Jari" toy_project/lib/Node.h && exit_fail 62 $GREP "2007 Peter" toy_project/lib/Node.h || exit_fail 52 63 53 run_svncopyright_with_ignore "41" 54 $GREP "2006 Jari" toy_project/README || exit_fail 55 $GREP "Copyright (C) 2007, 2008 Peter" toy_project/README || exit_fail 64 run_svncopyright_with_ignore "1" 65 $GREP "2006 Jari" toy_project/lib/Node.h || exit_fail 56 66 57 run_svncopyright_with_ignore "1-34" 58 $GREP "2006 Jari" toy_project/README || exit_fail 59 $GREP "Copyright (C) 2007, 2008 Peter" toy_project/README || exit_fail 67 run_svncopyright_with_ignore "1-22" 68 $GREP "2006 Jari" toy_project/lib/Node.h || exit_fail 60 69 61 run_svncopyright_with_ignore "1-35" 62 $GREP "2006 Jari" toy_project/README && exit_fail 63 $GREP "Copyright (C) 2007, 2008 Peter" toy_project/README || exit_fail 70 run_svncopyright_with_ignore "1-23" 71 $GREP "2006 Jari" toy_project/lib/Node.h && exit_fail 64 72 65 run_svncopyright_with_ignore "42-" 66 $GREP "2006 Jari" toy_project/README || exit_fail 67 $GREP "Copyright (C) 2007, 2008 Peter" toy_project/README && exit_fail 68 69 run_svncopyright_with_ignore "0-999" 70 $GREP "Copyright (C)" toy_project/README || exit_fail 73 run_svncopyright_with_ignore "41-" 74 $GREP "2006 Jari" toy_project/lib/Node.h || exit_fail 75 $GREP "2007 Peter" toy_project/lib/Node.h && exit_fail 71 76 72 77 # test that nonsense argument fails with grace … … 74 79 cat > config << _EOF 75 80 [svn-props] 76 README= svncopyright:ignore=nonsense81 Node.h = svncopyright:ignore=nonsense 77 82 _EOF 78 83 cat config … … 89 94 peter = Peter 90 95 [svn-props] 91 README = svncopyright:ignore=0-35 96 Node.h = svncopyright:ignore=41 92 97 toy_project = svncopyright:ignore=42 93 98 _EOF … … 95 100 # do not use --ignore-cache so we also test that cache is ignored automatically 96 101 SVNCOPYRIGHT_run 0 -v --root toy_project --config-file=config 97 $GREP "Copyright (C) 2006" toy_project/ README &&exit_fail98 $GREP "Copyright (C) 200 8" toy_project/README ||exit_fail102 $GREP "Copyright (C) 2006" toy_project/lib/Node.h || exit_fail 103 $GREP "Copyright (C) 2007" toy_project/lib/Node.h && exit_fail 99 104 100 105 exit_success
Note: See TracChangeset
for help on using the changeset viewer.