Fossil

Check-in [d9fffa4c58]
Login

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

Overview
Comment:Cleaned up some JSON output using the new %!j format.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | fileedit-ajaxify
Files: files | file ages | folders
SHA3-256: d9fffa4c58686fa563e35310d0bbad10a4c6a0e3f51d165843f4af40f8008bae
User & Date: stephan 2020-05-15 03:35:05.035
Original Comment: Cleaned up some JSON output using the new %jobs format.
Context
2020-05-15
04:20
Internally rearranged how diff flags are passed around, in anticipation of having to refactor for wiki/forum diffs. Added annotate/blame links to /fileedit's first tab. ... (check-in: 39a5241b6f user: stephan tags: fileedit-ajaxify)
03:35
Cleaned up some JSON output using the new %!j format. ... (check-in: d9fffa4c58 user: stephan tags: fileedit-ajaxify)
03:34
Added %!j to %j, which means to include double quotes around the resulting JSON string, and added the corresponding flag to encode_json_string_literal(). ... (check-in: 2cccc12d04 user: stephan tags: fileedit-ajaxify)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/fileedit.c.
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
static void fileedit_ajax_error(int httpCode, const char * zFmt, ...){
  Blob msg = empty_blob;
  Blob content = empty_blob;
  va_list vargs;
  va_start(vargs,zFmt);
  blob_vappendf(&msg, zFmt, vargs);
  va_end(vargs);
  blob_appendf(&content,"{\"error\":\"%j\"}", blob_str(&msg));
  blob_reset(&msg);
  cgi_set_content(&content);
  cgi_set_status(httpCode, "Error");
  cgi_set_content_type("application/json");
}

/*







|







1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
static void fileedit_ajax_error(int httpCode, const char * zFmt, ...){
  Blob msg = empty_blob;
  Blob content = empty_blob;
  va_list vargs;
  va_start(vargs,zFmt);
  blob_vappendf(&msg, zFmt, vargs);
  va_end(vargs);
  blob_appendf(&content,"{\"error\":%!j}", blob_str(&msg));
  blob_reset(&msg);
  cgi_set_content(&content);
  cgi_set_status(httpCode, "Error");
  cgi_set_content_type("application/json");
}

/*
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
  if(zCi!=0){
    char * zCiFull = 0;
    int vid = 0;
    if(0==fileedit_ajax_setup_filerev(zCi, &zCiFull, &vid, 0, 0)){
      /* Error already reported */
      return;
    }
    CX("{\"checkin\":\"%j\","
       "\"editableFiles\":[", zCiFull);
    blob_append_sql(&sql, "SELECT filename FROM files_of_checkin(%Q) "
                    "ORDER BY filename %s",
                    zCiFull, filename_collation());
    db_prepare_blob(&q, &sql);
    while( SQLITE_ROW==db_step(&q) ){
      const char * zFilename = db_column_text(&q, 0);
      if(fileedit_is_editable(zFilename)){
        if(i++){
          CX(",");
        }
        CX("\"%j\"", zFilename);
      }
    }
    db_finalize(&q);
    CX("]}");
  }else if(P("leaves")!=0){
    blob_append(&sql, timeline_query_for_tty(), -1);
    blob_append_sql(&sql, " AND blob.rid IN (SElECT rid FROM leaf "
                    "WHERE NOT EXISTS("
                    "SELECT 1 from tagxref WHERE tagid=%d AND "
                    "tagtype>0 AND rid=leaf.rid"
                    ")) "
                    "ORDER BY mtime DESC", TAG_CLOSED);
    db_prepare_blob(&q, &sql);
    CX("[");
    while( SQLITE_ROW==db_step(&q) ){
      if(i++){
        CX(",");
      }
      CX("{");
      CX("\"checkin\":\"%j\",", db_column_text(&q, 1));
      CX("\"timestamp\":\"%j\",", db_column_text(&q, 2));
      CX("\"branch\":\"%j\"", db_column_text(&q, 7));
      CX("}");
    }
    CX("]");
    db_finalize(&q);
  }else{
    fileedit_ajax_error(500, "Unhandled URL argument.");
  }







|











|



















|
|
|







