1/* dump-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#define APR_WANT_BYTEFUNC 24 25#include "svn_dirent_uri.h" 26#include "svn_pools.h" 27#include "private/svn_fs_fs_private.h" 28 29#include "svnfsfs.h" 30 31/* Return the 8 digit hex string for FNVV1, allocated in POOL. 32 */ 33static const char * 34fnv1_to_string(apr_uint32_t fnv1, 35 apr_pool_t *pool) 36{ 37 /* Construct a checksum object containing FNV1. */ 38 svn_checksum_t checksum = { NULL, svn_checksum_fnv1a_32 }; 39 apr_uint32_t digest = htonl(fnv1); 40 checksum.digest = (const unsigned char *)&digest; 41 42 /* Convert the digest to hex. */ 43 return svn_checksum_to_cstring_display(&checksum, pool); 44} 45 46/* Map svn_fs_fs__p2l_entry_t.type to C string. */ 47static const char *item_type_str[] 48 = {"none ", "frep ", "drep ", "fprop", "dprop", "node ", "chgs ", "rep "}; 49 50/* Implements svn_fs_fs__dump_index_func_t as printing one table row 51 * containing the fields of ENTRY to the console. 52 */ 53static svn_error_t * 54dump_index_entry(const svn_fs_fs__p2l_entry_t *entry, 55 void *baton, 56 apr_pool_t *scratch_pool) 57{ 58 const char *type_str 59 = entry->type < (sizeof(item_type_str) / sizeof(item_type_str[0])) 60 ? item_type_str[entry->type] 61 : "???"; 62 63 printf("%12" APR_UINT64_T_HEX_FMT " %12" APR_UINT64_T_HEX_FMT 64 " %s %9ld %8" APR_UINT64_T_FMT " %s\n", 65 (apr_uint64_t)entry->offset, (apr_uint64_t)entry->size, 66 type_str, entry->item.revision, entry->item.number, 67 fnv1_to_string(entry->fnv1_checksum, scratch_pool)); 68 69 return SVN_NO_ERROR; 70} 71 72/* Read the repository at PATH beginning with revision START_REVISION and 73 * return the result in *FS. Allocate caches with MEMSIZE bytes total 74 * capacity. Use POOL for non-cache allocations. 75 */ 76static svn_error_t * 77dump_index(const char *path, 78 svn_revnum_t revision, 79 apr_pool_t *pool) 80{ 81 svn_fs_t *fs; 82 svn_fs_fs__ioctl_dump_index_input_t input = {0}; 83 84 /* Check repository type and open it. */ 85 SVN_ERR(open_fs(&fs, path, pool)); 86 87 /* Write header line. */ 88 printf(" Start Length Type Revision Item Checksum\n"); 89 90 /* Dump the whole index contents */ 91 input.revision = revision; 92 input.callback_func = dump_index_entry; 93 SVN_ERR(svn_fs_ioctl(fs, SVN_FS_FS__IOCTL_DUMP_INDEX, &input, NULL, 94 check_cancel, NULL, pool, pool)); 95 96 return SVN_NO_ERROR; 97} 98 99/* This implements `svn_opt_subcommand_t'. */ 100svn_error_t * 101subcommand__dump_index(apr_getopt_t *os, void *baton, apr_pool_t *pool) 102{ 103 svnfsfs__opt_state *opt_state = baton; 104 105 SVN_ERR(dump_index(opt_state->repository_path, 106 opt_state->start_revision.value.number, pool)); 107 108 return SVN_NO_ERROR; 109} 110