source: trunk/lib/SVNlog.cc @ 768

Last change on this file since 768 was 768, checked in by Peter Johansson, 12 years ago

Merged patch release 0.6.7 to trunk. Delta 0.6.7 - 0.6.6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: SVNlog.cc 768 2009-01-31 21:30:37Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5
6  This file is part of svndigest, http://dev.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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "SVNlog.h"
23
24#include "Commitment.h"
25#include "SVN.h"
26
27#include <algorithm>
28#include <cassert>
29#include <stdexcept>
30#include <sstream>
31#include <string>
32
33namespace theplu {
34namespace svndigest {
35
36
37  SVNlog::SVNlog(void)
38  {
39  }
40
41
42  SVNlog::SVNlog(const std::string& path)
43  {
44    SVN::instance()->client_log(path, log_message_receiver,
45                                static_cast<void*>(&lb_));
46  }
47
48
49  SVNlog::~SVNlog(void)
50  {
51  }
52
53 
54  bool SVNlog::exist(std::string name) const
55  {
56   
57    SVNlog::container::const_reverse_iterator iter = commits().rbegin();
58    for ( ; iter!= commits().rend(); ++iter)
59      if (iter->author() == name)
60        return true;
61    return false;
62  }
63
64
65  const Commitment& SVNlog::latest_commit(void) const
66  {
67    assert(commits().size());
68    return *commits().rbegin();
69  }
70
71
72  const Commitment& SVNlog::latest_commit(std::string name) const
73  {
74    SVNlog::container::const_reverse_iterator iter = commits().rbegin();
75    for ( ; iter!= commits().rend(); ++iter)
76      if (iter->author() == name)
77        return *iter;
78    std::stringstream ss;
79    ss << __FILE__ << " could not find author: " << name;
80    throw std::runtime_error(ss.str());
81    // let us return something to avoid compiler warnings
82    return *commits().begin();
83  }
84
85
86  svn_error_t* 
87  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
88                               svn_revnum_t rev, const char *author,
89                               const char *date, const char *msg,
90                               apr_pool_t *pool)
91  {
92    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
93    if (!date || !date[0])
94      throw SVNException("No date defined for revision: " + rev); 
95    std::string a;
96    if (author && author[0])
97      a=author;
98    std::string message;
99    if (msg)
100      message = msg;
101    lb->commits.insert(lb->commits.end(), Commitment(a, date, message, rev));
102    return SVN_NO_ERROR;
103  }
104
105
106  void SVNlog::swap(SVNlog& rhs)
107  {
108    lb_.commits.swap(rhs.lb_.commits);
109  }
110
111
112  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
113  {
114    lhs.commits().insert(rhs.commits().begin(), rhs.commits().end());
115    return lhs;
116  }
117
118}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.