source: branches/replacing_gnuplot/lib/SVNlog.cc @ 646

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

Merged trunk changes r608:645 to replacing_gnuplot branch.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1// $Id: SVNlog.cc 646 2008-06-03 22:05:22Z jari $
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 <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    return commits().back();
69  }
70
71
72  const Commitment& SVNlog::latest_commit(std::string name) const
73  {
74    std::vector<Commitment>::const_reverse_iterator iter = commits().rbegin();
75    for ( ; iter!= commits().rend(); ++iter)
76      if (iter->author() == name)
77        return *iter;
78    assert(false);
79  }
80
81
82  svn_error_t* 
83  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
84                               svn_revnum_t rev, const char *author,
85                               const char *date, const char *msg,
86                               apr_pool_t *pool)
87  {
88    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
89    if (!date || !date[0])
90      throw SVNException("No date defined for revision: " + rev); 
91    std::string a;
92    if (author && author[0])
93      a=author;
94    std::string message;
95    if (msg)
96      message = msg;
97    lb->commits.push_back(Commitment(a, date, message, rev));
98    return SVN_NO_ERROR;
99  }
100
101
102  void SVNlog::swap(SVNlog& rhs)
103  {
104    lb_.commits.swap(rhs.lb_.commits);
105  }
106
107
108  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
109  {
110    SVNlog log;
111    std::vector<Commitment>::iterator lhs_iter=lhs.commits().begin();
112    std::vector<Commitment>::const_iterator rhs_iter=rhs.commits().begin();
113    while(lhs_iter<lhs.commits().end() && rhs_iter<rhs.commits().end()) {
114      if (lhs_iter->revision() < rhs_iter->revision()) {
115       
116        log.commits().push_back(*lhs_iter);
117        ++lhs_iter;
118      }
119      else if (rhs_iter->revision()<lhs_iter->revision()) {
120        log.commits().push_back(*rhs_iter);
121        ++rhs_iter;
122      }
123      else {
124        log.commits().push_back(*lhs_iter);
125        ++lhs_iter;
126        ++rhs_iter;
127      }
128    }
129    while(lhs_iter<lhs.commits().end()) {
130      log.commits().push_back(*lhs_iter);
131      ++lhs_iter;
132    }
133    while(rhs_iter<rhs.commits().end()) {
134      log.commits().push_back(*rhs_iter);
135      ++rhs_iter;
136    }
137    lhs.swap(log);
138    return lhs;
139  }
140
141}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.