Fossil

Check-in [cc444a02]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:more consolidation of timeline/artifact code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | json-multitag-test | json
Files: files | file ages | folders
SHA1: cc444a02cd9cc4b3fb9aa7d4848e9386f250fd15
User & Date: stephan 2011-10-01 07:47:26
Context
2011-10-01
07:58
s/commit/checkin/, for consistency. s/artifactType/type/. check-in: 44e032aa user: stephan tags: json-multitag-test, json
07:47
more consolidation of timeline/artifact code. check-in: cc444a02 user: stephan tags: json-multitag-test, json
07:04
more timeline/artifact refactoring. check-in: 22fc0ab8 user: stephan tags: json-multitag-test, json
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/json_artifact.c.

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
33
34
35
36
37
38
39
40
41
42
43
44




45
46
47
48
49
50
51
52
53



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79



80


81
82
83
84
85
86
87
88
89



90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include "json_artifact.h"

#if INTERFACE
#include "json_detail.h"
#endif

/*
** Internal callback for /json/artifact handlers. rid and uid refer to
** the rid/uid of a given type of artifact, and each callback is
** specialized to return a JSON form of one type of artifact.
*/
typedef cson_value * (*artifact_f)( int rid, char const * uid );

typedef struct ArtifactDispatchEntry {
  /**
     Artifact type name, e.g. "checkin".
   */
  char const * name;
  /**
................................................................................

/*
** Generates an artifact Object for the given rid/zUuid. rid
** must refer to a Checkin.
**
** Returned value is NULL or an Object owned by the caller.
*/
cson_value * json_artifact_for_ci( int rid, char const * zUuid, char showFiles ){
  char const * zParent = NULL;
  cson_value * v = NULL;
  Stmt q;
  assert( NULL != zUuid );




  zParent = db_text(0,
    "SELECT uuid FROM plink, blob"
    " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim",
    rid
  );

  db_prepare(&q, 
             "SELECT uuid, mtime, user, comment,"
             "       omtime"



             "  FROM blob, event"
             " WHERE blob.rid=%d"
             "   AND event.objid=%d",
             rid, rid
             );
  if( db_step(&q)==SQLITE_ROW ){
    cson_object * o;
    cson_value * tmpV = NULL;
    v = cson_value_new_object();
    o = cson_value_get_object(v);
    /*const char *zUuid = db_column_text(&q, 0);*/
    char * zTmp;
    const char *zUser;
    const char *zComment;
    char * zEUser, * zEComment;
    int mtime, omtime;
#define SET(K,V) cson_object_set(o,(K), (V))
    SET("isLeaf", cson_value_new_bool(is_a_leaf(rid)));
    SET("uuid",json_new_string(zUuid));

    zUser = db_column_text(&q,2);
    SET("user",json_new_string(zUser));
    zEUser = db_text(0,
                   "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
                   TAG_USER, rid);
    if(zEUser){
      SET("editedBy", json_new_string(zEUser));



      free(zEUser);


    }

    zComment = db_column_text(&q,3);
    SET("comment",json_new_string(zComment));
    zEComment = db_text(0, 
                   "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
                   TAG_COMMENT, rid);
    if(zEComment){
      SET("editedComment", json_new_string(zEComment));



      free(zEComment);


    }

    mtime = db_column_int(&q,1);
    SET("mtime",json_new_int(mtime));
    omtime = db_column_int(&q,4);
    if(omtime && (omtime!=mtime)){
      SET("omtime",json_new_int(omtime));
    }

    if(zParent){
      SET("parentUuid", json_new_string(zParent));
    }

    tmpV = json_tags_for_rid(rid);
................................................................................
  db_finalize(&q);
  return v;
}

/*
** Sub-impl of /json/artifact for checkins.
*/
static cson_value * json_artifact_ci( int rid, char const * zUuid ){
  return json_artifact_for_ci(rid, zUuid, 1);
}

static char perms_can_read(){
  return g.perm.Read ? 1 : 0;
}

static ArtifactDispatchEntry ArtifactDispatchList[] = {
................................................................................
    if(0!=strcmp(disp->name, zType)){
      continue;
    }else{
      cson_value * entry;
      if( ! (*disp->permCheck)() ){
        break;
      }
      entry = (*disp->func)(rid, zUuid);
      if(entry){
        cson_object_set(pay, "artifact", entry);
      }
      break;
    }
  }
  if( !disp->name ){







|
|


|







 







|



|
>
>
>
>







|
|
>
>
>
|









|






|

>

<




|
>
>
>

>
>



<




|
>
>
>

>
>






|







 







|
|







 







|







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include "json_artifact.h"

#if INTERFACE
#include "json_detail.h"
#endif

/*
** Internal callback for /json/artifact handlers. rid refers to
** the rid of a given type of artifact, and each callback is
** specialized to return a JSON form of one type of artifact.
*/
typedef cson_value * (*artifact_f)( int rid );

typedef struct ArtifactDispatchEntry {
  /**
     Artifact type name, e.g. "checkin".
   */
  char const * name;
  /**
................................................................................

/*
** Generates an artifact Object for the given rid/zUuid. rid
** must refer to a Checkin.
**
** Returned value is NULL or an Object owned by the caller.
*/
cson_value * json_artifact_for_ci( int rid, char showFiles ){
  char const * zParent = NULL;
  cson_value * v = NULL;
  Stmt q;
  static cson_value * eventTypeLabel = NULL;
  if(!eventTypeLabel){
    eventTypeLabel = json_new_string("commit");
    json_gc_add("$EVENT_TYPE_LABEL(commit)", eventTypeLabel, 1);
  }
  zParent = db_text(0,
    "SELECT uuid FROM plink, blob"
    " WHERE plink.cid=%d AND blob.rid=plink.pid AND plink.isprim",
    rid
  );

  db_prepare(&q, 
             "SELECT uuid, "
             " strftime('%%s',mtime), "
             " user, "
             " comment,"
             " strftime('%%s',omtime)"
             " FROM blob, event"
             " WHERE blob.rid=%d"
             "   AND event.objid=%d",
             rid, rid
             );
  if( db_step(&q)==SQLITE_ROW ){
    cson_object * o;
    cson_value * tmpV = NULL;
    v = cson_value_new_object();
    o = cson_value_get_object(v);
    const char *zUuid = db_column_text(&q, 0);
    char * zTmp;
    const char *zUser;
    const char *zComment;
    char * zEUser, * zEComment;
    int mtime, omtime;
#define SET(K,V) cson_object_set(o,(K), (V))
    SET("artifactType", eventTypeLabel );
    SET("uuid",json_new_string(zUuid));
    SET("isLeaf", cson_value_new_bool(is_a_leaf(rid)));
    zUser = db_column_text(&q,2);

    zEUser = db_text(0,
                   "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
                   TAG_USER, rid);
    if(zEUser){
      SET("user", json_new_string(zEUser));
      if(0!=strcmp(zEUser,zUser)){
        SET("originUser",json_new_string(zUser));
      }
      free(zEUser);
    }else{
      SET("user",json_new_string(zUser));
    }

    zComment = db_column_text(&q,3);

    zEComment = db_text(0, 
                   "SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
                   TAG_COMMENT, rid);
    if(zEComment){
      SET("comment",json_new_string(zEComment));
      if(0 != strcmp(zEComment,zComment)){
        SET("originComment", json_new_string(zComment));
      }
      free(zEComment);
    }else{
      SET("comment",json_new_string(zComment));
    }

    mtime = db_column_int(&q,1);
    SET("mtime",json_new_int(mtime));
    omtime = db_column_int(&q,4);
    if(omtime && (omtime!=mtime)){
      SET("originTime",json_new_int(omtime));
    }

    if(zParent){
      SET("parentUuid", json_new_string(zParent));
    }

    tmpV = json_tags_for_rid(rid);
................................................................................
  db_finalize(&q);
  return v;
}

/*
** Sub-impl of /json/artifact for checkins.
*/
static cson_value * json_artifact_ci( int rid ){
  return json_artifact_for_ci(rid, 1);
}

static char perms_can_read(){
  return g.perm.Read ? 1 : 0;
}

static ArtifactDispatchEntry ArtifactDispatchList[] = {
................................................................................
    if(0!=strcmp(disp->name, zType)){
      continue;
    }else{
      cson_value * entry;
      if( ! (*disp->permCheck)() ){
        break;
      }
      entry = (*disp->func)(rid);
      if(entry){
        cson_object_set(pay, "artifact", entry);
      }
      break;
    }
  }
  if( !disp->name ){

Changes to src/json_timeline.c.

315
316
317
318
319
320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
  listV = cson_value_new_array();
  list = cson_value_get_array(listV);
  tmp = listV;
  SET("timeline");
  while( (SQLITE_ROW == db_step(&q) )){
    /* convert each row into a JSON object...*/
    int const rid = db_column_int(&q,0);
    cson_value * rowV = cson_sqlite3_row_to_object(q.pStmt);
    cson_object * row = cson_value_get_object(rowV);
    cson_value * tagList = NULL;
    if(!row && !warnRowToJsonFailed){
      warnRowToJsonFailed = 1;
      json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED,
                 "Could not convert at least one timeline result row to JSON." );

      continue;
    }
    /* Split tags string field into JSON Array... */
    cson_array_append(list, rowV);
    tmp = json_tags_for_rid(rid);
    if(tmp){
        cson_object_set(row,"tags",tmp);
    }

    /* replace isLeaf int w/ JSON bool */
    tmp = cson_object_get(row,"isLeaf");
    if(tmp && cson_value_is_integer(tmp)){
      cson_object_set(row,"isLeaf",
                      cson_value_get_integer(tmp)
                      ? cson_value_true()
                      : cson_value_false());
      tmp = NULL;
    }
    if( showFiles ){
      cson_value * flist = json_get_changed_files(rid);
      if(flist){
        cson_object_set(row,"files",flist);
      }
    }
  }
#undef SET
  goto ok;
  error:
  assert( 0 != g.json.resultCode );
  cson_value_free(payV);
  payV = NULL;







|

|
|
|
|
|
>


<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

332




















333
334
335
336
337
338
339
  listV = cson_value_new_array();
  list = cson_value_get_array(listV);
  tmp = listV;
  SET("timeline");
  while( (SQLITE_ROW == db_step(&q) )){
    /* convert each row into a JSON object...*/
    int const rid = db_column_int(&q,0);
    cson_value * rowV = json_artifact_for_ci(rid, showFiles);
    cson_object * row = cson_value_get_object(rowV);
    if(!row){
      if( !warnRowToJsonFailed ){
        warnRowToJsonFailed = 1;
        json_warn( FSL_JSON_W_ROW_TO_JSON_FAILED,
                   "Could not convert at least one timeline result row to JSON." );
      }
      continue;
    }

    cson_array_append(list, rowV);




















  }
#undef SET
  goto ok;
  error:
  assert( 0 != g.json.resultCode );
  cson_value_free(payV);
  payV = NULL;