Fossil SCM

undid a stash snafu and added sbs option to json/diff.

stephan 2011-10-22 16:05 json-multitag-test
Commit adfd3db7657fe8fdf76caf4bdc4f59e0788a6b6f
1 file changed +9 -3
+9 -3
--- src/json_diff.c
+++ src/json_diff.c
@@ -26,19 +26,23 @@
2626
2727
/*
2828
** Generates a diff between two versions (zFrom and zTo), using nContext
2929
** content lines in the output. On success, returns a new JSON String
3030
** 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.
3133
*/
3234
cson_value * json_generate_diff(const char *zFrom, const char *zTo,
33
- int nContext){
35
+ int nContext, char fSbs){
3436
int fromid;
3537
int toid;
3638
int outLen;
3739
Blob from = empty_blob, to = empty_blob, out = empty_blob;
3840
cson_value * rc = NULL;
3941
char const * zType = "ci";
42
+ int flags = (DIFF_CONTEXT_MASK & nContext)
43
+ | (fSbs ? DIFF_SIDEBYSIDE : 0);
4044
fromid = name_to_typed_rid(zFrom, "*");
4145
if(fromid<=0){
4246
json_set_err(FSL_JSON_E_UNRESOLVED_UUID,
4347
"Could not resolve 'from' ID.");
4448
return NULL;
@@ -50,11 +54,11 @@
5054
return NULL;
5155
}
5256
content_get(fromid, &from);
5357
content_get(toid, &to);
5458
blob_zero(&out);
55
- text_diff(&from, &to, &out, nContext, 1);
59
+ text_diff(&from, &to, &out, flags);
5660
blob_reset(&from);
5761
blob_reset(&to);
5862
outLen = blob_size(&out);
5963
if(outLen>0){
6064
rc = cson_value_new_string(blob_buffer(&out), blob_size(&out));
@@ -79,10 +83,11 @@
7983
cson_object * pay = NULL;
8084
cson_value * v = NULL;
8185
char const * zFrom;
8286
char const * zTo;
8387
int nContext = 0;
88
+ char doSBS;
8489
if(!g.perm.Read){
8590
json_set_err(FSL_JSON_E_DENIED,
8691
"Requires 'o' permissions.");
8792
return NULL;
8893
}
@@ -103,11 +108,12 @@
103108
json_set_err(FSL_JSON_E_MISSING_ARGS,
104109
"Required 'v2' parameter is missing.");
105110
return NULL;
106111
}
107112
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);
109115
if(!v){
110116
if(!g.json.resultCode){
111117
json_set_err(FSL_JSON_E_UNKNOWN,
112118
"Generating diff failed for unknown reason.");
113119
}
114120
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button