source: trunk/lib/SVNlog.cc @ 318

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

Fixes #167 and addresses #74. Interfaces have changed. SVN::instance usage has changed, read SVN class documentation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1// $Id: SVNlog.cc 318 2007-05-18 09:35:45Z jari $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of svndigest, http://lev.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(const std::string& path)
38  {
39    SVN::instance()->client_log(path, log_message_receiver,
40                                static_cast<void*>(&lb_));
41    assert(date().size()==author().size());
42    assert(date().size()==revision().size());
43    assert(date().size()==message().size());
44  }
45
46
47  SVNlog::~SVNlog(void)
48  {
49  }
50
51 
52  bool SVNlog::exist(std::string name) const
53  {
54    std::vector<std::string>::const_reverse_iterator iter = 
55      find(author().rbegin(), author().rend(), name);
56    return iter!=author().rend();
57  }
58
59
60  Commitment SVNlog::latest_commit(void) const
61  {
62    return Commitment(author().back(), Date(date().back()), 
63                      message().back(), revision().back());
64                                             
65  }
66
67
68  Commitment SVNlog::latest_commit(std::string name) const
69  {
70    std::vector<std::string>::const_reverse_iterator iter = 
71      find(author().rbegin(), author().rend(), name);
72    size_t dist(std::distance(iter, author().rend()));
73    if (!dist) {
74      Commitment c;
75      assert(false);
76      return c;
77    }
78    return Commitment(author()[dist-1], Date(date()[dist-1]), 
79                      message()[dist-1], revision()[dist-1]);
80                                             
81  }
82
83
84  svn_error_t* 
85  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
86                               svn_revnum_t rev, const char *author,
87                               const char *date, const char *msg,
88                               apr_pool_t *pool)
89  {
90    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
91    if (date && date[0])
92      lb->commit_dates.push_back(date);
93    else
94      throw SVNException("No date defined for revision: " + rev); 
95    if (author && author[0])
96      lb->authors.push_back(author);
97    else
98      lb->authors.push_back("");
99    lb->rev.push_back(rev);
100    if (msg)
101      lb->msg.push_back(std::string(msg));
102    else
103      lb->msg.push_back(std::string(""));
104    return SVN_NO_ERROR;
105  }
106
107}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.