@@ -255,8 +255,8 @@ static void hex_format(char *dest, uint8_t *src, int hash_size)
255
255
}
256
256
}
257
257
258
- void reftable_ref_record_print (const struct reftable_ref_record * ref ,
259
- uint32_t hash_id )
258
+ static void reftable_ref_record_print_sz (const struct reftable_ref_record * ref ,
259
+ int hash_size )
260
260
{
261
261
char hex [GIT_MAX_HEXSZ + 1 ] = { 0 }; /* BUG */
262
262
printf ("ref{%s(%" PRIu64 ") " , ref -> refname , ref -> update_index );
@@ -265,14 +265,14 @@ void reftable_ref_record_print(const struct reftable_ref_record *ref,
265
265
printf ("=> %s" , ref -> value .symref );
266
266
break ;
267
267
case REFTABLE_REF_VAL2 :
268
- hex_format (hex , ref -> value .val2 .value , hash_size ( hash_id ) );
268
+ hex_format (hex , ref -> value .val2 .value , hash_size );
269
269
printf ("val 2 %s" , hex );
270
270
hex_format (hex , ref -> value .val2 .target_value ,
271
- hash_size ( hash_id ) );
271
+ hash_size );
272
272
printf ("(T %s)" , hex );
273
273
break ;
274
274
case REFTABLE_REF_VAL1 :
275
- hex_format (hex , ref -> value .val1 , hash_size ( hash_id ) );
275
+ hex_format (hex , ref -> value .val1 , hash_size );
276
276
printf ("val 1 %s" , hex );
277
277
break ;
278
278
case REFTABLE_REF_DELETION :
@@ -282,6 +282,11 @@ void reftable_ref_record_print(const struct reftable_ref_record *ref,
282
282
printf ("}\n" );
283
283
}
284
284
285
+ void reftable_ref_record_print (const struct reftable_ref_record * ref ,
286
+ uint32_t hash_id ) {
287
+ reftable_ref_record_print_sz (ref , hash_size (hash_id ));
288
+ }
289
+
285
290
static void reftable_ref_record_release_void (void * rec )
286
291
{
287
292
reftable_ref_record_release (rec );
@@ -443,6 +448,12 @@ static int reftable_ref_record_equal_void(const void *a,
443
448
return reftable_ref_record_equal (ra , rb , hash_size );
444
449
}
445
450
451
+ static void reftable_ref_record_print_void (const void * rec ,
452
+ int hash_size )
453
+ {
454
+ reftable_ref_record_print_sz ((struct reftable_ref_record * ) rec , hash_size );
455
+ }
456
+
446
457
static struct reftable_record_vtable reftable_ref_record_vtable = {
447
458
.key = & reftable_ref_record_key ,
448
459
.type = BLOCK_TYPE_REF ,
@@ -453,6 +464,7 @@ static struct reftable_record_vtable reftable_ref_record_vtable = {
453
464
.release = & reftable_ref_record_release_void ,
454
465
.is_deletion = & reftable_ref_record_is_deletion_void ,
455
466
.equal = & reftable_ref_record_equal_void ,
467
+ .print = & reftable_ref_record_print_void ,
456
468
};
457
469
458
470
static void reftable_obj_record_key (const void * r , struct strbuf * dest )
@@ -471,6 +483,21 @@ static void reftable_obj_record_release(void *rec)
471
483
memset (obj , 0 , sizeof (struct reftable_obj_record ));
472
484
}
473
485
486
+ static void reftable_obj_record_print (const void * rec , int hash_size )
487
+ {
488
+ const struct reftable_obj_record * obj = rec ;
489
+ char hex [GIT_MAX_HEXSZ + 1 ] = { 0 };
490
+ struct strbuf offset_str = STRBUF_INIT ;
491
+ int i ;
492
+
493
+ for (i = 0 ; i < obj -> offset_len ; i ++ )
494
+ strbuf_addf (& offset_str , "%" PRIu64 " " , obj -> offsets [i ]);
495
+ hex_format (hex , obj -> hash_prefix , obj -> hash_prefix_len );
496
+ printf ("prefix %s (len %d), offsets [%s]\n" ,
497
+ hex , obj -> hash_prefix_len , offset_str .buf );
498
+ strbuf_release (& offset_str );
499
+ }
500
+
474
501
static void reftable_obj_record_copy_from (void * rec , const void * src_rec ,
475
502
int hash_size )
476
503
{
@@ -617,31 +644,41 @@ static struct reftable_record_vtable reftable_obj_record_vtable = {
617
644
.release = & reftable_obj_record_release ,
618
645
.is_deletion = & not_a_deletion ,
619
646
.equal = & reftable_obj_record_equal_void ,
647
+ .print = & reftable_obj_record_print ,
620
648
};
621
649
622
- void reftable_log_record_print (struct reftable_log_record * log ,
623
- uint32_t hash_id )
650
+ static void reftable_log_record_print_sz (struct reftable_log_record * log ,
651
+ int hash_size )
624
652
{
625
653
char hex [GIT_MAX_HEXSZ + 1 ] = { 0 };
626
654
627
655
switch (log -> value_type ) {
628
656
case REFTABLE_LOG_DELETION :
629
- printf ("log{%s(%" PRIu64 ") delete" , log -> refname ,
657
+ printf ("log{%s(%" PRIu64 ") delete\n " , log -> refname ,
630
658
log -> update_index );
631
659
break ;
632
660
case REFTABLE_LOG_UPDATE :
633
661
printf ("log{%s(%" PRIu64 ") %s <%s> %" PRIu64 " %04d\n" ,
634
- log -> refname , log -> update_index , log -> value .update .name ,
635
- log -> value .update .email , log -> value .update .time ,
662
+ log -> refname , log -> update_index ,
663
+ log -> value .update .name ? log -> value .update .name : "" ,
664
+ log -> value .update .email ? log -> value .update .email : "" ,
665
+ log -> value .update .time ,
636
666
log -> value .update .tz_offset );
637
- hex_format (hex , log -> value .update .old_hash , hash_size ( hash_id ) );
667
+ hex_format (hex , log -> value .update .old_hash , hash_size );
638
668
printf ("%s => " , hex );
639
- hex_format (hex , log -> value .update .new_hash , hash_size (hash_id ));
640
- printf ("%s\n\n%s\n}\n" , hex , log -> value .update .message );
669
+ hex_format (hex , log -> value .update .new_hash , hash_size );
670
+ printf ("%s\n\n%s\n}\n" , hex ,
671
+ log -> value .update .message ? log -> value .update .message : "" );
641
672
break ;
642
673
}
643
674
}
644
675
676
+ void reftable_log_record_print (struct reftable_log_record * log ,
677
+ uint32_t hash_id )
678
+ {
679
+ reftable_log_record_print_sz (log , hash_size (hash_id ));
680
+ }
681
+
645
682
static void reftable_log_record_key (const void * r , struct strbuf * dest )
646
683
{
647
684
const struct reftable_log_record * rec =
@@ -959,6 +996,11 @@ static int reftable_log_record_is_deletion_void(const void *p)
959
996
(const struct reftable_log_record * )p );
960
997
}
961
998
999
+ static void reftable_log_record_print_void (const void * rec , int hash_size )
1000
+ {
1001
+ reftable_log_record_print_sz ((struct reftable_log_record * )rec , hash_size );
1002
+ }
1003
+
962
1004
static struct reftable_record_vtable reftable_log_record_vtable = {
963
1005
.key = & reftable_log_record_key ,
964
1006
.type = BLOCK_TYPE_LOG ,
@@ -968,7 +1010,8 @@ static struct reftable_record_vtable reftable_log_record_vtable = {
968
1010
.decode = & reftable_log_record_decode ,
969
1011
.release = & reftable_log_record_release_void ,
970
1012
.is_deletion = & reftable_log_record_is_deletion_void ,
971
- .equal = & reftable_log_record_equal_void
1013
+ .equal = & reftable_log_record_equal_void ,
1014
+ .print = & reftable_log_record_print_void ,
972
1015
};
973
1016
974
1017
static void reftable_index_record_key (const void * r , struct strbuf * dest )
@@ -1043,6 +1086,13 @@ static int reftable_index_record_equal(const void *a, const void *b, int hash_si
1043
1086
return ia -> offset == ib -> offset && !strbuf_cmp (& ia -> last_key , & ib -> last_key );
1044
1087
}
1045
1088
1089
+ static void reftable_index_record_print (const void * rec , int hash_size )
1090
+ {
1091
+ const struct reftable_index_record * idx = rec ;
1092
+ /* TODO: escape null chars? */
1093
+ printf ("\"%s\" %" PRIu64 "\n" , idx -> last_key .buf , idx -> offset );
1094
+ }
1095
+
1046
1096
static struct reftable_record_vtable reftable_index_record_vtable = {
1047
1097
.key = & reftable_index_record_key ,
1048
1098
.type = BLOCK_TYPE_INDEX ,
@@ -1053,6 +1103,7 @@ static struct reftable_record_vtable reftable_index_record_vtable = {
1053
1103
.release = & reftable_index_record_release ,
1054
1104
.is_deletion = & not_a_deletion ,
1055
1105
.equal = & reftable_index_record_equal ,
1106
+ .print = & reftable_index_record_print ,
1056
1107
};
1057
1108
1058
1109
void reftable_record_key (struct reftable_record * rec , struct strbuf * dest )
@@ -1255,3 +1306,9 @@ struct reftable_record reftable_new_record(uint8_t typ)
1255
1306
}
1256
1307
return clean ;
1257
1308
}
1309
+
1310
+ void reftable_record_print (struct reftable_record * rec , int hash_size )
1311
+ {
1312
+ printf ("'%c': " , rec -> type );
1313
+ reftable_record_vtable (rec )-> print (reftable_record_data (rec ), hash_size );
1314
+ }
0 commit comments