]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/svnfsfs/dump-index-cmd.c
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / svnfsfs / dump-index-cmd.c
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  */
33 static const char *
34 fnv1_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. */
47 static 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  */
53 static svn_error_t *
54 dump_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  */
76 static svn_error_t *
77 dump_index(const char *path,
78            svn_revnum_t revision,
79            apr_pool_t *pool)
80 {
81   svn_fs_t *fs;
82
83   /* Check repository type and open it. */
84   SVN_ERR(open_fs(&fs, path, pool));
85
86   /* Write header line. */
87   printf("       Start       Length Type   Revision     Item Checksum\n");
88
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));
92
93   return SVN_NO_ERROR;
94 }
95
96 /* This implements `svn_opt_subcommand_t'. */
97 svn_error_t *
98 subcommand__dump_index(apr_getopt_t *os, void *baton, apr_pool_t *pool)
99 {
100   svnfsfs__opt_state *opt_state = baton;
101
102   SVN_ERR(dump_index(opt_state->repository_path,
103                      opt_state->start_revision.value.number, pool));
104
105   return SVN_NO_ERROR;
106 }