1 /* dump-index-cmd.c -- implements the dump-index sub-command.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
20 * ====================================================================
23 #define APR_WANT_BYTEFUNC
25 #include "svn_dirent_uri.h"
26 #include "svn_pools.h"
27 #include "private/svn_fs_fs_private.h"
31 /* Return the 8 digit hex string for FNVV1, allocated in POOL.
34 fnv1_to_string(apr_uint32_t fnv1,
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;
42 /* Convert the digest to hex. */
43 return svn_checksum_to_cstring_display(&checksum, pool);
46 /* Map svn_fs_fs__p2l_entry_t.type to C string. */
47 static const char *item_type_str[]
48 = {"none ", "frep ", "drep ", "fprop", "dprop", "node ", "chgs ", "rep "};
50 /* Implements svn_fs_fs__dump_index_func_t as printing one table row
51 * containing the fields of ENTRY to the console.
54 dump_index_entry(const svn_fs_fs__p2l_entry_t *entry,
56 apr_pool_t *scratch_pool)
59 = entry->type < (sizeof(item_type_str) / sizeof(item_type_str[0]))
60 ? item_type_str[entry->type]
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));
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.
77 dump_index(const char *path,
78 svn_revnum_t revision,
83 /* Check repository type and open it. */
84 SVN_ERR(open_fs(&fs, path, pool));
86 /* Write header line. */
87 printf(" Start Length Type Revision Item Checksum\n");
89 /* Dump the whole index contents */
90 SVN_ERR(svn_fs_fs__dump_index(fs, revision, dump_index_entry, NULL,
91 check_cancel, NULL, pool));
96 /* This implements `svn_opt_subcommand_t'. */
98 subcommand__dump_index(apr_getopt_t *os, void *baton, apr_pool_t *pool)
100 svnfsfs__opt_state *opt_state = baton;
102 SVN_ERR(dump_index(opt_state->repository_path,
103 opt_state->start_revision.value.number, pool));