1/* 2 * compat.c : Wrappers and callbacks for compatibility. 3 * 4 * ==================================================================== 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * ==================================================================== 22 */ 23 24#include <apr_pools.h> 25#include <apr_strings.h> 26 27#include "svn_hash.h" 28#include "svn_types.h" 29#include "svn_error.h" 30#include "svn_compat.h" 31#include "svn_props.h" 32 33 34/* Baton for use with svn_compat_wrap_commit_callback */ 35struct commit_wrapper_baton { 36 void *baton; 37 svn_commit_callback_t callback; 38}; 39 40/* This implements svn_commit_callback2_t. */ 41static svn_error_t * 42commit_wrapper_callback(const svn_commit_info_t *commit_info, 43 void *baton, apr_pool_t *pool) 44{ 45 struct commit_wrapper_baton *cwb = baton; 46 47 if (cwb->callback) 48 return cwb->callback(commit_info->revision, 49 commit_info->date, 50 commit_info->author, 51 cwb->baton); 52 53 return SVN_NO_ERROR; 54} 55 56void 57svn_compat_wrap_commit_callback(svn_commit_callback2_t *callback2, 58 void **callback2_baton, 59 svn_commit_callback_t callback, 60 void *callback_baton, 61 apr_pool_t *pool) 62{ 63 struct commit_wrapper_baton *cwb = apr_palloc(pool, sizeof(*cwb)); 64 65 /* Set the user provided old format callback in the baton */ 66 cwb->baton = callback_baton; 67 cwb->callback = callback; 68 69 *callback2_baton = cwb; 70 *callback2 = commit_wrapper_callback; 71} 72 73 74void 75svn_compat_log_revprops_clear(apr_hash_t *revprops) 76{ 77 if (revprops) 78 { 79 svn_hash_sets(revprops, SVN_PROP_REVISION_AUTHOR, NULL); 80 svn_hash_sets(revprops, SVN_PROP_REVISION_DATE, NULL); 81 svn_hash_sets(revprops, SVN_PROP_REVISION_LOG, NULL); 82 } 83} 84 85apr_array_header_t * 86svn_compat_log_revprops_in(apr_pool_t *pool) 87{ 88 apr_array_header_t *revprops = apr_array_make(pool, 3, sizeof(char *)); 89 90 APR_ARRAY_PUSH(revprops, const char *) = SVN_PROP_REVISION_AUTHOR; 91 APR_ARRAY_PUSH(revprops, const char *) = SVN_PROP_REVISION_DATE; 92 APR_ARRAY_PUSH(revprops, const char *) = SVN_PROP_REVISION_LOG; 93 94 return revprops; 95} 96 97void 98svn_compat_log_revprops_out(const char **author, const char **date, 99 const char **message, apr_hash_t *revprops) 100{ 101 svn_string_t *author_s, *date_s, *message_s; 102 103 *author = *date = *message = NULL; 104 if (revprops) 105 { 106 if ((author_s = svn_hash_gets(revprops, SVN_PROP_REVISION_AUTHOR))) 107 *author = author_s->data; 108 if ((date_s = svn_hash_gets(revprops, SVN_PROP_REVISION_DATE))) 109 *date = date_s->data; 110 if ((message_s = svn_hash_gets(revprops, SVN_PROP_REVISION_LOG))) 111 *message = message_s->data; 112 } 113} 114 115/* Baton for use with svn_compat_wrap_log_receiver */ 116struct log_wrapper_baton { 117 void *baton; 118 svn_log_message_receiver_t receiver; 119}; 120 121/* This implements svn_log_entry_receiver_t. */ 122static svn_error_t * 123log_wrapper_callback(void *baton, 124 svn_log_entry_t *log_entry, 125 apr_pool_t *pool) 126{ 127 struct log_wrapper_baton *lwb = baton; 128 129 if (lwb->receiver && SVN_IS_VALID_REVNUM(log_entry->revision)) 130 { 131 const char *author, *date, *message; 132 svn_compat_log_revprops_out(&author, &date, &message, 133 log_entry->revprops); 134 return lwb->receiver(lwb->baton, 135 log_entry->changed_paths2, 136 log_entry->revision, 137 author, date, message, 138 pool); 139 } 140 141 return SVN_NO_ERROR; 142} 143 144void 145svn_compat_wrap_log_receiver(svn_log_entry_receiver_t *receiver2, 146 void **receiver2_baton, 147 svn_log_message_receiver_t receiver, 148 void *receiver_baton, 149 apr_pool_t *pool) 150{ 151 struct log_wrapper_baton *lwb = apr_palloc(pool, sizeof(*lwb)); 152 153 /* Set the user provided old format callback in the baton. */ 154 lwb->baton = receiver_baton; 155 lwb->receiver = receiver; 156 157 *receiver2_baton = lwb; 158 *receiver2 = log_wrapper_callback; 159} 160