source: trunk/lib/SVNlog.cc @ 448

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

adding LogIterator?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1// $Id: SVNlog.cc 448 2007-08-16 18:44:46Z 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 "SVN.h"
28
29#include <cassert>
30#include <string>
31#include <vector>
32
33namespace theplu {
34namespace svndigest {
35
36
37  SVNlog::SVNlog(void)
38  {
39    assert(date().size()==author().size());
40    assert(date().size()==revision().size());
41    assert(date().size()==message().size());
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    assert(date().size()==author().size());
50    assert(date().size()==revision().size());
51    assert(date().size()==message().size());
52  }
53
54
55  SVNlog::~SVNlog(void)
56  {
57  }
58
59 
60  bool SVNlog::exist(std::string name) const
61  {
62    std::vector<std::string>::const_reverse_iterator iter = 
63      find(author().rbegin(), author().rend(), name);
64    return iter!=author().rend();
65  }
66
67
68  Commitment SVNlog::latest_commit(void) const
69  {
70    return Commitment(author().back(), Date(date().back()), 
71                      message().back(), revision().back());
72                                             
73  }
74
75
76  Commitment SVNlog::latest_commit(std::string name) const
77  {
78    std::vector<std::string>::const_reverse_iterator iter = 
79      find(author().rbegin(), author().rend(), name);
80    size_t dist(std::distance(iter, author().rend()));
81    if (!dist) {
82      Commitment c;
83      assert(false);
84      return c;
85    }
86    return Commitment(author()[dist-1], Date(date()[dist-1]), 
87                      message()[dist-1], revision()[dist-1]);
88                                             
89  }
90
91
92  svn_error_t* 
93  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
94                               svn_revnum_t rev, const char *author,
95                               const char *date, const char *msg,
96                               apr_pool_t *pool)
97  {
98    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
99    if (date && date[0])
100      lb->commit_dates.push_back(date);
101    else
102      throw SVNException("No date defined for revision: " + rev); 
103    if (author && author[0])
104      lb->authors.push_back(author);
105    else
106      lb->authors.push_back("");
107    lb->rev.push_back(rev);
108    if (msg)
109      lb->msg.push_back(std::string(msg));
110    else
111      lb->msg.push_back(std::string(""));
112    return SVN_NO_ERROR;
113  }
114
115
116}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.