Changeset 1122


Ignore:
Timestamp:
Jul 7, 2010, 6:00:11 AM (10 years ago)
Author:
Peter Johansson
Message:

added line in config file describing config used to create cache (refs
#433). If config is different from the current one, the cache is
ignored and stats are retrieved from repo. Restructured code a bit to
allow loading old cache files; the first line (in cache) is used to
decide which function to use for the loading. Cache files VERSION 7
and newer are supported and older are ignored (refs #289).

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r1115 r1122  
    44
    55Version 0.8 (released NOT YET)
     6  - cache file now contains config information (ticket #433)
    67  - Gnuplot replaced with plplot (ticket:97)
    78  - option --copyright deprecated; use new program snvcopyright (ticket #307)
  • trunk/doc/readme.txt

    r1103 r1122  
    100100the case, for example, if you have switched working copy using `svn
    101101switch`, you can make svndigest ignore the cache through option
    102 `--ignore-cache`.
     102`--ignore-cache`. From svndigest 0.8 the cache file contains
     103information on the configuration (e.g. codons) used to create the
     104statistics.  If that configuration is different from the current one,
     105the cache file is ignored and statistics is retrieved from repository.
    103106
    104107
  • trunk/lib/Stats.cc

    r1026 r1122  
    5959    last_changed_rev_=svn_info.last_changed_rev();
    6060    reset();
     61
     62    std::ostringstream ss;
     63    if (const std::vector<std::pair<std::string, std::string> >*
     64        codons = Configuration::instance().codon(path)) {
     65      using std::string;
     66      typedef std::vector<std::pair<string, string> >::const_iterator citerator;
     67      for ( citerator codon=codons->begin(); codon!=codons->end(); ++codon)
     68        ss << codon->first << codon->second;
     69    }
     70    config_code_ = ss.str();
     71    // we don't allow newline in codon because we parse the string
     72    // with newline and thus want the string to be a one-liner.
     73    std::replace(config_code_.begin(), config_code_.end(), '\n', ' ');
    6174  }
    6275
     
    280293    std::string str;
    281294    getline(is, str);
    282     if (str!=cache_check_str()) {
    283       if (str == prev_cache_check_str())
    284         std::cout << "cache file is obsolete; "
    285                   << "retrieving statistics from repository.\n";
     295    if (str == "CACHE FILE VERSION 8")
     296      return load_cache8(is);
     297    if (str == "CACHE FILE VERSION 7")
     298      return load_cache7(is);
     299
     300    if (str == "CACHE FILE VERSION 6")
     301      std::cout << "cache file is obsolete; "
     302                << "retrieving statistics from repository.\n";
     303    return 0;
     304  }
     305
     306
     307  svn_revnum_t Stats::load_cache8(std::istream& is)
     308  {
     309    std::string line;
     310    getline(is, line);
     311    if (line!=config_code_) {
     312      std::cout << "cache file is for different configuration.\n"
     313                << "config code: '" << config_code_ << "'\n"
     314                << "config code in cache file: '" << line << "'\n"
     315                << "retrieving statistics from repository.\n";
    286316      return 0;
    287317    }
     318    return load_cache7(is);
     319  }
     320
     321
     322  svn_revnum_t Stats::load_cache7(std::istream& is)
     323  {
    288324    svn_revnum_t rev;
    289325    is >> rev;
     
    291327    size_t a_size=0;
    292328    is >> a_size;
     329    std::string str;
    293330    while (authors().size()<a_size && is.good()){
    294331      getline(is, str);
     
    487524  void Stats::print(std::ostream& os) const
    488525  {
    489     os << cache_check_str() << "\n";
     526    // indicate that cache file is version 8 here , but keep remaning
     527    // 'CACHE FILE VERSION' as 'VERSION 7' to allow load_cache7() to
     528    // be used from load_cache8().
     529    os << "CACHE FILE VERSION 8\n";
     530    os << config_code_ << "\n";
    490531    os << last_changed_rev() << " ";
    491532    os << authors().size() << "\n";
  • trunk/lib/Stats.h

    r1090 r1122  
    197197                                         std::string user) const;
    198198  private:
     199    /// one liner used in cache file to validate that cache file was
     200    /// created current configuration
     201    std::string config_code_;
     202
    199203    /**
    200204       \a vec is resized to revision().
     
    216220    virtual void do_parse(const std::string&, svn_revnum_t first_rev)=0;
    217221   
     222    /// load cache file version 7
     223    svn_revnum_t load_cache7(std::istream&);
     224    /// load cache file version 8
     225    svn_revnum_t load_cache8(std::istream&);
     226
    218227    /**
    219228       called from plot(2)
     
    232241    inline std::string cache_check_str(void) const
    233242    {return "CACHE FILE VERSION 7";}
    234 
    235     inline std::string prev_cache_check_str(void) const
    236     {return "CACHE FILE VERSION 6";}
    237243
    238244    void calc_all(void);
  • trunk/test/cache_partial_test.cc

    r1119 r1122  
    2424#include "Suite.h"
    2525
     26#include "lib/ClassicStats.h"
    2627#include "lib/File.h"
    2728#include "lib/SVN.h"
     
    6263  suite.add(equal(stats1, stats2, suite));
    6364
     65  // test that load of partial cache is successful
     66  copy_file(test::src_filename("data/AUTHORS.svndigest-cache-r61"), cache_file);
     67  ClassicStats cstats(filename);
     68  std::ifstream is(cache_file.c_str());
     69  svn_revnum_t rev = cstats.load_cache(is);
     70  if (rev!=48) {
     71    suite.out() << "load cache: " << cache_file << " returned " << rev << "\n"
     72                << " expected 48\n";
     73    suite.add(false);
     74  }
     75  is.close();
     76
    6477  if (suite.ok()) {
    6578    suite.out() << "Test is OK\n";
  • trunk/test/data/AUTHORS.svndigest-cache-r61

    r1003 r1122  
    1 CACHE FILE VERSION 7
     1CACHE FILE VERSION 8
     2
    2348 1
    34jari
Note: See TracChangeset for help on using the changeset viewer.