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