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
Line 
1// $Id: SVNlog.cc 660 2008-06-10 23:01:59Z peter $
2
3/*
4  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://trac.thep.lu.se/svndigest
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"
25
26#include "Commitment.h"
27#include "SVN.h"
28
29#include <algorithm>
30#include <cassert>
31#include <stdexcept>
32#include <sstream>
33#include <string>
34#include <vector>
35
36namespace theplu {
37namespace svndigest {
38
39
40  SVNlog::SVNlog(void)
41  {
42  }
43
44
45  SVNlog::SVNlog(const std::string& path)
46  {
47    SVN::instance()->client_log(path, log_message_receiver,
48                                static_cast<void*>(&lb_));
49  }
50
51
52  SVNlog::~SVNlog(void)
53  {
54  }
55
56 
57  bool SVNlog::exist(std::string name) const
58  {
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;
65  }
66
67
68  const Commitment& SVNlog::latest_commit(void) const
69  {
70    assert(commits().size());
71    return commits().back();
72  }
73
74
75  const Commitment& SVNlog::latest_commit(std::string name) const
76  {
77    std::vector<Commitment>::const_reverse_iterator iter = commits().rbegin();
78    for ( ; iter!= commits().rend(); ++iter)
79      if (iter->author() == name)
80        return *iter;
81    std::stringstream ss;
82    ss << __FILE__ << " could not find author: " << name;
83    throw std::runtime_error(ss.str());
84    // let us return something to avoid compiler warnings
85    return *commits().begin();
86  }
87
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);
96    if (!date || !date[0])
97      throw SVNException("No date defined for revision: " + rev); 
98    std::string a;
99    if (author && author[0])
100      a=author;
101    std::string message;
102    if (msg)
103      message = msg;
104    lb->commits.push_back(Commitment(a, date, message, rev));
105    return SVN_NO_ERROR;
106  }
107
108
109  void SVNlog::swap(SVNlog& rhs)
110  {
111    lb_.commits.swap(rhs.lb_.commits);
112  }
113
114
115  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
116  {
117    SVNlog log;
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()) {
121      if (lhs_iter->revision() < rhs_iter->revision()) {
122       
123        log.commits().push_back(*lhs_iter);
124        ++lhs_iter;
125      }
126      else if (rhs_iter->revision()<lhs_iter->revision()) {
127        log.commits().push_back(*rhs_iter);
128        ++rhs_iter;
129      }
130      else {
131        log.commits().push_back(*lhs_iter);
132        ++lhs_iter;
133        ++rhs_iter;
134      }
135    }
136    while(lhs_iter<lhs.commits().end()) {
137      log.commits().push_back(*lhs_iter);
138      ++lhs_iter;
139    }
140    while(rhs_iter<rhs.commits().end()) {
141      log.commits().push_back(*rhs_iter);
142      ++rhs_iter;
143    }
144    lhs.swap(log);
145    return lhs;
146  }
147
148}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.