| ︙ | | |
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
|
-
+
|
** --wet-run Disables the default dry-run mode.
**
** Example:
**
** %fossil test-ci-mini -R REPO -m ... -r foo --as src/myfile.c myfile.c
**
*/
void test_ci_mini_cmd(){
void test_ci_mini_cmd(void){
CheckinMiniInfo cimi; /* checkin state */
int newRid = 0; /* RID of new version */
const char * zFilename; /* argv[2] */
const char * zComment; /* -m comment */
const char * zCommentFile; /* -M FILE */
const char * zAsFilename; /* --as filename */
const char * zRevision; /* --revision|-r [=trunk|checkout] */
|
| ︙ | | |
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
|
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
|
-
+
+
|
/*
** Performs bootstrapping common to the /fileedit_xyz AJAX routes.
** Returns 0 if bootstrapping fails (wrong permissions), in which
** case it has reported the error and the route should immediately
** return. Returns true on success.
*/
static int fileedit_ajax_boostrap(){
static int fileedit_ajax_boostrap(void){
login_check_credentials();
if( !g.perm.Write ){
fileedit_ajax_error(403,"Write permissions required.");
return 0;
}
return 1;
}
/*
** Returns true if the current user is allowed to edit the given
** filename, as determined by fileedit_is_editable(), else false,
** in which case it queues up an error response and the caller
** must return immediately.
|
| ︙ | | |
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
|
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
|
-
+
+
+
+
-
+
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
|
** populates:
**
** - *zRevUuid = the fully-expanded value of zRev (owned by the
** caller). zRevUuid may be NULL.
**
** - *vid = the RID of zRevUuid. May not be NULL.
**
** - *frid = the RID of zFilename's blob content. May not be NULL.
** - *frid = the RID of zFilename's blob content. May not be NULL
** unless zFilename is also NULL. If BOTH of zFilename and frid are
** NULL then no confirmation is done on the filename argument - only
** zRev is checked.
**
** Returns 0 if the given file is not in the given checkin or if
** fileedit_ajax_check_filename() fails, else returns true. If it
** returns false, it queues up an error response and the caller must
** return immediately.
*/
static int fileedit_ajax_setup_filerev(const char * zRev,
char ** zRevUuid,
int * vid,
const char * zFilename,
int * frid){
char * zCi = 0; /* fully-resolved checkin UUID */
char * zFileUuid; /* file UUID */
const int checkFile = zFilename!=0 || frid!=0;
if(!fileedit_ajax_check_filename(zFilename)){
if(checkFile && !fileedit_ajax_check_filename(zFilename)){
return 0;
}
*vid = symbolic_name_to_rid(zRev, "ci");
if(0==*vid){
fileedit_ajax_error(404,"Cannot resolve name as a checkin: %s",
zRev);
return 0;
}else if(*vid<0){
fileedit_ajax_error(400,"Checkin name is ambiguous: %s",
zRev);
return 0;
}
if(checkFile){
zFileUuid = fileedit_file_uuid(zFilename, *vid, 0);
if(zFileUuid==0){
fileedit_ajax_error(404,"Checkin does not contain file.");
return 0;
}
zCi = rid_to_uuid(*vid);
*frid = fast_uuid_to_rid(zFileUuid);
fossil_free(zFileUuid);
if(zRevUuid!=0){
*zRevUuid = zCi;
zFileUuid = fileedit_file_uuid(zFilename, *vid, 0);
if(zFileUuid==0){
fileedit_ajax_error(404,"Checkin does not contain file.");
return 0;
}
}
if(zRevUuid!=0){
*zRevUuid = rid_to_uuid(*vid);
}
if(checkFile){
assert(zFileUuid!=0);
if(frid!=0){
*frid = fast_uuid_to_rid(zFileUuid);
}else{
fossil_free(zCi);
}
fossil_free(zFileUuid);
}
return 1;
}
/*
** WEBPAGE: fileedit_content
**
** Query parameters:
**
** filename=FILENAME
** checkin=CHECKIN_NAME
**
** User must have Write access to use this page.
**
** Responds with the raw content of the given page. On error it
** produces a JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_content(){
void fileedit_ajax_content(void){
const char * zFilename = 0;
const char * zRev = 0;
int vid, frid;
Blob content = empty_blob;
const char * zMime;
fileedit_get_fnci_args( &zFilename, &zRev );
|
| ︙ | | |
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
|
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
|
-
+
|
** iframe.
**
** User must have Write access to use this page.
**
** Responds with the HTML content of the preview. On error it produces
** a JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_preview(){
void fileedit_ajax_preview(void){
const char * zFilename = 0;
const char * zContent = P("content");
int renderMode = atoi(PD("render_mode","0"));
int ln = atoi(PD("ln","0"));
int iframeHeight = atoi(PD("iframe_height","40"));
Blob content = empty_blob;
|
| ︙ | | |
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
|
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
|
-
+
|
** sbs=integer (1=side-by-side or 0=unified, default=0)
**
** User must have Write access to use this page.
**
** Responds with the HTML content of the diff. On error it produces a
** JSON response as documented for fileedit_ajax_error().
*/
void fileedit_ajax_diff(){
void fileedit_ajax_diff(void){
/*
** Reminder: we only need the filename to perform valdiation
** against fileedit_is_editable(), else this route could be
** abused to get diffs against content disallowed by the
** whitelist.
*/
const char * zFilename = 0;
|
| ︙ | | |
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
|
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
|
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
end_fail:
#undef fail
fossil_free(zFileUuid);
return rc ? rc : 500;
}
/*
** WEBPAGE: fileedit_commit
** WEBPAGE: fileedit_filelist
**
** Fetches a JSON-format list of leaves and/or filenames for use in
** creating a file selection list in /fileedit. It has different modes
** of operation depending on its arguments:
**
** 'leaves': just fetch a list of open leaf versions, in this
** format:
**
** [
** {checkin: UUID, branch: branchName, timestamp: string}
** ]
**
** The entries are ordered newest first.
**
** 'checkin=CHECKIN_NAME': fetch the current list of is-editable files
** for the current user and given checkin name:
**
** {
** checkin: UUID,
** editableFiles: [ filename1, ... filenameN ] // sorted by name
** }
**
** On error it produces a JSON response as documented for
** fileedit_ajax_error().
*/
void fileedit_ajax_filelist(void){
const char * zCi = PD("checkin",P("ci"));
Blob sql = empty_blob;
Stmt q = empty_Stmt;
int i = 0;
if(!fileedit_ajax_boostrap()){
return;
}
cgi_set_content_type("application/json");
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.");
}
}
/*
** WEBPAGE: fileedit_commit ajax
**
** Required query parameters:
**
** filename=FILENAME
** checkin=Parent checkin UUID
** content=text
** comment=text
|
| ︙ | | |
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
|
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
|
-
+
|
** manifest: text of manifest,
** dryRun: bool
** }
**
** On error it produces a JSON response as documented for
** fileedit_ajax_error().
*/
void fileedit_ajax_commit(){
void fileedit_ajax_commit(void){
Blob err = empty_blob; /* Error messages */
Blob manifest = empty_blob; /* raw new manifest */
CheckinMiniInfo cimi; /* checkin state */
int rc; /* generic result code */
int newVid = 0; /* new version's RID */
char * zNewUuid = 0; /* newVid's UUID */
|
| ︙ | | |
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
|
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
|
-
-
+
+
-
+
|
** checkin=VERSION Checkin version, using any unambiguous
** supported symbolic version name.
**
** All other parameters are for internal use only, submitted via the
** form-submission process, and may change with any given revision of
** this code.
*/
void fileedit_page(){
const char * zFilename; /* filename. We'll accept 'name'
void fileedit_page(void){
const char * zFilename = 0; /* filename. We'll accept 'name'
because that param is handled
specially by the core. */
const char * zRev; /* checkin version */
const char * zRev = 0; /* checkin version */
const char * zFileMime = 0; /* File mime type guess */
CheckinMiniInfo cimi; /* Checkin state */
int previewHtmlHeight = 0; /* iframe height (EMs) */
int previewRenderMode = FE_RENDER_GUESS; /* preview mode */
Blob err = empty_blob; /* Error report */
Blob endScript = empty_blob; /* Script code to run at the
end. This content will be
|
| ︙ | | |
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
|
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
|
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
|
CheckinMiniInfo_init(&cimi);
style_header("File Editor");
/* As of this point, don't use return or fossil_fatal(). Write any
** error in (&err) and goto end_footer instead so that we can be
** sure to do any cleanup and end the transaction cleanly.
*/
if(fileedit_setup_cimi_from_p(&cimi, &err)!=0){
if(fileedit_setup_cimi_from_p(&cimi, &err)==0){
goto end_footer;
}
zFilename = cimi.zFilename;
zRev = cimi.zParentUuid;
assert(zRev);
assert(zFilename);
zFileMime = mimetype_from_name(cimi.zFilename);
zFilename = cimi.zFilename;
zRev = cimi.zParentUuid;
assert(zRev);
assert(zFilename);
zFileMime = mimetype_from_name(cimi.zFilename);
}
/********************************************************************
** All errors which "could" have happened up to this point are of a
** degree which keep us from rendering the rest of the page, and
** thus have already caused us to skipped to the end of the page to
** render the errors. Any up-coming errors, barring malloc failure
** or similar, are not "that" fatal. We can/should continue
|
| ︙ | | |
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
|
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
|
-
-
-
-
-
-
-
+
-
+
-
+
-
+
-
-
-
+
+
+
+
|
CX("document.body.classList.add('fileedit');\n");
style_emit_script_tag(1,0);
}
CX("<p>This page is <em>NEW AND EXPERIMENTAL</em>. "
"USE AT YOUR OWN RISK, preferably on a test "
"repo.</p>\n");
/******* Hidden fields *******/
CX("<input type='hidden' name='checkin' value='%s'>",
cimi.zParentUuid);
CX("<input type='hidden' name='filename' value='%T'>",
zFilename);
/* Status bar */
CX("<div id='fossil-status-bar'>Async. status messages will go "
"here.</div>\n"/* will be moved into the tab container via JS */);
/* Main tab container... */
CX("<div id='fileedit-tabs' class='tab-container'></div>");
/***** File/version info tab *****/
{
CX("<div id='fileedit-tab-version' "
"data-tab-parent='fileedit-tabs' "
"data-tab-label='Version Info'"
"data-tab-label='File Info & Selection'"
">");
CX("File: "
"<code id='finfo-file-name'>(loading)</code><br>");
"<code id='finfo-file-name'>" "???" "</code><br>");
CX("Checkin Version: "
"[<a id='timeline-link' href='#'>/timeline</a>] "
"[<a id='r-link' href='#'>/info</a>] "
/* %R/info/%!S */
"<code id='r-label'>(loading...)</code><br>"
"<code id='r-label'>" "???" "</code><br>"
);
CX("Permalink: <code>"
"<a id='permalink' href='#'>(loading...)</a></code><br>"
"<a id='permalink' href='#'>" "???" "</a></code><br>"
"(Clicking the permalink will reload the page and discard "
"all edits!)",
zFilename, cimi.zParentUuid,
zFilename, cimi.zParentUuid);
"all edits!)");
CX("<h1>Select a file to edit:</h1>");
CX("<div id='fileedit-file-selector'></div>");
CX("</div>"/*#fileedit-tab-version*/);
}
/******* Content tab *******/
{
CX("<div id='fileedit-tab-content' "
"data-tab-parent='fileedit-tabs' "
|
| ︙ | | |
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
|
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
|
+
-
+
+
|
NULL,
"Auto-refresh?",
"1", 1,
"If on, the preview will automatically "
"refresh when this tab is selected.");
/* Default preview rendering mode selection... */
previewRenderMode = zFileMime
previewRenderMode = fileedit_render_mode_for_mimetype(zFileMime);
? fileedit_render_mode_for_mimetype(zFileMime)
: FE_RENDER_GUESS;
style_select_list_int("select-preview-mode",
"preview_render_mode",
"Preview Mode",
"Preview mode format.",
previewRenderMode,
"Guess", FE_RENDER_GUESS,
"Wiki/Markdown", FE_RENDER_WIKI,
|
| ︙ | | |
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
|
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
|
-
-
-
+
-
|
"};\n",
FE_RENDER_GUESS, FE_RENDER_GUESS,
FE_RENDER_WIKI, FE_RENDER_WIKI,
FE_RENDER_HTML_IFRAME, FE_RENDER_HTML_IFRAME,
FE_RENDER_HTML_INLINE, FE_RENDER_HTML_INLINE,
FE_RENDER_PLAIN_TEXT, FE_RENDER_PLAIN_TEXT);
/* Allow selection of HTML preview iframe height */
previewHtmlHeight = atoi(PD("preview_html_ems","0"));
if(!previewHtmlHeight){
previewHtmlHeight = 40;
previewHtmlHeight = 40;
}
style_select_list_int("select-preview-html-ems",
"preview_html_ems",
"HTML Preview IFrame Height (EMs)",
"Height (in EMs) of the iframe used for "
"HTML preview",
previewHtmlHeight,
"", 20, "", 40,
|
| ︙ | | |
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
|
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
|
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
|
"<button id='fileedit-btn-commit'>Commit</button>"
"</div>\n");
CX("<div id='fileedit-manifest'></div>\n"
/* Manifest gets rendered here after a commit. */);
}
CX("</div>"/*#fileedit-tab-commit*/);
/* Dynamically populate the editor... */
blob_appendf(&endScript,
"window.addEventListener('load',"
"()=>fossil.page.loadFile('%j','%j'), false);\n",
zFilename, cimi.zParentUuid);
end_footer:
{
/* Dynamically populate the editor or display a warning
** about having no file loaded... */
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"
"fossil.page.tabs.switchToTab(0);\n",
blob_str(&err));
}else{
blob_appendf(&endScript,
"fossil.error('No file/version selected.')");
}
blob_appendf(&endScript,"}");
}
blob_appendf(&endScript,", false);\n");
}
if(stmt.pStmt){
db_finalize(&stmt);
}
if(blob_size(&err)){
CX("<div class='fileedit-error-report'>%s</div>",
blob_str(&err));
}
blob_reset(&err);
CheckinMiniInfo_cleanup(&cimi);
style_emit_script_fossil_bootstrap(0);
style_emit_script_fetch(0);
style_emit_script_tabs(0);
style_emit_script_confirmer(0);
style_emit_script_builtin(0, "fossil.page.fileedit.js");
|
| ︙ | | |