1
+ #include "git-compat-util.h"
2
+ #include "hash.h"
3
+ #include "hex.h"
1
4
#include "reftable/system.h"
2
5
#include "reftable/reftable-error.h"
3
6
#include "reftable/reftable-generic.h"
@@ -30,33 +33,12 @@ static void print_help(void)
30
33
"\n" );
31
34
}
32
35
33
- static char hexdigit (int c )
34
- {
35
- if (c <= 9 )
36
- return '0' + c ;
37
- return 'a' + (c - 10 );
38
- }
39
-
40
- static void hex_format (char * dest , const unsigned char * src , int hash_size )
41
- {
42
- assert (hash_size > 0 );
43
- if (src ) {
44
- int i = 0 ;
45
- for (i = 0 ; i < hash_size ; i ++ ) {
46
- dest [2 * i ] = hexdigit (src [i ] >> 4 );
47
- dest [2 * i + 1 ] = hexdigit (src [i ] & 0xf );
48
- }
49
- dest [2 * hash_size ] = 0 ;
50
- }
51
- }
52
-
53
36
static int dump_table (struct reftable_table * tab )
54
37
{
55
38
struct reftable_iterator it = { NULL };
56
39
struct reftable_ref_record ref = { NULL };
57
40
struct reftable_log_record log = { NULL };
58
- uint32_t hash_id = reftable_table_hash_id (tab );
59
- int hash_len = hash_size (hash_id );
41
+ const struct git_hash_algo * algop ;
60
42
int err ;
61
43
62
44
reftable_table_init_ref_iter (tab , & it );
@@ -65,9 +47,9 @@ static int dump_table(struct reftable_table *tab)
65
47
if (err < 0 )
66
48
return err ;
67
49
68
- while (1 ) {
69
- char hex [GIT_MAX_HEXSZ + 1 ] = { 0 }; /* BUG */
50
+ algop = & hash_algos [hash_algo_by_id (reftable_table_hash_id (tab ))];
70
51
52
+ while (1 ) {
71
53
err = reftable_iterator_next_ref (& it , & ref );
72
54
if (err > 0 )
73
55
break ;
@@ -80,15 +62,11 @@ static int dump_table(struct reftable_table *tab)
80
62
printf ("=> %s" , ref .value .symref );
81
63
break ;
82
64
case REFTABLE_REF_VAL2 :
83
- hex_format (hex , ref .value .val2 .value , hash_len );
84
- printf ("val 2 %s" , hex );
85
- hex_format (hex , ref .value .val2 .target_value ,
86
- hash_len );
87
- printf ("(T %s)" , hex );
65
+ printf ("val 2 %s" , hash_to_hex_algop (ref .value .val2 .value , algop ));
66
+ printf ("(T %s)" , hash_to_hex_algop (ref .value .val2 .target_value , algop ));
88
67
break ;
89
68
case REFTABLE_REF_VAL1 :
90
- hex_format (hex , ref .value .val1 , hash_len );
91
- printf ("val 1 %s" , hex );
69
+ printf ("val 1 %s" , hash_to_hex_algop (ref .value .val1 , algop ));
92
70
break ;
93
71
case REFTABLE_REF_DELETION :
94
72
printf ("delete" );
@@ -106,8 +84,6 @@ static int dump_table(struct reftable_table *tab)
106
84
return err ;
107
85
108
86
while (1 ) {
109
- char hex [GIT_MAX_HEXSZ + 1 ] = { 0 };
110
-
111
87
err = reftable_iterator_next_log (& it , & log );
112
88
if (err > 0 )
113
89
break ;
@@ -126,10 +102,8 @@ static int dump_table(struct reftable_table *tab)
126
102
log .value .update .email ? log .value .update .email : "" ,
127
103
log .value .update .time ,
128
104
log .value .update .tz_offset );
129
- hex_format (hex , log .value .update .old_hash , hash_len );
130
- printf ("%s => " , hex );
131
- hex_format (hex , log .value .update .new_hash , hash_len );
132
- printf ("%s\n\n%s\n}\n" , hex ,
105
+ printf ("%s => " , hash_to_hex_algop (log .value .update .old_hash , algop ));
106
+ printf ("%s\n\n%s\n}\n" , hash_to_hex_algop (log .value .update .new_hash , algop ),
133
107
log .value .update .message ? log .value .update .message : "" );
134
108
break ;
135
109
}
0 commit comments