19
19
#include "varint.h"
20
20
#include "ewah/ewok.h"
21
21
#include "fsmonitor.h"
22
+ #include "json-writer.h"
22
23
#include "submodule-config.h"
23
24
24
25
/*
@@ -2826,7 +2827,42 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
2826
2827
oid_stat -> valid = 1 ;
2827
2828
}
2828
2829
2829
- struct untracked_cache * read_untracked_extension (const void * data , unsigned long sz )
2830
+ static void jw_object_oid_stat (struct json_writer * jw , const char * key ,
2831
+ const struct oid_stat * oid_stat )
2832
+ {
2833
+ jw_object_inline_begin_object (jw , key );
2834
+ jw_object_bool (jw , "valid" , oid_stat -> valid );
2835
+ jw_object_string (jw , "oid" , oid_to_hex (& oid_stat -> oid ));
2836
+ jw_object_stat_data (jw , "stat" , & oid_stat -> stat );
2837
+ jw_end (jw );
2838
+ }
2839
+
2840
+ static void jw_object_untracked_cache_dir (struct json_writer * jw ,
2841
+ const struct untracked_cache_dir * ucd )
2842
+ {
2843
+ int i ;
2844
+
2845
+ jw_object_bool (jw , "valid" , ucd -> valid );
2846
+ jw_object_bool (jw , "check-only" , ucd -> check_only );
2847
+ jw_object_stat_data (jw , "stat" , & ucd -> stat_data );
2848
+ jw_object_string (jw , "exclude-oid" , oid_to_hex (& ucd -> exclude_oid ));
2849
+ jw_object_inline_begin_array (jw , "untracked" );
2850
+ for (i = 0 ; i < ucd -> untracked_nr ; i ++ )
2851
+ jw_array_string (jw , ucd -> untracked [i ]);
2852
+ jw_end (jw );
2853
+
2854
+ jw_object_inline_begin_object (jw , "dirs" );
2855
+ for (i = 0 ; i < ucd -> dirs_nr ; i ++ ) {
2856
+ jw_object_inline_begin_object (jw , ucd -> dirs [i ]-> name );
2857
+ jw_object_untracked_cache_dir (jw , ucd -> dirs [i ]);
2858
+ jw_end (jw );
2859
+ }
2860
+ jw_end (jw );
2861
+ }
2862
+
2863
+ struct untracked_cache * read_untracked_extension (const void * data ,
2864
+ unsigned long sz ,
2865
+ struct json_writer * jw )
2830
2866
{
2831
2867
struct untracked_cache * uc ;
2832
2868
struct read_data rd ;
@@ -2864,6 +2900,17 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
2864
2900
uc -> dir_flags = get_be32 (next + ouc_offset (dir_flags ));
2865
2901
exclude_per_dir = (const char * )next + exclude_per_dir_offset ;
2866
2902
uc -> exclude_per_dir = xstrdup (exclude_per_dir );
2903
+
2904
+ if (jw ) {
2905
+ jw_object_inline_begin_object (jw , "untracked-cache" );
2906
+ jw_object_intmax (jw , "ext-size" , sz );
2907
+ jw_object_string (jw , "ident" , ident );
2908
+ jw_object_oid_stat (jw , "info/exclude" , & uc -> ss_info_exclude );
2909
+ jw_object_oid_stat (jw , "excludes-file" , & uc -> ss_excludes_file );
2910
+ jw_object_intmax (jw , "flags" , uc -> dir_flags );
2911
+ jw_object_string (jw , "excludes-per-dir" , uc -> exclude_per_dir );
2912
+ }
2913
+
2867
2914
/* NUL after exclude_per_dir is covered by sizeof(*ouc) */
2868
2915
next += exclude_per_dir_offset + strlen (exclude_per_dir ) + 1 ;
2869
2916
if (next >= end )
@@ -2905,6 +2952,12 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
2905
2952
ewah_each_bit (rd .sha1_valid , read_oid , & rd );
2906
2953
next = rd .data ;
2907
2954
2955
+ if (jw ) {
2956
+ jw_object_inline_begin_object (jw , "root" );
2957
+ jw_object_untracked_cache_dir (jw , uc -> root );
2958
+ jw_end (jw );
2959
+ }
2960
+
2908
2961
done :
2909
2962
free (rd .ucd );
2910
2963
ewah_free (rd .valid );
@@ -2915,6 +2968,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
2915
2968
free_untracked_cache (uc );
2916
2969
uc = NULL ;
2917
2970
}
2971
+ jw_end_gently (jw );
2918
2972
return uc ;
2919
2973
}
2920
2974
0 commit comments