source: trunk/lib/SVNlog.cc @ 452

Last change on this file since 452 was 452, checked in by Peter Johansson, 14 years ago

fixes #248 and refs #185

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.3 KB
Line 
1// $Id: SVNlog.cc 452 2007-08-17 19:03:32Z 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/trac/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 "LogIterator.h"
28#include "SVN.h"
29
30#include <algorithm>
31#include <cassert>
32#include <string>
33#include <vector>
34
35namespace theplu {
36namespace svndigest {
37
38
39  SVNlog::SVNlog(void)
40  {
41    assert(date().empty());
42    assert(author().empty());
43    assert(revision().empty());
44    assert(message().empty());
45  }
46
47
48  SVNlog::SVNlog(const std::string& path)
49  {
50    SVN::instance()->client_log(path, log_message_receiver,
51                                static_cast<void*>(&lb_));
52    assert(date().size()==author().size());
53    assert(date().size()==revision().size());
54    assert(date().size()==message().size());
55  }
56
57
58  SVNlog::~SVNlog(void)
59  {
60  }
61
62 
63  LogIterator SVNlog::begin() const
64  {
65    return LogIterator(*this, 0);
66  }
67
68
69  LogIterator SVNlog::end() const
70  {
71    return LogIterator(*this, revision().size());
72  }
73
74
75  bool SVNlog::exist(std::string name) const
76  {
77    std::vector<std::string>::const_reverse_iterator iter = 
78      find(author().rbegin(), author().rend(), name);
79    return iter!=author().rend();
80  }
81
82
83  Commitment SVNlog::latest_commit(void) const
84  {
85    return Commitment(author().back(), date().back(), 
86                      message().back(), revision().back());
87                                             
88  }
89
90
91  Commitment SVNlog::latest_commit(std::string name) const
92  {
93    std::vector<std::string>::const_reverse_iterator iter = 
94      find(author().rbegin(), author().rend(), name);
95    size_t dist(std::distance(iter, author().rend()));
96    if (!dist) {
97      Commitment c;
98      assert(false);
99      return c;
100    }
101    return Commitment(author()[dist-1], date()[dist-1], 
102                      message()[dist-1], revision()[dist-1]);
103                                             
104  }
105
106
107  void SVNlog::push_back(const Commitment& c)
108  {
109    lb_.authors.push_back(c.author());
110    lb_.commit_dates.push_back(c.date());
111    lb_.msg.push_back(c.message());
112    lb_.rev.push_back(c.revision());
113  }
114
115
116  void SVNlog::reserve(size_t i)
117  {
118    lb_.authors.reserve(i);
119    lb_.commit_dates.reserve(i);
120    lb_.msg.reserve(i);
121    lb_.rev.reserve(i);
122  }
123
124
125  svn_error_t* 
126  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
127                               svn_revnum_t rev, const char *author,
128                               const char *date, const char *msg,
129                               apr_pool_t *pool)
130  {
131    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
132    if (date && date[0])
133      lb->commit_dates.push_back(date);
134    else
135      throw SVNException("No date defined for revision: " + rev); 
136    if (author && author[0])
137      lb->authors.push_back(author);
138    else
139      lb->authors.push_back("");
140    lb->rev.push_back(rev);
141    if (msg)
142      lb->msg.push_back(std::string(msg));
143    else
144      lb->msg.push_back(std::string(""));
145    return SVN_NO_ERROR;
146  }
147
148
149  void SVNlog::swap(SVNlog& rhs)
150  {
151    lb_.authors.swap(rhs.lb_.authors);
152    lb_.commit_dates.swap(rhs.lb_.commit_dates);
153    lb_.msg.swap(rhs.lb_.msg);
154    lb_.rev.swap(rhs.lb_.rev);
155  }
156
157
158  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
159  {
160    SVNlog log;
161    LogIterator lhs_iter(lhs.begin());
162    LogIterator rhs_iter(rhs.begin());
163    while(lhs_iter<lhs.end() && rhs_iter<rhs.end()) {
164      if (lhs_iter->revision() < rhs_iter->revision()) {
165       
166        log.push_back(*lhs_iter);
167        ++lhs_iter;
168      }
169      else if (rhs_iter->revision()<lhs_iter->revision()) {
170        log.push_back(*rhs_iter);
171        ++rhs_iter;
172      }
173      else {
174        log.push_back(*lhs_iter);
175        ++lhs_iter;
176        ++rhs_iter;
177      }
178    }
179    while(lhs_iter<lhs.end()) {
180        log.push_back(*lhs_iter);
181        ++lhs_iter;
182    }
183    while(rhs_iter<rhs.end()) {
184        log.push_back(*rhs_iter);
185        ++rhs_iter;
186    }
187    lhs.swap(log);
188    return lhs;
189  }
190
191}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.