Diff
Not logged in

Differences From Artifact [483018b79b]:

To Artifact [94ae971709]:


2910
2911
2912
2913
2914
2915
2916



2917
2918
2919
2920
2921
2922
2923
2924












2925



2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
  db_find_and_open_repository(0, 0);
  if( g.argc!=3 ) usage("RECORDID");
  rid = name_to_rid(g.argv[2]);
  content_get(rid, &content);
  manifest_crosslink(rid, &content, MC_NONE);
}




void artifact_to_json(Manifest *p, Blob *pOut){
  char * zTmp;
  blob_reset(pOut);
  blob_append_literal(pOut, "{");
  blob_appendf(pOut, "\"rid\": %d, ", p->rid);
  zTmp = rid_to_uuid(p->rid);
  blob_appendf(pOut, "\"uuid\": %!j", zTmp);
  fossil_free(zTmp);












  blob_append_literal(pOut, "}");



}

/*
** Convenience wrapper around artifact_to_json() which accepts any
** artifact name which is legal for symbolic_name_to_rid(). On success
** it returns the rid of the artifact. Returns 0 if no such artifact
** exists and a negative value if the name is ambiguous.
**
** If it returns a valid rid, pOut will be cleared before emitting the
** JSON to it.
**
*/
int artifact_to_json_by_name(const char *zName, Blob *pOut){
  int rid;

  rid = symbolic_name_to_rid(zName, 0);
  if( rid>0 ){
    Manifest * const p = manifest_get(rid, CFTYPE_ANY, 0);







>
>
>


<

|

|

>
>
>
>
>
>
>
>
>
>
>
>

>
>
>








|
|
<







2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921

2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952

2953
2954
2955
2956
2957
2958
2959
  db_find_and_open_repository(0, 0);
  if( g.argc!=3 ) usage("RECORDID");
  rid = name_to_rid(g.argv[2]);
  content_get(rid, &content);
  manifest_crosslink(rid, &content, MC_NONE);
}

/*
** Creates a JSON representation of p, appending it to pOut.
*/
void artifact_to_json(Manifest *p, Blob *pOut){
  char * zTmp;

  blob_append_literal(pOut, "{");
  blob_appendf(pOut, "\"rid\": %d", p->rid);
  zTmp = rid_to_uuid(p->rid);
  blob_appendf(pOut, ", \"uuid\": %!j", zTmp);
  fossil_free(zTmp);
#define CARD_FMT(LETTER, FMT, VAL)                                 \
  blob_appendf(pOut, ",\"" #LETTER "\": " #FMT, VAL)
#define CARD_STR(LETTER, VAL) \
  assert( VAL ); CARD_FMT(LETTER, %!j, VAL)
#define CARD_STR2(LETTER, VAL) \
  if( VAL ) { CARD_FMT(LETTER, %!j, VAL); }

  CARD_STR2(B, p->zBaseline);
  CARD_STR2(C, p->zComment);
  CARD_FMT(D, %f, p->rDate);
  CARD_STR2(W, p->zWiki);
  CARD_STR2(R, p->zRepoCksum);
  blob_append_literal(pOut, "}");
#undef CARD_STR
#undef CARD_STR2
#undef CARD_FMT
}

/*
** Convenience wrapper around artifact_to_json() which accepts any
** artifact name which is legal for symbolic_name_to_rid(). On success
** it returns the rid of the artifact. Returns 0 if no such artifact
** exists and a negative value if the name is ambiguous.
**
** pOut is not cleared before rendering, so the caller needs to do
** that if it's important for their use case.

*/
int artifact_to_json_by_name(const char *zName, Blob *pOut){
  int rid;

  rid = symbolic_name_to_rid(zName, 0);
  if( rid>0 ){
    Manifest * const p = manifest_get(rid, CFTYPE_ANY, 0);
2956
2957
2958
2959
2960
2961
2962

2963
2964
2965
2966
2967
2968
2969

2970

2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981


2982

** Tests the artifact_to_json() and artifact_to_json_by_name() APIs.
*/
void test_manifest_to_json(void){
  int i;
  Blob b = empty_blob;
  Stmt q;
  const int bPretty = find_option("pretty",0,0)!=0;


  db_find_and_open_repository(0,0);
  db_prepare(&q, "select json_pretty(:json)");
  for( i=2; i<g.argc; ++i ){
    char const *zName = g.argv[i];
    const int rc = artifact_to_json_by_name(zName, &b);
    if( rc<=0 ){

      fossil_warning("Error reading artifact %Q\n", zName);

    }else if( bPretty ){
      db_bind_blob(&q, ":json", &b);
      b.nUsed = 0;
      db_step(&q);
      db_column_blob(&q, 0, &b);
      db_reset(&q);
    }
    fossil_print("%b\n", &b);
    blob_reset(&b);
  }
  db_finalize(&q);


}








>







>
|
>











>
>
|
>
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
** Tests the artifact_to_json() and artifact_to_json_by_name() APIs.
*/
void test_manifest_to_json(void){
  int i;
  Blob b = empty_blob;
  Stmt q;
  const int bPretty = find_option("pretty",0,0)!=0;
  int nErr = 0;

  db_find_and_open_repository(0,0);
  db_prepare(&q, "select json_pretty(:json)");
  for( i=2; i<g.argc; ++i ){
    char const *zName = g.argv[i];
    const int rc = artifact_to_json_by_name(zName, &b);
    if( rc<=0 ){
      ++nErr;
      fossil_warning("Error reading artifact %Q", zName);
      continue;
    }else if( bPretty ){
      db_bind_blob(&q, ":json", &b);
      b.nUsed = 0;
      db_step(&q);
      db_column_blob(&q, 0, &b);
      db_reset(&q);
    }
    fossil_print("%b\n", &b);
    blob_reset(&b);
  }
  db_finalize(&q);
  if( nErr ){
    fossil_warning("Error count: %d", nErr);
  }
}