Fossil SCM
Added --html|-h option to /json/diff to retrieve HTML-marked-up diffs.
Commit
a15214e83c3adb3ee02ccae0d06330e3636dbef6
Parent
06cd311c17551de…
1 file changed
+9
-3
+9
-3
| --- src/json_diff.c | ||
| +++ src/json_diff.c | ||
| @@ -29,20 +29,24 @@ | ||
| 29 | 29 | ** Generates a diff between two versions (zFrom and zTo), using nContext |
| 30 | 30 | ** content lines in the output. On success, returns a new JSON String |
| 31 | 31 | ** object. On error it sets g.json's error state and returns NULL. |
| 32 | 32 | ** |
| 33 | 33 | ** If fSbs is true (non-0) them side-by-side diffs are used. |
| 34 | +** | |
| 35 | +** If fHtml is true then HTML markup is added to the diff. | |
| 34 | 36 | */ |
| 35 | 37 | cson_value * json_generate_diff(const char *zFrom, const char *zTo, |
| 36 | - int nContext, char fSbs){ | |
| 38 | + int nContext, char fSbs, | |
| 39 | + char fHtml){ | |
| 37 | 40 | int fromid; |
| 38 | 41 | int toid; |
| 39 | 42 | int outLen; |
| 40 | 43 | Blob from = empty_blob, to = empty_blob, out = empty_blob; |
| 41 | 44 | cson_value * rc = NULL; |
| 42 | 45 | int flags = (DIFF_CONTEXT_MASK & nContext) |
| 43 | - | (fSbs ? DIFF_SIDEBYSIDE : 0); | |
| 46 | + | (fSbs ? DIFF_SIDEBYSIDE : 0) | |
| 47 | + | (fHtml ? DIFF_HTML : 0); | |
| 44 | 48 | fromid = name_to_typed_rid(zFrom, "*"); |
| 45 | 49 | if(fromid<=0){ |
| 46 | 50 | json_set_err(FSL_JSON_E_UNRESOLVED_UUID, |
| 47 | 51 | "Could not resolve 'from' ID."); |
| 48 | 52 | return NULL; |
| @@ -85,10 +89,11 @@ | ||
| 85 | 89 | cson_value * v = NULL; |
| 86 | 90 | char const * zFrom; |
| 87 | 91 | char const * zTo; |
| 88 | 92 | int nContext = 0; |
| 89 | 93 | char doSBS; |
| 94 | + char doHtml; | |
| 90 | 95 | if(!g.perm.Read){ |
| 91 | 96 | json_set_err(FSL_JSON_E_DENIED, |
| 92 | 97 | "Requires 'o' permissions."); |
| 93 | 98 | return NULL; |
| 94 | 99 | } |
| @@ -110,11 +115,12 @@ | ||
| 110 | 115 | "Required 'v2' parameter is missing."); |
| 111 | 116 | return NULL; |
| 112 | 117 | } |
| 113 | 118 | nContext = json_find_option_int("context",NULL,"c",5); |
| 114 | 119 | doSBS = json_find_option_bool("sbs",NULL,"y",0); |
| 115 | - v = json_generate_diff(zFrom, zTo, nContext, doSBS); | |
| 120 | + doHtml = json_find_option_bool("html",NULL,"h",0); | |
| 121 | + v = json_generate_diff(zFrom, zTo, nContext, doSBS, doHtml); | |
| 116 | 122 | if(!v){ |
| 117 | 123 | if(!g.json.resultCode){ |
| 118 | 124 | json_set_err(FSL_JSON_E_UNKNOWN, |
| 119 | 125 | "Generating diff failed for unknown reason."); |
| 120 | 126 | } |
| 121 | 127 |
| --- src/json_diff.c | |
| +++ src/json_diff.c | |
| @@ -29,20 +29,24 @@ | |
| 29 | ** Generates a diff between two versions (zFrom and zTo), using nContext |
| 30 | ** content lines in the output. On success, returns a new JSON String |
| 31 | ** object. On error it sets g.json's error state and returns NULL. |
| 32 | ** |
| 33 | ** If fSbs is true (non-0) them side-by-side diffs are used. |
| 34 | */ |
| 35 | cson_value * json_generate_diff(const char *zFrom, const char *zTo, |
| 36 | int nContext, char fSbs){ |
| 37 | int fromid; |
| 38 | int toid; |
| 39 | int outLen; |
| 40 | Blob from = empty_blob, to = empty_blob, out = empty_blob; |
| 41 | cson_value * rc = NULL; |
| 42 | int flags = (DIFF_CONTEXT_MASK & nContext) |
| 43 | | (fSbs ? DIFF_SIDEBYSIDE : 0); |
| 44 | fromid = name_to_typed_rid(zFrom, "*"); |
| 45 | if(fromid<=0){ |
| 46 | json_set_err(FSL_JSON_E_UNRESOLVED_UUID, |
| 47 | "Could not resolve 'from' ID."); |
| 48 | return NULL; |
| @@ -85,10 +89,11 @@ | |
| 85 | cson_value * v = NULL; |
| 86 | char const * zFrom; |
| 87 | char const * zTo; |
| 88 | int nContext = 0; |
| 89 | char doSBS; |
| 90 | if(!g.perm.Read){ |
| 91 | json_set_err(FSL_JSON_E_DENIED, |
| 92 | "Requires 'o' permissions."); |
| 93 | return NULL; |
| 94 | } |
| @@ -110,11 +115,12 @@ | |
| 110 | "Required 'v2' parameter is missing."); |
| 111 | return NULL; |
| 112 | } |
| 113 | nContext = json_find_option_int("context",NULL,"c",5); |
| 114 | doSBS = json_find_option_bool("sbs",NULL,"y",0); |
| 115 | v = json_generate_diff(zFrom, zTo, nContext, doSBS); |
| 116 | if(!v){ |
| 117 | if(!g.json.resultCode){ |
| 118 | json_set_err(FSL_JSON_E_UNKNOWN, |
| 119 | "Generating diff failed for unknown reason."); |
| 120 | } |
| 121 |
| --- src/json_diff.c | |
| +++ src/json_diff.c | |
| @@ -29,20 +29,24 @@ | |
| 29 | ** Generates a diff between two versions (zFrom and zTo), using nContext |
| 30 | ** content lines in the output. On success, returns a new JSON String |
| 31 | ** object. On error it sets g.json's error state and returns NULL. |
| 32 | ** |
| 33 | ** If fSbs is true (non-0) them side-by-side diffs are used. |
| 34 | ** |
| 35 | ** If fHtml is true then HTML markup is added to the diff. |
| 36 | */ |
| 37 | cson_value * json_generate_diff(const char *zFrom, const char *zTo, |
| 38 | int nContext, char fSbs, |
| 39 | char fHtml){ |
| 40 | int fromid; |
| 41 | int toid; |
| 42 | int outLen; |
| 43 | Blob from = empty_blob, to = empty_blob, out = empty_blob; |
| 44 | cson_value * rc = NULL; |
| 45 | int flags = (DIFF_CONTEXT_MASK & nContext) |
| 46 | | (fSbs ? DIFF_SIDEBYSIDE : 0) |
| 47 | | (fHtml ? DIFF_HTML : 0); |
| 48 | fromid = name_to_typed_rid(zFrom, "*"); |
| 49 | if(fromid<=0){ |
| 50 | json_set_err(FSL_JSON_E_UNRESOLVED_UUID, |
| 51 | "Could not resolve 'from' ID."); |
| 52 | return NULL; |
| @@ -85,10 +89,11 @@ | |
| 89 | cson_value * v = NULL; |
| 90 | char const * zFrom; |
| 91 | char const * zTo; |
| 92 | int nContext = 0; |
| 93 | char doSBS; |
| 94 | char doHtml; |
| 95 | if(!g.perm.Read){ |
| 96 | json_set_err(FSL_JSON_E_DENIED, |
| 97 | "Requires 'o' permissions."); |
| 98 | return NULL; |
| 99 | } |
| @@ -110,11 +115,12 @@ | |
| 115 | "Required 'v2' parameter is missing."); |
| 116 | return NULL; |
| 117 | } |
| 118 | nContext = json_find_option_int("context",NULL,"c",5); |
| 119 | doSBS = json_find_option_bool("sbs",NULL,"y",0); |
| 120 | doHtml = json_find_option_bool("html",NULL,"h",0); |
| 121 | v = json_generate_diff(zFrom, zTo, nContext, doSBS, doHtml); |
| 122 | if(!v){ |
| 123 | if(!g.json.resultCode){ |
| 124 | json_set_err(FSL_JSON_E_UNKNOWN, |
| 125 | "Generating diff failed for unknown reason."); |
| 126 | } |
| 127 |