source: trunk/lib/SVNlog.cc @ 660

Last change on this file since 660 was 660, checked in by Peter Johansson, 13 years ago

making it compile -sorry

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
RevLine 
[233]1// $Id: SVNlog.cc 660 2008-06-10 23:01:59Z peter $
2
3/*
[408]4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
[233]5
[519]6  This file is part of svndigest, http://trac.thep.lu.se/svndigest
[233]7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "SVNlog.h"
[256]25
26#include "Commitment.h"
[233]27#include "SVN.h"
28
[452]29#include <algorithm>
[234]30#include <cassert>
[660]31#include <stdexcept>
32#include <sstream>
[233]33#include <string>
34#include <vector>
35
36namespace theplu {
37namespace svndigest {
38
39
[448]40  SVNlog::SVNlog(void)
41  {
42  }
43
44
[318]45  SVNlog::SVNlog(const std::string& path)
[233]46  {
[318]47    SVN::instance()->client_log(path, log_message_receiver,
48                                static_cast<void*>(&lb_));
[233]49  }
50
51
52  SVNlog::~SVNlog(void)
53  {
54  }
55
[256]56 
[282]57  bool SVNlog::exist(std::string name) const
58  {
[642]59   
60    std::vector<Commitment>::const_reverse_iterator iter = commits().rbegin();
61    for ( ; iter!= commits().rend(); ++iter)
62      if (iter->author() == name)
63        return true;
64    return false;
[282]65  }
66
67
[642]68  const Commitment& SVNlog::latest_commit(void) const
[259]69  {
[659]70    assert(commits().size());
[642]71    return commits().back();
[259]72  }
73
74
[642]75  const Commitment& SVNlog::latest_commit(std::string name) const
[256]76  {
[642]77    std::vector<Commitment>::const_reverse_iterator iter = commits().rbegin();
78    for ( ; iter!= commits().rend(); ++iter)
79      if (iter->author() == name)
80        return *iter;
[659]81    std::stringstream ss;
82    ss << __FILE__ << " could not find author: " << name;
[660]83    throw std::runtime_error(ss.str());
[659]84    // let us return something to avoid compiler warnings
85    return *commits().begin();
[256]86  }
[233]87
[318]88
89  svn_error_t* 
90  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
91                               svn_revnum_t rev, const char *author,
92                               const char *date, const char *msg,
93                               apr_pool_t *pool)
94  {
95    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
[642]96    if (!date || !date[0])
[318]97      throw SVNException("No date defined for revision: " + rev); 
[642]98    std::string a;
[318]99    if (author && author[0])
[642]100      a=author;
101    std::string message;
[318]102    if (msg)
[642]103      message = msg;
104    lb->commits.push_back(Commitment(a, date, message, rev));
[318]105    return SVN_NO_ERROR;
106  }
107
[448]108
[452]109  void SVNlog::swap(SVNlog& rhs)
110  {
[642]111    lb_.commits.swap(rhs.lb_.commits);
[452]112  }
113
114
115  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
116  {
117    SVNlog log;
[642]118    std::vector<Commitment>::iterator lhs_iter=lhs.commits().begin();
119    std::vector<Commitment>::const_iterator rhs_iter=rhs.commits().begin();
120    while(lhs_iter<lhs.commits().end() && rhs_iter<rhs.commits().end()) {
[452]121      if (lhs_iter->revision() < rhs_iter->revision()) {
122       
[642]123        log.commits().push_back(*lhs_iter);
[452]124        ++lhs_iter;
125      }
126      else if (rhs_iter->revision()<lhs_iter->revision()) {
[642]127        log.commits().push_back(*rhs_iter);
[452]128        ++rhs_iter;
129      }
130      else {
[642]131        log.commits().push_back(*lhs_iter);
[452]132        ++lhs_iter;
133        ++rhs_iter;
134      }
135    }
[642]136    while(lhs_iter<lhs.commits().end()) {
137      log.commits().push_back(*lhs_iter);
138      ++lhs_iter;
[452]139    }
[642]140    while(rhs_iter<rhs.commits().end()) {
141      log.commits().push_back(*rhs_iter);
142      ++rhs_iter;
[452]143    }
144    lhs.swap(log);
145    return lhs;
146  }
147
[233]148}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.