load-index.c revision 302408
1/* load-index-cmd.c -- implements the dump-index sub-command. 2 * 3 * ==================================================================== 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 * ==================================================================== 21 */ 22 23#include "svn_pools.h" 24 25#include "private/svn_fs_fs_private.h" 26#include "private/svn_sorts_private.h" 27 28#include "index.h" 29#include "util.h" 30#include "transaction.h" 31 32/* A svn_sort__array compatible comparator function, sorting the 33 * svn_fs_fs__p2l_entry_t** given in LHS, RHS by offset. */ 34static int 35compare_p2l_entry_revision(const void *lhs, 36 const void *rhs) 37{ 38 const svn_fs_fs__p2l_entry_t *lhs_entry 39 =*(const svn_fs_fs__p2l_entry_t **)lhs; 40 const svn_fs_fs__p2l_entry_t *rhs_entry 41 =*(const svn_fs_fs__p2l_entry_t **)rhs; 42 43 if (lhs_entry->offset < rhs_entry->offset) 44 return -1; 45 46 return lhs_entry->offset == rhs_entry->offset ? 0 : 1; 47} 48 49svn_error_t * 50svn_fs_fs__load_index(svn_fs_t *fs, 51 svn_revnum_t revision, 52 apr_array_header_t *entries, 53 apr_pool_t *scratch_pool) 54{ 55 apr_pool_t *iterpool = svn_pool_create(scratch_pool); 56 57 /* Check the FS format number. */ 58 if (! svn_fs_fs__use_log_addressing(fs)) 59 return svn_error_create(SVN_ERR_FS_UNSUPPORTED_FORMAT, NULL, NULL); 60 61 /* P2L index must be written in offset order. 62 * Sort ENTRIES accordingly. */ 63 svn_sort__array(entries, compare_p2l_entry_revision); 64 65 /* Treat an empty array as a no-op instead error. */ 66 if (entries->nelts != 0) 67 { 68 const char *l2p_proto_index; 69 const char *p2l_proto_index; 70 svn_fs_fs__revision_file_t *rev_file; 71 72 /* Open rev / pack file & trim indexes + footer off it. */ 73 SVN_ERR(svn_fs_fs__open_pack_or_rev_file_writable(&rev_file, fs, 74 revision, iterpool, 75 iterpool)); 76 SVN_ERR(svn_fs_fs__auto_read_footer(rev_file)); 77 SVN_ERR(svn_io_file_trunc(rev_file->file, rev_file->l2p_offset, 78 iterpool)); 79 80 /* Create proto index files for the new index data 81 * (will be cleaned up automatically with iterpool). */ 82 SVN_ERR(svn_fs_fs__p2l_index_from_p2l_entries(&p2l_proto_index, fs, 83 rev_file, entries, 84 iterpool, iterpool)); 85 SVN_ERR(svn_fs_fs__l2p_index_from_p2l_entries(&l2p_proto_index, fs, 86 entries, iterpool, 87 iterpool)); 88 89 /* Combine rev data with new index data. */ 90 SVN_ERR(svn_fs_fs__add_index_data(fs, rev_file->file, l2p_proto_index, 91 p2l_proto_index, 92 rev_file->start_revision, iterpool)); 93 } 94 95 svn_pool_destroy(iterpool); 96 97 return SVN_NO_ERROR; 98} 99