Fossil SCM
undid a stash snafu and added sbs option to json/diff.
Commit
adfd3db7657fe8fdf76caf4bdc4f59e0788a6b6f
Parent
acc253f44cfb783…
1 file changed
+9
-3
+9
-3
| --- src/json_diff.c | ||
| +++ src/json_diff.c | ||
| @@ -26,19 +26,23 @@ | ||
| 26 | 26 | |
| 27 | 27 | /* |
| 28 | 28 | ** Generates a diff between two versions (zFrom and zTo), using nContext |
| 29 | 29 | ** content lines in the output. On success, returns a new JSON String |
| 30 | 30 | ** object. On error it sets g.json's error state and returns NULL. |
| 31 | +** | |
| 32 | +** If fSbs is true (non-0) them side-by-side diffs are used. | |
| 31 | 33 | */ |
| 32 | 34 | cson_value * json_generate_diff(const char *zFrom, const char *zTo, |
| 33 | - int nContext){ | |
| 35 | + int nContext, char fSbs){ | |
| 34 | 36 | int fromid; |
| 35 | 37 | int toid; |
| 36 | 38 | int outLen; |
| 37 | 39 | Blob from = empty_blob, to = empty_blob, out = empty_blob; |
| 38 | 40 | cson_value * rc = NULL; |
| 39 | 41 | char const * zType = "ci"; |
| 42 | + int flags = (DIFF_CONTEXT_MASK & nContext) | |
| 43 | + | (fSbs ? DIFF_SIDEBYSIDE : 0); | |
| 40 | 44 | fromid = name_to_typed_rid(zFrom, "*"); |
| 41 | 45 | if(fromid<=0){ |
| 42 | 46 | json_set_err(FSL_JSON_E_UNRESOLVED_UUID, |
| 43 | 47 | "Could not resolve 'from' ID."); |
| 44 | 48 | return NULL; |
| @@ -50,11 +54,11 @@ | ||
| 50 | 54 | return NULL; |
| 51 | 55 | } |
| 52 | 56 | content_get(fromid, &from); |
| 53 | 57 | content_get(toid, &to); |
| 54 | 58 | blob_zero(&out); |
| 55 | - text_diff(&from, &to, &out, nContext, 1); | |
| 59 | + text_diff(&from, &to, &out, flags); | |
| 56 | 60 | blob_reset(&from); |
| 57 | 61 | blob_reset(&to); |
| 58 | 62 | outLen = blob_size(&out); |
| 59 | 63 | if(outLen>0){ |
| 60 | 64 | rc = cson_value_new_string(blob_buffer(&out), blob_size(&out)); |
| @@ -79,10 +83,11 @@ | ||
| 79 | 83 | cson_object * pay = NULL; |
| 80 | 84 | cson_value * v = NULL; |
| 81 | 85 | char const * zFrom; |
| 82 | 86 | char const * zTo; |
| 83 | 87 | int nContext = 0; |
| 88 | + char doSBS; | |
| 84 | 89 | if(!g.perm.Read){ |
| 85 | 90 | json_set_err(FSL_JSON_E_DENIED, |
| 86 | 91 | "Requires 'o' permissions."); |
| 87 | 92 | return NULL; |
| 88 | 93 | } |
| @@ -103,11 +108,12 @@ | ||
| 103 | 108 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 104 | 109 | "Required 'v2' parameter is missing."); |
| 105 | 110 | return NULL; |
| 106 | 111 | } |
| 107 | 112 | nContext = json_find_option_int("context",NULL,"c",5); |
| 108 | - v = json_generate_diff(zFrom, zTo, nContext); | |
| 113 | + doSBS = json_find_option_bool("sbs",NULL,"y",0); | |
| 114 | + v = json_generate_diff(zFrom, zTo, nContext, doSBS); | |
| 109 | 115 | if(!v){ |
| 110 | 116 | if(!g.json.resultCode){ |
| 111 | 117 | json_set_err(FSL_JSON_E_UNKNOWN, |
| 112 | 118 | "Generating diff failed for unknown reason."); |
| 113 | 119 | } |
| 114 | 120 |
| --- src/json_diff.c | |
| +++ src/json_diff.c | |
| @@ -26,19 +26,23 @@ | |
| 26 | |
| 27 | /* |
| 28 | ** Generates a diff between two versions (zFrom and zTo), using nContext |
| 29 | ** content lines in the output. On success, returns a new JSON String |
| 30 | ** object. On error it sets g.json's error state and returns NULL. |
| 31 | */ |
| 32 | cson_value * json_generate_diff(const char *zFrom, const char *zTo, |
| 33 | int nContext){ |
| 34 | int fromid; |
| 35 | int toid; |
| 36 | int outLen; |
| 37 | Blob from = empty_blob, to = empty_blob, out = empty_blob; |
| 38 | cson_value * rc = NULL; |
| 39 | char const * zType = "ci"; |
| 40 | fromid = name_to_typed_rid(zFrom, "*"); |
| 41 | if(fromid<=0){ |
| 42 | json_set_err(FSL_JSON_E_UNRESOLVED_UUID, |
| 43 | "Could not resolve 'from' ID."); |
| 44 | return NULL; |
| @@ -50,11 +54,11 @@ | |
| 50 | return NULL; |
| 51 | } |
| 52 | content_get(fromid, &from); |
| 53 | content_get(toid, &to); |
| 54 | blob_zero(&out); |
| 55 | text_diff(&from, &to, &out, nContext, 1); |
| 56 | blob_reset(&from); |
| 57 | blob_reset(&to); |
| 58 | outLen = blob_size(&out); |
| 59 | if(outLen>0){ |
| 60 | rc = cson_value_new_string(blob_buffer(&out), blob_size(&out)); |
| @@ -79,10 +83,11 @@ | |
| 79 | cson_object * pay = NULL; |
| 80 | cson_value * v = NULL; |
| 81 | char const * zFrom; |
| 82 | char const * zTo; |
| 83 | int nContext = 0; |
| 84 | if(!g.perm.Read){ |
| 85 | json_set_err(FSL_JSON_E_DENIED, |
| 86 | "Requires 'o' permissions."); |
| 87 | return NULL; |
| 88 | } |
| @@ -103,11 +108,12 @@ | |
| 103 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 104 | "Required 'v2' parameter is missing."); |
| 105 | return NULL; |
| 106 | } |
| 107 | nContext = json_find_option_int("context",NULL,"c",5); |
| 108 | v = json_generate_diff(zFrom, zTo, nContext); |
| 109 | if(!v){ |
| 110 | if(!g.json.resultCode){ |
| 111 | json_set_err(FSL_JSON_E_UNKNOWN, |
| 112 | "Generating diff failed for unknown reason."); |
| 113 | } |
| 114 |
| --- src/json_diff.c | |
| +++ src/json_diff.c | |
| @@ -26,19 +26,23 @@ | |
| 26 | |
| 27 | /* |
| 28 | ** Generates a diff between two versions (zFrom and zTo), using nContext |
| 29 | ** content lines in the output. On success, returns a new JSON String |
| 30 | ** object. On error it sets g.json's error state and returns NULL. |
| 31 | ** |
| 32 | ** If fSbs is true (non-0) them side-by-side diffs are used. |
| 33 | */ |
| 34 | cson_value * json_generate_diff(const char *zFrom, const char *zTo, |
| 35 | int nContext, char fSbs){ |
| 36 | int fromid; |
| 37 | int toid; |
| 38 | int outLen; |
| 39 | Blob from = empty_blob, to = empty_blob, out = empty_blob; |
| 40 | cson_value * rc = NULL; |
| 41 | char const * zType = "ci"; |
| 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; |
| @@ -50,11 +54,11 @@ | |
| 54 | return NULL; |
| 55 | } |
| 56 | content_get(fromid, &from); |
| 57 | content_get(toid, &to); |
| 58 | blob_zero(&out); |
| 59 | text_diff(&from, &to, &out, flags); |
| 60 | blob_reset(&from); |
| 61 | blob_reset(&to); |
| 62 | outLen = blob_size(&out); |
| 63 | if(outLen>0){ |
| 64 | rc = cson_value_new_string(blob_buffer(&out), blob_size(&out)); |
| @@ -79,10 +83,11 @@ | |
| 83 | cson_object * pay = NULL; |
| 84 | cson_value * v = NULL; |
| 85 | char const * zFrom; |
| 86 | char const * zTo; |
| 87 | int nContext = 0; |
| 88 | char doSBS; |
| 89 | if(!g.perm.Read){ |
| 90 | json_set_err(FSL_JSON_E_DENIED, |
| 91 | "Requires 'o' permissions."); |
| 92 | return NULL; |
| 93 | } |
| @@ -103,11 +108,12 @@ | |
| 108 | json_set_err(FSL_JSON_E_MISSING_ARGS, |
| 109 | "Required 'v2' parameter is missing."); |
| 110 | return NULL; |
| 111 | } |
| 112 | nContext = json_find_option_int("context",NULL,"c",5); |
| 113 | doSBS = json_find_option_bool("sbs",NULL,"y",0); |
| 114 | v = json_generate_diff(zFrom, zTo, nContext, doSBS); |
| 115 | if(!v){ |
| 116 | if(!g.json.resultCode){ |
| 117 | json_set_err(FSL_JSON_E_UNKNOWN, |
| 118 | "Generating diff failed for unknown reason."); |
| 119 | } |
| 120 |