13 #ifndef __STOUT_SVN_HPP__ 14 #define __STOUT_SVN_HPP__ 16 #include <apr_pools.h> 20 #include <svn_delta.h> 21 #include <svn_error.h> 22 #include <svn_pools.h> 23 #include <svn_version.h> 80 apr_pool_t* pool = svn_pool_create(
nullptr);
85 source.data = from.data();
86 source.len = from.length();
89 target.data = to.data();
90 target.len = to.length();
92 svn_txdelta_stream_t* delta;
94 #if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 8 97 svn_stream_from_string(&source, pool),
98 svn_stream_from_string(&target, pool),
104 svn_stream_from_string(&source, pool),
105 svn_stream_from_string(&target, pool),
112 svn_txdelta_window_handler_t handler;
113 void* baton =
nullptr;
114 svn_stringbuf_t*
diff = svn_stringbuf_create_ensure(1024, pool);
116 #if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 7 117 svn_txdelta_to_svndiff3(
120 svn_stream_from_stringbuf(diff, pool),
122 SVN_DELTA_COMPRESSION_LEVEL_DEFAULT,
124 #elif SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 4 125 svn_txdelta_to_svndiff2(
128 svn_stream_from_stringbuf(diff, pool),
132 svn_txdelta_to_svndiff(
133 svn_stream_from_stringbuf(diff, pool),
140 svn_error_t*
error = svn_txdelta_send_txstream(delta, handler, baton, pool);
142 if (error !=
nullptr) {
144 std::string message(svn_err_best_message(error, buffer, 1024));
145 svn_pool_destroy(pool);
146 return Error(message);
149 Diff d(std::string(diff->data, diff->len));
151 svn_pool_destroy(pool);
165 apr_pool_t* pool = svn_pool_create(
nullptr);
171 source.data = s.data();
172 source.len = s.length();
174 svn_txdelta_window_handler_t handler;
175 void* baton =
nullptr;
177 svn_stringbuf_t* patched = svn_stringbuf_create_ensure(s.length(), pool);
180 svn_stream_from_string(&source, pool),
181 svn_stream_from_stringbuf(patched, pool),
190 svn_stream_t* stream = svn_txdelta_parse_svndiff(
197 const char*
data = diff.
data.data();
198 apr_size_t length = diff.
data.length();
200 svn_error_t*
error = svn_stream_write(stream, data, &length);
202 if (error !=
nullptr) {
204 std::string message(svn_err_best_message(error, buffer, 1024));
205 svn_pool_destroy(pool);
206 return Error(message);
209 std::string result(patched->data, patched->len);
211 svn_pool_destroy(pool);
218 #endif // __STOUT_SVN_HPP__ Try< Diff > diff(const std::string &from, const std::string &to)
Definition: svn.hpp:72
void initialize()
Definition: svn.hpp:45
Definition: errorbase.hpp:36
Try< std::string > patch(const std::string &s, const Diff &diff)
Definition: svn.hpp:157
std::string data
Definition: svn.hpp:35
Diff(const std::string &data)
Definition: svn.hpp:33
std::string error(const std::string &msg, uint32_t code)