source: branches/0.7-stable/lib/SVNlog.cc @ 1110

Last change on this file since 1110 was 1110, checked in by Peter Johansson, 12 years ago

refs 458. added message to stderr when date is empty, and fixed code in assertion (so it compiles)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1// $Id: SVNlog.cc 1110 2010-07-02 13:11:17Z peter $
2
3/*
4  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
5  Copyright (C) 2009, 2010 Peter Johansson
6
7  This file is part of svndigest, http://dev.thep.lu.se/svndigest
8
9  svndigest is free software; you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 3 of the License, or
12  (at your option) any later version.
13
14  svndigest is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "SVNlog.h"
24
25#include "Commitment.h"
26#include "SVN.h"
27
28#include <algorithm>
29#include <cassert>
30#include <iostream>
31#include <stdexcept>
32#include <sstream>
33#include <string>
34
35namespace theplu {
36namespace svndigest {
37
38
39  SVNlog::SVNlog(void)
40  {
41  }
42
43
44  SVNlog::SVNlog(const std::string& path)
45  {
46    SVN::instance()->client_log(path, log_message_receiver,
47                                static_cast<void*>(&lb_));
48  }
49
50
51  SVNlog::~SVNlog(void)
52  {
53  }
54
55 
56  bool SVNlog::exist(std::string name) const
57  {
58   
59    SVNlog::container::const_reverse_iterator iter = commits().rbegin();
60    for ( ; iter!= commits().rend(); ++iter)
61      if (iter->author() == name)
62        return true;
63    return false;
64  }
65
66
67  const Commitment& SVNlog::latest_commit(void) const
68  {
69    assert(commits().size());
70    return *commits().rbegin();
71  }
72
73
74  const Commitment& SVNlog::latest_commit(std::string name) const
75  {
76    SVNlog::container::const_reverse_iterator iter = commits().rbegin();
77    for ( ; iter!= commits().rend(); ++iter)
78      if (iter->author() == name)
79        return *iter;
80    std::stringstream ss;
81    ss << __FILE__ << " could not find author: " << name;
82    throw std::runtime_error(ss.str());
83    // let us return something to avoid compiler warnings
84    return *commits().begin();
85  }
86
87
88  svn_error_t* 
89  SVNlog::log_message_receiver(void *baton, apr_hash_t *changed_paths,
90                               svn_revnum_t rev, const char *author,
91                               const char *date, const char *msg,
92                               apr_pool_t *pool)
93  {
94    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
95    std::string d;
96    if (date && date[0])
97      d = date;
98    else if (!lb->commits.empty()) {
99      // FIXME: this is a bit hackish to fix the problem reported in
100      // ticket #458. If we lack read permission for rev, no date is
101      // retrived and we use the date of the previous rev. That should
102      // be OK if we call the super-root and previous rev truly is
103      // rev-1 (super-root contains all revs). That should be the
104      // typical case where this happens. If this would happen when
105      // calling the log of a sub-node (e.g. the trunk) this could be
106      // problematic because log is more or less sparse and when
107      // merging two sparse logs together this workaround could have
108      // strange effects such as rev+1 having a earlier date than
109      // rev. To ensure that we only allow this workaround when
110      // calling super-root, we have the assert below:
111      std::cerr << "no date defined for revision: " << rev << "\n";
112      assert(rev == lb->commits.rbegin()->revision()+1);
113      d = lb->commits.rbegin()->date();
114    }
115    else {
116      std::stringstream msg;
117      msg << "No date defined for revision: " << rev;
118      throw SVNException(msg.str()); 
119    }
120    std::string a;
121    if (author && author[0])
122      a=author;
123    std::string message;
124    if (msg)
125      message = msg;
126    lb->commits.insert(lb->commits.end(), Commitment(a, d, message, rev));
127    return SVN_NO_ERROR;
128  }
129
130
131  void SVNlog::swap(SVNlog& rhs)
132  {
133    lb_.commits.swap(rhs.lb_.commits);
134  }
135
136
137  SVNlog& operator+=(SVNlog& lhs, const SVNlog& rhs)
138  {
139    lhs.commits().insert(rhs.commits().begin(), rhs.commits().end());
140    return lhs;
141  }
142
143}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.