1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
  if(zCi!=0){
    char * zCiFull = 0;
    int vid = 0;
    if(0==fileedit_ajax_setup_filerev(zCi, &zCiFull, &vid, 0, 0)){
      /* Error already reported */
      return;
    }
    CX("{\"checkin\":%!j,"
       "\"editableFiles\":[", zCiFull);
    blob_append_sql(&sql, "SELECT filename FROM files_of_checkin(%Q) "
                    "ORDER BY filename %s",
                    zCiFull, filename_collation());
    db_prepare_blob(&q, &sql);
    while( SQLITE_ROW==db_step(&q) ){
      const char * zFilename = db_column_text(&q, 0);
      if(fileedit_is_editable(zFilename)){
        if(i++){
          CX(",");
        }
        CX("%!j", zFilename);
      }
    }
    db_finalize(&q);
    CX("]}");
  }else if(P("leaves")!=0){
    blob_append(&sql, timeline_query_for_tty(), -1);
    blob_append_sql(&sql, " AND blob.rid IN (SElECT rid FROM leaf "
                    "WHERE NOT EXISTS("
                    "SELECT 1 from tagxref WHERE tagid=%d AND "
                    "tagtype>0 AND rid=leaf.rid"
                    ")) "
                    "ORDER BY mtime DESC", TAG_CLOSED);
    db_prepare_blob(&q, &sql);
    CX("[");
    while( SQLITE_ROW==db_step(&q) ){
      if(i++){
        CX(",");
      }
      CX("{");
      CX("\"checkin\":%!j,", db_column_text(&q, 1));
      CX("\"timestamp\":%!j,", db_column_text(&q, 2));
      CX("\"branch\":%!j", db_column_text(&q, 7));
      CX("}");
    }
    CX("]");
    db_finalize(&q);
  }else{
    fileedit_ajax_error(500, "Unhandled URL argument.");
  }
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
    fileedit_ajax_error(500,"%b",&err);
    goto end_cleanup;
  }
  assert(newVid>0);
  zNewUuid = rid_to_uuid(newVid);
  cgi_set_content_type("application/json");
  CX("{");
  CX("\"uuid\":\"%j\",", zNewUuid);
  CX("\"dryRun\": %s,",
     (CIMINI_DRY_RUN & cimi.flags) ? "true" : "false");
  CX("\"manifest\": \"%j\"", blob_str(&manifest));
  CX("}");
  db_end_transaction(0/*noting that dry-run mode will have already
                      ** set this to rollback mode. */);
end_cleanup:
  fossil_free(zNewUuid);
  blob_reset(&err);
  blob_reset(&manifest);







|


|







1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
    fileedit_ajax_error(500,"%b",&err);
    goto end_cleanup;
  }
  assert(newVid>0);
  zNewUuid = rid_to_uuid(newVid);
  cgi_set_content_type("application/json");
  CX("{");
  CX("\"uuid\":%!j,", zNewUuid);
  CX("\"dryRun\": %s,",
     (CIMINI_DRY_RUN & cimi.flags) ? "true" : "false");
  CX("\"manifest\": %!j", blob_str(&manifest));
  CX("}");
  db_end_transaction(0/*noting that dry-run mode will have already
                      ** set this to rollback mode. */);
end_cleanup:
  fossil_free(zNewUuid);
  blob_reset(&err);
  blob_reset(&manifest);
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
    ** blob, and/or switch to tab #0, where the file selector
    ** lives... */
    blob_appendf(&endScript,
                 "window.addEventListener('load',");
    if(zRev && zFilename){
      assert(0==blob_size(&err));
      blob_appendf(&endScript,
                   "()=>fossil.page.loadFile(\"%j\",'%j')",
                   zFilename, cimi.zParentUuid);
    }else{
      blob_appendf(&endScript,"function(){");
      if(blob_size(&err)>0){
        blob_appendf(&endScript,
                     "fossil.error(\"%j\");\n",
                     blob_str(&err));
      }
      blob_appendf(&endScript,
                   "fossil.page.tabs.switchToTab(0);\n");
      blob_appendf(&endScript,"}");
    }
    blob_appendf(&endScript,", false);\n");







|





|







2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
    ** blob, and/or switch to tab #0, where the file selector
    ** lives... */
    blob_appendf(&endScript,
                 "window.addEventListener('load',");
    if(zRev && zFilename){
      assert(0==blob_size(&err));
      blob_appendf(&endScript,
                   "()=>fossil.page.loadFile(%!j,%!j)",
                   zFilename, cimi.zParentUuid);
    }else{
      blob_appendf(&endScript,"function(){");
      if(blob_size(&err)>0){
        blob_appendf(&endScript,
                     "fossil.error(%!j);\n",
                     blob_str(&err));
      }
      blob_appendf(&endScript,
                   "fossil.page.tabs.switchToTab(0);\n");
      blob_appendf(&endScript,"}");
    }
    blob_appendf(&endScript,", false);\n");
Changes to src/style.c.
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
  static int once = 0;
  if(0==once++){
    /* Set up the generic/app-agnostic parts of window.fossil
    ** which require C-level state... */
    style_emit_script_tag(0,0);
    CX("(function(){\n"
       "if(!window.fossil) window.fossil={};\n"
       "window.fossil.version = \"%j\";\n"
    /* fossil.rootPath is the top-most CGI/server path,
    ** including a trailing slash. */
       "window.fossil.rootPath = \"%j\"+'/';\n",
       get_version(), g.zTop);
    /* fossil.config = {...various config-level options...} */
    CX("window.fossil.config = {"
       "hashDigits: %d, hashDigitsUrl: %d"
       "};\n", hash_digits(0), hash_digits(1));
    /*
    ** fossil.page holds info about the current page. This is also







|


|







1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
  static int once = 0;
  if(0==once++){
    /* Set up the generic/app-agnostic parts of window.fossil
    ** which require C-level state... */
    style_emit_script_tag(0,0);
    CX("(function(){\n"
       "if(!window.fossil) window.fossil={};\n"
       "window.fossil.version = %!j;\n"
    /* fossil.rootPath is the top-most CGI/server path,
    ** including a trailing slash. */
       "window.fossil.rootPath = %!j+'/';\n",
       get_version(), g.zTop);
    /* fossil.config = {...various config-level options...} */
    CX("window.fossil.config = {"
       "hashDigits: %d, hashDigitsUrl: %d"
       "};\n", hash_digits(0), hash_digits(1));
    /*
    ** fossil.page holds info about the current page. This is also