source: trunk/lib/SVNlog.cc @ 745

Last change on this file since 745 was 693, checked in by Jari Häkkinen, 13 years ago

Fixes #339. Change to GPLv3.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 KB
Line 
1// $Id: SVNlog.cc 693 2008-09-11 20:42:56Z jari $
2
3/*
4  Copyright (C) 2007 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#include <vector>
33
34namespace theplu {
35namespace svndigest {
36
37
38  SVNlog::SVNlog(void)
39  {
40  }
41
42
43  SVNlog::SVNlog(const std::string& path)
44  {
45    SVN::instance()->client_log(path, log_message_receiver,
46                                static_cast<void*>(&lb_));
47  }
48
49
50  SVNlog::~SVNlog(void)
51  {
52  }
53
54 
55  bool SVNlog::exist(std::string name) const
56  {
57   
58    std::vector<Commitment>::const_reverse_iterator iter = commits().rbegin();
59    for ( ; iter!= commits().rend(); ++iter)
60      if (iter->author() == name)
61        return true;
62    return false;
63  }
64
65
66  const Commitment& SVNlog::latest_commit(void) const
67  {
68    assert(commits().size());
69    return commits().back();
70  }
71
72
73  const Commitment& SVNlog::latest_commit(std::string name) const
74  {
75    std::vector<Commitment>::const_reverse_iterator iter = commits().rbegin();
76    for ( ; iter!= commits().rend(); ++iter)
77      if (iter->author() == name)
78        return *iter;
79    std::stringstream ss;
80    ss << __FILE__ << " could not find author: " << name;
81    throw std::runtime_error(ss.str());
82    // let us return something to avoid compiler warnings
83    return *commits().begin();
84  }
85
86
87  svn_error_t* 
88  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
89                               svn_revnum_t rev, const char *author,
90                               const char *date, const char *msg,
91                               apr_pool_t *pool)
92  {
93    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
94    if (!date || !date[0])
95      throw SVNException("No date defined for revision: " + rev); 
96    std::string a;
97    if (author && author[0])
98      a=author;
99    std::string message;
100    if (msg)
101      message = msg;
102    lb->commits.push_back(Commitment(a, date, message, rev));
103    return SVN_NO_ERROR;
104  }
105
106
107  void SVNlog::swap(SVNlog& rhs)
108  {
109    lb_.commits.swap(rhs.lb_.commits);
110  }
111
112
113  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
114  {
115    SVNlog log;
116    std::vector<Commitment>::iterator lhs_iter=lhs.commits().begin();
117    std::vector<Commitment>::const_iterator rhs_iter=rhs.commits().begin();
118    while(lhs_iter<lhs.commits().end() && rhs_iter<rhs.commits().end()) {
119      if (lhs_iter->revision() < rhs_iter->revision()) {
120       
121        log.commits().push_back(*lhs_iter);
122        ++lhs_iter;
123      }
124      else if (rhs_iter->revision()<lhs_iter->revision()) {
125        log.commits().push_back(*rhs_iter);
126        ++rhs_iter;
127      }
128      else {
129        log.commits().push_back(*lhs_iter);
130        ++lhs_iter;
131        ++rhs_iter;
132      }
133    }
134    while(lhs_iter<lhs.commits().end()) {
135      log.commits().push_back(*lhs_iter);
136      ++lhs_iter;
137    }
138    while(rhs_iter<rhs.commits().end()) {
139      log.commits().push_back(*rhs_iter);
140      ++rhs_iter;
141    }
142    lhs.swap(log);
143    return lhs;
144  }
145
146}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.